Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 12 Feb 2014 19:22:49 +0000 (UTC)
From:      Gleb Smirnoff <glebius@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r261805 - head/lib/libkvm
Message-ID:  <201402121922.s1CJMnXS045036@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: glebius
Date: Wed Feb 12 19:22:48 2014
New Revision: 261805
URL: http://svnweb.freebsd.org/changeset/base/261805

Log:
  Add kvm_getncpus() to obtain mp_ncpus.
  
  Sponsored by:	Nginx, Inc.

Modified:
  head/lib/libkvm/kvm.h
  head/lib/libkvm/kvm_getpcpu.3
  head/lib/libkvm/kvm_pcpu.c

Modified: head/lib/libkvm/kvm.h
==============================================================================
--- head/lib/libkvm/kvm.h	Wed Feb 12 19:07:59 2014	(r261804)
+++ head/lib/libkvm/kvm.h	Wed Feb 12 19:22:48 2014	(r261805)
@@ -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 *

Modified: head/lib/libkvm/kvm_getpcpu.3
==============================================================================
--- head/lib/libkvm/kvm_getpcpu.3	Wed Feb 12 19:07:59 2014	(r261804)
+++ head/lib/libkvm/kvm_getpcpu.3	Wed Feb 12 19:22:48 2014	(r261805)
@@ -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

Modified: head/lib/libkvm/kvm_pcpu.c
==============================================================================
--- head/lib/libkvm/kvm_pcpu.c	Wed Feb 12 19:07:59 2014	(r261804)
+++ head/lib/libkvm/kvm_pcpu.c	Wed Feb 12 19:22:48 2014	(r261805)
@@ -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)
 {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201402121922.s1CJMnXS045036>