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.
This commit is contained in:
glebius 2014-03-04 14:49:05 +00:00
parent 8a9528c4d0
commit 1b9278cc98
3 changed files with 22 additions and 5 deletions

View File

@ -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 *
@ -88,7 +89,7 @@ kvm_t *kvm_open
kvm_t *kvm_openfiles
(const char *, const char *, const char *, int, char *);
ssize_t kvm_read(kvm_t *, unsigned long, void *, size_t);
ssize_t kvm_read_zpcpu(kvm_t *, void *, u_long, size_t, int);
ssize_t kvm_read_zpcpu(kvm_t *, unsigned long, void *, size_t, int);
ssize_t kvm_write(kvm_t *, unsigned long, const void *, size_t);
__END_DECLS

View File

@ -28,7 +28,7 @@
.\"
.\" $FreeBSD$
.\"
.Dd April 11, 2013
.Dd February 12, 2014
.Dt KVM_GETPCPU 3
.Os
.Sh NAME
@ -47,10 +47,12 @@
.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
.Fn kvm_read_zpcpu "kvm_t *kd" "void *buf" "u_long base" "size_t size" "int cpu"
.Fn kvm_read_zpcpu "kvm_t *kd" "u_long base" "void *buf" "size_t size" "int cpu"
.Ft uint64_t
.Fn kvm_counter_u64_fetch "kvm_t *kd" "u_long base"
.Sh DESCRIPTION
@ -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

View File

@ -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;
}