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.
This commit is contained in:
thorpej 2022-09-03 00:31:02 +00:00
parent eca1c11589
commit 8310d9409c
2 changed files with 17 additions and 7 deletions

View File

@ -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 mbuf *m)
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 mbuf *m)
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 mbuf *m)
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 mbuf *m)
}
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);
}

View File

@ -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 mbuf *m)
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 mbuf *m)
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 mbuf *m)
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 mbuf *m)
/* 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;
}