Curious
Curious

Reputation: 13

How to get number of cores a program has executed on in Linux and CPU load

I need to find out how many CPU cores a given process has executed on during a certain time e.g 1 second or so? This has to be done from a C program (or possibly C++). I know that perf presents the number of cpu-migrations.

I need to know the number of CPU core swaps and also which cores the process has used. I assume that I first have to get which threads the process executes in and then to see what cores the threads run on.

The information I get is to be used to calculate the CPU load for a process. When running in only one CPU core I know how to do and have a working solution. However, handling several CPU cores that a process consisting of several threads that run in one or several CPU cores at different times makes it harder. Is there any solution or hint to solution anyone here could point at?

Upvotes: 1

Views: 236

Answers (2)

Karthik Balaguru
Karthik Balaguru

Reputation: 7822

Try out the tool kernelshark . It provides better visual representation of multi-core system, affinity and many more features that can help in information gathering.

Upvotes: 0

Emilien
Emilien

Reputation: 2445

I don't have a definitive answer, but here is what I found. I use stress -c 1 -t 1 (runs a sqrt+loop process during one second).

I think this answers your very first question (find out how many migrations happen during the execution of your process).

$ perf stat -e migrations stress -c 1 -t 1
stress: info: [4159] dispatching hogs: 1 cpu, 0 io, 0 vm, 0 hdd
stress: info: [4159] successful run completed in 1s
 Performance counter stats for 'stress -c 1 -t 1':
                 2      migrations

Next I found an interesting tracepoint:

perf stat -e sched:sched_migrate_task stress -c 1 -t 1

and it happens that sched_migrate_task has a dest_cpu argument which I don't know how to trace.

Upvotes: 1

Related Questions