Skip to contentSkip to conversation

procfs: export context switch counts in /proc/*/stat

PATCH Al Boldi 1 participant 1 message Dec 21, 2006

lore
Share & tools
lore

Al Boldi

author
#0 lore raw
Quoted 20 lines · Albert Cahalan
Quoted 10 lines · David Wragg
Quoted 8 lines · Albert Cahalan
Quoted 5 lines · David Wragg

This patch (against 2.6.19/2.6.19.1) adds the four context switch values (voluntary context switches, involuntary context switches, and the same values accumulated from terminated child processes) to the end of /proc/*/stat, similarly to min_flt, maj_flt and the time used values.

Hmmm, OK, do people have a use for these values?

Quoted 8 lines

My reason for writing the patch was to track which processes are active (i.e. got scheduled to run) by polling these context switch values. The time used values are not a reliable way to detect process activity on fast machines. So for example, when sorting by %CPU, top often shows many processes using 0% CPU, despite the fact that these processes are running occasionally. If top sorted by (%CPU, context switch count delta), it might give a more useful display of which processes are active on the system.

Quoted 1 line

Oh, that'd be great.

It may be great, but it's really only a workaround. The real fix is in changing the current probed proc-timing to an inlined one.

Quoted 6 lines

The cumulative ones are still not justified though, and I fear they may be 64-bit even on i386. It turns out that an i386 procps spends much of its time doing 64-bit division to parse the damn ASCII crap. I suppose I could just skip those fields, but generating them isn't too cheap and probably I'd get stuck parsing them for some other reason -- having them separate is probably a good idea.

Agreed. It may also be advisable to add a top3 line in /proc/stat, to circumvent parsing /proc/*/stat, when only checking who is eating CPU most.

Thanks!

--
Al