Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/net - Make _NET_STAT_GETREF()'s return value a net_stat_...
details: https://anonhg.NetBSD.org/src/rev/075daa990006
branches: trunk
changeset: 1006830:075daa990006
user: thorpej <thorpej%NetBSD.org@localhost>
date: Wed Jan 29 03:04:55 2020 +0000
description:
- Make _NET_STAT_GETREF()'s return value a net_stat_ref_t, which is
defined as a "void *" to prevent using a net_stat_ref_t as an array.
- For each _NET_STATADD(), etc. macro, also define a _NET_STATADD_REF()
macro that takes a ref returned by _NET_STAT_GETREF() as an argument.
This is intended to replace direct subscripting of the refernce;
consumers of this API will be updated in future commits.
diffstat:
sys/net/net_stats.h | 48 +++++++++++++++++++++++++++++++++++++-----------
1 files changed, 37 insertions(+), 11 deletions(-)
diffs (83 lines):
diff -r 79a1ca58ab12 -r 075daa990006 sys/net/net_stats.h
--- a/sys/net/net_stats.h Wed Jan 29 02:58:51 2020 +0000
+++ b/sys/net/net_stats.h Wed Jan 29 03:04:55 2020 +0000
@@ -1,7 +1,7 @@
-/* $NetBSD: net_stats.h,v 1.4 2014/09/05 06:01:24 matt Exp $ */
+/* $NetBSD: net_stats.h,v 1.5 2020/01/29 03:04:55 thorpej Exp $ */
/*-
- * Copyright (c) 2008 The NetBSD Foundation, Inc.
+ * Copyright (c) 2008, 2020 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@@ -35,34 +35,60 @@
#ifdef _KERNEL
#include <sys/percpu.h>
-#define _NET_STAT_GETREF(stat) ((uint64_t *)percpu_getref((stat)))
+typedef void *net_stat_ref_t;
+
+#define _NET_STAT_GETREF(stat) ((net_stat_ref_t)percpu_getref((stat)))
#define _NET_STAT_PUTREF(stat) percpu_putref((stat))
+#define _NET_STATINC_REF(r, x) \
+do { \
+ uint64_t *_stat_ = (r); \
+ _stat_[x]++; \
+} while (/*CONSTCOND*/0)
+
#define _NET_STATINC(stat, x) \
do { \
- uint64_t *_stat_ = _NET_STAT_GETREF(stat); \
- _stat_[x]++; \
+ net_stat_ref_t _nsr_ = _NET_STAT_GETREF(stat); \
+ _NET_STATINC_REF(_nsr_, x); \
_NET_STAT_PUTREF(stat); \
} while (/*CONSTCOND*/0)
+#define _NET_STATDEC_REF(r, x) \
+do { \
+ uint64_t *_stat_ = (r); \
+ _stat_[x]--; \
+} while (/*CONSTCOND*/0)
+
#define _NET_STATDEC(stat, x) \
do { \
- uint64_t *_stat_ = _NET_STAT_GETREF(stat); \
- _stat_[x]--; \
+ net_stat_ref_t _nsr_ = _NET_STAT_GETREF(stat); \
+ _NET_STATDEC_REF(_nsr_, x); \
_NET_STAT_PUTREF(stat); \
} while (/*CONSTCOND*/0)
+#define _NET_STATADD_REF(r, x, v) \
+do { \
+ uint64_t *_stat_ = (r); \
+ _stat_[x] += (v); \
+} while (/*CONSTCOND*/0)
+
#define _NET_STATADD(stat, x, v) \
do { \
- uint64_t *_stat_ = _NET_STAT_GETREF(stat); \
- _stat_[x] += (v); \
+ net_stat_ref_t _nsr_ = _NET_STAT_GETREF(stat); \
+ _NET_STATADD_REF(_nsr_, x, v); \
_NET_STAT_PUTREF(stat); \
} while (/*CONSTCOND*/0)
+#define _NET_STATSUB_REF(r, x, v) \
+do { \
+ uint64_t *_stat_ = (r); \
+ _stat_[x] -= (v); \
+} while (/*CONSTCOND*/0)
+
#define _NET_STATSUB(stat, x, v) \
do { \
- uint64_t *_stat_ = _NET_STAT_GETREF(stat); \
- _stat_[x] -= (v); \
+ net_stat_ref_t _nsr_ = _NET_STAT_GETREF(stat); \
+ _NET_STATSUB_REF(_nsr_, x, v); \
_NET_STAT_PUTREF(stat); \
} while (/*CONSTCOND*/0)
Home |
Main Index |
Thread Index |
Old Index