History log of /haiku/src/system/kernel/scheduler/scheduler.cpp
Revision Date Author Comments
# 163053a4 27-Sep-2023 Puck Meerburg <puck@puckipedia.com>

scheduler: Only unassign a thread's core if it is not pinned

If a pinned thread is being run while disabling a CPU core, the thread
is properly requeued to that core, but with fCore set to NULL, causing
the scheduler to panic the next time that thread is rescheduled.

Change-Id: I9cf18c5a470517124b2573347cf3eb6fd26ab7b6
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6917
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: waddlesplash <waddlesplash@gmail.com>


# 8dc67def 04-Aug-2022 Augustin Cavalier <waddlesplash@gmail.com>

kernel/scheduler: Always reschedule after enqueueing if the runqueue was empty.

Normally the heap's priority will suffice to check if we need to reschedule.
However, in cases where the CPU in question is currently in the middle of
rescheduling already, and it is about to change its priority to "idle",
we can race with it and not notice that we need to send it an ICI.
Previously this meant we would just lose some performance, but after
recent fixes to not reschedule only as necessary, this race led to hangs.

Now we report whether the runqueue we added the thread to was empty
in ThreadData::Enqueue(), and if it was, we then always trigger a
scheduler invocation on the target CPU.

In my testing, this fixes #17847; and at least in my unscientific
benchmarks, improves compile performance by as much as 10% (I saw
~55s -> ~50s in some tests.)


# 644fa4bf 12-Jul-2022 Augustin Cavalier <waddlesplash@gmail.com>

kernel/scheduler: Reset the invoke_scheduler flag on reschedule.

There is nowhere else that unsets it (or makes sense to unset it),
we have to do it here, or otherwise it will never be unset.
This has actually been broken since the new scheduler was merged
many years ago; the old scheduler (which had more complex logic here)
unset this flag correctly.

This oversight mostly did not cause obvious problems: while the scheduler
would be invoked unnecessarily on every single interrupt, that would
be a minor performance downturn at most. But there is one other effect:
since we can only reenable interrupts after invoking the scheduler,
"post_interrupt_callback"s of threads were not invoked most of the time.

The main user of "post_interrupt_callback"s is the profiler, which uses
them to trigger buffer flushes back to userland. Since they were not
invoked, the buffer would quickly fill up and then no more results
would be recorded.

Thus, this fixes #16345.


# b05be77d 23-Oct-2021 David Karoly <karolyd577@gmail.com>

kernel/scheduler: fix compile error when TRACE is enabled

Change-Id: I95da18c9faa343fb3a44c627c1227a778701ebbe
Reviewed-on: https://review.haiku-os.org/c/haiku/+/4653
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>


# e632208b 10-Sep-2020 Jérôme Duval <jerome.duval@gmail.com>

kernel/scheduler: enable cpu load tracking after boot

when the cpufreq module is loaded, we let the scheduler update its policy.
Improve assert report
CoreEntry::GetLoad() could return more than kMaxLoad.

Change-Id: I127f9b3e8062b5996872aae30b4021b9904fa179
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3216
Reviewed-by: Jérôme Duval <jerome.duval@gmail.com>


# 3142fb69 11-Jul-2018 Augustin Cavalier <waddlesplash@gmail.com>

scheduler: Fix setting priorities following the penalty cancellation changes.

Before hrev46809, the "thread->priority = priority" line was below this
check, and so all was well. But that commit moved the line to its present
location, which means ever since then, the following code which updates
CPU entries, scheduler listeners, etc. has never been run.

On my VMware instance (which is probably pretty affected by the host system
and thus not the greatest performance test), "time jam -j2 HaikuDepot" decreased
from 46.0s real to 43.3s real, 52.3s user to 48.1s user, 12.1s sys to 12.2s sys.
So this seems to make some sort of impact.

Spotted by Fishpond in #10454 and confirmed by korli, but somehow neither of
them followed up on that in the 4.5 years since...


# 1bba129c 08-Apr-2014 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Let ThreadData::ShouldRebalance() choose the actual core

Currently, ThreadData::ShouldRebalance() (and mode specific functions
it calls) only decides whether to migrate thread to another core or not.
However, in most cases it actually needs to find the best candidate for
new core so it could as well return that information.


# 230d1fcf 03-Feb-2014 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Update load of idle cores

In order to keep the scheduler tickless core load is computed and updated
only during various scheduler events (i.e. thread enqueue, reschedule, etc).
The problem it creates is that if a core becomes idle its load may remain
outdated for an extended period of time thus resulting in suboptimal thread
migration decisions.

The solution to this problem is to add a timer each time an idle thread is
scheudled which, after kLoadMeasureInterval, would fire and force load
update.


# f116370e 30-Jan-2014 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Relax penalty cancellation requirements

Priority penalties were made more strict in order to prevent situation
when two or more high priority threads uses up all available CPU time
in such manner that they do not receive a penalty but starve low priority
threads.

However, a significant change to thread priorites has been made since and
now priority of all non real time threads varies in a range from 1 to
static priority minus penalty. This means that the scheduler is able to
prevent thread starvation without any complex penalty policies.


# 931ce674 26-Jan-2014 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Fix core unassignment


# 7adce94d 26-Jan-2014 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Check team user time timers before entering scheduler

User timers may cause another thread to become ready in which case we would
like this to happen before scheduler_reschedule() chooses next thread to
be executed.


# 0269dd28 16-Jan-2014 Pawel Dziepak <pdziepak@quarnos.org>

Revert "scheduler: SCHEDULER_EXIT_FUNCTION() is not needed"

This reverts commit 667617ad043a4587d8d366d5192d9ad291cfa37a.

Scheduler profiler uses CPU local data to store function information, hence
arch_thread_context_switch() usually is not a problem. However, when
we switch to a new thread we end up scheduler_new_thread_entry() instead
of scheduler_reschedule() what may corrupt data collected by the profiler.


# b7d404c2 16-Jan-2014 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Add ThreadData::{GetPriority, IsIdle, IsRealTime}()


# 093c2202 16-Jan-2014 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Improve latencies


# a2634874 08-Jan-2014 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Estimate the load thread is able to produce

Previous implementation based on the actual load of each core and share
each thread has in that load turned up to be very problematic when
balancing load on very heavily loaded systems (i.e. more threads
consuming all available CPU time than there is logical CPUs).

The new approach is to estimate how much load would a thread produce
if it had all CPU time only for itself. Summing such load estimations
of each thread assigned to a given core we get a rank that contains
much more information than just simple actual core load.


# d36098e0 07-Jan-2014 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Keep track of the number of the ready threads


# 9c465cc8 07-Jan-2014 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Improve recognition of CPU bound threads


# c2a02dee 06-Jan-2014 Pawel Dziepak <pdziepak@quarnos.org>

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.


# a5f45afa 05-Jan-2014 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Remove unnecessary check against disabled CPU


# 8235bbc9 05-Jan-2014 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Improve thread creation performance


# cb66faef 04-Jan-2014 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Work around GCC2 limitations in function inlining

GCC2 won't inline a function if it is used before its definition.


# 9e99bf60 03-Jan-2014 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: SCHEDULER_EXIT_FUNCTION() is not needed


# 81e04d7b 03-Jan-2014 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Remove cpu_info::load

This field forces kernel to track each CPU load all the time. It is not
a problem with the current scheduler on a multicore systems, but on
single core machnies or with any other future scheduler this field may
become just an unnecessary burden. It isn't difficult for an application
to compute CPU load by itself when it needs it.


# e4ea6372 03-Jan-2014 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Disable load tracking when not needed


# db1ddabf 30-Dec-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Thread can not stay on CPU if it has been disabled


# 26592750 30-Dec-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Protect per CPU run queue with its own lock


# 15a7f204 29-Dec-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Return CPU load in cpu_info


# 56c0f467 29-Dec-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Fix unused variable warnings


# 96dcc73b 26-Dec-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Add scheduler profiler

A bit hackish implementation of a profiler for the scheduler.
SCHEDULER_ENTER_FUNCTION at the begining of each function aren't nice and
usage of __PRETTY_FUNCTION__ isn't any better (both gcc and clang support
it though), but it was quick to implement and doesn't lose information
on inlined functions. It's just a tool, not an integral part of the kernal
anyway.


# cf4984f6 23-Dec-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Use precomputed time slice lengths


# b24ea642 23-Dec-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Encapsulate ThreadData fields


# a08b40d4 23-Dec-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Encapsulate CPUEntry fields


# e1e7235c 23-Dec-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Encapsulate CoreEntry fields


# 60e198f2 22-Dec-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Encapsulate PackageEntry fields

Apart from the refactoring this commit takes the opportunity and removes
unnecessary read locks when choosing a package and a core from idle lists.
The data structures are accessed in a thread safe way and it does not really
matter whether the obtained data becomes outdated just when we release the
lock or during our search for the appropriate package/core.


# 9116eec2 19-Dec-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Allow calling UpdatePriority() for disabled CPU


# c08ed2db 19-Dec-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Try to keep thread on the same logical CPU

Some SMT implementations (e.g. recent AMD microarchitectures) have
separate L1d cache for each SMT thread (which AMD decides to call "cores").
This means that we shouldn't move threads to another logical processor too
often even if it belongs to the same core. We aren't very strict about
this as it would complicate load balancing, but we try to reduce unnecessary
migrations.


# 5a7289d7 17-Dec-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Fix unassigning threads from core being disabled


# 1b06228f 17-Dec-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Propagate scheduler modes to cpu{freq, idle} modules


# 4fcbac58 17-Dec-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Make get_cpu_topology() return a pointer to const

The client code is not supposed to change the topology info.
It would be also nice if cpu_topology_node::children was an array of
pointers to const but that would require several const_casts in the
topology tree generation code so it's probably not worth it.


# d287274d 05-Dec-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Code refactoring


# 255b6017 29-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Do not send reschedule ICI when not needed


# 2b7ea4cd 29-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Remove Thread::next_state


# c19f1e4f 29-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Add missing check for real time threads


# 07218997 28-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Allow mode to specify time slice length


# 7f8cf14b 28-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler, kernel/util: Fix style issues


# 1987bf19 28-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Update CPU disabling code to match recent changes


# 7b4befcd 28-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Introduce upper bound on latency


# f2243876 28-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Remove some unnecessary checks against idle threads


# f9ee217a 28-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Migrate threads less often in power saving mode


# 286b341a 28-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Merge two occurences of thread resume code


# 87115715 26-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Protect package data with rw_spinlock


# 9caf7f4f 26-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Update estimate_max_scheduling_latency()


# 7d7dc357 26-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Move simple inline functions to scheduler_common.h


# 28da7e98 26-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Improve debug commands


# 22ae68fa 26-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Simplify thread priority penalties


# b41eaf29 25-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler_set_thread_priority: Fix null dereference


# 35153d1c 25-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Send reschedule ICI after enqueueing the thread


# 26970784 24-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Clean scheduler_common.h

scheduler_common.h is now meant for types, variables and functions used
by both core scheduler code and implementations of scheduler modes.
Functions like switch_thread() and update_thread_times() do not belong
there anymore.


# 13a89839 24-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Fix power saving mode and other minor improvements


# f95b6fdf 24-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheudler: Do not include irq load in thread load


# 03f7d3d1 24-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Restore logical processor disabling


# 7c7b9b79 21-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Return time stolen by irq and ipi handlers


# 1a7eb502 21-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Calculate correct load on SMT processors


# 65741c8b 21-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Improve locking


# 6fb61d00 20-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Preallocate temporary heaps for debug commands


# 308f594e 20-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel, libroot: Make scheduler modes interface public


# cd1e7814 20-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Reduce scheduler mode lock cache bouncing


# ecfd4449 20-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Improve power saving mode

* Remove possibility to temporarily disable small task packing.
* When small task packing target gets overloaded continue packing
threads on another core, but avoid migrating the already packed
ones.

Scheduler still tends to needlessly migrate threads to another cores
when under heavier load, but it is now much better than before.


# c4ac37a3 20-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Try to pack IRQs in power saving mode


# 9c2e74da 20-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Move mode specific logic to separate files


# e2ff9a28 17-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Rebalance IRQs on overloaded cores


# 6a164daa 17-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Track load produced by interrupt handlers


# 288a2664 12-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Remove sSchedulerInternalLock

* pin idle threads to their specific CPUs
* allow scheduler to implement SMP_MSG_RESCHEDULE handler
* scheduler_set_thread_priority() reworked
* at reschedule: enqueue old thread after dequeueing the new one


# 72e1b394 12-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Fix gcc2 build


# 5f3a65e5 12-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Remove sCorePriorityHeap

sCorePriorityHeap was meant to be a temporary solution anyway. Thread
migration and assignment is now entirely based on core load.


# 829f8363 11-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Minor cleanup


# 8818c942 11-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Add {CPU,Core,Package}Entry constructors


# e1c40769 11-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Atomically access time and load measurements


# d17b71d6 11-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Reduce false sharing of per-CPU and per-core data


# 03fb2d88 07-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Remove gSchedulerLock

* Thread::scheduler_lock protects thread state, priority, etc.
* sThreadCreationLock protects thread creation and removal and list of
threads in team.
* Team::signal_lock and Team::time_lock protect list of threads in team
as well.
* Scheduler uses its own internal locking.


# d3e5752b 06-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Performance mode is actually low latency mode


# d8fcc8a8 30-Oct-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Remove B_TIMER_ACQUIRE_SCHEDULER_LOCK flag

The flag main purpose is to avoid race conditions between event handler
and cancel_timer(). However, cancel_timer() is safe even without
using gSchedulerLock.

If the event is scheduled to happen on other CPU than the CPU that
invokes cancel_timer() then cancel_timer() either disables the event
before its handler starts executing or waits until the event handler
is done.

If the event is scheduled on the same CPU that calls cancel_timer()
then, since cancel_timer() disables interrupts, the event is either
executed before cancel_timer() or when the timer interrupt handler
starts running the event is already disabled.


# 1e3cf82d 29-Oct-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Manage CPU performance


# 6d96f462 27-Oct-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Use load information to migrate threads


# 5e2701a2 27-Oct-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Keep track of the load each thread produces


# dc38e6ca 27-Oct-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Use core load to distribute threads


# d80cdf50 27-Oct-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Keep track of core and logical CPU load


# 890ba741 27-Oct-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Decide whether to cancel thread penalty


# 1df2e755 27-Oct-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Increase penalty of waiting threads

The fact that thread is waiting doesn't mean that it is nice to the others.
If the thread, indeed, waits for a longer time its penalty will be cancelled
anyway, however if the thread waits for a very short time do not count that
as being nice since lower priority threads didn't have much chance to run.


# 45ff5300 24-Oct-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Be more demanding when cancelling penalties


# 9d7e2acf 23-Oct-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Update scheduler_set_operation_mode()


# 978fc080 23-Oct-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Remove support for running different schedulers

Simple scheduler behaves exactly the same as affine scheduler with a
single core. Obviously, affine scheduler is more complicated thus
introduces greater overhead but quite a lot of multicore logic has been
disabled on single core systems in the previous commit.


# cf863a50 16-Oct-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Decide whether to use simple or affine scheduler

Simple scheduler is used when we do not have to worry about cache affinity
(i.e. single core with or without SMT, multicore with all cache levels
shared).

When we replace gSchedulerLock with more fine grained locking affine
scheduler should also be chosen when logical CPU count is high (regardless
of cache).


# 51d1e9ad 14-Oct-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Remove scheduler_simple_smp


# f20ad54b 14-Oct-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Add support for SMP systems to simple scheduler

In SMP systems simple scheduler will be used only when all logical
processors share all levels of cache and the number of CPUs is low.
In such systems we do not have to care about cache affinity and
the contention on the lock protecting shared run queue is low. Single
run queue makes load balancing very simple.


# 6d7e2912 05-Oct-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Allow scheduler initialization to fail


# 4be4fc6b 15-Jun-2012 Alex Smith <alex@alex-smith.me.uk>

More 64-bit compilation/safety fixes.


# 24df6592 11-Jun-2011 Ingo Weinhold <ingo_weinhold@gmx.de>

Merged signals-merge branch into trunk with the following changes:
* Reorganized the kernel locking related to threads and teams.
* We now discriminate correctly between process and thread signals. Signal
handlers have been moved to teams. Fixes #5679.
* Implemented real-time signal support, including signal queuing, SA_SIGINFO
support, sigqueue(), sigwaitinfo(), sigtimedwait(), waitid(), and the addition
of the real-time signal range. Closes #1935 and #2695.
* Gave SIGBUS a separate signal number. Fixes #6704.
* Implemented <time.h> clock and timer support, and fixed/completed alarm() and
[set]itimer(). Closes #5682.
* Implemented support for thread cancellation. Closes #5686.
* Moved send_signal() from <signal.h> to <OS.h>. Fixes #7554.
* Lots over smaller more or less related changes.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42116 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 4535495d 10-Jan-2011 Ingo Weinhold <ingo_weinhold@gmx.de>

Merged the signals branch into trunk, with these changes:
* The team and thread kernel structures have been renamed to Team and Thread
respectively and moved into the new BKernel namespace.
* Several (kernel add-on) sources have been converted from C to C++ since
private kernel headers are included that are no longer C compatible.

Changes after merging:
* Fixed gcc 2 build (warnings mainly in the scary firewire bus manager).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40196 a95241bf-73f2-0310-859d-f6bbb57e9c96


# f651548e 30-Apr-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

scheduler_reschedule_no_op(): panic() when the calling thread is not
continuing to run. This must not happen since the thread is the boot CPU's
idle thread performing the early kernel initialization (before the scheduler
is started).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36560 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 28d05e02 29-Apr-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Make scheduler_reschedule() an no-op until we're ready to start the
scheduler. This avoids the need to use the send_signal_etc() work-around for
resume_thread() during the early kernel initialization. Might fix #5851.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36530 a95241bf-73f2-0310-859d-f6bbb57e9c96


# ee0d2be9 11-Apr-2010 Axel Dörfler <axeld@pinc-software.de>

bonefish+axeld:
* Implemented a tiny bit more sophisticated version of
estimate_max_scheduling_latency() that uses a syscall that lets the scheduler
decide.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36170 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 022cdb9c 19-Dec-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

Fixed build with scheduler tracing enabled.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34714 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 3533b659 10-Dec-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

* Reintroduced the SMP_MSG_RESCHEDULE_IF_IDLE ICI message. This time
implemented by means of an additional member in cpu_ent.
* Removed thread::keep_scheduled and the related functions. The feature
wasn't used yet and wouldn't have worked as implemented anyway.
* Resurrected an older, SMP aware version of our simple scheduler and made it
the default instead of the affine scheduler. The latter is in no state to
be used yet. It causes enormous latencies (I've seen up to 0.1s) even when
six or seven CPUs were idle at the same time, totally killing parallelism.
That's also the reason why a -j8 build was slower than a -j2. This is no
longer the case. On my machine the -j2 build takes about 10% less time now
and the -j8 build saves another 20%. The latter is not particularly
impressive (compared with Linux), but that seems to be due to lock
contention.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34615 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 861b223c 21-Aug-2009 Michael Lotz <mmlr@mlotz.ch>

* Strip down scheduler_simple. Anything related to multiple CPU handling has
been removed. That includes CPU disabling and thread pinning, as that becomes
pointless with only one CPU.
* Return a proper reschedule hint on enqueing a thread, based on the priority
of the current thread vs. the enqueued one.
* Enable dynamic scheduler selection. With one CPU the simple scheduler will
be used, otherwise affine is selected.
* Removed the scheduler type define as we now always auto-select it.
* Some cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32573 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 009ccc29 20-Aug-2009 Rene Gollent <anevilyak@gmail.com>

anevilyak+mmlr:
* scheduler_enqueue_in_runqueue() now allows the scheduler to return a hint as to whether a reschedule is desirable or not. This is used in a few other places in order to relegate scheduling decisions entirely to the scheduler rather than the priority hacks previously used. There are probably other places in the kernel that could now make use of that information to more intelligently call reschedule() though.
* Switch over the default scheduler to scheduler_affine().



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32554 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 227fe7d3 23-Apr-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

* Scheduler/wait object listener:
- Moved scheduler listening interface to <listeners.h> and added more
convenient to use templatized notification functions.
- Added a listener mechanism for the wait objects (semaphores, condition
variables, mutex, rw_lock).
* system profiler:
- Hopefully fixed locking issues related to notifying the profiler thread
for good. We still had an inconsistent locking order, since the scheduler
notification callbacks are invoked with the thread lock held and have to
acquire the object lock then, while the other callbacks acquired the object
lock first and as a side effect of ConditionVariable::NotifyOne() acquired
the thread lock. Now we make sure the object lock is the innermost lock.
- Track the number of dropped events due to a full buffer.
_user_system_profiler_next_buffer() returns this count now.
- When scheduling profiling events are requested also listen to wait objects
and generate the respective profiling events. We send those events lazily
and cache the infos to avoid resending an event for the same wait object.
- When starting profiling we do now generate "thread scheduled" events for
the already running threads.
- _user_system_profiler_start(): Check whether the parameters pointer is a
userland address at all.
- The system_profiler_team_added event does now also contain the team's name.
* Added a sem_get_name_unsafe() returning a semaphore's name. It is "unsafe",
since the caller has to ensure that the semaphore exists and continues to
exist as long as the returned name is used.
* Adjusted the "profile" and "scheduling_recorder" according to the system
profiling changes. The latter prints the number of dropped events, now.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30345 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 79257a4a 18-Apr-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

Added a listener mechanism to the scheduler (ATM only for scheduler_simple).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30242 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 24fde47c 21-Mar-2009 Rene Gollent <anevilyak@gmail.com>

Introduce an experimental new scheduler intended to work fundamentally the same as our existing one, but with various optimizations to better handle the SMP case:
1) We now maintain a runqueue per CPU, rather than a single global shared queue. Idle threads are segregated into their own queue for simplicity.
2) Enqueueing threads is now somewhat more intelligent - if the thread is pinned, it is always enqueued onto that core. Otherwise we enqueue it on whichever CPU it previously ran, unless it either hasn't run before, or that core has been disabled via ProcessController. If so, we try to enqueue it on whichever core has been the most idle recently.
3) The above allow various simplifications to thread scheduling. Pinned threads and/or disabled cores are now no longer special cases that need to be dealt with. If a CPU has no threads ready, it looks for another one to steal a thread from, though that part still needs some tuning along with enqueueing for load balancing purposes.

The chief aim here is better load balancing and support for soft affinity. However, at the moment the overall behavior still exhibits some regressions compared to the old scheduler, so it's disabled by default. If you wish to experiment/debug with it, instructions for enabling it can be found in scheduler.cpp. Much thanks to Ingo, Axel and everyone who's helped with either code review/advice or testing so far.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29643 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 53892c92 20-Oct-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Replaced scheduler_remove_from_run_queue() by
scheduler_set_thread_priority(). Setting the thread priority was the
only situation in which it was used.
* Renamed scheduler.cpp to scheduler_simple.cpp.
* The scheduler functions are no longer called directly. Instead there's
an operation vector now, which is initialized at kernel init time.
This allows for picking the most suitable scheduler for the machine
(e.g. a non-SMP scheduler on a non-SMP machine).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28262 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 768036bb 20-Oct-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Moved scheduler.cpp into new subdirectory scheduler/. Moved the
scheduler tracing and scheduler analysis code into separate source
files.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28253 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 1bba129c56656a5c140fc8d1202ae1cac761d49b 08-Apr-2014 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Let ThreadData::ShouldRebalance() choose the actual core

Currently, ThreadData::ShouldRebalance() (and mode specific functions
it calls) only decides whether to migrate thread to another core or not.
However, in most cases it actually needs to find the best candidate for
new core so it could as well return that information.


# 230d1fcfeaedb4d034e3f03e1697957ca633e6ea 03-Feb-2014 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Update load of idle cores

In order to keep the scheduler tickless core load is computed and updated
only during various scheduler events (i.e. thread enqueue, reschedule, etc).
The problem it creates is that if a core becomes idle its load may remain
outdated for an extended period of time thus resulting in suboptimal thread
migration decisions.

