From 5df412519bc2acc8eb67339957ad11a8507ceb12 Mon Sep 17 00:00:00 2001 From: Pau Espin Pedrol Date: Tue, 20 Dec 2022 15:21:00 +0100 Subject: stream: Avoid useless polling if tx_queue becomes empty Before this patch, the WRITE poll flag was being left ON and waited to be polled again by the kernel in order to disable it. Let's spate that extra polling cycle which only creates more polling triggers, context switches, etc. Change-Id: I1dd2145249a7322ad95e49be588fd472f00734e1 --- src/stream.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/stream.c b/src/stream.c index 1ca4e9a..503fe3c 100644 --- a/src/stream.c +++ b/src/stream.c @@ -387,7 +387,12 @@ static int osmo_stream_cli_write(struct osmo_stream_cli *cli) } else if (ret < msgb_length(msg)) { LOGP(DLINP, LOGL_ERROR, "short send: %d < exp %u\n", ret, msgb_length(msg)); } + msgb_free(msg); + + if (llist_empty(&cli->tx_queue)) + osmo_fd_write_disable(&cli->ofd); + return 0; } @@ -1351,8 +1356,11 @@ static void osmo_stream_srv_write(struct osmo_stream_srv *conn) msgb_free(msg); - if (llist_empty(&conn->tx_queue) && (conn->flags & OSMO_STREAM_SRV_F_FLUSH_DESTROY)) - osmo_stream_srv_destroy(conn); + if (llist_empty(&conn->tx_queue)) { + osmo_fd_write_disable(&conn->ofd); + if (conn->flags & OSMO_STREAM_SRV_F_FLUSH_DESTROY) + osmo_stream_srv_destroy(conn); + } } static int osmo_stream_srv_cb(struct osmo_fd *ofd, unsigned int what) -- cgit v1.2.3