diff options
author | Andrew Waterman <andrew@sifive.com> | 2023-01-11 15:38:00 -0800 |
---|---|---|
committer | Andrew Waterman <andrew@sifive.com> | 2023-01-11 15:41:28 -0800 |
commit | 32cf5bb54a088385f8e27174c2caf4722cf7f0de (patch) | |
tree | 6abb4fefdd7388cb6e554f8b2fb3a9dc95b8158b /riscv/ns16550.cc | |
parent | 9874c1767179250e25094ccc6757a5faad9d99d1 (diff) | |
download | riscv-isa-sim-32cf5bb54a088385f8e27174c2caf4722cf7f0de.zip riscv-isa-sim-32cf5bb54a088385f8e27174c2caf4722cf7f0de.tar.gz riscv-isa-sim-32cf5bb54a088385f8e27174c2caf4722cf7f0de.tar.bz2 |
For NS16550 UART, poll stdin less often
On my Mac Mini, calling `poll()` on stdin takes around 10 us, and we
are invoking it every 20 us or so. Reduce the frequency of polling
by 16x when not actively receiving data, thereby reducing the fraction
of time spent in `poll()` to a trivial amount.
Diffstat (limited to 'riscv/ns16550.cc')
-rw-r--r-- | riscv/ns16550.cc | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/riscv/ns16550.cc b/riscv/ns16550.cc index 7bc1d20..8d7e4de 100644 --- a/riscv/ns16550.cc +++ b/riscv/ns16550.cc @@ -71,7 +71,7 @@ ns16550_t::ns16550_t(class bus_t *bus, abstract_interrupt_controller_t *intctrl, uint32_t interrupt_id, uint32_t reg_shift, uint32_t reg_io_width) - : bus(bus), intctrl(intctrl), interrupt_id(interrupt_id), reg_shift(reg_shift), reg_io_width(reg_io_width) + : bus(bus), intctrl(intctrl), interrupt_id(interrupt_id), reg_shift(reg_shift), reg_io_width(reg_io_width), backoff_counter(0) { ier = 0; iir = UART_IIR_NO_INT; @@ -300,11 +300,19 @@ void ns16550_t::tick(void) return; } + if (backoff_counter > 0 && backoff_counter < MAX_BACKOFF) { + backoff_counter++; + return; + } + int rc = canonical_terminal_t::read(); if (rc < 0) { + backoff_counter = 1; return; } + backoff_counter = 0; + rx_queue.push((uint8_t)rc); lsr |= UART_LSR_DR; update_interrupt(); |