Skip to content

Conversation

@likewhatevs
Copy link
Contributor

Add nvcsw and nivcsw -- number of voluntary context switches and number of involuntary context switches to platforms supporting these. Roughly (and IIUC), voluntary context switches are when threads sleep or yield, involuntary are when threads are preempted.

I named these Voluntary and NonVoluntary context switches. I've seen both names used, not sure which is more common, but I think that is.

image

These are super useful for when working with performance and scheduler related things.

likewhatevs and others added 2 commits April 19, 2025 02:46
Add nvcsw and nivcsw -- number of voluntary context switches
and number of involuntary context switches to platforms supporting
these.
@dalance
Copy link
Owner

dalance commented Oct 15, 2025

Sorry for the late reply.
I think this PR can be merged. So could you add the description of new columns to README.md ?

Add entries to README for NonvoluntaryContextSw (nivcsw, number of
involuntary context switch) and VoluntaryContextSw (nvcsw, number of
voluntary context switch).
impl Column for NonVoluntaryContextSw {
fn add(&mut self, proc: &ProcessInfo) {
let (fmt_content, raw_content) = if let Some(ref status) = proc.curr_status {
if status.nonvoluntary_ctxt_switches.is_some()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, involuntary is what everyone calls this. Not sure why this crate has it named differently. LMK if you would like this to be renamed involuntary.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name originates from the manual page of procfs.
https://man7.org/linux/man-pages/man5/proc_pid_status.5.html

voluntary_ctxt_switches
nonvoluntary_ctxt_switches
Number of voluntary and involuntary context switches
(since Linux 2.6.23).

nonvoluntary_ctxt_switches is the name of cat /proc/[PID]/status and "involuntary" is the description for users, so I think "involuntary" is appropriate for this context.

likewhatevs and others added 2 commits October 15, 2025 08:57
Rename NonVoluntaryContextSw to InvoluntaryContextSw. This is the more
commonly used name for this metric.
@dalance
Copy link
Owner

dalance commented Oct 16, 2025

Looks good!
I'll merge this PR after passing CI.

@dalance dalance merged commit cb4c901 into dalance:master Oct 16, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants