History log of /haiku/headers/private/kernel/smp.h
Revision Date Author Comments
# 8be37ed4 23-Nov-2021 Augustin Cavalier <waddlesplash@gmail.com>

kernel/smp: Avoid casting spinlocks, which are structures.

The lock entry is the first thing in the struct, so this is a no-op
change, but it is safer to do in case of changes, of course.

Spinlocks have been structures for quite a long time, so this was
probably just missed in the conversion.


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

kernel/smp: add call_single_cpu()

to call a function on the target cpu. Early mechanism not available.

Change-Id: I9d049e618c319c59729d1ab53fb313b748f82315
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3212
Reviewed-by: Axel Dörfler <axeld@pinc-software.de>


# 6b83d77f 09-Dec-2018 Augustin Cavalier <waddlesplash@gmail.com>

smp: Make {acquire|release}_read_seqlock_inline cast explicitly.

Also fix braces.


# 82bcd89b 23-Jan-2014 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Add CPUSet::{Clear, Set}BitAtomic() functions


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

kernel: Fix ABA problem in try_acquire_read_spinlock()


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

kernel/x86: Inline atomic functions and memory barriers


# 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.


# 3e0e3be7 06-Dec-2013 Pawel Dziepak <pdziepak@quarnos.org>

boot, kernel: Replace MAX_BOOT_CPUS with SMP_MAX_CPUS


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

kernel: Fix gcc2 build


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

x86/paging: Use CPUSet instead of cpu_mask_t


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

kernel: Use CPUSet in ICI code instead of cpu_mask_t


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

kernel: smp_cpu_rendezvous(): Use counter instead of bitmap


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

kernel: Improve rw_spinlock implementation

* Add more debug checks
* Reduce the number of executed instructions that lock the bus.


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

kernel: Add read write spinlock implementation


# 273f2f38 05-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Improve spinlock implementation

atomic_or() and atomic_and() are not supported by x86 are need to be
emulated using CAS. Use atomic_get_and_set() and atomic_set() instead.


# 077c84eb 05-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: atomic_*() functions rework

* No need for the atomically changed variables to be declared as
volatile.
* Drop support for atomically getting and setting unaligned data.
* Introduce atomic_get_and_set[64]() which works the same as
atomic_set[64]() used to. atomic_set[64]() does not return the
previous value anymore.


# 4824f763 04-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Add sequential lock implementation


# 7ea42e7a 20-Oct-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Remove invoke_scheduler_if_idle


# 11d3892d 14-Jun-2012 Alex Smith <alex@alex-smith.me.uk>

Changed ICI data argument types from uint32 to addr_t.

Since ICI arguments are used to send addresses in some places, uint32 is
not sufficient on x86_64. addr_t still refers to the same type as uint32
(unsigned long) on other platforms, so this change only really affects
x86_64.


# dc3ba981 13-Jun-2011 Ingo Weinhold <ingo_weinhold@gmx.de>

Added try_acquire_spinlock().


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


# 07655104 26-Nov-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Eliminated _acquire_spinlock(). Since the macro is defined after
acquire_spinlock_inline(), there's actually no undesired recursion.


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


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

Added a rendez-vous variable parameter to smp_trap_non_boot_cpus() and make
boot CPU wait until all other CPUs are ready to wait. This solves a
theoretical problem in main(): The boot CPU could run fully through the early
initialization and reset sCpuRendezvous2 before the other CPUs left
smp_cpu_rendezvous(). It's very unlikely on real hardware that the non-boot
CPUs are so much slower, but it might be a concern in emulation.


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


# 3fb2a94d 11-Jan-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

* Inline {acquire,release}_spinlock(), when spinlock debugging is disabled.
* Use atomic_{and,or}() instead of atomic_set(), as there are no built-ins
for the latter.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35021 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


# 29bd9bfd 21-Aug-2009 Michael Lotz <mmlr@mlotz.ch>

Remove SMP_MSG_RESCHEDULE_IF_IDLE as it is not used anymore.


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


# 152132f0 18-Aug-2009 Michael Lotz <mmlr@mlotz.ch>

mmlr+anevilyak:
* Keep track of the currently running threads.
* Make use of that info to decide if a thread that becomes ready should preempt
the running thread.
* If we should preempt we send the target CPU a reschedule message.
* This preemption strategy makes keeping track of idle CPUs by means of a bitmap
superflous and it is therefore removed.
* Right now only other CPUs are preempted though, not the current one.
* Add missing initialization of the quantum tracking code.
* Do not extend the quantum of the idle thread based quantum tracking as we want
it to not run longer than necessary. Once the preemption works completely
adding a quantum timer for the idle thread will become unnecessary though.
* Fix thread stealing code, it did missed the last thread in the run queue.
* When stealing, try to steal the highest priority thread that is currently
waiting by taking priorities into account when finding the target run queue.
* Simplify stealing code a bit as well.
* Minor cleanups.


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


# 671a2442 31-Jul-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

More work towards making our double fault handler less triple fault prone:
* SMP:
- Added smp_send_broadcast_ici_interrupts_disabled(), which is basically
equivalent to smp_send_broadcast_ici(), but is only called with interrupts
disabled and gets the CPU index, so it doesn't have to use
smp_get_current_cpu() (which dereferences the current thread).
- Added cpu index parameter to smp_intercpu_int_handler().
* x86:
- arch_int.c -> arch_int.cpp
- Set up an IDT per CPU. We were using a single IDT for all CPUs, but that
can't work, since we need different tasks for the double fault interrupt
vector.
- Set the per CPU double fault task gates correctly.
- Renamed set_intr_gate() to set_interrupt_gate and set_system_gate() to
set_trap_gate() and documented them a bit.
- Renamed double_fault_exception() x86_double_fault_exception() and fixed
it not to use smp_get_current_cpu(). Instead we have the new
x86_double_fault_get_cpu() that deducts the CPU index from the used stack.
- Fixed the double_fault interrupt handler: It no longer calls int_bottom to
avoid accessing the current thread.
* debug.cpp:
- Introduced explicit debug_double_fault() to enter the kernel debugger from
a double fault handler.
- Avoid using smp_get_current_cpu().
- Don't use kprintf() before sDebuggerOnCPU is set. Otherwise
acquire_spinlock() is invoked by arch_debug_serial_puts().

Things look a bit better when the current thread pointer is broken -- we run
into kernel_debugger_loop() and successfully print the "Welcome to KDL"
message -- but we still dereference the thread pointer afterwards, so that we
don't get a usable kernel debugger yet.


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


# 7ab39de9 17-Oct-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Removed unused SMP_MSG_RESCHEDULE ICI message.
* Introduced flag "invoke_scheduler" in the per CPU structure. It is
evaluated in hardware_interrupt() (x86 only ATM).
* Introduced SMP_MSG_RESCHEDULE_IF_IDLE message, which enters the
scheduler when the CPU currently runs an idle thread.
* Don't do dprintf() "CPU x halted!" when handling a SMP_MSG_CPU_HALT
ICI message. It uses nested spinlocks and could thus potentially
deadlock itself (acquire_spinlock() processes ICI messages, so it
could already hold one of the locks). This is a pretty likely scenario
on machines with more than two CPUs, but is also possible when the
panic()ing thread holds the threads spinlock. Probably fixes #2572.
* Reworked the way the kernel debugger is entered and added a "cpu"
command that allows switching the CPU once in KDL. It is thus possible
to get a stack trace of the thread not on the panic()ing CPU.
* When a thread is added to the run queue, we do now check, if another
CPU is idle and ask it to reschedule, if it is. Before this change, the
CPU was continuing to idle until the quantum of the idle thread
expired. Speeds up the libbe.so build about 8% on my machine (haven't
tested the full Haiku image build yet).
* When spinlock debugging is enabled (DEBUG_SPINLOCKS) we also record
the spinlock acquirer on non-smp machines. Added "spinlock" debugger
command to get the info.
* Added debugger commands "ici" and "ici_message", printing info on
pending ICI message respectively on a given one.
* Process not only a single ICI message in acquire_spinlock() and other
places, but all pending ones.
* Also process ICI messages when waiting for a free one -- avoids a
potential deadlock.
* Mask out non-existing CPUs in send_multicast_ici(). panic() instead of
just returning when there's no target CPU left.


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


