[haiku-commits] BRANCH pdziepak-github.scheduler [5159255] src/system/kernel/scheduler src/system/kernel headers/private/kernel

  • From: pdziepak-github.scheduler <community@xxxxxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Tue, 7 Jan 2014 02:30:32 +0100 (CET)

added 3 changesets to branch 'refs/remotes/pdziepak-github/scheduler'
old head: dc2635976cad7dad448adc25c28dad072777aa2d
new head: 51592558cc941f06948a58c48ff3ff462054a713
overview: https://github.com/pdziepak/Haiku/compare/dc26359...5159255

----------------------------------------------------------------------------

51f3693: kernel: Fix ABA problem in try_acquire_read_spinlock()

e56b289: scheduler: Improve should_rebalance

5159255: kernel: Relax cpu_ent::interrupt_time locking
  
  The value isn't accessed by the other CPUs and all writes and reads are
  done with interrupts disabled.

                                    [ Pawel Dziepak <pdziepak@xxxxxxxxxxx> ]

----------------------------------------------------------------------------

8 files changed, 33 insertions(+), 42 deletions(-)
headers/private/kernel/smp.h                     |  5 +----
src/system/kernel/int.cpp                        | 10 ++++++----
src/system/kernel/scheduler/low_latency.cpp      | 16 ++++++++++------
src/system/kernel/scheduler/power_saving.cpp     | 16 ++++++++--------
src/system/kernel/scheduler/scheduler.cpp        |  3 +--
src/system/kernel/scheduler/scheduler_thread.cpp |  7 -------
src/system/kernel/scheduler/scheduler_thread.h   | 12 ++++++------
src/system/kernel/smp.cpp                        |  6 +-----

############################################################################

Commit:      51f36939f376d54804d49b27218a62b99220527e
Author:      Pawel Dziepak <pdziepak@xxxxxxxxxxx>
Date:        Mon Jan  6 20:02:11 2014 UTC

kernel: Fix ABA problem in try_acquire_read_spinlock()

----------------------------------------------------------------------------

diff --git a/headers/private/kernel/smp.h b/headers/private/kernel/smp.h
index 685e3d5..43126eb 100644
--- a/headers/private/kernel/smp.h
+++ b/headers/private/kernel/smp.h
@@ -210,10 +210,7 @@ static inline bool
 try_acquire_read_spinlock_inline(rw_spinlock* lock)
 {
        uint32 previous = atomic_add(&lock->lock, 1);
-       if ((previous & (1u << 31)) == 0)
-               return true;
-       atomic_test_and_set(&lock->lock, 1u << 31, previous);
-       return false;
+       return (previous & (1u << 31)) == 0;
 }
 
 
diff --git a/src/system/kernel/smp.cpp b/src/system/kernel/smp.cpp
index a82c7a2..325fa72 100644
--- a/src/system/kernel/smp.cpp
+++ b/src/system/kernel/smp.cpp
@@ -617,11 +617,7 @@ try_acquire_read_spinlock(rw_spinlock* lock)
 #endif
 
        uint32 previous = atomic_add(&lock->lock, 1);
-       if ((previous & (1u << 31)) == 0)
-               return true;
-
-       atomic_test_and_set(&lock->lock, 1u << 31, previous);
-       return false;
+       return (previous & (1u << 31)) == 0;
 }
 
 

############################################################################

Commit:      e56b2896fe4253882884c3d9d98e074e3697d19f
Author:      Pawel Dziepak <pdziepak@xxxxxxxxxxx>
Date:        Tue Jan  7 00:09:56 2014 UTC

scheduler: Improve should_rebalance

----------------------------------------------------------------------------

diff --git a/src/system/kernel/scheduler/low_latency.cpp 
b/src/system/kernel/scheduler/low_latency.cpp
index 42baee3..09c6f71 100644
--- a/src/system/kernel/scheduler/low_latency.cpp
+++ b/src/system/kernel/scheduler/low_latency.cpp
@@ -84,14 +84,18 @@ should_rebalance(const ThreadData* threadData)
        if (threadData->GetLoad() >= coreLoad / 2)
                return false;
 
+       int32 threadLoad = threadData->GetLoad();
+       int32 coreNewLoad = coreLoad - threadLoad;
+
        // If there is high load on this core but this thread does not 
contribute
        // significantly consider giving it to someone less busy.
        if (coreLoad > kHighLoad) {
-               ReadSpinLocker coreLocker(gCoreHeapsLock);
-
                CoreEntry* other = gCoreLoadHeap.PeekMinimum();
-               if (other != NULL && coreLoad - other->GetLoad() >= 
kLoadDifference)
-                       return true;
+               if (other != NULL) {
+                       int32 otherNewLoad = other->GetLoad() + threadLoad;
+                       if (coreNewLoad - otherNewLoad >= kLoadDifference)
+                               return true;
+               }
        }
 
        // No cpu bound threads - the situation is quite good. Make sure it
@@ -101,8 +105,8 @@ should_rebalance(const ThreadData* threadData)
        CoreEntry* other = gCoreLoadHeap.PeekMinimum();
        if (other == NULL)
                other = gCoreHighLoadHeap.PeekMinimum();
-       ASSERT(other != NULL);
-       return coreLoad - other->GetLoad() >= kLoadDifference * 2;
+       int32 otherNewLoad = other->GetLoad() + threadLoad;
+       return coreNewLoad - otherNewLoad >= kLoadDifference * 2;
 }
 
 
diff --git a/src/system/kernel/scheduler/power_saving.cpp 
b/src/system/kernel/scheduler/power_saving.cpp
index 3b36add..b41bbe7 100644
--- a/src/system/kernel/scheduler/power_saving.cpp
+++ b/src/system/kernel/scheduler/power_saving.cpp
@@ -52,10 +52,7 @@ choose_small_task_core()
 {
        SCHEDULER_ENTER_FUNCTION();
 
-       ReadSpinLocker locker(gCoreHeapsLock);
        CoreEntry* core = gCoreLoadHeap.PeekMaximum();
-       locker.Unlock();
-
        if (core == NULL)
                return sSmallTaskCore;
 
@@ -126,25 +123,28 @@ should_rebalance(const ThreadData* threadData)
        CoreEntry* core = threadData->Core();
 
        int32 coreLoad = core->GetLoad();
+       int32 threadLoad = threadData->GetLoad();
        if (coreLoad > kHighLoad) {
-               ReadSpinLocker coreLocker(gCoreHeapsLock);
                if (sSmallTaskCore == core) {
                        sSmallTaskCore = NULL;
                        choose_small_task_core();
 
-                       if (threadData->GetLoad() > coreLoad / 3)
+                       if (threadLoad > coreLoad / 3)
                                return false;
                        return coreLoad > kVeryHighLoad;
                }
 
-               if (threadData->GetLoad() >= coreLoad / 2)
+               if (threadLoad >= coreLoad / 2)
                        return false;
 
                CoreEntry* other = gCoreLoadHeap.PeekMaximum();
                if (other == NULL)
                        other = gCoreHighLoadHeap.PeekMinimum();
                ASSERT(other != NULL);
-               return coreLoad - other->GetLoad() >= kLoadDifference / 2;
+
+               int32 coreNewLoad = coreLoad - threadLoad;
+               int32 otherNewLoad = other->GetLoad() + threadLoad;
+               return coreNewLoad - otherNewLoad >= kLoadDifference / 2;
        }
 
        if (coreLoad >= kMediumLoad)
@@ -154,7 +154,7 @@ should_rebalance(const ThreadData* threadData)
        if (smallTaskCore == NULL)
                return false;
        return smallTaskCore != core
-               && smallTaskCore->GetLoad() +threadData->GetLoad() < kHighLoad;
+               && smallTaskCore->GetLoad() + threadLoad < kHighLoad;
 }
 
 

############################################################################

Commit:      51592558cc941f06948a58c48ff3ff462054a713
Author:      Pawel Dziepak <pdziepak@xxxxxxxxxxx>
Date:        Tue Jan  7 01:09:29 2014 UTC

kernel: Relax cpu_ent::interrupt_time locking

The value isn't accessed by the other CPUs and all writes and reads are
done with interrupts disabled.

----------------------------------------------------------------------------

diff --git a/src/system/kernel/int.cpp b/src/system/kernel/int.cpp
index fea008b..c09d8bc 100644
--- a/src/system/kernel/int.cpp
+++ b/src/system/kernel/int.cpp
@@ -359,14 +359,16 @@ int_io_interrupt_handler(int vector, bool levelTriggered)
        if (!sVectors[vector].no_lock_vector)
                release_spinlock(&sVectors[vector].vector_lock);
 
