Skip to content

Commit de51527

Browse files
author
Paul Gofman
committed
fixup! ntdll: Implement CPU topology override.
Support WINE_CPU_TOPOLOGY=p[n], similar to Windows ProcessorCountLieForHybridCPU compatibility shim. Based on findings by Paulo Zanoni <paulo.r.zanoni@intel.com> in ValveSoftware/Proton#9880. CW-Bug-Id: #27255
1 parent 03d44de commit de51527

1 file changed

Lines changed: 45 additions & 3 deletions

File tree

dlls/ntdll/unix/system.c

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,17 @@ void init_shared_data_cpuinfo( KUSER_SHARED_DATA *data )
768768
static void fill_performance_core_info(void);
769769
static BOOL sysfs_parse_bitmap(const char *filename, ULONG_PTR *mask);
770770

771+
static ULONG popcount( ULONG val )
772+
{
773+
#if defined(__MINGW32__)
774+
return __builtin_popcount( val );
775+
#else
776+
val -= val >> 1 & 0x55555555;
777+
val = (val & 0x33333333) + (val >> 2 & 0x33333333);
778+
return ((val + (val >> 4)) & 0x0f0f0f0f) * 0x01010101 >> 24;
779+
#endif
780+
}
781+
771782
void fill_cpu_override(void)
772783
{
773784
const char *env_override = getenv("WINE_CPU_TOPOLOGY");
@@ -807,9 +818,40 @@ void fill_cpu_override(void)
807818
host_cpu_count = MAXIMUM_PROCESSORS;
808819
}
809820

810-
cpu_override.mapping.cpu_count = strtol(env_override, &s, 10);
811-
if (s == env_override)
812-
goto error;
821+
if (env_override[0] == 'p' || env_override[0] == 'P')
822+
{
823+
unsigned int count = host_cpu_count;
824+
825+
if (env_override[1])
826+
{
827+
count = strtol( env_override + 1, &s, 10 );
828+
if (!count || s == env_override + 1) goto error;
829+
}
830+
else s = env_override + 1;
831+
if (*s) goto error;
832+
fill_performance_core_info();
833+
if (!performance_cores_capacity)
834+
{
835+
TRACE( "No performance cores.\n" );
836+
return;
837+
}
838+
for (i = 0; i < performance_cores_capacity; ++i)
839+
{
840+
if (!performance_cores[i]) continue;
841+
cpu_override.mapping.cpu_count += popcount( performance_cores[i] );
842+
}
843+
if (!cpu_override.mapping.cpu_count)
844+
{
845+
TRACE( "No performance cores.\n" );
846+
return;
847+
}
848+
cpu_override.mapping.cpu_count = min( cpu_override.mapping.cpu_count, count );
849+
}
850+
else
851+
{
852+
cpu_override.mapping.cpu_count = strtol( env_override, &s, 10 );
853+
if (s == env_override) goto error;
854+
}
813855

814856
if (!cpu_override.mapping.cpu_count || cpu_override.mapping.cpu_count > MAXIMUM_PROCESSORS)
815857
{

0 commit comments

Comments
 (0)