mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
bst_vs_heap_vs_hashmap: create nicer version with separated benchmarks
One data structure per executable, and gem5 instrumented versions in separate executables. Create the allowed_emulators path_properties property. TODO: wire it up to benchmark result generation and remove the old version.
This commit is contained in:
@@ -11,6 +11,7 @@ class PathProperties:
|
|||||||
# All new properties must be listed here or else you get an error.
|
# All new properties must be listed here or else you get an error.
|
||||||
default_properties = {
|
default_properties = {
|
||||||
'allowed_archs': None,
|
'allowed_archs': None,
|
||||||
|
'allowed_emulators': None,
|
||||||
# The example uses aarch32 instructions which are not present in ARMv7.
|
# The example uses aarch32 instructions which are not present in ARMv7.
|
||||||
# Therefore, it cannot be run in baremetal ARMv7 CPUs.
|
# Therefore, it cannot be run in baremetal ARMv7 CPUs.
|
||||||
# User mode simulation however seems to enable aarch32 so these run fine.
|
# User mode simulation however seems to enable aarch32 so these run fine.
|
||||||
@@ -271,6 +272,10 @@ class PathProperties:
|
|||||||
self.unimplemented_instructions[env['emulator']][env['arch']] &
|
self.unimplemented_instructions[env['emulator']][env['arch']] &
|
||||||
self['uses_instructions'][env['arch']]
|
self['uses_instructions'][env['arch']]
|
||||||
)
|
)
|
||||||
|
) and
|
||||||
|
(
|
||||||
|
self['allowed_emulators'] is None or
|
||||||
|
env['emulator'] in self['allowed_emulators']
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -430,6 +435,19 @@ path_properties_tuples = (
|
|||||||
'userland': True,
|
'userland': True,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
'algorithm': (
|
||||||
|
{},
|
||||||
|
{
|
||||||
|
'set': (
|
||||||
|
{},
|
||||||
|
{
|
||||||
|
'std_priority_queue_gem5.cpp': {'allowed_emulators': {'gem5'}},
|
||||||
|
'std_set_gem5.cpp': {'allowed_emulators': {'gem5'}},
|
||||||
|
'std_unordered_set_gem5.cpp': {'allowed_emulators': {'gem5'}},
|
||||||
|
}
|
||||||
|
),
|
||||||
|
},
|
||||||
|
),
|
||||||
'arch': (
|
'arch': (
|
||||||
{
|
{
|
||||||
'baremetal': True,
|
'baremetal': True,
|
||||||
|
|||||||
1
userland/algorithm/build
Symbolic link
1
userland/algorithm/build
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../build
|
||||||
1
userland/algorithm/set/README.adoc
Normal file
1
userland/algorithm/set/README.adoc
Normal file
@@ -0,0 +1 @@
|
|||||||
|
https://cirosantilli.com/linux-kernel-module-cheat#bst-vs-heap-vs-hashmap
|
||||||
1
userland/algorithm/set/build
Symbolic link
1
userland/algorithm/set/build
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../build
|
||||||
115
userland/algorithm/set/main.hpp
Normal file
115
userland/algorithm/set/main.hpp
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
// https://cirosantilli.com/linux-kernel-module-cheat#bst-vs-heap-vs-hashmap
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cassert>
|
||||||
|
#include <chrono>
|
||||||
|
#include <iostream>
|
||||||
|
#if LKMC_ALGORITHM_SET_STD_PRIORITY_QUEUE
|
||||||
|
#include <queue>
|
||||||
|
#endif
|
||||||
|
#include <random>
|
||||||
|
#if LKMC_ALGORITHM_SET_STD_SET
|
||||||
|
#include <set>
|
||||||
|
#endif
|
||||||
|
#if LKMC_ALGORITHM_SET_STD_UNORDERED_SET
|
||||||
|
#include <unordered_set>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <lkmc/m5ops.h>
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
typedef uint64_t T;
|
||||||
|
#if LKMC_ALGORITHM_SET_STD_PRIORITY_QUEUE
|
||||||
|
std::priority_queue<T> set;
|
||||||
|
#endif
|
||||||
|
#if LKMC_ALGORITHM_SET_STD_SET
|
||||||
|
std::set<T> set;
|
||||||
|
#endif
|
||||||
|
#if LKMC_ALGORITHM_SET_STD_UNORDERED_SET
|
||||||
|
std::unordered_set<T> set;
|
||||||
|
#endif
|
||||||
|
std::vector<T> randoms;
|
||||||
|
size_t i, j = 0, n, granule, base;
|
||||||
|
unsigned int seed;
|
||||||
|
#ifndef LKMC_M5OPS_ENABLE
|
||||||
|
std::vector<std::chrono::nanoseconds::rep> dts;
|
||||||
|
std::vector<decltype(base)> bases;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// CLI arguments.
|
||||||
|
if (argc > 1) {
|
||||||
|
n = std::stoi(argv[1]);
|
||||||
|
} else {
|
||||||
|
n = 10;
|
||||||
|
}
|
||||||
|
if (argc > 2) {
|
||||||
|
granule = std::stoi(argv[2]);
|
||||||
|
} else {
|
||||||
|
granule = 1;
|
||||||
|
}
|
||||||
|
if (argc > 3) {
|
||||||
|
seed = std::stoi(argv[3]);
|
||||||
|
} else {
|
||||||
|
seed = std::random_device()();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Action.
|
||||||
|
for (i = 0; i < n; ++i) {
|
||||||
|
randoms.push_back(i);
|
||||||
|
}
|
||||||
|
std::shuffle(randoms.begin(), randoms.end(), std::mt19937(seed));
|
||||||
|
for (i = 0; i < n / granule; ++i) {
|
||||||
|
#ifndef LKMC_M5OPS_ENABLE
|
||||||
|
using clk = std::chrono::high_resolution_clock;
|
||||||
|
decltype(clk::now()) start, end;
|
||||||
|
#endif
|
||||||
|
base = i * granule;
|
||||||
|
#ifdef LKMC_M5OPS_ENABLE
|
||||||
|
LKMC_M5OPS_RESETSTATS;
|
||||||
|
#else
|
||||||
|
start = clk::now();
|
||||||
|
for (j = 0; j < granule; ++j) {
|
||||||
|
#endif
|
||||||
|
#if LKMC_ALGORITHM_SET_STD_PRIORITY_QUEUE
|
||||||
|
set.emplace(randoms[base + j]);
|
||||||
|
#else
|
||||||
|
set.insert(randoms[base + j]);
|
||||||
|
#endif
|
||||||
|
#ifdef LKMC_M5OPS_ENABLE
|
||||||
|
LKMC_M5OPS_DUMPSTATS;
|
||||||
|
#else
|
||||||
|
}
|
||||||
|
end = clk::now();
|
||||||
|
auto dt = (end - start) / granule;
|
||||||
|
bases.push_back(base);
|
||||||
|
dts.push_back(std::chrono::duration_cast<std::chrono::nanoseconds>(dt).count());
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
// Report results.
|
||||||
|
#ifndef LKMC_M5OPS_ENABLE
|
||||||
|
// Output.
|
||||||
|
std::cout << "times" << std::endl;
|
||||||
|
auto bases_it = bases.begin();
|
||||||
|
auto dts_it = dts.begin();
|
||||||
|
while(bases_it != bases.end()) {
|
||||||
|
const auto& base = *bases_it;
|
||||||
|
const auto& dt = *dts_it;
|
||||||
|
std::cout << base << " " << dt << std::endl;
|
||||||
|
bases_it++;
|
||||||
|
dts_it++;
|
||||||
|
}
|
||||||
|
std::cout << std::endl;
|
||||||
|
std::cout << "output" << std::endl;
|
||||||
|
#if LKMC_ALGORITHM_SET_STD_PRIORITY_QUEUE
|
||||||
|
while (!set.empty()) {
|
||||||
|
std::cout << set.top() << std::endl;
|
||||||
|
set.pop();
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
for (const auto& item : set) {
|
||||||
|
std::cout << item << std::endl;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
}
|
||||||
2
userland/algorithm/set/std_priority_queue.cpp
Normal file
2
userland/algorithm/set/std_priority_queue.cpp
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
#define LKMC_ALGORITHM_SET_STD_PRIORITY_QUEUE 1
|
||||||
|
#include "main.hpp"
|
||||||
3
userland/algorithm/set/std_priority_queue_gem5.cpp
Normal file
3
userland/algorithm/set/std_priority_queue_gem5.cpp
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
#define LKMC_M5OPS_ENABLE 1
|
||||||
|
#define LKMC_ALGORITHM_SET_STD_PRIORITY_QUEUE 1
|
||||||
|
#include "main.hpp"
|
||||||
2
userland/algorithm/set/std_set.cpp
Normal file
2
userland/algorithm/set/std_set.cpp
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
#define LKMC_ALGORITHM_SET_STD_SET 1
|
||||||
|
#include "main.hpp"
|
||||||
3
userland/algorithm/set/std_set_gem5.cpp
Normal file
3
userland/algorithm/set/std_set_gem5.cpp
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
#define LKMC_M5OPS_ENABLE 1
|
||||||
|
#define LKMC_ALGORITHM_SET_STD_SET 1
|
||||||
|
#include "main.hpp"
|
||||||
2
userland/algorithm/set/std_unordered_set.cpp
Normal file
2
userland/algorithm/set/std_unordered_set.cpp
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
#define LKMC_ALGORITHM_SET_STD_UNORDERED_SET 1
|
||||||
|
#include "main.hpp"
|
||||||
3
userland/algorithm/set/std_unordered_set_gem5.cpp
Normal file
3
userland/algorithm/set/std_unordered_set_gem5.cpp
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
#define LKMC_M5OPS_ENABLE 1
|
||||||
|
#define LKMC_ALGORITHM_SET_STD_UNORDERED_SET 1
|
||||||
|
#include "main.hpp"
|
||||||
1
userland/algorithm/set/test
Symbolic link
1
userland/algorithm/set/test
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../test
|
||||||
1
userland/algorithm/test
Symbolic link
1
userland/algorithm/test
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../test
|
||||||
Reference in New Issue
Block a user