Commit Graph

320 Commits

Author SHA1 Message Date
cheloha 09447e1ca7 top(1): remove last vestiges of "last pid" support
millert@ removed most of the "last pid" support from top(1) in 1997.
See, e.g. top/machine.c,v1.7:

http://cvsweb.openbsd.org/src/usr.bin/top/machine.c?rev=1.7&content-type=text/x-cvsweb-markup

Let's remove the rest of it:

- Eliminate system_info.last_pid.

- Remove mpid parameter and "last pid" printing code from i_loadave().

Link: https://marc.info/?l=openbsd-tech&m=166277253606823&w=2

ok millert@
2022-09-10 16:58:51 +00:00
cheloha 2d9cf35622 top(1): display uptime with seconds, print uptime in fixed format
1. It's sometimes useful to know the system uptime with more precision
   than one minute.

So, this patch changes top(1) to print seconds of uptime in addition
to minutes, hours, and days.

2. It's *always* annoying when the information you want on a realtime
   display is not shown in the same place in a consistent format.

So, this patch also changes top(1) to always print the uptime like
this:

	up D days HH:MM:SS

This is much easier to read at a glance.  In particular, it requires
no additional thought on my part to figure out whether the machine has
been up less than one day.

Maybe of note is that these changes make top(1)'s output different
from that of uptime(1).  I don't think this matters very much.  top(1)
is a realtime display, so it isn't likely to be parsed.  uptime(1) is
a different story.

Link: https://marc.info/?l=openbsd-tech&m=160046282400892&w=2

Positive feedback from kn@.

ok gnezdo@ bluhm@ millert@
2022-08-08 16:54:09 +00:00
naddy 41ce3b17e7 man pages: add missing commas between subordinate and main clauses
jmc@ dislikes a comma before "then" in a conditional, so leave those
untouched.

ok jmc@
2022-03-31 17:27:13 +00:00
deraadt 4ec73a1227 MAXCOMLEN is no longer needed in these programs, so remove the annotation
from sys/param.h include lines, or remove the include lines entirely if
it this was the least requirement.
ok millert
2022-02-22 17:35:01 +00:00
jsg 25a24f0b58 Avoid gendered language in man pages when not referring to a specific
person. Rewrite or use singular they.

ok thfr@ sthen@ daniel@ ian@ job@ kmos@ jcs@ ratchov@ phessler@ and
others I'm likely missing on an earlier version.
feedback tj@, feedback and ok jmc@
2022-02-18 23:17:13 +00:00
jsg c5d247d835 spelling 2021-03-12 05:18:00 +00:00
lum fb477dc16d Add 't' to options in man page. ok jmc@ kn@ 2021-02-19 19:59:36 +00:00
kn d31303eb50 Add "t" to toggle the display of routing tables
Swap the WAIT column with RTABLE (and vice versa);  WAIT is wide enough to
fit RTABLE, somewhat adds additional value to STATE and seems therefore most
appropiate to hide in favour of RTABLE.

Filtering rtables with "T" does not toggle the column, just like filtering
users with "u" does not toggle between user and thread id.

Feedback jmc
OK remi
2020-08-26 16:21:28 +00:00
kn 754b6bea87 Rename rtable filter variables and simplify buffer handling
No functional change, the rename is for consistency and the buffer
handling reduces churn in an upcoming diff.
2020-08-25 07:27:34 +00:00
kn f6c6777908 Filter by routing table
"-T-0" for processes outside the default routing table, "-T3" for those in
a specific one;  same semantics as with other filters.

Manual wording and command line flag taken from pgrep(1) being the only way
to identify processes by routing table;  After netstat(1)'s recent addition
of "-R", filtering in top makes for handy tooling around rtable(4).

"looks good to me" millert
OK remi
2020-08-23 21:11:55 +00:00
kn b1ef1ce065 Add / as alias for g (grep)
Simpliy mdoc(7) markup for "n|# count" while here.

