From owner-svn-src-head@FreeBSD.ORG Tue Jul 9 10:02:52 2013 Return-Path: Delivered-To: svn-src-head@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 D42D5DC7; Tue, 9 Jul 2013 10:02:52 +0000 (UTC) (envelope-from ae@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 C6D8816B1; Tue, 9 Jul 2013 10:02:52 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r69A2qOB043271; Tue, 9 Jul 2013 10:02:52 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r69A2qsR043268; Tue, 9 Jul 2013 10:02:52 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201307091002.r69A2qsR043268@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Tue, 9 Jul 2013 10:02:52 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r253087 - in head: sys/netinet usr.bin/netstat 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.14 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: Tue, 09 Jul 2013 10:02:52 -0000 Author: ae Date: Tue Jul 9 10:02:51 2013 New Revision: 253087 URL: http://svnweb.freebsd.org/changeset/base/253087 Log: Migrate struct carpstats to PCPU counters. Modified: head/sys/netinet/ip_carp.c head/sys/netinet/ip_carp.h head/usr.bin/netstat/inet.c Modified: head/sys/netinet/ip_carp.c ============================================================================== --- head/sys/netinet/ip_carp.c Tue Jul 9 09:59:46 2013 (r253086) +++ head/sys/netinet/ip_carp.c Tue Jul 9 10:02:51 2013 (r253087) @@ -50,6 +50,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -209,9 +210,25 @@ SYSCTL_INT(_net_inet_carp, OID_AUTO, sen SYSCTL_INT(_net_inet_carp, OID_AUTO, ifdown_demotion_factor, CTLFLAG_RW, &carp_ifdown_adj, 0, "Interface down demotion factor adjustment"); -static struct carpstats carpstats; -SYSCTL_STRUCT(_net_inet_carp, OID_AUTO, stats, CTLFLAG_RW, &carpstats, - carpstats, "CARP statistics (struct carpstats, netinet/ip_carp.h)"); +static counter_u64_t carpstats[sizeof(struct carpstats) / sizeof(uint64_t)]; +#define CARPSTATS_ADD(name, val) \ + counter_u64_add(carpstats[offsetof(struct carpstats, name) / \ + sizeof(uint64_t)], (val)) +#define CARPSTATS_INC(name) CARPSTATS_ADD(name, 1) + +static int +carpstats_sysctl(SYSCTL_HANDLER_ARGS) +{ + struct carpstats s; + + COUNTER_ARRAY_COPY(carpstats, &s, sizeof(s) / sizeof(uint64_t)); + if (req->newptr) + COUNTER_ARRAY_ZERO(carpstats, sizeof(s) / sizeof(uint64_t)); + return (SYSCTL_OUT(req, &s, sizeof(s))); +} +SYSCTL_PROC(_net_inet_carp, OID_AUTO, stats, CTLTYPE_OPAQUE | CTLFLAG_RW, + NULL, 0, carpstats_sysctl, "I", + "CARP statistics (struct carpstats, netinet/ip_carp.h)"); #define CARP_LOCK_INIT(sc) mtx_init(&(sc)->sc_mtx, "carp_softc", \ NULL, MTX_DEF) @@ -2084,6 +2101,8 @@ carp_mod_cleanup(void) mtx_unlock(&carp_mtx); taskqueue_drain(taskqueue_swi, &carp_sendall_task); mtx_destroy(&carp_mtx); + COUNTER_ARRAY_FREE(carpstats, + sizeof(struct carpstats) / sizeof(uint64_t)); } static int @@ -2093,6 +2112,8 @@ carp_mod_load(void) mtx_init(&carp_mtx, "carp_mtx", NULL, MTX_DEF); LIST_INIT(&carp_list); + COUNTER_ARRAY_ALLOC(carpstats, + sizeof(struct carpstats) / sizeof(uint64_t), M_WAITOK); carp_get_vhid_p = carp_get_vhid; carp_forus_p = carp_forus; carp_output_p = carp_output; Modified: head/sys/netinet/ip_carp.h ============================================================================== --- head/sys/netinet/ip_carp.h Tue Jul 9 09:59:46 2013 (r253086) +++ head/sys/netinet/ip_carp.h Tue Jul 9 10:02:51 2013 (r253087) @@ -117,11 +117,6 @@ struct carpstats { uint64_t carps_preempt; /* if enabled, preemptions */ }; -#ifdef _KERNEL -#define CARPSTATS_ADD(name, val) carpstats.name += (val) -#define CARPSTATS_INC(name) CARPSTATS_ADD(name, 1) -#endif - /* * Configuration structure for SIOCSVH SIOCGVH */ Modified: head/usr.bin/netstat/inet.c ============================================================================== --- head/usr.bin/netstat/inet.c Tue Jul 9 09:59:46 2013 (r253086) +++ head/usr.bin/netstat/inet.c Tue Jul 9 10:02:51 2013 (r253087) @@ -811,7 +811,7 @@ carp_stats(u_long off, const char *name, } else { if (off == 0) return; - kread(off, &carpstat, len); + kread_counters(off, &carpstat, len); } printf("%s:\n", name);