1

Does any body know that where CFS scheduling algorithm's data (for example content of suspend or ready queue, task duration, ...) is stored in Linux? (Is there any special file or data structure for this goal?)

Thanks.

Claudio
  • 10,614
  • 4
  • 31
  • 71
sami
  • 23
  • 8

1 Answers1

2

CFS keeps a different runqueue for each processing unit in the system (i.e., it is not a global scheduler, but rather it relies on task migration among the different runqueues). The data structure is struct cfs_rq in the kernel/sched/sched.h file.

Then, each runqueue internally keeps tasks ordered through a Red-Black Tree data structure. The implementation of this data structure is contained in the include/linux/rbtree.h file. It is a generic implementation in the sense that it is not strictly related to scheduling, and thus it can be used by any kernel component that needs to keep data sorted with this kind of data structure.

Within the kernel code, the data structure containing information about a process (or a thread) is task_struct, contained inside include/linux/sched.h. This is the main task data structure, used by all scheduling policies (i.e., SCHED_FAIR, SCHED_FIFO/SCHED_RR, SCHED_DEADLINE, etc.)

A good documentation about how CFS works is contained inside the Documentation/scheduler directory.

Community
  • 1
  • 1
Claudio
  • 10,614
  • 4
  • 31
  • 71
  • Thank you Claudio. they are quit useful But something which i'm looking for is a specific file or directory or data structure which contains the CFS's runtime data, such as queue. can you give me a clue? – sami Nov 20 '15 at 17:43
  • Check if my new answer answers your question. – Claudio Nov 23 '15 at 08:21
  • thanks a lot Claudio. it was very good. but a little detailed, i wanna ask you that is it possible that with some trick, see the content of cfs_rq or task_struct at run time? (I think that these are something which may sore in main memory during run time but i ask if there will be a trick). – sami Nov 23 '15 at 11:57
  • If your kernel has been compiled with debugging symbols, then you can inspect data structures at run-time using a debugger lik GDB (read-only) or KGDB. Have a look at http://www.elinux.org/Debugging_The_Linux_Kernel_Using_Gdb – Claudio Nov 23 '15 at 13:02