Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ OBJCOPY = aarch64-none-elf-objcopy
KERNEL_ELF = kernel.elf
KERNEL_BIN = kernel.bin
TEST_ELF = kernel_test.elf
BENCH_ELF = kernel_bench.elf

# Common source files (shared between server and tests)
COMMON_SRCS = src/drivers/uart.s \
src/drivers/virtio.s \
src/drivers/timer.s \
src/net/ethernet.s \
src/net/arp.s \
src/net/ipv4.s \
Expand Down Expand Up @@ -61,11 +63,24 @@ TEST_SRCS = src/test/test_main.s \
src/app.s
TEST_OBJS = $(TEST_SRCS:.s=.o)

# Benchmark sources
BENCH_SRCS = src/bench/bench_main.s \
src/bench/bench_harness.s \
src/bench/bench_slab.s \
src/bench/bench_db.s \
src/bench/bench_string.s \
src/bench/bench_json.s \
src/bench/bench_request.s \
$(COMMON_SRCS) \
$(MEM_DB_SRCS) \
$(SLOWAPI_SRCS)
BENCH_OBJS = $(BENCH_SRCS:.s=.o)

# Flags
ASFLAGS = -g
LDFLAGS = -T linker.ld -nostdlib

.PHONY: all clean run test
.PHONY: all clean run test bench

all: $(KERNEL_ELF)

Expand All @@ -75,14 +90,17 @@ $(KERNEL_ELF): $(SERVER_OBJS) linker.ld
$(TEST_ELF): $(TEST_OBJS) linker.ld
$(LD) $(LDFLAGS) -o $@ $(TEST_OBJS)

$(BENCH_ELF): $(BENCH_OBJS) linker.ld
$(LD) $(LDFLAGS) -o $@ $(BENCH_OBJS)

$(KERNEL_BIN): $(KERNEL_ELF)
$(OBJCOPY) -O binary $< $@

%.o: %.s
$(AS) $(ASFLAGS) -o $@ $<

clean:
rm -f $(SERVER_OBJS) $(TEST_OBJS) $(KERNEL_ELF) $(KERNEL_BIN) $(TEST_ELF)
rm -f $(SERVER_OBJS) $(TEST_OBJS) $(BENCH_OBJS) $(KERNEL_ELF) $(KERNEL_BIN) $(TEST_ELF) $(BENCH_ELF)

run: $(KERNEL_ELF)
qemu-system-aarch64 \
Expand All @@ -103,3 +121,13 @@ test: $(TEST_ELF)
-kernel $(TEST_ELF) \
-device virtio-net-device,netdev=net0 \
-netdev user,id=net0

bench: $(BENCH_ELF)
qemu-system-aarch64 \
-machine virt \
-cpu cortex-a72 \
-nographic \
-global virtio-mmio.force-legacy=true \
-kernel $(BENCH_ELF) \
-device virtio-net-device,netdev=net0 \
-netdev user,id=net0
187 changes: 187 additions & 0 deletions src/bench/bench_db.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
// Database Benchmarks

.section .text
.global run_db_benchmarks

run_db_benchmarks:
stp x29, x30, [sp, #-16]!
mov x29, sp

ldr x0, =section_name
bl bench_section

ldr x0, =ctx_db_create
bl bench_run
ldr x0, =ctx_db_get
bl bench_run
ldr x0, =ctx_db_delete
bl bench_run
ldr x0, =ctx_db_list
bl bench_run

ldp x29, x30, [sp], #16
ret

//=============================================================================
// Benchmark functions
//=============================================================================

// Create + delete a record (self-contained per iteration)
bench_fn_db_create:
stp x29, x30, [sp, #-16]!
mov x29, sp

ldr x0, =test_record
mov x1, #8
bl db_create
// Delete to keep db clean for next iteration
bl db_delete

ldp x29, x30, [sp], #16
ret

// Get a record by ID (record created in setup)
bench_fn_db_get:
stp x29, x30, [sp, #-16]!
mov x29, sp

ldr x0, =db_saved_id
ldr w0, [x0]
bl db_get

ldp x29, x30, [sp], #16
ret

// Create + delete (measures delete cost, self-contained)
bench_fn_db_delete:
stp x29, x30, [sp, #-16]!
mov x29, sp

ldr x0, =test_record
mov x1, #8
bl db_create
bl db_delete

ldp x29, x30, [sp], #16
ret

// Count records
bench_fn_db_list:
stp x29, x30, [sp, #-16]!
mov x29, sp

bl db_count

ldp x29, x30, [sp], #16
ret

// Setup: reinit mem + db
bench_db_setup_reinit:
stp x29, x30, [sp, #-16]!
mov x29, sp

bl mem_init
bl db_init

ldp x29, x30, [sp], #16
ret

// Setup: reinit + create one record (for get benchmark)
bench_db_setup_create:
stp x29, x30, [sp, #-16]!
mov x29, sp

bl mem_init
bl db_init
ldr x0, =test_record
mov x1, #8
bl db_create
ldr x1, =db_saved_id
str w0, [x1]

ldp x29, x30, [sp], #16
ret

// Setup: reinit + populate 10 records (for list benchmark)
bench_db_setup_populate:
stp x29, x30, [sp, #-16]!
mov x29, sp
stp x19, xzr, [sp, #-16]!

bl mem_init
bl db_init

mov w19, #10
.populate_loop:
cbz w19, .populate_done
ldr x0, =test_record
mov x1, #8
bl db_create
sub w19, w19, #1
b .populate_loop
.populate_done:

ldp x19, xzr, [sp], #16
ldp x29, x30, [sp], #16
ret

//=============================================================================
// Benchmark contexts
//=============================================================================

.section .data
.balign 8
ctx_db_create:
.quad name_db_create
.quad bench_fn_db_create
.quad bench_db_setup_reinit
.quad 0
.word 500
.skip 28

.balign 8
ctx_db_get:
.quad name_db_get
.quad bench_fn_db_get
.quad bench_db_setup_create
.quad 0
.word 1000
.skip 28

.balign 8
ctx_db_delete:
.quad name_db_delete
.quad bench_fn_db_delete
.quad bench_db_setup_reinit
.quad 0
.word 500
.skip 28

.balign 8
ctx_db_list:
.quad name_db_list
.quad bench_fn_db_list
.quad bench_db_setup_populate
.quad 0
.word 100
.skip 28

.section .rodata
section_name:
.asciz "database"
name_db_create:
.asciz "db_create"
name_db_get:
.asciz "db_get"
name_db_delete:
.asciz "db_delete"
name_db_list:
.asciz "db_list"

test_record:
.ascii "testdata"

.section .bss
.balign 4
db_saved_id:
.skip 4
Loading