Printing CPU number similar to ftrace

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 18:44:31

问题


I want to print CPU number on which the current process or function is executing similar to ftrace like this:

 TASK-PID   CPU#      TIMESTAMP  FUNCTION
    | |       |          |         |
<idle>-0     [002]  23636.756054: ttwu_do_activate.constprop.89 <-try_to_wake_up
<idle>-0     [002]  23636.756054: activate_task <-ttwu_do_activate.constprop.89
<idle>-0     [002]  23636.756055: enqueue_task <-activate_task

How do I get that value? I suppose its there in some function of start_kernel function. Can we print its value? I am using linux-4.1 kernel.


回答1:


For printing current cpu in kernel, the cpu field of task_struct can be used. Note that the kernel configuration CONFIG_THREAD_INFO_IN_TASK should be enabled. This will work for 4.9 kernel.

printk("My current cpu is %d\n", current->cpu);

smp_processor_id() also can be used if cpu field is not available.



来源:https://stackoverflow.com/questions/41870418/printing-cpu-number-similar-to-ftrace

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