1 /* Copyright (c) 2013-2018. 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 "src/plugins/vm/VirtualMachineImpl.hpp"
9 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_host, surf, "Logging specific to the SURF host module");
11 simgrid::surf::HostModel *surf_host_model = nullptr;
24 /* Each VM has a dummy CPU action on the PM layer. This CPU action works as the constraint (capacity) of the VM in the
25 * PM layer. If the VM does not have any active task, the dummy CPU action must be deactivated, so that the VM does not
26 * get any CPU share in the PM layer. */
27 void HostModel::ignore_empty_vm_in_pm_LMM()
29 /* iterate for all virtual machines */
30 for (s4u::VirtualMachine* const& ws_vm : vm::VirtualMachineImpl::allVms_) {
31 Cpu* cpu = ws_vm->pimpl_cpu;
32 int active_tasks = cpu->get_constraint()->get_variable_amount();
34 /* The impact of the VM over its PM is the min between its vCPU amount and the amount of tasks it contains */
35 int impact = std::min(active_tasks, ws_vm->getImpl()->coreAmount());
37 XBT_DEBUG("set the weight of the dummy CPU action of VM%p on PM to %d (#tasks: %d)", ws_vm, impact, active_tasks);
39 ws_vm->getImpl()->action_->set_priority(1. / impact);
41 ws_vm->getImpl()->action_->set_priority(0.);
45 /* Helper function for executeParallelTask */
46 static inline double has_cost(double* array, int pos)
54 kernel::resource::Action* HostModel::execute_parallel(int host_nb, s4u::Host** host_list, double* flops_amount,
55 double* bytes_amount, double rate)
57 kernel::resource::Action* action = nullptr;
58 if ((host_nb == 1) && (has_cost(bytes_amount, 0) <= 0)) {
59 action = host_list[0]->pimpl_cpu->execution_start(flops_amount[0]);
60 } else if ((host_nb == 1) && (has_cost(flops_amount, 0) <= 0)) {
61 action = surf_network_model->communicate(host_list[0], host_list[0], bytes_amount[0], rate);
62 } else if ((host_nb == 2) && (has_cost(flops_amount, 0) <= 0) && (has_cost(flops_amount, 1) <= 0)) {
66 for (int i = 0; i < host_nb * host_nb; i++) {
67 if (has_cost(bytes_amount, i) > 0.0) {
69 value = has_cost(bytes_amount, i);
73 action = surf_network_model->communicate(host_list[0], host_list[1], value, rate);
75 xbt_die("Cannot have a communication with no flop to exchange in this model. You should consider using the "
78 xbt_die("Cannot have a communication that is not a simple point-to-point in this model. You should consider "
79 "using the ptask model");
83 "This model only accepts one of the following. You should consider using the ptask model for the other cases.\n"
84 " - execution with one host only and no communication\n"
85 " - Self-comms with one host only\n"
86 " - Communications with two hosts and no computation");
89 delete[] flops_amount;
90 delete[] bytes_amount;
97 HostImpl::HostImpl(s4u::Host* host) : piface_(host)
99 /* The VM wants to reinstall a new HostImpl, but we don't want to leak the previously existing one */
100 delete piface_->pimpl_;
101 piface_->pimpl_ = this;
104 std::vector<const char*> HostImpl::get_attached_storages()
106 std::vector<const char*> storages;
107 for (auto const& s : storage_)
108 if (s.second->getHost() == piface_->get_cname())
109 storages.push_back(s.second->piface_.get_cname());