PA-API API's
File Structure:- Dynamo
- middleware
- lib
- paapi
- user-level
- kernel-level
- linux-ipaq-v0.6.1
- middleware
Directory user-level/ : use level library for using the PAAPI
- paapi_dvs.h - data structures and functions visible to the end user
- paapi_dvs.c - contains all functions that interface with the PAAPI system
calls as well as control the creation the destruction of POSIX threads. The
functions are described as follows:
- paapi_dvs_create_thread_type: creates a thread type. It takes in as parameter the thread type info (wcet, deadline, period) and it returns a handle identifying the type
- paapi_dvs_change_thread_type: changes the thread type of the calling thread
- paapi_dvs_create_instance: creates a thread instance given the type, the code to be executed and the data to pass to the thread and returns a handle identifying the instance. This functions creates a POSIX thread under the SCHED_FIFO linux real time scheduling policy and stores the handles for the posix thread internally in the library in the vector "threads". The threads start executing but get block when they call paapi_dvs_app_associate.
- paapi_dvs_init: start the PAAPI library. It only sets the scheduling policy of the calling thread and all its children to SCHED_FIFO
- paapi_dvs_select_policy: chooses which PAAPI scheduling policy will be used
- paapi_dvs_start_taskset: Starts all the threads created with paapi_dvs_create_instance. Here the schedulability analysis takes place (within the kernel) and the PAAPI tasks are waken up.
- paapi_dvs_app_start: Called by the PAAPI threads. It notifies the beginning of execution (this functions is actually unnecessary but I kept it there anyways. If you look at the code you will see that it does not do anything)
- paapi_dvs_app_start_period: Called by the PAAPI threads. It tells the PAAPI scheduler that the task will start executing its periodic jobs.
- paapi_dvs_app_done: it notifies the PAAPI scheduler that the execution of the job is finished.
- paapi_dvs_app_associate: Called by the PAAPI threads. Associated the thread as a PAAPI thread. Before calling this function the thread is technically not a PAAPI thread yet.
- paapi_dvs_app_leave: Called by the PAAPI threads. Leaves the PAAPI scheduler freeing all the resources allocated to it.
- paapi_dvs_app_sleep_until_next_period: called by the PAAPI threads. Puts the thread to sleep until its next period is due.
Directory kernel-level/ : use level library for using the PAAPI
- include/linux/paapi-user.h - defines data structures and constants visible to the user level libraries
- include/linux/paapi_syscall.h - proper definition of the PAAPI system calls added to the kernel (nothing very interesting)
- include/linux/paapi_sched.h - data structure and constants used at kernel level only
- include/paapi.h - interface of the new system calls to user level
- paapi_sched.c - contains the kernel internal data structures (type and
instance tables) as well as functions to help on debugging and trace
collection. This file initially has a lot more code but it was cut down
to a few functions and data structures only
- log_trace - we don't print out trace message during the execution of tasks because the overhead is prohibitive. So we store a trace of events in a kernel internal table and print it out at the end of the execution of the task set.
- print_trace - print the trace messages mentioned above.
- paapi.c - contains the implementation of all the PAAPI system calls defined
at kernel level as well as the queues used to manipulate the PAAPI
threads. There are two internal queues:
- wait_for_admission_control - the PAAPI threads are put in this queue after calling sys_paapi_associate.
- wait_for_next_period - the PAAPI threads are put in this queue after calling sys_paapi_sleep_until_next_period
- sys_paapi_create_type - creates a system type and insert in the system type table
- sys_paapi_create_instance - creates a new instance and inserts it in the instance table
- sys_paapi_app_status - depends on the parameter "status" as follows:
- PAAPI_DVS_APP_START - does not do anything anymore.
- PAAPI_DVS_APP_START_PERIOD - initializes some data structures in the instance table and puts the thread to sleep in the "wait_for_next_period" queue.
- PAAPI_DVS_APP_DONE - updates the instance table for the calling thread marking that the thread is done.
- sys_paapi_associate - marks the flag in the linux process data structure saying that the calling thread is a PAAPI thread.
- sys_paapi_sleep_until_next_period - puts the calling thread to sleep in the "wait_for_next_period" queue.
- sys_paapi_control_taskset - implement three distinct functions depending
on the parameter "cmd":
- PAAPI_CTRL_START_TASKSET - goes over the "wait_for_admission_control" queue and collects information about each thread (from the type tables) in order to perform the schedulability analysis and wake up the tasks
- PAAPI_CTRL_CHANGE_TYPE - changes the type information of the calling thread and performs a new schedulability test
- PAAPI_PRINT_LOG - print the trace log in the screen. It is called by the paapi_dvs_start_taskset user level function after all PAAPI threads join the parent thread.
- sys_paapi_destroy_task - deallocates info from the instance and type tables if necessary
- wake_up_tasks - called by the operating system tick handler in order to wake up tasks which are due to execution (according to their period).
- rm_schedulability_analysis - performs the schedulability analysis and
sets the processor speed accordingly. The three parameters are essential
in this functions and change its behavior as follows:
- max_iterations - defines for how many iterations the schedulability analysis algorithm runs. 1 iteration means that a single slowdown factor for the entires taskset will be computed. With more iterations it tries to compute individual slowdown factors per task.
- calc_dynamic_factor - when there this is a computation of dynamic slowdown factors or static slowdown factors. For the static factors the WCET of each task is used. For the dynamic factor the average execution time in the last HISTORY_WINDOW_SIZE is used.
- change_frequency - whether the processor frequency should be changed after computing the slowdown factors.
- update_next_task.incl - macro inserted within the Linux scheduler to keep track of execution information of a PAAPI job whenever a context switch takes place. This macro updates the info of the task selected for execution.
- update_current_task.incl - This macro updates the info of the job preempted of completed.
Linux kernel files modified (relative to the Linux directory three):
- power - softlink inserted in the tree and pointing to the directory "kernel-level"
- include/linux/power - softlink inserted in the tree and pointing to the directory "kernel-level/include/linux/".
- kernel/sched.c - macros update_next_task.incl and update_current_task.incl are inserted right before a context switch takes place. Two includes are also inserted "#include <linux/cpufreq.h>" and "#include <linux/power/paapi_sched.h>".
- include/linux/sched.h - two new fields are added to the "struct task_struct" data structure: instance_index and paapi_task. The first is a pointer to the PAAPI instance table representing this task and the second is a flag used to recognize whether this thread is a PAAPI thread.
- include/asm-arm/arch-sa1100/time.h - function call to wake_up_tasks is inserted in the OS tick interrupt handler "sa1100_timer_interrupt" in order to wake up tasks when their period is due.
- arch/arm/config.in - this line "int 'Timer frequency (HZ) (100)' CONFIG_HZ 100" is inserted to allow configuration of the OS timer tick precision.
- fs/proc/array.c - the following was added in the file:
/* start: modified for PAAPI implementation */ priority, nice, 0UL /* removed */, //task->it_real_value, hz_to_std(task->it_real_value), hz_to_std(task->start_time), vsize, mm ? mm->rss : 0, /* you might want to shift this left 3 */ /* end: modified for PAAPI implementation */
- include/asm-arm/param.h the following was modified in the file. The lines
commented out were there originally. The rest was added.
/* start: modified for PAAPI implementation */ //#ifndef HZ //#define HZ 100 #ifdef __KERNEL__ # define HZ CONFIG_HZ /* internal kernel timer frequency */ # define USER_HZ 100 /* some user interfaces are in ticks */ # define CLOCKS_PER_SEC (USER_HZ) /* like times() */ # define hz_to_std(x) ((x) / ((HZ) / (USER_HZ))) #endif //#if defined(__KERNEL__) && (HZ == 100) //#define hz_to_std(a) (a) #ifndef HZ #define HZ 100 /* if userspace cheats, give them 100 */ #endif /* end: modified for PAAPI implementation */