-.\" $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 <dlg@openbsd.org>
.\"
.\" 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
.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"
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
-/* $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 $ */
/*-
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];
-/* $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 <art@openbsd.org>
* Copyright (c) 2004 Aaron Campbell <aaron@openbsd.org>
{
int error = 0, s, nintr, i;
struct evcount *ec;
- u_int64_t count;
+ uint64_t count, scratch;
if (newp != NULL)
return (EPERM);
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;
-/* $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 <dlg@openbsd.org>
}
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 {
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
}
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;
-/* $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 $ */
/*
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];
-/* $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 <goda@openbsd.org>
*
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)));
}
-/* $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
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)));
}
-/* $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)
*
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);
-/* $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.
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];
-/* $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 $ */
/*
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];
-/* $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 $ */
/*
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];
-/* $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.
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)));
}
-/* $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 <michele@openbsd.org>
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];
-/* $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 $ */
/*
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];
-/* $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 $ */
/*
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];
-/* $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
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)));
}
-/* $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
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)));
}
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)));
}
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)));
}
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)));
}
-/* $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 $ */
/*
#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);
-/* $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 $ */
/*
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];
-/* $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 $ */
/*
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));
-/* $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 <michele@openbsd.org>
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];
-/* $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 $ */
/*
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));
-/* $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 $ */
/*
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)));
-/* $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 <dlg@openbsd.org>
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 *
-/* $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 $ */
/*
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];