1. 數(shù)據(jù)結(jié)構(gòu)
struct prio_array {
??? unsigned intnr_active; //優(yōu)先級(jí)隊(duì)列數(shù)據(jù)中task個(gè)數(shù)
??? unsignedlong bitmap[BITMAP_SIZE];
??? structlist_head queue[MAX_PRIO];
};
#define BITMAP_SIZE ((((MAX_PRIO+1+7)/8)+sizeof(long)-1)/sizeof(long))
//內(nèi)核中l(wèi)ong型占4個(gè)字節(jié),一個(gè)字節(jié)8位岖免,BITMAP_SIZE的值為5
2. 圖解
3. 隊(duì)列操作函數(shù)解析
場(chǎng)景:將任務(wù)加入到對(duì)應(yīng)優(yōu)先級(jí)隊(duì)列的尾部
static void enqueue_task(struct task_struct *p, prio_array_t *array)
{
????sched_info_queued(p);
????list_add_tail(&p->run_list, array->queue + p->prio);
????__set_bit(p->prio, array->bitmap);
????array->nr_active++;
????p->array = array;
}
場(chǎng)景:將任務(wù)從優(yōu)先級(jí)隊(duì)列中移除
static void dequeue_task(struct task_struct *p, prio_array_t *array)
{
????array->nr_active--;
????list_del(&p->run_list);
????if (list_empty(array->queue + p->prio))
????__clear_bit(p->prio, array->bitmap);
}
場(chǎng)景:將任務(wù)移動(dòng)到對(duì)應(yīng)優(yōu)先級(jí)隊(duì)列的尾部
/*
* Put task to the end of the run list without the overhead of dequeue
* followed by enqueue.
*/
static void requeue_task(struct task_struct *p, prio_array_t *array)
{
????list_move_tail(&p->run_list, array->queue + p->prio);
}
場(chǎng)景:將任務(wù)加入到對(duì)應(yīng)優(yōu)先級(jí)隊(duì)列的首部
static inline void enqueue_task_head(struct task_struct *p, prio_array_t *array)
{
????list_add(&p->run_list, array->queue + p->prio);
????__set_bit(p->prio, array->bitmap);
????array->nr_active++;
????p->array = array;
}