mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:47:34 +00:00
Kernel: Add Processor::pause() and use it to give the CPU a rest
On x86, the "pause" instruction is a "spin loop hint".
This commit is contained in:
parent
b7129c57df
commit
46215a8183
2 changed files with 9 additions and 4 deletions
|
@ -197,10 +197,15 @@ public:
|
||||||
return *g_total_processors.ptr();
|
return *g_total_processors.ptr();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ALWAYS_INLINE static void pause()
|
||||||
|
{
|
||||||
|
asm volatile("pause");
|
||||||
|
}
|
||||||
|
|
||||||
ALWAYS_INLINE static void wait_check()
|
ALWAYS_INLINE static void wait_check()
|
||||||
{
|
{
|
||||||
|
Processor::pause();
|
||||||
Processor::current().smp_process_pending_messages();
|
Processor::current().smp_process_pending_messages();
|
||||||
// TODO: pause
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[[noreturn]] static void halt();
|
[[noreturn]] static void halt();
|
||||||
|
|
|
@ -682,7 +682,7 @@ ProcessorMessage& Processor::smp_get_from_pool()
|
||||||
msg = s_message_pool.load(AK::MemoryOrder::memory_order_consume);
|
msg = s_message_pool.load(AK::MemoryOrder::memory_order_consume);
|
||||||
if (!msg) {
|
if (!msg) {
|
||||||
if (!Processor::current().smp_process_pending_messages()) {
|
if (!Processor::current().smp_process_pending_messages()) {
|
||||||
// TODO: pause for a bit?
|
Processor::pause();
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -898,7 +898,7 @@ void Processor::smp_broadcast_wait_sync(ProcessorMessage& msg)
|
||||||
// If synchronous then we must cleanup and return the message back
|
// If synchronous then we must cleanup and return the message back
|
||||||
// to the pool. Otherwise, the last processor to complete it will return it
|
// to the pool. Otherwise, the last processor to complete it will return it
|
||||||
while (msg.refs.load(AK::MemoryOrder::memory_order_consume) != 0) {
|
while (msg.refs.load(AK::MemoryOrder::memory_order_consume) != 0) {
|
||||||
// TODO: pause for a bit?
|
Processor::pause();
|
||||||
|
|
||||||
// We need to process any messages that may have been sent to
|
// We need to process any messages that may have been sent to
|
||||||
// us while we're waiting. This also checks if another processor
|
// us while we're waiting. This also checks if another processor
|
||||||
|
@ -928,7 +928,7 @@ void Processor::smp_unicast_message(u32 cpu, ProcessorMessage& msg, bool async)
|
||||||
// If synchronous then we must cleanup and return the message back
|
// If synchronous then we must cleanup and return the message back
|
||||||
// to the pool. Otherwise, the last processor to complete it will return it
|
// to the pool. Otherwise, the last processor to complete it will return it
|
||||||
while (msg.refs.load(AK::MemoryOrder::memory_order_consume) != 0) {
|
while (msg.refs.load(AK::MemoryOrder::memory_order_consume) != 0) {
|
||||||
// TODO: pause for a bit?
|
Processor::pause();
|
||||||
|
|
||||||
// We need to process any messages that may have been sent to
|
// We need to process any messages that may have been sent to
|
||||||
// us while we're waiting. This also checks if another processor
|
// us while we're waiting. This also checks if another processor
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue