Module Name:    src
Committed By:   thorpej
Date:           Sat Sep  3 00:31:02 UTC 2022

Modified Files:
        src/sys/net: if_ethersubr.c if_spppsubr.c

Log Message:
Only use configured RPS hash functions for IPv4 and IPv6 packets.

This is NFC change now because only IPv4 and IPv6 use pktqueue,
but that will change in future commits.


To generate a diff of this commit:
cvs rdiff -u -r1.315 -r1.316 src/sys/net/if_ethersubr.c
cvs rdiff -u -r1.264 -r1.265 src/sys/net/if_spppsubr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/if_ethersubr.c
diff -u src/sys/net/if_ethersubr.c:1.315 src/sys/net/if_ethersubr.c:1.316
--- src/sys/net/if_ethersubr.c:1.315	Mon Jun 20 12:22:00 2022
+++ src/sys/net/if_ethersubr.c	Sat Sep  3 00:31:02 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ethersubr.c,v 1.315 2022/06/20 12:22:00 martin Exp $	*/
+/*	$NetBSD: if_ethersubr.c,v 1.316 2022/09/03 00:31:02 thorpej Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.315 2022/06/20 12:22:00 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.316 2022/09/03 00:31:02 thorpej Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -655,6 +655,9 @@ ether_input(struct ifnet *ifp, struct mb
 	static int earlypkts;
 	int isr = 0;
 
+	/* No RPS for not-IP. */
+	pktq_rps_hash_func_t rps_hash = NULL;
+
 	KASSERT(!cpu_intr_p());
 	KASSERT((m->m_flags & M_PKTHDR) != 0);
 
@@ -897,6 +900,7 @@ ether_input(struct ifnet *ifp, struct mb
 			return;
 #endif
 		pktq = ip_pktq;
+		rps_hash = atomic_load_relaxed(&ether_pktq_rps_hash_p);
 		break;
 
 	case ETHERTYPE_ARP:
@@ -918,6 +922,7 @@ ether_input(struct ifnet *ifp, struct mb
 			return;
 #endif
 		pktq = ip6_pktq;
+		rps_hash = atomic_load_relaxed(&ether_pktq_rps_hash_p);
 		break;
 #endif
 
@@ -944,7 +949,7 @@ ether_input(struct ifnet *ifp, struct mb
 	}
 
 	if (__predict_true(pktq)) {
-		const uint32_t h = pktq_rps_hash(&ether_pktq_rps_hash_p, m);
+		const uint32_t h = rps_hash ? pktq_rps_hash(&rps_hash, m) : 0;
 		if (__predict_false(!pktq_enqueue(pktq, m, h))) {
 			m_freem(m);
 		}

Index: src/sys/net/if_spppsubr.c
diff -u src/sys/net/if_spppsubr.c:1.264 src/sys/net/if_spppsubr.c:1.265
--- src/sys/net/if_spppsubr.c:1.264	Sat Aug 27 19:25:35 2022
+++ src/sys/net/if_spppsubr.c	Sat Sep  3 00:31:02 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppsubr.c,v 1.264 2022/08/27 19:25:35 thorpej Exp $	 */
+/*	$NetBSD: if_spppsubr.c,v 1.265 2022/09/03 00:31:02 thorpej Exp $	 */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.264 2022/08/27 19:25:35 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.265 2022/09/03 00:31:02 thorpej Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -644,6 +644,9 @@ sppp_input(struct ifnet *ifp, struct mbu
 	struct sppp *sp = (struct sppp *)ifp;
 	int isr = 0;
 
+	/* No RPS for not-IP. */
+	pktq_rps_hash_func_t rps_hash = NULL;
+
 	SPPP_LOCK(sp, RW_READER);
 
 	if (ifp->if_flags & IFF_UP) {
@@ -747,6 +750,7 @@ sppp_input(struct ifnet *ifp, struct mbu
 		if (sp->scp[IDX_IPCP].state == STATE_OPENED) {
 			sp->pp_last_activity = time_uptime;
 			pktq = ip_pktq;
+			rps_hash = atomic_load_relaxed(&sppp_pktq_rps_hash_p);
 		}
 		break;
 #endif
@@ -770,6 +774,7 @@ sppp_input(struct ifnet *ifp, struct mbu
 		if (sp->scp[IDX_IPV6CP].state == STATE_OPENED) {
 			sp->pp_last_activity = time_uptime;
 			pktq = ip6_pktq;
+			rps_hash = atomic_load_relaxed(&sppp_pktq_rps_hash_p);
 		}
 		break;
 #endif
@@ -781,8 +786,8 @@ sppp_input(struct ifnet *ifp, struct mbu
 
 	/* Check queue. */
 	if (__predict_true(pktq)) {
-		uint32_t hash = pktq_rps_hash(&sppp_pktq_rps_hash_p, m);
-
+		const uint32_t hash =
+		    rps_hash ? pktq_rps_hash(&rps_hash, m) : 0;
 		if (__predict_false(!pktq_enqueue(pktq, m, hash))) {
 			goto drop;
 		}

Reply via email to