mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-22 17:55:57 +01:00
http.js
This commit is contained in:
55
README.adoc
55
README.adoc
@@ -13048,12 +13048,58 @@ Library support is automatically detected, and only built if you have it install
|
||||
|
||||
===== gem5 only dump selected stats
|
||||
|
||||
TODO
|
||||
|
||||
https://stackoverflow.com/questions/52014953/how-to-dump-only-a-single-or-certain-selected-stats-in-gem5
|
||||
|
||||
To prevent the stats file from becoming humongous.
|
||||
|
||||
https://stackoverflow.com/questions/52014953/how-to-dump-only-a-single-or-certain-selected-stats-in-gem5/57221132#57221132
|
||||
|
||||
===== Meaning of each gem5 stat
|
||||
|
||||
Well, run minimal examples, and reverse engineer them up!
|
||||
|
||||
We can start with link:userland/arch/x86_64/freestanding/linux/hello.S[] on atomic with <<gem5-execall-trace-format>>.
|
||||
|
||||
....
|
||||
./run \
|
||||
--arch aarch64 \
|
||||
--emulator gem5 \
|
||||
--userland userland/arch/aarch64/freestanding/linux/hello.S \
|
||||
--trace ExecAll \
|
||||
--trace-stdout \
|
||||
;
|
||||
....
|
||||
|
||||
which gives:
|
||||
|
||||
....
|
||||
0: system.cpu: A0 T0 : @_start : movz x0, #1, #0 : IntAlu : D=0x0000000000000001 flags=(IsInteger)
|
||||
500: system.cpu: A0 T0 : @_start+4 : adr x1, #28 : IntAlu : D=0x0000000000400098 flags=(IsInteger)
|
||||
1000: system.cpu: A0 T0 : @_start+8 : ldr w2, #4194464 : MemRead : D=0x0000000000000006 A=0x4000a0 flags=(IsInteger|IsMemRef|IsLoad)
|
||||
1500: system.cpu: A0 T0 : @_start+12 : movz x8, #64, #0 : IntAlu : D=0x0000000000000040 flags=(IsInteger)
|
||||
2000: system.cpu: A0 T0 : @_start+16 : svc #0x0 : IntAlu : flags=(IsSerializeAfter|IsNonSpeculative|IsSyscall)
|
||||
2500: system.cpu: A0 T0 : @_start+20 : movz x0, #0, #0 : IntAlu : D=0x0000000000000000 flags=(IsInteger)
|
||||
3000: system.cpu: A0 T0 : @_start+24 : movz x8, #93, #0 : IntAlu : D=0x000000000000005d flags=(IsInteger)
|
||||
3500: system.cpu: A0 T0 : @_start+28 : svc #0x0 : IntAlu : flags=(IsSerializeAfter|IsNonSpeculative|IsSyscall)
|
||||
....
|
||||
|
||||
The most important stat of all is usually the cycle count, which is a direct measure of performance if you modelled you system well:
|
||||
|
||||
....
|
||||
sim_ticks 3500 # Number of ticks simulated
|
||||
....
|
||||
|
||||
Next, `sim_insts` and `sim_ops` are often critical:
|
||||
|
||||
....
|
||||
sim_insts 6 # Number of instructions simulated
|
||||
sim_ops 6 # Number of ops (including micro ops) simulated
|
||||
....
|
||||
|
||||
`sim_ops` is like `sim_insts` but it also includes <<gem5-microops>>.
|
||||
|
||||
In <<gem5-syscall-emulation-mode>>, syscall instructions are magic, and therefore appear to not be counted, that is why we get 6 instructions instead of 8.
|
||||
|
||||
===== gem5 stats internals
|
||||
|
||||
This describes the internals of the <<gem5-m5out-stats-txt-file>>.
|
||||
@@ -13183,7 +13229,7 @@ On Ubuntu 20.04, you can also see the dot file "directly" with xdot:
|
||||
xdot "$(./getvar --arch arm --emulator gem5 m5out_dir)/config.dot"
|
||||
....
|
||||
|
||||
which is kind of really cool because it allows you to graph arrows with clicks.
|
||||
which is kind of really cool because it allows you to view graph arrows on hover. This can be very useful because the PDF and SVG often overlap so many arrows together that you just can't know which one is coming from/going to where.
|
||||
|
||||
It is worth noting that if you are running a bunch of short simulations, dot/SVG/PDF generation could have a significant impact in simulation startup time, so it is something to watch out for. As per https://gem5-review.googlesource.com/c/public/gem5/+/29232 it can be turned off with:
|
||||
|
||||
@@ -13392,7 +13438,7 @@ A trivial and very direct way to see message would be:
|
||||
....
|
||||
./run \
|
||||
--emulator gem5 \
|
||||
--userland \userland/arch/x86_64/freestanding/linux/hello.S \
|
||||
--userland userland/arch/x86_64/freestanding/linux/hello.S \
|
||||
--trace-insts-stdout \
|
||||
-- \
|
||||
--param 'system.cpu[0].max_insts_all_threads = 3' \
|
||||
@@ -20155,6 +20201,7 @@ MyClassToString { a: 1, b: 2 }
|
||||
toString
|
||||
my type is MyClassToString and a is 1 and b is 2
|
||||
....
|
||||
* link:rootfs_overlay/lkmc/nodejs/http.js[]: `http` module to create a simple HTTP server: https://nodejs.org/api/http.html
|
||||
|
||||
===== NPM
|
||||
|
||||
|
||||
46
baremetal/arch/arm/enable_cache.S
Normal file
46
baremetal/arch/arm/enable_cache.S
Normal file
@@ -0,0 +1,46 @@
|
||||
/* TODO not working on gem5. Maybe we need to flush some pipelines after the sysreg accesses. */
|
||||
|
||||
#include <lkmc.h>
|
||||
|
||||
#define NELEM 4
|
||||
#define ELEM_SIZE 4
|
||||
|
||||
.data;
|
||||
.align 4
|
||||
my_array_1:
|
||||
.word 0x11111111, 0x22222222, 0x33333333, 0x44444444
|
||||
my_array_2:
|
||||
.word 0x99999999, 0xAAAAAAAA, 0xBBBBBBBB, 0xCCCCCCCC
|
||||
|
||||
LKMC_PROLOGUE
|
||||
|
||||
/* Modify the array. */
|
||||
ldr r4, =my_array_1
|
||||
ldr r5, =0x55555555
|
||||
ldr r6, =0x66666666
|
||||
ldr r7, =0x77777777
|
||||
ldr r8, =0x88888888
|
||||
stmia r4, {r5-r8}
|
||||
|
||||
mrc p15, 0, r0, c1, c0, 0
|
||||
orr r0, r0, (1 << 2) /* SCTLR.C */
|
||||
orr r0, r0, (1 << 28) /* SCTLR.TRE */
|
||||
mcr p15, 0, r0, c1, c0, 0
|
||||
|
||||
mrc p15, 0, r0, c9, c2, 1
|
||||
orr r0, r0, 1 /* NMRR.IR0 */
|
||||
orr r0, r0, (1 << 16) /* NMRR.OR0 */
|
||||
mcr p15, 0, r0, c9, c2, 1
|
||||
|
||||
/* Modify the again. */
|
||||
ldr r4, =my_array_1
|
||||
ldr r5, =0x99999999
|
||||
ldr r6, =0xAAAAAAAA
|
||||
ldr r7, =0xBBBBBBBB
|
||||
ldr r8, =0xCCCCCCCC
|
||||
stmia r4, {r5-r8}
|
||||
|
||||
/* Verify that my_array_0 changed and is equal to my_array_1. */
|
||||
LKMC_ASSERT_MEMCMP(my_array_1, my_array_2, =0x10)
|
||||
|
||||
LKMC_EPILOGUE
|
||||
@@ -24,6 +24,7 @@ void lkmc_dump_system_regs() {
|
||||
__asm__ ("mrs %0, sctlr_el1" : "=r" (sctlr_el1) : :);
|
||||
LKMC_DUMP_SYSTEM_REGS_PRINTF("SCTLR_EL1 0x%" PRIX32 "\n", sctlr_el1);
|
||||
LKMC_DUMP_SYSTEM_REGS_PRINTF("SCTLR_EL1.nTWE 0x%" PRIX32 "\n", (sctlr_el1 >> 18) & 1);
|
||||
LKMC_DUMP_SYSTEM_REGS_PRINTF("SCTLR_EL1.C 0x%" PRIX32 "\n", (sctlr_el1 >> 2) & 1);
|
||||
LKMC_DUMP_SYSTEM_REGS_PRINTF("SCTLR_EL1.A 0x%" PRIX32 "\n", (sctlr_el1 >> 1) & 1);
|
||||
/* https://cirosantilli.com/linux-kernel-module-cheat#arm-paging */
|
||||
LKMC_DUMP_SYSTEM_REGS_PRINTF("SCTLR_EL1.M 0x%" PRIX32 "\n", (sctlr_el1 >> 0) & 1);
|
||||
|
||||
38
rootfs_overlay/lkmc/nodejs/http.js
Executable file
38
rootfs_overlay/lkmc/nodejs/http.js
Executable file
@@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
// https://cirosantilli.com/linux-kernel-module-cheat#node-js
|
||||
|
||||
const http = require('http');
|
||||
const util = require('util');
|
||||
const url = require('url');
|
||||
|
||||
http.createServer(
|
||||
(req, res) => {
|
||||
const myUrl = new url.URL(req.url, 'http://example.com');
|
||||
const searchString = [];
|
||||
for (const [key, value] of myUrl.searchParams) {
|
||||
searchString.push(`<div>${key}: ${value}</div>\n`)
|
||||
}
|
||||
const reqString = [];
|
||||
for (let prop of Object.keys(req).sort()) {
|
||||
reqString.push(`<div>${prop}: ${util.inspect(req[prop])}</div>\n`);
|
||||
}
|
||||
ret = `<!doctype html>
|
||||
<html lang=en>
|
||||
<head>
|
||||
<meta charset=utf-8>
|
||||
<title>hello html</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>req.url: ${req.url}</div>
|
||||
<div>url.pathname: ${myUrl.pathname}</div>
|
||||
<div>url.search:</div>
|
||||
${searchString.join('')}
|
||||
<div>req:</div>
|
||||
${reqString.join('')}
|
||||
</body>
|
||||
</html>
|
||||
`
|
||||
res.write(ret);
|
||||
res.end();
|
||||
}).listen(8080);
|
||||
Reference in New Issue
Block a user