From ee0be9cabc250df6c078d8ba38a9596d39b98721 Mon Sep 17 00:00:00 2001 From: Sepherosa Ziehau Date: Wed, 18 Jun 2014 21:16:58 +0800 Subject: [PATCH] net: Add initport protosw method to init socket's default protocol port Currently only tcp implements this method to distribute pru_attach and pru_connect workload. Nuke no longer necessary protosw flag PR_RAND_INITPORT and sysctl kern.ipc.rand_initport. --- sys/kern/uipc_socket.c | 21 ++++++++------------- sys/netinet/in_proto.c | 4 ++-- sys/netinet/ip_demux.c | 6 ++++++ sys/netinet/tcp_var.h | 2 ++ sys/sys/protosw.h | 4 +++- 5 files changed, 21 insertions(+), 16 deletions(-) diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c index 162ac332b9..249d56a8ab 100644 --- a/sys/kern/uipc_socket.c +++ b/sys/kern/uipc_socket.c @@ -150,10 +150,6 @@ int use_soconnect_async = 1; SYSCTL_INT(_kern_ipc, OID_AUTO, soconnect_async, CTLFLAG_RW, &use_soconnect_async, 0, "soconnect uses asynchronized pru_connect"); -int use_rand_initport = 1; -SYSCTL_INT(_kern_ipc, OID_AUTO, rand_initport, CTLFLAG_RW, - &use_rand_initport, 0, "socket uses random initial msgport"); - /* * Socket operation routines. * These routines are called by the routines in @@ -240,20 +236,19 @@ socreate(int dom, struct socket **aso, int type, * is able to match incoming packets, or until the socket becomes * available to userland. * - * We normally default the socket to the protocol thread on cpu 0. + * We normally default the socket to the protocol thread on cpu 0, + * if protocol does not provide its own method to initialize the + * default port. + * * If PR_SYNC_PORT is set (unix domain sockets) there is no protocol * thread and all pr_*()/pru_*() calls are executed synchronously. */ - if (prp->pr_flags & PR_SYNC_PORT) { + if (prp->pr_flags & PR_SYNC_PORT) so->so_port = &netisr_sync_port; - } else if (prp->pr_flags & PR_RAND_INITPORT) { - if (use_rand_initport) - so->so_port = netisr_cpuport(mycpuid & ncpus2_mask); - else - so->so_port = netisr_cpuport(0); - } else { + else if (prp->pr_initport != NULL) + so->so_port = prp->pr_initport(); + else so->so_port = netisr_cpuport(0); - } TAILQ_INIT(&so->so_incomp); TAILQ_INIT(&so->so_comp); diff --git a/sys/netinet/in_proto.c b/sys/netinet/in_proto.c index c57cd3e4fc..6d62f47836 100644 --- a/sys/netinet/in_proto.c +++ b/sys/netinet/in_proto.c @@ -136,9 +136,9 @@ struct protosw inetsw[] = { .pr_domain = &inetdomain, .pr_protocol = IPPROTO_TCP, .pr_flags = PR_CONNREQUIRED|PR_WANTRCVD|PR_MPSAFE| - PR_ASYNC_SEND|PR_ASYNC_RCVD|PR_ACONN_HOLDTD| - PR_RAND_INITPORT, + PR_ASYNC_SEND|PR_ASYNC_RCVD|PR_ACONN_HOLDTD, + .pr_initport = tcp_initport, .pr_input = tcp_input, .pr_output = NULL, .pr_ctlinput = tcp_ctlinput, diff --git a/sys/netinet/ip_demux.c b/sys/netinet/ip_demux.c index d668d4e2eb..bf5971bced 100644 --- a/sys/netinet/ip_demux.c +++ b/sys/netinet/ip_demux.c @@ -469,3 +469,9 @@ udp_ctlport(int cmd, struct sockaddr *sa, void *vip) } return (netisr_cpuport(cpu)); } + +struct lwkt_port * +tcp_initport(void) +{ + return netisr_cpuport(mycpuid & ncpus2_mask); +} diff --git a/sys/netinet/tcp_var.h b/sys/netinet/tcp_var.h index 9f0599408a..1bd26c3cd2 100644 --- a/sys/netinet/tcp_var.h +++ b/sys/netinet/tcp_var.h @@ -702,6 +702,8 @@ struct lwkt_port * tcp_soport(struct socket *, struct sockaddr *, struct mbuf **); struct lwkt_port * tcp_ctlport(int, struct sockaddr *, void *); +struct lwkt_port * + tcp_initport(void); struct tcpcb * tcp_timers (struct tcpcb *, int); void tcp_trace (short, short, struct tcpcb *, void *, struct tcphdr *, diff --git a/sys/sys/protosw.h b/sys/sys/protosw.h index d9a628ce80..ad1b066d29 100644 --- a/sys/sys/protosw.h +++ b/sys/sys/protosw.h @@ -88,6 +88,9 @@ struct protosw { short pr_protocol; /* protocol number */ short pr_flags; /* see below */ + struct lwkt_port *(*pr_initport)(void); + /* initial msgport */ + /* * Protocol hooks. These are typically called directly within the * context of a protocol thread based on the toeplitz hash. @@ -148,7 +151,6 @@ struct protosw { #define PR_ASYNC_RCVD 0x0800 /* async pru_rcvd */ #define PR_ASEND_HOLDTD 0x1000 /* async pru_send hold orig thread */ #define PR_ACONN_HOLDTD 0x2000 /* async pru_connect hold orig thread */ -#define PR_RAND_INITPORT 0x4000 /* random init msgport */ /* * The arguments to usrreq are: -- 2.41.0