From owner-svn-src-projects@FreeBSD.ORG Sun Mar 17 07:49:45 2013 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 0A76A50F; Sun, 17 Mar 2013 07:49:45 +0000 (UTC) (envelope-from glebius@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id C35336ED; Sun, 17 Mar 2013 07:49:44 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.6/8.14.6) with ESMTP id r2H7niMo001997; Sun, 17 Mar 2013 07:49:44 GMT (envelope-from glebius@svn.freebsd.org) Received: (from glebius@localhost) by svn.freebsd.org (8.14.6/8.14.5/Submit) id r2H7nim0001995; Sun, 17 Mar 2013 07:49:44 GMT (envelope-from glebius@svn.freebsd.org) Message-Id: <201303170749.r2H7nim0001995@svn.freebsd.org> From: Gleb Smirnoff Date: Sun, 17 Mar 2013 07:49:44 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r248420 - in projects/counters/sys: kern sys X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 17 Mar 2013 07:49:45 -0000 Author: glebius Date: Sun Mar 17 07:49:44 2013 New Revision: 248420 URL: http://svnweb.freebsd.org/changeset/base/248420 Log: Provide generic sysctl handler and macros for counter(9). Modified: projects/counters/sys/kern/subr_counter.c projects/counters/sys/sys/sysctl.h Modified: projects/counters/sys/kern/subr_counter.c ============================================================================== --- projects/counters/sys/kern/subr_counter.c Sun Mar 17 07:47:00 2013 (r248419) +++ projects/counters/sys/kern/subr_counter.c Sun Mar 17 07:49:44 2013 (r248420) @@ -32,6 +32,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include static uma_zone_t uint64_pcpu_zone; @@ -77,6 +78,30 @@ counter_u64_free(counter_u64_t c) uma_zfree(uint64_pcpu_zone, c); } +int +sysctl_handle_counter_u64(SYSCTL_HANDLER_ARGS) +{ + uint64_t out; + int error; + + out = counter_u64_fetch(*(counter_u64_t *)arg1); + + error = SYSCTL_OUT(req, &out, sizeof(uint64_t)); + + if (error || !req->newptr) + return (error); + + if (!arg1) + return (EPERM); + + /* + * Any write attempt to a counter zeroes it. + */ + counter_u64_zero(*(counter_u64_t *)arg1); + + return (0); +} + static void counter_startup(void) { Modified: projects/counters/sys/sys/sysctl.h ============================================================================== --- projects/counters/sys/sys/sysctl.h Sun Mar 17 07:47:00 2013 (r248419) +++ projects/counters/sys/sys/sysctl.h Sun Mar 17 07:49:44 2013 (r248420) @@ -184,6 +184,7 @@ int sysctl_handle_long(SYSCTL_HANDLER_AR int sysctl_handle_64(SYSCTL_HANDLER_ARGS); int sysctl_handle_string(SYSCTL_HANDLER_ARGS); int sysctl_handle_opaque(SYSCTL_HANDLER_ARGS); +int sysctl_handle_counter_u64(SYSCTL_HANDLER_ARGS); int sysctl_dpcpu_int(SYSCTL_HANDLER_ARGS); int sysctl_dpcpu_long(SYSCTL_HANDLER_ARGS); @@ -379,6 +380,18 @@ SYSCTL_ALLOWED_TYPES(UINT64, uint64_t *a SYSCTL_ADD_ASSERT_TYPE(UINT64, ptr), 0, \ sysctl_handle_64, "QU", __DESCR(descr)) +#define SYSCTL_COUNTER_U64(parent, nbr, name, access, ptr, val, descr) \ + SYSCTL_ASSERT_TYPE(UINT64, ptr, parent, name); \ + SYSCTL_OID(parent, nbr, name, \ + CTLTYPE_U64 | CTLFLAG_MPSAFE | (access), \ + ptr, val, sysctl_handle_counter_u64, "QU", descr) + +#define SYSCTL_ADD_COUNTER_U64(ctx, parent, nbr, name, access, ptr, descr)\ + sysctl_add_oid(ctx, parent, nbr, name, \ + CTLTYPE_U64 | CTLFLAG_MPSAFE | (access), \ + SYSCTL_ADD_ASSERT_TYPE(UINT64, ptr), 0, \ + sysctl_handle_counter_u64, "QU", __DESCR(descr)) + /* Oid for an opaque object. Specified by a pointer and a length. */ #define SYSCTL_OPAQUE(parent, nbr, name, access, ptr, len, fmt, descr) \ SYSCTL_OID(parent, nbr, name, CTLTYPE_OPAQUE|(access), \