Positive manual feedback jmc
No objections millert
2020-07-26 21:59:16 +00:00
kn 75fa0b3707 Use mnemonic KERN_PROC_ALL not literal zero
No object change.
2020-07-06 16:27:59 +00:00
kn 7ee3686f31 Add missing scroll keys to help page, name default signale for kill command
The order of commands is not in sync between help page and manual, but I
refrained from reordering to avoid churn.

OK millert
2020-06-27 01:09:57 +00:00
kn 859f4dcdc2 Remove duplicate initialisation
Those are global variables are (zero) initialised as such already and
machine_init() is called only once upon startup.

OK mvs
2020-06-26 20:55:55 +00:00
kn 9602517c5b Remove unused "remaining" member in struct handle
Only ever set or decremented since import with machine.c r1.1 (1997);

While here, simplify the skip semantics behind the scroll functionality.

OK millert
2020-06-25 20:38:41 +00:00
kn 2ef6040707 Remove obsolete comment about "extra nulls"
Those were removed in r1.39 in 2004.
2020-06-24 23:56:01 +00:00
kn 6088410e3a Fix COMMAND description
There is no code anymore that puts angle brackets around swapped out
processes, machine.c r1.54 removed this in 2006.

Typo in first diff spotted by Matthew Martin,
OK jmc (who also pointed out the CVS commit)
2020-06-23 21:39:19 +00:00
kn 95d22deeeb Remove redundant NULL check
For the sake of simplicity and to reflect that the process list is always
sorted (default is "cpu"), even if not explicitly requested;  this makes it
easier to argue about the code around sort order and its selection.

OK millert
2020-06-23 19:12:47 +00:00
jmc bad1bec0fa zap trailing whitespace; 2020-01-07 13:30:43 +00:00
zhuk afe88fd5f3 Implement scrolling in top(1) using 9 and 0 keys.
Planned improvements: scroll position displaying, using arrow/pgup/pgdown keys.

okay tedu@
2020-01-06 20:05:10 +00:00
guenther 0f1976c81e Delete tests for P_THREAD that predate the existence of
KERN_PROC_SHOW_THREADS and have been rendered superfluous by it.
Similarly, some P_SYSTEM tests can be deleted or pushed to the
kernel by using KERN_PROC_ALL instead of KERN_PROC_KTHREAD.

ok visa@ mpi@
2019-12-16 19:21:16 +00:00
kn d52a3de7d1 + resets P as well
The manual has it, complete the help screen.

OK millert
2019-10-27 13:52:26 +00:00
kn 135164c7e9 Simplify threads flag handling
Instead of always passing the threads flag which decides whether other
function arguments are used or not, make callers pass those arguments or
NULL depending on the threads flag.

This reflects better how thread IDs are shown in place of user names/IDs.

OK millert
2019-10-08 20:51:03 +00:00
kn 0767cd885e Replace "boolean.h" with <stdbool.h>
Be consistent with other programs in base and unify variable usage as
follows to improve readability:

bool = (bool == No) ? Yes : No  ->  bool = !bool
if (bool == Yes)                ->  if (bool)
if (bool == No)                 ->  if (!bool)
bool = Maybe                    ->  bool = -1

OK millert
2019-10-08 07:26:59 +00:00
kn 6f80dee341 Avoid gasting around get_process_info()
get_process_info() returns a pointer to the global handle later only be
used in format_next_process();  treat this struct handle as such without
casting the pointer to caddr_t and back again.

No object change.
OK millert deraadt
2019-10-06 15:08:54 +00:00
kn b772193238 Zap intermediate structs in compare_*()
SETORDER() can assign from function arguments directly without additional
identical structs in each function.

