From 61534d63a1a5988b837425b2ac48b1e956c07e7d Mon Sep 17 00:00:00 2001 From: Vladislav Belov Date: Mon, 19 Oct 2026 20:48:10 +0200 Subject: [PATCH] Removes unused lib CPU functions All needed information is already provided by SDL. Refs: #9136, #8855. --- source/lib/sysdep/os/bsd/bcpu.cpp | 39 ------------------- source/lib/sysdep/os/linux/lcpu.cpp | 41 -------------------- source/lib/sysdep/os/osx/ocpu.cpp | 30 --------------- source/lib/sysdep/os/unix/uvm.cpp | 8 +--- source/lib/sysdep/os/win/wcpu.cpp | 42 --------------------- source/lib/sysdep/os/win/wvm.cpp | 58 +---------------------------- source/lib/sysdep/os_cpu.h | 35 ----------------- source/lib/sysdep/vm.h | 5 +-- 8 files changed, 4 insertions(+), 254 deletions(-) diff --git a/source/lib/sysdep/os/bsd/bcpu.cpp b/source/lib/sysdep/os/bsd/bcpu.cpp index 4502dfa8a2..ad5af3dfc4 100644 --- a/source/lib/sysdep/os/bsd/bcpu.cpp +++ b/source/lib/sysdep/os/bsd/bcpu.cpp @@ -24,51 +24,12 @@ #include "lib/sysdep/os_cpu.h" #include "lib/alignment.h" -#include "lib/bits.h" #include "lib/config2.h" #include "lib/module_init.h" -#if CONFIG2_VALGRIND -# include "valgrind.h" -#endif #include #include -size_t os_cpu_NumProcessors() -{ - static size_t numProcessors; - - if(numProcessors == 0) - { -#if CONFIG2_VALGRIND - // Valgrind reports the number of real CPUs, but only emulates a single CPU. - // That causes problems when we expect all those CPUs to be distinct, so - // just pretend there's only one CPU - if (RUNNING_ON_VALGRIND) - numProcessors = 1; - else -#endif - { - long res = sysconf(_SC_NPROCESSORS_CONF); - ENSURE(res != -1); - numProcessors = (size_t)res; - } - } - - return numProcessors; -} - - -uintptr_t os_cpu_ProcessorMask() -{ - static uintptr_t processorMask; - - if(!processorMask) - processorMask = bit_mask(os_cpu_NumProcessors()); - - return processorMask; -} - size_t os_cpu_PageSize() { diff --git a/source/lib/sysdep/os/linux/lcpu.cpp b/source/lib/sysdep/os/linux/lcpu.cpp index 88120d3294..69946ef5ae 100644 --- a/source/lib/sysdep/os/linux/lcpu.cpp +++ b/source/lib/sysdep/os/linux/lcpu.cpp @@ -25,7 +25,6 @@ #include "lib/sysdep/os_cpu.h" #include "lib/alignment.h" -#include "lib/bits.h" #include "lib/config2.h" #include "lib/debug.h" #include "lib/module_init.h" @@ -38,46 +37,6 @@ #include #include -#if CONFIG2_VALGRIND -# include "valgrind.h" -#endif - - -size_t os_cpu_NumProcessors() -{ - static size_t numProcessors; - - if(numProcessors == 0) - { -#if CONFIG2_VALGRIND - // Valgrind reports the number of real CPUs, but only emulates a single CPU. - // That causes problems when we expect all those CPUs to be distinct, so - // just pretend there's only one CPU - if (RUNNING_ON_VALGRIND) - numProcessors = 1; - else -#endif - { - long res = sysconf(_SC_NPROCESSORS_CONF); - ENSURE(res != -1); - numProcessors = (size_t)res; - } - } - - return numProcessors; -} - - -uintptr_t os_cpu_ProcessorMask() -{ - static uintptr_t processorMask; - - if(!processorMask) - processorMask = bit_mask(os_cpu_NumProcessors()); - - return processorMask; -} - size_t os_cpu_PageSize() { diff --git a/source/lib/sysdep/os/osx/ocpu.cpp b/source/lib/sysdep/os/osx/ocpu.cpp index 65fd6aa8b0..a0602c46d8 100644 --- a/source/lib/sysdep/os/osx/ocpu.cpp +++ b/source/lib/sysdep/os/osx/ocpu.cpp @@ -24,39 +24,9 @@ #include "lib/sysdep/os_cpu.h" #include "lib/alignment.h" -#include "lib/bits.h" #include -size_t os_cpu_NumProcessors() -{ - static size_t numProcessors; - - if(numProcessors == 0) - { - // Mac OS X doesn't have sysconf(_SC_NPROCESSORS_CONF) - int mib[]={CTL_HW, HW_NCPU}; - int ncpus; - size_t len = sizeof(ncpus); - int ret = sysctl(mib, 2, &ncpus, &len, NULL, 0); - ENSURE(ret != -1); - numProcessors = (size_t)ncpus; - } - - return numProcessors; -} - - -uintptr_t os_cpu_ProcessorMask() -{ - static uintptr_t processorMask; - - if(!processorMask) - processorMask = bit_mask(os_cpu_NumProcessors()); - - return processorMask; -} - size_t os_cpu_PageSize() { diff --git a/source/lib/sysdep/os/unix/uvm.cpp b/source/lib/sysdep/os/unix/uvm.cpp index 41d0b9264a..b1e2f39adf 100644 --- a/source/lib/sysdep/os/unix/uvm.cpp +++ b/source/lib/sysdep/os/unix/uvm.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -134,10 +134,4 @@ void EndOnDemandCommits() // not yet implemented, but possible with a signal handler } - -void DumpStatistics() -{ - // we haven't collected any statistics -} - } // namespace vm diff --git a/source/lib/sysdep/os/win/wcpu.cpp b/source/lib/sysdep/os/win/wcpu.cpp index f1f27ab173..0acce85215 100644 --- a/source/lib/sysdep/os/win/wcpu.cpp +++ b/source/lib/sysdep/os/win/wcpu.cpp @@ -27,50 +27,8 @@ #include "precompiled.h" #include "lib/sysdep/os_cpu.h" -#include "lib/bits.h" #include "lib/alignment.h" -#include "lib/module_init.h" #include "lib/sysdep/os/win/wutil.h" -#include "lib/sysdep/arch/x86_x64/x86_x64.h" - -#include - - -uintptr_t os_cpu_ProcessorMask() -{ - static uintptr_t processorMask; - - if(!processorMask) - { - const HANDLE hProcess = GetCurrentProcess(); - DWORD_PTR processAffinity, systemAffinity; - const BOOL ok = GetProcessAffinityMask(hProcess, &processAffinity, &systemAffinity); - ENSURE(ok); - ENSURE(processAffinity != 0); - processorMask = processAffinity; - } - - return processorMask; -} - - -size_t os_cpu_NumProcessors() -{ - static size_t numProcessors; - - if(!numProcessors) - { - numProcessors = std::popcount(os_cpu_ProcessorMask()); - - // sanity check - SYSTEM_INFO si; - GetSystemInfo(&si); // guaranteed to succeed - ENSURE(numProcessors <= (size_t)si.dwNumberOfProcessors); - ENSURE(numProcessors >= 1); - } - - return numProcessors; -} size_t os_cpu_PageSize() diff --git a/source/lib/sysdep/os/win/wvm.cpp b/source/lib/sysdep/os/win/wvm.cpp index a7de1c7628..1170d97627 100644 --- a/source/lib/sysdep/os/win/wvm.cpp +++ b/source/lib/sysdep/os/win/wvm.cpp @@ -41,57 +41,6 @@ namespace vm { - -//----------------------------------------------------------------------------- -// per-processor statistics - -// (alignment avoids false sharing) -CACHE_ALIGNED(struct Statistics) // POD -{ - // thread-safe (required due to concurrent commits) - void NotifyLargePageCommit() - { - ++largePageCommits; - } - - void NotifySmallPageCommit() - { - ++smallPageCommits; - } - - std::atomic largePageCommits{ 0 }; - std::atomic smallPageCommits{ 0 }; -}; -static CACHE_ALIGNED(Statistics) statistics[os_cpu_MaxProcessors]; - -void DumpStatistics() -{ - ENSURE(IsAligned(&statistics[0], cacheLineSize)); - ENSURE(IsAligned(&statistics[1], cacheLineSize)); - - size_t smallPageCommits = 0; - size_t largePageCommits = 0; - uintptr_t processorsWithNoCommits = 0; - for(size_t processor = 0; processor < os_cpu_NumProcessors(); processor++) - { - const Statistics& s = statistics[processor]; - if(s.smallPageCommits == 0 && s.largePageCommits == 0) - processorsWithNoCommits |= Bit(processor); - smallPageCommits += s.smallPageCommits; - largePageCommits += s.largePageCommits; - } - - const size_t totalCommits = smallPageCommits+largePageCommits; - if(totalCommits == 0) // this module wasn't used => don't print debug output - return; - - const size_t largePageRatio = totalCommits? largePageCommits*100/totalCommits : 0; - debug_printf("%d commits (%d, i.e. %d%% of them via large pages)\n", totalCommits, largePageCommits, largePageRatio); - if(processorsWithNoCommits != 0) - debug_printf(" processors with no commits: %x\n", processorsWithNoCommits); -} - - //----------------------------------------------------------------------------- // allocator with large-page and NUMA support @@ -159,8 +108,6 @@ static void* AllocateLargeOrSmallPages(uintptr_t address, size_t size, DWORD all largePageAllocationTookTooLong = true; // avoid large pages next time if(largePages) { - if((allocationType & MEM_COMMIT) != 0) - statistics[processor].NotifyLargePageCommit(); return largePages; } } @@ -169,8 +116,6 @@ static void* AllocateLargeOrSmallPages(uintptr_t address, size_t size, DWORD all void* smallPages = VirtualAllocExNuma(hProcess, LPVOID(address), size, allocationType, protect, node); if(smallPages) { - if((allocationType & MEM_COMMIT) != 0) - statistics[processor].NotifySmallPageCommit(); return smallPages; } else @@ -301,7 +246,8 @@ CACHE_ALIGNED(struct AddressRangeDescriptor) // POD }; // (array size governs the max. number of extant allocations) -static AddressRangeDescriptor ranges[2*os_cpu_MaxProcessors]; +// It's chosen heuristically, equals twice the bit width of a 64-bit affinity mask. +static AddressRangeDescriptor ranges[128]; static AddressRangeDescriptor* FindDescriptor(uintptr_t address) diff --git a/source/lib/sysdep/os_cpu.h b/source/lib/sysdep/os_cpu.h index eb86cca548..f3b0eaae0f 100644 --- a/source/lib/sysdep/os_cpu.h +++ b/source/lib/sysdep/os_cpu.h @@ -27,42 +27,7 @@ #ifndef INCLUDED_OS_CPU #define INCLUDED_OS_CPU -#include "lib/status.h" - -#include #include -#include - -//----------------------------------------------------------------------------- -// processor topology - -// processor ID = [0, os_cpu_NumProcessors()) -// they are a numbering of the bits of the process affinity mask where the -// least significant nonzero bit corresponds to ID 0. -// rationale: this spares users from having to deal with noncontiguous IDs, -// e.g. when administrative tools are used to restrict process affinity. - - -/** - * maximum number of processors supported by the OS (determined by the - * number of bits in an affinity mask) - **/ -static const size_t os_cpu_MaxProcessors = sizeof(uintptr_t)*CHAR_BIT; - -/** - * @return bit mask of processors that exist and are available to - * this process. - * its population count is by definition equal to os_cpu_NumProcessors(). - **/ -uintptr_t os_cpu_ProcessorMask(); - -/** - * @return the number of processors available to this process. - * - * note: this function is necessary because POSIX sysconf _SC_NPROCESSORS_CONF - * is not suppored on MacOSX, else we would use that. - **/ -size_t os_cpu_NumProcessors(); //----------------------------------------------------------------------------- diff --git a/source/lib/sysdep/vm.h b/source/lib/sysdep/vm.h index 315655d2e1..059ee5144c 100644 --- a/source/lib/sysdep/vm.h +++ b/source/lib/sysdep/vm.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -150,9 +150,6 @@ void BeginOnDemandCommits(); **/ void EndOnDemandCommits(); - -void DumpStatistics(); - } // namespace vm #endif // #ifndef INCLUDED_SYSDEP_VM