Results 1 to 5 of 5
I have done some searching around the internet and this site, but I haven't found a good way to count the context switches on a thread in a c++ program ...
- 06-10-2010 #1Just Joined!
- Join Date
- May 2010
- Posts
- 28
counting context switches?
I have done some searching around the internet and this site, but I haven't found a good way to count the context switches on a thread in a c++ program I am running. I need to know if it get swapped off of a CPU for correct timing.
Anyone have any idea?
- 06-10-2010 #2Linux Newbie
- Join Date
- Mar 2010
- Posts
- 121
I don't think I get what you mean. Why is this?
Does your program rely on context switches happening/not happening at a certain time? If so, there are much, much better ways of synchronising threads than counting context switches. If that is what you're trying to do, there's no way that plan will ever end well.
- 06-10-2010 #3Linux Newbie
- Join Date
- Mar 2010
- Posts
- 121
Oh yeah, I nearly forgot - if you really do need to find out how many context switches you've encountered, the proc(5) man page says /proc/[pid]/status has this information. Would be interesting to know why you need this, though.
- 06-10-2010 #4Just Joined!
- Join Date
- May 2010
- Posts
- 28
I am not sync-ing threads with it. I need to know if my thread ever gets switched off a core. I gave it HIGH_PRIORITY scheduling and FIFO policy on linux. So unless there is a realtime event that requires the core, it should get to keep it, right? But I need to make sure linux isn't taking it off that core....thus I need to see if its doing context switches.
How long does that take? I was certainly hoping for something less than an io call. A system call is bad enough, but do-able.
- 06-11-2010 #5Just Joined!
- Join Date
- May 2010
- Posts
- 28


Reply With Quote
