Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Correctly disable DPOR when StateEq reduction is enabled
[simgrid.git] / src / surf / disk_s19.cpp
1 /* Copyright (c) 2013-2022. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #include <simgrid/kernel/routing/NetPoint.hpp>
7 #include <simgrid/kernel/routing/NetZoneImpl.hpp>
8 #include <simgrid/s4u/Engine.hpp>
9 #include <simgrid/s4u/Host.hpp>
10
11 #include "src/kernel/EngineImpl.hpp"
12 #include "src/kernel/lmm/maxmin.hpp"
13 #include "src/kernel/resource/profile/Event.hpp"
14 #include "src/surf/disk_s19.hpp"
15
16 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(res_disk);
17
18 /*********
19  * Model *
20  *********/
21
22 void surf_disk_model_init_default()
23 {
24   auto disk_model = std::make_shared<simgrid::kernel::resource::DiskS19Model>("Disk");
25   auto* engine    = simgrid::kernel::EngineImpl::get_instance();
26   engine->add_model(disk_model);
27   engine->get_netzone_root()->set_disk_model(disk_model);
28 }
29
30 namespace simgrid::kernel::resource {
31
32 DiskImpl* DiskS19Model::create_disk(const std::string& name, double read_bandwidth, double write_bandwidth)
33 {
34   return (new DiskS19(name, read_bandwidth, write_bandwidth))->set_model(this);
35 }
36
37 void DiskS19Model::update_actions_state(double /*now*/, double delta)
38 {
39   for (auto it = std::begin(*get_started_action_set()); it != std::end(*get_started_action_set());) {
40     auto& action = *it;
41     ++it; // increment iterator here since the following calls to action.finish() may invalidate it
42     action.update_remains(rint(action.get_rate() * delta));
43     action.update_max_duration(delta);
44
45     if (((action.get_remains_no_update() <= 0) && (action.get_variable()->get_penalty() > 0)) ||
46         ((action.get_max_duration() != NO_MAX_DURATION) && (action.get_max_duration() <= 0))) {
47       action.finish(Action::State::FINISHED);
48     }
49   }
50 }
51
52 DiskAction* DiskS19Model::io_start(const DiskImpl* disk, sg_size_t size, s4u::Io::OpType type)
53 {
54   auto* action = new DiskS19Action(this, static_cast<double>(size), not disk->is_on());
55   get_maxmin_system()->expand(disk->get_constraint(), action->get_variable(), 1.0);
56   switch (type) {
57     case s4u::Io::OpType::READ:
58       get_maxmin_system()->expand(disk->get_read_constraint(), action->get_variable(), 1.0);
59       break;
60     case s4u::Io::OpType::WRITE:
61       get_maxmin_system()->expand(disk->get_write_constraint(), action->get_variable(), 1.0);
62       break;
63     default:
64       THROW_UNIMPLEMENTED;
65   }
66   if (const auto& factor_cb = disk->get_factor_cb()) { // handling disk variability
67     action->set_rate_factor(factor_cb(size, type));
68   }
69   return action;
70 }
71
72 /************
73  * Resource *
74  ************/
75 void DiskS19::set_read_bandwidth(double value)
76 {
77   DiskImpl::set_read_bandwidth(value);
78   if (get_read_constraint()) {
79     get_model()->get_maxmin_system()->update_constraint_bound(get_read_constraint(), get_read_bandwidth());
80   }
81 }
82
83 void DiskS19::set_write_bandwidth(double value)
84 {
85   DiskImpl::set_write_bandwidth(value);
86   if (get_write_constraint()) {
87     get_model()->get_maxmin_system()->update_constraint_bound(get_write_constraint(), get_write_bandwidth());
88   }
89 }
90
91 void DiskS19::set_readwrite_bandwidth(double value)
92 {
93   DiskImpl::set_readwrite_bandwidth(value);
94   if (get_constraint()) {
95     get_model()->get_maxmin_system()->update_constraint_bound(get_constraint(), get_readwrite_bandwidth());
96   }
97 }
98
99 void DiskS19::apply_event(kernel::profile::Event* triggered, double value)
100 {
101   /* Find out which of my iterators was triggered, and react accordingly */
102   if (triggered == get_read_event()) {
103     set_read_bandwidth(value);
104     unref_read_event();
105   } else if (triggered == get_write_event()) {
106     set_write_bandwidth(value);
107     unref_write_event();
108   } else if (triggered == get_state_event()) {
109     if (value > 0)
110       turn_on();
111     else
112       turn_off();
113     unref_state_event();
114   } else {
115     xbt_die("Unknown event!\n");
116   }
117
118   XBT_DEBUG("There was a resource state event, need to update actions related to the constraint (%p)",
119             get_constraint());
120 }
121
122 /**********
123  * Action *
124  **********/
125
126 DiskS19Action::DiskS19Action(Model* model, double cost, bool failed)
127     : DiskAction(model, cost, failed, model->get_maxmin_system()->variable_new(this, 1.0, -1.0, 3))
128 {
129 }
130
131 void DiskS19Action::update_remains_lazy(double /*now*/)
132 {
133   THROW_IMPOSSIBLE;
134 }
135 } // namespace simgrid::kernel::resource