From 8c1069610ba56ba1d98b2bf60cc62fa20cd9ad2a Mon Sep 17 00:00:00 2001 From: David Yeung Date: Wed, 3 May 2017 15:14:38 -0400 Subject: [PATCH] feat(EventManager): adds event counter --- src/native/EventManager.cc | 9 +++++++-- src/native/EventManager.h | 21 +++++++++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/native/EventManager.cc b/src/native/EventManager.cc index dc1f7f2f..669dd65d 100644 --- a/src/native/EventManager.cc +++ b/src/native/EventManager.cc @@ -16,6 +16,7 @@ #include "Trace.h" #include "VMem.h" + namespace { struct InterruptHandler { ebbrt::RcuHListHook hook; @@ -135,6 +136,7 @@ void ebbrt::EventManager::Process() { // instruction is executed (to allow for a halt for example). The nop gives us // a one instruction window to process an interrupt (before the cli) process: + Inc(); asm volatile("sti;" "nop;" "cli;"); @@ -175,7 +177,7 @@ void ebbrt::EventManager::FreeStack(Pfn stack) { free_stacks_.push(stack); } static_assert(ebbrt::Cpu::kMaxCpus <= 256, "adjust event id calculation"); ebbrt::EventManager::EventManager(const RepMap& rm) - : reps_(rm), next_event_id_(Cpu::GetMine() << 24), + : reps_(rm), next_event_id_(Cpu::GetMine() << 24), active_event_context_(next_event_id_++, AllocateStack()) {} void ebbrt::EventManager::Spawn(MovableFunction func, @@ -222,7 +224,7 @@ void ebbrt::EventManager::SpawnLocal(MovableFunction func, tasks_.emplace_back(std::move(func)); } else { sync_spawn_fn_ = std::move(func); - + // put current context on the stack sync_contexts_.emplace(std::move(active_event_context_)); @@ -394,6 +396,9 @@ void ebbrt::EventManager::ReceiveToken() { StartTimer(); } + + + // Check Generation void ebbrt::EventManager::Fire() { if (generation_count_[pending_generation_ % 2] == 0) { diff --git a/src/native/EventManager.h b/src/native/EventManager.h index 2f40e1fa..650e1305 100644 --- a/src/native/EventManager.h +++ b/src/native/EventManager.h @@ -13,9 +13,9 @@ #include #include - #include "../MoveLambda.h" #include "../Timer.h" + #include "Cpu.h" #include "Isr.h" #include "Main.h" @@ -64,9 +64,11 @@ class EventManager : Timer::Hook { explicit EventManager(const RepMap& rm); + static void Init(); static EventManager& HandleFault(EbbId id); - + //void ReceiveMessage(ebbrt::Messenger::NetworkId nid, std::unique_ptr&& buffer){}; + void Spawn(ebbrt::MovableFunction func, bool force_async = false); void SpawnLocal(ebbrt::MovableFunction func, bool force_async = false); @@ -79,6 +81,19 @@ class EventManager : Timer::Hook { std::unordered_map<__gthread_key_t, void*>& GetTlsMap(); void DoRcu(MovableFunction func); void Fire() override; + int Nodeval(){ + auto sum = count; + for (size_t core = 0; core < Cpu::Count(); ++core){ + auto it = reps_.find(core); + if(it != reps_.end()){ + sum += it->second->Coreval(); + } else{ + ebbrt::kprintf("skipped core %d!", core); + } + } + return sum; + }; + int Coreval(){ return count; }; private: template void InvokeFunction(F&& f); @@ -98,6 +113,8 @@ class EventManager : Timer::Hook { void ReceiveToken(); void CheckGeneration(); void StartTimer(); + void Inc(){ count++; }; + int count; const RepMap& reps_; std::stack free_stacks_;