verifying where 'kworker/n:n' (in ps -aux) is invoked from

三世轮回 提交于 2021-01-29 19:15:49

问题


In the result of 'ps -aux', I couldn't find how to verify that 'kworker/...' are created from and what module/functions are related to it.

Please let me know how I find out kworkers are from with pid or else.

I've try to check files in /proc, nothing is shown about this.

$ ps -aux | grep kworker
root        15  0.0  0.0      0     0 ?        S    Aug12   0:00 [kworker/1:0]
root        16  0.0  0.0      0     0 ?        S<   Aug12   0:00 [kworker/1:0H]
root        85  0.0  0.0      0     0 ?        S<   Aug12   0:09 [kworker/0:1H]
root      3562  0.0  0.0      0     0 ?        S<   Aug12   0:00 [kworker/0:2H]
root      5578  0.0  0.0      0     0 ?        S    11:13   0:01 [kworker/0:0]
root      5579  0.0  0.0      0     0 ?        S    11:13   0:00 [kworker/u4:1]
root      8789  0.1  0.0      0     0 ?        S    12:19   0:10 [kworker/0:2]
root     30236  0.0  0.0      0     0 ?        S    08:39   0:01 [kworker/u4:0]

回答1:


A good solution for these kinds of problems that I'm familiar with is to use the perf tool (It's not always enabled by default and you may need to install perf on your device).

Step 1: Set perf to record workqueue events:

perf record -e 'workqueue:*' -ag -T

Step 2: Run it as long as you think you need to catch the event (10 seconds should be ok if this event is frequent enough, but you can let it run longer, depending on the available free space you have left on your device) and then stop it with Ctrl + C.

Step 3: Print the captured events (on Linux versions < 4.1 I think it should be -f and not -F):

perf script -F comm,pid,tid,time,event,trace

This will display something like this: 

      task-name    pid/tid     timestamp    event 
------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
    turtle        9201/9201   1473.339166:  workqueue:workqueue_queue_work:    work struct=0xef20d4c4 function=pm_runtime_work workqueue=0xef1cb600 req_cpu=8 cpu=1
    turtle        9201/9201   1473.339176:  workqueue:workqueue_activate_work: work struct 0xef20d4c4
    kworker/0:3  24223/24223  1473.339221:  workqueue:workqueue_execute_start: work struct 0xef20d4c4: function pm_runtime_work
    kworker/0:3  24223/24223  1473.339248:  workqueue:workqueue_execute_end:   work struct 0xef20d4c4

Step 4: Analyzing the table above:

In the first row, a task named turtle (pid 9201) is pushing the work pm_runtime_work to the workqueue. In the third row, we can see that the kworker/0:3 (pid 24223) is executing that work.

Summary: Now back to your questions, we see that kworker/0:3 has been requested by turtle task to run the pm_runtime_work function. Now, if you want to dig further, you'll have step into the code and see what the pm_runtime_work function does. Good luck !!!



来源:https://stackoverflow.com/questions/58161086/verifying-where-kworker-nn-in-ps-aux-is-invoked-from

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!