From owner-svn-src-all@FreeBSD.ORG Mon Oct 13 21:35:11 2008 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3B14C1065727; Mon, 13 Oct 2008 21:35:11 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 281478FC1F; Mon, 13 Oct 2008 21:35:11 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id m9DLZBHx087163; Mon, 13 Oct 2008 21:35:11 GMT (envelope-from jhb@svn.freebsd.org) Received: (from jhb@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id m9DLZA70087159; Mon, 13 Oct 2008 21:35:10 GMT (envelope-from jhb@svn.freebsd.org) Message-Id: <200810132135.m9DLZA70087159@svn.freebsd.org> From: John Baldwin Date: Mon, 13 Oct 2008 21:35:10 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-6@freebsd.org X-SVN-Group: stable-6 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r183852 - in stable/6: contrib/top usr.bin/top X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 13 Oct 2008 21:35:11 -0000 Author: jhb Date: Mon Oct 13 21:35:10 2008 New Revision: 183852 URL: http://svn.freebsd.org/changeset/base/183852 Log: MFC: Several top '-P' fixes originally from ru@. This fixes top -P on i386. Approved by: re (kib) Modified: stable/6/contrib/top/machine.h stable/6/contrib/top/top.X stable/6/contrib/top/top.c stable/6/usr.bin/top/machine.c Modified: stable/6/contrib/top/machine.h ============================================================================== --- stable/6/contrib/top/machine.h Mon Oct 13 21:20:50 2008 (r183851) +++ stable/6/contrib/top/machine.h Mon Oct 13 21:35:10 2008 (r183852) @@ -44,7 +44,6 @@ struct system_info int *memory; int *swap; struct timeval boottime; - unsigned long cpumask; /* bitfield of cpu states represented */ int ncpus; }; Modified: stable/6/contrib/top/top.X ============================================================================== --- stable/6/contrib/top/top.X Mon Oct 13 21:20:50 2008 (r183851) +++ stable/6/contrib/top/top.X Mon Oct 13 21:35:10 2008 (r183852) @@ -10,7 +10,7 @@ top \- display and update information ab .SH SYNOPSIS .B top [ -.B \-bCHIijnqStuv +.B \-bCHIijnPqStuv ] [ .BI \-d count ] [ @@ -113,6 +113,9 @@ Display either 'cpu' or 'io' statistics. Use \*(lqnon-interactive\*(rq mode. This is identical to \*(lqbatch\*(rq mode. .TP +.B \-P +Display per-cpu CPU usage statistics. +.TP .B \-q Renice .I top Modified: stable/6/contrib/top/top.c ============================================================================== --- stable/6/contrib/top/top.c Mon Oct 13 21:20:50 2008 (r183851) +++ stable/6/contrib/top/top.c Mon Oct 13 21:35:10 2008 (r183852) @@ -283,7 +283,7 @@ char *argv[]; optind = 1; } - while ((i = getopt(ac, av, "CSIHPbijnpquvs:d:U:m:o:t")) != EOF) + while ((i = getopt(ac, av, "CSIHPbijnquvs:d:U:m:o:t")) != EOF) { switch(i) { @@ -408,14 +408,10 @@ char *argv[]; pcpu_stats = Yes; break; - case 'p': - pcpu_stats = No; - break; - default: fprintf(stderr, "Top version %s\n" -"Usage: %s [-bCHIijnqStuv] [-d count] [-m io | cpu] [-o field] [-s time]\n" +"Usage: %s [-bCHIijnPqStuv] [-d count] [-m io | cpu] [-o field] [-s time]\n" " [-U username] [number]\n", version_string(), myname); exit(1); Modified: stable/6/usr.bin/top/machine.c ============================================================================== --- stable/6/usr.bin/top/machine.c Mon Oct 13 21:20:50 2008 (r183851) +++ stable/6/usr.bin/top/machine.c Mon Oct 13 21:35:10 2008 (r183852) @@ -305,6 +305,7 @@ machine_init(struct statics *statics) err(1, "malloc %zd bytes", size); if (sysctlbyname("kern.cp_times", times, &size, NULL, 0) == -1) err(1, "sysctlbyname kern.cp_times"); + pcpu_cp_time = calloc(1, size); maxid = (size / CPUSTATES / sizeof(long)) - 1; for (i = 0; i <= maxid; i++) { empty = 1; @@ -328,14 +329,9 @@ machine_init(struct statics *statics) Header_lines += ncpus - 1; /* 7 */ } size = sizeof(long) * ncpus * CPUSTATES; - pcpu_cp_time = malloc(size); - pcpu_cp_old = malloc(size); - pcpu_cp_diff = malloc(size); - pcpu_cpu_states = malloc(size); - bzero(pcpu_cp_time, size); - bzero(pcpu_cp_old, size); - bzero(pcpu_cp_diff, size); - bzero(pcpu_cpu_states, size); + pcpu_cp_old = calloc(1, size); + pcpu_cp_diff = calloc(1, size); + pcpu_cpu_states = calloc(1, size); statics->ncpus = ncpus; } else { statics->ncpus = 1; @@ -410,14 +406,15 @@ get_system_info(struct system_info *si) si->load_avg[i] = (double)sysload.ldavg[i] / sysload.fscale; if (pcpu_stats) { - for (i = j = 0; i <= maxid; i++, j++) { - if (cpumask && (1ul << i) == 0) + for (i = j = 0; i <= maxid; i++) { + if ((cpumask & (1ul << i)) == 0) continue; /* convert cp_time counts to percentages */ percentages(CPUSTATES, &pcpu_cpu_states[j * CPUSTATES], &pcpu_cp_time[j * CPUSTATES], &pcpu_cp_old[j * CPUSTATES], &pcpu_cp_diff[j * CPUSTATES]); + j++; } } else { /* convert cp_time counts to percentages */ @@ -478,11 +475,9 @@ get_system_info(struct system_info *si) /* set arrays and strings */ if (pcpu_stats) { si->cpustates = pcpu_cpu_states; - si->cpumask = cpumask; si->ncpus = ncpus; } else { si->cpustates = cpu_states; - si->cpumask = 1; si->ncpus = 1; } si->memory = memory_stats;