From: Nicholas Nethercote Date: Fri, 26 Nov 2004 18:36:02 +0000 (+0000) Subject: Simplified the way Cachegrind configures the caches; it was really X-Git-Tag: svn/VALGRIND_3_0_0~1200 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=64af386b3e0de48497dd3ba76c6e7cd69cb7f001;p=thirdparty%2Fvalgrind.git Simplified the way Cachegrind configures the caches; it was really strange before. Also aborting if any command-line-provided cache configuration is unacceptable, rather than falling back on defaults; it's simpler and arguably better than just emitting a warning. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@3118 --- diff --git a/cachegrind/cg_arch.h b/cachegrind/cg_arch.h index 71ed2bd842..c12e0d9a0d 100644 --- a/cachegrind/cg_arch.h +++ b/cachegrind/cg_arch.h @@ -38,9 +38,10 @@ typedef struct { int line_size; // bytes } cache_t; +// Gives the configuration of I1, D1 and L2 caches. They get overridden +// by any cache configurations specified on the command line. void VGA_(configure_caches)(cache_t* I1c, cache_t* D1c, cache_t* L2c, - cache_t* I1_dflt, cache_t* D1_dflt, cache_t* L2_dflt, - Bool all_caches_clo_defined); + Bool all_caches_clo_defined); #endif // __CG_ARCH_H diff --git a/cachegrind/cg_main.c b/cachegrind/cg_main.c index 90cf31e1ed..5f370fca25 100644 --- a/cachegrind/cg_main.c +++ b/cachegrind/cg_main.c @@ -679,29 +679,28 @@ static cache_t clo_L2_cache = UNDEFINED_CACHE; /* Checks cache config is ok; makes it so if not. */ static -void check_cache(cache_t* cache, cache_t* dflt, Char *name) +void check_cache(cache_t* cache, Char *name) { /* First check they're all powers of two */ if (-1 == VG_(log2)(cache->size)) { VG_(message)(Vg_UserMsg, - "warning: %s size of %dB not a power of two; " - "defaulting to %dB", name, cache->size, dflt->size); - cache->size = dflt->size; + "error: %s size of %dB not a power of two; aborting.", + name, cache->size); + VG_(exit)(1); } if (-1 == VG_(log2)(cache->assoc)) { VG_(message)(Vg_UserMsg, - "warning: %s associativity of %d not a power of two; " - "defaulting to %d-way", name, cache->assoc, dflt->assoc); - cache->assoc = dflt->assoc; + "error: %s associativity of %d not a power of two; aborting.", + name, cache->assoc); + VG_(exit)(1); } if (-1 == VG_(log2)(cache->line_size)) { VG_(message)(Vg_UserMsg, - "warning: %s line size of %dB not a power of two; " - "defaulting to %dB", - name, cache->line_size, dflt->line_size); - cache->line_size = dflt->line_size; + "error: %s line size of %dB not a power of two; aborting.", + name, cache->line_size); + VG_(exit)(1); } /* Then check line size >= 16 -- any smaller and a single instruction could @@ -709,27 +708,24 @@ void check_cache(cache_t* cache, cache_t* dflt, Char *name) * stupid anyway. */ if (cache->line_size < MIN_LINE_SIZE) { VG_(message)(Vg_UserMsg, - "warning: %s line size of %dB too small; " - "increasing to %dB", name, cache->line_size, MIN_LINE_SIZE); - cache->line_size = MIN_LINE_SIZE; + "error: %s line size of %dB too small; aborting.", + name, cache->line_size); + VG_(exit)(1); } /* Then check cache size > line size (causes seg faults if not). */ if (cache->size <= cache->line_size) { VG_(message)(Vg_UserMsg, - "warning: %s cache size of %dB <= line size of %dB; " - "increasing to %dB", name, cache->size, cache->line_size, - cache->line_size * 2); - cache->size = cache->line_size * 2; + "error: %s cache size of %dB <= line size of %dB; aborting.", + name, cache->size, cache->line_size); + VG_(exit)(1); } /* Then check assoc <= (size / line size) (seg faults otherwise). */ if (cache->assoc > (cache->size / cache->line_size)) { VG_(message)(Vg_UserMsg, - "warning: %s associativity > (size / line size); " - "increasing size to %dB", - name, cache->assoc * cache->line_size); - cache->size = cache->assoc * cache->line_size; + "warning: %s associativity > (size / line size); aborting.", name); + VG_(exit)(1); } } @@ -739,17 +735,15 @@ void configure_caches(cache_t* I1c, cache_t* D1c, cache_t* L2c) #define DEFINED(L) (-1 != L.size || -1 != L.assoc || -1 != L.line_size) Int n_clos = 0; - cache_t I1_dflt, D1_dflt, L2_dflt; // Count how many were defined on the command line. if (DEFINED(clo_I1_cache)) { n_clos++; } if (DEFINED(clo_D1_cache)) { n_clos++; } if (DEFINED(clo_L2_cache)) { n_clos++; } - // Set the default cache config (using auto-detection, if supported by - // current arch) - VGA_(configure_caches)( I1c, D1c, L2c, &I1_dflt, &D1_dflt, &L2_dflt, - (3 == n_clos) ); + // Set the cache config (using auto-detection, if supported by the + // architecture) + VGA_(configure_caches)( I1c, D1c, L2c, (3 == n_clos) ); // Then replace with any defined on the command line. if (DEFINED(clo_I1_cache)) { *I1c = clo_I1_cache; } @@ -757,9 +751,9 @@ void configure_caches(cache_t* I1c, cache_t* D1c, cache_t* L2c) if (DEFINED(clo_L2_cache)) { *L2c = clo_L2_cache; } // Then check values and fix if not acceptable. - check_cache(I1c, &I1_dflt, "I1"); - check_cache(D1c, &D1_dflt, "D1"); - check_cache(L2c, &L2_dflt, "L2"); + check_cache(I1c, "I1"); + check_cache(D1c, "D1"); + check_cache(L2c, "L2"); if (VG_(clo_verbosity) > 1) { VG_(message)(Vg_UserMsg, "Cache configuration used:"); diff --git a/cachegrind/x86/cg_arch.c b/cachegrind/x86/cg_arch.c index 7d6cafa09a..6e2b710e12 100644 --- a/cachegrind/x86/cg_arch.c +++ b/cachegrind/x86/cg_arch.c @@ -331,18 +331,14 @@ Int get_caches_from_CPUID(cache_t* I1c, cache_t* D1c, cache_t* L2c) void VGA_(configure_caches)(cache_t* I1c, cache_t* D1c, cache_t* L2c, - cache_t* I1_dflt, cache_t* D1_dflt, cache_t* L2_dflt, - Bool all_caches_clo_defined) + Bool all_caches_clo_defined) { Int res; // Set caches to default. - *I1_dflt = (cache_t) { 65536, 2, 64 }; - *D1_dflt = (cache_t) { 65536, 2, 64 }; - *L2_dflt = (cache_t) { 262144, 8, 64 }; - *I1c = *I1_dflt; - *D1c = *D1_dflt; - *L2c = *L2_dflt; + *I1c = (cache_t) { 65536, 2, 64 }; + *D1c = (cache_t) { 65536, 2, 64 }; + *L2c = (cache_t) { 262144, 8, 64 }; // Then replace with any info we can get from CPUID. res = get_caches_from_CPUID(I1c, D1c, L2c);