git: 751d4c7b8728 - main - pf: postpone clearing of struct pf_pdesc

From: Kristof Provost <kp_at_FreeBSD.org>
Date: Tue, 11 Jan 2022 10:16:57 UTC
The branch main has been updated by kp:

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

commit 751d4c7b8728d82cb4dd51b851e4dc5d6b4092c8
Author:     Kristof Provost <kp@FreeBSD.org>
AuthorDate: 2022-01-10 17:43:35 +0000
Commit:     Kristof Provost <kp@FreeBSD.org>
CommitDate: 2022-01-11 09:10:23 +0000

    pf: postpone clearing of struct pf_pdesc
    
    Postpone zeroing out pd until after the PFI_IFLAG_SKIP/M_SKIP_FIREWALL
    checks. We don't need it until then, and it saves us a few CPU cycles in
    some cases.
    This isn't expected to make a measurable performance change though.
    
    Reviewed by:    mjg, glebius
    Pointed out by: markj
    Sponsored by:   Rubicon Communications, LLC ("Netgate")
    Differential Revision:  https://reviews.freebsd.org/D33815
---
 sys/netpfil/pf/pf.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c
index 9390f0050cdc..7e98d5062286 100644
--- a/sys/netpfil/pf/pf.c
+++ b/sys/netpfil/pf/pf.c
@@ -6461,8 +6461,6 @@ pf_test(int dir, int pflags, struct ifnet *ifp, struct mbuf **m0, struct inpcb *
 	if (!V_pf_status.running)
 		return (PF_PASS);
 
-	memset(&pd, 0, sizeof(pd));
-
 	kif = (struct pfi_kkif *)ifp->if_pf_kif;
 
 	if (kif == NULL) {
@@ -6476,6 +6474,7 @@ pf_test(int dir, int pflags, struct ifnet *ifp, struct mbuf **m0, struct inpcb *
 	if (m->m_flags & M_SKIP_FIREWALL)
 		return (PF_PASS);
 
+	memset(&pd, 0, sizeof(pd));
 	pd.pf_mtag = pf_find_mtag(m);
 
 	if (ip_dn_io_ptr != NULL && pd.pf_mtag != NULL &&
@@ -6962,9 +6961,6 @@ pf_test6(int dir, int pflags, struct ifnet *ifp, struct mbuf **m0, struct inpcb
 	if (!V_pf_status.running)
 		return (PF_PASS);
 
-	memset(&pd, 0, sizeof(pd));
-	pd.pf_mtag = pf_find_mtag(m);
-
 	kif = (struct pfi_kkif *)ifp->if_pf_kif;
 	if (kif == NULL) {
 		DPFPRINTF(PF_DEBUG_URGENT,
@@ -6977,6 +6973,9 @@ pf_test6(int dir, int pflags, struct ifnet *ifp, struct mbuf **m0, struct inpcb
 	if (m->m_flags & M_SKIP_FIREWALL)
 		return (PF_PASS);
 
+	memset(&pd, 0, sizeof(pd));
+	pd.pf_mtag = pf_find_mtag(m);
+
 	if (ip_dn_io_ptr != NULL && pd.pf_mtag != NULL &&
 	    pd.pf_mtag->flags & PF_TAG_DUMMYNET) {
 		pd.pf_mtag->flags &= ~PF_TAG_DUMMYNET;