Welcome to Linux Forums! With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.
Find the answer to your Linux question:
New to Linux Forums? Register here for free!
    Linux Forums > GNU Linux Zone > The Linux Kernel > scheduler

Forgot Password?
 The Linux Kernel   Compiling, theory, programming or other discussion about the linux kernel

Site Navigation
Linux Articles
Linux Forums
Linux Downloads
Linux Hosting
Free Magazines
Job Board
IRC Chat
RSS Feeds


Linux Forum Topics
Linux Forums
Your Distro
Linux Resources
GNU Linux Zone
The Community
Reply
 
Thread Tools Display Modes
Old 09-29-2009   #1 (permalink)
Just 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!
adanun is offline  


Reply With Quote
Old 10-08-2009   #2 (permalink)
Just Joined!
 
probe's Avatar
 
Join Date: Oct 2009
Location: Belgrade, Serbia
Posts: 21
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
probe is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Free Magazines
Run Your Own Web Server Using Linux & Apache - Free 191 Page Preview
Learn about everything you'll need to build and maintain your Linux servers, and to deploy Web applications to them.
subscribe
Open Source Security Myths Dispelled
Dispel the five major myths surrounding Open Source Security and gain the tools necessary to make a truly informed decision for your IT organization
subscribe
InformationWeek
InformationWeek is the only newsweekly you'll need to stay on top of the latest developments in information technology.
subscribe



All times are GMT. The time now is 11:21 AM.






© 2000 - 2009 - All Rights Reserved - Property of  MAS Media

Content Relevant URLs by vBSEO 3.3.0 RC2