diff --git a/src/mtp/model/mtp-interface.cc b/src/mtp/model/mtp-interface.cc index 14bce44df..7a94b10ed 100644 --- a/src/mtp/model/mtp-interface.cc +++ b/src/mtp/model/mtp-interface.cc @@ -113,6 +113,30 @@ MtpInterface::EnableNew(const uint32_t newSystemCount) { g_systems[i].Enable(i, g_systemCount + 1); } + + UintegerValue ui; + g_sortPeriod.GetValue(ui); + if (ui.Get() == 0) + { + g_period = std::ceil(std::log2(g_systemCount) / 4 + 1); + NS_LOG_INFO("Secheduling period is automatically set to " << g_period); + } + else + { + g_period = ui.Get(); + } + + // create a thread local storage key + // so that we can access the currently assigned LP of each thread + pthread_key_create(&g_key, nullptr); + pthread_setspecific(g_key, &g_systems[0]); +} + +void +MtpInterface::EnableNew(const uint32_t threadCount, const uint32_t newSystemCount) +{ + g_threadCount = threadCount; + EnableNew(newSystemCount); } void diff --git a/src/mtp/model/mtp-interface.h b/src/mtp/model/mtp-interface.h index f79e11f04..cf3fd41fe 100644 --- a/src/mtp/model/mtp-interface.h +++ b/src/mtp/model/mtp-interface.h @@ -35,6 +35,7 @@ class MtpInterface static void Enable(const uint32_t threadCount); // auto partition, specify thread count static void Enable(const uint32_t threadCount, const uint32_t systemCount); // manual partition static void EnableNew(const uint32_t newSystemCount); // add LPs for dynamic added node + static void EnableNew(const uint32_t threadCount, const uint32_t newSystemCount); static void Disable(); static void Run(); static void RunBefore(); diff --git a/src/mtp/model/multithreaded-simulator-impl.cc b/src/mtp/model/multithreaded-simulator-impl.cc index ea743e5b5..7adb9f10e 100644 --- a/src/mtp/model/multithreaded-simulator-impl.cc +++ b/src/mtp/model/multithreaded-simulator-impl.cc @@ -141,8 +141,7 @@ MultithreadedSimulatorImpl::Remove(const EventId& id) if (id.GetUid() == EventId::DESTROY) { // destroy events. - for (std::list::iterator i = m_destroyEvents.begin(); i != m_destroyEvents.end(); - i++) + for (auto i = m_destroyEvents.begin(); i != m_destroyEvents.end(); i++) { if (*i == id) { @@ -176,9 +175,7 @@ MultithreadedSimulatorImpl::IsExpired(const EventId& id) const { return true; } - for (std::list::const_iterator i = m_destroyEvents.begin(); - i != m_destroyEvents.end(); - i++) + for (auto i = m_destroyEvents.begin(); i != m_destroyEvents.end(); i++) { if (*i == id) { @@ -206,7 +203,7 @@ MultithreadedSimulatorImpl::Run() } Time -MultithreadedSimulatorImpl::Now(void) const +MultithreadedSimulatorImpl::Now() const { // Do not add function logging here, to avoid stack overflow return MtpInterface::GetSystem()->Now(); @@ -226,7 +223,7 @@ MultithreadedSimulatorImpl::GetDelayLeft(const EventId& id) const } Time -MultithreadedSimulatorImpl::GetMaximumSimulationTime(void) const +MultithreadedSimulatorImpl::GetMaximumSimulationTime() const { return Time::Max() / 2; } @@ -243,7 +240,7 @@ MultithreadedSimulatorImpl::SetScheduler(ObjectFactory schedulerFactory) } uint32_t -MultithreadedSimulatorImpl::GetSystemId(void) const +MultithreadedSimulatorImpl::GetSystemId() const { return MtpInterface::GetSystem()->GetSystemId(); } @@ -255,7 +252,7 @@ MultithreadedSimulatorImpl::GetContext() const } uint64_t -MultithreadedSimulatorImpl::GetEventCount(void) const +MultithreadedSimulatorImpl::GetEventCount() const { uint64_t eventCount = 0; for (uint32_t i = 0; i < MtpInterface::GetSize(); i++) @@ -284,7 +281,7 @@ MultithreadedSimulatorImpl::Partition() if (m_minLookahead == TimeStep(0)) { std::vector