Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 11 Aug 2021 13:25:18 GMT
From:      Mateusz Guzik <mjg@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: f45535b6c79d - stable/12 - pf: switch pf_status.fcounters to pf_counter_u64
Message-ID:  <202108111325.17BDPIGS004880@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/12 has been updated by mjg:

URL: https://cgit.FreeBSD.org/src/commit/?id=f45535b6c79d359625fb2d9cff5e46de5bd59861

commit f45535b6c79d359625fb2d9cff5e46de5bd59861
Author:     Mateusz Guzik <mjg@FreeBSD.org>
AuthorDate: 2021-07-24 05:33:52 +0000
Commit:     Mateusz Guzik <mjg@FreeBSD.org>
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]);
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202108111325.17BDPIGS004880>