diff options
author | attilio <attilio@FreeBSD.org> | 2011-07-15 11:46:54 +0000 |
---|---|---|
committer | attilio <attilio@FreeBSD.org> | 2011-07-15 11:46:54 +0000 |
commit | 3b092444e94a084b65ab95d481df255b58d72825 (patch) | |
tree | adec64797645709b675fe04db29b1915065b8df5 /usr.sbin/pmccontrol | |
parent | 466a13c175275736c8af0c003ec4a4f0ec0abd48 (diff) | |
download | FreeBSD-src-3b092444e94a084b65ab95d481df255b58d72825.zip FreeBSD-src-3b092444e94a084b65ab95d481df255b58d72825.tar.gz |
Fix logical_cpus_mask retrieving by using, correctly, cpuset_t.
This fix also a bug where pmccontrol uses a 32 static type rather than
old cpumask_t.
Reported and reviewed by: avg
Diffstat (limited to 'usr.sbin/pmccontrol')
-rw-r--r-- | usr.sbin/pmccontrol/pmccontrol.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/usr.sbin/pmccontrol/pmccontrol.c b/usr.sbin/pmccontrol/pmccontrol.c index 35ea005..2a680ae 100644 --- a/usr.sbin/pmccontrol/pmccontrol.c +++ b/usr.sbin/pmccontrol/pmccontrol.c @@ -30,6 +30,7 @@ __FBSDID("$FreeBSD$"); #include <sys/param.h> #include <sys/queue.h> +#include <sys/cpuset.h> #include <sys/sysctl.h> #include <assert.h> @@ -220,9 +221,10 @@ pmcc_do_enable_disable(struct pmcc_op_list *op_list) static int pmcc_do_list_state(void) { - size_t dummy; + cpuset_t logical_cpus_mask; + long cpusetsize; + size_t setsize; int c, cpu, n, npmc, ncpu; - unsigned int logical_cpus_mask; struct pmc_info *pd; struct pmc_pmcinfo *pi; const struct pmc_cpuinfo *pc; @@ -234,17 +236,22 @@ pmcc_do_list_state(void) pmc_name_of_cputype(pc->pm_cputype), pc->pm_npmc); - dummy = sizeof(logical_cpus_mask); + /* Determine the set of logical CPUs. */ + cpusetsize = sysconf(_SC_CPUSET_SIZE); + if (cpusetsize == -1 || (u_long)cpusetsize > sizeof(cpuset_t)) + err(EX_OSERR, "Cannot determine which CPUs are logical"); + CPU_ZERO(&logical_cpus_mask); + setsize = (size_t)cpusetsize; if (sysctlbyname("machdep.logical_cpus_mask", &logical_cpus_mask, - &dummy, NULL, 0) < 0) - logical_cpus_mask = 0; + &setsize, NULL, 0) < 0) + CPU_ZERO(&logical_cpus_mask); ncpu = pc->pm_ncpu; for (c = cpu = 0; cpu < ncpu; cpu++) { #if defined(__i386__) || defined(__amd64__) if (pc->pm_cputype == PMC_CPU_INTEL_PIV && - (logical_cpus_mask & (1 << cpu))) + CPU_ISSET(cpu, &logical_cpus_mask)) continue; /* skip P4-style 'logical' cpus */ #endif if (pmc_pmcinfo(cpu, &pi) < 0) { |