From 1b9278cc989bd23a4e620f1b58d624819ca8e1c0 Mon Sep 17 00:00:00 2001 From: glebius Date: Tue, 4 Mar 2014 14:49:05 +0000 Subject: Merge r261796 from head: While it isn't too late and kvm_read_zpcpu() function isn't yet used outside libkvm(3), change its order of arguments, so that it is the same as in kvm_read(). Merge r261805 from head: Add kvm_getncpus() to obtain mp_ncpus. --- lib/libkvm/kvm_pcpu.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'lib/libkvm/kvm_pcpu.c') diff --git a/lib/libkvm/kvm_pcpu.c b/lib/libkvm/kvm_pcpu.c index 2d7fb41..662566a 100644 --- a/lib/libkvm/kvm_pcpu.c +++ b/lib/libkvm/kvm_pcpu.c @@ -173,6 +173,16 @@ kvm_getmaxcpu(kvm_t *kd) return (maxcpu); } +int +kvm_getncpus(kvm_t *kd) +{ + + if (mp_ncpus == 0) + if (_kvm_pcpu_init(kd) < 0) + return (-1); + return (mp_ncpus); +} + static int _kvm_dpcpu_setcpu(kvm_t *kd, u_int cpu, int report_error) { @@ -306,7 +316,7 @@ kvm_dpcpu_setcpu(kvm_t *kd, u_int cpu) * Obtain a per-CPU copy for given cpu from UMA_ZONE_PCPU allocation. */ ssize_t -kvm_read_zpcpu(kvm_t *kd, void *buf, u_long base, size_t size, int cpu) +kvm_read_zpcpu(kvm_t *kd, u_long base, void *buf, size_t size, int cpu) { return (kvm_read(kd, (uintptr_t)(base + sizeof(struct pcpu) * cpu), @@ -327,7 +337,7 @@ kvm_counter_u64_fetch(kvm_t *kd, u_long base) r = 0; for (int i = 0; i < mp_ncpus; i++) { - if (kvm_read_zpcpu(kd, &c, base, sizeof(c), i) != sizeof(c)) + if (kvm_read_zpcpu(kd, base, &c, sizeof(c), i) != sizeof(c)) return (0); r += c; } -- cgit v1.1