Thanks for your replay. On Fri, Jan 2, 2009 at 2:23 AM, Henrik Austad <[email protected]> wrote:
> On Tuesday 30 December 2008 23:25:39 Shyam Burkule wrote: > > Hi All, > > Hi! > > > Linux kernel make use list_head to link process descriptor. I am > > reading scheduler part of Linux kernel. There is structure *runqueue* > that > > contains list of all runnable process. The *runqueue* has pointer to > > *prio_array_t* structre that have field *queue*(array of struct > > prio_array_t) which list process according to priority. The scheduler > gets > > head_list from this queue. > > First, which version of the kernel are you working with? I am working with kernel version 2.6.27.6. > From what you ask, it > sounds like you are working with the O(1) scheduler setup. > > as Peter said, there's a individual instance of the runqueue, > (kernel/sched.c > struct rq). In this rq, you will find a cfs_rq struct (the runqueue for > normal tasks) as well as a rt_rq struct. In these runqueues are the tasks > runnable on a given CPU. > > The only place you will find prio_array, will be in the rt_rq runqueue, > which > has been renamed to rt_prio_array (as normal tasks do not use prio-array > but > red-black trees nowadays). But in UTLK I read that prio_array_t is used for both real-time and normal processes. > > > > I did not understand how scheduler gets process desciptor address > > corrosponding to list_head, which it (scheduler) gets from runqueue > list?? > > Please point me to code gthat does this translation. > > you have a macro, called this_cpu() that will return the current cpu. With > this, you can retrieve the correct runqueue, and from that, you can find > the > given runqueues for normal- and rt-tasks via the macro cpu_rq(cpu) > > so, a struct rq *r = cpu_rq(this_cpu()); would probably do the trick. You > also > have the smp_processor_id() wich returns the id of the processor > > I think the answer to your question, is that the kernel first retrieves the > appropriate CPU, then finds the runqueue for this CPU, and from the > runqueue, > find the currently executing task, as well as actual queues with tasks. > > Let me know if I misunderstood your question! :-) > Actually my question is that if we have pointer to list_head(embedded in task_struct), then how kernel gets address of corresponding task_struct. Here I just given example of scheduler, where the kernel need this operation. I traverse kernel code and for such operation kernel always comes to *container_of* micro, now I am trying to understand how this function works? /** <http://lxr.linux.no/linux+v2.6.11/include/linux/kernel.h#L236> * container_of - cast a member of a structure out to the containing structure <http://lxr.linux.no/linux+v2.6.11/include/linux/kernel.h#L237> * <http://lxr.linux.no/linux+v2.6.11/include/linux/kernel.h#L238> * @ptr: the pointer to the member. <http://lxr.linux.no/linux+v2.6.11/include/linux/kernel.h#L239> * @type: the type of the container struct this is embedded in. <http://lxr.linux.no/linux+v2.6.11/include/linux/kernel.h#L240> * @member: the name of the member within the struct. <http://lxr.linux.no/linux+v2.6.11/include/linux/kernel.h#L241> * <http://lxr.linux.no/linux+v2.6.11/include/linux/kernel.h#L242> */ #define container_of <http://lxr.linux.no/linux+v2.6.11/+code=container_of>(ptr <http://lxr.linux.no/linux+v2.6.11/+code=ptr>, type <http://lxr.linux.no/linux+v2.6.11/+code=type>, member <http://lxr.linux.no/linux+v2.6.11/+code=member>) ({ \ <http://lxr.linux.no/linux+v2.6.11/include/linux/kernel.h#L244> const typeof <http://lxr.linux.no/linux+v2.6.11/+code=typeof>( ((type <http://lxr.linux.no/linux+v2.6.11/+code=type> *)0)->member <http://lxr.linux.no/linux+v2.6.11/+code=member> ) *__mptr <http://lxr.linux.no/linux+v2.6.11/+code=__mptr> = (ptr <http://lxr.linux.no/linux+v2.6.11/+code=ptr>); \ <http://lxr.linux.no/linux+v2.6.11/include/linux/kernel.h#L245> (type <http://lxr.linux.no/linux+v2.6.11/+code=type> *)( (char *)__mptr <http://lxr.linux.no/linux+v2.6.11/+code=__mptr> - offsetof <http://lxr.linux.no/linux+v2.6.11/+code=offsetof>(type <http://lxr.linux.no/linux+v2.6.11/+code=type>,member <http://lxr.linux.no/linux+v2.6.11/+code=member>) );}) > > > Thanks > > Shyam > > -- > -> henrik > Thanks Shyam
