Add os/round-robin: Round Robin scheduler in C++ and C with Gantt chart, quantum sweep and captured output
This commit is contained in:
Executable
+21
@@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Runs the earlier tick-loop program and rr.cpp on random workloads where every process
|
||||
arrives at time 0 (the only case the old program can express) and compares waiting times."""
|
||||
import random, subprocess, sys
|
||||
|
||||
random.seed(2015)
|
||||
TRIALS, mismatches = 500, 0
|
||||
for _ in range(TRIALS):
|
||||
n = random.randint(1, 7)
|
||||
bursts = [random.randint(1, 15) for _ in range(n)]
|
||||
q = random.randint(1, 9)
|
||||
old_in = f"{n}\n" + "\n".join(map(str, bursts)) + f"\n{q}\n"
|
||||
new_in = f"{n}\n" + "\n".join(f"0 {b}" for b in bursts) + f"\n{q}\n"
|
||||
old = subprocess.run(["build/old"], input=old_in, capture_output=True, text=True).stdout
|
||||
new = subprocess.run(["build/rr"], input=new_in, capture_output=True, text=True).stdout
|
||||
old_wt = [int(l.split()[2]) for l in old.split("PNo")[1].splitlines()[1:1 + n]]
|
||||
new_wt = [int(l.split("\t")[5]) for l in new.splitlines()[3:3 + n]]
|
||||
if old_wt != new_wt:
|
||||
mismatches += 1
|
||||
print(f"random workloads (all arrivals at 0, seed 2015): {TRIALS}")
|
||||
print(f"waiting-time mismatches, legacy vs rr.cpp : {mismatches}")
|
||||
Executable
+39
@@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env bash
|
||||
# Rebuilds the C++ and C programs and regenerates every file in output/.
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
mkdir -p output build
|
||||
CXX=${CXX:-g++}; CC=${CC:-gcc}
|
||||
$CXX -std=c++17 -Wall -Wextra -O2 -o build/rr rr.cpp
|
||||
$CC -std=c11 -Wall -Wextra -O2 -o build/rrc rr.c
|
||||
$CXX -std=c++17 -o build/old legacy/old_rr_tick_loop.cpp
|
||||
|
||||
build/rr < input/legacy-5proc-q10.txt > output/01-rr-legacy-5proc-q10.txt
|
||||
build/rr < input/classic-q4.txt > output/02-rr-classic-q4.txt
|
||||
build/rr < input/staggered-q2.txt > output/03-rr-staggered-q2.txt
|
||||
build/rr < input/idle-gap-q3.txt > output/04-rr-idle-gap-q3.txt
|
||||
build/rr < input/quantum-1.txt > output/05-rr-quantum-1.txt
|
||||
build/rr < input/large-quantum.txt > output/06-rr-large-quantum.txt
|
||||
build/old < input/legacy-bursts-only.txt > output/07-legacy-full-session.txt
|
||||
|
||||
# Quantum sweep on the 5-process workload: average waiting time and number of Gantt boxes
|
||||
{
|
||||
echo "Q avg-WT avg-TAT gantt-boxes"
|
||||
for q in 1 2 3 5 7 10 12 15 20 29 40; do
|
||||
sed "\$s/.*/$q/" input/legacy-5proc-q10.txt | build/rr | awk -v q="$q" '
|
||||
/Average waiting/ {w=$NF}
|
||||
/Average turnaround/ {t=$NF}
|
||||
/^\| / {b=gsub(/\| /,"| ")}
|
||||
END {printf "%-3s %-8s %-9s %s\n", q, w, t, b}'
|
||||
done
|
||||
} > output/08-quantum-sweep.txt
|
||||
|
||||
# The C and C++ versions must agree byte for byte on every input
|
||||
{
|
||||
for f in input/*.txt; do
|
||||
[ "$f" = input/legacy-bursts-only.txt ] && continue
|
||||
if cmp -s <(build/rr < "$f") <(build/rrc < "$f"); then echo "identical $f"; else echo "DIFFERENT $f"; fi
|
||||
done
|
||||
} > output/09-c-vs-cpp.txt
|
||||
python3 scripts/compare_legacy.py > output/10-legacy-vs-new.txt
|
||||
echo "done: $(ls output | wc -l) files in output/"
|
||||
Reference in New Issue
Block a user