From 7165e0db44eea5285f2eaa427ecc2349949464e5 Mon Sep 17 00:00:00 2001 From: Martin Karsten <mkarsten@uwaterloo.ca> Date: Thu, 19 Jul 2018 15:02:23 -0400 Subject: [PATCH] - separate out busyLock from Cluster's idleLock --- src/kernel/KernelProcessor.cc | 2 +- src/libfibre/SystemProcessor.cc | 2 +- src/runtime/Cluster.h | 21 +++++++++++++-------- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/kernel/KernelProcessor.cc b/src/kernel/KernelProcessor.cc index d3796a0..eb24ec9 100644 --- a/src/kernel/KernelProcessor.cc +++ b/src/kernel/KernelProcessor.cc @@ -43,8 +43,8 @@ inline void KernelProcessor::idleLoop(bool irqs) { if (cluster.setProcessorIdle(*this, terminate)) { stats->idle.count(); if (!CurrFM().zeroMemory<smallpl>()) halt(!irqs); - cluster.setProcessorBusy(*this); } + cluster.setProcessorBusy(*this); } unreachable(); } diff --git a/src/libfibre/SystemProcessor.cc b/src/libfibre/SystemProcessor.cc index 3f6f031..f79ba5f 100644 --- a/src/libfibre/SystemProcessor.cc +++ b/src/libfibre/SystemProcessor.cc @@ -101,8 +101,8 @@ inline void SystemProcessor::idleLoop() { if (reinterpret_cast<FibreCluster&>(cluster).setProcessorIdle(*this, terminate)) { stats->idle.count(); idleSem.P(); - cluster.setProcessorBusy(*this); } + cluster.setProcessorBusy(*this); } } diff --git a/src/runtime/Cluster.h b/src/runtime/Cluster.h index 450ebca..83912ab 100644 --- a/src/runtime/Cluster.h +++ b/src/runtime/Cluster.h @@ -33,6 +33,7 @@ protected: SystemLock idleLock; ProcessorList idleList; volatile size_t idleCount; + SystemLock busyLock; ProcessorList busyList; public: @@ -54,7 +55,7 @@ public: ProcessorRing::insert_after(*ringProc, proc); } #endif - ScopedLock<SystemLock> sli(idleLock); + ScopedLock<SystemLock> sli(busyLock); busyList.push_back(proc); pCount += 1; } @@ -69,7 +70,7 @@ public: if (ringProc == &proc) ringProc = nullptr; ProcessorRing::remove(proc); #endif - ScopedLock<SystemLock> sli(idleLock); + ScopedLock<SystemLock> sli(busyLock); busyList.remove(proc); pCount -= 1; } @@ -92,7 +93,7 @@ public: } StackContext* steal() { - ScopedLock<SystemLock> sl(idleLock); + ScopedLock<SystemLock> sl(busyLock); BaseProcessor* p = busyList.front(); while (p != busyList.edge()) { StackContext* s = p->dequeue<true>(_friend<Cluster>()); @@ -107,21 +108,25 @@ public: } size_t setProcessorIdle(BaseProcessor& proc, bool terminating) { - ScopedLock<SystemLock> sl(idleLock); - if (!terminating && (backgroundProc.load() || stagingProc.load())) return 0; + busyLock.acquire(); busyList.remove(proc); + busyLock.release(); + Runtime::debugS("Processor ", FmtHex(&proc), " on idle list"); + ScopedLock<SystemLock> sl(idleLock); idleList.push_back(proc); idleCount += 1; - Runtime::debugS("Processor ", FmtHex(&proc), " on idle list"); + if (!terminating && (backgroundProc.load() || stagingProc.load())) return 0; return idleCount; } void setProcessorBusy(BaseProcessor& proc) { - ScopedLock<SystemLock> sl(idleLock); + idleLock.acquire(); idleCount -= 1; idleList.remove(proc); - busyList.push_back(proc); + idleLock.release(); Runtime::debugS("Processor ", FmtHex(&proc), " off idle list"); + ScopedLock<SystemLock> sl(busyLock); + busyList.push_back(proc); } BaseProcessor* findIdleProcessorHard() { -- GitLab