Convert NETATALK from a legacy netisr to pktqueue.

This commit is contained in:
thorpej 2022-09-03 01:48:22 +00:00
parent 63ae4dd2e0
commit 6bd159b890
9 changed files with 78 additions and 93 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_ethersubr.c,v 1.317 2022/09/03 01:35:03 thorpej Exp $ */
/* $NetBSD: if_ethersubr.c,v 1.318 2022/09/03 01:48:22 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.317 2022/09/03 01:35:03 thorpej Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.318 2022/09/03 01:48:22 thorpej Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@ -574,8 +574,7 @@ bad:
static void
ether_input_llc(struct ifnet *ifp, struct mbuf *m, struct ether_header *eh)
{
struct ifqueue *inq = NULL;
int isr = 0;
pktqueue_t *pktq = NULL;
struct llc *l;
if (m->m_len < sizeof(*eh) + sizeof(struct llc))
@ -594,10 +593,9 @@ ether_input_llc(struct ifnet *ifp, struct mbuf *m, struct ether_header *eh)
at_org_code, sizeof(at_org_code)) == 0 &&
ntohs(l->llc_snap_ether_type) ==
ETHERTYPE_ATALK) {
inq = &atintrq2;
pktq = at_pktq2;
m_adj(m, sizeof(struct ether_header)
+ sizeof(struct llc));
isr = NETISR_ATALK;
break;
}
@ -621,8 +619,10 @@ ether_input_llc(struct ifnet *ifp, struct mbuf *m, struct ether_header *eh)
goto noproto;
}
KASSERT(inq != NULL);
IFQ_ENQUEUE_ISR(inq, m, isr);
KASSERT(pktq != NULL);
if (__predict_false(!pktq_enqueue(pktq, m, 0))) {
m_freem(m);
}
return;
noproto:
@ -927,8 +927,7 @@ ether_input(struct ifnet *ifp, struct mbuf *m)
#ifdef NETATALK
case ETHERTYPE_ATALK:
isr = NETISR_ATALK;
inq = &atintrq1;
pktq = at_pktq1;
break;
case ETHERTYPE_AARP:

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_gre.c,v 1.181 2021/09/21 14:59:14 christos Exp $ */
/* $NetBSD: if_gre.c,v 1.182 2022/09/03 01:48:22 thorpej Exp $ */
/*
* Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@ -45,7 +45,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_gre.c,v 1.181 2021/09/21 14:59:14 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_gre.c,v 1.182 2022/09/03 01:48:22 thorpej Exp $");
#ifdef _KERNEL_OPT
#include "opt_atalk.h"
@ -825,8 +825,7 @@ gre_input(struct gre_softc *sc, struct mbuf *m, const struct gre_h *gh)
#endif
#ifdef NETATALK
case ETHERTYPE_ATALK:
ifq = &atintrq1;
isr = NETISR_ATALK;
pktq = at_pktq1;
af = AF_APPLETALK;
break;
#endif

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_loop.c,v 1.114 2022/07/31 13:14:54 mlelstv Exp $ */
/* $NetBSD: if_loop.c,v 1.115 2022/09/03 01:48:22 thorpej Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@ -65,7 +65,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_loop.c,v 1.114 2022/07/31 13:14:54 mlelstv Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_loop.c,v 1.115 2022/09/03 01:48:22 thorpej Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@ -348,8 +348,7 @@ looutput(struct ifnet *ifp, struct mbuf *m, const struct sockaddr *dst,
#endif
#ifdef NETATALK
case AF_APPLETALK:
ifq = &atintrq2;
isr = NETISR_ATALK;
pktq = at_pktq2;
break;
#endif
default:
@ -397,11 +396,10 @@ lostart(struct ifnet *ifp)
{
for (;;) {
pktqueue_t *pktq = NULL;
struct ifqueue *ifq = NULL;
struct mbuf *m;
size_t pktlen;
uint32_t af;
int s, isr = 0;
int s;
IFQ_DEQUEUE(&ifp->if_snd, m);
if (m == NULL)
@ -424,8 +422,7 @@ lostart(struct ifnet *ifp)
#endif
#ifdef NETATALK
case AF_APPLETALK:
ifq = &atintrq2;
isr = NETISR_ATALK;
pktq = at_pktq2;
break;
#endif
default:
@ -435,25 +432,14 @@ lostart(struct ifnet *ifp)
}
pktlen = m->m_pkthdr.len;
KASSERT(pktq != NULL);
s = splnet();
if (__predict_true(pktq)) {
if (__predict_false(pktq_enqueue(pktq, m, 0))) {
m_freem(m);
splx(s);
return;
}
if_statadd2(ifp, if_ipackets, 1, if_ibytes, pktlen);
splx(s);
continue;
}
if (IF_QFULL(ifq)) {
IF_DROP(ifq);
splx(s);
if (__predict_false(pktq_enqueue(pktq, m, 0))) {
m_freem(m);
splx(s);
return;
}
IF_ENQUEUE(ifq, m);
schednetisr(isr);
if_statadd2(ifp, if_ipackets, 1, if_ibytes, pktlen);
splx(s);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: netisr_dispatch.h,v 1.21 2022/09/03 01:35:03 thorpej Exp $ */
/* $NetBSD: netisr_dispatch.h,v 1.22 2022/09/03 01:48:22 thorpej Exp $ */
#ifndef _NET_NETISR_DISPATCH_H_
#define _NET_NETISR_DISPATCH_H_
@ -27,9 +27,6 @@
* their prototypes in <net/netisr.h> (if necessary).
*/
#ifdef NETATALK
DONETISR(NETISR_ATALK,atintr);
#endif
#ifdef MPLS
DONETISR(NETISR_MPLS,mplsintr);
#endif

