Cache detection fails when there are four levels of cache

Issue #128 new
Al Grant created an issue

PAPI can detect cache hierarchy on Linux by scanning /sys, in generic_get_memory_info. PAPI_MAX_MEM_HIERARCHY_LEVELS=4, implying it can cope with 4-level cache, but the hierarchy array dimensioned by it is zero-based. The variable “level_index” is set to 1 less than the cache level reported by Linux. I.e. when Linux reports a L1 cache, level_index=0, and when Linux reports a L4 cache, level_index=3. So this should be able to fit into the 4-element array. But the test is “level >= PAPI_MAX_MEM_HIERARCHY_LEVELS” which triggers when level=4, and the scan terminates. Since Linux directory traversal can report the cache nodes in any order, this means that the scan might terminate before any levels are successfully detected at all. This leads to PAPI detecting no cache. Failure to detect cache also has knock-on effects, e.g. the PAPI_L2_DCW event test spuriously appears to pass.

This test ought to trigger only when the system reports too many levels, i.e. more levels than the maximum allowed level, PAPI_MAX_MEM_HIERARCHY_LEVELS. Specifically, it should trigger when there are five or more levels. So the test should be either “level > PAPI_MAX_MEM_HIERARCHY_LEVELS” or “level_index >= PAPI_MAX_MEM_HIERARCHY_LEVELS” - they are equivalent.

Comments (2)

  1. Log in to comment