Skip to content

Replace global value of Stats by a DLS.key#404

Merged
clecat merged 3 commits intomirage:mainfrom
lyrm:stats_dls
Sep 30, 2025
Merged

Replace global value of Stats by a DLS.key#404
clecat merged 3 commits intomirage:mainfrom
lyrm:stats_dls

Conversation

@lyrm
Copy link
Contributor

@lyrm lyrm commented Sep 29, 2025

This patch allows multiple domains to compute their own stats and merge them with the new function merge.

Examples:

let work barrier id =
  Atomic.decr barrier;
  while Atomic.get barrier <> 0 do
    Domain.cpu_relax ()
  done;
  add_read (10 * id);
  add_write (10 * id);
  get ()

let () =
  let ndomain = 5 in
  let barrier = Atomic.make ndomain in
  let domains =
    Array.init ndomain (fun id -> Domain.spawn (fun () -> work barrier id))
  in
  let stats = Array.map (fun d -> Domain.join d) domains in
  Array.iteri
    (fun id s ->
      Printf.printf "Domain %d: read %d write %d\n" id s.bytes_read
        s.bytes_written)
    stats;
  let total = Array.fold_left merge (fresh_stats ()) stats in
  Printf.printf "Total: read %d write %d\n" total.bytes_read total.bytes_written

returns

Domain 0: read 0 write 0
Domain 1: read 10 write 10
Domain 2: read 20 write 20
Domain 3: read 30 write 30
Domain 4: read 40 write 40
Total: read 100 write 100

@lyrm lyrm marked this pull request as ready for review September 30, 2025 08:01
Copy link
Contributor

@clecat clecat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks a lot for your work.
DLS seems to be a good option to resolve the multicore issues of Index stats.

@clecat clecat merged commit 6e84bed into mirage:main Sep 30, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants