From patchwork Sat Feb 8 16:39:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 863294 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e42:0:b0:385:e875:8a9e with SMTP id r2csp874030wrt; Sat, 8 Feb 2025 08:41:02 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXlGmd/uYdEPyYaJ6IeKDROePxntJaM+/dTNoTV7an8/4nqUuvMo7BztOPeCdOk2+5aWWzrGQ==@linaro.org X-Google-Smtp-Source: AGHT+IHIvPSOJRev4SpdaNypb5sSCL1NtVGAbEuq+tXiTn/bqOtce09Dxfq0+15uLwZ6VRK/SlHu X-Received: by 2002:a05:622a:182a:b0:46e:4de6:8a06 with SMTP id d75a77b69052e-47167b1c3f6mr94328401cf.52.1739032862549; Sat, 08 Feb 2025 08:41:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1739032862; cv=none; d=google.com; s=arc-20240605; b=Nzjmy+xVv85L/DTN8kakmLavQonH5wYtf14Km1fmoru9FGj+YswUl/vz8W53+xX33y vnUsPFqYV3mJDwff3ezX8kNv7USbyac0gvLK44ATFJz7Y5Ux3qVkCHwnuJBxzwFTlMsv TzoWI/ixb8KrmqN8GpB9aROFtb/hMZ9BnqW6/c14b/wQ0i6neatVRXXo64pdvsJ90aoW A0MytZ5HT0aQgZDXMOSGmN5ZZavvNMLoPpQef9FWC7cliKGK1cptaE/D6qmgh79opHLr RwuC0ofb43ADAyI0aO3ossjcUPBCghLPlkEOHuzO1lGYtvtuAvUr8L4MvJk6WLVq5Agl cVKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=jH9Ymqij6X/GfoOzNSD/xDBEcCWv01J+bpak1JyU5gs=; fh=WGFE+0W6f+dD3jknfQlrhoGgO7GDhxdk3Z2S7mb98/0=; b=O7Tk3WWKEixZp1HEWP8vSXC+7ZX9n5aZqK4qm2UF4eLv6+oG8HqZcgYxmWJYG2BmMU ta8VEME/PqWcZDAFwxu30ugSbRcohakUh5Udx+6Igji/hwJpsJYZ0xFcfbAOqGBogHY1 m7wmYwocprJvq7QOwZBmCPZ5065XD0ywu2IIRP3X4ebifpZnsyo+4lASIqL0AFr2gbo4 2rbPPqUkeTSsnvvs3+JmTDNutc/WBBjFqn4QZB936CdRvs1TeUb5gItGM7HYo0S5QCuy 1CX5IJjC1ddnmO6mffvujIuuSWCV+Cs+8iJ8E+BFkn6KkDpsQcjtD76f0Z48FKh8R4D/ cUJQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=B2uuuX1O; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-47153b90ac0si60674551cf.357.2025.02.08.08.41.02 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 08 Feb 2025 08:41:02 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=B2uuuX1O; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tgns5-0001DD-Uq; Sat, 08 Feb 2025 11:39:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tgns3-00019i-5f for qemu-devel@nongnu.org; Sat, 08 Feb 2025 11:39:55 -0500 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tgns1-0000JF-77 for qemu-devel@nongnu.org; Sat, 08 Feb 2025 11:39:54 -0500 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-4361b0ec57aso29811455e9.0 for ; Sat, 08 Feb 2025 08:39:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1739032791; x=1739637591; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jH9Ymqij6X/GfoOzNSD/xDBEcCWv01J+bpak1JyU5gs=; b=B2uuuX1OyrMlAAe9XDZmfCWKlL1mSejNcoLOwlR0cXLSdWackCCdVMmsum0sR0kzhF 1iV4V8XIlIfF26D14fMXo8YZLPHIbqlsM7McLGS6k2ycmIPJP7P3vP86kTXftHpoXvGd WiDUFF26HkK0q1Wmv/rxiOWCA9/Nres+RRoBRUkZwYjhxG/eijcQP+KvdnTguwYFpoQT qC1z9eWCdiZLaW/yxQFStzR4fnmRg5TI3TUMljxs4CepMAM8uPy8LeQJy9JlFUM4PB8r bVpJssTz2dLRencvf/OWmYrkyKwAW1fphvxYuwNtOSTcxaK9f8YdVBzBgMJODv2gisD5 HP3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739032791; x=1739637591; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jH9Ymqij6X/GfoOzNSD/xDBEcCWv01J+bpak1JyU5gs=; b=jmL0t83q8cCam6PbEJ6hD4rtJ1zgCY3TCtGbxStSA6DRor4Pl4cnMYa4IxWlrQKA3E gCdFZOym0x+5/VrucpDmdjMJmFbGpYtgnZFrOyaRexeVrojV5BY00mtnjC/PjjZVmhBU SqLs+aX52MNEs70gdLHno8MeYxS/3tL8MqFO/eCp4S2X0OKNpuCb91YJh+kqyD2nEF7h izNVz6Gt0f0x19sYbnOBSuiMPLkI6mvkMUAVlQgS2fFY9QCSA/ECILzCpzz6MTEZ5u7W wx/vFEGQcn9II/FwbUUyJQ6wSKEAkIGpPKrYJA/HyIWKNB0ShVDRGnyqHoRB06hZuL4l 4wdw== X-Gm-Message-State: AOJu0YxLR2Hvz6nf7USxnDIYihp528C2XWJ6NiVsU5eS0E8FD/Lic1ID ylE069p93noqKUaa/JB59EqSyCcQW+x8bK5FU5WJGQkoGJ+dbHJ0ebVBnStFStIuNKF+PFovGoQ g1cE= X-Gm-Gg: ASbGncuTH/u9cMWXcMApX3ARJ3GVpgNjvrlF2I3lMio3kBebbEdaqnRvP6nTuAtFab1 LkzlBpyGWYQbIs5RwTQgI23qBubi15GfMoJiCKh3H5ARcvTxLaHqqGrkI9+z+LjWKE5QCdkQfSh nDikQiR2tukMZ2a3HfZgG2KhU8oO69/gQIcSDUqFX1kwHEP3d1oWQQgTfg34FyQOAHz8iW6H9Ux 0UR71BUgKoEJmnGiq5O0k1+oewnmIRzs86wb7ERFcv/yHGVNPbhoccBkZ/loQrkCMdrxEaA5NKb z/IdgmjMRZbvxo25qnwKxNcrWWMuQgltDm0Z8TiNcBYXdMZsj5tN/bCAlaawwiTxLA== X-Received: by 2002:a05:600c:5114:b0:434:ff25:199f with SMTP id 5b1f17b1804b1-439249bd37amr48708985e9.26.1739032791285; Sat, 08 Feb 2025 08:39:51 -0800 (PST) Received: from localhost.localdomain (88-187-86-199.subs.proxad.net. [88.187.86.199]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4390d964c7csm124586685e9.17.2025.02.08.08.39.49 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 08 Feb 2025 08:39:50 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Paolo Bonzini , qemu-arm@nongnu.org, Mark Cave-Ayland , =?utf-8?q?Alex_Benn=C3=A9?= =?utf-8?q?e?= , Peter Maydell , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Mikko Rapeli Subject: [PATCH v6 7/7] hw/char/pl011: Implement TX FIFO Date: Sat, 8 Feb 2025 17:39:11 +0100 Message-ID: <20250208163911.54522-8-philmd@linaro.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250208163911.54522-1-philmd@linaro.org> References: <20250208163911.54522-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=philmd@linaro.org; helo=mail-wm1-x32e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org If the UART back-end chardev doesn't drain data as fast as stdout does or blocks, buffer in the TX FIFO to try again later. This avoids having the IO-thread busy waiting on chardev back-ends, reported recently when testing the Trusted Reference Stack and using the socket backend. Implement registering a front-end 'watch' callback on back-end events, so we can resume transmitting when the back-end is writable again, not blocking the main loop. Similarly to the RX FIFO path, FIFO level selection is not implemented (interrupt is triggered when a single byte is available in the FIFO). Reported-by: Mikko Rapeli Suggested-by: Alex Bennée Signed-off-by: Philippe Mathieu-Daudé --- hw/char/pl011.c | 39 +++++++++++++++++++++++++++++++-------- hw/char/trace-events | 1 + 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/hw/char/pl011.c b/hw/char/pl011.c index 3c4264869df..70eba224a9c 100644 --- a/hw/char/pl011.c +++ b/hw/char/pl011.c @@ -251,11 +251,15 @@ static gboolean pl011_xmit(void *do_not_use, GIOCondition cond, void *opaque) { PL011State *s = opaque; int bytes_consumed; - uint8_t data; + uint8_t buf[PL011_FIFO_DEPTH]; uint32_t count; count = fifo8_num_used(&s->xmit_fifo); trace_pl011_fifo_tx_xmit_used(count); + if (count < 1) { + /* FIFO empty */ + return G_SOURCE_REMOVE; + } if (!qemu_chr_fe_backend_connected(&s->chr)) { /* Instant drain the fifo when there's no back-end. */ @@ -263,19 +267,29 @@ static gboolean pl011_xmit(void *do_not_use, GIOCondition cond, void *opaque) return G_SOURCE_REMOVE; } - data = fifo8_pop(&s->xmit_fifo); - bytes_consumed = 1; + count = fifo8_peek_buf(&s->xmit_fifo, buf, fifo8_num_used(&s->xmit_fifo)); + trace_pl011_fifo_tx_xmit_peek(count); - /* - * XXX this blocks entire thread. Rewrite to use - * qemu_chr_fe_write and background I/O callbacks - */ - qemu_chr_fe_write_all(&s->chr, &data, bytes_consumed); + /* Transmit as much data as we can. */ + bytes_consumed = qemu_chr_fe_write(&s->chr, buf, count); trace_pl011_fifo_tx_xmit_consumed(bytes_consumed); + if (bytes_consumed < 0) { + /* Error in back-end: drain the fifo. */ + pl011_drain_tx(s); + return G_SOURCE_REMOVE; + } + + /* Pop the data we could transmit. */ + fifo8_drop(&s->xmit_fifo, bytes_consumed); s->int_level |= INT_TX; pl011_update(s); + if (!fifo8_is_empty(&s->xmit_fifo)) { + /* Reschedule another transmission if we couldn't transmit all. */ + return G_SOURCE_CONTINUE; + } + return G_SOURCE_REMOVE; } @@ -300,6 +314,10 @@ static void pl011_write_txdata(PL011State *s, uint8_t data) trace_pl011_fifo_tx_put(data); pl011_loopback_tx(s, data); fifo8_push(&s->xmit_fifo, data); + if (pl011_is_tx_fifo_full(s)) { + s->flags |= PL011_FLAG_TXFF; + } + pl011_xmit(NULL, G_IO_OUT, s); } @@ -651,6 +669,11 @@ static int pl011_post_load(void *opaque, int version_id) s->read_pos = 0; } + if (!fifo8_is_empty(&s->xmit_fifo)) { + /* Reschedule another transmission */ + qemu_chr_fe_add_watch(&s->chr, G_IO_OUT | G_IO_HUP, pl011_xmit, s); + } + s->ibrd &= IBRD_MASK; s->fbrd &= FBRD_MASK; diff --git a/hw/char/trace-events b/hw/char/trace-events index 7d1cba1b4f8..2d02c057483 100644 --- a/hw/char/trace-events +++ b/hw/char/trace-events @@ -69,6 +69,7 @@ pl011_fifo_rx_put(uint32_t c, int read_count) "new char 0x%02x read_count now %d pl011_fifo_rx_full(void) "RX FIFO now full, RXFF set" pl011_fifo_tx_is_full(const char *desc, bool full) "mode:%s full:%u" pl011_fifo_tx_put(uint8_t byte) "TX FIFO push char [0x%02x]" +pl011_fifo_tx_xmit_peek(unsigned sent) "TX FIFO peek %u chars" pl011_fifo_tx_xmit_used(unsigned sent) "TX FIFO used %u chars" pl011_fifo_tx_xmit_consumed(unsigned sent) "TX FIFO consumed %u chars" pl011_fifo_tx_overrun(void) "TX FIFO overrun"