View File

@ -1,4 +1,4 @@
/* $NetBSD: at_extern.h,v 1.20 2018/05/29 16:29:47 maxv Exp $ */
/* $NetBSD: at_extern.h,v 1.21 2022/09/03 01:48:22 thorpej Exp $ */
/*
* Copyright (c) 1990,1994 Regents of The University of Michigan.
@ -44,7 +44,8 @@ extern struct mowner atalk_tx_mowner;
extern const struct pr_usrreqs ddp_usrreqs;
void atintr(void);
void atintr1(void *);
void atintr2(void *);
void aarpprobe(void *);
int aarpresolve(struct ifnet *, struct mbuf *, const struct sockaddr_at *,
u_char *);
@ -66,5 +67,4 @@ struct ddpcb *
int ddp_route(struct mbuf *, struct route *);
char * prsockaddr(const void *);
#endif /* !_NETATALK_AT_EXTERN_H_ */

View File

@ -1,4 +1,4 @@
/* $NetBSD: at_proto.c,v 1.22 2017/09/21 07:15:34 ozaki-r Exp $ */
/* $NetBSD: at_proto.c,v 1.23 2022/09/03 01:48:22 thorpej Exp $ */
/*
* Copyright (c) 1990,1991 Regents of The University of Michigan.
@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: at_proto.c,v 1.22 2017/09/21 07:15:34 ozaki-r Exp $");
__KERNEL_RCSID(0, "$NetBSD: at_proto.c,v 1.23 2022/09/03 01:48:22 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -73,7 +73,6 @@ struct domain atalkdomain = {
.dom_maxrtkey = sizeof(struct sockaddr_at),
.dom_ifattach = NULL,
.dom_ifdetach = NULL,
.dom_ifqueues = { &atintrq1, &atintrq2 },
.dom_link = { NULL },
.dom_mowner = MOWNER_INIT("",""),
.dom_sa_cmpofs = offsetof(struct sockaddr_at, sat_addr),

View File

@ -1,4 +1,4 @@
/* $NetBSD: at_var.h,v 1.9 2019/10/09 14:15:40 maxv Exp $ */
/* $NetBSD: at_var.h,v 1.10 2022/09/03 01:48:22 thorpej Exp $ */
/*
* Copyright (c) 1990,1991 Regents of The University of Michigan.
@ -67,6 +67,9 @@ struct at_aliasreq {
#define AFA_PHASE2 0x0004
#ifdef _KERNEL
#include <net/pktqueue.h>
int sockaddr_at_cmp(const struct sockaddr *, const struct sockaddr *);
static __inline void
@ -104,7 +107,7 @@ sockaddr_at_alloc(const struct at_addr *addr, uint8_t port, int flags)
}
TAILQ_HEAD(at_ifaddrhead, at_ifaddr);
extern struct at_ifaddrhead at_ifaddr;
extern struct ifqueue atintrq1, atintrq2;
extern pktqueue_t *at_pktq1, *at_pktq2;
#endif
#endif /* !_NETATALK_AT_VAR_H_ */

View File

