draft: how to select a realtime task when schedule
0.1. summary
There is a struct rt_rq in struct rq. struct rt_rq is used to store all the realtime task in current struct rq. which has a struct rt_prio_array active.
1 2 3 4 5 6 7 8 9 10 11 12
structrq { ... structrt_rq { ... structrt_prio_arrayactive { DECLARE_BITMAP(bitmap, MAX_RT_PRIO+1); /* include 1 bit for delimiter */ structlist_headqueue[MAX_RT_PRIO]; } ... } ... }
for arq: All the realtime tasks are stored by a bit map and a list array.
DECLARE_BITMAP(bitmap, MAX_RT_PRIO+1) This is a bit map to show if a priority level has task to be selected. One bit set to 1 means one or more task(s).
struct list_head queue[MAX_RT_PRIO] This is list array, each element is a list head. All tasks are linked into different lists according their priority by struct sched_rt_entity‘s struct list_head run_list.
95/* 96 * This is the priority-queue data structure of the RT scheduling class: 97 */ 98structrt_prio_array { 99 DECLARE_BITMAP(bitmap, MAX_RT_PRIO+1); /* include 1 bit for delimiter */ 100structlist_headqueue[MAX_RT_PRIO]; 101 };
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
1001structsched_rt_entity { 1002structlist_headrun_list; 1003unsignedlong timeout; 1004unsignedlong watchdog_stamp; 1005unsignedint time_slice; 1006 1007structsched_rt_entity *back; 1008#ifdef CONFIG_RT_GROUP_SCHED 1009structsched_rt_entity *parent; 1010/* rq on which this entity is (to be) queued: */ 1011structrt_rq *rt_rq; 1012/* rq "owned" by this entity/group: */ 1013structrt_rq *my_q; 1014#endif 1015 };
0.2.3. pick_next_task_rt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
1323staticstruct task_struct *pick_next_task_rt(struct rq *rq) 1324 { 1325structtask_struct *p = _pick_next_task_rt(rq); 1326 1327/* The running task is never eligible for pushing */ 1328if (p) 1329 dequeue_pushable_task(rq, p); 1330 1331#ifdef CONFIG_SMP 1332/* 1333 * We detect this state here so that we can avoid taking the RQ 1334 * lock again later if there is no need to push 1335 */ 1336 rq->post_schedule = has_pushable_tasks(rq); 1337#endif 1338 1339return p; 1340 }