Skip to content

Commit 7ccc1d3

Browse files
committed
m5ops: move to factored .h file
Create empty subs for unsupported archs, much less messy for callers. bst_vs_heap: create
1 parent eb4f4ba commit 7ccc1d3

File tree

6 files changed

+142
-64
lines changed

6 files changed

+142
-64
lines changed

README.adoc

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7415,7 +7415,9 @@ A flexible setup is:
74157415
....
74167416
arch=aarch64
74177417
cmd="./run -a '$arch' -g -F '/gem5.sh'"
7418-
restore='-l 1 -- --cpu-type=HPI --restore-with-cpu=HPI --caches --l2cache --l1d_size=1024kB --l1i_size=1024kB --l2_size=1024kB --l3_size=1024kB'
7418+
# These cache sizes roughly match the ARM Cortex A75
7419+
# https://en.wikipedia.org/wiki/ARM_Cortex-A75
7420+
restore='-l 1 -- --cpu-type=HPI --restore-with-cpu=HPI --caches --l2cache --l1d_size=128kB --l1i_size=1024kB --l2_size=256kB'
74197421
74207422
# Generate a checkpoint after Linux boots, using the faster and less detailed CPU.
74217423
# The boot takes a while, be patient young Padawan.
@@ -7702,6 +7704,25 @@ Buildroot built-in libraries, mostly under Libraries > Other:
77027704

77037705
There are not yet enabled, but it should be easy to so, see: <<add-new-buildroot-packages>>
77047706

7707+
===== BST vs heap
7708+
7709+
https://stackoverflow.com/questions/6147242/heap-vs-binary-search-tree-bst/29548834#29548834
7710+
7711+
Usage:
7712+
7713+
....
7714+
printf '/bst_vs_heap.out' > data/readfile
7715+
./run -aA -g -F '/gem5.sh'
7716+
./bst-vs-heap > bst_vs_heap.dat
7717+
....
7718+
7719+
and then feed `bst_vs_heap.dat` into: https://github.com/cirosantilli/cpp-cheat/blob/9d0f77792fc8e55b20b6ee32018761ef3c5a3f2f/cpp/interactive/bst_vs_heap.gnuplot
7720+
7721+
Sources:
7722+
7723+
* link:bst-vs-heap[]
7724+
* link:kernel_module/user/bst_vs_heap.cpp[]
7725+
77057726
===== OpenMP
77067727

77077728
Implemented by GCC itself, so just a toolchain configuration, no external libs, and we enable it by default:

bst-vs-heap

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common"
3+
while getopts "${common_getopts_flags}" OPT; do
4+
case "$OPT" in
5+
?)
6+
common_getopts_case "$OPT"
7+
;;
8+
esac
9+
done
10+
shift "$(($OPTIND - 1))"
11+
"${common_root_dir}/gem5-stat" -a "$common_arch" | awk 'NR % 2 { printf "%d %s ", NR/2, $0; next; } 1'

kernel_module/user/Makefile

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
.PHONY: all clean
22

3-
CFLAGS_EXTRA ?= -fopenmp -std=c99 -Wall -Werror -Wextra
4-
IN_EXT_C ?= .c
5-
IN_EXT_CXX ?= .cpp
6-
LIBS :=
7-
OUT_EXT ?= .out
3+
CFLAGS_EXTRA = -fopenmp -std=c99
4+
CXXFLAGS_EXTRA = -std=c++17
5+
CCFLAGS_EXTRA = -Wall -Werror -Wextra
6+
IN_EXT_C = .c
7+
IN_EXT_CXX = .cpp
8+
LIBS =
9+
OUT_EXT = .out
810

911
OUTS := $(foreach IN_EXT,$(IN_EXT_C) $(IN_EXT_CXX),$(addsuffix $(OUT_EXT), $(basename $(wildcard *$(IN_EXT)))))
1012
ifeq ($(BR2_PACKAGE_EIGEN),y)

kernel_module/user/bst_vs_heap.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/* https://github.com/cirosantilli/linux-kernel-module-cheat#bst-vs-heap */
2+
3+
#include <algorithm>
4+
#include <iostream>
5+
#include <queue>
6+
#include <random>
7+
#include <set>
8+
9+
#include "m5ops.h"
10+
11+
int main(int argc, char **argv) {
12+
typedef uint64_t I;
13+
std::vector<I> randoms;
14+
size_t i, n;
15+
std::priority_queue<I> heap;
16+
std::set<I> bst;
17+
unsigned int seed = std::random_device()();
18+
19+
// CLI arguments.
20+
if (argc > 1) {
21+
n = std::stoi(argv[1]);
22+
} else {
23+
n = 1000;
24+
}
25+
26+
// Action.
27+
for (i = 0; i < n; ++i) {
28+
randoms.push_back(i);
29+
}
30+
std::shuffle(randoms.begin(), randoms.end(), std::mt19937(seed));
31+
for (i = 0; i < n; ++i) {
32+
auto random = randoms[i];
33+
34+
// Heap.
35+
m5_resetstats();
36+
heap.emplace(random);
37+
m5_dumpstats();
38+
39+
// BST.
40+
m5_resetstats();
41+
bst.insert(random);
42+
m5_dumpstats();
43+
}
44+
}

kernel_module/user/m5ops.c

Lines changed: 4 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -4,63 +4,10 @@
44
#include <stdio.h>
55
#include <stdlib.h>
66

7-
#define ENABLED 1
8-
#if defined(__arm__)
9-
static void m5_checkpoint(void)
10-
{
11-
__asm__ __volatile__ ("mov r0, #0; mov r1, #0; mov r2, #0; mov r3, #0; .inst 0xEE000110 | (0x43 << 16);");
12-
};
13-
static void m5_dump_stats(void)
14-
{
15-
__asm__ __volatile__ ("mov r0, #0; mov r1, #0; mov r2, #0; mov r3, #0; .inst 0xEE000110 | (0x41 << 16);");
16-
};
17-
static void m5_exit()
18-
{
19-
__asm__ __volatile__ ("mov r0, #0; .inst 0xEE000110 | (0x21 << 16);");
20-
};
21-
static void m5_fail_1(void)
22-
{
23-
__asm__ __volatile__ ("mov r0, #0; mov r1, #0; mov r2, #1; mov r3, #0; .inst 0xEE000110 | (0x22 << 16);");
24-
};
25-
static void m5_reset_stats(void)
26-
{
27-
__asm__ __volatile__ ("mov r0, #0; mov r1, #0; mov r2, #0; mov r3, #0; .inst 0xEE000110 | (0x40 << 16);");
28-
};
29-
#elif defined(__aarch64__)
30-
static void m5_checkpoint(void)
31-
{
32-
__asm__ __volatile__ ("mov x0, #0; mov x1, #0; .inst 0xFF000110 | (0x43 << 16);");
33-
};
34-
static void m5_dump_stats(void)
35-
{
36-
__asm__ __volatile__ ("mov x0, #0; mov x1, #0; .inst 0xFF000110 | (0x41 << 16);");
37-
};
38-
static void m5_exit(void)
39-
{
40-
__asm__ __volatile__ ("mov x0, #0; .inst 0XFF000110 | (0x21 << 16);");
41-
};
42-
static void m5_fail_1(void)
43-
{
44-
__asm__ __volatile__ ("mov x0, #0; mov x1, #1; .inst 0xFF000110 | (0x22 << 16);");
45-
};
46-
static void m5_reset_stats(void)
47-
{
48-
__asm__ __volatile__ ("mov x0, #0; mov x1, #0; .inst 0XFF000110 | (0x40 << 16);");
49-
};
50-
#else
51-
#undef ENABLED
52-
#define ENABLED 0
53-
#endif
7+
#include "m5ops.h"
548

55-
int main(
56-
#if ENABLED
57-
int argc, char **argv
58-
#else
59-
void
60-
#endif
61-
)
9+
int main(int argc, char **argv)
6210
{
63-
#if ENABLED
6411
char action;
6512
if (argc > 1) {
6613
action = argv[1][0];
@@ -73,7 +20,7 @@ void
7320
m5_checkpoint();
7421
break;
7522
case 'd':
76-
m5_dump_stats();
23+
m5_dumpstats();
7724
break;
7825
case 'e':
7926
m5_exit();
@@ -82,9 +29,8 @@ void
8229
m5_fail_1();
8330
break;
8431
case 'r':
85-
m5_reset_stats();
32+
m5_resetstats();
8633
break;
8734
}
88-
#endif
8935
return EXIT_SUCCESS;
9036
}

kernel_module/user/m5ops.h

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#ifndef M5OPS_H
2+
#define M5OPS_H
3+
4+
#if defined(__arm__)
5+
static void m5_checkpoint(void)
6+
{
7+
__asm__ __volatile__ ("mov r0, #0; mov r1, #0; mov r2, #0; mov r3, #0; .inst 0xEE000110 | (0x43 << 16);");
8+
};
9+
static void m5_dumpstats(void)
10+
{
11+
__asm__ __volatile__ ("mov r0, #0; mov r1, #0; mov r2, #0; mov r3, #0; .inst 0xEE000110 | (0x41 << 16);");
12+
};
13+
static void m5_exit()
14+
{
15+
__asm__ __volatile__ ("mov r0, #0; .inst 0xEE000110 | (0x21 << 16);");
16+
};
17+
static void m5_fail_1(void)
18+
{
19+
__asm__ __volatile__ ("mov r0, #0; mov r1, #0; mov r2, #1; mov r3, #0; .inst 0xEE000110 | (0x22 << 16);");
20+
};
21+
static void m5_resetstats(void)
22+
{
23+
__asm__ __volatile__ ("mov r0, #0; mov r1, #0; mov r2, #0; mov r3, #0; .inst 0xEE000110 | (0x40 << 16);");
24+
};
25+
#elif defined(__aarch64__)
26+
static void m5_checkpoint(void)
27+
{
28+
__asm__ __volatile__ ("mov x0, #0; mov x1, #0; .inst 0xFF000110 | (0x43 << 16);");
29+
};
30+
static void m5_dumpstats(void)
31+
{
32+
__asm__ __volatile__ ("mov x0, #0; mov x1, #0; .inst 0xFF000110 | (0x41 << 16);");
33+
};
34+
static void m5_exit(void)
35+
{
36+
__asm__ __volatile__ ("mov x0, #0; .inst 0XFF000110 | (0x21 << 16);");
37+
};
38+
static void m5_fail_1(void)
39+
{
40+
__asm__ __volatile__ ("mov x0, #0; mov x1, #1; .inst 0xFF000110 | (0x22 << 16);");
41+
};
42+
static void m5_resetstats(void)
43+
{
44+
__asm__ __volatile__ ("mov x0, #0; mov x1, #0; .inst 0XFF000110 | (0x40 << 16);");
45+
};
46+
#else
47+
static void m5_checkpoint(void) {};
48+
static void m5_dumpstats(void) {};
49+
static void m5_exit(void) {};
50+
static void m5_fail_1(void) {};
51+
static void m5_resetstats(void) {};
52+
#endif
53+
54+
#endif

0 commit comments

Comments
 (0)