The solution to this problem is to add a timer each time an idle thread is
scheudled which, after kLoadMeasureInterval, would fire and force load
update.


# f116370edda18472a248387a7256e2b4e528c666 30-Jan-2014 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Relax penalty cancellation requirements

Priority penalties were made more strict in order to prevent situation
when two or more high priority threads uses up all available CPU time
in such manner that they do not receive a penalty but starve low priority
threads.

However, a significant change to thread priorites has been made since and
now priority of all non real time threads varies in a range from 1 to
static priority minus penalty. This means that the scheduler is able to
prevent thread starvation without any complex penalty policies.


# 931ce674a9dfdc8f4a05bdb54fc21b207018f7a2 26-Jan-2014 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Fix core unassignment


# 7adce94d45a69dd1a8dece6d3324b9a0859e90b4 26-Jan-2014 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Check team user time timers before entering scheduler

User timers may cause another thread to become ready in which case we would
like this to happen before scheduler_reschedule() chooses next thread to
be executed.


# 0269dd284e334fef121a93547cf2a81e065109bb 16-Jan-2014 Pawel Dziepak <pdziepak@quarnos.org>

Revert "scheduler: SCHEDULER_EXIT_FUNCTION() is not needed"

This reverts commit 667617ad043a4587d8d366d5192d9ad291cfa37a.

Scheduler profiler uses CPU local data to store function information, hence
arch_thread_context_switch() usually is not a problem. However, when
we switch to a new thread we end up scheduler_new_thread_entry() instead
of scheduler_reschedule() what may corrupt data collected by the profiler.


# b7d404c2df546acbe91df76939005bab666dd71b 16-Jan-2014 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Add ThreadData::{GetPriority, IsIdle, IsRealTime}()


# 093c2202675b2ef2c9a76dec558fe6ed4a5e6f17 16-Jan-2014 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Improve latencies


# a2634874ed5e33a36fe83c272614e2042fafde1d 08-Jan-2014 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Estimate the load thread is able to produce

Previous implementation based on the actual load of each core and share
each thread has in that load turned up to be very problematic when
balancing load on very heavily loaded systems (i.e. more threads
consuming all available CPU time than there is logical CPUs).

The new approach is to estimate how much load would a thread produce
if it had all CPU time only for itself. Summing such load estimations
of each thread assigned to a given core we get a rank that contains
much more information than just simple actual core load.


# d36098e0430bdec4c5202673c3a8bff776dd03db 07-Jan-2014 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Keep track of the number of the ready threads


# 9c465cc83bbd40732475db43bd870221b99bdbb7 07-Jan-2014 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Improve recognition of CPU bound threads


# c2a02dee65184026ea953726a9ab1bac1c0a4617 06-Jan-2014 Pawel Dziepak <pdziepak@quarnos.org>

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.


# a5f45afa6c2f39d00951d01a0a4a2865b4b80059 05-Jan-2014 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Remove unnecessary check against disabled CPU


# 8235bbc9965b083b294b366ea5438d2ff274dbf7 05-Jan-2014 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Improve thread creation performance


# cb66faef24f64af40a51f23300ff546d975535b3 04-Jan-2014 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Work around GCC2 limitations in function inlining

GCC2 won't inline a function if it is used before its definition.


# 9e99bf6085a30c0fdb30234af1924007e6033494 03-Jan-2014 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: SCHEDULER_EXIT_FUNCTION() is not needed


# 81e04d7b9734081a6c3190b9b8bdab304dc0fe3e 03-Jan-2014 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Remove cpu_info::load

This field forces kernel to track each CPU load all the time. It is not
a problem with the current scheduler on a multicore systems, but on
single core machnies or with any other future scheduler this field may
become just an unnecessary burden. It isn't difficult for an application
to compute CPU load by itself when it needs it.


# e4ea637227d7cf9a53bc89317990b8a22a76780a 03-Jan-2014 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Disable load tracking when not needed


# db1ddabfd0121c18ab9d87e2047c6ff6e4d29653 30-Dec-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Thread can not stay on CPU if it has been disabled


# 265927509dc56e82b12cd68750ae1e96601fd558 30-Dec-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Protect per CPU run queue with its own lock


# 15a7f2046addd659e66d7614ac1e698a0aade255 29-Dec-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Return CPU load in cpu_info


# 56c0f467b028beb8b5104dd16f51373b20fad9e4 29-Dec-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Fix unused variable warnings


# 96dcc73b39cc68a59c276a35690f8af1886214ef 26-Dec-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Add scheduler profiler

A bit hackish implementation of a profiler for the scheduler.
SCHEDULER_ENTER_FUNCTION at the begining of each function aren't nice and
usage of __PRETTY_FUNCTION__ isn't any better (both gcc and clang support
it though), but it was quick to implement and doesn't lose information
on inlined functions. It's just a tool, not an integral part of the kernal
anyway.


# cf4984f64588ef80b96d573c0931c3517585c162 23-Dec-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Use precomputed time slice lengths


# b24ea642d759ad6e6b30007cb112b3cdfad35204 23-Dec-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Encapsulate ThreadData fields


# a08b40d4087b35c586959dc7da44035171d4cf15 23-Dec-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Encapsulate CPUEntry fields


# e1e7235c60d942d4fd58ac7caedf4a9715efcc7a 23-Dec-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Encapsulate CoreEntry fields


# 60e198f2cbf2e26b584370c0d32c37cb3dce556c 22-Dec-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Encapsulate PackageEntry fields

Apart from the refactoring this commit takes the opportunity and removes
unnecessary read locks when choosing a package and a core from idle lists.
The data structures are accessed in a thread safe way and it does not really
matter whether the obtained data becomes outdated just when we release the
lock or during our search for the appropriate package/core.


# 9116eec24c3a9e8be6ba721487fa29604fb5b944 19-Dec-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Allow calling UpdatePriority() for disabled CPU


# c08ed2db65267bea18a3ba424f98fffde9da6c25 19-Dec-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Try to keep thread on the same logical CPU

Some SMT implementations (e.g. recent AMD microarchitectures) have
separate L1d cache for each SMT thread (which AMD decides to call "cores").
This means that we shouldn't move threads to another logical processor too
often even if it belongs to the same core. We aren't very strict about
this as it would complicate load balancing, but we try to reduce unnecessary
migrations.


