From owner-svn-src-head@FreeBSD.ORG Wed Feb 12 19:22:50 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 0C4DC4A7; Wed, 12 Feb 2014 19:22:50 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id D16D81486; Wed, 12 Feb 2014 19:22:49 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s1CJMnun045051; Wed, 12 Feb 2014 19:22:49 GMT (envelope-from glebius@svn.freebsd.org) Received: (from glebius@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s1CJMnXS045036; Wed, 12 Feb 2014 19:22:49 GMT (envelope-from glebius@svn.freebsd.org) Message-Id: <201402121922.s1CJMnXS045036@svn.freebsd.org> From: Gleb Smirnoff Date: Wed, 12 Feb 2014 19:22:49 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r261805 - head/lib/libkvm X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 12 Feb 2014 19:22:50 -0000 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) {