From da2164847258855bb8863f5aa97945da8603642d Mon Sep 17 00:00:00 2001 From: Andrew Waterman Date: Thu, 20 Oct 2022 12:46:40 -0700 Subject: [PATCH] Set 16..4096-byte bound on cache-block size 16 B suffices to subsume all aligned accesses (including the Q extension). Spike does not actually rely on this property, but in some real systems, it is impractical to guarantee atomicity across cache lines. 4096 B suffices to prevent cache lines from spanning pages (which would require multiple TLB accesses). This one is a bug fix, since we were not performing multiple TLB accesses in this case. --- spike_main/spike.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/spike_main/spike.cc b/spike_main/spike.cc index 933f626d..20afac92 100644 --- a/spike_main/spike.cc +++ b/spike_main/spike.cc @@ -411,8 +411,11 @@ int main(int argc, char** argv) }); parser.option(0, "blocksz", 1, [&](const char* s){ blocksz = strtoull(s, 0, 0); - if (((blocksz & (blocksz - 1))) != 0) { - fprintf(stderr, "--blocksz should be power of 2\n"); + const unsigned min_blocksz = 16; + const unsigned max_blocksz = PGSIZE; + if (blocksz < min_blocksz || blocksz > max_blocksz || ((blocksz & (blocksz - 1))) != 0) { + fprintf(stderr, "--blocksz must be a power of 2 between %u and %u\n", + min_blocksz, max_blocksz); exit(-1); } });