summaryrefslogtreecommitdiffhomepage
path: root/dev/misc/BenchKit
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-07-04 18:58:57 +0200
committerAmlal El Mahrouss <amlal@nekernel.org>2025-07-04 18:58:57 +0200
commit95ae0f42a5f22bd913a713db987729520c42a123 (patch)
treeb0da5c9d6d1940bc9b1c6b0331abe4487d00e0f1 /dev/misc/BenchKit
parent32edc6508c91e51316d67b92eb86b4e72d0a41a4 (diff)
feat: see below.
feat: Rework `OpenMSG` into `LibMSG` feat: Rename `generic_kits` to `misc` Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'dev/misc/BenchKit')
-rw-r--r--dev/misc/BenchKit/Chrono.h31
-rw-r--r--dev/misc/BenchKit/X64Chrono.h54
2 files changed, 85 insertions, 0 deletions
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 <CompilerKit/CompilerKit.h>
+#include <NeKit/Defines.h>
+
+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 <misc/BenchKit/Chrono.h>
+
+#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