From: Rob Landley <rob@landley.net>
To: "H. Peter Anvin" <hpa@zytor.com>
Cc: qemu-devel@nongnu.org
Subject: [Qemu-devel] Re: 2.6.24 says "serial8250: too much work for irq4" a lot.
Date: Fri, 8 Feb 2008 23:49:34 -0600 [thread overview]
Message-ID: <200802082349.34301.rob@landley.net> (raw)
In-Reply-To: <47AB75EB.3040405@zytor.com>
Here's a patch Peter Anvin wrote so the serial I/O doesn't flood the kernel.
Here's the thread on linux-kernel aboout it:
http://lkml.org/lkml/2008/2/5/401
Rob
On Thursday 07 February 2008 15:19:39 you wrote:
> Rob Landley wrote:
> > Specifically, qemu isn't paravirtualized, it's fully virtualized. The
> > same kernel can run on real hardware just fine. (Sort of the point of
> > the project...)
> >
> > I can yank the warning for the kernels I build (or set PASS_LIMIT to
> > 9999999), but I'd rather not carry any more patches than I can avoid...
>
> Patch attached, completely untested beyond compilation.
>
> In particular:
>
> - we should probably clear the burst counter when the interrupt
> line goes from inactive to active.
> - there probably should be a timer which clears the burst
> counter.
>
> However, I think I've covered most of the bases...
>
> -hpa
diff --git a/hw/serial.c b/hw/serial.c
index b1bd0ff..c902792 100644
--- a/hw/serial.c
+++ b/hw/serial.c
@@ -73,6 +73,15 @@
#define UART_LSR_OE 0x02 /* Overrun error indicator */
#define UART_LSR_DR 0x01 /* Receiver data ready */
+/*
+ * It's common for an IRQ handler to keep reading the RBR until
+ * the LSR indicates that the FIFO is empty, expecting that the
+ * CPU is vastly faster than the serial line. This can cause
+ * overruns or error indications if the FIFO never empties, so
+ * give the target OS a breather every so often.
+ */
+#define MAX_BURST 512
+
struct SerialState {
uint16_t divider;
uint8_t rbr; /* receive register */
@@ -91,8 +100,14 @@ struct SerialState {
int last_break_enable;
target_phys_addr_t base;
int it_shift;
+ int burst_len;
};
+static void serial_clear_burst(SerialState *s)
+{
+ s->burst_len = 0;
+}
+
static void serial_update_irq(SerialState *s)
{
if ((s->lsr & UART_LSR_DR) && (s->ier & UART_IER_RDI)) {
@@ -114,6 +129,8 @@ static void serial_update_parameters(SerialState *s)
int speed, parity, data_bits, stop_bits;
QEMUSerialSetParams ssp;
+ serial_clear_burst(s);
+
if (s->lcr & 0x08) {
if (s->lcr & 0x10)
parity = 'E';
@@ -221,9 +238,12 @@ static uint32_t serial_ioport_read(void *opaque, uint32_t addr)
ret = s->divider & 0xff;
} else {
ret = s->rbr;
- s->lsr &= ~(UART_LSR_DR | UART_LSR_BI);
- serial_update_irq(s);
- qemu_chr_accept_input(s->chr);
+ if (s->burst_len < MAX_BURST) {
+ s->burst_len++;
+ s->lsr &= ~(UART_LSR_DR | UART_LSR_BI);
+ serial_update_irq(s);
+ qemu_chr_accept_input(s->chr);
+ }
}
break;
case 1:
@@ -235,6 +255,7 @@ static uint32_t serial_ioport_read(void *opaque, uint32_t addr)
break;
case 2:
ret = s->iir;
+ serial_clear_burst(s);
/* reset THR pending bit */
if ((ret & 0x7) == UART_IIR_THRI)
s->thr_ipending = 0;
@@ -248,6 +269,10 @@ static uint32_t serial_ioport_read(void *opaque, uint32_t addr)
break;
case 5:
ret = s->lsr;
+ if (s->burst_len >= MAX_BURST)
+ ret &= ~(UART_LSR_DR|UART_LSR_BI);
+ if (!(ret & UART_LSR_DR))
+ serial_clear_burst(s);
break;
case 6:
if (s->mcr & UART_MCR_LOOP) {
--
"One of my most productive days was throwing away 1000 lines of code."
- Ken Thompson.
next prev parent reply other threads:[~2008-02-09 5:49 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <200802051455.10831.rob@landley.net>
[not found] ` <47A8D00F.9040803@zytor.com>
2008-02-06 0:43 ` [Qemu-devel] Re: 2.6.24 says "serial8250: too much work for irq4" a lot Rob Landley
[not found] ` <200802071413.45085.rob@landley.net>
[not found] ` <47AB75EB.3040405@zytor.com>
2008-02-09 5:49 ` Rob Landley [this message]
2008-02-09 7:04 ` Blue Swirl
2008-02-09 7:12 ` H. Peter Anvin
2008-02-09 11:15 ` Blue Swirl
2008-02-09 21:36 ` H. Peter Anvin
2008-02-10 8:01 ` Blue Swirl
2008-02-10 11:26 ` Paul Brook
2008-03-11 23:51 ` Aurelien Jarno
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200802082349.34301.rob@landley.net \
--to=rob@landley.net \
--cc=hpa@zytor.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).