mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-08 06:00:08 +01:00
CPU (Windows): detect CPU caches
This commit is contained in:
@@ -10,6 +10,21 @@ typedef struct FFCPUCore
|
||||
uint32_t count;
|
||||
} FFCPUCore;
|
||||
|
||||
typedef enum 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;
|
||||
FFCPUCacheType type;
|
||||
} FFCPUCache;
|
||||
|
||||
typedef struct FFCPUResult
|
||||
{
|
||||
FFstrbuf name;
|
||||
@@ -25,6 +40,7 @@ typedef struct FFCPUResult
|
||||
double frequencyBiosLimit; // GHz
|
||||
|
||||
FFCPUCore coreTypes[16]; // number of P cores, E cores, etc.
|
||||
FFlist caches[3]; // L1, L2, L3
|
||||
|
||||
double temperature;
|
||||
} FFCPUResult;
|
||||
|
||||
@@ -126,9 +126,9 @@ static const char* detectNCores(FFCPUResult* cpu)
|
||||
ptr = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX*)(((uint8_t*)ptr) + ptr->Size)
|
||||
)
|
||||
{
|
||||
if(ptr->Relationship == RelationProcessorCore)
|
||||
if (ptr->Relationship == RelationProcessorCore)
|
||||
++cpu->coresPhysical;
|
||||
else if(ptr->Relationship == RelationGroup)
|
||||
else if (ptr->Relationship == RelationGroup)
|
||||
{
|
||||
for (uint32_t index = 0; index < ptr->Group.ActiveGroupCount; ++index)
|
||||
{
|
||||
@@ -136,6 +136,42 @@ static const char* detectNCores(FFCPUResult* cpu)
|
||||
cpu->coresLogical += ptr->Group.GroupInfo[index].MaximumProcessorCount;
|
||||
}
|
||||
}
|
||||
else if(ptr->Relationship == RelationCache)
|
||||
{
|
||||
if (__builtin_expect(ptr->Cache.Level <= 3, true))
|
||||
{
|
||||
FFCPUCacheType cacheType = 0;
|
||||
switch (ptr->Cache.Type)
|
||||
{
|
||||
case CacheUnified: cacheType = FF_CPU_CACHE_TYPE_UNIFIED; break;
|
||||
case CacheInstruction: cacheType = FF_CPU_CACHE_TYPE_INSTRUCTION; break;
|
||||
case CacheData: cacheType = FF_CPU_CACHE_TYPE_DATA; break;
|
||||
case CacheTrace: cacheType = FF_CPU_CACHE_TYPE_TRACE; break;
|
||||
default: __builtin_unreachable(); break;
|
||||
}
|
||||
|
||||
FFlist* cacheLevel = &cpu->caches[ptr->Cache.Level - 1];
|
||||
FFCPUCache* found = NULL;
|
||||
FF_LIST_FOR_EACH(FFCPUCache, item, *cacheLevel)
|
||||
{
|
||||
if (item->type == cacheType && item->size == ptr->Cache.CacheSize)
|
||||
{
|
||||
found = item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found)
|
||||
found->num++;
|
||||
else
|
||||
{
|
||||
*(FFCPUCache*) ffListAdd(cacheLevel) = (FFCPUCache) {
|
||||
.size = ptr->Cache.CacheSize,
|
||||
.num = 1,
|
||||
.type = cacheType,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
||||
Reference in New Issue
Block a user