Results 1 to 2 of 2
Can someone help explain what the coding in lines 3012 and 3013 are doing in the scheduler() main function (in sched.c for linux v2.6.17.14).
3011 idx = sched_find_first_bit(array->bitmap);
3012 queue ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 09-29-2009 #1Just Joined!
- Join Date
- Sep 2009
- Posts
- 1
scheduler
Can someone help explain what the coding in lines 3012 and 3013 are doing in the scheduler() main function (in sched.c for linux v2.6.17.14).
3011 idx = sched_find_first_bit(array->bitmap);
3012 queue = array->queue + idx;
3013 next = list_entry(queue->next, task_t, run_list);
Thanks!
- 10-08-2009 #2
Ok, I still do not write kernel code, but i also have interest
in the search how it all works.
So i went to LXR / The Linux Cross Reference , selected kernel version you
mentioned and found lines of code you are talking about.
I found next:
1. First line:
idx = sched_find_first_bit(array->bitmap);
Variable array is of type prio_array_t, and prio_array_t is defined in same
file as
typedef struct prio_array prio_array_t;
Then I looked for prio_array and found this definition:
struct prio_array {
192 unsigned int nr_active;
193 unsigned long bitmap[BITMAP_SIZE];
194 struct list_head queue[MAX_PRIO];
195};
list_head is simple doubly linked list implementation. bitmaps provide an array of bits, implemented using an an array of unsigned longs. The number of valid bits in a given bitmap does _not_ need to be an exact multiple of BITS_PER_LONG. About MAX_PRIO I found this:
/*
469 * Priority of a process goes from 0..MAX_PRIO-1, valid RT
470 * priority is 0..MAX_RT_PRIO-1, and SCHED_NORMAL/SCHED_BATCH
471 * tasks are in the range MAX_RT_PRIO..MAX_PRIO-1. Priority
472 * values are inverted: lower p->prio value means higher priority.
473 *
474 * The MAX_USER_RT_PRIO value allows the actual maximum
475 * RT priority to be separate from the value exported to
476 * user-space. This allows kernel threads to set their
477 * priority to a value higher than any user task. Note:
478 * MAX_RT_PRIO must not be smaller than MAX_USER_RT_PRIO.
479 */
480
481#define MAX_USER_RT_PRIO 100
482#define MAX_RT_PRIO MAX_USER_RT_PRIO
483
484#define MAX_PRIO (MAX_RT_PRIO + 40)
So the name of the function clears what it does , sched_find_first_bit, finds first bit of bitmap array of bits in prio_array structure, and put's it in idx variable.
2. Second line
queue = array->queue + idx;
queue is defined as double linked list in this method. So this puts in queue next bit from array (this is structure prio_array that contains double linked list queue), shifted with variable idx.
3. Third line
next = list_entry(queue->next, task_t, run_list);
next is task_t, which is task_struct, defined as
typedef struct task_struct task_t;
and we know that process are described as task_struct in kernel space
"Process has a machine state represented by stacks, registers and so on. These will be saved in the process's task_struct data structure ".
so it looks like this line of code sets next process in scheduler.
Hope this helps
regards
---------------------------------------------------------
"Didn't you know, we are obsolete."
card M.Sc. in Astrophysics; Programmer
contact dragoslav.zaric.kd@gmail.com
web-site www.tech-vibe.com


Reply With Quote
