summaryrefslogtreecommitdiffstats
path: root/usr.sbin/pmcstat
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2015-09-29 18:39:58 +0000
committerjhb <jhb@FreeBSD.org>2015-09-29 18:39:58 +0000
commit7b63f549f4f646525bdab72edb1f71f244ee5b2a (patch)
treeb340964c7df074661b10247170df409cd52f2514 /usr.sbin/pmcstat
parentcfb75697333c495bbc229f1c1d8251aa6da1f768 (diff)
downloadFreeBSD-src-7b63f549f4f646525bdab72edb1f71f244ee5b2a.zip
FreeBSD-src-7b63f549f4f646525bdab72edb1f71f244ee5b2a.tar.gz
MFC 283613,287374:
Use the cpuset API more consistently: - Fetch the root set from cpuset_getaffinity() instead of assuming all CPUs from 0 to hw.ncpu are the root set. - Use CPU_SETSIZE and CPU_FFS. - The original notion of halted CPUs the manpage and code refers to is gone. Use the term "available" instead.
Diffstat (limited to 'usr.sbin/pmcstat')
-rw-r--r--usr.sbin/pmcstat/pmcstat.86
-rw-r--r--usr.sbin/pmcstat/pmcstat.c45
2 files changed, 21 insertions, 30 deletions
diff --git a/usr.sbin/pmcstat/pmcstat.8 b/usr.sbin/pmcstat/pmcstat.8
index af54cea..677b21f 100644
--- a/usr.sbin/pmcstat/pmcstat.8
+++ b/usr.sbin/pmcstat/pmcstat.8
@@ -25,7 +25,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd May 8, 2015
+.Dd May 27, 2015
.Dt PMCSTAT 8
.Os
.Sh NAME
@@ -246,8 +246,8 @@ Argument
.Ar cpu-spec
is a comma separated list of CPU numbers, or the literal
.Sq *
-denoting all unhalted CPUs.
-The default is to allocate system mode PMCs on all unhalted
+denoting all available CPUs.
+The default is to allocate system mode PMCs on all available
CPUs.
.It Fl d
Toggle between process mode PMCs measuring events for the target
diff --git a/usr.sbin/pmcstat/pmcstat.c b/usr.sbin/pmcstat/pmcstat.c
index 05dffaa..9ce4918 100644
--- a/usr.sbin/pmcstat/pmcstat.c
+++ b/usr.sbin/pmcstat/pmcstat.c
@@ -116,11 +116,10 @@ struct pmcstat_args args;
static void
pmcstat_clone_event_descriptor(struct pmcstat_ev *ev, const cpuset_t *cpumask)
{
- int cpu, mcpu;
+ int cpu;
struct pmcstat_ev *ev_clone;
- mcpu = sizeof(*cpumask) * NBBY;
- for (cpu = 0; cpu < mcpu; cpu++) {
+ for (cpu = 0; cpu < CPU_SETSIZE; cpu++) {
if (!CPU_ISSET(cpu, cpumask))
continue;
@@ -161,6 +160,7 @@ pmcstat_get_cpumask(const char *cpuspec, cpuset_t *cpumask)
CPU_SET(cpu, cpumask);
s = end + strspn(end, ", \t");
} while (*s);
+ assert(!CPU_EMPTY(cpumask));
}
void
@@ -550,10 +550,10 @@ pmcstat_topexit(void)
int
main(int argc, char **argv)
{
- cpuset_t cpumask;
+ cpuset_t cpumask, rootmask;
double interval;
double duration;
- int hcpu, option, npmc, ncpu;
+ int option, npmc;
int c, check_driver_stats, current_sampling_count;
int do_callchain, do_descendants, do_logproccsw, do_logprocexit;
int do_print, do_read;
@@ -618,14 +618,13 @@ main(int argc, char **argv)
err(EX_OSERR, "ERROR: Cannot determine path of running kernel");
/*
- * The initial CPU mask specifies all non-halted CPUS in the
- * system.
+ * The initial CPU mask specifies the root mask of this process
+ * which is usually all CPUs in the system.
*/
- len = sizeof(int);
- if (sysctlbyname("hw.ncpu", &ncpu, &len, NULL, 0) < 0)
- err(EX_OSERR, "ERROR: Cannot determine the number of CPUs");
- for (hcpu = 0; hcpu < ncpu; hcpu++)
- CPU_SET(hcpu, &cpumask);
+ if (cpuset_getaffinity(CPU_LEVEL_ROOT, CPU_WHICH_PID, -1,
+ sizeof(rootmask), &rootmask) == -1)
+ err(EX_OSERR, "ERROR: Cannot determine the root set of CPUs");
+ CPU_COPY(&rootmask, &cpumask);
while ((option = getopt(argc, argv,
"CD:EF:G:M:NO:P:R:S:TWa:c:df:gk:l:m:n:o:p:qr:s:t:vw:z:")) != -1)
@@ -642,11 +641,9 @@ main(int argc, char **argv)
break;
case 'c': /* CPU */
-
- if (optarg[0] == '*' && optarg[1] == '\0') {
- for (hcpu = 0; hcpu < ncpu; hcpu++)
- CPU_SET(hcpu, &cpumask);
- } else
+ if (optarg[0] == '*' && optarg[1] == '\0')
+ CPU_COPY(&rootmask, &cpumask);
+ else
pmcstat_get_cpumask(optarg, &cpumask);
args.pa_flags |= FLAGS_HAS_CPUMASK;
@@ -771,13 +768,9 @@ main(int argc, char **argv)
else
ev->ev_count = -1;
- if (option == 'S' || option == 's') {
- hcpu = sizeof(cpumask) * NBBY;
- for (hcpu--; hcpu >= 0; hcpu--)
- if (CPU_ISSET(hcpu, &cpumask))
- break;
- ev->ev_cpu = hcpu;
- } else
+ if (option == 'S' || option == 's')
+ ev->ev_cpu = CPU_FFS(&cpumask) - 1;
+ else
ev->ev_cpu = PMC_CPU_ANY;
ev->ev_flags = 0;
@@ -804,11 +797,9 @@ main(int argc, char **argv)
STAILQ_INSERT_TAIL(&args.pa_events, ev, ev_next);
if (option == 's' || option == 'S') {
- hcpu = CPU_ISSET(ev->ev_cpu, &cpumask);
CPU_CLR(ev->ev_cpu, &cpumask);
pmcstat_clone_event_descriptor(ev, &cpumask);
- if (hcpu != 0)
- CPU_SET(ev->ev_cpu, &cpumask);
+ CPU_SET(ev->ev_cpu, &cpumask);
}
break;
OpenPOWER on IntegriCloud