From owner-dev-commits-src-main@freebsd.org Sun Jul 25 08:24:59 2021 Return-Path: Delivered-To: dev-commits-src-main@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id D075265635A; Sun, 25 Jul 2021 08:24:59 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4GXbhW4hQHz3nJY; Sun, 25 Jul 2021 08:24:59 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 822D62057C; Sun, 25 Jul 2021 08:24:59 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 16P8OxmJ056646; Sun, 25 Jul 2021 08:24:59 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 16P8OxtQ056645; Sun, 25 Jul 2021 08:24:59 GMT (envelope-from git) Date: Sun, 25 Jul 2021 08:24:59 GMT Message-Id: <202107250824.16P8OxtQ056645@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mateusz Guzik Subject: git: fc4c42ce0b5c - main - pf: switch pf_status.fcounters to pf_counter_u64 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mjg X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: fc4c42ce0b5ce87901b327e25f55b4e3ab4c6cf5 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 25 Jul 2021 08:25:00 -0000 The branch main has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=fc4c42ce0b5ce87901b327e25f55b4e3ab4c6cf5 commit fc4c42ce0b5ce87901b327e25f55b4e3ab4c6cf5 Author: Mateusz Guzik AuthorDate: 2021-07-24 05:33:52 +0000 Commit: Mateusz Guzik CommitDate: 2021-07-25 08:22:16 +0000 pf: switch pf_status.fcounters to pf_counter_u64 Reviewed by: kp Sponsored by: Rubicon Communications, LLC ("Netgate") --- sys/net/pfvar.h | 2 +- sys/netpfil/pf/pf.c | 26 +++++++++++++++++++++----- sys/netpfil/pf/pf_ioctl.c | 8 ++++---- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/sys/net/pfvar.h b/sys/net/pfvar.h index 62aebfaf8981..8683e4fece58 100644 --- a/sys/net/pfvar.h +++ b/sys/net/pfvar.h @@ -1371,7 +1371,7 @@ enum pf_syncookies_mode { struct pf_kstatus { counter_u64_t counters[PFRES_MAX]; /* reason for passing/dropping */ counter_u64_t lcounters[LCNT_MAX]; /* limit counters */ - counter_u64_t fcounters[FCNT_MAX]; /* state operation counters */ + struct pf_counter_u64 fcounters[FCNT_MAX]; /* state operation counters */ counter_u64_t scounters[SCNT_MAX]; /* src_node operation counters */ uint32_t states; uint32_t src_nodes; diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c index 7cef71c78140..e2e4f5895cfa 100644 --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -1311,7 +1311,7 @@ pf_state_insert(struct pfi_kkif *kif, struct pfi_kkif *orig_kif, /* One for keys, one for ID hash. */ refcount_init(&s->refs, 2); - counter_u64_add(V_pf_status.fcounters[FCNT_STATE_INSERT], 1); + pf_counter_u64_add(&V_pf_status.fcounters[FCNT_STATE_INSERT], 1); if (V_pfsync_insert_state_ptr != NULL) V_pfsync_insert_state_ptr(s); @@ -1328,7 +1328,7 @@ pf_find_state_byid(uint64_t id, uint32_t creatorid) struct pf_idhash *ih; struct pf_kstate *s; - counter_u64_add(V_pf_status.fcounters[FCNT_STATE_SEARCH], 1); + pf_counter_u64_add(&V_pf_status.fcounters[FCNT_STATE_SEARCH], 1); ih = &V_pf_idhash[(be64toh(id) % (pf_hashmask + 1))]; @@ -1355,7 +1355,7 @@ pf_find_state(struct pfi_kkif *kif, struct pf_state_key_cmp *key, u_int dir) struct pf_kstate *s; int idx; - counter_u64_add(V_pf_status.fcounters[FCNT_STATE_SEARCH], 1); + pf_counter_u64_add(&V_pf_status.fcounters[FCNT_STATE_SEARCH], 1); kh = &V_pf_keyhash[pf_hashkey((struct pf_state_key *)key)]; @@ -1399,7 +1399,7 @@ pf_find_state_all(struct pf_state_key_cmp *key, u_int dir, int *more) struct pf_kstate *s, *ret = NULL; int idx, inout = 0; - counter_u64_add(V_pf_status.fcounters[FCNT_STATE_SEARCH], 1); + pf_counter_u64_add(&V_pf_status.fcounters[FCNT_STATE_SEARCH], 1); kh = &V_pf_keyhash[pf_hashkey((struct pf_state_key *)key)]; @@ -1517,6 +1517,21 @@ pf_intr(void *v) #define pf_purge_thread_period (hz / 10) #ifdef PF_WANT_32_TO_64_COUNTER +static void +pf_status_counter_u64_periodic(void) +{ + + PF_RULES_RASSERT(); + + if ((V_pf_counter_periodic_iter % (pf_purge_thread_period * 10 * 60)) != 0) { + return; + } + + for (int i = 0; i < FCNT_MAX; i++) { + pf_counter_u64_periodic(&V_pf_status.fcounters[i]); + } +} + static void pf_counter_u64_periodic_main(void) { @@ -1526,6 +1541,7 @@ pf_counter_u64_periodic_main(void) PF_RULES_RLOCK(); pf_counter_u64_critical_enter(); + pf_status_counter_u64_periodic(); pf_counter_u64_critical_exit(); PF_RULES_RUNLOCK(); } @@ -1781,7 +1797,7 @@ pf_free_state(struct pf_kstate *cur) pf_normalize_tcp_cleanup(cur); uma_zfree(V_pf_state_z, cur); - counter_u64_add(V_pf_status.fcounters[FCNT_STATE_REMOVALS], 1); + pf_counter_u64_add(&V_pf_status.fcounters[FCNT_STATE_REMOVALS], 1); } /* diff --git a/sys/netpfil/pf/pf_ioctl.c b/sys/netpfil/pf/pf_ioctl.c index 432585610aa1..560dd4f666c0 100644 --- a/sys/netpfil/pf/pf_ioctl.c +++ b/sys/netpfil/pf/pf_ioctl.c @@ -354,7 +354,7 @@ pfattach_vnet(void) for (int i = 0; i < LCNT_MAX; i++) V_pf_status.lcounters[i] = counter_u64_alloc(M_WAITOK); for (int i = 0; i < FCNT_MAX; i++) - V_pf_status.fcounters[i] = counter_u64_alloc(M_WAITOK); + pf_counter_u64_init(&V_pf_status.fcounters[i], M_WAITOK); for (int i = 0; i < SCNT_MAX; i++) V_pf_status.scounters[i] = counter_u64_alloc(M_WAITOK); @@ -2986,7 +2986,7 @@ DIOCGETSTATESV2_full: counter_u64_fetch(V_pf_status.lcounters[i]); for (int i = 0; i < FCNT_MAX; i++) s->fcounters[i] = - counter_u64_fetch(V_pf_status.fcounters[i]); + pf_counter_u64_fetch(&V_pf_status.fcounters[i]); for (int i = 0; i < SCNT_MAX; i++) s->scounters[i] = counter_u64_fetch(V_pf_status.scounters[i]); @@ -3018,7 +3018,7 @@ DIOCGETSTATESV2_full: for (int i = 0; i < PFRES_MAX; i++) counter_u64_zero(V_pf_status.counters[i]); for (int i = 0; i < FCNT_MAX; i++) - counter_u64_zero(V_pf_status.fcounters[i]); + pf_counter_u64_zero(&V_pf_status.fcounters[i]); for (int i = 0; i < SCNT_MAX; i++) counter_u64_zero(V_pf_status.scounters[i]); for (int i = 0; i < LCNT_MAX; i++) @@ -5615,7 +5615,7 @@ pf_unload_vnet(void) for (int i = 0; i < LCNT_MAX; i++) counter_u64_free(V_pf_status.lcounters[i]); for (int i = 0; i < FCNT_MAX; i++) - counter_u64_free(V_pf_status.fcounters[i]); + pf_counter_u64_deinit(&V_pf_status.fcounters[i]); for (int i = 0; i < SCNT_MAX; i++) counter_u64_free(V_pf_status.scounters[i]); }