mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
userland/arch/aarch64/freestanding/linux/gem5_exit.S to benchmark immediate gem5 exit
ldxr_stxr does an ldxr on thread 0 to fall in the ISA case where event is certain. Also add ldxr_str which tests yet another case where event is certain: non conditional write.
This commit is contained in:
10
userland/arch/aarch64/freestanding/linux/gem5_exit.S
Normal file
10
userland/arch/aarch64/freestanding/linux/gem5_exit.S
Normal file
@@ -0,0 +1,10 @@
|
||||
/* https://cirosantilli.com/linux-kernel-module-cheat#benchmark-emulators-on-userland-executables */
|
||||
|
||||
#define LKMC_M5OPS_ENABLE 1
|
||||
#include "lkmc/m5ops.h"
|
||||
|
||||
.text
|
||||
.global _start
|
||||
_start:
|
||||
asm_main_after_prologue:
|
||||
LKMC_M5OPS_EXIT_ASM
|
||||
35
userland/arch/aarch64/inline_asm/wfe_ldxr_str.cpp
Normal file
35
userland/arch/aarch64/inline_asm/wfe_ldxr_str.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
// https://cirosantilli.com/linux-kernel-module-cheat#arm-wfe-global-monitor-events
|
||||
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
#include <atomic>
|
||||
#include <iostream>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
|
||||
#include <lkmc/futex.h>
|
||||
|
||||
std::atomic_ulong done;
|
||||
int futex = 1;
|
||||
|
||||
void myfunc() {
|
||||
__asm__ __volatile__ ("ldxr x0, [%0];wfe;wfe" : : "r" (&futex) : "x0");
|
||||
done.store(futex);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
bool do_sev = true;
|
||||
if (argc > 1) {
|
||||
do_sev = (argv[1][0] != '0');
|
||||
}
|
||||
done.store(0);
|
||||
std::thread thread;
|
||||
thread = std::thread(myfunc);
|
||||
while (!done.load()) {
|
||||
if (do_sev) {
|
||||
__asm__ __volatile__ ("mov x0, 1;str x0, [%0]" : : "r" (&futex) : "x0", "x1");
|
||||
}
|
||||
}
|
||||
thread.join();
|
||||
}
|
||||
@@ -28,7 +28,7 @@ int main(int argc, char **argv) {
|
||||
thread = std::thread(myfunc);
|
||||
while (!done.load()) {
|
||||
if (do_sev) {
|
||||
__asm__ __volatile__ ("mov x0, 1;stxr w1, x0, [%0]" : : "r" (&futex) : "x0", "x1");
|
||||
__asm__ __volatile__ ("mov x0, 1;ldxr x0, [%0];stxr w1, x0, [%0]" : : "r" (&futex) : "x0", "x1");
|
||||
}
|
||||
}
|
||||
thread.join();
|
||||
|
||||
Reference in New Issue
Block a user