From 084009e28b58577006b6b58af0e8dc60ef7413bc Mon Sep 17 00:00:00 2001 From: Sepherosa Ziehau Date: Thu, 17 Nov 2011 21:42:29 +0800 Subject: [PATCH] sendfile: Use asynchronized pru_send when ever possible On Phenom 9550 (4 core, 2.2GHz): 8 parallel netperf -H 127.0.0.1 -t TCP_SENDFILE -P0 (4 runs, unit: Mbps) old 10509.48 12364.60 11930.55 11104.94 new 21031.34 20165.39 19888.42 19896.47 This give 70% ~ 90% performance improvement --- sys/kern/uipc_syscalls.c | 4 ++-- sys/sys/socketops.h | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/sys/kern/uipc_syscalls.c b/sys/kern/uipc_syscalls.c index 561233b2f6..9b87fe2943 100644 --- a/sys/kern/uipc_syscalls.c +++ b/sys/kern/uipc_syscalls.c @@ -1768,7 +1768,7 @@ retry_space: } goto retry_space; } - error = so_pru_send(so, 0, m, NULL, NULL, td); + error = so_pru_senda(so, 0, m, NULL, NULL, td); crit_exit(); if (error) { ssb_unlock(&so->so_snd); @@ -1777,7 +1777,7 @@ retry_space: } if (mheader != NULL) { *sbytes += mheader->m_pkthdr.len; - error = so_pru_send(so, 0, mheader, NULL, NULL, td); + error = so_pru_senda(so, 0, mheader, NULL, NULL, td); mheader = NULL; } ssb_unlock(&so->so_snd); diff --git a/sys/sys/socketops.h b/sys/sys/socketops.h index 6159c8d6d7..ea43075276 100644 --- a/sys/sys/socketops.h +++ b/sys/sys/socketops.h @@ -106,5 +106,17 @@ int so_pr_ctloutput(struct socket *so, struct sockopt *sopt); void so_pru_ctlinput(struct protosw *pr, int cmd, struct sockaddr *arg, void *extra); +static __inline int +so_pru_senda(struct socket *so, int flags, struct mbuf *m, + struct sockaddr *addr, struct mbuf *control, struct thread *td) +{ + if (so->so_proto->pr_flags & PR_ASYNC_SEND) { + so_pru_send_async(so, flags, m, addr, control, td); + return 0; + } else { + return so_pru_send(so, flags, m, addr, control, td); + } +} + #endif /* _KERNEL */ #endif /* _SYS_SOCKETOPS_H_ */ -- 2.41.0