打印类似于ftrace的CPU编号 [英] Printing CPU number similar to ftrace

查看:120
本文介绍了打印类似于ftrace的CPU编号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要打印正在执行当前进程或功能的CPU编号,类似于ftrace,如下所示:

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

我如何获得该价值?我猜想它在start_kernel函数的某个函数中存在.我们可以打印它的值吗?我正在使用linux-4.1内核.

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.

推荐答案

要在内核中打印当前的CPU,请使用

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);

如果CPU字段不可用,也可以使用

smp_processor_id().

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

这篇关于打印类似于ftrace的CPU编号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