# 5a7289d7209b101262421c6263a4efe1236e1d04 17-Dec-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Fix unassigning threads from core being disabled


# 1b06228f136128b8094c8a7d954815e29775cfe4 17-Dec-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Propagate scheduler modes to cpu{freq, idle} modules


# 4fcbac58de122ff3313cb0bfe9115314d28bf219 17-Dec-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Make get_cpu_topology() return a pointer to const

The client code is not supposed to change the topology info.
It would be also nice if cpu_topology_node::children was an array of
pointers to const but that would require several const_casts in the
topology tree generation code so it's probably not worth it.


# d287274dcec634da4973a1b92c97dd14d7c5ecd0 05-Dec-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Code refactoring


# 255b6017502aa4548d14bff5d0b366b0f266b833 29-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Do not send reschedule ICI when not needed


# 2b7ea4cddf362859cd3089e3cb95481cda4adc5f 29-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Remove Thread::next_state


# c19f1e4fbb379d6a6456d6cbaa4f09033274de18 29-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Add missing check for real time threads


# 072189970913d3cce35c34b4307b5e58b0f241b5 28-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Allow mode to specify time slice length


# 7f8cf14b711fae638e2c089afb9513461513100f 28-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler, kernel/util: Fix style issues


# 1987bf19b57e2789bbf4cc736f81cfa803a62af2 28-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Update CPU disabling code to match recent changes


# 7b4befcd47d4a7ee56d50b40a41cf79aa23cf7c6 28-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Introduce upper bound on latency


# f2243876dfa5c8543ca031d685a9d403d292757a 28-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Remove some unnecessary checks against idle threads


# f9ee217ad6c59122fefd39a445c99f2c0fb2af1e 28-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Migrate threads less often in power saving mode


# 286b341a400e8d12060a8be52214618b8f02df87 28-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Merge two occurences of thread resume code


# 87115715b40c394b08de08b6709863eb257b020d 26-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Protect package data with rw_spinlock


# 9caf7f4fb95b33daa9e2caf2267c2636ba24ce49 26-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Update estimate_max_scheduling_latency()


# 7d7dc357bf0966b28dce9e0f08bff04353be7098 26-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Move simple inline functions to scheduler_common.h


# 28da7e985fd8463ec31ce9ebbb4b9610b361f8be 26-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Improve debug commands


# 22ae68fa692c4dd82e53001ace5f071f1b209fe8 26-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Simplify thread priority penalties


# b41eaf299a3d74bbcd6e496dfda0d0d9d9978eac 25-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler_set_thread_priority: Fix null dereference


# 35153d1c49c6b0bb3858c24e8824cbc834973c07 25-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Send reschedule ICI after enqueueing the thread


# 26970784cd0050d72a1bb96eccd027dfc2769ffb 24-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Clean scheduler_common.h

scheduler_common.h is now meant for types, variables and functions used
by both core scheduler code and implementations of scheduler modes.
Functions like switch_thread() and update_thread_times() do not belong
there anymore.


# 13a89839fc09fea7d328568ddb76d8369ce2839d 24-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Fix power saving mode and other minor improvements


# f95b6fdfc84784fd24255fff8a492b877a26cbfd 24-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheudler: Do not include irq load in thread load


# 03f7d3d1db10c0a467bea944fb3230ee70c6e015 24-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Restore logical processor disabling


# 7c7b9b795bbb537b889e96e335dd9a4add8b2789 21-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Return time stolen by irq and ipi handlers


# 1a7eb50254e1cee8160de17253aa6972c3d960cf 21-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Calculate correct load on SMT processors


# 65741c8b56b2fc74e8e1cd419b92f799e75f556d 21-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Improve locking


# 6fb61d001a6022e27892cc643f345541c4e954dc 20-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Preallocate temporary heaps for debug commands


# 308f594e2a5d3674bd019a7620e193ab0a845e6f 20-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel, libroot: Make scheduler modes interface public


# cd1e7814a92caa9060f161e2c910f9d42b92ab9e 20-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Reduce scheduler mode lock cache bouncing


# ecfd44493554c78001bbe001d35637b7eab0ffb6 20-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Improve power saving mode

* Remove possibility to temporarily disable small task packing.
* When small task packing target gets overloaded continue packing
threads on another core, but avoid migrating the already packed
ones.

Scheduler still tends to needlessly migrate threads to another cores
when under heavier load, but it is now much better than before.


# c4ac37a35e449a07393867fed7278f377cca8dbf 20-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Try to pack IRQs in power saving mode


# 9c2e74da043b32ecd64a0ec4f4917f83ac6cc10f 20-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Move mode specific logic to separate files


# e2ff9a2865beeabed2dbe7cc2b975b377cd12087 17-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Rebalance IRQs on overloaded cores


# 6a164daad43169daf0a407fb1f6b0484671ff466 17-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Track load produced by interrupt handlers


# 288a2664a2de429f159d746beaab87373184cd3d 12-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Remove sSchedulerInternalLock

* pin idle threads to their specific CPUs
* allow scheduler to implement SMP_MSG_RESCHEDULE handler
* scheduler_set_thread_priority() reworked
* at reschedule: enqueue old thread after dequeueing the new one


# 72e1b394a40aa34fd93fc83e9137dfbe48a0e34e 12-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Fix gcc2 build


# 5f3a65e5780002f8a4acf814a1b3347e95e65bd2 12-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Remove sCorePriorityHeap

sCorePriorityHeap was meant to be a temporary solution anyway. Thread
migration and assignment is now entirely based on core load.


# 829f83632457377650eaf92309fbc856a2276e34 11-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Minor cleanup


# 8818c942dd31f098825c6230b90515b688d110cf 11-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Add {CPU,Core,Package}Entry constructors


# e1c40769d32886085323e58a9cc270bc09383e32 11-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Atomically access time and load measurements


# d17b71d6b02775bb918b340c5bbaaa39320dfc53 11-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Reduce false sharing of per-CPU and per-core data


# 03fb2d886830e4dd4b344c56725db59f96733216 07-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Remove gSchedulerLock

