From 2949e2c105959639ef2e8b13a13cdc18f2daaa8a Mon Sep 17 00:00:00 2001 From: Bruno Donassolo Date: Fri, 6 Aug 2021 20:36:27 +0200 Subject: [PATCH] Add test for multicore speed/state file --- MANIFEST.in | 2 + src/surf/cpu_cas01.cpp | 6 - teshsuite/s4u/CMakeLists.txt | 4 +- .../host-multicore-speed-file.cpp | 113 ++++++++++++++++++ .../host-multicore-speed-file.tesh | 23 ++++ 5 files changed, 140 insertions(+), 8 deletions(-) create mode 100644 teshsuite/s4u/host-multicore-speed-file/host-multicore-speed-file.cpp create mode 100644 teshsuite/s4u/host-multicore-speed-file/host-multicore-speed-file.tesh diff --git a/MANIFEST.in b/MANIFEST.in index da8b7be17d..fb0bf5c6f5 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -733,6 +733,8 @@ include teshsuite/s4u/concurrent_rw/concurrent_rw.cpp include teshsuite/s4u/concurrent_rw/concurrent_rw.tesh include teshsuite/s4u/evaluate-get-route-time/evaluate-get-route-time.cpp include teshsuite/s4u/evaluate-parse-time/evaluate-parse-time.cpp +include teshsuite/s4u/host-multicore-speed-file/host-multicore-speed-file.cpp +include teshsuite/s4u/host-multicore-speed-file/host-multicore-speed-file.tesh include teshsuite/s4u/host-on-off-actors/host-on-off-actors.cpp include teshsuite/s4u/host-on-off-actors/host-on-off-actors.tesh include teshsuite/s4u/host-on-off-recv/host-on-off-recv.cpp diff --git a/src/surf/cpu_cas01.cpp b/src/surf/cpu_cas01.cpp index 8ac6a3638c..88aab666be 100644 --- a/src/surf/cpu_cas01.cpp +++ b/src/surf/cpu_cas01.cpp @@ -107,17 +107,11 @@ void CpuCas01::on_speed_change() void CpuCas01::apply_event(profile::Event* event, double value) { if (event == speed_.event) { - /* TODO (Hypervisor): do the same thing for constraint_core[i] */ - xbt_assert(get_core_count() == 1, "FIXME: add speed scaling code also for constraint_core[i]"); - speed_.scale = value; on_speed_change(); tmgr_trace_event_unref(&speed_.event); } else if (event == state_event_) { - /* TODO (Hypervisor): do the same thing for constraint_core[i] */ - xbt_assert(get_core_count() == 1, "FIXME: add state change code also for constraint_core[i]"); - if (value > 0) { if (not is_on()) { XBT_VERB("Restart actors on host %s", get_iface()->get_cname()); diff --git a/teshsuite/s4u/CMakeLists.txt b/teshsuite/s4u/CMakeLists.txt index 64c74c7b2a..1a4c45ef52 100644 --- a/teshsuite/s4u/CMakeLists.txt +++ b/teshsuite/s4u/CMakeLists.txt @@ -3,7 +3,7 @@ foreach(x actor actor-autorestart actor-suspend comm-get-sender comm-pt2pt wait-all-for wait-any-for cloud-interrupt-migration cloud-two-execs concurrent_rw - host-on-off host-on-off-actors host-on-off-recv io-set-bw + host-on-off host-on-off-actors host-on-off-recv host-multicore-speed-file io-set-bw basic-link-test basic-parsing-test evaluate-get-route-time evaluate-parse-time is-router storage_client_server listen_async pid trace-integration @@ -34,7 +34,7 @@ foreach(x actor actor-autorestart actor-suspend ADD_TESH_FACTORIES(tesh-s4u-${x} "*" --setenv bindir=${CMAKE_BINARY_DIR}/teshsuite/s4u/${x} --setenv srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite/s4u/${x} --setenv platfdir=${CMAKE_HOME_DIRECTORY}/examples/platforms --cd ${CMAKE_BINARY_DIR}/teshsuite/s4u/${x} ${CMAKE_HOME_DIRECTORY}/teshsuite/s4u/${x}/${x}.tesh) endforeach() -foreach(x basic-link-test basic-parsing-test host-on-off host-on-off-actors host-on-off-recv is-router listen_async +foreach(x basic-link-test basic-parsing-test host-on-off host-on-off-actors host-on-off-recv host-multicore-speed-file is-router listen_async pid storage_client_server trace-integration seal-platform issue71) set(tesh_files ${tesh_files} ${CMAKE_CURRENT_SOURCE_DIR}/${x}/${x}.tesh) ADD_TESH(tesh-s4u-${x} --setenv srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite/s4u/${x} --setenv platfdir=${CMAKE_HOME_DIRECTORY}/examples/platforms --cd ${CMAKE_BINARY_DIR}/teshsuite/s4u/${x} ${CMAKE_HOME_DIRECTORY}/teshsuite/s4u/${x}/${x}.tesh) diff --git a/teshsuite/s4u/host-multicore-speed-file/host-multicore-speed-file.cpp b/teshsuite/s4u/host-multicore-speed-file/host-multicore-speed-file.cpp new file mode 100644 index 0000000000..56d133eaa3 --- /dev/null +++ b/teshsuite/s4u/host-multicore-speed-file/host-multicore-speed-file.cpp @@ -0,0 +1,113 @@ +/* Copyright (c) 2010-2021. The SimGrid Team. + * All rights reserved. */ + +/* This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. */ + +#include "simgrid/kernel/ProfileBuilder.hpp" +#include "simgrid/s4u.hpp" + +namespace sg4 = simgrid::s4u; + +XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example"); + +static void run_activities(int n, double size, double rate = -1.0) +{ + double start = sg4::Engine::get_clock(); + std::vector activities; + + // initialize exec activities + for (int i = 0; i < n; i++) { + sg4::ExecPtr op = sg4::this_actor::exec_init(size); + if (rate != -1.0) + op->set_bound(rate); + op->start(); + activities.emplace_back(op); + } + + // waiting for executions + for (const auto& act : activities) + act->wait(); + XBT_INFO("Finished running 2 activities, elapsed %lf", sg4::Engine::get_clock() - start); +} + +static void worker() +{ + XBT_INFO("Running 1 tasks (1.5e6) in a 2*(1e6) speed host. Should take 2s (1 (limited by core) + 1 (limited by speed " + "file)"); + run_activities(1, 1.5e6); + + XBT_INFO("Running 1 tasks (.8e6) in a 2*(1e6) speed host with limited rate (.4e6). Should take 2s (limited by rate)"); + run_activities(1, .8e6, .4e6); + + XBT_INFO("Running 1 tasks (1.1e6) in a 2*(1e6) speed host with limited rate (.6e6). Should take 2s (.6 limited by " + "rate + .5 limited by speed file)"); + run_activities(1, 1.1e6, .6e6); + + XBT_INFO("Running 2 tasks (1e6) in a 2*(1e6) speed host. Should take 1s"); + run_activities(2, 1e6); + + XBT_INFO("Running 2 tasks (.5e6) in a .5*2*(1e6) speed host. Should take 1s"); + run_activities(2, .5e6); + + XBT_INFO("Running 2 tasks (1.1e6) with limited rate (.6e6). Should take 2s (0.6 limited by rate + 0.5 limited by " + "speed file)"); + run_activities(2, 1.1e6, .6e6); + + XBT_INFO("Running 2 tasks (.8e6) with limited rate (.4e6). Should take 2s (limited by rate)"); + run_activities(2, .8e6, .4e6); + + XBT_INFO("I'm done. See you!"); +} + +static void failed_worker() +{ + XBT_INFO("Running a 2 tasks: a small .5e6 and a big 2e6."); + sg4::ExecPtr ok = sg4::this_actor::exec_init(.5e6); + sg4::ExecPtr fail = sg4::this_actor::exec_init(2e6); + ok->wait(); + XBT_INFO("Finished the small task"); + try { + XBT_INFO("Waiting big task to finish"); + fail->wait(); + } catch (simgrid::ForcefulKillException&) { + XBT_INFO("Unable to finish big task, host went down"); + } +} + +int main(int argc, char* argv[]) +{ + sg4::Engine e(&argc, argv); + + /* speed and state file description */ + const char* erin_state_file = R"( +0 1 +1 0 +50 1 +100 1 +)"; + const char* carol_speed_file = R"( +0 1.0 +1 0.5 +)"; + /* simple platform containing 1 host and 2 disk */ + auto* zone = sg4::create_full_zone("red"); + zone->create_host("erin", 1e6) + ->set_core_count(2) + ->set_state_profile(simgrid::kernel::profile::ProfileBuilder::from_string("erin_state", erin_state_file, 0)) + ->seal(); + zone->create_host("carol", 1e6) + ->set_core_count(2) + ->set_speed_profile(simgrid::kernel::profile::ProfileBuilder::from_string("carol_speed", carol_speed_file, 1)) + ->seal(); + zone->seal(); + + sg4::Actor::create("carol", simgrid::s4u::Host::by_name("carol"), worker); + sg4::Actor::create("erin", simgrid::s4u::Host::by_name("erin"), failed_worker)->set_auto_restart(true); + + e.run(); + + XBT_INFO("Simulation time %g", simgrid::s4u::Engine::get_clock()); + + return 0; +} diff --git a/teshsuite/s4u/host-multicore-speed-file/host-multicore-speed-file.tesh b/teshsuite/s4u/host-multicore-speed-file/host-multicore-speed-file.tesh new file mode 100644 index 0000000000..f6596d3736 --- /dev/null +++ b/teshsuite/s4u/host-multicore-speed-file/host-multicore-speed-file.tesh @@ -0,0 +1,23 @@ + +$ ./host-multicore-speed-file +> [carol:carol:(1) 0.000000] [s4u_test/INFO] Running 1 tasks (1.5e6) in a 2*(1e6) speed host. Should take 2s (1 (limited by core) + 1 (limited by speed file) +> [erin:erin:(2) 0.000000] [s4u_test/INFO] Running a 2 tasks: a small .5e6 and a big 2e6. +> [erin:erin:(3) 0.000000] [s4u_test/INFO] Running a 2 tasks: a small .5e6 and a big 2e6. +> [erin:erin:(3) 0.500000] [s4u_test/INFO] Finished the small task +> [erin:erin:(3) 0.500000] [s4u_test/INFO] Waiting big task to finish +> [erin:erin:(3) 1.000000] [s4u_test/INFO] Unable to finish big task, host went down +> [carol:carol:(1) 2.000000] [s4u_test/INFO] Finished running 2 activities, elapsed 2.000000 +> [carol:carol:(1) 2.000000] [s4u_test/INFO] Running 1 tasks (.8e6) in a 2*(1e6) speed host with limited rate (.4e6). Should take 2s (limited by rate) +> [carol:carol:(1) 4.000000] [s4u_test/INFO] Finished running 2 activities, elapsed 2.000000 +> [carol:carol:(1) 4.000000] [s4u_test/INFO] Running 1 tasks (1.1e6) in a 2*(1e6) speed host with limited rate (.6e6). Should take 2s (.6 limited by rate + .5 limited by speed file) +> [carol:carol:(1) 6.000000] [s4u_test/INFO] Finished running 2 activities, elapsed 2.000000 +> [carol:carol:(1) 6.000000] [s4u_test/INFO] Running 2 tasks (1e6) in a 2*(1e6) speed host. Should take 1s +> [carol:carol:(1) 7.000000] [s4u_test/INFO] Finished running 2 activities, elapsed 1.000000 +> [carol:carol:(1) 7.000000] [s4u_test/INFO] Running 2 tasks (.5e6) in a .5*2*(1e6) speed host. Should take 1s +> [carol:carol:(1) 8.000000] [s4u_test/INFO] Finished running 2 activities, elapsed 1.000000 +> [carol:carol:(1) 8.000000] [s4u_test/INFO] Running 2 tasks (1.1e6) with limited rate (.6e6). Should take 2s (0.6 limited by rate + 0.5 limited by speed file) +> [carol:carol:(1) 10.000000] [s4u_test/INFO] Finished running 2 activities, elapsed 2.000000 +> [carol:carol:(1) 10.000000] [s4u_test/INFO] Running 2 tasks (.8e6) with limited rate (.4e6). Should take 2s (limited by rate) +> [carol:carol:(1) 12.000000] [s4u_test/INFO] Finished running 2 activities, elapsed 2.000000 +> [carol:carol:(1) 12.000000] [s4u_test/INFO] I'm done. See you! +> [12.000000] [s4u_test/INFO] Simulation time 12 -- 2.20.1