LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-22-2017, 02:05 PM   #1
DavidJun
LQ Newbie
 
Registered: Sep 2017
Posts: 1

Rep: Reputation: Disabled
I don't know how to print pid and nice value of previous and next processes when context switching occurs in linux kernel.


I don't know how to print pid and nice value of previous and next processes when context switching occurs in linux kernel.

For example, I want to print as below when I enter "dmesg | grep "DAVID" | head -n 50"

[ 77.241213] [DAVID] PREV: CPU 7 pid 286 nice 120
[ 77.241214] [DAVID] NEXT: CPU 7 pid 0 nice 120
[ 77.245020] [DAVID] PREV: CPU 4 pid 0 nice 120
[ 77.245022] [DAVID] NEXT: CPU 4 pid 969 nice 120
.
.
... and so on.

Please help me.
 
Old 09-23-2017, 10:46 AM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,269

Rep: Reputation: 1314Reputation: 1314Reputation: 1314Reputation: 1314Reputation: 1314Reputation: 1314Reputation: 1314Reputation: 1314Reputation: 1314Reputation: 1314
Sounds like you would need to instrument a scheduler. Processes call yield when blocked which results in a context switch when the scheduler picks a different choice from the queue of runnable processes. If preemption is enabled, it can also happen due to timer interrupts.
 
Old 09-23-2017, 09:18 PM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,326

Rep: Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176
Where did you get the idea you could get that specific output from dmesg ?.
Instrumenting the scheduler for context switches is very expensive.
 
Old 09-27-2017, 02:33 PM   #4
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,269

Rep: Reputation: 1314Reputation: 1314Reputation: 1314Reputation: 1314Reputation: 1314Reputation: 1314Reputation: 1314Reputation: 1314Reputation: 1314Reputation: 1314
Quote:
Originally Posted by syg00 View Post
Where did you get the idea you could get that specific output from dmesg ?.
Instrumenting the scheduler for context switches is very expensive.
I think it's just a couple of lines in pick_next_task_fair:

Code:
	 if (prev != p) {
>                printk(KERN_INFO "[DAVID] PREV: CPU %u pid %d nice %d\n", prev->cpu, prev->pid, prev->prio);
>                printk(KERN_INFO "[DAVID] NEXT: CPU %u pid %d nice %d\n", p->cpu, p->pid, p->prio);
Of course, this will generate a LOT of output when log level is set to INFO, so only do that for the time needed to run the test.
 
Old 09-27-2017, 06:02 PM   #5
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,326

Rep: Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176

I was thinking of it from the other end - perf/bpf. Most people seem to want it "now", not after a rebuild. The OP has remained mute.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
context switching in linux using c programming MUHAMMAD ABID SHAHZAD Linux - Newbie 2 05-09-2016 06:24 PM
context switching in linux using c programming MUHAMMAD ABID SHAHZAD Linux - Newbie 1 05-09-2016 01:53 PM
Switching to kernel context in a multiple-CPU system kmccall Linux - Kernel 0 06-21-2010 03:55 PM
Kernel Thread Execution Context and PID ratwings Linux - Newbie 0 02-11-2005 05:06 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:29 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration