diff options
author | glebius <glebius@FreeBSD.org> | 2014-02-12 19:22:48 +0000 |
---|---|---|
committer | glebius <glebius@FreeBSD.org> | 2014-02-12 19:22:48 +0000 |
commit | d231df0ee2698e42fce6474a0d4168002867b271 (patch) | |
tree | 1a3e3b22110536177e40ea0bada12db4e0ffb383 /lib | |
parent | 5e1e2540f9777d999e322a3969bc45cb65e2a868 (diff) | |
download | FreeBSD-src-d231df0ee2698e42fce6474a0d4168002867b271.zip FreeBSD-src-d231df0ee2698e42fce6474a0d4168002867b271.tar.gz |
Add kvm_getncpus() to obtain mp_ncpus.
Sponsored by: Nginx, Inc.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libkvm/kvm.h | 1 | ||||
-rw-r--r-- | lib/libkvm/kvm_getpcpu.3 | 8 | ||||
-rw-r--r-- | lib/libkvm/kvm_pcpu.c | 10 |
3 files changed, 18 insertions, 1 deletions
diff --git a/lib/libkvm/kvm.h b/lib/libkvm/kvm.h index b99a5ef..d697795 100644 --- a/lib/libkvm/kvm.h +++ b/lib/libkvm/kvm.h @@ -77,6 +77,7 @@ char *kvm_geterr(kvm_t *); char *kvm_getfiles(kvm_t *, int, int, int *); int kvm_getloadavg(kvm_t *, double [], int); int kvm_getmaxcpu(kvm_t *); +int kvm_getncpus(kvm_t *); void *kvm_getpcpu(kvm_t *, int); uint64_t kvm_counter_u64_fetch(kvm_t *, u_long); struct kinfo_proc * diff --git a/lib/libkvm/kvm_getpcpu.3 b/lib/libkvm/kvm_getpcpu.3 index d1eb9b1..13192c2 100644 --- a/lib/libkvm/kvm_getpcpu.3 +++ b/lib/libkvm/kvm_getpcpu.3 @@ -28,7 +28,7 @@ .\" .\" $FreeBSD$ .\" -.Dd April 11, 2013 +.Dd February 12, 2014 .Dt KVM_GETPCPU 3 .Os .Sh NAME @@ -47,6 +47,8 @@ .Fn kvm_dpcpu_setcpu "kvm_t *kd" "u_int cpu" .Ft int .Fn kvm_getmaxcpu "kvm_t *kd" +.Ft int +.Fn kvm_getncpus "kvm_t *kd" .Ft void * .Fn kvm_getpcpu "kvm_t *kd" "int cpu" .Ft ssize_t @@ -73,6 +75,10 @@ The function returns the maximum number of CPUs supported by the kernel. .Pp The +.Fn kvm_getncpus +function returns the current number of CPUs in the kernel. +.Pp +The .Fn kvm_getpcpu function returns a buffer holding the per-CPU data for a single CPU. This buffer is described by the diff --git a/lib/libkvm/kvm_pcpu.c b/lib/libkvm/kvm_pcpu.c index ff7c119..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) { |