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

memguard: changed #ifdef names of headers and function names. Moved many...

memguard: changed #ifdef names of headers and function names. Moved many definitions into the freertos config file
parent c9af48be
......@@ -37,48 +37,6 @@
__typeof__ (b) _b = (b); \
_a < _b ? _a : _b; })
/* Max task priority to be used in the task which sets up the timer */
#define MEMGUARD_SETUP_TASK_PRIORITY configMAX_PRIORITIES - 1
/* Priority of the PMU Overflow Interrupt for the
XScuGic_SetPriorityTriggerType(). The priority can be multiples of 8 and
the lowest is 248. The higher the value the lower the priority */
#define PMU_OVERFLOW_INT_PRIORITY 240U
/* Inter-core interrupt (ICI) ID used for communications among instances of
MemGuard on different cores. The direction of the interrupt is from Master
to Slave. This is used for comm. the beginning of a new window */
#define MEMGUARD_ICI_INT_ID 0
/* Inter-core interrupt ID used for communicating from Slave to Master. It
is used by the slaves for asking the beginning of a new time window when a
slave finds that the minimum available bandwidth finished */
#define MASTER_MEMGUARD_ICI_INT_ID 1
/* Base ID for the PMU interrupts. To obtain the PMU interrupt of a specific
core add the core id (range 0 to 3) to the Base ID.
eg. for core 1 PMU ID = 175 + 1 = 176 */
#define PMU_INT_BASE_ID (143U + 32U)
/* Masks used in ICI communications to the Master Core */
#define MASTER_CORE_ICI_MASK XSCUGIC_SPI_CPU0_MASK
/* ICI mask of active cores */
#define CORES_ICI_MASK (XSCUGIC_SPI_CPU1_MASK | XSCUGIC_SPI_CPU0_MASK)
/* Priority of ICI for the XScuGic_SetPriorityTriggerType(). It has higher
priority than the overflow interrupt in order to preemt the latter */
#define ICI_INT_PRIORITY 232U
/* Triple Timer Counter (TTC) definitions for MemGuard. The TTC with ID == 0
is used by the FreeRTOS tick therefore using the TTC with ID == 1 for
memguard */
#define TTC_TIMER_DEVICE_ID XPAR_XTTCPS_1_DEVICE_ID
#define TTC_TIMER_INTR_ID XPAR_XTTCPS_1_INTR
/* Window time in seconds */
#define WINDOW_TIME ((float) 0.001)
/* Frequency of the TTC timer of memguard */
#define TIMER_FREQ_MEMGUARD ((u32) (1 / WINDOW_TIME))
......@@ -105,10 +63,6 @@ before memguard starts monitoring */
#define MEMGUARD_TASK_BUDGET \
(BANDWIDTH_ASS_MEMGUARD_TASK_IN_MB_PER_S * ACCESSES_PER_MB * WINDOW_TIME)
/* Base address of the On-Chip Memory where we store the variables shared
among the cores */
#define OCM_ADDRESS 0xFFFC0000
/* Weight used for the ema() function */
#define ALPHA_EMA ((float) 0.05)
......@@ -202,11 +156,14 @@ typedef struct {
} memguard_glob_info_t;
/* Global Variable - structure shared among all cores - stored on the OCM
memory */
memguard_glob_info_t __attribute__((section (".ocm_ram"))) memguard_info;
/* Base address of the On-Chip Memory where we store the variables shared
among the cores */
extern uint32_t __start_ocm_ram;
/* Instance of the GIC Controller, it is set inside the portZynqUltrascale.c */
extern XScuGic xInterruptController;
......@@ -224,21 +181,22 @@ static TaskHandle_t memguard_task_handle;
******************************************************************************/
static void memguard_init_task(void *arg);
int setup_inter_core_interrupts();
int setup_pmu_overflow_interrupt();
static int setup_inter_core_interrupts();
static int setup_pmu_overflow_interrupt();
static void start_slave(void);
void memguard_timer_setup();
void check_if_cores_are_ready();
static void memguard_timer_setup();
static void check_if_cores_are_ready();
static void periodic_timer_handler_master(void *callback_ref);
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);
static void overflow_interrupt_handler(void *callback_ref);
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_t *task_info);
static void suspend_task_routine(void *pvParameter1, uint32_t ulParameter2);
static 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);
......@@ -332,6 +290,11 @@ void memguard_setup_task(TaskHandle_t task_handle, uint32_t bandwidth,
BaseType_t prediction_allowed)
{
if(task_handle != NULL){
/* MemGuard handles the memory of the memguard_task_info_t
structures, allocating the memory and freeing the memory. The
free memory operation is executed when a task is deleted inside the
function memguard_notify_task_deleted() */
memguard_task_info_t *new_task_info = pvPortMalloc(sizeof(memguard_task_info_t));
/* Converting the bandwidth into the statically assigned budget and
......@@ -363,16 +326,13 @@ void memguard_setup_task(TaskHandle_t task_handle, uint32_t bandwidth,
new_task_info->tsk_susp_by_memguard = pdTRUE;
}
/* The order of the next 2 ifs is important in order to don't get a
configASSERT() fail. If we try to resume any task which was not created
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() ||
xTimerGetTimerDaemonTaskHandle()) {
vTaskResume(task_handle);
} else {
/* If a task different from the TimerTask and the IdleTask has a NULL
pointer as task_info the system will be halted by a configAssert() */
configASSERT(task_handle != NULL);
}
}
......@@ -446,8 +406,6 @@ BaseType_t memguard_can_task_resume(TaskHandle_t xTask)
stop_memguard_trace();
#endif
/* If the task was suspended and the tsk_susp_by_user flag is false means
that memguard suspended it, otherwise the flag would be pdTRUE */
return can_task_resume;
}
......@@ -492,7 +450,6 @@ void memguard_task_reset_window(TaskHandle_t task_handle)
task_info->counter_val - mask_value(task_info->cur_ass_budget);
else
task_info->curr_used_budget += task_info->cur_ass_budget;
}
/* Computing the average of bandwidth usage in order to reduce the
......@@ -531,7 +488,7 @@ void memguard_task_reset_window(TaskHandle_t task_handle)
}
}
void memguard_switch_in()
void memguard_task_switch_in()
{
#if (INCLUDE_memguard_benchmark)
{
......@@ -562,7 +519,7 @@ void memguard_switch_in()
#endif
}
void memguard_switch_out()
void memguard_task_switch_out()
{
#if (INCLUDE_memguard_benchmark)
{
......@@ -633,7 +590,7 @@ static void memguard_init_task(void *arg)
* These are exectued trough software generated interrupts (SGI). The ICI
* setup here are bidirectional, meaning from Master to Slave and vice versa.
*/
int setup_inter_core_interrupts()
static int setup_inter_core_interrupts()
{
int status;
......@@ -684,7 +641,7 @@ int setup_inter_core_interrupts()
*
* @return status of the setup
*/
int setup_pmu_overflow_interrupt()
static int setup_pmu_overflow_interrupt()
{
int status;
......@@ -741,7 +698,7 @@ static void start_slave(void)
* window. The shared variable "cores_ready" is used for this synchronisation
* purpose.
*/
void check_if_cores_are_ready()
static void check_if_cores_are_ready()
{
int status;
......@@ -768,7 +725,7 @@ void check_if_cores_are_ready()
* This function sets up the window timer. It is supposed to be executed
* inside a Task context in order to execute properly.
*/
void memguard_timer_setup()
static void memguard_timer_setup()
{
int status;
XTtcPs_Config *config;
......@@ -879,9 +836,9 @@ static void periodic_timer_handler_slave(void *callback_ref)
if(atomic_load(&(memguard_info.cores_ready)) > 0){
u64 attrib = (NORM_NONCACHE | INNER_SHAREABLE | OUTER_SHAREABLE);
Xil_SetTlbAttributes(OCM_ADDRESS, attrib);
Xil_SetTlbAttributes(__start_ocm_ram, attrib);
Xil_DCacheEnable();
Xil_SetTlbAttributes(OCM_ADDRESS, attrib);
Xil_SetTlbAttributes(__start_ocm_ram, attrib);
/* We use cores_ready variable here in order to don't enable the
cache a second time, therefore decreasing the value of the
......@@ -943,7 +900,7 @@ static void reset_window_routine(void *pvParameter1, uint32_t ulParameter2)
*
* @param callback_ref not used
*/
void overflow_interrupt_handler(void *callback_ref)
static void overflow_interrupt_handler(void *callback_ref)
{
#if (INCLUDE_memguard_benchmark == 1)
start_memguard_trace();
......@@ -1103,7 +1060,7 @@ BaseType_t find_new_budget(memguard_task_info_t *task_info)
* @param pvParameter1 not used
* @param ulParameter2 not used
*/
void suspend_task_routine(void *pvParameter1, uint32_t ulParameter2)
static void suspend_task_routine(void *pvParameter1, uint32_t ulParameter2)
{
#if (INCLUDE_memguard_benchmark)
start_memguard_trace();
......@@ -1132,7 +1089,8 @@ 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_t *task_info)
static void memguard_vTaskSuspend(TaskHandle_t task_handle,
memguard_task_info_t *task_info)
{
if(task_handle == memguard_task_handle)
return;
......
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