From nobody Mon Feb 9 10:32:49 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 152607783510454.02104108730475; Fri, 11 May 2018 15:30:35 -0700 (PDT) Received: from localhost ([::1]:50241 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fHGYc-0004oH-4U for importer@patchew.org; Fri, 11 May 2018 18:30:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54054) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fHF6x-0002Do-2l for qemu-devel@nongnu.org; Fri, 11 May 2018 16:57:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fHF6w-00055X-0r for qemu-devel@nongnu.org; Fri, 11 May 2018 16:57:55 -0400 Received: from mail-it0-x244.google.com ([2607:f8b0:4001:c0b::244]:54641) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fHF6v-00055T-S9 for qemu-devel@nongnu.org; Fri, 11 May 2018 16:57:53 -0400 Received: by mail-it0-x244.google.com with SMTP id z6-v6so3560869iti.4 for ; Fri, 11 May 2018 13:57:53 -0700 (PDT) Received: from localhost.localdomain (c-24-11-27-195.hsd1.ut.comcast.net. [24.11.27.195]) by smtp.gmail.com with ESMTPSA id n64-v6sm1128000itc.32.2018.05.11.13.57.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 May 2018 13:57:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=yCRJ1oE0jwu5Nd67aIPTuaf4MMC75ottj2xuSOAnfg0=; b=Wgesa4lHCNts0QT233e1JJlvBIm4sIHZcrkD1V7WNRPmehXc70/m/JLlprY0L75//C NWv4/3TIAtGwfgFS/1hB684lpBq4Cido99NkPZ2wWWR+1aK3Ux7qoghEiA7W8GL2IPlY m/reTMWsP5B7sYUQkeP+Q0k9Wk/34IlOLCn18bG98IJaPl0Kcb16jn3/y4e5b5ztFJ8f vwhFxXRyHLCCtAUrvfenchfwhwkJZUOXLQyexLpzS3IYiykvGeg3CuEm7MmS4OtOTv1r Hvwjp+bNxXNqXniEMRGJLWg6qSEujqLvbOfTnJpYOhcZhTVY7/OKnPD+EOcuw+X3wfFn RD6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=yCRJ1oE0jwu5Nd67aIPTuaf4MMC75ottj2xuSOAnfg0=; b=OsVUU7cmTS7PvbCeGMAbvkddpPGh/DOVPkKaXxFBSv47FPwQrq9DMMJFhtPvn2IBG7 67SMAQaOguMhd4j0TY/lRZd+7XDt0OO5NHjRLC/q7GsBhriwNfMjG2wbDdzBYJgW15Pr CPmPUCvH/x7J++Fb+j1Suf0Cb2aNZBVDlz+QxbV5NElRsNujpAXcMmRA1ver8Pq3JIMI etAByQJxYDAyIT8M9c2rhLv/7RjkXC9xN0t04/hswBBaJVhWy3zeBdcW00dPBuevoY98 Kg1ADgr/sshJbJzlmHBCNYwjinROHt3xaUtj0XdpLyOBGFB9C1B1yl2kmHD5goNW6Wx/ qWgA== X-Gm-Message-State: ALKqPwfCdRP3O2jFEbvys9pdaH/rbwTvYPYvlrGkq8NitFODtzbYJiW5 GJ4z7DcE0ZjKY7LiH3u1CzauzAnm X-Google-Smtp-Source: AB8JxZpITNygtPH1dWrzyogspNBKLBIOElc8uN1qD7mmfadw5RtfcJrjObII//eUc+YZKaXUNZz2NA== X-Received: by 2002:a24:4651:: with SMTP id j78-v6mr4940190itb.111.1526072272906; Fri, 11 May 2018 13:57:52 -0700 (PDT) From: Calvin Lee To: qemu-devel@nongnu.org Date: Fri, 11 May 2018 14:57:24 -0600 Message-Id: <20180511205724.4039-3-cyrus296@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180511205724.4039-1-cyrus296@gmail.com> References: <20180511205724.4039-1-cyrus296@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4001:c0b::244 X-Mailman-Approved-At: Fri, 11 May 2018 18:28:34 -0400 Subject: [Qemu-devel] [PATCH RFC 2/2] PC Chipset: Send serial bytes at correct rate 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: Calvin Lee , pbonzini@redhat.com, dgilbert@redhat.com, mst@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This fixes bug in QEMU such that UART bytes would be sent immediatly after being put in the THR regardless of the UART frequency (and divisor). Now they will be sent at the appropriate rate. Signed-off-by: Calvin Lee --- I am not sure about VM migration here. I want to move a struct field from one VMStateDescription to a new one. I did this by bumping the version number on the old VMStateDescription, and kept the field as `_TEST`. If this is incorrect please let me know. hw/char/serial.c | 47 +++++++++++++++++++++++++++++++++++----- include/hw/char/serial.h | 2 ++ 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/hw/char/serial.c b/hw/char/serial.c index 4159a46a2f..b621d99f28 100644 --- a/hw/char/serial.c +++ b/hw/char/serial.c @@ -359,9 +359,8 @@ static void serial_ioport_write(void *opaque, hwaddr ad= dr, uint64_t val, s->lsr &=3D ~UART_LSR_THRE; s->lsr &=3D ~UART_LSR_TEMT; serial_update_irq(s); - if (s->tsr_retry =3D=3D 0) { - serial_xmit(s); - } + timer_mod(s->xmit_timeout_timer, + qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + s->char_transmit_t= ime); } break; case 1: @@ -586,6 +585,15 @@ static void serial_receive_break(SerialState *s) serial_update_irq(s); } =20 +/* There is data to be sent in xmit_fifo or the thr */ +static void xmit_timeout_int(void *opaque) +{ + SerialState *s =3D opaque; + if (s->tsr_retry =3D=3D 0) { + serial_xmit(s); + } +} + /* There's data in recv_fifo and s->rbr has not been read for 4 char trans= mit times */ static void fifo_timeout_int (void *opaque) { SerialState *s =3D opaque; @@ -726,12 +734,13 @@ static bool serial_tsr_needed(void *opaque) =20 static const VMStateDescription vmstate_serial_tsr =3D { .name =3D "serial/tsr", - .version_id =3D 1, + .version_id =3D 2, .minimum_version_id =3D 1, .needed =3D serial_tsr_needed, .fields =3D (VMStateField[]) { VMSTATE_UINT32(tsr_retry, SerialState), - VMSTATE_UINT8(thr, SerialState), + /* Moved to `xmit_timeout_timer` */ + VMSTATE_UINT8_TEST(thr, SerialState, 1); VMSTATE_UINT8(tsr, SerialState), VMSTATE_END_OF_LIST() } @@ -772,6 +781,24 @@ static const VMStateDescription vmstate_serial_xmit_fi= fo =3D { } }; =20 +static bool serial_xmit_timeout_timer_needed(void *opaque) +{ + SerialState *s =3D (SerialState *)opaque; + return timer_pending(s->xmit_timeout_timer); +} + +static const VMStateDescription vmstate_serial_xmit_timeout_timer =3D { + .name =3D "serial/xmit_timeout_timer", + .version_id =3D 1, + .minimum_version_id =3D 1, + .needed =3D serial_xmit_timeout_timer_needed, + .fields =3D (VMStateField[]) { + VMSTATE_UINT8(thr, SerialState), + VMSTATE_TIMER_PTR(xmit_timeout_timer, SerialState), + VMSTATE_END_OF_LIST() + } +}; + static bool serial_fifo_timeout_timer_needed(void *opaque) { SerialState *s =3D (SerialState *)opaque; @@ -849,6 +876,7 @@ const VMStateDescription vmstate_serial =3D { &vmstate_serial_tsr, &vmstate_serial_recv_fifo, &vmstate_serial_xmit_fifo, + &vmstate_serial_xmit_timeout_timer, &vmstate_serial_fifo_timeout_timer, &vmstate_serial_timeout_ipending, &vmstate_serial_poll, @@ -880,6 +908,7 @@ static void serial_reset(void *opaque) s->poll_msl =3D 0; =20 s->timeout_ipending =3D 0; + timer_del(s->xmit_timeout_timer); timer_del(s->fifo_timeout_timer); timer_del(s->modem_status_poll); =20 @@ -928,7 +957,10 @@ void serial_realize_core(SerialState *s, Error **errp) { s->modem_status_poll =3D timer_new_ns(QEMU_CLOCK_VIRTUAL, (QEMUTimerCB= *) serial_update_msl, s); =20 - s->fifo_timeout_timer =3D timer_new_ns(QEMU_CLOCK_VIRTUAL, (QEMUTimerC= B *) fifo_timeout_int, s); + s->xmit_timeout_timer =3D + timer_new_ns(QEMU_CLOCK_VIRTUAL, (QEMUTimerCB *) xmit_timeout_int,= s); + s->fifo_timeout_timer =3D + timer_new_ns(QEMU_CLOCK_VIRTUAL, (QEMUTimerCB *) fifo_timeout_int,= s); qemu_register_reset(serial_reset, s); =20 qemu_chr_fe_set_handlers(&s->chr, serial_can_receive1, serial_receive1, @@ -945,6 +977,9 @@ void serial_exit_core(SerialState *s) timer_del(s->modem_status_poll); timer_free(s->modem_status_poll); =20 + timer_del(s->xmit_timeout_timer); + timer_free(s->xmit_timeout_timer); + timer_del(s->fifo_timeout_timer); timer_free(s->fifo_timeout_timer); =20 diff --git a/include/hw/char/serial.h b/include/hw/char/serial.h index 0acfbbc382..09aece90fb 100644 --- a/include/hw/char/serial.h +++ b/include/hw/char/serial.h @@ -65,6 +65,8 @@ struct SerialState { /* Time when the last byte was successfully sent out of the tsr */ uint64_t last_xmit_ts; Fifo8 recv_fifo; + /* Time to read the next byte from the thr */ + QEMUTimer *xmit_timeout_timer; Fifo8 xmit_fifo; /* Interrupt trigger level for recv_fifo */ uint8_t recv_fifo_itl; --=20 2.17.0