X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/cf2a7c6a685a2a56113882f9cf278849e315fd32..a4e7a60bca6c13451f237201eb5a7534e5da0838:/src/surf/cpu_ti.cpp diff --git a/src/surf/cpu_ti.cpp b/src/surf/cpu_ti.cpp index 8dc0926b71..eea488f589 100644 --- a/src/surf/cpu_ti.cpp +++ b/src/surf/cpu_ti.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2013-2015. The SimGrid Team. +/* Copyright (c) 2013-2017. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -34,7 +34,7 @@ CpuTiTrace::CpuTiTrace(tmgr_trace_t speedTrace) nbPoints_ = speedTrace->event_list.size() + 1; timePoints_ = new double[nbPoints_]; integral_ = new double[nbPoints_]; - for (auto val : speedTrace->event_list) { + for (auto const& val : speedTrace->event_list) { timePoints_[i] = time; integral_[i] = integral; integral += val.date_ * val.value_; @@ -255,7 +255,7 @@ CpuTiTgmr::CpuTiTgmr(tmgr_trace_t speedTrace, double value) : trace_ = 0; /* no availability file, fixed trace */ - if (!speedTrace) { + if (not speedTrace) { type_ = TRACE_FIXED; value_ = value; XBT_DEBUG("No availability trace. Constant value = %f", value); @@ -273,7 +273,7 @@ CpuTiTgmr::CpuTiTgmr(tmgr_trace_t speedTrace, double value) : type_ = TRACE_DYNAMIC; /* count the total time of trace file */ - for (auto val : speedTrace->event_list) + for (auto const& val : speedTrace->event_list) total_time += val.date_; trace_ = new CpuTiTrace(speedTrace); @@ -296,9 +296,8 @@ int CpuTiTrace::binarySearch(double *array, double a, int low, int high) { xbt_assert(low < high, "Wrong parameters: low (%d) should be smaller than high (%d)", low, high); - int mid; do { - mid = low + (high - low) / 2; + int mid = low + (high - low) / 2; XBT_DEBUG("a %f low %d high %d mid %d value %f", a, low, high, mid, array[mid]); if (array[mid] > a) @@ -320,8 +319,8 @@ int CpuTiTrace::binarySearch(double *array, double a, int low, int high) void surf_cpu_model_init_ti() { - xbt_assert(!surf_cpu_model_pm,"CPU model already initialized. This should not happen."); - xbt_assert(!surf_cpu_model_vm,"CPU model already initialized. This should not happen."); + xbt_assert(not surf_cpu_model_pm, "CPU model already initialized. This should not happen."); + xbt_assert(not surf_cpu_model_vm, "CPU model already initialized. This should not happen."); surf_cpu_model_pm = new simgrid::surf::CpuTiModel(); all_existing_models->push_back(surf_cpu_model_pm); @@ -381,10 +380,9 @@ void CpuTiModel::updateActionsState(double now, double /*delta*/) while ((xbt_heap_size(tiActionHeap_) > 0) && (xbt_heap_maxkey(tiActionHeap_) <= now)) { CpuTiAction *action = static_cast(xbt_heap_pop(tiActionHeap_)); XBT_DEBUG("Action %p: finish", action); - action->finish(); + action->finish(Action::State::done); /* set the remains to 0 due to precision problems when updating the remaining amount */ action->setRemains(0); - action->setState(Action::State::done); /* update remaining amount of all actions */ action->cpu_->updateRemainingAmount(surf_get_clock()); } @@ -424,7 +422,7 @@ void CpuTi::setSpeedTrace(tmgr_trace_t trace) if (trace && trace->event_list.size() > 1) { trace_mgr::DatedValue val = trace->event_list.back(); if (val.date_ < 1e-12) - speed_.event = future_evt_set->add_trace(tmgr_empty_trace_new(), this); + speed_.event = future_evt_set->add_trace(new simgrid::trace_mgr::trace(), this); } } @@ -491,7 +489,6 @@ void CpuTi::updateActionsFinishTime(double now) CpuTiAction *action; double sum_priority = 0.0; double total_area; - double min_finish = -1; /* update remaining amount of actions */ updateRemainingAmount(now); @@ -516,7 +513,7 @@ void CpuTi::updateActionsFinishTime(double now) for(ActionTiList::iterator it(actionSet_->begin()), itend(actionSet_->end()) ; it != itend ; ++it) { action = &*it; - min_finish = -1; + double min_finish = -1; /* action not running, skip it */ if (action->getStateSet() != surf_cpu_model_pm->getRunningActionSet()) continue; @@ -551,8 +548,8 @@ void CpuTi::updateActionsFinishTime(double now) if (min_finish > NO_MAX_DURATION) xbt_heap_push(static_cast(model())->tiActionHeap_, action, min_finish); - XBT_DEBUG("Update finish time: Cpu(%s) Action: %p, Start Time: %f Finish Time: %f Max duration %f", cname(), action, - action->getStartTime(), action->finishTime_, action->getMaxDuration()); + XBT_DEBUG("Update finish time: Cpu(%s) Action: %p, Start Time: %f Finish Time: %f Max duration %f", getCname(), + action, action->getStartTime(), action->finishTime_, action->getMaxDuration()); } /* remove from modified cpu */ modified(false); @@ -560,7 +557,7 @@ void CpuTi::updateActionsFinishTime(double now) bool CpuTi::isUsed() { - return !actionSet_->empty(); + return not actionSet_->empty(); } double CpuTi::getAvailableSpeed() @@ -612,7 +609,7 @@ void CpuTi::updateRemainingAmount(double now) CpuAction *CpuTi::execution_start(double size) { - XBT_IN("(%s,%g)", cname(), size); + XBT_IN("(%s,%g)", getCname(), size); CpuTiAction* action = new CpuTiAction(static_cast(model()), size, isOff(), this); actionSet_->push_back(*action); @@ -627,7 +624,7 @@ CpuAction *CpuTi::sleep(double duration) if (duration > 0) duration = MAX(duration, sg_surf_precision); - XBT_IN("(%s,%g)", cname(), duration); + XBT_IN("(%s,%g)", getCname(), duration); CpuTiAction* action = new CpuTiAction(static_cast(model()), 1.0, isOff(), this); action->maxDuration_ = duration; @@ -649,7 +646,7 @@ CpuAction *CpuTi::sleep(double duration) void CpuTi::modified(bool modified){ CpuTiList* modifiedCpu = static_cast(model())->modifiedCpu_; if (modified) { - if (!cpu_ti_hook.is_linked()) { + if (not cpu_ti_hook.is_linked()) { modifiedCpu->push_back(*this); } } else { @@ -667,6 +664,7 @@ CpuTiAction::CpuTiAction(CpuTiModel *model_, double cost, bool failed, CpuTi *cp : CpuAction(model_, cost, failed) , cpu_(cpu) { + indexHeap_ = -1; cpu_->modified(true); } @@ -684,7 +682,7 @@ void CpuTiAction::setState(Action::State state) int CpuTiAction::unref() { refcount_--; - if (!refcount_) { + if (not refcount_) { if (action_hook.is_linked()) getStateSet()->erase(getStateSet()->iterator_to(*this)); /* remove from action_set */ @@ -752,10 +750,10 @@ void CpuTiAction::setMaxDuration(double duration) XBT_OUT(); } -void CpuTiAction::setPriority(double priority) +void CpuTiAction::setSharingWeight(double priority) { XBT_IN("(%p,%g)", this, priority); - priority_ = priority; + sharingWeight_ = priority; cpu_->modified(true); XBT_OUT(); }