Skip to content

Commit db0fa0c

Browse files
committed
stress-cachehammer: add new stressor to exercise prefetch/flush cache ops
exercise the cache with a randomized mix of memory read/writes and where possible cache prefetches and cache flushes to random addresses in three emory mapped regions, one of which is shared among all the cache stressors and is the size of the L3 cache, one is local to each instance and is 4 times the L3 cache size and one is a single page mapping that cannot be read or written. Signed-off-by: Colin Ian King <[email protected]>
1 parent 86f83e8 commit db0fa0c

11 files changed

+557
-13
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ STRESS_SRC = \
349349
stress-bsearch.c \
350350
stress-bubblesort.c \
351351
stress-cache.c \
352+
stress-cachehammer.c \
352353
stress-cacheline.c \
353354
stress-cap.c \
354355
stress-cgroup.c \

Makefile.config

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,6 +1241,7 @@ cpufeatures: \
12411241
ASM_X86_PREFETCHT1 \
12421242
ASM_X86_PREFETCHT2 \
12431243
ASM_X86_PREFETCHW \
1244+
ASM_X86_PREFETCHWT1 \
12441245
ASM_X86_RDMSR \
12451246
ASM_X86_RDPMC \
12461247
ASM_X86_RDRAND \
@@ -1507,6 +1508,9 @@ ASM_X86_PREFETCHNTA:
15071508
ASM_X86_PREFETCHW:
15081509
$(call check,test-asm-x86-prefetchw,HAVE_ASM_X86_PREFETCHW,x86 prefetchw instruction)
15091510

1511+
ASM_X86_PREFETCHWT1:
1512+
$(call check,test-asm-x86-prefetchwt1,HAVE_ASM_X86_PREFETCHWT1,x86 prefetchwt1 instruction)
1513+
15101514
ASM_X86_RDMSR:
15111515
$(call check,test-asm-x86-rdmsr,HAVE_ASM_X86_RDMSR,x86 rdmsr instruction)
15121516

core-asm-x86.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,13 @@ static inline void ALWAYS_INLINE stress_asm_x86_prefetchw(void *p)
322322
}
323323
#endif
324324

325+
#if defined(HAVE_ASM_X86_PREFETCHWT1)
326+
static inline void ALWAYS_INLINE stress_asm_x86_prefetchwt1(void *p)
327+
{
328+
__asm__ __volatile__("prefetchwt1 (%0)\n" : : "r"(p) : "memory");
329+
}
330+
#endif
331+
325332
#if !defined(HAVE_COMPILER_PCC) && \
326333
defined(STRESS_ARCH_X86_64) && \
327334
defined(STRESS_ARCH_X86_LP64)

core-cpu.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,27 @@ bool stress_cpu_x86_has_cldemote(void)
374374
#endif
375375
}
376376

