Wed Jan 29 03:04:55 2020 UTC ()
- 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.


(thorpej)
diff -r1.4 -r1.5 src/sys/net/net_stats.h

cvs diff -r1.4 -r1.5 src/sys/net/net_stats.h (expand / switch to unified diff)

--- src/sys/net/net_stats.h 2014/09/05 06:01:24 1.4
+++ src/sys/net/net_stats.h 2020/01/29 03:04:55 1.5
@@ -1,17 +1,17 @@ @@ -1,17 +1,17 @@
1/* $NetBSD: net_stats.h,v 1.4 2014/09/05 06:01:24 matt Exp $ */ 1/* $NetBSD: net_stats.h,v 1.5 2020/01/29 03:04:55 thorpej Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2008 The NetBSD Foundation, Inc. 4 * Copyright (c) 2008, 2020 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe. 8 * by Jason R. Thorpe.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the 16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution. 17 * documentation and/or other materials provided with the distribution.
@@ -25,54 +25,80 @@ @@ -25,54 +25,80 @@
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#ifndef _NET_NET_STATS_H_ 32#ifndef _NET_NET_STATS_H_
33#define _NET_NET_STATS_H_ 33#define _NET_NET_STATS_H_
34 34
35#ifdef _KERNEL 35#ifdef _KERNEL
36#include <sys/percpu.h> 36#include <sys/percpu.h>
37 37
38#define _NET_STAT_GETREF(stat) ((uint64_t *)percpu_getref((stat))) 38typedef void *net_stat_ref_t;
 39
 40#define _NET_STAT_GETREF(stat) ((net_stat_ref_t)percpu_getref((stat)))
39#define _NET_STAT_PUTREF(stat) percpu_putref((stat)) 41#define _NET_STAT_PUTREF(stat) percpu_putref((stat))
40 42
41#define _NET_STATINC(stat, x) \ 43#define _NET_STATINC_REF(r, x) \
42do { \ 44do { \
43 uint64_t *_stat_ = _NET_STAT_GETREF(stat); \ 45 uint64_t *_stat_ = (r); \
44 _stat_[x]++; \ 46 _stat_[x]++; \
 47} while (/*CONSTCOND*/0)
 48
 49#define _NET_STATINC(stat, x) \
 50do { \
 51 net_stat_ref_t _nsr_ = _NET_STAT_GETREF(stat); \
 52 _NET_STATINC_REF(_nsr_, x); \
45 _NET_STAT_PUTREF(stat); \ 53 _NET_STAT_PUTREF(stat); \
46} while (/*CONSTCOND*/0) 54} while (/*CONSTCOND*/0)
47 55
48#define _NET_STATDEC(stat, x) \ 56#define _NET_STATDEC_REF(r, x) \
49do { \ 57do { \
50 uint64_t *_stat_ = _NET_STAT_GETREF(stat); \ 58 uint64_t *_stat_ = (r); \
51 _stat_[x]--; \ 59 _stat_[x]--; \
 60} while (/*CONSTCOND*/0)
 61
 62#define _NET_STATDEC(stat, x) \
 63do { \
 64 net_stat_ref_t _nsr_ = _NET_STAT_GETREF(stat); \
 65 _NET_STATDEC_REF(_nsr_, x); \
52 _NET_STAT_PUTREF(stat); \ 66 _NET_STAT_PUTREF(stat); \
53} while (/*CONSTCOND*/0) 67} while (/*CONSTCOND*/0)
54 68
55#define _NET_STATADD(stat, x, v) \ 69#define _NET_STATADD_REF(r, x, v) \
56do { \ 70do { \
57 uint64_t *_stat_ = _NET_STAT_GETREF(stat); \ 71 uint64_t *_stat_ = (r); \
58 _stat_[x] += (v); \ 72 _stat_[x] += (v); \
 73} while (/*CONSTCOND*/0)
 74
 75#define _NET_STATADD(stat, x, v) \
 76do { \
 77 net_stat_ref_t _nsr_ = _NET_STAT_GETREF(stat); \
 78 _NET_STATADD_REF(_nsr_, x, v); \
59 _NET_STAT_PUTREF(stat); \ 79 _NET_STAT_PUTREF(stat); \
60} while (/*CONSTCOND*/0) 80} while (/*CONSTCOND*/0)
61 81
62#define _NET_STATSUB(stat, x, v) \ 82#define _NET_STATSUB_REF(r, x, v) \
63do { \ 83do { \
64 uint64_t *_stat_ = _NET_STAT_GETREF(stat); \ 84 uint64_t *_stat_ = (r); \
65 _stat_[x] -= (v); \ 85 _stat_[x] -= (v); \
 86} while (/*CONSTCOND*/0)
 87
 88#define _NET_STATSUB(stat, x, v) \
 89do { \
 90 net_stat_ref_t _nsr_ = _NET_STAT_GETREF(stat); \
 91 _NET_STATSUB_REF(_nsr_, x, v); \
66 _NET_STAT_PUTREF(stat); \ 92 _NET_STAT_PUTREF(stat); \
67} while (/*CONSTCOND*/0) 93} while (/*CONSTCOND*/0)
68 94
69__BEGIN_DECLS 95__BEGIN_DECLS
70struct lwp; 96struct lwp;
71struct sysctlnode; 97struct sysctlnode;
72 98
73int netstat_sysctl(percpu_t *, u_int, 99int netstat_sysctl(percpu_t *, u_int,
74 const int *, u_int, void *, 100 const int *, u_int, void *,
75 size_t *, const void *, size_t, 101 size_t *, const void *, size_t,
76 const int *, struct lwp *, const struct sysctlnode *); 102 const int *, struct lwp *, const struct sysctlnode *);
77 103
78#define NETSTAT_SYSCTL(stat, nctrs) \ 104#define NETSTAT_SYSCTL(stat, nctrs) \