* Thread::scheduler_lock protects thread state, priority, etc.
* sThreadCreationLock protects thread creation and removal and list of
threads in team.
* Team::signal_lock and Team::time_lock protect list of threads in team
as well.
* Scheduler uses its own internal locking.


# d3e5752b112000b3722d744259be44fa8438cfe7 06-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Performance mode is actually low latency mode


# d8fcc8a82519cef977c689cee497316be6f1531f 30-Oct-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Remove B_TIMER_ACQUIRE_SCHEDULER_LOCK flag

The flag main purpose is to avoid race conditions between event handler
and cancel_timer(). However, cancel_timer() is safe even without
using gSchedulerLock.

If the event is scheduled to happen on other CPU than the CPU that
invokes cancel_timer() then cancel_timer() either disables the event
before its handler starts executing or waits until the event handler
is done.

If the event is scheduled on the same CPU that calls cancel_timer()
then, since cancel_timer() disables interrupts, the event is either
executed before cancel_timer() or when the timer interrupt handler
starts running the event is already disabled.


# 1e3cf82d8584947cc10c0c9ac3aa23ccbea5ca4e 29-Oct-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Manage CPU performance


# 6d96f462dcea05a929f52e0c45aa5a2ff1efb9ae 27-Oct-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Use load information to migrate threads


# 5e2701a2b50591b76e8981935ceea0e7e07573ea 27-Oct-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Keep track of the load each thread produces


# dc38e6ca871a7da1b033fb0c027950e6ca53ab24 27-Oct-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Use core load to distribute threads


# d80cdf504fe9db6f6f7be62fd456ccdae4ea9178 27-Oct-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Keep track of core and logical CPU load


# 890ba7415c79c371440981da45a96b3b3476b414 27-Oct-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Decide whether to cancel thread penalty


# 1df2e75540af9a6331fcf0914719c4b3d71ee551 27-Oct-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Increase penalty of waiting threads

The fact that thread is waiting doesn't mean that it is nice to the others.
If the thread, indeed, waits for a longer time its penalty will be cancelled
anyway, however if the thread waits for a very short time do not count that
as being nice since lower priority threads didn't have much chance to run.


# 45ff5300693f788a134f62eaa5f5982413cd10ec 24-Oct-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Be more demanding when cancelling penalties


# 9d7e2acf34add493940b0a0bbd0986d018033201 23-Oct-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Update scheduler_set_operation_mode()


# 978fc080654a2367cfb75a8afa196361ab56645e 23-Oct-2013 Pawel Dziepak <pdziepak@quarnos.org>

scheduler: Remove support for running different schedulers

Simple scheduler behaves exactly the same as affine scheduler with a
single core. Obviously, affine scheduler is more complicated thus
introduces greater overhead but quite a lot of multicore logic has been
disabled on single core systems in the previous commit.


# cf863a50401af89883ea314ccf54e16badd9439e 16-Oct-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Decide whether to use simple or affine scheduler

Simple scheduler is used when we do not have to worry about cache affinity
(i.e. single core with or without SMT, multicore with all cache levels
shared).

When we replace gSchedulerLock with more fine grained locking affine
scheduler should also be chosen when logical CPU count is high (regardless
of cache).


# 51d1e9ada0e963b344954f7d6b7e94399197eeaf 14-Oct-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Remove scheduler_simple_smp


# f20ad54be26d164713bd06dab0435cee985561ef 14-Oct-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Add support for SMP systems to simple scheduler

In SMP systems simple scheduler will be used only when all logical
processors share all levels of cache and the number of CPUs is low.
In such systems we do not have to care about cache affinity and
the contention on the lock protecting shared run queue is low. Single
run queue makes load balancing very simple.


# 6d7e2912332e6f40dda0724eff35d99ecdcc8371 05-Oct-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Allow scheduler initialization to fail


# 4be4fc6b1faddbd037146214a0011d320842b4f3 15-Jun-2012 Alex Smith <alex@alex-smith.me.uk>

More 64-bit compilation/safety fixes.


# 24df65921befcd0ad0c5c7866118f922da61cb96 11-Jun-2011 Ingo Weinhold <ingo_weinhold@gmx.de>

Merged signals-merge branch into trunk with the following changes:
* Reorganized the kernel locking related to threads and teams.
* We now discriminate correctly between process and thread signals. Signal
handlers have been moved to teams. Fixes #5679.
* Implemented real-time signal support, including signal queuing, SA_SIGINFO
support, sigqueue(), sigwaitinfo(), sigtimedwait(), waitid(), and the addition
of the real-time signal range. Closes #1935 and #2695.
* Gave SIGBUS a separate signal number. Fixes #6704.
* Implemented <time.h> clock and timer support, and fixed/completed alarm() and
[set]itimer(). Closes #5682.
* Implemented support for thread cancellation. Closes #5686.
* Moved send_signal() from <signal.h> to <OS.h>. Fixes #7554.
* Lots over smaller more or less related changes.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42116 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 4535495d80c86e19e2610e7444a4fcefe3e0f8e6 10-Jan-2011 Ingo Weinhold <ingo_weinhold@gmx.de>

Merged the signals branch into trunk, with these changes:
* The team and thread kernel structures have been renamed to Team and Thread
respectively and moved into the new BKernel namespace.
* Several (kernel add-on) sources have been converted from C to C++ since
private kernel headers are included that are no longer C compatible.

Changes after merging:
* Fixed gcc 2 build (warnings mainly in the scary firewire bus manager).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40196 a95241bf-73f2-0310-859d-f6bbb57e9c96


# f651548ee600e131a95d82fa21859bd7a9860b37 30-Apr-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

scheduler_reschedule_no_op(): panic() when the calling thread is not
continuing to run. This must not happen since the thread is the boot CPU's
idle thread performing the early kernel initialization (before the scheduler
is started).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36560 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 28d05e026f982a3b5fef1545d1b508d847410f80 29-Apr-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Make scheduler_reschedule() an no-op until we're ready to start the
scheduler. This avoids the need to use the send_signal_etc() work-around for
resume_thread() during the early kernel initialization. Might fix #5851.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36530 a95241bf-73f2-0310-859d-f6bbb57e9c96


