From 7afa74b53110c0258c7fa9ae5aa8e7dde7534b4d Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sun, 31 Aug 2025 16:49:59 +0200 Subject: feat! BenchKit breaking changes. why: - Made it expandable to other traits and platforms. - You can provide a `Traits` now to the `HWChrono`. Signed-off-by: Amlal El Mahrouss --- dev/misc/BenchKit/HWChronometer.h | 66 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 dev/misc/BenchKit/HWChronometer.h (limited to 'dev/misc/BenchKit/HWChronometer.h') diff --git a/dev/misc/BenchKit/HWChronometer.h b/dev/misc/BenchKit/HWChronometer.h new file mode 100644 index 00000000..2b8637d8 --- /dev/null +++ b/dev/misc/BenchKit/HWChronometer.h @@ -0,0 +1,66 @@ +/* ------------------------------------------- + +Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +#include + +namespace Kernel { +struct HWChronoTraits; + +template +class HWChrono; + +/// @brief BenchKit chrono logic for x64. +struct HWChronoTraits final { + private: + STATIC UInt64 TickImpl_(void) { +#ifdef __NE_AMD64__ + UInt64 a = 0, d = 0; + + asm volatile("rdtsc" : "=a"(a), "=d"(d)); + + return (d << 32) | a; +#elif defined(__NE_ARM64__) + UInt64 result; + + asm volatile("mrs %0, cntvct_el1" : "=r"(result)); + + return result; +#else +#error !!! no backend defined !!! +#endif + } + + friend HWChrono; +}; + +/// @brief hardware chronometer implementation using a trait to extract the data. +template +class HWChrono BENCHKIT_INTERFACE { + public: + HWChrono() = default; + ~HWChrono() override = default; + + NE_COPY_DEFAULT(HWChrono) + + public: + Void Start() override { fStart = ChronoTraits::TickImpl_(); } + + Void Stop() override { fStop = ChronoTraits::TickImpl_(); } + + Void Reset() override { + fStart = 0; + fStop = 0; + } + + UInt64 GetElapsedTime() const override { return fStop - fStart; } + + private: + UInt64 fStart{}; + UInt64 fStop{}; +}; +} // namespace Kernel -- cgit v1.2.3 From 257b0a377e0e0f226623e7aa807780051a9cc9e6 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 1 Sep 2025 06:12:55 +0200 Subject: feat: BenchKit: `HWChronometer` shall be `virtual`. Signed-off-by: Amlal El Mahrouss --- dev/misc/BenchKit/HWChronometer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'dev/misc/BenchKit/HWChronometer.h') diff --git a/dev/misc/BenchKit/HWChronometer.h b/dev/misc/BenchKit/HWChronometer.h index 2b8637d8..80e1d84a 100644 --- a/dev/misc/BenchKit/HWChronometer.h +++ b/dev/misc/BenchKit/HWChronometer.h @@ -43,7 +43,7 @@ template class HWChrono BENCHKIT_INTERFACE { public: HWChrono() = default; - ~HWChrono() override = default; + virtual ~HWChrono() override = default; NE_COPY_DEFAULT(HWChrono) -- cgit v1.2.3 From 12fe96873ad4a2f1d3c7c3d9f84bc8eb367fb2f0 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 1 Sep 2025 08:43:46 +0200 Subject: feat: Signal System improvements. Signed-off-by: Amlal El Mahrouss --- dev/boot/BootKit/BitManip.h | 2 +- dev/kernel/SignalKit/SignalGen.h | 39 ++++++++++++++++++++++++--------------- dev/misc/BenchKit/HWChronometer.h | 2 +- 3 files changed, 26 insertions(+), 17 deletions(-) (limited to 'dev/misc/BenchKit/HWChronometer.h') diff --git a/dev/boot/BootKit/BitManip.h b/dev/boot/BootKit/BitManip.h index b1c72bfb..196953b3 100644 --- a/dev/boot/BootKit/BitManip.h +++ b/dev/boot/BootKit/BitManip.h @@ -8,7 +8,7 @@ #define __BITMANIP_H__ /// File: BitManip.h -/// Purpose: Bit manipulation helpers, based on coreboot-dev. +/// Purpose: Bit manipulation helpers, based on neboot-dev. #define bk_set_bit(X, O) X = (1 << O) | X #define bk_clear_bit(X, O) X = ~(1 << O) & X diff --git a/dev/kernel/SignalKit/SignalGen.h b/dev/kernel/SignalKit/SignalGen.h index e1684acb..ad127830 100644 --- a/dev/kernel/SignalKit/SignalGen.h +++ b/dev/kernel/SignalKit/SignalGen.h @@ -8,36 +8,45 @@ #include -#define SIGKILL 1 -#define SIGPAUS 2 -#define SIGEXEC 3 -#define SIGTRAP 4 -#define SIGABRT 5 -#define SIGCONT 6 -#define SIGSEG 7 - -#define SIGBREK 660 -#define SIGATCH 661 -#define SIGDTCH 662 +#define SIGKILL 1 /* kill */ +#define SIGPAUS 2 /* pause */ +#define SIGEXEC 3 /* execute */ +#define SIGTRAP 4 /* trap */ +#define SIGABRT 5 /* abort */ +#define SIGCONT 6 /* continue */ +#define SIGSEG 7 /* process fault */ +#define SIGBREK 8 +#define SIGATCH 9 +#define SIGDTCH 10 /// @author Amlal El Mahrouss /// @brief Signal Generation API. namespace Kernel { -typedef UInt32 rt_signal_kind; +typedef SizeT rt_signal_kind; /// @brief Standard signal seed for general purpose usage. -inline static constexpr auto kBasicSignalSeed = 0x0895034f; +inline static constexpr auto kUserSignalSeed = 0x0895034fUL; + +/// @brief Special signal seed for kernel usage. +inline static constexpr auto kKernelSignalSeed = 0x0895034f9fUL; /// @brief Generate signal from **Sig** -template +template inline rt_signal_kind sig_generate_unique() { static_assert(Sig > 0, "Signal is zero (invalid)"); return Sig ^ Seed; } +/// @brief Checks if the signal matches the seed (user_seed or kernel_seed) +template +inline BOOL sig_matches_seed(const rt_signal_kind& sig) { + static_assert(sig > 0, "Signal is zero (invalid)"); + return (sig & Seed) > 0; +} + /// @brief Validate signal from **sig** -constexpr BOOL sig_validate_unique(rt_signal_kind sig) { +inline BOOL sig_validate_unique(rt_signal_kind sig) { return sig > 0; } } // namespace Kernel diff --git a/dev/misc/BenchKit/HWChronometer.h b/dev/misc/BenchKit/HWChronometer.h index 80e1d84a..e232db7e 100644 --- a/dev/misc/BenchKit/HWChronometer.h +++ b/dev/misc/BenchKit/HWChronometer.h @@ -42,7 +42,7 @@ struct HWChronoTraits final { template class HWChrono BENCHKIT_INTERFACE { public: - HWChrono() = default; + HWChrono() = default; virtual ~HWChrono() override = default; NE_COPY_DEFAULT(HWChrono) -- cgit v1.2.3