# 6bbe7eb8 07-Oct-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* smp.c -> smp.cpp
* Added smp_send_multicast_ici(), which sends the message to all CPUs
specified via a mask.


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


# 1c8de858 01-Jun-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Added optional spinlock contention measurement feature. Enabled when
B_DEBUG_SPINLOCK_CONTENTION is defined to 1. It typedefs spinlock to a
structure (thus breaking BeOS binary compatibility), containing a
counter which is incremented whenever a thread has to wait for the
spinlock.
* Added macros for spinlock initialization and access and changed
code using spinlocks accordingly. This breaks compilation for BeOS --
the macros should be defined in the respective compatibility wrappers.
* Added generic syscall to get the spinlock counters for the thread and
the team spinlocks.


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


# 00988673 01-Mar-2007 Travis Geiselbrecht <geist@foobox.com>

this seems to solve the 'lock up on bootup on core 2' problem.
Basically, there was a pretty subtle race between the cpus in main where if the main cpu released the AP cpus and then before the AP cpus had a chance to run the boot cpu started creating the main thread (which causes smp ici messages to be created) the system would livelock, where the boot cpu waited forever for the AP cpu to acknowledge the ICI (for a TLB flush when creating the kernel stack).
Added smp_cpu_rendezvous(), used to synchronize all the cpus to a particular point, and used it a few times in main().
While i was at it i fixed another race that'll probably never happen, but what the hey. Make sure the kernel args are copied into kernel space by the main cpu before letting any other ones use it.


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


# e0e9a3e6 14-Dec-2005 Axel Dörfler <axeld@pinc-software.de>

* We now support the global page feature of x86 processors that prevents
kernel TLBs from being flushed on context switch.
* new arch_cpu_user_TLB_invalidate() that now does what arch_cpu_global_TLB_invalidate()
did before.
* arch_cpu_global_TLB_invalidate() will now flush all TLBs, even those from the
kernel.
* some cleanups.


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


# ef7bac18 25-Oct-2005 Axel Dörfler <axeld@pinc-software.de>

Implemented call_all_cpus(), and get_cpuid() properly (tested only the latter, though).
The "data_ptr" parameter is now only freed if you specify SMP_MSG_FLAG_FREE_ARG
when sending the ICI message.


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


# 6cd505ce 25-Oct-2005 Axel Dörfler <axeld@pinc-software.de>

Changed the boot procedure a bit.
Extracted scheduler_init() from start_scheduler() (which is now called scheduler_start()).
Moved scheduler related function prototypes from thread.h to the new scheduler.h.
Cleanup.


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


# 74b043d9 17-Mar-2005 Axel Dörfler <axeld@pinc-software.de>

Removed execute property that was set accidently (since CVS days).


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


# 4a2e872c 14-Mar-2004 Axel Dörfler <axeld@pinc-software.de>

Applied NewOS change 1914: moved APIC setup into the kernel due to a
problem with the APIC clock speed test.


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


# a2b6866f 14-Mar-2004 Axel Dörfler <axeld@pinc-software.de>

Fixed compilation without having included boot/kernel_args.h.


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


# 564cba31 03-May-2003 Axel Dörfler <axeld@pinc-software.de>

Some header work: removed unnecessary dependencies to stage2.h, fixed
some broken C++ export definitions, added missing licenses etc.


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


# 5cdacbaa 26-Oct-2002 lillo <lillo@nowhere.fake>

*LOTS* of small changes to make the kernel compatible with Be's KernelExport.h


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


# 52a38012 08-Jul-2002 ejakowatz <ejakowatz@nowhere.fake>

It is accomplished ...


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


# 82bcd89b92f9c7934845782a1e34f433d51d2f9c 23-Jan-2014 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Add CPUSet::{Clear, Set}BitAtomic() functions


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

kernel: Fix ABA problem in try_acquire_read_spinlock()


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

kernel/x86: Inline atomic functions and memory barriers


# 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.


# 3e0e3be7604ed12ab61b58789c44bc6d7333f48b 06-Dec-2013 Pawel Dziepak <pdziepak@quarnos.org>

boot, kernel: Replace MAX_BOOT_CPUS with SMP_MAX_CPUS


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

kernel: Fix gcc2 build


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

x86/paging: Use CPUSet instead of cpu_mask_t


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

kernel: Use CPUSet in ICI code instead of cpu_mask_t


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

kernel: smp_cpu_rendezvous(): Use counter instead of bitmap


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

kernel: Improve rw_spinlock implementation

* Add more debug checks
* Reduce the number of executed instructions that lock the bus.


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

kernel: Add read write spinlock implementation


# 273f2f38cd4b219ac8197888962d0710c149d606 05-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Improve spinlock implementation

atomic_or() and atomic_and() are not supported by x86 are need to be
emulated using CAS. Use atomic_get_and_set() and atomic_set() instead.


# 077c84eb27b25430428d356f3d13afabc0cc0d13 05-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: atomic_*() functions rework

* No need for the atomically changed variables to be declared as
volatile.
* Drop support for atomically getting and setting unaligned data.
* Introduce atomic_get_and_set[64]() which works the same as
atomic_set[64]() used to. atomic_set[64]() does not return the
previous value anymore.


# 4824f7630b2ca9c5750f93c4daa837dfcac3059e 04-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Add sequential lock implementation


# 7ea42e7addccef196b840aa5e4921adfe13be44d 20-Oct-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Remove invoke_scheduler_if_idle


# 11d3892d285a72e161f5b13365dcce6e05a32374 14-Jun-2012 Alex Smith <alex@alex-smith.me.uk>

Changed ICI data argument types from uint32 to addr_t.

Since ICI arguments are used to send addresses in some places, uint32 is
not sufficient on x86_64. addr_t still refers to the same type as uint32
(unsigned long) on other platforms, so this change only really affects
x86_64.


# dc3ba981d47a9ed00cf02cffee5c9ae08a752696 13-Jun-2011 Ingo Weinhold <ingo_weinhold@gmx.de>

Added try_acquire_spinlock().


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


# 07655104d58ba54837514d07eae7e9d9a651368b 26-Nov-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Eliminated _acquire_spinlock(). Since the macro is defined after
acquire_spinlock_inline(), there's actually no undesired recursion.


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


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

Added a rendez-vous variable parameter to smp_trap_non_boot_cpus() and make
boot CPU wait until all other CPUs are ready to wait. This solves a
theoretical problem in main(): The boot CPU could run fully through the early
initialization and reset sCpuRendezvous2 before the other CPUs left
smp_cpu_rendezvous(). It's very unlikely on real hardware that the non-boot
CPUs are so much slower, but it might be a concern in emulation.


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


# 3fb2a94dfb528d9fc0640e60cf632da1f7d8e354 11-Jan-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

* Inline {acquire,release}_spinlock(), when spinlock debugging is disabled.
* Use atomic_{and,or}() instead of atomic_set(), as there are no built-ins
for the latter.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35021 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


# 29bd9bfd7df23f442fcd3ab4f5ba484cf35dfef3 21-Aug-2009 Michael Lotz <mmlr@mlotz.ch>

Remove SMP_MSG_RESCHEDULE_IF_IDLE as it is not used anymore.


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


# 152132f08ac3f84228ea7d94513a28eb137229a3 18-Aug-2009 Michael Lotz <mmlr@mlotz.ch>

mmlr+anevilyak:
* Keep track of the currently running threads.
* Make use of that info to decide if a thread that becomes ready should preempt
the running thread.
* If we should preempt we send the target CPU a reschedule message.
* This preemption strategy makes keeping track of idle CPUs by means of a bitmap
superflous and it is therefore removed.
* Right now only other CPUs are preempted though, not the current one.
* Add missing initialization of the quantum tracking code.
* Do not extend the quantum of the idle thread based quantum tracking as we want
it to not run longer than necessary. Once the preemption works completely
adding a quantum timer for the idle thread will become unnecessary though.
* Fix thread stealing code, it did missed the last thread in the run queue.
* When stealing, try to steal the highest priority thread that is currently
waiting by taking priorities into account when finding the target run queue.
* Simplify stealing code a bit as well.
* Minor cleanups.


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


