diff options
author | ae <ae@FreeBSD.org> | 2013-07-09 09:37:21 +0000 |
---|---|---|
committer | ae <ae@FreeBSD.org> | 2013-07-09 09:37:21 +0000 |
commit | 027c687189cc0647592f671691e0a08064401c1d (patch) | |
tree | bb1321b60c85eceb0561d4bd22fdd6629839f34d /sys/net | |
parent | 1a36dfcc879833c6fdc45e20d39db618b110f55c (diff) | |
download | FreeBSD-src-027c687189cc0647592f671691e0a08064401c1d.zip FreeBSD-src-027c687189cc0647592f671691e0a08064401c1d.tar.gz |
Add several macros to help migrate statistics structures to PCPU counters.
Diffstat (limited to 'sys/net')
-rw-r--r-- | sys/net/vnet.h | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/sys/net/vnet.h b/sys/net/vnet.h index 6bdf163..7836f6b 100644 --- a/sys/net/vnet.h +++ b/sys/net/vnet.h @@ -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 */ |