No object change.
OK millert
2019-10-06 15:05:35 +00:00
deraadt 515e489c3d snprintf/vsnprintf return < 0 on error, rather than -1. 2019-07-03 03:24:01 +00:00
deraadt 3aaa63eb46 When system calls indicate an error they return -1, not some arbitrary
value < 0.  errno is only updated in this case.  Change all (most?)
callers of syscalls to follow this better, and let's see if this strictness
helps us in the future.
2019-06-28 13:34:58 +00:00
kn 2f895e4aec Allow reverse sort order
Prefixing the field with a dash will sort processes in reverse order.
`o -pid' will therefore list PID 1 on top.

"looks good" tedu, improvements and OK cheloha
2018-11-28 22:00:30 +00:00
cheloha d52dbbbe91 Add new KERN_CPUSTATS sysctl(2) so we can identify offline CPUs.
Because of hw.smt we need a way to determine whether a given CPU is "online"
or "offline" from userspace.  KERN_CPTIME2 is an array, and so cannot be
cleanly extended for this purpose, so add a new sysctl(2) KERN_CPUSTATS
with an extensible struct.  At the moment it's just KERN_CPTIME2 with a
flags member, but it can grow as needed.

KERN_CPUSTATS appears to have been defined by BSDi long ago, but there are
few (if any) packages in the wild still using the symbol so breakage in ports
should be near zero.  No other system inherited the symbol from BSDi, either.

Then, use the new sysctl(2) in systat(1) and top(1):

  - systat(1) draws placeholder marks ('-') instead of percentages for
    offline CPUs in the cpu view.

  - systat(1) omits offline CPU ticks when drawing the "big bar" in
    the vmstat view.  The upshot is that the bar isn't half idle when
    half your logical CPUs are disabled.

  - top(1) does not draw lines for offline CPUs; if CPUs toggle on or
    offline in interactive mode we redraw the display to expand/reduce
    space for the new/missing CPUs.  This is consistent with what some
    top(1) implementations do on Linux.

  - top(1) omits offline CPUs from the totals when CPU totals are
    combined into a single line (the '-1' flag).

Originally prompted by deraadt@.  Discussed endlessly with deraadt@,
ketennis@, and sthen@.  Tested by jmc@ and jca@.  Earlier versions also
discussed with jca@.  Earlier versions tested by jmc@, tb@, and many
others.

docs ok jmc@, kernel bits ok ketennis@, everything ok sthen@,
"Is your stuff in yet?" deraadt@
2018-11-17 23:10:07 +00:00
kn e4bc73e252 Accept numeric user IDs
This makes `top -U 0' and "u-1000" work.

Feedback and "that looks right" tedu, OK millert, manual bits and OK jmc
2018-11-02 12:46:10 +00:00
kn 967a4e50eb Merge duplicate code into helper functions
This introduces filteruser() and filterpid(), where the first one can now
easily be extended to support matching numeric UIDs. The latter one is now
used by the `highlight` command as well.

No change in behaviour or output.

Feedback and OK millert
2018-11-01 18:04:13 +00:00
cheloha 7befbc1b4c Revert KERN_CPTIME2 ENODEV changes in kernel and userspace.
ok kettenis deraadt
2018-10-05 18:56:57 +00:00
cheloha 3634178a0c KERN_CPTIME2: set ENODEV if the CPU is offline.
This lets userspace distinguish between idle CPUs and those that are
not schedulable because hw.smt=0.

A subsequent commit probably needs to add documentation for this
to sysctl.2 (and perhaps elsewhere) after the dust settles.

Also included here are changes to systat(1) and top(1) that account
for the ENODEV case and adjust behavior accordingly:

 - systat(1)'s cpu view prints placeholder marks ('-') instead of
   percentages for each state if the given CPU is offline.

 - systat(1)'s vmstat view checks for offline CPUs when computing the
   machine state total and excludes them, so the CPU usage graph
   only represents the states for online CPUs.

 - top(1) does not draw CPU rows for offline CPUs when the view is
   redrawn.  If CPUs "go offline", percentages for each state are
   replaced by placeholder marks ('-'); the view will need to be
   redrawn to remove these rows.  If CPUs "go online" the view will
   need to be redrawn to show these new CPUs.  In "combined CPU" mode,
   the count and the state totals only represent online CPUs.

Ports using KERN_CPTIME2 will need to be updated.  The changes
described above to make systat(1) and top(1) aware of the ENODEV
case *and* gracefully handle a changing HW_NCPUONLINE while the
application is running are not necessarily appropriate for each
and every port.

