Skip to content

Commit

Permalink
CP-52709: autotune service
Browse files Browse the repository at this point in the history
bindir
  • Loading branch information
edwintorok committed Dec 11, 2024
1 parent 03b7c63 commit d45fad4
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ocaml/hwtune/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(executable
(public_name xshwtune)
(libraries xapi_timeslice unix xapi-log)
(package xapi)
)
44 changes: 44 additions & 0 deletions ocaml/hwtune/xshwtune.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
(* Tunes parameters for the hardware and kernel that we are currently running on. *)

module D = Debug.Make (struct let name = "xshwtune" end)

let () =
Debug.log_to_stdout () ;
let recommended = Xapi_timeslice.Recommended.measure () in
D.debug "Recommended OCaml timeslice: %.6fs" recommended ;

let itimer_min =
Sys.set_signal Sys.sigvtalrm Sys.Signal_ignore ;
let _ =
Unix.setitimer Unix.ITIMER_VIRTUAL
Unix.{it_value= 1e-6; it_interval= 1e-6}
in
let actual = Unix.getitimer Unix.ITIMER_VIRTUAL in
actual.Unix.it_value
in

D.debug "POSIX itimer granularity: %.6fs" itimer_min ;
let recommended = Float.max itimer_min recommended in

(* just in case something goes very wrong, ensure it is not too small or big *)
let recommended = recommended |> Float.max 0.001 |> Float.min 0.050 in
D.debug "Adjusted timeslice: %.6fs" recommended ;

(* Use consistent rounding in debug messages and conf file,
by converting to string in a single place.
*)
let recommended = Printf.sprintf "%.3f" recommended in

D.info "OCaml timeslice: %s" recommended ;

let write_conf path =
Out_channel.with_open_text path @@ fun ch ->
Printf.fprintf ch "timeslice=%s" recommended
in

Array.iteri
(fun i arg ->
if i > 0 then
write_conf arg
)
Sys.argv
1 change: 1 addition & 0 deletions scripts/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ install:
$(IDATA) xapi-domains.service $(DESTDIR)/usr/lib/systemd/system/xapi-domains.service
$(IDATA) generate-iscsi-iqn.service $(DESTDIR)/usr/lib/systemd/system/generate-iscsi-iqn.service
$(IDATA) xapi.service $(DESTDIR)/usr/lib/systemd/system/xapi.service
$(IDATA) xshwtune.service $(DESTDIR)/usr/lib/systemd/system/xshwtune.service
$(IDATA) attach-static-vdis.service $(DESTDIR)/usr/lib/systemd/system/attach-static-vdis.service
$(IDATA) save-boot-info.service $(DESTDIR)/usr/lib/systemd/system/save-boot-info.service
$(IDATA) mpathalert.service $(DESTDIR)/usr/lib/systemd/system/mpathalert.service
Expand Down
15 changes: 15 additions & 0 deletions scripts/xshwtune.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[Unit]
Description=Tune system for current hardware and kernel
Before=xapi.service xenopsd-xc.service
ConditionPathExists=/etc/xenserver/features.d/ocamltimeslice
ConditionPathExists=!@ETCDIR@/xenopsd.conf.d/xshwtune.conf

[Service]
Type=oneshot
RemainAfterExit=yes
ExecCondition=/bin/bash -c '[ "$($</etc/xenserver/features.d/ocamltimeslice)" = "1" ]'
ExecStartPre=/usr/bin/mkdir -p /etc/xapi.conf.d /etc/xenopsd.conf.d
ExecStart=/usr/bin/xshwtune @ETCDIR@/xapi.conf.d/xshwtune.conf @ETCDIR@/xenopsd.conf.d/xshwtune.conf

[Install]
WantedBy=multi-user.target

0 comments on commit d45fad4

Please sign in to comment.