diff options
Diffstat (limited to 'src/detection/cpucache/cpucache.h')
| -rw-r--r-- | src/detection/cpucache/cpucache.h | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/detection/cpucache/cpucache.h b/src/detection/cpucache/cpucache.h new file mode 100644 index 0000000..287154b --- /dev/null +++ b/src/detection/cpucache/cpucache.h @@ -0,0 +1,44 @@ +#pragma once + +#include "fastfetch.h" +#include "modules/cpucache/option.h" + +typedef enum FF_A_PACKED FFCPUCacheType { + FF_CPU_CACHE_TYPE_UNIFIED = 0, + FF_CPU_CACHE_TYPE_INSTRUCTION = 1, + FF_CPU_CACHE_TYPE_DATA = 2, + FF_CPU_CACHE_TYPE_TRACE = 3, +} FFCPUCacheType; + +typedef struct FFCPUCache { + uint32_t size; + uint32_t num; + uint32_t lineSize; + FFCPUCacheType type; +} FFCPUCache; + +typedef struct FFCPUCacheResult { + FFlist caches[4]; // L1, L2, L3, L4(?) +} FFCPUCacheResult; + +const char* ffDetectCPUCache(FFCPUCacheResult* result); + +static inline FFCPUCache* ffCPUCacheAddItem(FFCPUCacheResult* result, uint32_t level, uint32_t size, uint32_t lineSize, FFCPUCacheType type) { + FFlist* cacheLevel = &result->caches[level - 1]; + + FF_LIST_FOR_EACH (FFCPUCache, item, *cacheLevel) { + if (item->type == type && item->size == size && item->lineSize == lineSize) { + item->num++; + return item; + } + } + + FFCPUCache* item = FF_LIST_ADD(FFCPUCache, *cacheLevel); + *item = (FFCPUCache) { + .size = size, + .num = 1, + .lineSize = lineSize, + .type = type, + }; + return item; +} |