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
15 changes: 11 additions & 4 deletions bench/pages/main.odin
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ rss_kb :: proc() -> int {
// Every page the bench opens carries one of these as user_data, so every completion
// is counted — the cold and warm rounds too, not only the churn. A round with
// `total` 0 never refills; the churn round reopens until `total` pages have run.
// The global surface every bench page opens on. `.Node` unless BENCH_SURFACE=web,
// which measures the same pages without the Node names (and without stdio and the
// node-streams stack compiling at start-up). The page sources name no Node global,
// so they run unchanged on both.
bench_surface: lava.Global_Surface

Round :: struct {
opened, finished, failed, total: int,
limits: lava.Page_Limits,
Expand All @@ -101,7 +107,7 @@ discard :: proc(runner: ^lava.Page_Runner, user_data: rawptr, result: lava.Resul
}
if r.opened < r.total {
r.opened += 1
lava.page_runner_open(runner, r.source, "<bench>", r.limits, r)
lava.page_runner_open(runner, r.source, "<bench>", r.limits, r, bench_surface)
}
lava.result_destroy(&result)
}
Expand All @@ -112,11 +118,12 @@ discard :: proc(runner: ^lava.Page_Runner, user_data: rawptr, result: lava.Resul
// whether these were really pages is only known from `r.failed` after the round runs.
open_n :: proc(runner: ^lava.Page_Runner, r: ^Round, n: int, source: string) -> f64 {
start := time.tick_now()
for _ in 0 ..< n do lava.page_runner_open(runner, source, "<bench>", r.limits, r)
for _ in 0 ..< n do lava.page_runner_open(runner, source, "<bench>", r.limits, r, bench_surface)
return time.duration_milliseconds(time.tick_since(start)) / f64(n)
}

main :: proc() {
if v, ok := os.lookup_env("BENCH_SURFACE", context.temp_allocator); ok && v == "web" do bench_surface = .Web
if len(os.args) < 2 {
fmt.eprintln("usage: bench-pages <N> [total] [budget] [heap_every] [trivial|heavy] | dispatch <threads> <slots> [total]")
os.exit(2)
Expand Down Expand Up @@ -172,7 +179,7 @@ main :: proc() {
start := time.tick_now()
for _ in 0 ..< min(n, total) {
churn.opened += 1
lava.page_runner_open(&runner, shape, "<bench>", limits, &churn)
lava.page_runner_open(&runner, shape, "<bench>", limits, &churn, bench_surface)
}
lava.page_runner_run(&runner)
secs := time.duration_seconds(time.tick_since(start))
Expand Down Expand Up @@ -234,7 +241,7 @@ dispatch_main :: proc() {
start := time.tick_now()
refused := 0
for _ in 0 ..< total {
if !lava.page_dispatcher_submit(&d, TRIVIAL, "<bench>", BENCH_LIMITS, &tally) do refused += 1
if !lava.page_dispatcher_submit(&d, TRIVIAL, "<bench>", BENCH_LIMITS, &tally, bench_surface) do refused += 1
}
for sync.atomic_load(&tally.done) < total - refused do time.sleep(time.Millisecond)
secs := time.duration_seconds(time.tick_since(start))
Expand Down
6 changes: 5 additions & 1 deletion pkg/runtime/page_dispatcher.odin
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ Dispatch_Job :: struct {
source_name: string,
limits: Page_Limits,
user_data: rawptr,
surface: Global_Surface,
}

@(private = "file")
Expand Down Expand Up @@ -217,6 +218,7 @@ page_dispatcher_init :: proc(
// Params:
// source, source_name Copied through the dispatcher's allocator; the caller's
// strings may go away as soon as this returns.
// surface As page_runner_open's; `.Node` by default.
// limits As page_runner_open's: a page without a CPU budget is still
// accepted, and reported .Invalid_Input through on_done — one
// path for every per-page failure.
Expand All @@ -230,6 +232,7 @@ page_dispatcher_submit :: proc(
source, source_name: string,
limits: Page_Limits,
user_data: rawptr = nil,
surface: Global_Surface = .Node,
) -> bool {
// A zero dispatcher has no allocator to copy through; it is Closed anyway.
if d.allocator.procedure == nil do return false
Expand All @@ -247,6 +250,7 @@ page_dispatcher_submit :: proc(
source_name = name,
limits = limits,
user_data = user_data,
surface = surface,
}
if serr != nil || nerr != nil {
job_free(d, job)
Expand Down Expand Up @@ -486,7 +490,7 @@ worker_loop :: proc(w: ^Dispatch_Worker) {
for page_runner_live(&w.runner) < d.pages_per_thread {
job := worker_pop(w)
if job == nil do break
page_runner_open(&w.runner, job.source, job.source_name, job.limits, job)
page_runner_open(&w.runner, job.source, job.source_name, job.limits, job, job.surface)
}
// Done once nothing is live. That also means the inbox is empty — the open loop
// above stops only at a full runner or an empty inbox — and it stays empty:
Expand Down
8 changes: 7 additions & 1 deletion pkg/runtime/page_runner.odin
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,18 @@ page_runner_destroy :: proc(runner: ^Page_Runner) {
// "a page that spins is killed alone" hold for every caller. Negative and
// NaN read as "no budget" to vm_set_cpu_budget, and are refused alike.
// Pinned by runner_refuses_a_page_without_a_cpu_budget.
// surface The global names the page can reach (Global_Surface, runtime.odin).
// `.Node` by default; `.Web` hides process, require, Buffer and the rest
// (#5). Each page gets a fresh global in its pooled VM, so pages of both
// surfaces can take turns in one VM. Pinned by
// runner_web_page_sees_no_node_names_in_a_reused_vm.
page_runner_open :: proc(
runner: ^Page_Runner,
source: string,
source_name: string,
limits: Page_Limits,
user_data: rawptr = nil,
surface: Global_Surface = .Node,
) {
context.allocator = runner.allocator
defer free_all(context.temp_allocator)
Expand All @@ -226,7 +232,7 @@ page_runner_open :: proc(
append(&runner.pages, rp)
index := len(runner.pages) - 1

if !page_open(&rp.page, source, source_name, rp.loop, false, nil, limits, &runner.pool, runner_page = true) {
if !page_open(&rp.page, source, source_name, rp.loop, false, nil, limits, &runner.pool, runner_page = true, surface = surface) {
runner_finish(runner, index, deliver = false)
return
}
Expand Down
Loading