Reputation: 127
I'm working on a kernel module that implements a driver.
When my read() file op is called, I can used current to get the current running process. But, when read() is entered, I also intend to get all the processes that are currently being executed by other cores on a multicore platform.
I can use for_each_process() to iterate each struct task_struct to see if it is TASK_RUNNING. But I know this cannot solve my problem, since TASK_RUNNING cannot give info about whether the process is being executed by CPU (it just means the corresponding process is runnable). Besides, I don't want to iterate all processes to save some overhead.
Any idea on how to solve this problem? Thank you!
Upvotes: 3
Views: 291
Reputation: 1458
There is command echo l > /proc/sysrq-trigger
, that shows active tasks on CPU ( https://en.wikipedia.org/wiki/Magic_SysRq_key ). You can send l
from your read()
function
Or you can try to write your own dump function. That's how it works in current linux kernel:
sysrq_handle_showallcpus
( https://elixir.bootlin.com/linux/v5.0.8/source/drivers/tty/sysrq.c#L234 ) =>
trigger_all_cpu_backtrace
( https://elixir.bootlin.com/linux/v5.0.8/source/include/linux/nmi.h#L144 ) =>
arch_trigger_cpumask_backtrace
( arch dependent )
Upvotes: 1