The changes described above are so extensive in part to demonstrate
one way a program *might* be made robust to changing CPU availability.
In particular, changing hw.smt after boot is an extremely rare event,
and this needs to be weighed when updating ports.

The logic needed to account for the KERN_CPTIME2 ENODEV case is
very roughly:

	if (sysctl(...) == -1) {
		if (errno != ENODEV) {
			/* Actual error occurred. */
		} else {
			/* CPU is offline. */
		}
	} else {
		/* CPU is online and CPU states were set by sysctl(2). */
	}

Prompted by deraadt@.  Basic idea for ENODEV from kettenis@.  Discussed at
length with kettenis@.  Additional testing by tb@.

No complaints from hackers@ after a week.

ok kettenis@, "I think you should commit [now]" deraadt@
2018-09-26 17:23:13 +00:00
millert ead5667772 Remove unused Table_size define and digits() function. 2018-09-22 17:10:28 +00:00
millert 86e032d7ea Use user_from_uid() and uid_from_user() directly. The wrappers
in username.c are now so simple there is no longer a good reason
to use them.  OK deraadt@
2018-09-22 16:50:35 +00:00
procter 3f11dd66be fix uid -> username lookup
ok deraadt@
2018-09-22 02:18:19 +00:00
krw a82320a21f Unbreak tree with 'char *' -> 'const char *' for
userid().
2018-09-16 17:37:11 +00:00
millert a0f924b8c9 Use uid_from_user(3) and gid_from_group(3) in utilities that
do repeated lookups.  OK tb@
2018-09-16 02:44:06 +00:00
millert cdc5a29bb5 Fix warnings caused by user_from_uid() and group_from_gid() now
returning const char *.
2018-09-13 15:23:32 +00:00
deraadt 4421d4c68b After "termcap" initilization is finished, top appears to not open any
files ever again, so we can re-pledge tighter.
2018-07-29 13:34:26 +00:00
bluhm def3d7a0ae Document the spinning time of the CPU in systat(1) and top(1).
from Marcus MERIGHI; OK deraadt@ jmc@
2018-07-25 17:24:14 +00:00
mpi 531d803425 Stopping counting and reporting CPU time spent spinning on a lock as
system time.

Introduce a new CP_SPIN "scheduler state" and modify userland tools
to display the % of timer a CPU spents spinning.

Based on a diff from jmatthew@, ok pirofti@, bluhm@, visa@, deraadt@
2018-05-14 12:31:21 +00:00
deraadt 5af343a9f1 glaring KNF violation 2018-01-04 17:44:20 +00:00
cheloha b50bd52298 Add the CLOCK_BOOTTIME clockid for use with clock_gettime(2)
and put it to use in userspace in lieu of the kern.boottime
sysctl.

Its absolute value is the time that has elapsed since the
system booted, i.e., the system uptime.

Use in top(1), w(1), and snmpd(8) eliminates a race with
settimeofday(2), adjtime(2), etc. inherent to deriving the
system uptime via the kern.boottime sysctl.

Product of a great deal of discussion/revision with jca@, tb@,
and guenther@.

ok tb@ jca@ guenther@ dlg@ mlarkin@ tom@
2017-12-18 05:51:53 +00:00
tedu 489ad1fb44 avoid some shadow warnings. from Brian Callahan 2017-05-30 06:01:30 +00:00
deraadt 73f7147e67 annoying whitespace die die die 2017-03-15 04:24:14 +00:00
tedu efdd1a437c as with ps, update bug to caveat and clarify 2016-09-08 16:47:47 +00:00
guenther 5bc099a9f8 Pull in <sys/time.h> for struct timespec and timeval
ok deraadt@
2016-08-27 04:07:42 +00:00
tedu e8182c463d rework realloc loop. there's no need to shrink the allocation between
calls. if we need a big space once, we'll likely need a big space again.
2016-07-28 21:45:00 +00:00