# 671a2442d93f46c5343ef34e01306befa760c16a 31-Jul-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

More work towards making our double fault handler less triple fault prone:
* SMP:
- Added smp_send_broadcast_ici_interrupts_disabled(), which is basically
equivalent to smp_send_broadcast_ici(), but is only called with interrupts
disabled and gets the CPU index, so it doesn't have to use
smp_get_current_cpu() (which dereferences the current thread).
- Added cpu index parameter to smp_intercpu_int_handler().
* x86:
- arch_int.c -> arch_int.cpp
- Set up an IDT per CPU. We were using a single IDT for all CPUs, but that
can't work, since we need different tasks for the double fault interrupt
vector.
- Set the per CPU double fault task gates correctly.
- Renamed set_intr_gate() to set_interrupt_gate and set_system_gate() to
set_trap_gate() and documented them a bit.
- Renamed double_fault_exception() x86_double_fault_exception() and fixed
it not to use smp_get_current_cpu(). Instead we have the new
x86_double_fault_get_cpu() that deducts the CPU index from the used stack.
- Fixed the double_fault interrupt handler: It no longer calls int_bottom to
avoid accessing the current thread.
* debug.cpp:
- Introduced explicit debug_double_fault() to enter the kernel debugger from
a double fault handler.
- Avoid using smp_get_current_cpu().
- Don't use kprintf() before sDebuggerOnCPU is set. Otherwise
acquire_spinlock() is invoked by arch_debug_serial_puts().

Things look a bit better when the current thread pointer is broken -- we run
into kernel_debugger_loop() and successfully print the "Welcome to KDL"
message -- but we still dereference the thread pointer afterwards, so that we
don't get a usable kernel debugger yet.


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


# 7ab39de9895775d10669a1a85ce3ff60b1ca7b55 17-Oct-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Removed unused SMP_MSG_RESCHEDULE ICI message.
* Introduced flag "invoke_scheduler" in the per CPU structure. It is
evaluated in hardware_interrupt() (x86 only ATM).
* Introduced SMP_MSG_RESCHEDULE_IF_IDLE message, which enters the
scheduler when the CPU currently runs an idle thread.
* Don't do dprintf() "CPU x halted!" when handling a SMP_MSG_CPU_HALT
ICI message. It uses nested spinlocks and could thus potentially
deadlock itself (acquire_spinlock() processes ICI messages, so it
could already hold one of the locks). This is a pretty likely scenario
on machines with more than two CPUs, but is also possible when the
panic()ing thread holds the threads spinlock. Probably fixes #2572.
* Reworked the way the kernel debugger is entered and added a "cpu"
command that allows switching the CPU once in KDL. It is thus possible
to get a stack trace of the thread not on the panic()ing CPU.
* When a thread is added to the run queue, we do now check, if another
CPU is idle and ask it to reschedule, if it is. Before this change, the
CPU was continuing to idle until the quantum of the idle thread
expired. Speeds up the libbe.so build about 8% on my machine (haven't
tested the full Haiku image build yet).
* When spinlock debugging is enabled (DEBUG_SPINLOCKS) we also record
the spinlock acquirer on non-smp machines. Added "spinlock" debugger
command to get the info.
* Added debugger commands "ici" and "ici_message", printing info on
pending ICI message respectively on a given one.
* Process not only a single ICI message in acquire_spinlock() and other
places, but all pending ones.
* Also process ICI messages when waiting for a free one -- avoids a
potential deadlock.
* Mask out non-existing CPUs in send_multicast_ici(). panic() instead of
just returning when there's no target CPU left.


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


# 6bbe7eb8caad128659bb2edc617d0ccb2f2d89dd 07-Oct-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* smp.c -> smp.cpp
* Added smp_send_multicast_ici(), which sends the message to all CPUs
specified via a mask.


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


