Skip to contentSkip to conversation

sched: current instead rq->current

DISCUSSION Colin Vidal 2 participants 3 messages Aug 15, 2016 – Aug 18, 2016

lore
Share & tools
lore
#0 lore raw

Hello,

At the beginning of __schedule (kernel/sched/core.c), the current task is get with rq->curr. I try to to understand why not directly using current instead?

Since a runqueue is specific to a CPU, it dosen't make sense to get the the current task of another CPU's runqueue. Yes?

I try the following of Linus's master branch

-       int cpu;

-       cpu = smp_processor_id();
-       rq = cpu_rq(cpu);
-       prev = rq->curr;
+       rq = cpu_rq(smp_processor_id());
+       prev = current;

and it seems to work (only tested on x86-64), but... To simple?

Thanks!

Colin

#1 lore raw
Quoted 21 lines · Colin Vidal

Hello,

At the beginning of __schedule (kernel/sched/core.c), the current task
is get with rq->curr. I try to to understand why not directly using current instead?

Since a runqueue is specific to a CPU, it dosen't make sense to get the
the current task of another CPU's runqueue. Yes?

I try the following of Linus's master branch

-       int cpu;

-       cpu = smp_processor_id();
-       rq = cpu_rq(cpu);
-       prev = rq->curr;
+       rq = cpu_rq(smp_processor_id());
+       prev = current;

Quoted 5 lines

and it seems to work (only tested on x86-64), but... To simple?

Thanks!

Colin

I realize that I have forgotten to add scheduler subsystem in CC... So I do it now. Sorry for double post.

Thanks

Colin

#2 lore raw
Quoted 16 lines · Colin Vidal
Quoted 15 lines · Colin Vidal

Hello,

At the beginning of __schedule (kernel/sched/core.c), the current task
is get with rq->curr. I try to to understand why not directly using current instead?

-       int cpu;

-       cpu = smp_processor_id();
-       rq = cpu_rq(cpu);
-       prev = rq->curr;
+       rq = cpu_rq(smp_processor_id());
+       prev = current;

Quoted 1 line
Quoted 1 line

and it seems to work (only tested on x86-64), but... To simple?

its more expensive, rq->curr is a simple dereference (and we need that cacheline anyway), while current is a weird macro that expands to potentially a lot of code, depending on the arch.