Where is run_node defined in the sched_fair.c of Linux 2.6.33?

Valentin Vidić vvidic at valentin-vidic.from.hr
Wed May 6 14:26:40 EDT 2020


On Wed, May 06, 2020 at 05:32:26PM +0530, Sreyan Chakravarty wrote:
> I am reading Robert Love's Book Linux Kernel Development(
> https://rads.stackoverflow.com/amzn/click/com/B003V4ATI0).
> 
> It uses the 2.6.33 kernel for demonstration.
> 
> I have been going through certain parts of the source and can't find out
> where is the initial definition of many things. A lot of things are just
> used, like "magic" without me finding the definition.
> 
> One example:
> 
> static struct sched_entity *__pick_next_entity(struct cfs_rq *cfs_rq)
> {
> struct rb_node *left = cfs_rq->rb_leftmost;
> 
> if (!left)
> return NULL;
> 
> return rb_entry(left, struct sched_entity, run_node);
> }

include/linux/rbtree.h:#define  rb_entry(ptr, type, member) container_of(ptr, type, member)

So rb_entry is a macro and it basically rewrites the return line
into another macro:

  return container_of(left, struct sched_entity, run_node);

And that one gives the address of the struct sched_entity that
left is a member of by subtracting the offset from the struct
start to run_node member:

struct sched_entity {       -
 ...                        |
 ...                        | offset
 ...                        |
 ...                        -
 struct rb_node run_node;   <=== left points here
 ...
}

https://stackoverflow.com/questions/15832301/understanding-container-of-macro-in-the-linux-kernel

-- 
Valentin



More information about the Kernelnewbies mailing list