From 24cdcdc756ebcf4f6d813968c0084a7158a022d9 Mon Sep 17 00:00:00 2001 From: Ciro Santilli Date: Sun, 15 Apr 2018 23:23:40 +0100 Subject: [PATCH] readme: document rdtsc --- README.adoc | 38 ++++++++++++++++++++++++++++++++++++-- kernel_module/pmccntr.c | 7 ------- kernel_module/user/rdtsc.c | 3 +-- 3 files changed, 37 insertions(+), 11 deletions(-) diff --git a/README.adoc b/README.adoc index 63ea353..8136561 100644 --- a/README.adoc +++ b/README.adoc @@ -327,6 +327,7 @@ printk debug .... head kernel_module/modulename.c +grep 'modulename\.' README.adoc .... Many of the modules have userland test scripts / executables with the same name as the module, e.g. form inside the guest: @@ -3357,7 +3358,7 @@ and also: `gem5-dist`: https://publish.illinois.edu/icsl-pdgem5/ Clock frequency: TODO how does it affect performance in benchmarks? .... -./run -a arm -g -- --cpu-clock 10000000 +./run -a aarch64 -g -- --cpu-clock 10000000 .... Check with: @@ -3369,7 +3370,7 @@ m5 resetstats && sleep 10 && m5 dumpstats and then: .... -grep numCycles out/aarch64/gem5/m5out/stats.txt +./gem5-stat -a aarch64 .... TODO: why doesn't this exist: @@ -4163,6 +4164,39 @@ chmoe +x /tmp/execfile m5 execfile .... +=== gem5 stats + +Lets try to understand some stats better. + +==== rdtsc + +.... +./build -kg && ./run -E '/rdtsc.out;m5 exit;' -g +./gem5-stat +.... + +gives cycle counts: + +* `3828578153` +* `3830832635` + +Which are pretty close, and serve as a nice sanity check that the cycle counter is coherent. + +It is also nice to see that `rdtsc` is a bit smaller than the `stats.txt` value, since the latter also includes the exec syscall for `m5`. + +See also: + +* https://en.wikipedia.org/wiki/Time_Stamp_Counter +* https://stackoverflow.com/questions/9887839/clock-cycle-count-wth-gcc/9887979 + +===== pmccntr kernel module + +Unfortunately-we didn't manage to find an ARM analogue: link:kernel_module/pmccntr.c[] is oopsing, and even it if weren't, it likely won't give the cycle count since boot since it needs to be activate before it starts counting anything: + +* https://stackoverflow.com/questions/40454157/is-there-an-equivalent-instruction-to-rdtsc-in-arm +* https://stackoverflow.com/questions/31620375/arm-cortex-a7-returning-pmccntr-0-in-kernel-mode-and-illegal-instruction-in-u/31649809#31649809 +* https://blog.regehr.org/archives/794 + === gem5 limitations * networking not working. We currently just disable it from `inittab` by default to prevent waiting at startup diff --git a/kernel_module/pmccntr.c b/kernel_module/pmccntr.c index 9246e41..bd1dca1 100644 --- a/kernel_module/pmccntr.c +++ b/kernel_module/pmccntr.c @@ -1,11 +1,5 @@ /* ARM only. - -TODO not working. - -* https://stackoverflow.com/questions/40454157/is-there-an-equivalent-instruction-to-rdtsc-in-arm -* https://stackoverflow.com/questions/31620375/arm-cortex-a7-returning-pmccntr-0-in-kernel-mode-and-illegal-instruction-in-u/31649809#31649809 -* https://blog.regehr.org/archives/794 */ #include @@ -17,7 +11,6 @@ TODO not working. #include /* copy_from_user, copy_to_user */ #include /* S_IRUSR */ - static struct dentry *debugfs_file; static int show(struct seq_file *m, void *v) diff --git a/kernel_module/user/rdtsc.c b/kernel_module/user/rdtsc.c index baf50c0..949ec65 100644 --- a/kernel_module/user/rdtsc.c +++ b/kernel_module/user/rdtsc.c @@ -16,11 +16,10 @@ Only works in x86_64. int main(void) { uintmax_t val; #if defined(__i386__) || defined(__x86_64__) - /* https://stackoverflow.com/questions/9887839/clock-cycle-count-wth-gcc/9887979 */ val = __rdtsc(); #else val = 0; #endif - printf("%jx\n", val); + printf("%ju\n", val); return EXIT_SUCCESS; }