# ee0d2be9e44bc80bd060f2ad24fbf29d8d449250 11-Apr-2010 Axel Dörfler <axeld@pinc-software.de>

bonefish+axeld:
* Implemented a tiny bit more sophisticated version of
estimate_max_scheduling_latency() that uses a syscall that lets the scheduler
decide.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36170 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 022cdb9ce3cab5b489038c5b93caa25a42697cf1 19-Dec-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

Fixed build with scheduler tracing enabled.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34714 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 3533b6597db4ad65493632da8a92c1f6ea3de149 10-Dec-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

* Reintroduced the SMP_MSG_RESCHEDULE_IF_IDLE ICI message. This time
implemented by means of an additional member in cpu_ent.
* Removed thread::keep_scheduled and the related functions. The feature
wasn't used yet and wouldn't have worked as implemented anyway.
* Resurrected an older, SMP aware version of our simple scheduler and made it
the default instead of the affine scheduler. The latter is in no state to
be used yet. It causes enormous latencies (I've seen up to 0.1s) even when
six or seven CPUs were idle at the same time, totally killing parallelism.
That's also the reason why a -j8 build was slower than a -j2. This is no
longer the case. On my machine the -j2 build takes about 10% less time now
and the -j8 build saves another 20%. The latter is not particularly
impressive (compared with Linux), but that seems to be due to lock
contention.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34615 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 861b223cf2fa057c1bf0c6bc8e703ab4b30177dd 21-Aug-2009 Michael Lotz <mmlr@mlotz.ch>

* Strip down scheduler_simple. Anything related to multiple CPU handling has
been removed. That includes CPU disabling and thread pinning, as that becomes
pointless with only one CPU.
* Return a proper reschedule hint on enqueing a thread, based on the priority
of the current thread vs. the enqueued one.
* Enable dynamic scheduler selection. With one CPU the simple scheduler will
be used, otherwise affine is selected.
* Removed the scheduler type define as we now always auto-select it.
* Some cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32573 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 009ccc29623e2b54f3e881739754c5cea121e7d6 20-Aug-2009 Rene Gollent <anevilyak@gmail.com>

anevilyak+mmlr:
* scheduler_enqueue_in_runqueue() now allows the scheduler to return a hint as to whether a reschedule is desirable or not. This is used in a few other places in order to relegate scheduling decisions entirely to the scheduler rather than the priority hacks previously used. There are probably other places in the kernel that could now make use of that information to more intelligently call reschedule() though.
* Switch over the default scheduler to scheduler_affine().



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32554 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 227fe7d34aeed45d0727a0abde2ea2309352983b 23-Apr-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

* Scheduler/wait object listener:
- Moved scheduler listening interface to <listeners.h> and added more
convenient to use templatized notification functions.
- Added a listener mechanism for the wait objects (semaphores, condition
variables, mutex, rw_lock).
* system profiler:
- Hopefully fixed locking issues related to notifying the profiler thread
for good. We still had an inconsistent locking order, since the scheduler
notification callbacks are invoked with the thread lock held and have to
acquire the object lock then, while the other callbacks acquired the object
lock first and as a side effect of ConditionVariable::NotifyOne() acquired
the thread lock. Now we make sure the object lock is the innermost lock.
- Track the number of dropped events due to a full buffer.
_user_system_profiler_next_buffer() returns this count now.
- When scheduling profiling events are requested also listen to wait objects
and generate the respective profiling events. We send those events lazily
and cache the infos to avoid resending an event for the same wait object.
- When starting profiling we do now generate "thread scheduled" events for
the already running threads.
- _user_system_profiler_start(): Check whether the parameters pointer is a
userland address at all.
- The system_profiler_team_added event does now also contain the team's name.
* Added a sem_get_name_unsafe() returning a semaphore's name. It is "unsafe",
since the caller has to ensure that the semaphore exists and continues to
exist as long as the returned name is used.
* Adjusted the "profile" and "scheduling_recorder" according to the system
profiling changes. The latter prints the number of dropped events, now.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30345 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 79257a4ad6d56bc5283b11708be63ced4f136ab0 18-Apr-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

Added a listener mechanism to the scheduler (ATM only for scheduler_simple).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30242 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 24fde47c7a34e4d5088ef52efbe0c6a14ea3f65b 21-Mar-2009 Rene Gollent <anevilyak@gmail.com>

Introduce an experimental new scheduler intended to work fundamentally the same as our existing one, but with various optimizations to better handle the SMP case:
1) We now maintain a runqueue per CPU, rather than a single global shared queue. Idle threads are segregated into their own queue for simplicity.
2) Enqueueing threads is now somewhat more intelligent - if the thread is pinned, it is always enqueued onto that core. Otherwise we enqueue it on whichever CPU it previously ran, unless it either hasn't run before, or that core has been disabled via ProcessController. If so, we try to enqueue it on whichever core has been the most idle recently.
3) The above allow various simplifications to thread scheduling. Pinned threads and/or disabled cores are now no longer special cases that need to be dealt with. If a CPU has no threads ready, it looks for another one to steal a thread from, though that part still needs some tuning along with enqueueing for load balancing purposes.

The chief aim here is better load balancing and support for soft affinity. However, at the moment the overall behavior still exhibits some regressions compared to the old scheduler, so it's disabled by default. If you wish to experiment/debug with it, instructions for enabling it can be found in scheduler.cpp. Much thanks to Ingo, Axel and everyone who's helped with either code review/advice or testing so far.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29643 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 53892c92a02939d7e657f4fbb9563bc692716318 20-Oct-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Replaced scheduler_remove_from_run_queue() by
scheduler_set_thread_priority(). Setting the thread priority was the
only situation in which it was used.
* Renamed scheduler.cpp to scheduler_simple.cpp.
* The scheduler functions are no longer called directly. Instead there's
an operation vector now, which is initialized at kernel init time.
This allows for picking the most suitable scheduler for the machine
(e.g. a non-SMP scheduler on a non-SMP machine).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28262 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 768036bb6eff60aa41a27d0aff463384c932d364 20-Oct-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Moved scheduler.cpp into new subdirectory scheduler/. Moved the
scheduler tracing and scheduler analysis code into separate source
files.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28253 a95241bf-73f2-0310-859d-f6bbb57e9c96