linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* What's the priority of the idle task?
@ 2018-04-03 10:24 Ferenc Wágner
  2018-04-04 14:37 ` Till Smejkal
  0 siblings, 1 reply; 3+ messages in thread
From: Ferenc Wágner @ 2018-04-03 10:24 UTC (permalink / raw)
  To: linux-kernel; +Cc: wferi

Hi,

(Please let me ask my Stackexchange question [1] here as well in the
hope of getting an answer from this board of dedicated experts.)

As explained by several (if somewhat old) articles [2,3,4], the Linux
idle task (PID=0, one per CPU) is run when there are no other tasks to
run. To get the scheduler do this, the idle task must have the lowest
priority reserved for it. That old Documentation/ftrace.txt in the
linked LWN article explicitly says that

> The prio "140" is reserved for the idle task which is the lowest
> priority thread (pid 0).

This makes sense, but under Linux 4.9

# perf record -e sched:sched_switch sleep 1
# perf script
   sleep  6526 [000] 362661.310842: sched:sched_switch: sleep:6526 [120] S ==> swapper/0:0 [120]

reports a priority of 120 for swapper/0 (in the closing bracket),
contradicting the above.

How does the Linux scheduler handle the idle task nowadays? The commits
removing the quoted text from ftrace.txt (87d80de28, 294ae4011) didn't
help.

Please Cc me on answers/comments.

Thanks,
Feri.

[1] https://unix.stackexchange.com/questions/435089/whats-the-priority-of-the-idle-task
[2] https://superuser.com/a/972581/462180
[3] https://lwn.net/Articles/290277/
[4] https://unix.stackexchange.com/questions/361245/what-does-an-idle-cpu-process-do

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: What's the priority of the idle task?
  2018-04-03 10:24 What's the priority of the idle task? Ferenc Wágner
@ 2018-04-04 14:37 ` Till Smejkal
  2018-04-09 17:45   ` Ferenc Wágner
  0 siblings, 1 reply; 3+ messages in thread
From: Till Smejkal @ 2018-04-04 14:37 UTC (permalink / raw)
  To: Ferenc Wágner; +Cc: linux-kernel

On Tue, 03 Apr 2018, Ferenc Wágner wrote:
> As explained by several (if somewhat old) articles [2,3,4], the Linux
> idle task (PID=0, one per CPU) is run when there are no other tasks to
> run. To get the scheduler do this, the idle task must have the lowest
> priority reserved for it. That old Documentation/ftrace.txt in the
> linked LWN article explicitly says that
> 
> > The prio "140" is reserved for the idle task which is the lowest
> > priority thread (pid 0).
> 
> This makes sense, but under Linux 4.9
> 
> # perf record -e sched:sched_switch sleep 1
> # perf script
>    sleep  6526 [000] 362661.310842: sched:sched_switch: sleep:6526 [120] S ==> swapper/0:0 [120]
> 
> reports a priority of 120 for swapper/0 (in the closing bracket),
> contradicting the above.
> 
> How does the Linux scheduler handle the idle task nowadays? The commits
> removing the quoted text from ftrace.txt (87d80de28, 294ae4011) didn't
> help.

The idle task has its own scheduling class that only handles the idle threads per CPU
core. This scheduling class has the lowest priority of the scheduling classes
available in the kernel. This means that it is the last one in the list of scheduling
classes that are asked at a task switch whether they have a task to schedule on the
CPU. Hence, the idle task is not managed by CFS and accordingly doesn't have any nice
value or priority (or at least it is not important nowadays). Interesting files in
the kernel source that might contain more information are kernel/sched/idle_task.c,
kernel/sched/sched.h and kernel/sched/core.c.

Regards
Till

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: What's the priority of the idle task?
  2018-04-04 14:37 ` Till Smejkal
@ 2018-04-09 17:45   ` Ferenc Wágner
  0 siblings, 0 replies; 3+ messages in thread
From: Ferenc Wágner @ 2018-04-09 17:45 UTC (permalink / raw)
  To: linux-kernel; +Cc: wferi

Till Smejkal <till.smejkal@googlemail.com> writes:

> [...] Hence, the idle task is not managed by CFS and accordingly
> doesn't have any nice value or priority (or at least it is not
> important nowadays).

Thanks for your very to-the-point answer!  I'm still disturbed by the
above statement, though, because not being managed by CFS does not imply
having no meaningful priority: RT tasks seem to have one.  Did you mean
to imply this?  Guessing not, I added your answer with code illustrations 
as https://unix.stackexchange.com/a/436575/119808.
-- 
Regards,
Feri

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-04-09 17:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-03 10:24 What's the priority of the idle task? Ferenc Wágner
2018-04-04 14:37 ` Till Smejkal
2018-04-09 17:45   ` Ferenc Wágner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).