# 1c8de8581b66c14ea94bccd7ddcea99291955796 01-Jun-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Added optional spinlock contention measurement feature. Enabled when
B_DEBUG_SPINLOCK_CONTENTION is defined to 1. It typedefs spinlock to a
structure (thus breaking BeOS binary compatibility), containing a
counter which is incremented whenever a thread has to wait for the
spinlock.
* Added macros for spinlock initialization and access and changed
code using spinlocks accordingly. This breaks compilation for BeOS --
the macros should be defined in the respective compatibility wrappers.
* Added generic syscall to get the spinlock counters for the thread and
the team spinlocks.


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


# 0098867364c187e4419101ca8156ac094808a25d 01-Mar-2007 Travis Geiselbrecht <geist@foobox.com>

this seems to solve the 'lock up on bootup on core 2' problem.
Basically, there was a pretty subtle race between the cpus in main where if the main cpu released the AP cpus and then before the AP cpus had a chance to run the boot cpu started creating the main thread (which causes smp ici messages to be created) the system would livelock, where the boot cpu waited forever for the AP cpu to acknowledge the ICI (for a TLB flush when creating the kernel stack).
Added smp_cpu_rendezvous(), used to synchronize all the cpus to a particular point, and used it a few times in main().
While i was at it i fixed another race that'll probably never happen, but what the hey. Make sure the kernel args are copied into kernel space by the main cpu before letting any other ones use it.


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


# e0e9a3e69f18220cf21cd2fa8ba2d9fb794b922b 14-Dec-2005 Axel Dörfler <axeld@pinc-software.de>

* We now support the global page feature of x86 processors that prevents
kernel TLBs from being flushed on context switch.
* new arch_cpu_user_TLB_invalidate() that now does what arch_cpu_global_TLB_invalidate()
did before.
* arch_cpu_global_TLB_invalidate() will now flush all TLBs, even those from the
kernel.
* some cleanups.


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


# ef7bac18bbfefe2305748466cbdcc79ad74d799d 25-Oct-2005 Axel Dörfler <axeld@pinc-software.de>

Implemented call_all_cpus(), and get_cpuid() properly (tested only the latter, though).
The "data_ptr" parameter is now only freed if you specify SMP_MSG_FLAG_FREE_ARG
when sending the ICI message.


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


# 6cd505cee71447d8c4829e79c2fee9c6d92badc7 25-Oct-2005 Axel Dörfler <axeld@pinc-software.de>

Changed the boot procedure a bit.
Extracted scheduler_init() from start_scheduler() (which is now called scheduler_start()).
Moved scheduler related function prototypes from thread.h to the new scheduler.h.
Cleanup.


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


# 74b043d98d35652a6892fc430537a02f5f9d9f76 17-Mar-2005 Axel Dörfler <axeld@pinc-software.de>

Removed execute property that was set accidently (since CVS days).


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


# 4a2e872ccab6d0891dc8be6bc3395c23180d6d59 14-Mar-2004 Axel Dörfler <axeld@pinc-software.de>

Applied NewOS change 1914: moved APIC setup into the kernel due to a
problem with the APIC clock speed test.


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


# a2b6866fb9fb303f8e46ac821a1894c47164ee4e 14-Mar-2004 Axel Dörfler <axeld@pinc-software.de>

Fixed compilation without having included boot/kernel_args.h.


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


# 564cba312ebe49860fbb8416737c4de3e6ccd5f2 03-May-2003 Axel Dörfler <axeld@pinc-software.de>

Some header work: removed unnecessary dependencies to stage2.h, fixed
some broken C++ export definitions, added missing licenses etc.


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


# 5cdacbaabbd66673ada83b4d97d87126776484dc 26-Oct-2002 lillo <lillo@nowhere.fake>

*LOTS* of small changes to make the kernel compatible with Be's KernelExport.h


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


# 52a380120846174213ccce9c4aab0dda17c72083 08-Jul-2002 ejakowatz <ejakowatz@nowhere.fake>

It is accomplished ...


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