All of lore.kernel.org
 help / color / mirror / Atom feed
* How to measure time spent in context switch
@ 2012-07-16 19:28 Manavendra Nath Manav
  2012-07-16 19:50 ` Victor Rodriguez
  2012-07-17  4:43 ` Mulyadi Santosa
  0 siblings, 2 replies; 5+ messages in thread
From: Manavendra Nath Manav @ 2012-07-16 19:28 UTC (permalink / raw)
  To: kernelnewbies

How to measure time spent in context switch in Linux i.e. the time the
application stays suspended while the kernel is doing something else. I
don't want to use any profiling tools. What approach should I take to write
my own C code, which can also run as kernel module if required, to measure
time spent accurately. Will it also require to modify the scheduler code?
Does /proc gives any statistics in this regard?

Ref:
http://stackoverflow.com/questions/2368384/write-a-c-program-to-measure-time-spent-in-context-switch-in-linux-os

--
Manavendra Nath Manav
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20120717/bee032ab/attachment.html 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* How to measure time spent in context switch
  2012-07-16 19:28 How to measure time spent in context switch Manavendra Nath Manav
@ 2012-07-16 19:50 ` Victor Rodriguez
  2012-07-16 20:09   ` Manavendra Nath Manav
  2012-07-17  4:43 ` Mulyadi Santosa
  1 sibling, 1 reply; 5+ messages in thread
From: Victor Rodriguez @ 2012-07-16 19:50 UTC (permalink / raw)
  To: kernelnewbies

Hi Manavendra

Have you think in a driver that you can call when the context switch
happen? If this can be detected (more investigation on this area is
required). If that is possible we can create the driver to measure the
time according to the interruption.

Thanks a lot and regards

Victor Rodriguez



On Mon, Jul 16, 2012 at 2:28 PM, Manavendra Nath Manav
<mnm.kernel@gmail.com> wrote:
> How to measure time spent in context switch in Linux i.e. the time the
> application stays suspended while the kernel is doing something else. I
> don't want to use any profiling tools. What approach should I take to write
> my own C code, which can also run as kernel module if required, to measure
> time spent accurately. Will it also require to modify the scheduler code?
> Does /proc gives any statistics in this regard?
>
> Ref:
> http://stackoverflow.com/questions/2368384/write-a-c-program-to-measure-time-spent-in-context-switch-in-linux-os
>
> --
> Manavendra Nath Manav
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* How to measure time spent in context switch
  2012-07-16 19:50 ` Victor Rodriguez
@ 2012-07-16 20:09   ` Manavendra Nath Manav
  2012-07-17  4:46     ` Mulyadi Santosa
  0 siblings, 1 reply; 5+ messages in thread
From: Manavendra Nath Manav @ 2012-07-16 20:09 UTC (permalink / raw)
  To: kernelnewbies

On Tue, Jul 17, 2012 at 1:20 AM, Victor Rodriguez <vm.rod25@gmail.com> wrote:
>
> Hi Manavendra
>
> Have you think in a driver that you can call when the context switch
> happen? If this can be detected (more investigation on this area is
> required). If that is possible we can create the driver to measure the
> time according to the interruption.
>
> Thanks a lot and regards
>
> Victor Rodriguez
>
>
>
> On Mon, Jul 16, 2012 at 2:28 PM, Manavendra Nath Manav
> <mnm.kernel@gmail.com> wrote:
> > How to measure time spent in context switch in Linux i.e. the time the
> > application stays suspended while the kernel is doing something else. I
> > don't want to use any profiling tools. What approach should I take to write
> > my own C code, which can also run as kernel module if required, to measure
> > time spent accurately. Will it also require to modify the scheduler code?
> > Does /proc gives any statistics in this regard?
> >
> > Ref:
> > http://stackoverflow.com/questions/2368384/write-a-c-program-to-measure-time-spent-in-context-switch-in-linux-os
> >
> > --
> > Manavendra Nath Manav
> > _______________________________________________

Hi Victor

I was thinking something in these terms:
1) Process is executing a non-critical section like a bottom-half.
2) At Nth line of code, I will measure the timestamp.
3) At (N+1)th line of code, I will voluntarily call schedule() to do
context switch.
4) At (N+2)th, I will measure the timestamp, and calculate the time difference.

Although the above procedure will measure context switch time
statically and not dynamically, it can give a fair idea but for
multi-core processors this measurement will heavily deviate from
accuracy. If we can set scheduler() process affinity to one single
core, will it affect the measurements and predictability of context
switches?

--
Manavendra Nath Manav

^ permalink raw reply	[flat|nested] 5+ messages in thread

* How to measure time spent in context switch
  2012-07-16 19:28 How to measure time spent in context switch Manavendra Nath Manav
  2012-07-16 19:50 ` Victor Rodriguez
@ 2012-07-17  4:43 ` Mulyadi Santosa
  1 sibling, 0 replies; 5+ messages in thread
From: Mulyadi Santosa @ 2012-07-17  4:43 UTC (permalink / raw)
  To: kernelnewbies

Hi...

On Tue, Jul 17, 2012 at 2:28 AM, Manavendra Nath Manav
<mnm.kernel@gmail.com> wrote:
> How to measure time spent in context switch in Linux i.e. the time the
> application stays suspended while the kernel is doing something else. I
> don't want to use any profiling tools. What approach should I take to write
> my own C code, which can also run as kernel module if required, to measure
> time spent accurately. Will it also require to modify the scheduler code?
> Does /proc gives any statistics in this regard?

IMHO, you need to mimic how lmbench does it. And AFAIK too, what you
are going to do is very much what lmbench does. But please check their
code for better understanding.

-- 
regards,

Mulyadi Santosa
Freelance Linux trainer and consultant

blog: the-hydra.blogspot.com
training: mulyaditraining.blogspot.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

* How to measure time spent in context switch
  2012-07-16 20:09   ` Manavendra Nath Manav
@ 2012-07-17  4:46     ` Mulyadi Santosa
  0 siblings, 0 replies; 5+ messages in thread
From: Mulyadi Santosa @ 2012-07-17  4:46 UTC (permalink / raw)
  To: kernelnewbies

Hi... :)

Sorry for jumping in...

On Tue, Jul 17, 2012 at 3:09 AM, Manavendra Nath Manav
<mnm.kernel@gmail.com> wrote:
......
>If we can set scheduler() process affinity to one single
> core, will it affect the measurements and predictability of context
> switches?

I think it will affect, up to some unknown degree. On inter processor
scheduling, there would happen cache remote invalidation and process
task_struct transfer (IIRC process descripter is per cpu).

-- 
regards,

Mulyadi Santosa
Freelance Linux trainer and consultant

blog: the-hydra.blogspot.com
training: mulyaditraining.blogspot.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-07-17  4:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-16 19:28 How to measure time spent in context switch Manavendra Nath Manav
2012-07-16 19:50 ` Victor Rodriguez
2012-07-16 20:09   ` Manavendra Nath Manav
2012-07-17  4:46     ` Mulyadi Santosa
2012-07-17  4:43 ` Mulyadi Santosa

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.