From 31b8aa3c83f2bb1cd448c40677a1eb8266dad2ce Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 15 May 2023 11:58:53 +0200 Subject: Add CPU boosting for higher 4th priority levels --- bbot/agent/agent.cli | 6 +++++- bbot/agent/agent.cxx | 16 +++++++++++++--- bbot/agent/machine.cxx | 13 ++++++++----- bbot/agent/machine.hxx | 3 ++- 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/bbot/agent/agent.cli b/bbot/agent/agent.cli index 1046685..0a9147c 100644 --- a/bbot/agent/agent.cli +++ b/bbot/agent/agent.cli @@ -60,7 +60,11 @@ namespace bbot number (\cb{--cpu}) is boosted to the full number of available hardware threads (or, to view it another way, the fourth priority level has 20 possible values, not 10, with the first 0-9 being without the boost while - the last 10-19 being with the boost). + the last 10-19 being with the boost). Note that this boosting semantics + may not be accurate if the agent is executed with CPU affinity. Also note + that there is no corresponding RAM boosting and it's possible that in some + configurations the amount of RAM will be insufficient for the boosted CPU + count. Note that the priority levels are hierarchical in a sense that within a given higher level URLs can be further prioritized using the lower diff --git a/bbot/agent/agent.cxx b/bbot/agent/agent.cxx index 67cf57f..9aba216 100644 --- a/bbot/agent/agent.cxx +++ b/bbot/agent/agent.cxx @@ -23,6 +23,7 @@ #include #include #include +#include // thread::hardware_concurrency() #include #include // setw() #include @@ -1250,7 +1251,8 @@ perform_task (toolchain_lock tl, // Note: assumes ownership. machine_lock& ml, const dir_path& md, const bootstrapped_machine_manifest& mm, - const task_manifest& tm) + const task_manifest& tm, + optional boost_cpus) try { tracer trace ("perform_task", md.string ().c_str ()); @@ -1399,7 +1401,8 @@ try mm.machine.mac, ops.bridge (), tftpd.port (), - tm.interactive.has_value ())); + tm.interactive.has_value (), + boost_cpus)); auto mg ( make_exception_guard ( @@ -2525,8 +2528,15 @@ try } } + // Check if we need to boost the number of CPUs to the full hardware + // concurrency. + // + optional bcpus; + if (prio >= 10000) + bcpus = std::thread::hardware_concurrency (); + pm->lock.perform_task (tl, prio); - r = perform_task (move (tl), pm->lock, pm->path, pm->manifest, t); + r = perform_task (move (tl), pm->lock, pm->path, pm->manifest, t, bcpus); } catch (const interrupt&) { diff --git a/bbot/agent/machine.cxx b/bbot/agent/machine.cxx index 8308989..16f0525 100644 --- a/bbot/agent/machine.cxx +++ b/bbot/agent/machine.cxx @@ -172,7 +172,8 @@ namespace bbot const optional& mac, const string& br_iface, uint16_t tftp_port, - bool pub_vnc); + bool pub_vnc, + optional boost_cpus = nullopt); virtual bool shutdown (size_t& seconds) override; @@ -216,7 +217,8 @@ namespace bbot const optional& omac, const string& br, uint16_t port, - bool pub_vnc) + bool pub_vnc, + optional bcpus) : machine (mm.mac ? *mm.mac : // Fixed mac from machine manifest. omac ? *omac : // Generated mac from previous bootstrap. generate_mac ()), @@ -249,7 +251,7 @@ namespace bbot // Note that for best results you may want to adjust (e.g., by over- // committing) the number of CPUs to be power of 2. // - size_t cpus (ops.cpu ()), cores (cpus); + size_t cpus (bcpus ? *bcpus : ops.cpu ()), cores (cpus); size_t sockets (cores >= 16 && cores % 4 == 0 ? 2 : cores >= 64 && cores % 8 == 0 ? 4 : 1); @@ -672,13 +674,14 @@ namespace bbot const optional& mac, const string& br_iface, uint16_t tftp_port, - bool pub_vnc) + bool pub_vnc, + optional bcpus) { switch (mm.type) { case machine_type::kvm: return make_unique ( - md, mm, mac, br_iface, tftp_port, pub_vnc); + md, mm, mac, br_iface, tftp_port, pub_vnc, bcpus); case machine_type::nspawn: assert (false); //@@ TODO diff --git a/bbot/agent/machine.hxx b/bbot/agent/machine.hxx index adace1f..0bb74b9 100644 --- a/bbot/agent/machine.hxx +++ b/bbot/agent/machine.hxx @@ -84,7 +84,8 @@ namespace bbot const optional& mac, const string& br_iface, uint16_t tftp_port, - bool pub_vnc); + bool pub_vnc, + optional boost_cpus = nullopt); // Return the machine's public or private VNC session endpoint in the // ':' form. -- cgit v1.1