summaryrefslogtreecommitdiffstats
path: root/usr.bin/top/machine.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* Allow reverse sort orderkn2018-11-281-22/+21
| | | | | | | 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
* Add new KERN_CPUSTATS sysctl(2) so we can identify offline CPUs.cheloha2018-11-171-41/+42
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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@
* Revert KERN_CPTIME2 ENODEV changes in kernel and userspace.cheloha2018-10-051-35/+24
| | | | ok kettenis deraadt
* KERN_CPTIME2: set ENODEV if the CPU is offline.cheloha2018-09-261-24/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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@
* Use user_from_uid() and uid_from_user() directly. The wrappersmillert2018-09-221-4/+4
| | | | | in username.c are now so simple there is no longer a good reason to use them. OK deraadt@
* Fix warnings caused by user_from_uid() and group_from_gid() nowmillert2018-09-131-2/+2
| | | | returning const char *.
* Stopping counting and reporting CPU time spent spinning on a lock asmpi2018-05-141-2/+2
| | | | | | | | | 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@
* avoid some shadow warnings. from Brian Callahantedu2017-05-301-7/+7
|
* annoying whitespace die die diederaadt2017-03-151-8/+8
|
* rework realloc loop. there's no need to shrink the allocation betweentedu2016-07-281-10/+15
| | | | calls. if we need a big space once, we'll likely need a big space again.
* Allow top(1) to filter process args if they are being displayed.edd2016-05-111-20/+65
| | | | | | OK tedu@, deraadt@, and with input from Michal Mazurek. Thanks
* Do not cast result of malloc/calloc/realloc* if stdlib.h is in scopederaadt2015-08-201-3/+3
| | | | ok krw millert
* Display thread IDs instead of the name of the process's owner when "-H"mpi2015-05-061-7/+19
| | | | | | | | | | | | 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@
* Kill loadavg.h and just use the fscale value directly.millert2015-01-191-12/+3
| | | | | There's no need for crazy casts of p_pctcpu in ORDERKEY_PCTCPU since kinfo_proc exports it as uint32_t. OK deraadt@
* like in ps(1), fetch the FSCALE value using sysctl rather than usingderaadt2015-01-191-1/+16
| | | | | the header version ok guenther
* Replace <sys/param.h> with <limits.h> and other less dirty headers wherederaadt2015-01-161-2/+3
| | | | | | | | | 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)
* if there are more than 8 cpus, default to combined cpu stats (likedlg2014-09-171-6/+18
| | | | | | you passed -1 on the command line). ok kettenis@ tedu@
* Remove non-standard <sys/dkstat.h> header. It has not contained anythingmiod2014-09-151-2/+2
| | | | | | | | | | 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@
* Track whether a process is a zombie or not yet fully built via flagsguenther2014-07-041-2/+2
| | | | | | | | | | | 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@
* Use VM_UVMEXP instead of VM_METER for memory usages and directlympi2014-04-081-9/+9
| | | | | | | 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@
* wchan is no longer exposed, just check if wmesg is not empty.tedu2013-03-231-11/+5
| | | | | | (wmesg hasn't itself been a pointer since conversion to kinfo_proc.) noticed by sthen. ok deraadt jsing millert sthen
* We no longer use struct eproc for kinfo_proc in sysctl.h so theremillert2012-12-181-5/+7
| | | | | | | 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@
* According to miod, KERNBASE used as a userland symbol should diederaadt2012-07-091-2/+2
| | | | | in a fire. Start by removing the definitions, before we clean the headers later.
* Add support for hiding a user's processes in top.brynet2012-06-051-1/+4
| | | | feedback & ok lum@
* Remove a check made superfluous by the KERN_PROC_SHOW_THREADS flag.guenther2012-04-211-3/+1
| | | | | | This lets new binaries work (at least w/o the -H option) with old kernels. ok pirofti@ deraadt@
* Make it optional for kvm_getprocs() (and related sysctl) to returnpirofti2012-04-171-2/+6
| | | | | | | | | | | | 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@.
* Add per thread accounting, mainly for usage & friends.pirofti2012-04-121-1/+5
| | | | | | | | | | | | | | 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@.
* print out the amount of memory used for cache. ok ottotedu2011-07-121-7/+18
|
* Switch back from KERN_PROC2/kinfo_proc2 to KERN_PROC/kinfo_proc nowguenther2011-04-101-42/+42
| | | | | | that we've got name we want for the API we want "ZAP!" deraadt@
* more portable codederaadt2010-04-261-2/+4
|
* Make the source of process TIME for displaying and sorting the same.lum2010-03-261-22/+2
| | | | | top(1) and ps(1) now display the same info. ok tedu@ millert@ otto@ and tested on sparc64 by landry@
* Allow sorting by command and pid. Also, allow partial matches with strncmp.tedu2010-01-291-2/+57
| | | | ok jmc otto
* extend STATE column to fit > 9 cpus; Aivar Jaakson; PR6131deraadt2009-04-281-3/+3
|
* bump arbitrary limit on arg length shown by -C; requested by and ok deraadt@otto2007-11-011-4/+3
|
* replace a few more malloc(n*m) idioms with calloc(n,m) for safety;deraadt2007-07-271-6/+6
| | | | inspired by zinovik@cs.karelia.ru
* Instead of using hand-crafted redraws minimizing screen updates, use curses.otto2007-05-291-2/+3
| | | | | Enables nice things like process highlighting without hurting the brain. ok deraadt@
* don't truncate wchan, ok miod@otto2007-04-161-3/+3
|
* include cleanup and fix in comment; from Mark Lumsdenotto2007-04-131-10/+3
|
* missing prototypes; from Mark Lumsden with a twist by me.otto2007-04-041-3/+5
|
* long and long long is not the same on 32 bits archsotto2007-02-041-2/+2
|
* Add a 'g' command to only show processes having a string in theirotto2007-01-031-3/+6
| | | | command name. ok deraadt@
* top(1) doesn't use any math.h function, so do not include math.h andotto2007-01-021-2/+1
| | | | do not link with libm. ok ray@
* Do not test for processes being swapped out since this can't happen anymore.miod2006-11-291-10/+1
|
* Recommit memory leak fix.ray2006-09-201-2/+4
|
* use calloc(3) instead of malloc(3) to allocate cpu state structs; it'sotto2006-04-291-4/+4
| | | | | better style here; plus it prevents bogus data to show up on first display. report + ok pedro@
* Userland programs should include <errno.h> not <sys/errno.h>millert2005-12-211-2/+2
| | | | OK deraadt@
* support for toggling thread viewing.tedu2005-12-041-3/+5
| | | | ok brad, hints from jmc
* add a 'C' command ) that toggles the display of the full cmdline;markus2005-06-171-3/+39
| | | | with Jared Yanovich; ok deraadt
* Multi-cpu support for top. Each cpu now gets its own stats line.millert2005-06-081-14/+49
| | | | Based on work by todd@ at the hackathon.
* missing space; bluhm at genua.demarkus2004-12-061-2/+2
|