From 95ae0f42a5f22bd913a713db987729520c42a123 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Fri, 4 Jul 2025 18:58:57 +0200 Subject: feat: see below. feat: Rework `OpenMSG` into `LibMSG` feat: Rename `generic_kits` to `misc` Signed-off-by: Amlal El Mahrouss --- dev/misc/BenchKit/Chrono.h | 31 +++++++++++++++++++++++++ dev/misc/BenchKit/X64Chrono.h | 54 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 dev/misc/BenchKit/Chrono.h create mode 100644 dev/misc/BenchKit/X64Chrono.h (limited to 'dev/misc/BenchKit') diff --git a/dev/misc/BenchKit/Chrono.h b/dev/misc/BenchKit/Chrono.h new file mode 100644 index 00000000..394f16fd --- /dev/null +++ b/dev/misc/BenchKit/Chrono.h @@ -0,0 +1,31 @@ +/* ------------------------------------------- + +Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#ifndef BENCHKIT_CHRONO_H +#define BENCHKIT_CHRONO_H + +#include +#include + +namespace Kernel { +class ChronoInterface; + +/// @brief a Chronometer interface used for benchmarking. +class ChronoInterface { + public: + ChronoInterface() = default; + virtual ~ChronoInterface() = default; + + NE_COPY_DEFAULT(ChronoInterface); + + virtual void Start() = 0; + virtual void Stop() = 0; + virtual void Reset() = 0; + virtual UInt64 GetElapsedTime() const = 0; +}; +} // namespace Kernel + +#endif // BENCHKIT_CHRONO_H diff --git a/dev/misc/BenchKit/X64Chrono.h b/dev/misc/BenchKit/X64Chrono.h new file mode 100644 index 00000000..706ce883 --- /dev/null +++ b/dev/misc/BenchKit/X64Chrono.h @@ -0,0 +1,54 @@ +/* ------------------------------------------- + +Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +#include + +#if defined(__NE_AMD64__) + +namespace Kernel { +class X64Chrono; +struct X64ChronoTraits; + +struct X64ChronoTraits { + private: + STATIC UInt64 TickImpl_(void) { + UInt64 a = 0, d = 0; + __asm__ volatile("rdtsc" : "=a"(a), "=d"(d)); + return (d << 32) | a; + } + + friend X64Chrono; +}; + +/// @brief X86_64 hardware chrono implementation using the `rdtsc` instruction. +class X64Chrono : public ChronoInterface { + public: + X64Chrono() = default; + ~X64Chrono() override = default; + + NE_COPY_DEFAULT(X64Chrono); + + public: + void Start() override { fStart = X64ChronoTraits::TickImpl_(); } + + void Stop() override { fStop = X64ChronoTraits::TickImpl_(); } + + void Reset() override { + fStart = 0; + fStop = 0; + } + + UInt64 GetElapsedTime() const override { return fStop - fStart; } + + private: + UInt64 fStart = 0; + UInt64 fStop = 0; +}; +} // namespace Kernel + +#endif // defined(__NE_AMD64__) \ No newline at end of file -- cgit v1.2.3