Synchronously read board output instead of thread for determinism in benchmark.
This commit is contained in:
@@ -20,16 +20,12 @@ public final class Main {
|
||||
final String firmware = "C:\\Users\\fnuecke\\Documents\\Repositories\\Circuity-1.15\\buildroot\\fw_jump.bin";
|
||||
final String kernel = "C:\\Users\\fnuecke\\Documents\\Repositories\\Circuity-1.15\\buildroot\\Image";
|
||||
|
||||
final UARTReader reader = new UARTReader(board);
|
||||
final Thread thread = new Thread(reader);
|
||||
thread.start();
|
||||
|
||||
System.out.println("Waiting for profiler...");
|
||||
Thread.sleep(5 * 1000);
|
||||
System.out.println("Starting!");
|
||||
|
||||
final long cyclesPerRun = 300_000_000;
|
||||
final int cyclesPerStep = 10_000;
|
||||
final int cyclesPerStep = 1_000;
|
||||
final int hz = 50_000_000;
|
||||
|
||||
final int samples = 10;
|
||||
@@ -38,28 +34,36 @@ public final class Main {
|
||||
int accRunDuration = 0;
|
||||
|
||||
final R5CPU cpu = board.getCpu();
|
||||
final StringBuilder sb = new StringBuilder(16 * 1024);
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
board.reset();
|
||||
loadProgramFile(memory, 0, kernel);
|
||||
loadProgramFile(rom, 0, firmware);
|
||||
cpu.reset();
|
||||
sb.setLength(0);
|
||||
|
||||
final long runStart = System.currentTimeMillis();
|
||||
|
||||
final long limit = cpu.getTime() + cyclesPerRun;
|
||||
int remaining = 0;
|
||||
while (cpu.getTime() < cyclesPerRun) {
|
||||
while (cpu.getTime() < limit) {
|
||||
final long stepStart = System.currentTimeMillis();
|
||||
|
||||
remaining += hz;
|
||||
while (remaining > 0) {
|
||||
board.step(cyclesPerStep);
|
||||
remaining -= cyclesPerStep;
|
||||
|
||||
int value;
|
||||
while ((value = board.readValue()) != -1) {
|
||||
sb.append((char) value);
|
||||
}
|
||||
}
|
||||
|
||||
final long stepDuration = System.currentTimeMillis() - stepStart;
|
||||
final long sleep = 1000 - stepDuration;
|
||||
if (sleep > 0) {
|
||||
// Thread.sleep(sleep);
|
||||
// Thread.sleep(sleep);
|
||||
} else {
|
||||
System.out.println("Running behind by " + (-sleep) + "ms...");
|
||||
}
|
||||
@@ -70,16 +74,14 @@ public final class Main {
|
||||
minRunDuration = Integer.min(minRunDuration, runDuration);
|
||||
maxRunDuration = Integer.max(maxRunDuration, runDuration);
|
||||
|
||||
System.out.print(sb.toString());
|
||||
|
||||
System.out.printf("\n\ntime: %.2fs\n", runDuration / 1000.0);
|
||||
}
|
||||
|
||||
reader.stop();
|
||||
|
||||
final int avgDuration = accRunDuration / samples;
|
||||
System.out.printf("\n\ntimes: min=%.2fs, max=%.2fs, avg=%.2fs\n",
|
||||
minRunDuration / 1000.0, maxRunDuration / 1000.0, avgDuration / 1000.0);
|
||||
|
||||
thread.join();
|
||||
}
|
||||
|
||||
private static void loadProgramFile(final PhysicalMemory memory, int address, final String path) throws Exception {
|
||||
@@ -90,39 +92,4 @@ public final class Main {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final class UARTReader implements Runnable {
|
||||
private final R5Board board;
|
||||
private boolean keepRunning = true;
|
||||
|
||||
private UARTReader(final R5Board board) {
|
||||
this.board = board;
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
keepRunning = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
while (keepRunning) {
|
||||
final int i = board.readValue();
|
||||
if (i >= 0) {
|
||||
final char ch = (char) i;
|
||||
sb.append(ch);
|
||||
if (ch == '\r' || ch == '\n') {
|
||||
final String line = sb.toString();
|
||||
System.out.print(line);
|
||||
sb.setLength(0);
|
||||
}
|
||||
}
|
||||
Thread.yield();
|
||||
}
|
||||
} catch (final Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user