-       SpinLocker locker(sVectors[vector].load_lock);
+       SpinLocker vectorLocker(sVectors[vector].load_lock);
        bigtime_t deltaTime = system_time() - start;
        sVectors[vector].last_measure_active += deltaTime;
-       locker.Unlock();
+       vectorLocker.Unlock();
 
-       atomic_add64(&get_cpu_struct()->interrupt_time, deltaTime);
+       cpu_ent* cpu = get_cpu_struct();
+       cpu->interrupt_time += deltaTime;
        if (sVectors[vector].type == INTERRUPT_TYPE_IRQ)
-               atomic_add64(&get_cpu_struct()->irq_time, deltaTime);
+               cpu->irq_time += deltaTime;
+
        update_int_load(vector);
 
        if (levelTriggered)
diff --git a/src/system/kernel/scheduler/scheduler.cpp 
b/src/system/kernel/scheduler/scheduler.cpp
index ca67208..ca04585 100644
--- a/src/system/kernel/scheduler/scheduler.cpp
+++ b/src/system/kernel/scheduler/scheduler.cpp
@@ -393,8 +393,7 @@ reschedule(int32 nextState)
        ThreadData* oldThreadData = oldThread->scheduler_data;
 
        // return time spent in interrupts
-       oldThreadData->IncreaseStolenTime(
-               gCPU[thisCPU].interrupt_time - 
oldThreadData->LastInterruptTime());
+       oldThreadData->SetStolenInterruptTime(gCPU[thisCPU].interrupt_time);
 
        bool enqueueOldThread = false;
        bool putOldThreadAtBack = false;
diff --git a/src/system/kernel/scheduler/scheduler_thread.cpp 
b/src/system/kernel/scheduler/scheduler_thread.cpp
index 6f9c818..af4b40a 100644
--- a/src/system/kernel/scheduler/scheduler_thread.cpp
+++ b/src/system/kernel/scheduler/scheduler_thread.cpp
@@ -166,13 +166,6 @@ ThreadData::ComputeLoad()
        SCHEDULER_ENTER_FUNCTION();
 
        ASSERT(gTrackLoad);
-
-       if (fLastInterruptTime > 0) {
-               bigtime_t interruptTime = 
gCPU[smp_get_current_cpu()].interrupt_time;
-               interruptTime -= fLastInterruptTime;
-               fMeasureActiveTime -= interruptTime;
-       }
-
        compute_load(fMeasureTime, fMeasureActiveTime, fLoad);
 }
 
diff --git a/src/system/kernel/scheduler/scheduler_thread.h 
b/src/system/kernel/scheduler/scheduler_thread.h
index 8d9cbdd..5c8d052 100644
--- a/src/system/kernel/scheduler/scheduler_thread.h
+++ b/src/system/kernel/scheduler/scheduler_thread.h
@@ -51,12 +51,9 @@ public:
                        bool            ChooseCoreAndCPU(CoreEntry*& targetCore,
                                                        CPUEntry*& targetCPU);
 
-       inline  bigtime_t       LastInterruptTime() const
-                                                       { return 
fLastInterruptTime; }
        inline  void            SetLastInterruptTime(bigtime_t interruptTime)
                                                        { fLastInterruptTime = 
interruptTime; }
-
-       inline  void            IncreaseStolenTime(bigtime_t stolenTime);
+       inline  void            SetStolenInterruptTime(bigtime_t interruptTime);
 
        inline  void            GoesAway();
        inline  bigtime_t       WentSleep() const       { return fWentSleep; }
@@ -226,10 +223,13 @@ ThreadData::ShouldCancelPenalty() const
 
 
 inline void
-ThreadData::IncreaseStolenTime(bigtime_t stolenTime)
+ThreadData::SetStolenInterruptTime(bigtime_t interruptTime)
 {
        SCHEDULER_ENTER_FUNCTION();
-       fStolenTime += stolenTime;
+
+       interruptTime -= fLastInterruptTime;
+       fStolenTime += interruptTime;
+       fMeasureActiveTime -= interruptTime;
 }
 
 


Other related posts:

  • » [haiku-commits] BRANCH pdziepak-github.scheduler [5159255] src/system/kernel/scheduler src/system/kernel headers/private/kernel - pdziepak-github . scheduler