Bug 129965 - [patch] ps(1): ps -lH doesn't show the proper CPU#
Summary: [patch] ps(1): ps -lH doesn't show the proper CPU#
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 7.1-PRERELEASE
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-bugs (Nobody)
Depends on:
Reported: 2008-12-27 00:20 UTC by Nikola Knežević
Modified: 2021-08-03 20:05 UTC (History)
1 user (show)

See Also:

file.diff (570 bytes, patch)
2008-12-27 00:20 UTC, Nikola Knežević
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Nikola Knežević 2008-12-27 00:20:03 UTC
ps -Hl shows 0 in the CPU# column for every thread. It should show the correct CPU#.

Fix: Patch attached with submission follows:
How-To-Repeat: observe the output of ps -axHl
Comment 1 Gavin Atkinson freebsd_committer freebsd_triage 2010-07-19 13:44:41 UTC
Responsible Changed
From-To: freebsd-bugs->gavin

I'll grab this one
Comment 2 Glen Barber freebsd_committer 2011-11-15 23:18:33 UTC
Hi Gavin,

I have a patch against HEAD that applies cleanly.  Is there any chance
this can be committed?



Glen Barber | gjb@FreeBSD.org
FreeBSD Documentation Project

Index: ps/keyword.c
--- ps/keyword.c	(revision 227541)
+++ ps/keyword.c	(working copy)
@@ -76,7 +76,7 @@
 	{"comm", "COMMAND", NULL, LJUST, ucomm, 0, CHAR, NULL, 0},
 	{"command", "COMMAND", NULL, COMM|LJUST|USER, command, 0,
 		CHAR, NULL, 0},
-	{"cpu", "CPU", NULL, 0, kvar, KOFF(ki_estcpu), UINT, "d", 0},
+	{"cpu", "CPU", NULL, 0, kvar, KOFF(ki_lastcpu), CHAR, "d", 0},
 	{"cputime", "", "time", 0, NULL, 0, CHAR, NULL, 0},
 	{"egid", "", "gid", 0, NULL, 0, CHAR, NULL, 0},
 	{"egroup", "", "group", 0, NULL, 0, CHAR, NULL, 0},
Comment 3 Eitan Adler freebsd_committer freebsd_triage 2017-12-31 07:59:36 UTC
For bugs matching the following criteria:

Status: In Progress Changed: (is less than) 2014-06-01

Reset to default assignee and clear in-progress tags.

Mail being skipped
Comment 4 Piotr Pawel Stefaniak freebsd_committer 2020-06-20 20:55:43 UTC
I don't think that the patch is correct. My main disagreement with it is the replacing of ki_estcpu with ki_lastcpu, which would render a part of the manual page definitely incorrect.

It seems to me that the intention of the keyword "cpu" really is "short-term CPU usage factor (for scheduling)" as the manual page puts it. I believe that it isn't meant to show the CPU on which the process is running.

Therefore, I think, the way forward is to add another keyword to do what you expected of the keyword "cpu". My patch calls it "cpu#" and is currently under review at https://reviews.freebsd.org/D25377
Comment 5 Piotr Pawel Stefaniak freebsd_committer 2020-06-20 23:45:49 UTC
I've changed my mind. Currently, "cpu" is based on a sched_4bsd-specific value, so I don't want to keep it. I just updated the diff review and also added more details.
Comment 6 commit-hook freebsd_committer 2020-06-27 19:09:49 UTC
A commit references this bug:

Author: pstef
Date: Sat Jun 27 19:09:34 UTC 2020
New revision: 362705
URL: https://svnweb.freebsd.org/changeset/base/362705

  ps(1): reuse keyword "cpu" to show CPU number

  This flag will now show the processor number on which a process is running.

  This change was inspired by PR129965. Initially I didn't think that the
  patch attached to it was correct -- it sacrificed ki_estcpu use in "cpu"
  for ki_lastcpu and I thought that the old functionality should be kept and
  the new (cpu#) one added to it. But I've since discovered that ki_estcpu is
  sched_4bsd-specific. What's worse, it represents the same thing as
  ki_pctcpu, except ki_pctcpu is universal -- so "%cpu" has been using it
  successfully. Therefore, I've decided to replace information based on
  ki_estcpu with information based on ki_oncpu/ki_lastcpu.

  Key parts of the code and manual changes were borrowed from top(1).

  PR:		129965
  Reported by:	Nikola Kne?evi?
  MFC after:	1 week
  Differential Revision:	https://reviews.freebsd.org/D25377