@ -1,4 +1,4 @@
/* $NetBSD: ddp_input.c,v 1.31 2018/03/21 14:23:54 roy Exp $ */
/* $NetBSD: ddp_input.c,v 1.32 2022/09/03 01:48:22 thorpej Exp $ */
/*
* Copyright (c) 1990,1994 Regents of The University of Michigan.
@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ddp_input.c,v 1.31 2018/03/21 14:23:54 roy Exp $");
__KERNEL_RCSID(0, "$NetBSD: ddp_input.c,v 1.32 2022/09/03 01:48:22 thorpej Exp $");
#include "opt_atalk.h"
#include <sys/param.h>
@ -53,59 +53,57 @@ __KERNEL_RCSID(0, "$NetBSD: ddp_input.c,v 1.31 2018/03/21 14:23:54 roy Exp $");
int ddp_forward = 1;
int ddp_firewall = 0;
extern int ddp_cksum;
void ddp_input(struct mbuf *, struct ifnet *,
struct elaphdr *, int);
void ddp_input(struct mbuf *, struct ifnet *, struct elaphdr *, int);
/*
* Could probably merge these two code segments a little better...
*/
void
atintr(void)
static struct at_ifaddr *
at_ifaddr_for_ifp(struct ifnet * const ifp, int phase_flag)
{
struct elaphdr *elhp, elh;
struct ifnet *ifp;
struct mbuf *m;
struct at_ifaddr *aa;
mutex_enter(softnet_lock);
for (;;) {
IFQ_LOCK(&atintrq2);
IF_DEQUEUE(&atintrq2, m);
IFQ_UNLOCK(&atintrq2);
TAILQ_FOREACH(aa, &at_ifaddr, aa_list) {
if (aa->aa_ifp == ifp &&
(aa->aa_flags & AFA_PHASE2) == phase_flag) {
return aa;
}
}
return NULL;
}
if (m == 0) /* no more queued packets */
break;
void
atintr2(void *arg __unused)
{
struct mbuf *m;
mutex_enter(softnet_lock);
while ((m = pktq_dequeue(at_pktq2)) != NULL) {
struct ifnet *ifp;
m_claimm(m, &atalk_rx_mowner);
ifp = m_get_rcvif_NOMPSAFE(m);
for (aa = at_ifaddr.tqh_first; aa; aa = aa->aa_list.tqe_next) {
if (aa->aa_ifp == ifp && (aa->aa_flags & AFA_PHASE2))
break;
}
if (aa == NULL) { /* ifp not an appletalk interface */
if (at_ifaddr_for_ifp(ifp, AFA_PHASE2) == NULL) {
/* ifp not an appletalk interface */
m_freem(m);
continue;
}
ddp_input(m, ifp, NULL, 2);
}
mutex_exit(softnet_lock);
}
for (;;) {
IFQ_LOCK(&atintrq1);
IF_DEQUEUE(&atintrq1, m);
IFQ_UNLOCK(&atintrq1);
void
atintr1(void *arg __unused)
{
struct mbuf *m;
if (m == 0) /* no more queued packets */
break;
mutex_enter(softnet_lock);
while ((m = pktq_dequeue(at_pktq1)) != NULL) {
struct ifnet *ifp;
struct elaphdr *elhp, elh;
m_claimm(m, &atalk_rx_mowner);
ifp = m_get_rcvif_NOMPSAFE(m);
for (aa = at_ifaddr.tqh_first; aa; aa = aa->aa_list.tqe_next) {
if (aa->aa_ifp == ifp &&
(aa->aa_flags & AFA_PHASE2) == 0)
break;
}
if (aa == NULL) { /* ifp not an appletalk interface */
if (at_ifaddr_for_ifp(ifp, 0) == NULL) {
/* ifp not an appletalk interface */
m_freem(m);
continue;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: ddp_usrreq.c,v 1.75 2021/09/21 15:01:59 christos Exp $ */
/* $NetBSD: ddp_usrreq.c,v 1.76 2022/09/03 01:48:22 thorpej Exp $ */
/*
* Copyright (c) 1990,1991 Regents of The University of Michigan.
@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ddp_usrreq.c,v 1.75 2021/09/21 15:01:59 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: ddp_usrreq.c,v 1.76 2022/09/03 01:48:22 thorpej Exp $");
#include "opt_mbuftrace.h"
#include "opt_atalk.h"
@ -63,7 +63,9 @@ static int at_pcbsetaddr(struct ddpcb *, struct sockaddr_at *);
static int at_pcbconnect(struct ddpcb *, struct sockaddr_at *);
static void ddp_detach(struct socket *);
struct ifqueue atintrq1, atintrq2;
pktqueue_t * at_pktq1 __read_mostly;
pktqueue_t * at_pktq2 __read_mostly;
struct ddpcb *ddp_ports[ATPORT_LAST];
struct ddpcb *ddpcb = NULL;
percpu_t *ddpstat_percpu;
@ -603,10 +605,12 @@ ddp_init(void)
ddpstat_percpu = percpu_alloc(sizeof(uint64_t) * DDP_NSTATS);
TAILQ_INIT(&at_ifaddr);
atintrq1.ifq_maxlen = IFQ_MAXLEN;
atintrq2.ifq_maxlen = IFQ_MAXLEN;
IFQ_LOCK_INIT(&atintrq1);
IFQ_LOCK_INIT(&atintrq2);
at_pktq1 = pktq_create(IFQ_MAXLEN, atintr1, NULL);
KASSERT(at_pktq1 != NULL);
at_pktq2 = pktq_create(IFQ_MAXLEN, atintr2, NULL);
KASSERT(at_pktq2 != NULL);
MOWNER_ATTACH(&atalk_tx_mowner);
MOWNER_ATTACH(&atalk_rx_mowner);