Re: list_head and struct_task

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thanks for your replay.

On Fri, Jan 2, 2009 at 2:23 AM, Henrik Austad <henrik@xxxxxxxxx> 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?
/**
* container_of - cast a member of a structure out to the containing structure
*
* @ptr: the pointer to the member.
* @type: the type of the container struct this is embedded in.
* @member: the name of the member within the struct.
*
*/
#define container_of(ptr, type, member) ({                      \
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})

  

> Thanks
>      Shyam

--
 -> henrik


Thanks
 Shyam

[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux