The branch stable/13 has been updated by mjg:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=b45b050a69ee7c9bd1c1b6c546e0d0a9714688e1
commit b45b050a69ee7c9bd1c1b6c546e0d0a9714688e1
Author:     Mateusz Guzik <m...@freebsd.org>
AuthorDate: 2021-07-24 05:33:52 +0000
Commit:     Mateusz Guzik <m...@freebsd.org>
CommitDate: 2021-08-11 13:37:54 +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 e381279a113f..bf70a8a5d016 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 b74491bb88d0..5d043bdbd0e4 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 d3d0ede278fd..2cce147035ae 100644
--- a/sys/netpfil/pf/pf_ioctl.c
+++ b/sys/netpfil/pf/pf_ioctl.c
@@ -368,7 +368,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);
 
@@ -3050,7 +3050,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]);
@@ -3082,7 +3082,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++)
@@ -5618,7 +5618,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]);
 }
_______________________________________________
dev-commits-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-all
To unsubscribe, send any mail to "dev-commits-src-all-unsubscr...@freebsd.org"

Reply via email to