Skip to content

Commit

Permalink
WIP: Add test secript for scale data
Browse files Browse the repository at this point in the history
  • Loading branch information
Mes0903 committed Jan 17, 2025
1 parent ee5506e commit e814185
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ OBJS := \
aclint.o \
$(OBJS_EXTRA)

LDFLAGS := -pg

deps := $(OBJS:%.o=.%.o.d)

$(BIN): $(OBJS)
Expand Down
30 changes: 30 additions & 0 deletions auto_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash

# Create a directory to store logs (optional)
mkdir -p logs

for N in $(seq 1 32); do
echo "============================================="
echo "Starting experiment with SMP=$N"
echo "============================================="

# 1) Clean
make clean

# 2) Build and run checks with SMP=N, capturing emulator output
# The 'tee' command copies output to the terminal AND a log file
echo "Building and running 'make check SMP=$N'..."
make check SMP=$N 2>&1 | tee "logs/emulator_SMP_${N}.log"

# 3) After the emulator run, record gprof output
# We assume 'gprof ./semu' uses data from 'gmon.out'
echo "Running gprof for SMP=$N..."
gprof ./semu > "logs/gprof_SMP_${N}.log" 2>&1

echo "Done with SMP=$N. Logs saved:"
echo " - logs/emulator_SMP_${N}.log"
echo " - logs/gprof_SMP_${N}.log"
echo
done

echo "All experiments complete!"
33 changes: 31 additions & 2 deletions utils.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#include "utils.h"
Expand All @@ -22,6 +24,11 @@
bool boot_complete = false;
static double scale_factor;

/* for testing */
uint64_t count = 0;
struct timespec boot_begin, boot_end;
double TEST_ns_per_call, TEST_predict_sec;

/* Calculate "x * n / d" without unnecessary overflow or loss of precision.
*
* Reference:
Expand Down Expand Up @@ -114,14 +121,18 @@ static void measure_bogomips_ns(uint64_t iterations)
(double) (elapsed_ns_2 - elapsed_ns_1) / (double) iterations;

/* 'semu_timer_clocksource' is called ~2e8 times per SMP. Each call's
* overhead ~ ns_per_call. The total overhead is ~ ns_per_call * SMP * 2e8.
* That overhead is about 10% of the entire boot, so effectively:
* overhead ~ ns_per_call. The total overhead is ~ ns_per_call * SMP *
* 2e8. That overhead is about 10% of the entire boot, so effectively:
* predict_sec = ns_per_call * SMP * 2e8 * (100%/10%) / 1e9
* = ns_per_call * SMP * 2.0
* Then scale_factor = (desired_time) / (predict_sec).
*/
const double predict_sec = ns_per_call * SEMU_SMP * 2.0;
scale_factor = SEMU_BOOT_TARGET_TIME / predict_sec;

/* for testing */
TEST_ns_per_call = ns_per_call;
TEST_predict_sec = predict_sec;
}

/* The main function that returns the "emulated time" in ticks.
Expand All @@ -132,6 +143,8 @@ static void measure_bogomips_ns(uint64_t iterations)
*/
static uint64_t semu_timer_clocksource(semu_timer_t *timer)
{
count++;

/* After boot process complete, the timer will switch to real time. Thus,
* there is an offset between the real time and the emulator time.
*
Expand All @@ -157,8 +170,23 @@ static uint64_t semu_timer_clocksource(semu_timer_t *timer)

/* The boot is done => switch to real freq with an offset bridging. */
if (first_switch) {
clock_gettime(CLOCKID, &boot_end);
double boot_time = (boot_end.tv_sec - boot_begin.tv_sec) +
(boot_end.tv_nsec - boot_begin.tv_nsec) / 1e9;

first_switch = false;
offset = (int64_t) (real_ticks - scaled_ticks);
printf(
"\033[1;31m[SEMU LOG]: Boot time: %.5f seconds, called %ld "
"times semu_timer_total_ticks\033[0m\n",
boot_time, count);

printf(
"\033[1;31m[SEMU LOG]: ns_per_call = %.5f, predict_sec = %.5f, "
"scale_factor = %.5f\033[0m\n",
TEST_ns_per_call, TEST_predict_sec, scale_factor);

exit(0);
}
return (uint64_t) ((int64_t) real_ticks - offset);

Expand Down Expand Up @@ -196,6 +224,7 @@ void semu_timer_init(semu_timer_t *timer, uint64_t freq)
*/
measure_bogomips_ns(freq);

clock_gettime(CLOCKID, &boot_begin);
timer->freq = freq;
semu_timer_rebase(timer, 0);
}
Expand Down

0 comments on commit e814185

Please sign in to comment.