Commit c9af48be authored by Dorel Coman's avatar Dorel Coman Committed by Oliver Horst
Browse files

memguard: improved comments and code structure

parent 25382da1
......@@ -11,30 +11,26 @@
#include <xil/drivers/xttcps.h>
#include <stdint-gcc.h>
#include <stdatomic.h>
#include "freertos/FreeRTOS.h"
#include "freertos/core/task.h"
#include "freertos/core/semphr.h"
#include "freertos/core/timers.h"
#include "memguard/memguard.h"
#include "memguard/perfmon.h"
#include "xil/xil_printf.h"
#include <freertos/core/timers.h>
#include "xil/drivers/xscugic.h"
#include "xil/xil_cache.h"
#include "xil/xil_mmu.h"
#include "platform_info.h"
#include "openamp/remoteproc.h"
#include "metal/sys.h"
#include <metal/atomic.h>
#include <stdatomic.h>
#include "xil/xil_mmu.h"
#include "metal/atomic.h"
#include "openamp/remoteproc.h"
/*******************************************************************************
* Global Definitions and Macros
******************************************************************************/
/* Redefinition of some functions for local use */
#define malloc(size) pvPortMalloc(size)
#define free(ptr) vPortFree(ptr)
/* Function returning the minimum between a and b */
#define min(a, b) \
({ __typeof__ (a) _a = (a); \
......@@ -152,8 +148,8 @@ typedef struct memguard_task_info {
uint32_t average_used_budget;
/* It stores the value which has to be set on the PMU counter. The value
is computed from the cur_ass_budget usingthe function mask_value from
perfmon.c. It represents therefore the negative value of the budget. The
is computed from the cur_ass_budget using the function mask_value from
perfmon.c. It represents therefore the negative value of the budget. The
value is stored during context switch. It is q in the memguard paper */
uint32_t counter_val;
......@@ -168,13 +164,13 @@ typedef struct memguard_task_info {
MemGuard it will be resumed at the beginning of the next time window */
BaseType_t tsk_susp_by_memguard;
/* This variable keeps track about the type of task. It can be Hard
Real-Time and therefore no prediction of bandwidth usage is allowed
(eg. pdFALSE) or it can be Soft Real-Time and allow dynamic banwidth
/* This variable keeps track about the type of task. It can be hard
real-time and therefore no prediction of bandwidth usage is allowed
(i.e., pdFALSE) or it can be soft real-time and allow dynamic bandwidth
prediction. */
BaseType_t prediction_allowed;
} memguard_task_info ;
} memguard_task_info_t ;
/**
* Global structure which is shared among the cores. It keeps track of total
......@@ -204,12 +200,12 @@ typedef struct {
MIN_GUARANTEED_BUDGET */
atomic_uint bw_allocated;
} memguard_glob_info;
} memguard_glob_info_t;
/* Global Variable - structure shared among all cores - stored on the OCM
memory */
memguard_glob_info __attribute__((section (".ocm_ram"))) memguard_info;
memguard_glob_info_t __attribute__((section (".ocm_ram"))) memguard_info;
/* Instance of the GIC Controller, it is set inside the portZynqUltrascale.c */
extern XScuGic xInterruptController;
......@@ -239,10 +235,10 @@ static void periodic_timer_handler_slave(void *callback_ref);
static void reset_window_routine(void *pvParameter1, uint32_t ulParameter2);
void overflow_interrupt_handler(void *callback_ref);
BaseType_t find_new_budget(memguard_task_info *task_info);
BaseType_t find_new_budget(memguard_task_info_t *task_info);
void suspend_task_routine(void *pvParameter1, uint32_t ulParameter2);
void memguard_vTaskSuspend(TaskHandle_t task_handle, memguard_task_info *task_info);
void memguard_vTaskSuspend(TaskHandle_t task_handle, memguard_task_info_t *task_info);
/* Functions defined in runtimes/memguard/benchmark.c */
void memguard_trace_bw_per_tick(uint32_t bandwidth_used);
......@@ -273,7 +269,7 @@ static void assert_print(const char8 *FilenamePtr, s32 LineNumber)
* @param bandwidth in MB/s
* @return in BUS_ACCESS events / window time
*/
uint32_t convert_mb_to_events(uint32_t bandwidth)
static inline uint32_t convert_mb_to_events(uint32_t bandwidth)
{
return (uint32_t) (bandwidth * ACCESSES_PER_MB * WINDOW_TIME);
}
......@@ -286,7 +282,7 @@ uint32_t convert_mb_to_events(uint32_t bandwidth)
* @param old_average computed in the last step, or initial value of the sample
* @return the new average
*/
uint32_t ema(uint32_t new_sample, uint32_t old_average, float alpha)
static inline uint32_t ema(uint32_t new_sample, uint32_t old_average, float alpha)
{
uint32_t new_average = (uint32_t)(alpha * new_sample)
+ (uint32_t)((1-alpha) * old_average);
......@@ -321,12 +317,12 @@ void memguard_init()
pmu_enable_counter_for_event(MEMGUARD_CNTR_ID, ARMV8_PMUV3_PERFCTR_BUS_ACCESS);
/* The task activated at the beginning of scheduling to setup the timer and
then deleted */
then deleted */
xTaskCreate(memguard_init_task, "Memguard", configMINIMAL_STACK_SIZE, NULL,
MEMGUARD_SETUP_TASK_PRIORITY, &memguard_task_handle);
/* The budget size of the setup task is not important because this task
will be deleted after memguard is setup */
will be deleted after memguard is setup */
memguard_setup_task(memguard_task_handle,
BANDWIDTH_ASS_MEMGUARD_TASK_IN_MB_PER_S,
pdTRUE);
......@@ -336,15 +332,15 @@ void memguard_setup_task(TaskHandle_t task_handle, uint32_t bandwidth,
BaseType_t prediction_allowed)
{
if(task_handle != NULL){
memguard_task_info *new_task_info = malloc(sizeof(memguard_task_info));
memguard_task_info_t *new_task_info = pvPortMalloc(sizeof(memguard_task_info_t));
/* Converting the bandwidth into the statically assigned budget and
storing it */
storing it */
new_task_info->ass_budget = convert_mb_to_events(bandwidth);
new_task_info->budget_finished = 0;
/* The average budget is initializes with teh ass_budget in order to
have an initial value */
/* The average budget is initializes with the ass_budget in order to
have an initial value */
new_task_info->average_used_budget = new_task_info->ass_budget;
new_task_info->prediction_allowed = prediction_allowed;
......@@ -353,7 +349,7 @@ void memguard_setup_task(TaskHandle_t task_handle, uint32_t bandwidth,
atomic_uint val_read = atomic_load(&(memguard_info.bw_allocated));
/* We check if the sum of the allocated budgets for each task is not
higher than the minimum guaranteed bandwidth */
higher than the minimum guaranteed bandwidth */
configASSERT(val_read <= MIN_GUARANTEED_BUDGET +
MEMGUARD_TASK_BUDGET * NUMBER_CORES);
......@@ -372,10 +368,8 @@ void memguard_setup_task(TaskHandle_t task_handle, uint32_t bandwidth,
already, we will get an error inside the 2 functions below.
If another task has a NULL pointer as task_info the system will be halted
by a configAssert()*/
} else if (task_handle == xTaskGetIdleTaskHandle()) {
vTaskResume(task_handle);
} else if(task_handle == xTimerGetTimerDaemonTaskHandle()){
} else if (task_handle == xTaskGetIdleTaskHandle() ||
xTimerGetTimerDaemonTaskHandle()) {
vTaskResume(task_handle);
} else {
......@@ -389,7 +383,7 @@ void memguard_notify_task_suspended(TaskHandle_t task_handle)
start_memguard_trace();
#endif
memguard_task_info *task_info = (memguard_task_info *)
memguard_task_info_t *task_info = (memguard_task_info_t *)
pvTaskGetMemguardTaskInfo(task_handle);
if(task_info != NULL)
......@@ -406,7 +400,7 @@ void memguard_notify_task_resumed(TaskHandle_t task_handle)
start_memguard_trace();
#endif
memguard_task_info *task_info = (memguard_task_info *)
memguard_task_info_t *task_info = (memguard_task_info_t *)
pvTaskGetMemguardTaskInfo(task_handle);
task_info->tsk_susp_by_user = pdFALSE;
......@@ -419,7 +413,7 @@ void memguard_notify_task_deleted(TaskHandle_t task_handle)
{
/* The memguard struct allocated for the task has to be deleted once
the task is being deleted */
memguard_task_info *task_info = (memguard_task_info *)
memguard_task_info_t *task_info = (memguard_task_info_t *)
pvTaskGetMemguardTaskInfo(task_handle);
vPortFree(task_info);
}
......@@ -430,20 +424,22 @@ BaseType_t memguard_can_task_resume(TaskHandle_t xTask)
start_memguard_trace();
#endif
memguard_task_info *task_info = (memguard_task_info *) pvTaskGetMemguardTaskInfo(xTask);
memguard_task_info_t *task_info =
(memguard_task_info_t *) pvTaskGetMemguardTaskInfo(xTask);
BaseType_t can_task_resume;
if(task_info != NULL){
can_task_resume = task_info->tsk_susp_by_memguard;
} else if (xTask == xTaskGetIdleTaskHandle()) {
can_task_resume = pdTRUE;
} else {
} else if(xTask == xTimerGetTimerDaemonTaskHandle()){
can_task_resume = pdTRUE;
if ((xTask == xTaskGetIdleTaskHandle()) ||
(xTask == xTimerGetTimerDaemonTaskHandle())) {
can_task_resume = pdTRUE;
} else {
can_task_resume = pdFALSE;
} else {
can_task_resume = pdFALSE;
}
}
#if (INCLUDE_memguard_benchmark)
......@@ -462,7 +458,7 @@ void memguard_task_reset_window(TaskHandle_t task_handle)
if(task_handle == memguard_task_handle)
return;
memguard_task_info *task_info = (memguard_task_info *)
memguard_task_info_t *task_info = (memguard_task_info_t *)
pvTaskGetMemguardTaskInfo(task_handle);
if(task_info->prediction_allowed == pdFALSE) {
......@@ -481,7 +477,7 @@ void memguard_task_reset_window(TaskHandle_t task_handle)
/* The substraction represents how much quota the task wasn't able
to use in the last time window. We do it in order to "compensate"
and improve the average computation */
and improve the average computation */
if(task_info->ass_budget > task_info->curr_used_budget){
task_info->curr_used_budget = task_info->ass_budget +
(task_info->ass_budget - task_info->curr_used_budget);
......@@ -544,7 +540,7 @@ void memguard_switch_in()
#endif
TaskHandle_t taskHandle = xTaskGetCurrentTaskHandle();
memguard_task_info *task_info = (memguard_task_info *)
memguard_task_info_t *task_info = (memguard_task_info_t *)
pvTaskGetMemguardTaskInfo(taskHandle);
if(task_info != NULL){
......@@ -579,7 +575,7 @@ void memguard_switch_out()
pmu_disable_intr(MEMGUARD_CNTR_ID);
TaskHandle_t taskHandle = xTaskGetCurrentTaskHandle();
memguard_task_info *task_info = (memguard_task_info *)
memguard_task_info_t *task_info = (memguard_task_info_t *)
pvTaskGetMemguardTaskInfo(taskHandle);
if(task_info != NULL){
......@@ -964,7 +960,7 @@ void overflow_interrupt_handler(void *callback_ref)
pmu_clear_interrupt(MEMGUARD_CNTR_ID);
TaskHandle_t curr_task = xTaskGetCurrentTaskHandle();
memguard_task_info *task_info = (memguard_task_info *)
memguard_task_info_t *task_info = (memguard_task_info_t *)
pvTaskGetMemguardTaskInfo(curr_task);
if(task_info == NULL)
......@@ -1053,7 +1049,7 @@ void overflow_interrupt_handler(void *callback_ref)
* @param task_info of the task with budget finished
* @return pdTRUE if new budget was found, otherwise pdFALSE
*/
BaseType_t find_new_budget(memguard_task_info *task_info)
BaseType_t find_new_budget(memguard_task_info_t *task_info)
{
uint32_t reclaimed;
atomic_uint new_global_budget;
......@@ -1116,7 +1112,7 @@ void suspend_task_routine(void *pvParameter1, uint32_t ulParameter2)
taskDISABLE_INTERRUPTS();
TaskHandle_t task_handle = pvParameter1;
memguard_task_info *task_info = (memguard_task_info *) pvTaskGetMemguardTaskInfo(task_handle);
memguard_task_info_t *task_info = (memguard_task_info_t *) pvTaskGetMemguardTaskInfo(task_handle);
#if(INCLUDE_memguard_benchmark)
trace_suspend_routine();
......@@ -1136,7 +1132,7 @@ void suspend_task_routine(void *pvParameter1, uint32_t ulParameter2)
* @param task_handle of the task which has to be suspended
* @param task_info of the task which has to be suspended
*/
void memguard_vTaskSuspend(TaskHandle_t task_handle, memguard_task_info *task_info)
void memguard_vTaskSuspend(TaskHandle_t task_handle, memguard_task_info_t *task_info)
{
if(task_handle == memguard_task_handle)
return;
......
......@@ -46,6 +46,7 @@
#include "openamp/hil.h"
#include "metal/atomic.h"
#include "platform_info.h"
#include "freertos/FreeRTOSConfig.h"
#define IPI_BASE_ADDR XPAR_XIPIPSU_0_BASE_ADDRESS /* IPI base address*/
#define IPI_CHN_BITMASK 0x01000000 /* IPI channel bit mask for IPI from/to
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment