OpenBSD CVS

CVS log for src/usr.bin/top/machine.c


[BACK] Up to [local] / src / usr.bin / top

Request diff between arbitrary revisions


Default branch: MAIN


Revision 1.113 / (download) - annotate - [select for diffs], Sat Jan 7 05:24:59 2023 UTC (16 months, 1 week ago) by guenther
Branch: MAIN
CVS Tags: OPENBSD_7_5_BASE, OPENBSD_7_5, OPENBSD_7_4_BASE, OPENBSD_7_4, OPENBSD_7_3_BASE, OPENBSD_7_3, HEAD
Changes since 1.112: +20 -17 lines
Diff to previous 1.112 (colored)

Add {get,set}thrname(2) for putting thread names in the kernel and
exposed in a new field returned by sysctl(KERN_PROC).  Update
pthread_{get,set}_name_np(3) to use the syscalls.  Show them, when
set, in ps -H and top -H output.

libc and libpthread minor bumps

ok mpi@, mvs@, deraadt@

Revision 1.112 / (download) - annotate - [select for diffs], Sat Sep 10 16:58:51 2022 UTC (20 months, 1 week ago) by cheloha
Branch: MAIN
CVS Tags: OPENBSD_7_2_BASE, OPENBSD_7_2
Changes since 1.111: +1 -2 lines
Diff to previous 1.111 (colored)

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@

Revision 1.111 / (download) - annotate - [select for diffs], Tue Feb 22 17:35:01 2022 UTC (2 years, 2 months ago) by deraadt
Branch: MAIN
CVS Tags: OPENBSD_7_1_BASE, OPENBSD_7_1
Changes since 1.110: +2 -2 lines
Diff to previous 1.110 (colored)

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

Revision 1.110 / (download) - annotate - [select for diffs], Wed Aug 26 16:21:28 2020 UTC (3 years, 8 months ago) by kn
Branch: MAIN
CVS Tags: OPENBSD_7_0_BASE, OPENBSD_7_0, OPENBSD_6_9_BASE, OPENBSD_6_9, OPENBSD_6_8_BASE, OPENBSD_6_8
Changes since 1.109: +18 -14 lines
Diff to previous 1.109 (colored)

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

Revision 1.109 / (download) - annotate - [select for diffs], Tue Aug 25 07:27:34 2020 UTC (3 years, 8 months ago) by kn
Branch: MAIN
Changes since 1.108: +13 -15 lines
Diff to previous 1.108 (colored)

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.

Revision 1.108 / (download) - annotate - [select for diffs], Sun Aug 23 21:11:55 2020 UTC (3 years, 8 months ago) by kn
Branch: MAIN
Changes since 1.107: +6 -2 lines
Diff to previous 1.107 (colored)

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

Revision 1.107 / (download) - annotate - [select for diffs], Mon Jul 6 16:27:59 2020 UTC (3 years, 10 months ago) by kn
Branch: MAIN
Changes since 1.106: +3 -2 lines
Diff to previous 1.106 (colored)

Use mnemonic KERN_PROC_ALL not literal zero

No object change.

Revision 1.106 / (download) - annotate - [select for diffs], Fri Jun 26 20:55:55 2020 UTC (3 years, 10 months ago) by kn
Branch: MAIN
Changes since 1.105: +1 -6 lines
Diff to previous 1.105 (colored)

Remove duplicate initialisation

Those are global variables are (zero) initialised as such already and
machine_init() is called only once upon startup.

OK mvs

Revision 1.105 / (download) - annotate - [select for diffs], Thu Jun 25 20:38:41 2020 UTC (3 years, 10 months ago) by kn
Branch: MAIN
Changes since 1.104: +3 -8 lines
Diff to previous 1.104 (colored)

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

Revision 1.104 / (download) - annotate - [select for diffs], Wed Jun 24 23:56:01 2020 UTC (3 years, 10 months ago) by kn
Branch: MAIN
Changes since 1.103: +1 -6 lines
Diff to previous 1.103 (colored)

Remove obsolete comment about "extra nulls"

Those were removed in r1.39 in 2004.

Revision 1.103 / (download) - annotate - [select for diffs], Tue Jun 23 19:12:47 2020 UTC (3 years, 10 months ago) by kn
Branch: MAIN
Changes since 1.102: +2 -5 lines
Diff to previous 1.102 (colored)

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

Revision 1.102 / (download) - annotate - [select for diffs], Mon Jan 6 20:05:10 2020 UTC (4 years, 4 months ago) by zhuk
Branch: MAIN
CVS Tags: OPENBSD_6_7_BASE, OPENBSD_6_7
Changes since 1.101: +9 -1 lines
Diff to previous 1.101 (colored)

Implement scrolling in top(1) using 9 and 0 keys.

Planned improvements: scroll position displaying, using arrow/pgup/pgdown keys.

okay tedu@

Revision 1.101 / (download) - annotate - [select for diffs], Mon Dec 16 19:21:17 2019 UTC (4 years, 5 months ago) by guenther
Branch: MAIN
Changes since 1.100: +16 -12 lines
Diff to previous 1.100 (colored)

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@

Revision 1.100 / (download) - annotate - [select for diffs], Tue Oct 8 20:51:03 2019 UTC (4 years, 7 months ago) by kn
Branch: MAIN
CVS Tags: OPENBSD_6_6_BASE, OPENBSD_6_6
Changes since 1.99: +5 -8 lines
Diff to previous 1.99 (colored)

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

Revision 1.99 / (download) - annotate - [select for diffs], Sun Oct 6 15:08:54 2019 UTC (4 years, 7 months ago) by kn
Branch: MAIN
Changes since 1.98: +6 -8 lines
Diff to previous 1.98 (colored)

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

Revision 1.98 / (download) - annotate - [select for diffs], Sun Oct 6 15:05:35 2019 UTC (4 years, 7 months ago) by kn
Branch: MAIN
Changes since 1.97: +5 -19 lines
Diff to previous 1.97 (colored)

Zap intermediate structs in compare_*()

SETORDER() can assign from function arguments directly without additional
identical structs in each function.

No object change.
OK millert

Revision 1.97 / (download) - annotate - [select for diffs], Fri Jun 28 13:35:05 2019 UTC (4 years, 10 months ago) by deraadt
Branch: MAIN
Changes since 1.96: +7 -7 lines
Diff to previous 1.96 (colored)

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.

Revision 1.96 / (download) - annotate - [select for diffs], Wed Nov 28 22:00:30 2018 UTC (5 years, 5 months ago) by kn
Branch: MAIN
CVS Tags: OPENBSD_6_5_BASE, OPENBSD_6_5
Changes since 1.95: +21 -22 lines
Diff to previous 1.95 (colored)

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

Revision 1.95 / (download) - annotate - [select for diffs], Sat Nov 17 23:10:08 2018 UTC (5 years, 6 months ago) by cheloha
Branch: MAIN
Changes since 1.94: +42 -41 lines
Diff to previous 1.94 (colored)

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@

Revision 1.94 / (download) - annotate - [select for diffs], Fri Oct 5 18:56:57 2018 UTC (5 years, 7 months ago) by cheloha
Branch: MAIN
CVS Tags: OPENBSD_6_4_BASE, OPENBSD_6_4
Changes since 1.93: +23 -34 lines
Diff to previous 1.93 (colored)

Revert KERN_CPTIME2 ENODEV changes in kernel and userspace.

ok kettenis deraadt

Revision 1.93 / (download) - annotate - [select for diffs], Wed Sep 26 17:23:13 2018 UTC (5 years, 7 months ago) by cheloha
Branch: MAIN
Changes since 1.92: +35 -24 lines
Diff to previous 1.92 (colored)

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@

Revision 1.92 / (download) - annotate - [select for diffs], Sat Sep 22 16:50:35 2018 UTC (5 years, 7 months ago) by millert
Branch: MAIN
Changes since 1.91: +4 -4 lines
Diff to previous 1.91 (colored)

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@

Revision 1.91 / (download) - annotate - [select for diffs], Thu Sep 13 15:23:32 2018 UTC (5 years, 8 months ago) by millert
Branch: MAIN
Changes since 1.90: +2 -2 lines
Diff to previous 1.90 (colored)

Fix warnings caused by user_from_uid() and group_from_gid() now
returning const char *.

Revision 1.90 / (download) - annotate - [select for diffs], Mon May 14 12:31:21 2018 UTC (6 years ago) by mpi
Branch: MAIN
Changes since 1.89: +2 -2 lines
Diff to previous 1.89 (colored)

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@

Revision 1.89 / (download) - annotate - [select for diffs], Tue May 30 06:01:30 2017 UTC (6 years, 11 months ago) by tedu
Branch: MAIN
CVS Tags: OPENBSD_6_3_BASE, OPENBSD_6_3, OPENBSD_6_2_BASE, OPENBSD_6_2
Changes since 1.88: +7 -7 lines
Diff to previous 1.88 (colored)

avoid some shadow warnings. from Brian Callahan

Revision 1.88 / (download) - annotate - [select for diffs], Wed Mar 15 04:24:14 2017 UTC (7 years, 2 months ago) by deraadt
Branch: MAIN
CVS Tags: OPENBSD_6_1_BASE, OPENBSD_6_1
Changes since 1.87: +8 -8 lines
Diff to previous 1.87 (colored)

annoying whitespace die die die

Revision 1.87 / (download) - annotate - [select for diffs], Thu Jul 28 21:45:00 2016 UTC (7 years, 9 months ago) by tedu
Branch: MAIN
Changes since 1.86: +15 -10 lines
Diff to previous 1.86 (colored)

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.

Revision 1.86 / (download) - annotate - [select for diffs], Wed May 11 08:11:27 2016 UTC (8 years ago) by edd
Branch: MAIN
CVS Tags: OPENBSD_6_0_BASE, OPENBSD_6_0
Changes since 1.85: +65 -20 lines
Diff to previous 1.85 (colored)

Allow top(1) to filter process args if they are being displayed.

OK tedu@, deraadt@, and with input from Michal Mazurek.

Thanks

Revision 1.85 / (download) - annotate - [select for diffs], Thu Aug 20 22:32:42 2015 UTC (8 years, 9 months ago) by deraadt
Branch: MAIN
CVS Tags: OPENBSD_5_9_BASE, OPENBSD_5_9
Changes since 1.84: +3 -3 lines
Diff to previous 1.84 (colored)

Do not cast result of malloc/calloc/realloc* if stdlib.h is in scope
ok krw millert

Revision 1.84 / (download) - annotate - [select for diffs], Wed May 6 07:53:29 2015 UTC (9 years ago) by mpi
Branch: MAIN
CVS Tags: OPENBSD_5_8_BASE, OPENBSD_5_8
Changes since 1.83: +19 -7 lines
Diff to previous 1.83 (colored)

Display thread IDs instead of the name of the process's owner when "-H"
is used.

The rationnal is that when you're looking at threads you're generally
already filtereing by PID and this allow you to see which thread is a
pig.

Written some time ago with mikeb@

ok sthen@, krw@, guenther@

Revision 1.83 / (download) - annotate - [select for diffs], Mon Jan 19 18:01:13 2015 UTC (9 years, 4 months ago) by millert
Branch: MAIN
CVS Tags: OPENBSD_5_7_BASE, OPENBSD_5_7
Changes since 1.82: +3 -12 lines
Diff to previous 1.82 (colored)

Kill loadavg.h and just use the fscale value directly.
There's no need for crazy casts of p_pctcpu in ORDERKEY_PCTCPU
since kinfo_proc exports it as uint32_t.  OK deraadt@

Revision 1.82 / (download) - annotate - [select for diffs], Mon Jan 19 01:53:18 2015 UTC (9 years, 4 months ago) by deraadt
Branch: MAIN
Changes since 1.81: +16 -1 lines
Diff to previous 1.81 (colored)

like in ps(1), fetch the FSCALE value using sysctl rather than using
the header version
ok guenther

Revision 1.81 / (download) - annotate - [select for diffs], Fri Jan 16 06:40:13 2015 UTC (9 years, 4 months ago) by deraadt
Branch: MAIN
Changes since 1.80: +3 -2 lines
Diff to previous 1.80 (colored)

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible.  Annotate <sys/param.h> lines with their current reasons.  Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc.  Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution.  These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)

Revision 1.80 / (download) - annotate - [select for diffs], Wed Sep 17 01:56:54 2014 UTC (9 years, 8 months ago) by dlg
Branch: MAIN
Changes since 1.79: +18 -6 lines
Diff to previous 1.79 (colored)

if there are more than 8 cpus, default to combined cpu stats (like
you passed -1 on the command line).

ok kettenis@ tedu@

Revision 1.79 / (download) - annotate - [select for diffs], Mon Sep 15 19:08:21 2014 UTC (9 years, 8 months ago) by miod
Branch: MAIN
Changes since 1.78: +2 -2 lines
Diff to previous 1.78 (colored)

Remove non-standard <sys/dkstat.h> header. It has not contained anything
related to disk stastics for almost 17 years, and the remaining
userland-visible defines duplicate those found in <sys/sched.h>.

Move the remaining _KERNEL defines to <sys/tty.h> where they belong, and
update all users to cope with this.

ok kettenis@

Revision 1.78 / (download) - annotate - [select for diffs], Fri Jul 4 05:58:31 2014 UTC (9 years, 10 months ago) by guenther
Branch: MAIN
CVS Tags: OPENBSD_5_6_BASE, OPENBSD_5_6
Changes since 1.77: +2 -2 lines
Diff to previous 1.77 (colored)

Track whether a process is a zombie or not yet fully built via flags
PS_{ZOMBIE,EMBRYO} on the process instead of peeking into the process's
thread data.  This eliminates the need for the thread-level SDEAD state.

Change kvm_getprocs() (both the sysctl() and kvm backends) to report the
"most active" scheduler state for the process's threads.

tweaks kettenis@
feedback and ok matthew@

Revision 1.77 / (download) - annotate - [select for diffs], Tue Apr 8 14:04:11 2014 UTC (10 years, 1 month ago) by mpi
Branch: MAIN
Changes since 1.76: +9 -9 lines
Diff to previous 1.76 (colored)

Use VM_UVMEXP instead of VM_METER for memory usages and directly
include <sys/vmmeter.h> where it is needed instead of relying on
it being included by <uvm/uvm_extern.h>.

miod@ likes it, ok guenther@

Revision 1.76 / (download) - annotate - [select for diffs], Sat Mar 23 21:12:32 2013 UTC (11 years, 1 month ago) by tedu
Branch: MAIN
CVS Tags: OPENBSD_5_5_BASE, OPENBSD_5_5, OPENBSD_5_4_BASE, OPENBSD_5_4
Changes since 1.75: +5 -11 lines
Diff to previous 1.75 (colored)

wchan is no longer exposed, just check if wmesg is not empty.
(wmesg hasn't itself been a pointer since conversion to kinfo_proc.)
noticed by sthen.
ok deraadt jsing millert sthen

Revision 1.75 / (download) - annotate - [select for diffs], Tue Dec 18 21:28:45 2012 UTC (11 years, 5 months ago) by millert
Branch: MAIN
CVS Tags: OPENBSD_5_3_BASE, OPENBSD_5_3
Changes since 1.74: +7 -5 lines
Diff to previous 1.74 (colored)

We no longer use struct eproc for kinfo_proc in sysctl.h so there
is no direct need for sys/proc.h or sys/resource.h.  Some consumers
of kinfo_proc need these for the proc flags and rlimit defines like
RLIM_INF so add the appropriate includes to them.
OK deraadt@ sthen@

Revision 1.74 / (download) - annotate - [select for diffs], Mon Jul 9 22:41:45 2012 UTC (11 years, 10 months ago) by deraadt
Branch: MAIN
CVS Tags: OPENBSD_5_2_BASE, OPENBSD_5_2
Changes since 1.73: +2 -2 lines
Diff to previous 1.73 (colored)

According to miod, KERNBASE used as a userland symbol should die
in a fire.  Start by removing the definitions, before we clean the
headers later.

Revision 1.73 / (download) - annotate - [select for diffs], Tue Jun 5 18:52:53 2012 UTC (11 years, 11 months ago) by brynet
Branch: MAIN
Changes since 1.72: +4 -1 lines
Diff to previous 1.72 (colored)

Add support for hiding a user's processes in top.

feedback & ok lum@

Revision 1.72 / (download) - annotate - [select for diffs], Sat Apr 21 03:14:50 2012 UTC (12 years, 1 month ago) by guenther
Branch: MAIN
Changes since 1.71: +1 -3 lines
Diff to previous 1.71 (colored)

Remove a check made superfluous by the KERN_PROC_SHOW_THREADS flag.
This lets new binaries work (at least w/o the -H option) with old kernels.

ok pirofti@ deraadt@

Revision 1.71 / (download) - annotate - [select for diffs], Tue Apr 17 23:17:53 2012 UTC (12 years, 1 month ago) by pirofti
Branch: MAIN
Changes since 1.70: +6 -2 lines
Diff to previous 1.70 (colored)

Make it optional for kvm_getprocs() (and related sysctl) to return
thread information.

Add a KERN_PROC_SHOW_THREADS flag that has to be set in order to get the
thread info and make it off by default. This creates backwards compatibility
for applications that relied on a given size/number of items to be returned.

Modify ps(1) and top(1) accordingly.

Okay guenther@.

Revision 1.70 / (download) - annotate - [select for diffs], Thu Apr 12 14:59:19 2012 UTC (12 years, 1 month ago) by pirofti
Branch: MAIN
Changes since 1.69: +5 -1 lines
Diff to previous 1.69 (colored)

Add per thread accounting, mainly for usage & friends.

This expands the already bloated FILL_KPROC macro to take an extra
parameter that indicates if the callee is a thread or a process.

The userland bits are adjusted accordingly and ps(1) and top(1) now
display per thread usage times when -H is used.

Also pkill(1) had to be adjusted so that duplicates don't pop up.

libkvm does basically the same thing as the kernel bits.

Okay guenther@.

Revision 1.69 / (download) - annotate - [select for diffs], Tue Jul 12 14:57:53 2011 UTC (12 years, 10 months ago) by tedu
Branch: MAIN
CVS Tags: OPENBSD_5_1_BASE, OPENBSD_5_1, OPENBSD_5_0_BASE, OPENBSD_5_0
Changes since 1.68: +18 -7 lines
Diff to previous 1.68 (colored)

print out the amount of memory used for cache.  ok otto

Revision 1.68 / (download) - annotate - [select for diffs], Sun Apr 10 03:20:59 2011 UTC (13 years, 1 month ago) by guenther
Branch: MAIN
Changes since 1.67: +42 -42 lines
Diff to previous 1.67 (colored)

Switch back from KERN_PROC2/kinfo_proc2 to KERN_PROC/kinfo_proc now
that we've got name we want for the API we want

"ZAP!" deraadt@

Revision 1.67 / (download) - annotate - [select for diffs], Mon Apr 26 00:30:58 2010 UTC (14 years ago) by deraadt
Branch: MAIN
CVS Tags: OPENBSD_4_9_BASE, OPENBSD_4_9, OPENBSD_4_8_BASE, OPENBSD_4_8
Changes since 1.66: +4 -2 lines
Diff to previous 1.66 (colored)

more portable code

Revision 1.66 / (download) - annotate - [select for diffs], Fri Mar 26 05:10:50 2010 UTC (14 years, 1 month ago) by lum
Branch: MAIN
Changes since 1.65: +2 -22 lines
Diff to previous 1.65 (colored)

Make the source of process TIME for displaying and sorting the same.
top(1) and ps(1) now display the same info.
ok tedu@ millert@ otto@ and tested on sparc64 by landry@

Revision 1.65 / (download) - annotate - [select for diffs], Fri Jan 29 00:36:09 2010 UTC (14 years, 3 months ago) by tedu
Branch: MAIN
CVS Tags: OPENBSD_4_7_BASE, OPENBSD_4_7
Changes since 1.64: +57 -2 lines
Diff to previous 1.64 (colored)

Allow sorting by command and pid.  Also, allow partial matches with strncmp.
ok jmc otto

Revision 1.64 / (download) - annotate - [select for diffs], Tue Apr 28 21:24:41 2009 UTC (15 years ago) by deraadt
Branch: MAIN
CVS Tags: OPENBSD_4_6_BASE, OPENBSD_4_6
Changes since 1.63: +3 -3 lines
Diff to previous 1.63 (colored)

extend STATE column to fit > 9 cpus; Aivar Jaakson; PR6131

Revision 1.63 / (download) - annotate - [select for diffs], Thu Nov 1 19:19:48 2007 UTC (16 years, 6 months ago) by otto
Branch: MAIN
CVS Tags: OPENBSD_4_5_BASE, OPENBSD_4_5, OPENBSD_4_4_BASE, OPENBSD_4_4, OPENBSD_4_3_BASE, OPENBSD_4_3
Changes since 1.62: +3 -4 lines
Diff to previous 1.62 (colored)

bump arbitrary limit on arg length shown by -C; requested by and ok deraadt@

Revision 1.62 / (download) - annotate - [select for diffs], Fri Jul 27 13:57:50 2007 UTC (16 years, 9 months ago) by deraadt
Branch: MAIN
CVS Tags: OPENBSD_4_2_BASE, OPENBSD_4_2
Changes since 1.61: +6 -6 lines
Diff to previous 1.61 (colored)

replace a few more malloc(n*m) idioms with calloc(n,m) for safety;
inspired by zinovik@cs.karelia.ru

Revision 1.61 / (download) - annotate - [select for diffs], Tue May 29 00:56:56 2007 UTC (16 years, 11 months ago) by otto
Branch: MAIN
Changes since 1.60: +3 -2 lines
Diff to previous 1.60 (colored)

Instead of using hand-crafted redraws minimizing screen updates, use curses.
Enables nice things like process highlighting without hurting the brain.
ok deraadt@

Revision 1.60 / (download) - annotate - [select for diffs], Mon Apr 16 11:49:51 2007 UTC (17 years, 1 month ago) by otto
Branch: MAIN
Changes since 1.59: +3 -3 lines
Diff to previous 1.59 (colored)

don't truncate wchan, ok miod@

Revision 1.59 / (download) - annotate - [select for diffs], Fri Apr 13 19:19:54 2007 UTC (17 years, 1 month ago) by otto
Branch: MAIN
Changes since 1.58: +3 -10 lines
Diff to previous 1.58 (colored)

include cleanup and fix in comment; from Mark Lumsden

Revision 1.58 / (download) - annotate - [select for diffs], Wed Apr 4 19:24:18 2007 UTC (17 years, 1 month ago) by otto
Branch: MAIN
Changes since 1.57: +5 -3 lines
Diff to previous 1.57 (colored)

missing prototypes; from Mark Lumsden with a twist by me.

Revision 1.57 / (download) - annotate - [select for diffs], Sun Feb 4 14:58:45 2007 UTC (17 years, 3 months ago) by otto
Branch: MAIN
CVS Tags: OPENBSD_4_1_BASE, OPENBSD_4_1
Changes since 1.56: +2 -2 lines
Diff to previous 1.56 (colored)

long and long long is not the same on 32 bits archs

Revision 1.56 / (download) - annotate - [select for diffs], Wed Jan 3 18:57:49 2007 UTC (17 years, 4 months ago) by otto
Branch: MAIN
Changes since 1.55: +6 -3 lines
Diff to previous 1.55 (colored)

Add a 'g' command to only show processes having a string in their
command name. ok deraadt@

Revision 1.55 / (download) - annotate - [select for diffs], Tue Jan 2 19:09:24 2007 UTC (17 years, 4 months ago) by otto
Branch: MAIN
Changes since 1.54: +1 -2 lines
Diff to previous 1.54 (colored)

top(1) doesn't use any math.h function, so do not include math.h and
do not link with libm. ok ray@

Revision 1.54 / (download) - annotate - [select for diffs], Wed Nov 29 12:34:22 2006 UTC (17 years, 5 months ago) by miod
Branch: MAIN
Changes since 1.53: +1 -10 lines
Diff to previous 1.53 (colored)

Do not test for processes being swapped out since this can't happen anymore.

Revision 1.53 / (download) - annotate - [select for diffs], Wed Sep 20 21:26:20 2006 UTC (17 years, 8 months ago) by ray
Branch: MAIN
Changes since 1.52: +4 -2 lines
Diff to previous 1.52 (colored)

Recommit memory leak fix.

Revision 1.52 / (download) - annotate - [select for diffs], Sat Apr 29 14:40:44 2006 UTC (18 years ago) by otto
Branch: MAIN
CVS Tags: OPENBSD_4_0_BASE, OPENBSD_4_0
Changes since 1.51: +4 -4 lines
Diff to previous 1.51 (colored)

use calloc(3) instead of malloc(3) to allocate cpu state structs; it's
better style here; plus it prevents bogus data to show up on first display.
report + ok pedro@

Revision 1.51 / (download) - annotate - [select for diffs], Wed Dec 21 01:40:24 2005 UTC (18 years, 5 months ago) by millert
Branch: MAIN
CVS Tags: OPENBSD_3_9_BASE, OPENBSD_3_9
Changes since 1.50: +2 -2 lines
Diff to previous 1.50 (colored)

Userland programs should include <errno.h> not <sys/errno.h>
OK deraadt@

Revision 1.50 / (download) - annotate - [select for diffs], Sun Dec 4 23:10:06 2005 UTC (18 years, 5 months ago) by tedu
Branch: MAIN
Changes since 1.49: +5 -3 lines
Diff to previous 1.49 (colored)

support for toggling thread viewing.
ok brad, hints from jmc

Revision 1.49 / (download) - annotate - [select for diffs], Fri Jun 17 09:40:48 2005 UTC (18 years, 11 months ago) by markus
Branch: MAIN
CVS Tags: OPENBSD_3_8_BASE, OPENBSD_3_8
Changes since 1.48: +39 -3 lines
Diff to previous 1.48 (colored)

add a 'C' command ) that toggles the display of the full cmdline;
with Jared Yanovich; ok deraadt

Revision 1.48 / (download) - annotate - [select for diffs], Wed Jun 8 22:36:43 2005 UTC (18 years, 11 months ago) by millert
Branch: MAIN
Changes since 1.47: +48 -13 lines
Diff to previous 1.47 (colored)

Multi-cpu support for top.  Each cpu now gets its own stats line.
Based on work by todd@ at the hackathon.

Revision 1.47 / (download) - annotate - [select for diffs], Mon Dec 6 15:57:04 2004 UTC (19 years, 5 months ago) by markus
Branch: MAIN
CVS Tags: OPENBSD_3_7_BASE, OPENBSD_3_7
Changes since 1.46: +2 -2 lines
Diff to previous 1.46 (colored)

missing space; bluhm at genua.de

Revision 1.46 / (download) - annotate - [select for diffs], Mon Nov 22 15:26:53 2004 UTC (19 years, 6 months ago) by pat
Branch: MAIN
Changes since 1.45: +3 -3 lines
Diff to previous 1.45 (colored)

simplify loop iteration

ok otto millert

Revision 1.45 / (download) - annotate - [select for diffs], Wed Nov 17 09:22:43 2004 UTC (19 years, 6 months ago) by markus
Branch: MAIN
Changes since 1.44: +3 -3 lines
Diff to previous 1.44 (colored)

off-by-one in process_states[], fixes display of memory; ok deraadt, aaron

Revision 1.44 / (download) - annotate - [select for diffs], Thu Oct 7 06:26:12 2004 UTC (19 years, 7 months ago) by otto
Branch: MAIN
Changes since 1.43: +6 -4 lines
Diff to previous 1.43 (colored)

introduce -p option and p command to only show a single process.
From Patrick Latifi. ok deraadt@ millert@

Revision 1.43 / (download) - annotate - [select for diffs], Sun Jun 13 18:49:02 2004 UTC (19 years, 11 months ago) by otto
Branch: MAIN
CVS Tags: OPENBSD_3_6_BASE, OPENBSD_3_6
Changes since 1.42: +2 -2 lines
Diff to previous 1.42 (colored)

Typos in comments and a redundant prototype. From Brian Poole via jmc@
ok jmc@

Revision 1.42 / (download) - annotate - [select for diffs], Fri Jun 11 16:08:54 2004 UTC (19 years, 11 months ago) by deraadt
Branch: MAIN
Changes since 1.41: +2 -2 lines
Diff to previous 1.41 (colored)

handle the KI_NOCPU case, pointed out by markus

Revision 1.41 / (download) - annotate - [select for diffs], Fri Jun 11 05:29:28 2004 UTC (19 years, 11 months ago) by deraadt
Branch: MAIN
Changes since 1.40: +16 -4 lines
Diff to previous 1.40 (colored)

only print /# if > 1 cpu on a machine

Revision 1.40 / (download) - annotate - [select for diffs], Fri Jun 11 01:32:11 2004 UTC (19 years, 11 months ago) by deraadt
Branch: MAIN
Changes since 1.39: +15 -5 lines
Diff to previous 1.39 (colored)

export cpuid via kproc2, and make ps & top aware... from niklas

Revision 1.39 / (download) - annotate - [select for diffs], Fri Jun 11 01:00:58 2004 UTC (19 years, 11 months ago) by deraadt
Branch: MAIN
Changes since 1.38: +2 -2 lines
Diff to previous 1.38 (colored)

hide top breakage, until the next commit which will do it right

Revision 1.38 / (download) - annotate - [select for diffs], Sun May 9 22:14:15 2004 UTC (20 years ago) by deraadt
Branch: MAIN
Changes since 1.37: +4 -4 lines
Diff to previous 1.37 (colored)

spaces

Revision 1.37 / (download) - annotate - [select for diffs], Thu Jan 8 18:15:06 2004 UTC (20 years, 4 months ago) by millert
Branch: MAIN
CVS Tags: OPENBSD_3_5_BASE, OPENBSD_3_5
Changes since 1.36: +75 -89 lines
Diff to previous 1.36 (colored)

Convert to kinfo_proc2; ok deraadt@

Revision 1.36 / (download) - annotate - [select for diffs], Mon Jul 7 21:36:52 2003 UTC (20 years, 10 months ago) by deraadt
Branch: MAIN
CVS Tags: OPENBSD_3_4_BASE, OPENBSD_3_4
Changes since 1.35: +9 -9 lines
Diff to previous 1.35 (colored)

protos

Revision 1.35 / (download) - annotate - [select for diffs], Wed Jun 18 08:36:31 2003 UTC (20 years, 11 months ago) by deraadt
Branch: MAIN
Changes since 1.34: +6 -9 lines
Diff to previous 1.34 (colored)

remove unused variables

Revision 1.34 / (download) - annotate - [select for diffs], Tue Jun 17 00:51:29 2003 UTC (20 years, 11 months ago) by jfb
Branch: MAIN
Changes since 1.33: +3 -3 lines
Diff to previous 1.33 (colored)

properly typecast to uid_t the return value of proc_owner() and report
ESRCH instead of EACCES if it returns -1

ok millert@

Revision 1.33 / (download) - annotate - [select for diffs], Sun Jun 15 16:24:44 2003 UTC (20 years, 11 months ago) by millert
Branch: MAIN
Changes since 1.32: +6 -6 lines
Diff to previous 1.32 (colored)

use uid_t and fix some sign compare warnings; OK krw@ and deraadt@

Revision 1.32 / (download) - annotate - [select for diffs], Sat Jun 14 20:23:41 2003 UTC (20 years, 11 months ago) by avsm
Branch: MAIN
Changes since 1.31: +4 -4 lines
Diff to previous 1.31 (colored)

use correct length instead of sizeof(char *) for some strl* bound values
millert@ ok

Revision 1.31 / (download) - annotate - [select for diffs], Fri Jun 13 21:52:24 2003 UTC (20 years, 11 months ago) by deraadt
Branch: MAIN
Changes since 1.30: +16 -101 lines
Diff to previous 1.30 (colored)

readable code

Revision 1.30 / (download) - annotate - [select for diffs], Thu Jun 12 23:09:29 2003 UTC (20 years, 11 months ago) by deraadt
Branch: MAIN
Changes since 1.29: +137 -148 lines
Diff to previous 1.29 (colored)

knf

Revision 1.29 / (download) - annotate - [select for diffs], Thu Jun 12 22:30:23 2003 UTC (20 years, 11 months ago) by pvalchev
Branch: MAIN
Changes since 1.28: +16 -35 lines
Diff to previous 1.28 (colored)

cleanup; ok deraadt

Revision 1.28 / (download) - annotate - [select for diffs], Tue Jul 2 03:05:47 2002 UTC (21 years, 10 months ago) by tholo
Branch: MAIN
CVS Tags: OPENBSD_3_3_BASE, OPENBSD_3_3, OPENBSD_3_2_BASE, OPENBSD_3_2
Changes since 1.27: +28 -1 lines
Diff to previous 1.27 (colored)

Add missing copyright

Revision 1.27 / (download) - annotate - [select for diffs], Sat Feb 16 21:27:55 2002 UTC (22 years, 3 months ago) by millert
Branch: MAIN
CVS Tags: OPENBSD_3_1_BASE, OPENBSD_3_1
Changes since 1.26: +3 -3 lines
Diff to previous 1.26 (colored)

Part one of userland __P removal.  Done with a simple regexp with some minor hand editing to make comments line up correctly.  Another pass is forthcoming that handles the cases that could not be done automatically.

Revision 1.26 / (download) - annotate - [select for diffs], Wed Dec 5 02:29:19 2001 UTC (22 years, 5 months ago) by art
Branch: MAIN
Changes since 1.25: +12 -3 lines
Diff to previous 1.25 (colored)

Get maxslp with sysctl. Not the constant.

Revision 1.25 / (download) - annotate - [select for diffs], Thu Jul 12 05:17:26 2001 UTC (22 years, 10 months ago) by deraadt
Branch: MAIN
CVS Tags: OPENBSD_3_0_BASE, OPENBSD_3_0
Changes since 1.24: +2 -8 lines
Diff to previous 1.24 (colored)

first pass at a -Wall cleanup

Revision 1.24 / (download) - annotate - [select for diffs], Sun Jun 3 06:46:47 2001 UTC (22 years, 11 months ago) by angelos
Branch: MAIN
Changes since 1.23: +6 -5 lines
Diff to previous 1.23 (colored)

Use KERN_NPROCS to get the number of processes on the system, to
determine the amount of space we'll need to store the
information. The alternative, calling sysctl() with a NULL argument
for data, meant the kernel had to go through the process table.

Revision 1.23 / (download) - annotate - [select for diffs], Thu Feb 22 03:10:24 2001 UTC (23 years, 3 months ago) by deraadt
Branch: MAIN
CVS Tags: OPENBSD_2_9_BASE, OPENBSD_2_9
Changes since 1.22: +4 -2 lines
Diff to previous 1.22 (colored)

plug mem leak i introduced; spotted by millert

Revision 1.22 / (download) - annotate - [select for diffs], Sat Feb 17 23:01:40 2001 UTC (23 years, 3 months ago) by deraadt
Branch: MAIN
Changes since 1.21: +43 -29 lines
Diff to previous 1.21 (colored)

bye bye setgid kvm

Revision 1.21 / (download) - annotate - [select for diffs], Sat Feb 17 22:55:07 2001 UTC (23 years, 3 months ago) by deraadt
Branch: MAIN
Changes since 1.20: +10 -83 lines
Diff to previous 1.20 (colored)

do not use nlist anymore, kvm gets the bullet next

Revision 1.20 / (download) - annotate - [select for diffs], Sat Feb 17 22:51:26 2001 UTC (23 years, 3 months ago) by deraadt
Branch: MAIN
Changes since 1.19: +448 -538 lines
Diff to previous 1.19 (colored)

partial KNF, because i cannot read the diffs i am trying to debug

Revision 1.19 / (download) - annotate - [select for diffs], Sun Jun 18 17:59:56 2000 UTC (23 years, 11 months ago) by niklas
Branch: MAIN
CVS Tags: OPENBSD_2_8_BASE, OPENBSD_2_8
Changes since 1.18: +2 -2 lines
Diff to previous 1.18 (colored)

Mark kernel threads as system processes.  Make ps hide them by default,
show them with -k.  Do not try to show RSS based values for them as they
mess up column alignment.  vmstat -f now shows kernel threads separately
from rforks too.

Revision 1.18 / (download) - annotate - [select for diffs], Sun Nov 14 09:03:46 1999 UTC (24 years, 6 months ago) by deraadt
Branch: MAIN
CVS Tags: OPENBSD_2_7_BASE, OPENBSD_2_7
Changes since 1.17: +20 -10 lines
Diff to previous 1.17 (colored)

stathz instead of hz, plus improvements by me; camield@inet.unisource.nl

Revision 1.17 / (download) - annotate - [select for diffs], Fri Oct 29 08:58:43 1999 UTC (24 years, 6 months ago) by todd
Branch: MAIN
Changes since 1.16: +2 -2 lines
Diff to previous 1.16 (colored)

writen

Revision 1.16 / (download) - annotate - [select for diffs], Mon Jun 21 20:48:01 1999 UTC (24 years, 11 months ago) by art
Branch: MAIN
CVS Tags: OPENBSD_2_6_BASE, OPENBSD_2_6
Changes since 1.15: +2 -2 lines
Diff to previous 1.15 (colored)

stop casting the third argument to kvm_read to char *. it is a void *.

Revision 1.15 / (download) - annotate - [select for diffs], Sat May 22 21:42:26 1999 UTC (25 years ago) by weingart
Branch: MAIN
Changes since 1.14: +29 -152 lines
Diff to previous 1.14 (colored)

Update for new vmswap code.

Revision 1.14 / (download) - annotate - [select for diffs], Sat Nov 28 02:37:35 1998 UTC (25 years, 5 months ago) by kstailey
Branch: MAIN
CVS Tags: OPENBSD_2_5_BASE, OPENBSD_2_5
Changes since 1.13: +6 -4 lines
Diff to previous 1.13 (colored)

do not count swap spaces that were not swapon(2)ed

Revision 1.13 / (download) - annotate - [select for diffs], Sun Sep 20 06:19:14 1998 UTC (25 years, 8 months ago) by niklas
Branch: MAIN
CVS Tags: OPENBSD_2_4_BASE, OPENBSD_2_4
Changes since 1.12: +4 -4 lines
Diff to previous 1.12 (colored)

cp_time is long, deal with it.

Revision 1.12 / (download) - annotate - [select for diffs], Sun Sep 20 05:58:54 1998 UTC (25 years, 8 months ago) by niklas
Branch: MAIN
Changes since 1.11: +2 -2 lines
Diff to previous 1.11 (colored)

widen unsigned entities to signed ones before subtracting, fixes sorting on alpha

Revision 1.11 / (download) - annotate - [select for diffs], Fri Aug 21 13:55:23 1998 UTC (25 years, 9 months ago) by kstailey
Branch: MAIN
Changes since 1.10: +212 -13 lines
Diff to previous 1.10 (colored)

support "-o field" and the interactive "o" command

Revision 1.10 / (download) - annotate - [select for diffs], Wed Jul 8 22:14:16 1998 UTC (25 years, 10 months ago) by deraadt
Branch: MAIN
Changes since 1.9: +4 -1 lines
Diff to previous 1.9 (colored)

whack kmem gid after kvm_openfiles()

Revision 1.9 / (download) - annotate - [select for diffs], Thu Jun 25 16:54:35 1998 UTC (25 years, 11 months ago) by deraadt
Branch: MAIN
Changes since 1.8: +6 -1 lines
Diff to previous 1.8 (colored)

handle missing swap

Revision 1.8 / (download) - annotate - [select for diffs], Sat Nov 8 23:36:44 1997 UTC (26 years, 6 months ago) by millert
Branch: MAIN
CVS Tags: OPENBSD_2_3_BASE, OPENBSD_2_3
Changes since 1.7: +3 -3 lines
Diff to previous 1.7 (colored)

Sort idle processes by total CPU usage, not cpticks since cpticks
get zeroed every second; dan@dan.emsphone.com

Revision 1.7 / (download) - annotate - [select for diffs], Tue Sep 9 15:23:13 1997 UTC (26 years, 8 months ago) by millert
Branch: MAIN
CVS Tags: OPENBSD_2_2_BASE, OPENBSD_2_2
Changes since 1.6: +2 -26 lines
Diff to previous 1.6 (colored)

"last pid" stuff is useless with random pids.

Revision 1.6 / (download) - annotate - [select for diffs], Tue Sep 9 14:58:21 1997 UTC (26 years, 8 months ago) by millert
Branch: MAIN
Changes since 1.5: +19 -17 lines
Diff to previous 1.5 (colored)

Use kvm_openfiles() not the sunos compat kvm_open().
Use warn/warnx where it makes sense and check some more ret vals.

Revision 1.5 / (download) - annotate - [select for diffs], Sun Aug 24 18:37:46 1997 UTC (26 years, 9 months ago) by millert
Branch: MAIN
Changes since 1.4: +2 -2 lines
Diff to previous 1.4 (colored)

Fix compiler warnings.

Revision 1.4 / (download) - annotate - [select for diffs], Fri Aug 22 07:39:27 1997 UTC (26 years, 9 months ago) by downsj
Branch: MAIN
Changes since 1.3: +4 -4 lines
Diff to previous 1.3 (colored)

Two more alpha warnings.

Revision 1.3 / (download) - annotate - [select for diffs], Fri Aug 22 07:16:28 1997 UTC (26 years, 9 months ago) by downsj
Branch: MAIN
Changes since 1.2: +17 -16 lines
Diff to previous 1.2 (colored)

First sweep.  Prototype, type fixes, long fixes, mostly compiles with
-Wall.

Revision 1.2 / (download) - annotate - [select for diffs], Sun Aug 17 23:18:47 1997 UTC (26 years, 9 months ago) by kstailey
Branch: MAIN
Changes since 1.1: +3 -2 lines
Diff to previous 1.1 (colored)

print "idle" for idle processes

Revision 1.1 / (download) - annotate - [select for diffs], Thu Aug 14 14:00:22 1997 UTC (26 years, 9 months ago) by downsj
Branch: MAIN

top 3.4, with a few changes.  Still needs more work.

This form allows you to request diff's between any two revisions of a file. You may select a symbolic revision name using the selection box or you may type in a numeric name using the type-in text box.