Load the module and create proc directory and status file.
This function requires to initialize proc file directory, slab cache, spinlock, and dispatching thread.
Unload the module and remove proc directory and status file.
This function requires to free all the memories used glabally or stop the process, including dispatching thread, task cache and file directory.
Create and insert task struct into the process list.
This function requires to initialize each variables of the task struct and only register the task which pass the admission control check.
Make the process yield for next process.
This function requires to update timer, wake up the dispatching thread and make high-prioty task to sleep until next period starts.
Destroy the task struct from the process list.
This function requires to remove the corresponding task from process task list and release memory of all data structures.
Fetch task pid, period and process time from userapp.
This function requires to divide the input into three different cases(R, D, Y).
Read task pid, period and process time from /proc.
Help to dispatch thread in the linked list and choose a highest prioty ready task to preempt the current executing task.
This function requirese to find the highest prioty ready task first, and if there is a current running task, we need to change the corresponding states of both tasks and adjust their priority.
Sum up the total raio of process time divided by task period, then add the ratio of new task. If the (overall ratio * 1000) <= 693, and this new task passes the check and can be registered.
Read in the user command and do the whole process automatically. This app will print each step and execution time of doing the job.
make modules
make app
sudo insmod lujin2_MP2.ko
./userapp [task_period] [task_process_time] [number_of_jobs] & ./userapp [task_period] [task_process_time] [number_of_jobs]
Mention that the [task_process] should be the same, as we compare the prioty of tasks by their periods. As a result, the input of [task_process] should remain the same. Also, the unit of both [task_process] and [task_process_time] are in ms.
sudo rmmod lujin2_MP2
./userapp 9000 2000 3 & ./userapp 5000 2000 3 &
Read task succeeded: pid is 1965, period is 9000, process_time is 2000, number of jobs is 3.
Read task succeeded: pid is 1966, period is 5000, process_time is 2000, number of jobs is 3.
Task 1966 registeration begins.
Task in /proc/mp2/status are listed:
1966, 1, 5000, 2000
Task 1966 registration succeeded.
Task 1965 registeration begins.
Task in /proc/mp2/status are listed:
1965, 1, 9000, 2000
1966, 1, 5000, 2000
Task 1965 registration succeeded.
Job 0 of task 1966 is running, start time: 1553587058.223311 s.
Job 0 of task 1966 finished, end time: 1553587060.223311 s.
Task 1966 yield begins...
Job 0 of task 1965 is running, start time: 1553587062.239308 s.
Job 1 of task 1966 is running, start time: 1553587063.215313 s.
Job 1 of task 1966 finished, end time: 1553587065.215315 s.
Task 1966 yield begins...
Job 0 of task 1965 finished, end time: 1553587065.887535 s.
Task 1965 yield begins...
Job 2 of task 1966 is running, start time: 1553587068.215315 s.
Job 2 of task 1966 finished, end time: 1553587070.215309 s.
Task 1966 yield begins...
Job 1 of task 1965 is running, start time: 1553587071.215366 s.
Job 1 of task 1965 finished, end time: 1553587073.215392 s.
Task 1965 yield begins...
Task in /proc/mp2/status are listed:
1965, 1, 9000, 2000
Task 1966 unregistration succeeded.
Job 2 of task 1965 is running, start time: 1553587080.224030 s.
Job 2 of task 1965 finished, end time: 1553587082.224042 s.
Task 1965 yield begins...
Task in /proc/mp2/status are listed:
Task 1965 unregistration succeeded.