377+
/*
378+
* stress_cpu_x86_has_prefetchwt1()
379+
* does x86 cpu support prefetchwt1?
380+
*/
381+
bool stress_cpu_x86_has_prefetchwt1(void)
382+
{
383+
#if defined(STRESS_ARCH_X86)
384+
uint32_t ebx = 0, ecx = 0, edx = 0;
385+
386+
if (!stress_cpu_is_x86())
387+
return false;
388+
389+
stress_cpu_x86_extended_features(ebx, ecx, edx);
390+
391+
return !!(ecx & CPUID_prefetchwt1_ECX);
392+
#else
393+
return false;
394+
#endif
395+
}
396+
397+
377398
/*
378399
* stress_cpu_x86_has_waitpkg()
379400
* does x86 cpu support waitpkg?

core-cpu.h

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,25 @@
2323
#include "core-arch.h"
2424

2525
extern WARN_UNUSED bool stress_cpu_is_x86(void);
26+
extern WARN_UNUSED bool stress_cpu_x86_has_avx_vnni(void);
27+
extern WARN_UNUSED bool stress_cpu_x86_has_avx512_vl(void);
28+
extern WARN_UNUSED bool stress_cpu_x86_has_avx512_vnni(void);
29+
extern WARN_UNUSED bool stress_cpu_x86_has_avx512_bw(void);
2630
extern WARN_UNUSED bool stress_cpu_x86_has_clflushopt(void);
2731
extern WARN_UNUSED bool stress_cpu_x86_has_clwb(void);
2832
extern WARN_UNUSED bool stress_cpu_x86_has_cldemote(void);
29-
extern WARN_UNUSED bool stress_cpu_x86_has_waitpkg(void);
30-
extern WARN_UNUSED bool stress_cpu_x86_has_rdseed(void);
31-
extern WARN_UNUSED bool stress_cpu_x86_has_syscall(void);
32-
extern WARN_UNUSED bool stress_cpu_x86_has_rdrand(void);
33-
extern WARN_UNUSED bool stress_cpu_x86_has_rdtscp(void);
34-
extern WARN_UNUSED bool stress_cpu_x86_has_tsc(void);
35-
extern WARN_UNUSED bool stress_cpu_x86_has_msr(void);
3633
extern WARN_UNUSED bool stress_cpu_x86_has_clfsh(void);
3734
extern WARN_UNUSED bool stress_cpu_x86_has_mmx(void);
35+
extern WARN_UNUSED bool stress_cpu_x86_has_msr(void);
36+
extern WARN_UNUSED bool stress_cpu_x86_has_prefetchwt1(void);
37+
extern WARN_UNUSED bool stress_cpu_x86_has_rdrand(void);
38+
extern WARN_UNUSED bool stress_cpu_x86_has_rdseed(void);
39+
extern WARN_UNUSED bool stress_cpu_x86_has_rdtscp(void);
40+
extern WARN_UNUSED bool stress_cpu_x86_has_serialize(void);
3841
extern WARN_UNUSED bool stress_cpu_x86_has_sse(void);
3942
extern WARN_UNUSED bool stress_cpu_x86_has_sse2(void);
40-
extern WARN_UNUSED bool stress_cpu_x86_has_serialize(void);
41-
extern WARN_UNUSED bool stress_cpu_x86_has_avx_vnni(void);
42-
extern WARN_UNUSED bool stress_cpu_x86_has_avx512_vl(void);
43-
extern WARN_UNUSED bool stress_cpu_x86_has_avx512_vnni(void);
44-
extern WARN_UNUSED bool stress_cpu_x86_has_avx512_bw(void);
43+
extern WARN_UNUSED bool stress_cpu_x86_has_syscall(void);
44+
extern WARN_UNUSED bool stress_cpu_x86_has_tsc(void);
45+
extern WARN_UNUSED bool stress_cpu_x86_has_waitpkg(void);
4546

4647
#endif

core-opts.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ const struct option stress_long_options[] = {
106106
{ "cache-prefetchw", 0, 0, OPT_cache_prefetchw },
107107
{ "cache-sfence", 0, 0, OPT_cache_sfence },
108108
{ "cache-ways", 1, 0, OPT_cache_ways },
109+
{ "cachehammer", 1, 0, OPT_cachehammer },
110+
{ "cachehammer-ops", 1, 0, OPT_cachehammer_ops },
109111
{ "cacheline", 1, 0, OPT_cacheline },
110112
{ "cacheline-affinity", 0, 0, OPT_cacheline_affinity },
111113
{ "cacheline-method", 1, 0, OPT_cacheline_method },

core-opts.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,9 @@ typedef enum {
253253
OPT_cache_prefetchw,
254254
OPT_cache_ways,
255255

256+
OPT_cachehammer,
257+
OPT_cachehammer_ops,
258+
256259
OPT_cacheline,
257260
OPT_cacheline_ops,
258261
OPT_cacheline_affinity,

core-stressors.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
MACRO(bsearch) \
4848
MACRO(bubblesort) \
4949
MACRO(cache) \
50+
MACRO(cachehammer) \
5051
MACRO(cacheline) \
5152
MACRO(cap) \
5253
MACRO(cgroup) \

0 commit comments

Comments
 (0)