diff options
author | Andreas Sandberg <andreas.sandberg@arm.com> | 2016-04-27 15:33:58 +0100 |
---|---|---|
committer | Andreas Sandberg <andreas.sandberg@arm.com> | 2016-04-27 15:33:58 +0100 |
commit | 6d74892b38d48e48c4aa69ff9205ef32b222c974 (patch) | |
tree | df6c3ca7519616542ea29b7c8213b6fb0b86a07b /src | |
parent | 67e93a5846dd05eff8a31990e3b18f4d9caf3496 (diff) | |
download | gem5-6d74892b38d48e48c4aa69ff9205ef32b222c974.tar.xz |
dev: Fix incorrect terminal backlog handling
The Terminal device currently uses the peek functionality in gem5's
circular buffer implementation to send existing buffered content on
the terminal when a new client attaches. This functionallity is
however not implemented correctly and re-sends the same block multiple
time.
Add the required functionality to peek with an offset into the
circular buffer and change the Terminal::accept() implementation to
send the buffered contents.
Signed-off-by: Andreas Sandberg <andreas.sandberg@arm.com>
Reviewed-by: Radhika Jagtap <radhika.jagtap@arm.com>
Reviewed-by: Nikos Nikoleris <nikos.nikoleris@arm.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/base/circlebuf.hh | 26 | ||||
-rw-r--r-- | src/dev/terminal.cc | 2 |
2 files changed, 20 insertions, 8 deletions
diff --git a/src/base/circlebuf.hh b/src/base/circlebuf.hh index eca293669..2ab14e269 100644 --- a/src/base/circlebuf.hh +++ b/src/base/circlebuf.hh @@ -103,24 +103,36 @@ class CircleBuf */ template <class OutputIterator> void peek(OutputIterator out, size_t len) const { - panic_if(len > size(), + peek(out, 0, len); + } + + /** + * Copy buffer contents without advancing the read pointer + * + * @param out Output iterator/pointer + * @param offset Offset into the ring buffer + * @param len Number of elements to copy + */ + template <class OutputIterator> + void peek(OutputIterator out, off_t offset, size_t len) const { + panic_if(offset + len > size(), "Trying to read past end of circular buffer.\n"); - if (_start + len <= buf.size()) { - std::copy(buf.begin() + _start, - buf.begin() + _start + len, + const off_t real_start((offset + _start) % buf.size()); + if (real_start + len <= buf.size()) { + std::copy(buf.begin() + real_start, + buf.begin() + real_start + len, out); } else { - const size_t head_size(buf.size() - _start); + const size_t head_size(buf.size() - real_start); const size_t tail_size(len - head_size); - std::copy(buf.begin() + _start, buf.end(), + std::copy(buf.begin() + real_start, buf.end(), out); std::copy(buf.begin(), buf.begin() + tail_size, out + head_size); } } - /** * Copy buffer contents and advance the read pointer * diff --git a/src/dev/terminal.cc b/src/dev/terminal.cc index 53e593f85..9f0ea5ea3 100644 --- a/src/dev/terminal.cc +++ b/src/dev/terminal.cc @@ -204,7 +204,7 @@ Terminal::accept() char buf[1024]; for (size_t i = 0; i < txbuf.size(); i += sizeof(buf)) { const size_t chunk_len(std::min(txbuf.size() - i, sizeof(buf))); - txbuf.peek(buf, chunk_len); + txbuf.peek(buf, i, chunk_len); write((const uint8_t *)buf, chunk_len); } } |