0001-refs-2447-TOP-isn-t-reporting-correctly-CPU-states-w.patch

jalcazar, 01/05/2013 09:24 PM

Download (3.14 KB)

View differences:

usr.bin/top/m_dragonfly.c
125 125
/* these are for detailing the cpu states */
126 126
#define CPU_STATES 5
127 127
int *cpu_states;
128
int* cpu_averages;
128 129
char *cpustatenames[CPU_STATES + 1] = {
129 130
	"user", "nice", "system", "interrupt", "idle", NULL
130 131
};
......
344 345
	lastpid = 0;
345 346

  
346 347
	/* convert cp_time counts to percentages */
348
	int combine_cpus = (enable_ncpus == 0 && n_cpus > 1);
347 349
	for (cpu = 0; cpu < n_cpus; ++cpu) {
348 350
		cputime_percentages(cpu_states + cpu * CPU_STATES,
349 351
		    &cp_time[cpu], &cp_old[cpu]);
350 352
	}
353
	if (combine_cpus) {
354
        	if (cpu_averages == NULL) {
355
  			cpu_averages = calloc(CPU_STATES, sizeof(*cpu_averages));
356
  			if (cpu_averages == NULL)
357
  				err(1, "cpu_averages");
358
  		}
359
  		memset(cpu_averages, 0, sizeof(*cpu_averages) * CPU_STATES);
360
		for (cpu = 0; cpu < n_cpus; ++cpu) {
361
			int j = 0;
362
			cpu_averages[0] += *(cpu_states + ((cpu * CPU_STATES) + j++) );
363
			cpu_averages[1] += *(cpu_states + ((cpu * CPU_STATES) + j++) );
364
			cpu_averages[2] += *(cpu_states + ((cpu * CPU_STATES) + j++) );
365
			cpu_averages[3] += *(cpu_states + ((cpu * CPU_STATES) + j++) );
366
			cpu_averages[4] += *(cpu_states + ((cpu * CPU_STATES) + j++) );       
367
		}                   
368
  		for (int i = 0; i < CPU_STATES; ++i) 
369
			cpu_averages[i] /= n_cpus;
370
	}
351 371

  
352 372
	/* sum memory & swap statistics */
353 373
	{
......
404 424
	}
405 425

  
406 426
	/* set arrays and strings */
407
	si->cpustates = cpu_states;
427
	si->cpustates = combine_cpus == 1 ?
428
	    cpu_averages : cpu_states;  
408 429
	si->memory = memory_stats;
409 430
	si->swap = swap_stats;
410 431

  
usr.bin/top/top.1
330 330
by a breakdown of processes per state.  Examples of states common
331 331
to Unix systems are sleeping, running, starting, stopped, and zombie.
332 332
The next line displays a percentage of time spent in each of the
333
processor states (typically user, nice, system, idle, and iowait).
333
processor states (user, nice, system, interrupt, idle).
334 334
These percentages show the processor activity during the time since
335 335
the last update.  For multi-processor systems, this information is 
336
a summation of time across all processors.  The next line shows
336
an average of all processors.  The next line shows
337 337
kernel-related activity (not available on all systems).  The numbers
338 338
shown on this line are per-second rates sampled since the last update.
339 339
The exact
340
-