Author: ae Date: Tue Jul 9 09:37:21 2013 New Revision: 253082 URL: http://svnweb.freebsd.org/changeset/base/253082
Log: Add several macros to help migrate statistics structures to PCPU counters. Modified: head/sys/net/vnet.h head/sys/sys/counter.h Modified: head/sys/net/vnet.h ============================================================================== --- head/sys/net/vnet.h Tue Jul 9 09:32:06 2013 (r253081) +++ head/sys/net/vnet.h Tue Jul 9 09:37:21 2013 (r253082) @@ -85,6 +85,55 @@ struct vnet { #ifdef _KERNEL +#define VNET_PCPUSTAT_DECLARE(type, name) \ + VNET_DECLARE(counter_u64_t, name[sizeof(type) / sizeof(uint64_t)]) + +#define VNET_PCPUSTAT_DEFINE(type, name) \ + VNET_DEFINE(counter_u64_t, name[sizeof(type) / sizeof(uint64_t)]) + +#define VNET_PCPUSTAT_ALLOC(name, wait) \ + COUNTER_ARRAY_ALLOC(VNET(name), \ + sizeof(VNET(name)) / sizeof(counter_u64_t), (wait)) + +#define VNET_PCPUSTAT_FREE(name) \ + COUNTER_ARRAY_FREE(VNET(name), sizeof(VNET(name)) / sizeof(counter_u64_t)) + +#define VNET_PCPUSTAT_ADD(type, name, f, v) \ + counter_u64_add(VNET(name)[offsetof(type, f) / sizeof(uint64_t)], (v)) + +#define VNET_PCPUSTAT_SYSINIT(name) \ +static void \ +vnet_##name##_init(const void *unused) \ +{ \ + VNET_PCPUSTAT_ALLOC(name, M_WAITOK); \ +} \ +VNET_SYSINIT(vnet_ ## name ## _init, SI_SUB_PROTO_IFATTACHDOMAIN, \ + SI_ORDER_ANY, vnet_ ## name ## _init, NULL) + +#define VNET_PCPUSTAT_SYSUNINIT(name) \ +static void \ +vnet_##name##_uninit(const void *unused) \ +{ \ + VNET_PCPUSTAT_FREE(name); \ +} \ +VNET_SYSUNINIT(vnet_ ## name ## _uninit, SI_SUB_PROTO_IFATTACHDOMAIN, \ + SI_ORDER_ANY, vnet_ ## name ## _uninit, NULL) + +#define SYSCTL_VNET_PCPUSTAT(parent, nbr, name, type, array, desc) \ +static int \ +array##_sysctl(SYSCTL_HANDLER_ARGS) \ +{ \ + type s; \ + CTASSERT(sizeof(type) == sizeof(VNET(array))); \ + COUNTER_ARRAY_COPY(VNET(array), &s, sizeof(type) / sizeof(uint64_t));\ + if (req->newptr) \ + COUNTER_ARRAY_ZERO(VNET(array), \ + sizeof(type) / sizeof(uint64_t)); \ + return (SYSCTL_OUT(req, &s, sizeof(type))); \ +} \ +SYSCTL_VNET_PROC(parent, nbr, name, CTLTYPE_OPAQUE | CTLFLAG_RW, NULL, \ + 0, array ## _sysctl, "I", desc) + #ifdef VIMAGE #include <sys/lock.h> #include <sys/proc.h> /* for struct thread */ Modified: head/sys/sys/counter.h ============================================================================== --- head/sys/sys/counter.h Tue Jul 9 09:32:06 2013 (r253081) +++ head/sys/sys/counter.h Tue Jul 9 09:37:21 2013 (r253082) @@ -39,4 +39,23 @@ void counter_u64_free(counter_u64_t); void counter_u64_zero(counter_u64_t); uint64_t counter_u64_fetch(counter_u64_t); +#define COUNTER_ARRAY_ALLOC(a, n, wait) do { \ + for (int i = 0; i < (n); i++) \ + (a)[i] = counter_u64_alloc(wait); \ +} while (0) + +#define COUNTER_ARRAY_FREE(a, n) do { \ + for (int i = 0; i < (n); i++) \ + counter_u64_free((a)[i]); \ +} while (0) + +#define COUNTER_ARRAY_COPY(a, dstp, n) do { \ + for (int i = 0; i < (n); i++) \ + ((uint64_t *)(dstp))[i] = counter_u64_fetch((a)[i]);\ +} while (0) + +#define COUNTER_ARRAY_ZERO(a, n) do { \ + for (int i = 0; i < (n); i++) \ + counter_u64_zero((a)[i]); \ +} while (0) #endif /* ! __SYS_COUNTER_H__ */ _______________________________________________ svn-src-head@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"