From: mpi Date: Sat, 16 Sep 2023 09:33:27 +0000 (+0000) Subject: Allow counters_read(9) to take an optional scratch buffer. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=bf0d449c49808ab2d0a67677895f728770d3c8af;p=openbsd Allow counters_read(9) to take an optional scratch buffer. Using a scratch buffer makes it possible to take a consistent snapshot of per-CPU counters without having to allocate memory. Makes ddb(4) show uvmexp command work in OOM situations. ok kn@, mvs@, cheloha@ --- diff --git a/share/man/man9/counters_alloc.9 b/share/man/man9/counters_alloc.9 index 1de8bffc639..01d343d356c 100644 --- a/share/man/man9/counters_alloc.9 +++ b/share/man/man9/counters_alloc.9 @@ -1,4 +1,4 @@ -.\" $OpenBSD: counters_alloc.9,v 1.12 2022/02/20 23:11:01 dlg Exp $ +.\" $OpenBSD: counters_alloc.9,v 1.13 2023/09/16 09:33:28 mpi Exp $ .\" .\" Copyright (c) 2016 David Gwynne .\" @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: February 20 2022 $ +.Dd $Mdocdate: September 16 2023 $ .Dt COUNTERS_ALLOC 9 .Os .Sh NAME @@ -64,6 +64,7 @@ .Fa "struct cpumem *cm" .Fa "uint64_t *counters" .Fa "unsigned int ncounters" +.Fa "uint64_t *scratch" .Fc .Ft void .Fn counters_zero "struct cpumem *cm" "unsigned int ncounters" @@ -191,6 +192,12 @@ The sum of the counters is written to the array. The number of counters is specified with .Fa ncounters . +.Fa scratch +may point to a buffer used to temporarily hold +.Fa counters . +If +.Dv NULL , +one will be dynamically allocated and freed. .Pp .Fn counters_zero iterates over each CPU's set of counters referenced by diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c index 10c6b5acad8..07d9a6f9e80 100644 --- a/sys/kern/kern_sysctl.c +++ b/sys/kern/kern_sysctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_sysctl.c,v 1.418 2023/07/16 03:01:31 yasuoka Exp $ */ +/* $OpenBSD: kern_sysctl.c,v 1.419 2023/09/16 09:33:27 mpi Exp $ */ /* $NetBSD: kern_sysctl.c,v 1.17 1996/05/20 17:49:05 mrg Exp $ */ /*- @@ -519,7 +519,7 @@ kern_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, unsigned int i; memset(&mbs, 0, sizeof(mbs)); - counters_read(mbstat, counters, MBSTAT_COUNT); + counters_read(mbstat, counters, MBSTAT_COUNT, NULL); for (i = 0; i < MBSTAT_TYPES; i++) mbs.m_mtypes[i] = counters[i]; diff --git a/sys/kern/subr_evcount.c b/sys/kern/subr_evcount.c index c77c953630d..a1ed2ee7c3b 100644 --- a/sys/kern/subr_evcount.c +++ b/sys/kern/subr_evcount.c @@ -1,4 +1,4 @@ -/* $OpenBSD: subr_evcount.c,v 1.15 2022/12/05 08:58:49 visa Exp $ */ +/* $OpenBSD: subr_evcount.c,v 1.16 2023/09/16 09:33:27 mpi Exp $ */ /* * Copyright (c) 2004 Artur Grabowski * Copyright (c) 2004 Aaron Campbell @@ -101,7 +101,7 @@ evcount_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, { int error = 0, s, nintr, i; struct evcount *ec; - u_int64_t count; + uint64_t count, scratch; if (newp != NULL) return (EPERM); @@ -129,7 +129,7 @@ evcount_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, if (ec == NULL) return (ENOENT); if (ec->ec_percpu != NULL) { - counters_read(ec->ec_percpu, &count, 1); + counters_read(ec->ec_percpu, &count, 1, &scratch); } else { s = splhigh(); count = ec->ec_count; diff --git a/sys/kern/subr_percpu.c b/sys/kern/subr_percpu.c index 4cc66d0b81e..6c03becf49e 100644 --- a/sys/kern/subr_percpu.c +++ b/sys/kern/subr_percpu.c @@ -1,4 +1,4 @@ -/* $OpenBSD: subr_percpu.c,v 1.10 2022/10/03 14:10:53 bluhm Exp $ */ +/* $OpenBSD: subr_percpu.c,v 1.11 2023/09/16 09:33:27 mpi Exp $ */ /* * Copyright (c) 2016 David Gwynne @@ -159,17 +159,19 @@ counters_free(struct cpumem *cm, unsigned int n) } void -counters_read(struct cpumem *cm, uint64_t *output, unsigned int n) +counters_read(struct cpumem *cm, uint64_t *output, unsigned int n, + uint64_t *scratch) { struct cpumem_iter cmi; - uint64_t *gen, *counters, *temp; + uint64_t *gen, *counters, *temp = scratch; uint64_t enter, leave; unsigned int i; for (i = 0; i < n; i++) output[i] = 0; - temp = mallocarray(n, sizeof(uint64_t), M_TEMP, M_WAITOK); + if (scratch == NULL) + temp = mallocarray(n, sizeof(uint64_t), M_TEMP, M_WAITOK); gen = cpumem_first(&cmi, cm); do { @@ -202,7 +204,8 @@ counters_read(struct cpumem *cm, uint64_t *output, unsigned int n) gen = cpumem_next(&cmi, cm); } while (gen != NULL); - free(temp, M_TEMP, n * sizeof(uint64_t)); + if (scratch == NULL) + free(temp, M_TEMP, n * sizeof(uint64_t)); } void @@ -305,7 +308,8 @@ counters_free(struct cpumem *cm, unsigned int n) } void -counters_read(struct cpumem *cm, uint64_t *output, unsigned int n) +counters_read(struct cpumem *cm, uint64_t *output, unsigned int n, + uint64_t *scratch) { uint64_t *counters; unsigned int i; diff --git a/sys/net/if.c b/sys/net/if.c index 7f60292fdb1..94ebb42744a 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if.c,v 1.707 2023/08/18 08:10:16 jsg Exp $ */ +/* $OpenBSD: if.c,v 1.708 2023/09/16 09:33:27 mpi Exp $ */ /* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */ /* @@ -2797,7 +2797,8 @@ if_getdata(struct ifnet *ifp, struct if_data *data) if (ifp->if_counters != NULL) { uint64_t counters[ifc_ncounters]; - counters_read(ifp->if_counters, counters, nitems(counters)); + counters_read(ifp->if_counters, counters, nitems(counters), + NULL); data->ifi_ipackets += counters[ifc_ipackets]; data->ifi_ierrors += counters[ifc_ierrors]; diff --git a/sys/net/if_etherip.c b/sys/net/if_etherip.c index 3abc9d4b5aa..4abd3f167e4 100644 --- a/sys/net/if_etherip.c +++ b/sys/net/if_etherip.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_etherip.c,v 1.50 2022/02/28 00:12:11 dlg Exp $ */ +/* $OpenBSD: if_etherip.c,v 1.51 2023/09/16 09:33:27 mpi Exp $ */ /* * Copyright (c) 2015 Kazuya GODA * @@ -789,7 +789,7 @@ etherip_sysctl_etheripstat(void *oldp, size_t *oldlenp, void *newp) sizeof(uint64_t))); memset(ðeripstat, 0, sizeof etheripstat); counters_read(etheripcounters, (uint64_t *)ðeripstat, - etherips_ncounters); + etherips_ncounters, NULL); return (sysctl_rdstruct(oldp, oldlenp, newp, ðeripstat, sizeof(etheripstat))); } diff --git a/sys/net/if_pfsync.c b/sys/net/if_pfsync.c index d57a0250210..0a067bc547f 100644 --- a/sys/net/if_pfsync.c +++ b/sys/net/if_pfsync.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_pfsync.c,v 1.320 2023/08/18 08:03:57 jsg Exp $ */ +/* $OpenBSD: if_pfsync.c,v 1.321 2023/09/16 09:33:27 mpi Exp $ */ /* * Copyright (c) 2002 Michael Shalayeff @@ -3339,7 +3339,7 @@ pfsync_sysctl_pfsyncstat(void *oldp, size_t *oldlenp, void *newp) CTASSERT(sizeof(pfsyncstat) == (pfsyncs_ncounters * sizeof(uint64_t))); memset(&pfsyncstat, 0, sizeof pfsyncstat); counters_read(pfsynccounters, (uint64_t *)&pfsyncstat, - pfsyncs_ncounters); + pfsyncs_ncounters, NULL); return (sysctl_rdstruct(oldp, oldlenp, newp, &pfsyncstat, sizeof(pfsyncstat))); } diff --git a/sys/net/pfkeyv2_convert.c b/sys/net/pfkeyv2_convert.c index 68686055a11..83a1feb614e 100644 --- a/sys/net/pfkeyv2_convert.c +++ b/sys/net/pfkeyv2_convert.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pfkeyv2_convert.c,v 1.80 2023/08/07 03:35:06 dlg Exp $ */ +/* $OpenBSD: pfkeyv2_convert.c,v 1.81 2023/09/16 09:33:27 mpi Exp $ */ /* * The author of this code is Angelos D. Keromytis (angelos@keromytis.org) * @@ -992,7 +992,7 @@ export_counter(void **p, struct tdb *tdb) uint64_t counters[tdb_ncounters]; struct sadb_x_counter *scnt = (struct sadb_x_counter *)*p; - counters_read(tdb->tdb_counters, counters, tdb_ncounters); + counters_read(tdb->tdb_counters, counters, tdb_ncounters, NULL); scnt->sadb_x_counter_len = sizeof(struct sadb_x_counter) / sizeof(uint64_t); diff --git a/sys/net/pipex.c b/sys/net/pipex.c index 3a1a524c669..71bd7bbec25 100644 --- a/sys/net/pipex.c +++ b/sys/net/pipex.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pipex.c,v 1.148 2022/08/30 19:42:29 bluhm Exp $ */ +/* $OpenBSD: pipex.c,v 1.149 2023/09/16 09:33:27 mpi Exp $ */ /*- * Copyright (c) 2009 Internet Initiative Japan Inc. @@ -558,7 +558,7 @@ pipex_export_session_stats(struct pipex_session *session, memset(stats, 0, sizeof(*stats)); - counters_read(session->stat_counters, counters, pxc_ncounters); + counters_read(session->stat_counters, counters, pxc_ncounters, NULL); stats->ipackets = counters[pxc_ipackets]; stats->ierrors = counters[pxc_ierrors]; stats->ibytes = counters[pxc_ibytes]; diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c index d7c5763df5b..d7b6d1907a3 100644 --- a/sys/net/rtsock.c +++ b/sys/net/rtsock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtsock.c,v 1.369 2023/07/28 09:33:16 mvs Exp $ */ +/* $OpenBSD: rtsock.c,v 1.370 2023/09/16 09:33:27 mpi Exp $ */ /* $NetBSD: rtsock.c,v 1.18 1996/03/29 00:32:10 cgd Exp $ */ /* @@ -2245,7 +2245,7 @@ sysctl_rtable_rtstat(void *oldp, size_t *oldlenp, void *newp) CTASSERT(sizeof(rtstat) == (nitems(counters) * sizeof(uint32_t))); memset(&rtstat, 0, sizeof rtstat); - counters_read(rtcounters, counters, nitems(counters)); + counters_read(rtcounters, counters, nitems(counters), NULL); for (i = 0; i < nitems(counters); i++) words[i] = (uint32_t)counters[i]; diff --git a/sys/netinet/igmp.c b/sys/netinet/igmp.c index 82b6cb5d090..00dba7d2088 100644 --- a/sys/netinet/igmp.c +++ b/sys/netinet/igmp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: igmp.c,v 1.82 2022/09/08 10:22:06 kn Exp $ */ +/* $OpenBSD: igmp.c,v 1.83 2023/09/16 09:33:27 mpi Exp $ */ /* $NetBSD: igmp.c,v 1.15 1996/02/13 23:41:25 christos Exp $ */ /* @@ -687,7 +687,7 @@ igmp_sysctl_igmpstat(void *oldp, size_t *oldlenp, void *newp) CTASSERT(sizeof(igmpstat) == (nitems(counters) * sizeof(u_long))); memset(&igmpstat, 0, sizeof igmpstat); - counters_read(igmpcounters, counters, nitems(counters)); + counters_read(igmpcounters, counters, nitems(counters), NULL); for (i = 0; i < nitems(counters); i++) words[i] = (u_long)counters[i]; diff --git a/sys/netinet/ip_carp.c b/sys/netinet/ip_carp.c index 064c4424910..9aae24d5dde 100644 --- a/sys/netinet/ip_carp.c +++ b/sys/netinet/ip_carp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_carp.c,v 1.357 2023/05/16 14:32:54 jan Exp $ */ +/* $OpenBSD: ip_carp.c,v 1.358 2023/09/16 09:33:27 mpi Exp $ */ /* * Copyright (c) 2002 Michael Shalayeff. All rights reserved. @@ -749,7 +749,8 @@ carp_sysctl_carpstat(void *oldp, size_t *oldlenp, void *newp) CTASSERT(sizeof(carpstat) == (carps_ncounters * sizeof(uint64_t))); memset(&carpstat, 0, sizeof carpstat); - counters_read(carpcounters, (uint64_t *)&carpstat, carps_ncounters); + counters_read(carpcounters, (uint64_t *)&carpstat, carps_ncounters, + NULL); return (sysctl_rdstruct(oldp, oldlenp, newp, &carpstat, sizeof(carpstat))); } diff --git a/sys/netinet/ip_divert.c b/sys/netinet/ip_divert.c index acb00eb853c..b21569e7205 100644 --- a/sys/netinet/ip_divert.c +++ b/sys/netinet/ip_divert.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_divert.c,v 1.91 2023/05/13 13:35:17 bluhm Exp $ */ +/* $OpenBSD: ip_divert.c,v 1.92 2023/09/16 09:33:27 mpi Exp $ */ /* * Copyright (c) 2009 Michele Marchetto @@ -350,7 +350,7 @@ divert_sysctl_divstat(void *oldp, size_t *oldlenp, void *newp) CTASSERT(sizeof(divstat) == (nitems(counters) * sizeof(u_long))); memset(&divstat, 0, sizeof divstat); - counters_read(divcounters, counters, nitems(counters)); + counters_read(divcounters, counters, nitems(counters), NULL); for (i = 0; i < nitems(counters); i++) words[i] = (u_long)counters[i]; diff --git a/sys/netinet/ip_icmp.c b/sys/netinet/ip_icmp.c index 44811886c26..30bec63a512 100644 --- a/sys/netinet/ip_icmp.c +++ b/sys/netinet/ip_icmp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_icmp.c,v 1.191 2022/05/05 13:57:40 claudio Exp $ */ +/* $OpenBSD: ip_icmp.c,v 1.192 2023/09/16 09:33:27 mpi Exp $ */ /* $NetBSD: ip_icmp.c,v 1.19 1996/02/13 23:42:22 christos Exp $ */ /* @@ -917,7 +917,7 @@ icmp_sysctl_icmpstat(void *oldp, size_t *oldlenp, void *newp) CTASSERT(sizeof(icmpstat) == (nitems(counters) * sizeof(u_long))); memset(&icmpstat, 0, sizeof icmpstat); - counters_read(icmpcounters, counters, nitems(counters)); + counters_read(icmpcounters, counters, nitems(counters), NULL); for (i = 0; i < nitems(counters); i++) words[i] = (u_long)counters[i]; diff --git a/sys/netinet/ip_input.c b/sys/netinet/ip_input.c index 5db74552c14..279252353cc 100644 --- a/sys/netinet/ip_input.c +++ b/sys/netinet/ip_input.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_input.c,v 1.386 2023/09/06 11:09:43 bluhm Exp $ */ +/* $OpenBSD: ip_input.c,v 1.387 2023/09/16 09:33:27 mpi Exp $ */ /* $NetBSD: ip_input.c,v 1.30 1996/03/16 23:53:58 christos Exp $ */ /* @@ -1747,7 +1747,7 @@ ip_sysctl_ipstat(void *oldp, size_t *oldlenp, void *newp) CTASSERT(sizeof(ipstat) == (nitems(counters) * sizeof(u_long))); memset(&ipstat, 0, sizeof ipstat); - counters_read(ipcounters, counters, nitems(counters)); + counters_read(ipcounters, counters, nitems(counters), NULL); for (i = 0; i < nitems(counters); i++) words[i] = (u_long)counters[i]; diff --git a/sys/netinet/ip_ipip.c b/sys/netinet/ip_ipip.c index e9a561393ff..f56caca9841 100644 --- a/sys/netinet/ip_ipip.c +++ b/sys/netinet/ip_ipip.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_ipip.c,v 1.98 2022/01/02 22:36:04 jsg Exp $ */ +/* $OpenBSD: ip_ipip.c,v 1.99 2023/09/16 09:33:27 mpi Exp $ */ /* * The authors of this code are John Ioannidis (ji@tla.org), * Angelos D. Keromytis (kermit@csd.uch.gr) and @@ -573,7 +573,8 @@ ipip_sysctl_ipipstat(void *oldp, size_t *oldlenp, void *newp) CTASSERT(sizeof(ipipstat) == (ipips_ncounters * sizeof(uint64_t))); memset(&ipipstat, 0, sizeof ipipstat); - counters_read(ipipcounters, (uint64_t *)&ipipstat, ipips_ncounters); + counters_read(ipipcounters, (uint64_t *)&ipipstat, ipips_ncounters, + NULL); return (sysctl_rdstruct(oldp, oldlenp, newp, &ipipstat, sizeof(ipipstat))); } diff --git a/sys/netinet/ipsec_input.c b/sys/netinet/ipsec_input.c index 9e3f4dee18f..07de8e38eff 100644 --- a/sys/netinet/ipsec_input.c +++ b/sys/netinet/ipsec_input.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ipsec_input.c,v 1.205 2023/08/07 03:43:57 dlg Exp $ */ +/* $OpenBSD: ipsec_input.c,v 1.206 2023/09/16 09:33:27 mpi Exp $ */ /* * The authors of this code are John Ioannidis (ji@tla.org), * Angelos D. Keromytis (kermit@csd.uch.gr) and @@ -664,7 +664,7 @@ esp_sysctl_espstat(void *oldp, size_t *oldlenp, void *newp) CTASSERT(sizeof(espstat) == (esps_ncounters * sizeof(uint64_t))); memset(&espstat, 0, sizeof espstat); - counters_read(espcounters, (uint64_t *)&espstat, esps_ncounters); + counters_read(espcounters, (uint64_t *)&espstat, esps_ncounters, NULL); return (sysctl_rdstruct(oldp, oldlenp, newp, &espstat, sizeof(espstat))); } @@ -698,7 +698,7 @@ ah_sysctl_ahstat(void *oldp, size_t *oldlenp, void *newp) CTASSERT(sizeof(ahstat) == (ahs_ncounters * sizeof(uint64_t))); memset(&ahstat, 0, sizeof ahstat); - counters_read(ahcounters, (uint64_t *)&ahstat, ahs_ncounters); + counters_read(ahcounters, (uint64_t *)&ahstat, ahs_ncounters, NULL); return (sysctl_rdstruct(oldp, oldlenp, newp, &ahstat, sizeof(ahstat))); } @@ -733,7 +733,7 @@ ipcomp_sysctl_ipcompstat(void *oldp, size_t *oldlenp, void *newp) CTASSERT(sizeof(ipcompstat) == (ipcomps_ncounters * sizeof(uint64_t))); memset(&ipcompstat, 0, sizeof ipcompstat); counters_read(ipcompcounters, (uint64_t *)&ipcompstat, - ipcomps_ncounters); + ipcomps_ncounters, NULL); return (sysctl_rdstruct(oldp, oldlenp, newp, &ipcompstat, sizeof(ipcompstat))); } @@ -745,7 +745,8 @@ ipsec_sysctl_ipsecstat(void *oldp, size_t *oldlenp, void *newp) CTASSERT(sizeof(ipsecstat) == (ipsec_ncounters * sizeof(uint64_t))); memset(&ipsecstat, 0, sizeof ipsecstat); - counters_read(ipseccounters, (uint64_t *)&ipsecstat, ipsec_ncounters); + counters_read(ipseccounters, (uint64_t *)&ipsecstat, ipsec_ncounters, + NULL); return (sysctl_rdstruct(oldp, oldlenp, newp, &ipsecstat, sizeof(ipsecstat))); } diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c index 75d69a12aa7..f96fc7782e5 100644 --- a/sys/netinet/tcp_usrreq.c +++ b/sys/netinet/tcp_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tcp_usrreq.c,v 1.221 2023/07/06 09:15:24 bluhm Exp $ */ +/* $OpenBSD: tcp_usrreq.c,v 1.222 2023/09/16 09:33:27 mpi Exp $ */ /* $NetBSD: tcp_usrreq.c,v 1.20 1996/02/13 23:44:16 christos Exp $ */ /* @@ -1237,7 +1237,7 @@ tcp_sysctl_tcpstat(void *oldp, size_t *oldlenp, void *newp) #define ASSIGN(field) do { tcpstat.field = counters[i++]; } while (0) memset(&tcpstat, 0, sizeof tcpstat); - counters_read(tcpcounters, counters, nitems(counters)); + counters_read(tcpcounters, counters, nitems(counters), NULL); ASSIGN(tcps_connattempt); ASSIGN(tcps_accepts); ASSIGN(tcps_connects); diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c index 89a18a98d1c..5daee4d8efb 100644 --- a/sys/netinet/udp_usrreq.c +++ b/sys/netinet/udp_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: udp_usrreq.c,v 1.305 2023/01/22 12:05:44 mvs Exp $ */ +/* $OpenBSD: udp_usrreq.c,v 1.306 2023/09/16 09:33:27 mpi Exp $ */ /* $NetBSD: udp_usrreq.c,v 1.28 1996/03/16 23:54:03 christos Exp $ */ /* @@ -1314,7 +1314,7 @@ udp_sysctl_udpstat(void *oldp, size_t *oldlenp, void *newp) CTASSERT(sizeof(udpstat) == (nitems(counters) * sizeof(u_long))); memset(&udpstat, 0, sizeof udpstat); - counters_read(udpcounters, counters, nitems(counters)); + counters_read(udpcounters, counters, nitems(counters), NULL); for (i = 0; i < nitems(counters); i++) words[i] = (u_long)counters[i]; diff --git a/sys/netinet6/icmp6.c b/sys/netinet6/icmp6.c index 9173b5292a1..868f3f5d755 100644 --- a/sys/netinet6/icmp6.c +++ b/sys/netinet6/icmp6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: icmp6.c,v 1.248 2023/04/05 21:51:47 bluhm Exp $ */ +/* $OpenBSD: icmp6.c,v 1.249 2023/09/16 09:33:27 mpi Exp $ */ /* $KAME: icmp6.c,v 1.217 2001/06/20 15:03:29 jinmei Exp $ */ /* @@ -1870,7 +1870,8 @@ icmp6_sysctl_icmp6stat(void *oldp, size_t *oldlenp, void *newp) CTASSERT(sizeof(*icmp6stat) == icp6s_ncounters * sizeof(uint64_t)); icmp6stat = malloc(sizeof(*icmp6stat), M_TEMP, M_WAITOK|M_ZERO); - counters_read(icmp6counters, (uint64_t *)icmp6stat, icp6s_ncounters); + counters_read(icmp6counters, (uint64_t *)icmp6stat, icp6s_ncounters, + NULL); ret = sysctl_rdstruct(oldp, oldlenp, newp, icmp6stat, sizeof(*icmp6stat)); free(icmp6stat, M_TEMP, sizeof(*icmp6stat)); diff --git a/sys/netinet6/ip6_divert.c b/sys/netinet6/ip6_divert.c index aa7fc4ccdcc..6826bd9a287 100644 --- a/sys/netinet6/ip6_divert.c +++ b/sys/netinet6/ip6_divert.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_divert.c,v 1.89 2023/04/04 10:12:03 bluhm Exp $ */ +/* $OpenBSD: ip6_divert.c,v 1.90 2023/09/16 09:33:27 mpi Exp $ */ /* * Copyright (c) 2009 Michele Marchetto @@ -358,7 +358,7 @@ divert6_sysctl_div6stat(void *oldp, size_t *oldlenp, void *newp) CTASSERT(sizeof(div6stat) == (nitems(counters) * sizeof(u_long))); - counters_read(div6counters, counters, nitems(counters)); + counters_read(div6counters, counters, nitems(counters), NULL); for (i = 0; i < nitems(counters); i++) words[i] = (u_long)counters[i]; diff --git a/sys/netinet6/ip6_input.c b/sys/netinet6/ip6_input.c index be7e0010fa1..76ff8cbfbbf 100644 --- a/sys/netinet6/ip6_input.c +++ b/sys/netinet6/ip6_input.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_input.c,v 1.255 2023/09/06 11:09:43 bluhm Exp $ */ +/* $OpenBSD: ip6_input.c,v 1.256 2023/09/16 09:33:27 mpi Exp $ */ /* $KAME: ip6_input.c,v 1.188 2001/03/29 05:34:31 itojun Exp $ */ /* @@ -1466,7 +1466,7 @@ ip6_sysctl_ip6stat(void *oldp, size_t *oldlenp, void *newp) CTASSERT(sizeof(*ip6stat) == (ip6s_ncounters * sizeof(uint64_t))); ip6stat = malloc(sizeof(*ip6stat), M_TEMP, M_WAITOK); - counters_read(ip6counters, (uint64_t *)ip6stat, ip6s_ncounters); + counters_read(ip6counters, (uint64_t *)ip6stat, ip6s_ncounters, NULL); ret = sysctl_rdstruct(oldp, oldlenp, newp, ip6stat, sizeof(*ip6stat)); free(ip6stat, M_TEMP, sizeof(*ip6stat)); diff --git a/sys/netinet6/raw_ip6.c b/sys/netinet6/raw_ip6.c index 1ef501434ad..05879b42fad 100644 --- a/sys/netinet6/raw_ip6.c +++ b/sys/netinet6/raw_ip6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: raw_ip6.c,v 1.172 2023/01/22 12:05:44 mvs Exp $ */ +/* $OpenBSD: raw_ip6.c,v 1.173 2023/09/16 09:33:27 mpi Exp $ */ /* $KAME: raw_ip6.c,v 1.69 2001/03/04 15:55:44 itojun Exp $ */ /* @@ -784,7 +784,8 @@ rip6_sysctl_rip6stat(void *oldp, size_t *oldplen, void *newp) struct rip6stat rip6stat; CTASSERT(sizeof(rip6stat) == rip6s_ncounters * sizeof(uint64_t)); - counters_read(rip6counters, (uint64_t *)&rip6stat, rip6s_ncounters); + counters_read(rip6counters, (uint64_t *)&rip6stat, rip6s_ncounters, + NULL); return (sysctl_rdstruct(oldp, oldplen, newp, &rip6stat, sizeof(rip6stat))); diff --git a/sys/sys/percpu.h b/sys/sys/percpu.h index 53a1a885239..5595b1abafe 100644 --- a/sys/sys/percpu.h +++ b/sys/sys/percpu.h @@ -1,4 +1,4 @@ -/* $OpenBSD: percpu.h,v 1.8 2018/08/28 15:15:02 mpi Exp $ */ +/* $OpenBSD: percpu.h,v 1.9 2023/09/16 09:33:27 mpi Exp $ */ /* * Copyright (c) 2016 David Gwynne @@ -113,7 +113,8 @@ static struct { \ struct cpumem *counters_alloc(unsigned int); struct cpumem *counters_alloc_ncpus(struct cpumem *, unsigned int); void counters_free(struct cpumem *, unsigned int); -void counters_read(struct cpumem *, uint64_t *, unsigned int); +void counters_read(struct cpumem *, uint64_t *, unsigned int, + uint64_t *); void counters_zero(struct cpumem *, unsigned int); static inline uint64_t * diff --git a/sys/uvm/uvm_meter.c b/sys/uvm/uvm_meter.c index 25bc9126d9d..3289cdb854a 100644 --- a/sys/uvm/uvm_meter.c +++ b/sys/uvm/uvm_meter.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uvm_meter.c,v 1.49 2023/08/18 09:18:52 claudio Exp $ */ +/* $OpenBSD: uvm_meter.c,v 1.50 2023/09/16 09:33:27 mpi Exp $ */ /* $NetBSD: uvm_meter.c,v 1.21 2001/07/14 06:36:03 matt Exp $ */ /* @@ -249,11 +249,12 @@ uvm_total(struct vmtotal *totalp) void uvmexp_read(struct uvmexp *uexp) { - uint64_t counters[exp_ncounters]; + uint64_t counters[exp_ncounters], scratch[exp_ncounters]; memcpy(uexp, &uvmexp, sizeof(*uexp)); - counters_read(uvmexp_counters, counters, exp_ncounters); + counters_read(uvmexp_counters, counters, exp_ncounters, + scratch); /* stat counters */ uexp->faults = (int)counters[faults];