top: a few fixes

. fixed overflow in ticks compare function, causing
	  occasionally esp. the kernel to be mis-ordered by cpu
	  time
	. fixed some const string related warnings
	. fixed some variable name shadowing warnings

Change-Id: I02c177b1579bce164372f9b03f6b472537cc9e3e
This commit is contained in:
Ben Gras 2013-04-05 15:24:47 +00:00
parent a264c7ec4c
commit 2db46bcfa1

View file

@ -59,7 +59,7 @@ int nr_total;
#define TC_BUFFER 1024 /* Size of termcap(3) buffer */ #define TC_BUFFER 1024 /* Size of termcap(3) buffer */
#define TC_STRINGS 200 /* Enough room for cm,cl,so,se */ #define TC_STRINGS 200 /* Enough room for cm,cl,so,se */
char *Tclr_all; const char *Tclr_all;
int blockedverbose = 0; int blockedverbose = 0;
@ -261,19 +261,19 @@ static int print_load(double *loads, int nloads)
return 1; return 1;
} }
static int print_proc_summary(struct proc *proc) static int print_proc_summary(struct proc *pproc)
{ {
int p, alive, running, sleeping; int p, alive, running, sleeping;
alive = running = sleeping = 0; alive = running = sleeping = 0;
for(p = 0; p < nr_total; p++) { for(p = 0; p < nr_total; p++) {
if (proc[p].p_endpoint == IDLE) if (pproc[p].p_endpoint == IDLE)
continue; continue;
if(!(proc[p].p_flags & USED)) if(!(pproc[p].p_flags & USED))
continue; continue;
alive++; alive++;
if(proc[p].p_flags & BLOCKED) if(pproc[p].p_flags & BLOCKED)
sleeping++; sleeping++;
else else
running++; running++;
@ -317,7 +317,9 @@ static int cmp_procs(const void *v1, const void *v2)
if(!p2blocked && p1blocked) if(!p2blocked && p1blocked)
return 1; return 1;
} else if(p1->ticks != p2->ticks) { } else if(p1->ticks != p2->ticks) {
return (p2->ticks - p1->ticks); if(p1->ticks > p2->ticks) return -1;
assert(p1->ticks < p2->ticks);
return 1;
} }
/* Process slot number is a tie breaker. */ /* Process slot number is a tie breaker. */
@ -345,7 +347,7 @@ static void print_proc(struct tp *tp, u64_t total_ticks)
int euid = 0; int euid = 0;
static struct passwd *who = NULL; static struct passwd *who = NULL;
static int last_who = -1; static int last_who = -1;
char *name = ""; const char *name = "";
int ticks; int ticks;
struct proc *pr = tp->p; struct proc *pr = tp->p;
@ -410,7 +412,7 @@ static u64_t cputicks(struct proc *p1, struct proc *p2, int timemode)
return t; return t;
} }
static char *ordername(int orderno) static const char *ordername(int orderno)
{ {
switch(orderno) { switch(orderno) {
case ORDER_CPU: return "cpu"; case ORDER_CPU: return "cpu";
@ -625,7 +627,7 @@ static void getkinfo(void)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int r, c, s = 0; int r, optc, s = 0;
int cputimemode = 1; /* bitmap. */ int cputimemode = 1; /* bitmap. */
if (chdir(_PATH_PROC) != 0) { if (chdir(_PATH_PROC) != 0) {
@ -639,8 +641,8 @@ int main(int argc, char *argv[])
init(&r); init(&r);
while((c=getopt(argc, argv, "s:B")) != EOF) { while((optc=getopt(argc, argv, "s:B")) != EOF) {
switch(c) { switch(optc) {
case 's': case 's':
s = atoi(optarg); s = atoi(optarg);
break; break;
@ -681,9 +683,9 @@ int main(int argc, char *argv[])
} }
if(ns > 0 && FD_ISSET(STDIN_FILENO, &fds)) { if(ns > 0 && FD_ISSET(STDIN_FILENO, &fds)) {
char c; char inc;
if(read(STDIN_FILENO, &c, 1) == 1) { if(read(STDIN_FILENO, &inc, 1) == 1) {
switch(c) { switch(inc) {
case 'q': case 'q':
putchar('\r'); putchar('\r');
return 0; return 0;