summaryrefslogtreecommitdiffhomepage
path: root/dev/misc
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-08-16 19:56:21 +0200
committerGitHub <noreply@github.com>2025-08-16 19:56:21 +0200
commit1a32b9307357ac0fc9095e853b2b6d94f9fe62bb (patch)
treef41f723659c8926e38182fbe062746d821ab487e /dev/misc
parenteb9df5eea339812513c25a8d3b2eeb03c633e7ac (diff)
parentb301047903b79560dce69085fc271a653a1eb4b6 (diff)
Merge pull request #55 from nekernel-org/dev
v0.0.4
Diffstat (limited to 'dev/misc')
-rw-r--r--dev/misc/.keep0
-rw-r--r--dev/misc/BenchKit/Chrono.h40
-rw-r--r--dev/misc/BenchKit/X64Chrono.h56
3 files changed, 96 insertions, 0 deletions
diff --git a/dev/misc/.keep b/dev/misc/.keep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/dev/misc/.keep
diff --git a/dev/misc/BenchKit/Chrono.h b/dev/misc/BenchKit/Chrono.h
new file mode 100644
index 00000000..3a82a94e
--- /dev/null
+++ b/dev/misc/BenchKit/Chrono.h
@@ -0,0 +1,40 @@
+/* -------------------------------------------
+
+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>
+
+/// @author Amlal El Mahrouss
+/// @brief BenchKit Chrono contract.
+
+#define BENCHKIT_INTERFACE : public ::Kernel::ChronoInterface
+
+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
+
+namespace BenchKit {
+using 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..728e7d60
--- /dev/null
+++ b/dev/misc/BenchKit/X64Chrono.h
@@ -0,0 +1,56 @@
+/* -------------------------------------------
+
+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;
+
+/// @brief BenchKit chrono logic for x64.
+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 BENCHKIT_INTERFACE {
+ 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{};
+ UInt64 fStop{};
+};
+} // namespace Kernel
+
+#endif // defined(__NE_AMD64__) \ No newline at end of file