mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-11-08 10:09:16 +00:00
Removes unused lib CPU functions
All needed information is already provided by SDL. Refs: #9136, #8855.
This commit is contained in:
8 files changed
+4
-254
No files matched your search
@@ -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 <sys/param.h>
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
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<uintptr_t>(os_cpu_NumProcessors());
|
||||
|
||||
return processorMask;
|
||||
}
|
||||
|
||||
|
||||
size_t os_cpu_PageSize()
|
||||
{
|
||||
|
||||
@@ -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 <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
#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<uintptr_t>(os_cpu_NumProcessors());
|
||||
|
||||
return processorMask;
|
||||
}
|
||||
|
||||
|
||||
size_t os_cpu_PageSize()
|
||||
{
|
||||
|
||||
@@ -24,39 +24,9 @@
|
||||
|
||||
#include "lib/sysdep/os_cpu.h"
|
||||
#include "lib/alignment.h"
|
||||
#include "lib/bits.h"
|
||||
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
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<uintptr_t>(os_cpu_NumProcessors());
|
||||
|
||||
return processorMask;
|
||||
}
|
||||
|
||||
|
||||
size_t os_cpu_PageSize()
|
||||
{
|
||||
|
||||
@@ -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
|
||||
@@ -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 <bit>
|
||||
|
||||
|
||||
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()
|
||||
|
||||
@@ -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<size_t> largePageCommits{ 0 };
|
||||
std::atomic<size_t> 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<uintptr_t>(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)
|
||||
|
||||
@@ -27,42 +27,7 @@
|
||||
#ifndef INCLUDED_OS_CPU
|
||||
#define INCLUDED_OS_CPU
|
||||
|
||||
#include "lib/status.h"
|
||||
|
||||
#include <climits>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// 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();
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
@@ -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
|
||||
Reference in new issue
Block a user