From owner-dev-commits-src-branches@freebsd.org Wed Aug 11 13:25:19 2021 Return-Path: Delivered-To: dev-commits-src-branches@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 55FDA6536EB; Wed, 11 Aug 2021 13:25:19 +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 4Gl9YC1gbXz3ClZ; Wed, 11 Aug 2021 13:25:19 +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 152B37EF5; Wed, 11 Aug 2021 13:25:19 +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 17BDPINU004881; Wed, 11 Aug 2021 13:25:18 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17BDPIGS004880; Wed, 11 Aug 2021 13:25:18 GMT (envelope-from git) Date: Wed, 11 Aug 2021 13:25:18 GMT Message-Id: <202108111325.17BDPIGS004880@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mateusz Guzik Subject: git: f45535b6c79d - stable/12 - 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/stable/12 X-Git-Reftype: branch X-Git-Commit: f45535b6c79d359625fb2d9cff5e46de5bd59861 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Aug 2021 13:25:19 -0000 The branch stable/12 has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=f45535b6c79d359625fb2d9cff5e46de5bd59861 commit f45535b6c79d359625fb2d9cff5e46de5bd59861 Author: Mateusz Guzik AuthorDate: 2021-07-24 05:33:52 +0000 Commit: Mateusz Guzik CommitDate: 2021-08-11 12:21:04 +0000 pf: switch pf_status.fcounters to pf_counter_u64 Reviewed by: kp Sponsored by: Rubicon Communications, LLC ("Netgate") (cherry picked from commit fc4c42ce0b5ce87901b327e25f55b4e3ab4c6cf5) --- 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 fd0b36c72a42..7c1e92d39470 100644 --- a/sys/net/pfvar.h +++ b/sys/net/pfvar.h @@ -1368,7 +1368,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 5edafe4b5e7a..1ba95754bd32 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)]; @@ -1513,6 +1513,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) { @@ -1522,6 +1537,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(); } @@ -1779,7 +1795,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 bb71f44cad97..1b2c329fdb2c 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); @@ -3019,7 +3019,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]); @@ -3051,7 +3051,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++) @@ -5616,7 +5616,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]); }