mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
m5ops: move to factored .h file
Create empty subs for unsupported archs, much less messy for callers. bst_vs_heap: create
This commit is contained in:
23
README.adoc
23
README.adoc
@@ -7415,7 +7415,9 @@ A flexible setup is:
|
||||
....
|
||||
arch=aarch64
|
||||
cmd="./run -a '$arch' -g -F '/gem5.sh'"
|
||||
restore='-l 1 -- --cpu-type=HPI --restore-with-cpu=HPI --caches --l2cache --l1d_size=1024kB --l1i_size=1024kB --l2_size=1024kB --l3_size=1024kB'
|
||||
# These cache sizes roughly match the ARM Cortex A75
|
||||
# https://en.wikipedia.org/wiki/ARM_Cortex-A75
|
||||
restore='-l 1 -- --cpu-type=HPI --restore-with-cpu=HPI --caches --l2cache --l1d_size=128kB --l1i_size=1024kB --l2_size=256kB'
|
||||
|
||||
# Generate a checkpoint after Linux boots, using the faster and less detailed CPU.
|
||||
# The boot takes a while, be patient young Padawan.
|
||||
@@ -7702,6 +7704,25 @@ Buildroot built-in libraries, mostly under Libraries > Other:
|
||||
|
||||
There are not yet enabled, but it should be easy to so, see: <<add-new-buildroot-packages>>
|
||||
|
||||
===== BST vs heap
|
||||
|
||||
https://stackoverflow.com/questions/6147242/heap-vs-binary-search-tree-bst/29548834#29548834
|
||||
|
||||
Usage:
|
||||
|
||||
....
|
||||
printf '/bst_vs_heap.out' > data/readfile
|
||||
./run -aA -g -F '/gem5.sh'
|
||||
./bst-vs-heap > bst_vs_heap.dat
|
||||
....
|
||||
|
||||
and then feed `bst_vs_heap.dat` into: https://github.com/cirosantilli/cpp-cheat/blob/9d0f77792fc8e55b20b6ee32018761ef3c5a3f2f/cpp/interactive/bst_vs_heap.gnuplot
|
||||
|
||||
Sources:
|
||||
|
||||
* link:bst-vs-heap[]
|
||||
* link:kernel_module/user/bst_vs_heap.cpp[]
|
||||
|
||||
===== OpenMP
|
||||
|
||||
Implemented by GCC itself, so just a toolchain configuration, no external libs, and we enable it by default:
|
||||
|
||||
11
bst-vs-heap
Executable file
11
bst-vs-heap
Executable file
@@ -0,0 +1,11 @@
|
||||
#!/usr/bin/env bash
|
||||
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common"
|
||||
while getopts "${common_getopts_flags}" OPT; do
|
||||
case "$OPT" in
|
||||
?)
|
||||
common_getopts_case "$OPT"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
shift "$(($OPTIND - 1))"
|
||||
"${common_root_dir}/gem5-stat" -a "$common_arch" | awk 'NR % 2 { printf "%d %s ", NR/2, $0; next; } 1'
|
||||
@@ -1,10 +1,12 @@
|
||||
.PHONY: all clean
|
||||
|
||||
CFLAGS_EXTRA ?= -fopenmp -std=c99 -Wall -Werror -Wextra
|
||||
IN_EXT_C ?= .c
|
||||
IN_EXT_CXX ?= .cpp
|
||||
LIBS :=
|
||||
OUT_EXT ?= .out
|
||||
CFLAGS_EXTRA = -fopenmp -std=c99
|
||||
CXXFLAGS_EXTRA = -std=c++17
|
||||
CCFLAGS_EXTRA = -Wall -Werror -Wextra
|
||||
IN_EXT_C = .c
|
||||
IN_EXT_CXX = .cpp
|
||||
LIBS =
|
||||
OUT_EXT = .out
|
||||
|
||||
OUTS := $(foreach IN_EXT,$(IN_EXT_C) $(IN_EXT_CXX),$(addsuffix $(OUT_EXT), $(basename $(wildcard *$(IN_EXT)))))
|
||||
ifeq ($(BR2_PACKAGE_EIGEN),y)
|
||||
|
||||
44
kernel_module/user/bst_vs_heap.cpp
Normal file
44
kernel_module/user/bst_vs_heap.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
/* https://github.com/cirosantilli/linux-kernel-module-cheat#bst-vs-heap */
|
||||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <queue>
|
||||
#include <random>
|
||||
#include <set>
|
||||
|
||||
#include "m5ops.h"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
typedef uint64_t I;
|
||||
std::vector<I> randoms;
|
||||
size_t i, n;
|
||||
std::priority_queue<I> heap;
|
||||
std::set<I> bst;
|
||||
unsigned int seed = std::random_device()();
|
||||
|
||||
// CLI arguments.
|
||||
if (argc > 1) {
|
||||
n = std::stoi(argv[1]);
|
||||
} else {
|
||||
n = 1000;
|
||||
}
|
||||
|
||||
// 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; ++i) {
|
||||
auto random = randoms[i];
|
||||
|
||||
// Heap.
|
||||
m5_resetstats();
|
||||
heap.emplace(random);
|
||||
m5_dumpstats();
|
||||
|
||||
// BST.
|
||||
m5_resetstats();
|
||||
bst.insert(random);
|
||||
m5_dumpstats();
|
||||
}
|
||||
}
|
||||
@@ -4,63 +4,10 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define ENABLED 1
|
||||
#if defined(__arm__)
|
||||
static void m5_checkpoint(void)
|
||||
{
|
||||
__asm__ __volatile__ ("mov r0, #0; mov r1, #0; mov r2, #0; mov r3, #0; .inst 0xEE000110 | (0x43 << 16);");
|
||||
};
|
||||
static void m5_dump_stats(void)
|
||||
{
|
||||
__asm__ __volatile__ ("mov r0, #0; mov r1, #0; mov r2, #0; mov r3, #0; .inst 0xEE000110 | (0x41 << 16);");
|
||||
};
|
||||
static void m5_exit()
|
||||
{
|
||||
__asm__ __volatile__ ("mov r0, #0; .inst 0xEE000110 | (0x21 << 16);");
|
||||
};
|
||||
static void m5_fail_1(void)
|
||||
{
|
||||
__asm__ __volatile__ ("mov r0, #0; mov r1, #0; mov r2, #1; mov r3, #0; .inst 0xEE000110 | (0x22 << 16);");
|
||||
};
|
||||
static void m5_reset_stats(void)
|
||||
{
|
||||
__asm__ __volatile__ ("mov r0, #0; mov r1, #0; mov r2, #0; mov r3, #0; .inst 0xEE000110 | (0x40 << 16);");
|
||||
};
|
||||
#elif defined(__aarch64__)
|
||||
static void m5_checkpoint(void)
|
||||
{
|
||||
__asm__ __volatile__ ("mov x0, #0; mov x1, #0; .inst 0xFF000110 | (0x43 << 16);");
|
||||
};
|
||||
static void m5_dump_stats(void)
|
||||
{
|
||||
__asm__ __volatile__ ("mov x0, #0; mov x1, #0; .inst 0xFF000110 | (0x41 << 16);");
|
||||
};
|
||||
static void m5_exit(void)
|
||||
{
|
||||
__asm__ __volatile__ ("mov x0, #0; .inst 0XFF000110 | (0x21 << 16);");
|
||||
};
|
||||
static void m5_fail_1(void)
|
||||
{
|
||||
__asm__ __volatile__ ("mov x0, #0; mov x1, #1; .inst 0xFF000110 | (0x22 << 16);");
|
||||
};
|
||||
static void m5_reset_stats(void)
|
||||
{
|
||||
__asm__ __volatile__ ("mov x0, #0; mov x1, #0; .inst 0XFF000110 | (0x40 << 16);");
|
||||
};
|
||||
#else
|
||||
#undef ENABLED
|
||||
#define ENABLED 0
|
||||
#endif
|
||||
#include "m5ops.h"
|
||||
|
||||
int main(
|
||||
#if ENABLED
|
||||
int argc, char **argv
|
||||
#else
|
||||
void
|
||||
#endif
|
||||
)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
#if ENABLED
|
||||
char action;
|
||||
if (argc > 1) {
|
||||
action = argv[1][0];
|
||||
@@ -73,7 +20,7 @@ void
|
||||
m5_checkpoint();
|
||||
break;
|
||||
case 'd':
|
||||
m5_dump_stats();
|
||||
m5_dumpstats();
|
||||
break;
|
||||
case 'e':
|
||||
m5_exit();
|
||||
@@ -82,9 +29,8 @@ void
|
||||
m5_fail_1();
|
||||
break;
|
||||
case 'r':
|
||||
m5_reset_stats();
|
||||
m5_resetstats();
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
54
kernel_module/user/m5ops.h
Normal file
54
kernel_module/user/m5ops.h
Normal file
@@ -0,0 +1,54 @@
|
||||
#ifndef M5OPS_H
|
||||
#define M5OPS_H
|
||||
|
||||
#if defined(__arm__)
|
||||
static void m5_checkpoint(void)
|
||||
{
|
||||
__asm__ __volatile__ ("mov r0, #0; mov r1, #0; mov r2, #0; mov r3, #0; .inst 0xEE000110 | (0x43 << 16);");
|
||||
};
|
||||
static void m5_dumpstats(void)
|
||||
{
|
||||
__asm__ __volatile__ ("mov r0, #0; mov r1, #0; mov r2, #0; mov r3, #0; .inst 0xEE000110 | (0x41 << 16);");
|
||||
};
|
||||
static void m5_exit()
|
||||
{
|
||||
__asm__ __volatile__ ("mov r0, #0; .inst 0xEE000110 | (0x21 << 16);");
|
||||
};
|
||||
static void m5_fail_1(void)
|
||||
{
|
||||
__asm__ __volatile__ ("mov r0, #0; mov r1, #0; mov r2, #1; mov r3, #0; .inst 0xEE000110 | (0x22 << 16);");
|
||||
};
|
||||
static void m5_resetstats(void)
|
||||
{
|
||||
__asm__ __volatile__ ("mov r0, #0; mov r1, #0; mov r2, #0; mov r3, #0; .inst 0xEE000110 | (0x40 << 16);");
|
||||
};
|
||||
#elif defined(__aarch64__)
|
||||
static void m5_checkpoint(void)
|
||||
{
|
||||
__asm__ __volatile__ ("mov x0, #0; mov x1, #0; .inst 0xFF000110 | (0x43 << 16);");
|
||||
};
|
||||
static void m5_dumpstats(void)
|
||||
{
|
||||
__asm__ __volatile__ ("mov x0, #0; mov x1, #0; .inst 0xFF000110 | (0x41 << 16);");
|
||||
};
|
||||
static void m5_exit(void)
|
||||
{
|
||||
__asm__ __volatile__ ("mov x0, #0; .inst 0XFF000110 | (0x21 << 16);");
|
||||
};
|
||||
static void m5_fail_1(void)
|
||||
{
|
||||
__asm__ __volatile__ ("mov x0, #0; mov x1, #1; .inst 0xFF000110 | (0x22 << 16);");
|
||||
};
|
||||
static void m5_resetstats(void)
|
||||
{
|
||||
__asm__ __volatile__ ("mov x0, #0; mov x1, #0; .inst 0XFF000110 | (0x40 << 16);");
|
||||
};
|
||||
#else
|
||||
static void m5_checkpoint(void) {};
|
||||
static void m5_dumpstats(void) {};
|
||||
static void m5_exit(void) {};
|
||||
static void m5_fail_1(void) {};
|
||||
static void m5_resetstats(void) {};
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user