From patchwork Thu Feb 7 14:02:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 10801309 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EFB601390 for ; Thu, 7 Feb 2019 14:08:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DEE842D84B for ; Thu, 7 Feb 2019 14:08:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D2E592D859; Thu, 7 Feb 2019 14:08:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 67BE02D84B for ; Thu, 7 Feb 2019 14:08:49 +0000 (UTC) Received: from localhost ([127.0.0.1]:40647 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkMC-0005yM-L4 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 07 Feb 2019 09:08:48 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57378) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkHS-00024O-4j for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:04:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grkHP-0000xn-Rr for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:03:53 -0500 Received: from hera.aquilenet.fr ([2a0c:e300::1]:49834) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grkHN-0000uR-N0 for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:03:51 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id E9402CD21; Thu, 7 Feb 2019 15:03:28 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id impem3-ONRoD; Thu, 7 Feb 2019 15:03:27 +0100 (CET) Received: from function (unknown [160.40.205.85]) by hera.aquilenet.fr (Postfix) with ESMTPSA id B5139CD27; Thu, 7 Feb 2019 15:03:19 +0100 (CET) Received: from samy by function with local (Exim 4.92-RC4) (envelope-from ) id 1grkGr-0004DQ-F2; Thu, 07 Feb 2019 15:03:17 +0100 From: Samuel Thibault To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Thu, 7 Feb 2019 16:02:58 +0200 Message-Id: <20190207140316.16103-15-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> References: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a0c:e300::1 Subject: [Qemu-devel] [PULLv4 14/32] slirp: replace qemu_notify_event() with a callback X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Samuel Thibault , stefanha@redhat.com, jan.kiszka@siemens.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Marc-André Lureau Introduce a SlirpCb callback to kick the main io-thread. Add an intermediary sodrop() function that will call SlirpCb.notify callback when sbdrop() returns true. Signed-off-by: Marc-André Lureau Signed-off-by: Samuel Thibault --- net/slirp.c | 1 + slirp/libslirp.h | 2 ++ slirp/sbuf.c | 6 ++++-- slirp/sbuf.h | 2 +- slirp/socket.c | 7 +++++++ slirp/socket.h | 1 + slirp/tcp_input.c | 6 +++--- 7 files changed, 19 insertions(+), 6 deletions(-) diff --git a/net/slirp.c b/net/slirp.c index 78ba96b63f..7b4f9f5c5e 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -205,6 +205,7 @@ static const SlirpCb slirp_cb = { .timer_mod = net_slirp_timer_mod, .register_poll_fd = net_slirp_register_poll_fd, .unregister_poll_fd = net_slirp_unregister_poll_fd, + .notify = qemu_notify_event, }; static int net_slirp_init(NetClientState *peer, const char *model, diff --git a/slirp/libslirp.h b/slirp/libslirp.h index 8ce69f0be3..679a25422b 100644 --- a/slirp/libslirp.h +++ b/slirp/libslirp.h @@ -31,6 +31,8 @@ typedef struct SlirpCb { void (*register_poll_fd)(int fd); /* Unregister a fd */ void (*unregister_poll_fd)(int fd); + /* Kick the io-thread, to signal that new events may be processed */ + void (*notify)(void); } SlirpCb; diff --git a/slirp/sbuf.c b/slirp/sbuf.c index 912f235f65..17f28e97a6 100644 --- a/slirp/sbuf.c +++ b/slirp/sbuf.c @@ -17,7 +17,7 @@ sbfree(struct sbuf *sb) free(sb->sb_data); } -void +bool sbdrop(struct sbuf *sb, int num) { int limit = sb->sb_datalen / 2; @@ -34,8 +34,10 @@ sbdrop(struct sbuf *sb, int num) sb->sb_rptr -= sb->sb_datalen; if (sb->sb_cc < limit && sb->sb_cc + num >= limit) { - qemu_notify_event(); + return true; } + + return false; } void diff --git a/slirp/sbuf.h b/slirp/sbuf.h index 644c201341..1cb9a42834 100644 --- a/slirp/sbuf.h +++ b/slirp/sbuf.h @@ -21,7 +21,7 @@ struct sbuf { }; void sbfree(struct sbuf *); -void sbdrop(struct sbuf *, int); +bool sbdrop(struct sbuf *, int); void sbreserve(struct sbuf *, int); void sbappend(struct socket *, struct mbuf *); void sbcopy(struct sbuf *, int, int, char *); diff --git a/slirp/socket.c b/slirp/socket.c index 5805d30f3d..2e8dc22fb6 100644 --- a/slirp/socket.c +++ b/slirp/socket.c @@ -928,3 +928,10 @@ void sotranslate_accept(struct socket *so) break; } } + +void sodrop(struct socket *s, int num) +{ + if (sbdrop(&s->so_snd, num)) { + s->slirp->cb->notify(); + } +} diff --git a/slirp/socket.h b/slirp/socket.h index fc35ca5f72..1c1c8b5871 100644 --- a/slirp/socket.h +++ b/slirp/socket.h @@ -156,6 +156,7 @@ int soreadbuf(struct socket *so, const char *buf, int size); void sotranslate_out(struct socket *, struct sockaddr_storage *); void sotranslate_in(struct socket *, struct sockaddr_storage *); void sotranslate_accept(struct socket *); +void sodrop(struct socket *, int num); #endif /* SLIRP_SOCKET_H */ diff --git a/slirp/tcp_input.c b/slirp/tcp_input.c index de5b74a52b..7c1fe18fec 100644 --- a/slirp/tcp_input.c +++ b/slirp/tcp_input.c @@ -506,7 +506,7 @@ findso: SEQ_GT(ti->ti_ack, tp->t_rtseq)) tcp_xmit_timer(tp, tp->t_rtt); acked = ti->ti_ack - tp->snd_una; - sbdrop(&so->so_snd, acked); + sodrop(so, acked); tp->snd_una = ti->ti_ack; m_free(m); @@ -1118,10 +1118,10 @@ trimthenstep6: } if (acked > so->so_snd.sb_cc) { tp->snd_wnd -= so->so_snd.sb_cc; - sbdrop(&so->so_snd, (int )so->so_snd.sb_cc); + sodrop(so, (int)so->so_snd.sb_cc); ourfinisacked = 1; } else { - sbdrop(&so->so_snd, acked); + sodrop(so, acked); tp->snd_wnd -= acked; ourfinisacked = 0; }