mirror of
https://github.com/SerenityOS/serenity
synced 2024-10-15 12:23:15 +00:00
Kernel: Abstract platform-specific current time methods from Scheduler
This change ensures that the scheduler doesn't depend on a platform specific or arch-specific code when it initializes itself, but rather we ensure that in compile-time we will generate the appropriate code to find the correct arch-specific current time methods.
This commit is contained in:
parent
c439a34ff7
commit
3651d9701e
17
Kernel/Arch/CurrentTime.h
Normal file
17
Kernel/Arch/CurrentTime.h
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022, Liav A. <liavalb@hotmail.co.il>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/Types.h>
|
||||||
|
|
||||||
|
namespace Kernel {
|
||||||
|
|
||||||
|
typedef u64 (*fptr)();
|
||||||
|
|
||||||
|
fptr optional_current_time();
|
||||||
|
|
||||||
|
}
|
18
Kernel/Arch/aarch64/CurrentTime.cpp
Normal file
18
Kernel/Arch/aarch64/CurrentTime.cpp
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022, Liav A. <liavalb@hotmail.co.il>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Kernel/Arch/CurrentTime.h>
|
||||||
|
|
||||||
|
namespace Kernel {
|
||||||
|
|
||||||
|
fptr optional_current_time()
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
28
Kernel/Arch/x86/CurrentTime.cpp
Normal file
28
Kernel/Arch/x86/CurrentTime.cpp
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022, Liav A. <liavalb@hotmail.co.il>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <Kernel/Arch/CurrentTime.h>
|
||||||
|
#include <Kernel/Arch/x86/ASM_wrapper.h>
|
||||||
|
#include <Kernel/Arch/x86/Processor.h>
|
||||||
|
|
||||||
|
namespace Kernel {
|
||||||
|
|
||||||
|
static u64 current_time_tsc()
|
||||||
|
{
|
||||||
|
return read_tsc();
|
||||||
|
}
|
||||||
|
|
||||||
|
fptr optional_current_time()
|
||||||
|
{
|
||||||
|
VERIFY(Processor::is_initialized()); // sanity check
|
||||||
|
// Figure out a good scheduling time source
|
||||||
|
if (Processor::current().has_feature(CPUFeature::TSC) && Processor::current().has_feature(CPUFeature::CONSTANT_TSC)) {
|
||||||
|
return current_time_tsc;
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -327,6 +327,8 @@ if ("${SERENITY_ARCH}" STREQUAL "i686" OR "${SERENITY_ARCH}" STREQUAL "x86_64")
|
||||||
Arch/x86/common/SmapDisabler.cpp
|
Arch/x86/common/SmapDisabler.cpp
|
||||||
Arch/x86/common/Shutdown.cpp
|
Arch/x86/common/Shutdown.cpp
|
||||||
|
|
||||||
|
Arch/x86/CurrentTime.cpp
|
||||||
|
|
||||||
Arch/x86/Hypervisor/BochsDisplayConnector.cpp
|
Arch/x86/Hypervisor/BochsDisplayConnector.cpp
|
||||||
Arch/x86/Hypervisor/VMWareBackdoor.cpp
|
Arch/x86/Hypervisor/VMWareBackdoor.cpp
|
||||||
|
|
||||||
|
@ -477,6 +479,7 @@ else()
|
||||||
Arch/aarch64/boot.S
|
Arch/aarch64/boot.S
|
||||||
Arch/aarch64/BootPPMParser.cpp
|
Arch/aarch64/BootPPMParser.cpp
|
||||||
Arch/aarch64/CrashHandler.cpp
|
Arch/aarch64/CrashHandler.cpp
|
||||||
|
Arch/aarch64/CurrentTime.cpp
|
||||||
Arch/aarch64/Dummy.cpp
|
Arch/aarch64/Dummy.cpp
|
||||||
Arch/aarch64/Exceptions.cpp
|
Arch/aarch64/Exceptions.cpp
|
||||||
Arch/aarch64/init.cpp
|
Arch/aarch64/init.cpp
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include <AK/ScopeGuard.h>
|
#include <AK/ScopeGuard.h>
|
||||||
#include <AK/Singleton.h>
|
#include <AK/Singleton.h>
|
||||||
#include <AK/Time.h>
|
#include <AK/Time.h>
|
||||||
|
#include <Kernel/Arch/CurrentTime.h>
|
||||||
#include <Kernel/Arch/InterruptDisabler.h>
|
#include <Kernel/Arch/InterruptDisabler.h>
|
||||||
#include <Kernel/Arch/x86/TrapFrame.h>
|
#include <Kernel/Arch/x86/TrapFrame.h>
|
||||||
#include <Kernel/Debug.h>
|
#include <Kernel/Debug.h>
|
||||||
|
@ -365,11 +366,6 @@ Process* Scheduler::colonel()
|
||||||
return s_colonel_process;
|
return s_colonel_process;
|
||||||
}
|
}
|
||||||
|
|
||||||
static u64 current_time_tsc()
|
|
||||||
{
|
|
||||||
return read_tsc();
|
|
||||||
}
|
|
||||||
|
|
||||||
static u64 current_time_monotonic()
|
static u64 current_time_monotonic()
|
||||||
{
|
{
|
||||||
// We always need a precise timestamp here, we cannot rely on a coarse timestamp
|
// We always need a precise timestamp here, we cannot rely on a coarse timestamp
|
||||||
|
@ -380,13 +376,11 @@ UNMAP_AFTER_INIT void Scheduler::initialize()
|
||||||
{
|
{
|
||||||
VERIFY(Processor::is_initialized()); // sanity check
|
VERIFY(Processor::is_initialized()); // sanity check
|
||||||
|
|
||||||
// Figure out a good scheduling time source
|
auto* possible_arch_specific_current_time_function = optional_current_time();
|
||||||
if (Processor::current().has_feature(CPUFeature::TSC) && Processor::current().has_feature(CPUFeature::CONSTANT_TSC)) {
|
if (possible_arch_specific_current_time_function)
|
||||||
current_time = current_time_tsc;
|
current_time = possible_arch_specific_current_time_function;
|
||||||
} else {
|
else
|
||||||
// TODO: Using HPET is rather slow, can we use any other time source that may be faster?
|
|
||||||
current_time = current_time_monotonic;
|
current_time = current_time_monotonic;
|
||||||
}
|
|
||||||
|
|
||||||
LockRefPtr<Thread> idle_thread;
|
LockRefPtr<Thread> idle_thread;
|
||||||
g_finalizer_wait_queue = new WaitQueue;
|
g_finalizer_wait_queue = new WaitQueue;
|
||||||
|
|
Loading…
Reference in a new issue