3

I am trying to print some function names and the CPU ID in which the function runs. Using linux-4.1 kernel and when I print the CPU ID its always zero. I am using a dual core board. I just want to show that some kernel function can run in other CPU also. Is there any way to switch the CPU and print the cpu id as 1. I am using armv7 board. Example:

 0)   0.073 us    |        mutex_unlock();
 3)   0.124 us    |                iov_iter_fault_in_readable();
 1)   0.105 us    |        fget_light();
 3)               |                ext3_write_begin() {
 0)   0.071 us    |        put_pid();
 3)               |                  ext3_writepage_trans_blocks() {
 3)   0.043 us    |                    journal_blocks_per_page();
 1)               |        sock_poll() {
 0)   3.126 us    |      }
 1)               |          unix_poll() {
 3)   0.390 us    |                  }
 0)   6.007 us    |    }
 3)               |                  grab_cache_page_write_begin() {
 1)               |            __pollwait() {
 3)               |                    find_lock_page() {
 0)   0.077 us    |    fput();
 3)   0.074 us    |                      find_get_page();
 1)               |              add_wait_queue() {
 1)   0.081 us    |                _raw_spin_lock_irqsave();

As we can see in first column the number changes, how can I achieve that my modifying kernel source.

arceus
  • 327
  • 4
  • 15
  • http://stackoverflow.com/questions/7476656/setting-cpu-affinity-for-linux-kernel-not-process and http://stackoverflow.com/questions/41870418/printing-cpu-number-similar-to-ftrace/41871080#41871080 might help !!! – Jeyaram Jan 27 '17 at 16:23

1 Answers1

1

Is there any way to switch the CPU

sched_setaffinity user space function uses sched_setaffinity system call.

By looking at the implementation of sched_setaffinity system call, there is a kernel function with same name used in kernel space.
http://lxr.free-electrons.com/source/kernel/sched/core.c#L4685

Here sched_setaffinity is used in kernel.
http://lxr.free-electrons.com/source/kernel/trace/trace_hwlat.c#L269

Jeyaram
  • 9,158
  • 7
  • 41
  • 63