101101#endif
102102#ifdef _WIN32
103103#include < windows.h>
104+ #else
105+ #include < sched.h>
104106#endif
105107namespace Xbyak { namespace util {
106108class CpuTopology ;
@@ -1564,9 +1566,10 @@ inline bool initCpuTopology(CpuTopology& cpuTopo)
15641566 // Assign core types for hybrid architectures
15651567 const bool isHybrid = cpuTopo.isHybrid ();
15661568 if (isHybrid) {
1567- // For hybrid systems, read P-core and E-core lists from sysfs
1569+ // For hybrid systems, try toread P-core and E-core lists from sysfs first
15681570 CpuMask pCoreMask;
1569- if (parseCpuList (pCoreMask, " /sys/devices/cpu_core/cpus" )) {
1571+ const bool hasPCoreSysfs = parseCpuList (pCoreMask, " /sys/devices/cpu_core/cpus" );
1572+ if (hasPCoreSysfs) {
15701573 // Set Performance core types
15711574 for (CpuMask::const_iterator it = pCoreMask.begin (); it != pCoreMask.end (); ++it) {
15721575 uint32_t cpuIdx = *it;
@@ -1576,7 +1579,8 @@ inline bool initCpuTopology(CpuTopology& cpuTopo)
15761579 }
15771580 }
15781581 CpuMask eCoreMask;
1579- if (parseCpuList (eCoreMask, " /sys/devices/cpu_atom/cpus" )) {
1582+ const bool hasECoreSysfs = parseCpuList (eCoreMask, " /sys/devices/cpu_atom/cpus" );
1583+ if (hasECoreSysfs) {
15801584 // Set Efficient core types
15811585 for (CpuMask::const_iterator it = eCoreMask.begin (); it != eCoreMask.end (); ++it) {
15821586 uint32_t cpuIdx = *it;
@@ -1585,6 +1589,38 @@ inline bool initCpuTopology(CpuTopology& cpuTopo)
15851589 }
15861590 }
15871591 }
1592+ // Fallback: if either sysfs paths are unavailable, detect both core type per-CPU
1593+ // via CPUID leaf 0x1A (Hybrid Information) by pinning each logical CPU.
1594+ if (!hasPCoreSysfs || !hasECoreSysfs) {
1595+ // CPUID leaf 0x1A EAX[31:24] core type identifiers
1596+ const uint32_t Cpuid_StandardCoreType = 0x40 ; // P-core (Performance)
1597+ const uint32_t Cpuid_AtomCoreType = 0x20 ; // E-core (Efficient)
1598+
1599+ cpu_set_t originalMask;
1600+ CPU_ZERO (&originalMask);
1601+ if (sched_getaffinity (0 , sizeof (cpu_set_t ), &originalMask) != 0 ) goto SKIP_FALLBACK;
1602+
1603+ for (uint32_t cpu = 0 ; cpu < logicalCpuNum; cpu++) {
1604+ cpu_set_t cpuMask;
1605+ CPU_ZERO (&cpuMask);
1606+ CPU_SET (cpu, &cpuMask);
1607+ if (sched_setaffinity (0 , sizeof (cpu_set_t ), &cpuMask) == 0 ) {
1608+ // CPUID leaf 0x1A: Hybrid Information
1609+ uint32_t data[4 ] = {};
1610+ Cpu::getCpuidEx (0x1A , 0 , data);
1611+ const uint32_t coreTypeField = (data[0 ] >> 24 ) & 0xFF ;
1612+ if (coreTypeField == Cpuid_StandardCoreType) {
1613+ cpuTopo.logicalCpus_ [cpu].coreType = Performance;
1614+ } else if (coreTypeField == Cpuid_AtomCoreType) {
1615+ cpuTopo.logicalCpus_ [cpu].coreType = Efficient;
1616+ }
1617+ }
1618+ }
1619+
1620+ // Restore the original CPU affinity mask
1621+ sched_setaffinity (0 , sizeof (cpu_set_t ), &originalMask);
1622+ SKIP_FALLBACK:;
1623+ }
15881624 }
15891625
15901626 // Read coherency line size
0 commit comments