1 /* Copyright (c) 2017-2022. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #include <simgrid/s4u.hpp>
8 namespace sg4 = simgrid::s4u;
10 XBT_LOG_NEW_DEFAULT_CATEGORY(io_set_bw, "Messages specific for this simulation");
12 static void io(const sg4::Disk* disk)
14 double cur_time = sg4::Engine::get_clock();
16 XBT_INFO("Read finished. Took: %lf", sg4::Engine::get_clock() - cur_time);
17 cur_time = sg4::Engine::get_clock();
19 XBT_INFO("Write finished. Took: %lf", sg4::Engine::get_clock() - cur_time);
24 auto* disk = sg4::Host::current()->get_disks()[0];
25 XBT_INFO("I/O operations: size 1e6. Should take 1s each");
28 XBT_INFO("Setting read limit to half (.5e6). Read should take 2s, write still 1s");
29 disk->set_read_bandwidth(.5e6);
32 XBT_INFO("Setting write limit to half (.5e6). Write should take 2s, read still 1s");
33 disk->set_read_bandwidth(1e6);
34 disk->set_write_bandwidth(.5e6);
37 XBT_INFO("Setting readwrite limit to half (.5e6). Write and read should take 2s now");
38 disk->set_readwrite_bandwidth(.5e6);
39 disk->set_write_bandwidth(1e6);
42 disk->set_readwrite_bandwidth(1e6);
45 XBT_INFO("Change bandwidth in the middle of I/O operation");
46 XBT_INFO("Setting read limit to half (.5e6) in the middle of IO. Read should take 1.5s");
47 cur_time = sg4::Engine::get_clock();
48 act = disk->read_async(1e6);
49 sg4::this_actor::sleep_for(.5);
50 disk->set_read_bandwidth(.5e6);
52 XBT_INFO("Read finished. Took: %lf", sg4::Engine::get_clock() - cur_time);
53 disk->set_read_bandwidth(1e6);
55 XBT_INFO("Setting write limit to half (.5e6) in the middle of IO. Write should take 1.5s");
56 cur_time = sg4::Engine::get_clock();
57 act = disk->write_async(1e6);
58 sg4::this_actor::sleep_for(.5);
59 disk->set_write_bandwidth(.5e6);
61 XBT_INFO("Write finished. Took: %lf", sg4::Engine::get_clock() - cur_time);
62 disk->set_write_bandwidth(1e6);
64 XBT_INFO("Setting readwrite limit to half (.5e6) in the middle of IO. Read and write should take 1.5s");
65 cur_time = sg4::Engine::get_clock();
66 act = disk->write_async(.5e6);
67 sg4::IoPtr act2 = disk->read_async(.5e6);
68 sg4::this_actor::sleep_for(.5);
69 disk->set_readwrite_bandwidth(.5e6);
72 XBT_INFO("Read and write finished. Took: %lf", sg4::Engine::get_clock() - cur_time);
75 /*************************************************************************************************/
76 int main(int argc, char** argv)
78 sg4::Engine e(&argc, argv);
80 /* simple platform containing 1 host and 2 disk */
81 auto* zone = sg4::create_full_zone("bob_zone");
82 auto* bob = zone->create_host("bob", 1e6);
83 auto* disk = bob->create_disk("bob_disk", 1e3, 1e3);
84 /* manually setting before seal */
85 disk->set_read_bandwidth(1e6);
86 disk->set_write_bandwidth(1e6);
87 disk->set_readwrite_bandwidth(1e6);
90 sg4::Actor::create("", bob, host);