From patchwork Tue Feb 5 18:28:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 10798321 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 2F643746 for ; Tue, 5 Feb 2019 20:01:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 22C982CA10 for ; Tue, 5 Feb 2019 20:01:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1FF402CA1A; Tue, 5 Feb 2019 20:01:25 +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 96C522CA19 for ; Tue, 5 Feb 2019 20:01:24 +0000 (UTC) Received: from localhost ([127.0.0.1]:39567 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gr6uJ-0005OX-9q for patchwork-qemu-devel@patchwork.kernel.org; Tue, 05 Feb 2019 15:01:23 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42460) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gr5TF-0005Ev-J3 for qemu-devel@nongnu.org; Tue, 05 Feb 2019 13:29:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gr5TD-0005iv-Os for qemu-devel@nongnu.org; Tue, 05 Feb 2019 13:29:21 -0500 Received: from hera.aquilenet.fr ([185.233.100.1]:34810) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gr5TD-0005UT-5N for qemu-devel@nongnu.org; Tue, 05 Feb 2019 13:29:19 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 4FF21C10F; Tue, 5 Feb 2019 19:29:09 +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 p3EKD6CxGqa9; Tue, 5 Feb 2019 19:29:07 +0100 (CET) Received: from function (unknown [188.164.201.34]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 93592C124; Tue, 5 Feb 2019 19:28:55 +0100 (CET) Received: from samy by function with local (Exim 4.92-RC4) (envelope-from ) id 1gr5Sj-0007ni-LR; Tue, 05 Feb 2019 19:28:49 +0100 From: Samuel Thibault To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Tue, 5 Feb 2019 20:28:30 +0200 Message-Id: <20190205182848.29887-15-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190205182848.29887-1-samuel.thibault@ens-lyon.org> References: <20190205182848.29887-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 185.233.100.1 Subject: [Qemu-devel] [PULLv3 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; }