Cannot avoid context-switches on a process launched alone on a CPU

后端 未结 3 792
南旧
南旧 2021-01-12 04:28

I am investigating how run a process on a dedicated CPU in order to avoid context-switches. On my Ubuntu, I isolated two CPUs using the kernel parameters \"isolcpus=3,7\" an

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-12 05:27

    Today, I obtained more clues regarding my problem I realized that I had to investigate deeply what was happening in the Kernel scheduler. I found these two pages:

    • Ftrace Linux Kernel Tracing
    • ftrace - Function Tracer

    I enabled scheduler tracing while my application was running like that:

    # sudo bash
    # cd /sys/kernel/debug/tracing
    # echo 1 > options/function-trace ; echo function_graph > current_tracer ; echo 1 > tracing_on ; echo 0 > tracing_max_latency ; taskset -c 7 [path-to-my-program]/TestCpuset ; echo 0 > tracing_on
    # cat trace
    

    As my program was launched on CPU 7 (taskset -c 7), I have to filter the "trace" output

    # grep " 7)" trace
    

    I can then search for transitions, from one process to another one:

    # grep " 7)" trace | grep "=>"
     ...
     7)  TestCpu-4753  =>  kworker-5866 
     7)  kworker-5866  =>  TestCpu-4753 
     7)  TestCpu-4753  =>   watchdo-26  
     7)   watchdo-26   =>  TestCpu-4753 
     7)  TestCpu-4753  =>  kworker-5866 
     7)  kworker-5866  =>  TestCpu-4753 
     7)  TestCpu-4753  =>  kworker-5866 
     7)  kworker-5866  =>  TestCpu-4753 
     7)  TestCpu-4753  =>  kworker-5866 
     7)  kworker-5866  =>  TestCpu-4753 
     ...
    

    Bingo! It seems that the context switches I am tracking are transitions to:

    • kworker
    • watchdog

    I now have to find:

    • what are exactly these processes/threads? (it seems that they are handled by the kernel)
    • Can I avoid them to run on my dedicated CPUs?

    For course, once again I would appreciate any help :-P

提交回复
热议问题