Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

top - Adjust top to account for kernel changes

* ccpu no longer exists

* if top is out of sync with the system, fix a seg-fault which can occur
  when it tries to use lwp_stat as an array indx.
  • Loading branch information...
commit d6eee5179f96afa7695c19158ccaa58fb87c73fc 1 parent 0274e76
Matthew Dillon authored
Showing with 11 additions and 19 deletions.
  1. +1 −1  usr.bin/top/config.h
  2. +10 −18 usr.bin/top/m_dragonfly.c
View
2  usr.bin/top/config.h
@@ -5,7 +5,7 @@
/* #undef DEBUG */
/* Default delay */
-#define DEFAULT_DELAY 5
+#define DEFAULT_DELAY 2
/* Default number of processes to display */
#define DEFAULT_TOPN 30
View
28 usr.bin/top/m_dragonfly.c
@@ -78,10 +78,6 @@ struct handle {
#define LP(pp, field) ((pp)->kp_lwp.kl_ ## field)
#define VP(pp, field) ((pp)->kp_vm_ ## field)
-/* define what weighted cpu is. */
-#define weighted_cpu(pct, pp) (PP((pp), swtime) == 0 ? 0.0 : \
- ((pct) / (1.0 - exp(PP((pp), swtime) * logcpu))))
-
/* what we consider to be process size: */
#define PROCSIZE(pp) (VP((pp), map_size) / 1024)
@@ -117,10 +113,7 @@ static kvm_t *kd;
/* values that we stash away in _init and use in later routines */
-static double logcpu;
-
static long lastpid;
-static int ccpu;
/* these are for calculating cpu state percentages */
@@ -128,7 +121,10 @@ static struct kinfo_cputime *cp_time, *cp_old;
/* these are for detailing the process states */
-int process_states[6];
+#define MAXPSTATES 6
+
+int process_states[MAXPSTATES];
+
char *procstatenames[] = {
" running, ", " idle, ", " active, ", " stopped, ", " zombie, ",
NULL
@@ -277,13 +273,6 @@ machine_init(struct statics *statics)
if ((kd = kvm_open(NULL, NULL, NULL, O_RDONLY, NULL)) == NULL)
return -1;
- if (kinfo_get_sched_ccpu(&ccpu)) {
- fprintf(stderr, "top: kinfo_get_sched_ccpu failed\n");
- return (-1);
- }
- /* this is used in calculating WCPU -- calculate it ahead of time */
- logcpu = log(loaddouble(ccpu));
-
pbase = NULL;
pref = NULL;
nproc = 0;
@@ -496,13 +485,16 @@ get_process_info(struct system_info *si, struct process_select *sel,
*/
if ((show_threads && (LP(pp, pid) == -1)) ||
(show_system || ((PP(pp, flags) & P_SYSTEM) == 0))) {
+ int pstate = LP(pp, stat);
+
total_procs++;
- if (LP(pp, stat) == LSRUN)
+ if (pstate == LSRUN)
process_states[0]++;
- process_states[PP(pp, stat)]++;
+ if (pstate >= 0 && pstate < MAXPSTATES)
+ process_states[pstate]++;
if ((show_threads && (LP(pp, pid) == -1)) ||
(show_idle || (LP(pp, pctcpu) != 0) ||
- (LP(pp, stat) == LSRUN)) &&
+ (pstate == LSRUN)) &&
(!show_uid || PP(pp, ruid) == (uid_t) sel->uid)) {
*prefp++ = pp;
active_procs++;
Please sign in to comment.
Something went wrong with that request. Please try again.