Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'multi_models_no_globals' into 'master'
[simgrid.git] / src / surf / HostImpl.hpp
1 /* Copyright (c) 2004-2021. 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 #ifndef SURF_HOST_INTERFACE_HPP
7 #define SURF_HOST_INTERFACE_HPP
8
9 #include "src/kernel/actor/ActorImpl.hpp"
10 #include "src/kernel/resource/DiskImpl.hpp"
11 #include "src/surf/cpu_interface.hpp"
12 #include "src/surf/network_interface.hpp"
13 #include <xbt/PropertyHolder.hpp>
14
15 #include <vector>
16
17 namespace simgrid {
18 namespace surf {
19
20 /*********
21  * Model *
22  *********/
23
24 /** @ingroup SURF_host_interface
25  * @brief SURF Host model interface class
26  * @details A model is an object which handle the interactions between its Resources and its Actions
27  */
28 class XBT_PRIVATE HostModel : public kernel::resource::Model {
29 public:
30   HostModel() : Model(Model::UpdateAlgo::FULL) {}
31
32   virtual kernel::resource::Action* execute_parallel(const std::vector<s4u::Host*>& host_list,
33                                                      const double* flops_amount, const double* bytes_amount,
34                                                      double rate) = 0;
35 };
36
37 /************
38  * Resource *
39  ************/
40 /** @ingroup SURF_host_interface
41  * @brief SURF Host interface class
42  * @details A host represents a machine with an aggregation of a Cpu, a RoutingEdge and Disk(s)
43  */
44 class XBT_PRIVATE HostImpl : public xbt::PropertyHolder {
45   using ActorList = boost::intrusive::list<
46       kernel::actor::ActorImpl,
47       boost::intrusive::member_hook<kernel::actor::ActorImpl, boost::intrusive::list_member_hook<>,
48                                     &kernel::actor::ActorImpl::host_actor_list_hook>>;
49
50   ActorList actor_list_;
51   std::vector<kernel::actor::ProcessArg*> actors_at_boot_;
52   s4u::Host* piface_ = nullptr; // we must have a pointer there because the VM wants to change the piface in its ctor
53   std::vector<kernel::resource::DiskImpl*> disks_;
54
55 public:
56   friend simgrid::vm::VirtualMachineImpl;
57   explicit HostImpl(s4u::Host* host);
58   virtual ~HostImpl();
59
60   std::vector<s4u::Disk*> get_disks() const;
61   void set_disks(const std::vector<kernel::resource::DiskImpl*>& disks, s4u::Host* host);
62   void add_disk(const s4u::Disk* disk);
63   void remove_disk(const std::string& disk_name);
64
65   s4u::Host* get_iface() const { return piface_; }
66
67   void turn_on() const;
68   void turn_off(const kernel::actor::ActorImpl* issuer);
69   std::vector<s4u::ActorPtr> get_all_actors();
70   size_t get_actor_count() const;
71   void add_actor(kernel::actor::ActorImpl* actor) { actor_list_.push_back(*actor); }
72   void remove_actor(kernel::actor::ActorImpl* actor) { xbt::intrusive_erase(actor_list_, *actor); }
73   void add_actor_at_boot(kernel::actor::ProcessArg* arg) { actors_at_boot_.emplace_back(arg); }
74
75   template <class F> void foreach_actor(F function)
76   {
77     for (auto& actor : actor_list_)
78       function(actor);
79   }
80 };
81 }
82 }
83
84 #endif /* SURF_HOST_INTERFACE_HPP */