mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
improve gem5 memory model and cpufreq experiments
This commit is contained in:
28
userland/c/malloc_touch.c
Normal file
28
userland/c/malloc_touch.c
Normal file
@@ -0,0 +1,28 @@
|
||||
/* https://cirosantilli.com/linux-kernel-module-cheat#gem5-memory-latency */
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
size_t nbytes, step;
|
||||
if (argc > 1) {
|
||||
nbytes = strtoull(argv[1], NULL, 0);
|
||||
} else {
|
||||
nbytes = 0x10;
|
||||
}
|
||||
if (argc > 2) {
|
||||
step = strtoull(argv[2], NULL, 0);
|
||||
} else {
|
||||
step = 1;
|
||||
}
|
||||
|
||||
char *base = malloc(nbytes);
|
||||
assert(base);
|
||||
char *i = base;
|
||||
while (i < base + nbytes) {
|
||||
*i = 13;
|
||||
i += step;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -8,9 +8,9 @@ void __attribute__ ((noinline)) busy_loop(
|
||||
unsigned long long max,
|
||||
unsigned long long max2
|
||||
) {
|
||||
for (unsigned long long i = 0; i < max; i++) {
|
||||
for (unsigned long long j = 0; j < max2; j++) {
|
||||
__asm__ __volatile__ ("" : "+g" (j), "+g" (j) : :);
|
||||
for (unsigned long long i = 0; i < max2; i++) {
|
||||
for (unsigned long long j = 0; j < max; j++) {
|
||||
__asm__ __volatile__ ("" : "+g" (i), "+g" (j) : :);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,11 +5,31 @@
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define SYSCONF(x) printf("_SC_%-23s = %ld\n", #x, sysconf(_SC_ ## x))
|
||||
|
||||
int main(void) {
|
||||
/* Number of processors, not considering affinity:
|
||||
* http://stackoverflow.com/questions/2693948/how-do-i-retrieve-the-number-of-processors-on-c-linux */
|
||||
printf("_SC_NPROCESSORS_ONLN = %ld\n", sysconf(_SC_NPROCESSORS_ONLN));
|
||||
SYSCONF(NPROCESSORS_ONLN);
|
||||
/* CPUs configured by OS during boot. Some may have gone offline, so could be larger than _SC_NPROCESSORS_ONLN.a */
|
||||
printf("_SC_NPROCESSORS_CONF = %ld\n", sysconf(_SC_NPROCESSORS_CONF));
|
||||
SYSCONF(NPROCESSORS_CONF);
|
||||
|
||||
/* https://cirosantilli.com/linux-kernel-module-cheat#gem5-cache-size */
|
||||
SYSCONF(LEVEL1_ICACHE_SIZE);
|
||||
SYSCONF(LEVEL1_ICACHE_ASSOC);
|
||||
SYSCONF(LEVEL1_ICACHE_LINESIZE);
|
||||
SYSCONF(LEVEL1_DCACHE_SIZE);
|
||||
SYSCONF(LEVEL1_DCACHE_ASSOC);
|
||||
SYSCONF(LEVEL1_DCACHE_LINESIZE);
|
||||
SYSCONF(LEVEL2_CACHE_SIZE);
|
||||
SYSCONF(LEVEL2_CACHE_ASSOC);
|
||||
SYSCONF(LEVEL2_CACHE_LINESIZE);
|
||||
SYSCONF(LEVEL3_CACHE_SIZE);
|
||||
SYSCONF(LEVEL3_CACHE_ASSOC);
|
||||
SYSCONF(LEVEL3_CACHE_LINESIZE);
|
||||
SYSCONF(LEVEL4_CACHE_SIZE);
|
||||
SYSCONF(LEVEL4_CACHE_ASSOC);
|
||||
SYSCONF(LEVEL4_CACHE_LINESIZE);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user