Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
yet another bunch of int -> unsigned long
[simgrid.git] / src / surf / cpu_interface.cpp
index 8a9a5c1..df62d8a 100644 (file)
@@ -54,7 +54,7 @@ CpuImpl::CpuImpl(s4u::Host* host, const std::vector<double>& speed_per_pstate)
 {
   speed_.scale    = 1;
   speed_.peak     = speed_per_pstate_.front();
-  host->pimpl_cpu = this;
+  host->set_cpu(this);
 }
 
 void CpuImpl::reset_vcpu(CpuImpl* that)
@@ -65,12 +65,13 @@ void CpuImpl::reset_vcpu(CpuImpl* that)
   this->speed_per_pstate_.assign(that->speed_per_pstate_.begin(), that->speed_per_pstate_.end());
 }
 
-CpuImpl* CpuImpl::set_pstate(int pstate_index)
+CpuImpl* CpuImpl::set_pstate(unsigned long pstate_index)
 {
-  xbt_assert(pstate_index <= static_cast<int>(speed_per_pstate_.size()),
-             "Invalid parameters for CPU %s (pstate %d > length of pstates %d). Please fix your platform file, or your "
-             "call to change the pstate.",
-             get_cname(), pstate_index, static_cast<int>(speed_per_pstate_.size()));
+  xbt_assert(
+      pstate_index <= speed_per_pstate_.size(),
+      "Invalid parameters for CPU %s (pstate %lu > length of pstates %lu). Please fix your platform file, or your "
+      "call to change the pstate.",
+      get_cname(), pstate_index, speed_per_pstate_.size());
 
   double new_peak_speed = speed_per_pstate_[pstate_index];
   pstate_               = pstate_index;
@@ -89,10 +90,9 @@ CpuImpl* CpuImpl::set_pstate_speed(const std::vector<double>& speed_per_state)
   return this;
 }
 
-double CpuImpl::get_pstate_peak_speed(int pstate_index) const
+double CpuImpl::get_pstate_peak_speed(unsigned long pstate_index) const
 {
-  xbt_assert((pstate_index <= static_cast<int>(speed_per_pstate_.size())),
-             "Invalid parameters (pstate index out of bounds)");
+  xbt_assert((pstate_index <= speed_per_pstate_.size()), "Invalid parameters (pstate index out of bounds)");
 
   return speed_per_pstate_[pstate_index];
 }
@@ -113,6 +113,31 @@ CpuImpl* CpuImpl::set_core_count(int core_count)
   return this;
 }
 
+void CpuImpl::apply_sharing_policy_cfg() const
+{
+  if (!get_constraint())
+    return;
+
+  kernel::lmm::Constraint::SharingPolicy lmm_policy = kernel::lmm::Constraint::SharingPolicy::SHARED;
+  if (sharing_policy_ == s4u::Host::SharingPolicy::NONLINEAR)
+    lmm_policy = kernel::lmm::Constraint::SharingPolicy::NONLINEAR;
+
+  get_constraint()->set_sharing_policy(lmm_policy, sharing_policy_cb_);
+}
+
+void CpuImpl::set_sharing_policy(s4u::Host::SharingPolicy policy, const s4u::NonLinearResourceCb& cb)
+{
+  xbt_assert(dynamic_cast<CpuTiModel*>(get_model()) == nullptr, "Cannot change sharing policy with CPU:TI model");
+  sharing_policy_    = policy;
+  sharing_policy_cb_ = cb;
+  apply_sharing_policy_cfg();
+}
+
+s4u::Host::SharingPolicy CpuImpl::get_sharing_policy() const
+{
+  return sharing_policy_;
+}
+
 int CpuImpl::get_core_count()
 {
   return core_count_;
@@ -135,6 +160,7 @@ void CpuImpl::seal()
   lmm::System* lmm = get_model()->get_maxmin_system();
   if (dynamic_cast<CpuTiModel*>(get_model()) == nullptr)
     this->set_constraint(lmm->constraint_new(this, core_count_ * speed_per_pstate_.front()));
+  apply_sharing_policy_cfg();
   Resource::seal();
 }