Skip to content

Commit

Permalink
Update Environment.ProcessorCount - port dotnet#45943 (dotnet#598)
Browse files Browse the repository at this point in the history
Port of dotnet#45943

Delete some dead code
  • Loading branch information
jkotas authored Jan 28, 2021
1 parent 1c0c677 commit e28a392
Show file tree
Hide file tree
Showing 15 changed files with 33 additions and 230 deletions.
2 changes: 2 additions & 0 deletions src/coreclr/gc/gcload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,12 @@ GC_Initialize(
// various components may want to query the current configuration.
GCConfig::Initialize();

#ifndef FEATURE_REDHAWK // GCToOSInterface is initialized directly
if (!GCToOSInterface::Initialize())
{
return E_FAIL;
}
#endif

IGCHandleManager* handleManager = CreateGCHandleManager();
if (handleManager == nullptr)
Expand Down
26 changes: 1 addition & 25 deletions src/coreclr/nativeaot/Runtime/PalRedhawk.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,27 +82,6 @@ typedef struct _GUID {

#define DECLARE_HANDLE(_name) typedef HANDLE _name

struct SYSTEM_INFO
{
union
{
uint32_t dwOemId;
struct {
uint16_t wProcessorArchitecture;
uint16_t wReserved;
} DUMMYSTRUCTNAME;
} DUMMYUNIONNAME;
uint32_t dwPageSize;
void * lpMinimumApplicationAddress;
void * lpMaximumApplicationAddress;
uintptr_t dwActiveProcessorMask;
uint32_t dwNumberOfProcessors;
uint32_t dwProcessorType;
uint32_t dwAllocationGranularity;
uint16_t wProcessorLevel;
uint16_t wProcessorRevision;
};

// defined in gcrhenv.cpp
bool __SwitchToThread(uint32_t dwSleepMSec, uint32_t dwSwitchCount);

Expand Down Expand Up @@ -559,7 +538,7 @@ EventDataDescCreate(_Out_ EVENT_DATA_DESCRIPTOR * EventDataDescriptor, _In_opt_
}
#endif // _EVNTPROV_H_

extern GCSystemInfo g_RhSystemInfo;
extern uint32_t g_RhNumberOfProcessors;

#ifdef TARGET_UNIX
#define REDHAWK_PALIMPORT extern "C"
Expand All @@ -570,8 +549,6 @@ extern GCSystemInfo g_RhSystemInfo;
#define REDHAWK_PALAPI __stdcall
#endif // TARGET_UNIX

bool InitializeSystemInfo();

#ifndef DACCESS_COMPILE

#ifdef _DEBUG
Expand Down Expand Up @@ -679,7 +656,6 @@ REDHAWK_PALIMPORT void REDHAWK_PALAPI PalSleep(uint32_t milliseconds);
REDHAWK_PALIMPORT UInt32_BOOL REDHAWK_PALAPI PalSwitchToThread();
REDHAWK_PALIMPORT HANDLE REDHAWK_PALAPI PalCreateEventW(_In_opt_ LPSECURITY_ATTRIBUTES pEventAttributes, UInt32_BOOL manualReset, UInt32_BOOL initialState, _In_opt_z_ LPCWSTR pName);
REDHAWK_PALIMPORT uint64_t REDHAWK_PALAPI PalGetTickCount64();
REDHAWK_PALIMPORT HANDLE REDHAWK_PALAPI PalCreateLowMemoryNotification();
REDHAWK_PALIMPORT void REDHAWK_PALAPI PalTerminateCurrentProcess(uint32_t exitCode);
REDHAWK_PALIMPORT HANDLE REDHAWK_PALAPI PalGetModuleHandleFromPointer(_In_ void* pointer);

Expand Down
12 changes: 0 additions & 12 deletions src/coreclr/nativeaot/Runtime/PalRedhawkFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,6 @@ inline void PalRaiseException(uint32_t arg1, uint32_t arg2, uint32_t arg3, const
RaiseException(arg1, arg2, arg3, arg4);
}

extern "C" UInt32_BOOL __stdcall ReleaseMutex(HANDLE);
inline UInt32_BOOL PalReleaseMutex(HANDLE arg1)
{
return ReleaseMutex(arg1);
}

extern "C" UInt32_BOOL __stdcall ResetEvent(HANDLE);
inline UInt32_BOOL PalResetEvent(HANDLE arg1)
{
Expand All @@ -159,12 +153,6 @@ inline UInt32_BOOL PalSetEvent(HANDLE arg1)
return SetEvent(arg1);
}

extern "C" void __stdcall TerminateProcess(HANDLE, uint32_t);
inline void PalTerminateProcess(HANDLE arg1, uint32_t arg2)
{
TerminateProcess(arg1, arg2);
}

extern "C" uint32_t __stdcall WaitForSingleObjectEx(HANDLE, uint32_t, UInt32_BOOL);
inline uint32_t PalWaitForSingleObjectEx(HANDLE arg1, uint32_t arg2, UInt32_BOOL arg3)
{
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/nativeaot/Runtime/RWLock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ void ReaderWriterLock::AcquireReadLockWorker()
if (TryAcquireReadLock())
return;

if (g_RhSystemInfo.dwNumberOfProcessors <= 1)
if (g_RhNumberOfProcessors <= 1)
break;

// Delay by approximately 2*i clock cycles (Pentium III).
Expand Down Expand Up @@ -241,7 +241,7 @@ void ReaderWriterLock::AcquireWriteLock()
RedhawkGCInterface::WaitForGCCompletion();
}

if (g_RhSystemInfo.dwNumberOfProcessors <= 1)
if (g_RhNumberOfProcessors <= 1)
{
break;
}
Expand Down
13 changes: 0 additions & 13 deletions src/coreclr/nativeaot/Runtime/arm/StubDispatch.S
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,6 @@

#ifdef FEATURE_CACHED_INTERFACE_DISPATCH

// TODO: Implement Arm support
#ifdef _DEBUG
.rodata
AssertMsg: .asciz "__FILE__:%s: %s is not implemented\n"
FileName: .asciz "StubDispatch.S"
RhpVTableOffsetDispatchName: .asciz "RhpVTableOffsetDispatch"
.text
.macro GEN_ASSERT_FUNC func
GEN_ASSERT AssertMsg, FileName, \func
.endm
#endif


// Macro that generates a stub consuming a cache with the given number of entries.
.macro DEFINE_INTERFACE_DISPATCH_STUB entries

Expand Down
6 changes: 0 additions & 6 deletions src/coreclr/nativeaot/Runtime/gcrhenv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,6 @@ bool RedhawkGCInterface::InitializeSubsystems()
MICROSOFT_WINDOWS_REDHAWK_GC_PUBLIC_PROVIDER_Context.RegistrationHandle = Microsoft_Windows_Redhawk_GC_PublicHandle;
#endif // FEATURE_ETW

if (!InitializeSystemInfo())
{
return false;
}

// Initialize the special EEType used to mark free list entries in the GC heap.
g_FreeObjectEEType.InitializeAsGcFreeType();
g_pFreeObjectEEType = &g_FreeObjectEEType;
Expand All @@ -188,7 +183,6 @@ bool RedhawkGCInterface::InitializeSubsystems()
return false;

#ifdef FEATURE_SVR_GC
// TODO: This should use the logical CPU count adjusted for process affinity and cgroup limits
g_heap_type = (g_pRhConfig->GetUseServerGC() && PalGetProcessCpuCount() > 1) ? GC_HEAP_SVR : GC_HEAP_WKS;
#else
g_heap_type = GC_HEAP_WKS;
Expand Down
15 changes: 1 addition & 14 deletions src/coreclr/nativeaot/Runtime/rhassert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void Assert(const char * expr, const char * file, uint32_t line_num, const char
switch (result)
{
case IDABORT:
PalTerminateProcess(PalGetCurrentProcess(), 666);
PalTerminateCurrentProcess(42);
break;
case IDRETRY:
PalDebugBreak();
Expand All @@ -94,17 +94,4 @@ void Assert(const char * expr, const char * file, uint32_t line_num, const char
#endif //!DACCESS_COMPILE
}

extern "C" void NYI_Assert(const char *message, ...)
{
#if !defined(DACCESS_COMPILE)
va_list args;
va_start(args, message);
vprintf(message, args);
va_end(args);
ASSERT_UNCONDITIONALLY("NYI");
#else
UNREFERENCED_PARAMETER(message);
#endif
}

#endif // _DEBUG
6 changes: 0 additions & 6 deletions src/coreclr/nativeaot/Runtime/rhassert.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@ void Assert(const char * expr, const char * file, unsigned int line_num, const c
#define _ASSERTE(_expr) ASSERT(_expr)
#endif

#if defined(_DEBUG)

void NYI_ASSERT();

#endif

#define PORTABILITY_ASSERT(message) \
ASSERT_UNCONDITIONALLY(message); \
ASSUME(0); \
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/nativeaot/Runtime/threadstore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ void ThreadStore::SuspendAllThreads(bool waitForGCEvent, bool fireDebugEvent)

if (keepWaiting)
{
if (PalSwitchToThread() == 0 && g_RhSystemInfo.dwNumberOfProcessors > 1)
if (PalSwitchToThread() == 0 && g_RhNumberOfProcessors > 1)
{
// No threads are scheduled on this processor. Perhaps we're waiting for a thread
// that's scheduled on another processor. If so, let's give it a little time
Expand Down
115 changes: 12 additions & 103 deletions src/coreclr/nativeaot/Runtime/unix/PalRedhawkUnix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,6 @@
#include <lwp.h>
#endif

#if HAVE_SYSCONF
// <unistd.h> already included above
#elif HAVE_SYSCTL
#include <sys/sysctl.h>
#else
#error Either sysctl or sysconf is required for GetSystemInfo.
#endif

#if HAVE_SYS_VMPARAM_H
#include <sys/vmparam.h>
#endif // HAVE_SYS_VMPARAM_H
Expand All @@ -73,24 +65,6 @@

using std::nullptr_t;

#ifndef __APPLE__
#if HAVE_SYSCONF && HAVE__SC_AVPHYS_PAGES
#define SYSCONF_PAGES _SC_AVPHYS_PAGES
#elif HAVE_SYSCONF && HAVE__SC_PHYS_PAGES
#define SYSCONF_PAGES _SC_PHYS_PAGES
#else
#error Dont know how to get page-size on this architecture!
#endif
#endif // __APPLE__

#if defined(HOST_ARM) || defined(HOST_ARM64)
#define SYSCONF_GET_NUMPROCS _SC_NPROCESSORS_CONF
#define SYSCONF_GET_NUMPROCS_NAME "_SC_NPROCESSORS_CONF"
#else
#define SYSCONF_GET_NUMPROCS _SC_NPROCESSORS_ONLN
#define SYSCONF_GET_NUMPROCS_NAME "_SC_NPROCESSORS_ONLN"
#endif

#define PalRaiseFailFastException RaiseFailFastException

#define FATAL_ASSERT(e, msg) \
Expand Down Expand Up @@ -126,10 +100,6 @@ static const int tccMilliSecondsToMicroSeconds = 1000;
static const int tccMilliSecondsToNanoSeconds = 1000000;
static const int tccMicroSecondsToNanoSeconds = 1000;

static uint32_t g_cNumProcs = 0;

bool QueryLogicalProcessorCount();

extern "C" void RaiseFailFastException(PEXCEPTION_RECORD arg1, PCONTEXT arg2, uint32_t arg3)
{
// Abort aborts the process and causes creation of a crash dump
Expand Down Expand Up @@ -401,9 +371,6 @@ void ConfigureSignals()
// initialization and false on failure.
REDHAWK_PALEXPORT bool REDHAWK_PALAPI PalInit()
{
if (!QueryLogicalProcessorCount())
return false;

#ifndef USE_PORTABLE_HELPERS
if (!InitializeHardwareExceptionHandling())
{
Expand All @@ -413,6 +380,14 @@ REDHAWK_PALEXPORT bool REDHAWK_PALAPI PalInit()

ConfigureSignals();

if (!GCToOSInterface::Initialize())
{
return false;
}

// Use the same adjustment for current processor count as GC
g_RhNumberOfProcessors = GCToOSInterface::GetCurrentProcessCpuCount();

return true;
}

Expand Down Expand Up @@ -705,30 +680,6 @@ REDHAWK_PALEXPORT void PalPrintFatalError(const char* message)
write(STDERR_FILENO, message, sizeof(message));
}

bool QueryLogicalProcessorCount()
{
#if HAVE_SYSCONF
g_cNumProcs = sysconf(SYSCONF_GET_NUMPROCS);
if (g_cNumProcs < 1)
{
ASSERT_UNCONDITIONALLY("sysconf failed for " SYSCONF_GET_NUMPROCS_NAME "\n");
return false;
}
#elif HAVE_SYSCTL
size_t sz = sizeof(g_cNumProcs);

int st = 0;
if (sysctlbyname("hw.logicalcpu_max", &g_cNumProcs, &sz, NULL, 0) != 0)
{
ASSERT_UNCONDITIONALLY("sysctl failed for hw.logicalcpu_max\n");
return false;
}

#endif // HAVE_SYSCONF

return true;
}

static int W32toUnixAccessControl(uint32_t flProtect)
{
int prot = 0;
Expand Down Expand Up @@ -904,14 +855,6 @@ extern "C" UInt32_BOOL IsDebuggerPresent()
#endif
}

extern "C" void TerminateProcess(HANDLE arg1, uint32_t arg2)
{
// TODO: change it to TerminateCurrentProcess
// Then if we modified the signature of the DuplicateHandle too, we can
// get rid of the PalGetCurrentProcess.
PORTABILITY_ASSERT("UNIXTODO: Implement this function");
}

extern "C" UInt32_BOOL SetEvent(HANDLE event)
{
EventUnixHandle* unixHandle = (EventUnixHandle*)event;
Expand Down Expand Up @@ -1002,9 +945,12 @@ extern "C" int32_t _stricmp(const char *string1, const char *string2)
return strcasecmp(string1, string2);
}

uint32_t g_RhNumberOfProcessors;

REDHAWK_PALEXPORT int32_t PalGetProcessCpuCount()
{
return g_cNumProcs;
ASSERT(g_RhNumberOfProcessors > 0);
return g_RhNumberOfProcessors;
}

__thread void* pStackHighOut = NULL;
Expand Down Expand Up @@ -1081,43 +1027,6 @@ REDHAWK_PALEXPORT int32_t PalGetModuleFileName(_Out_ const TCHAR** pModuleNameOu
#endif // defined(HOST_WASM)
}

GCSystemInfo g_RhSystemInfo;

// Initialize the g_SystemInfo
bool InitializeSystemInfo()
{
long pagesize = getpagesize();
g_RhSystemInfo.dwPageSize = pagesize;
g_RhSystemInfo.dwAllocationGranularity = pagesize;

int nrcpus = 0;

#if HAVE_SYSCONF
nrcpus = sysconf(SYSCONF_GET_NUMPROCS);
if (nrcpus < 1)
{
ASSERT_UNCONDITIONALLY("sysconf failed for " SYSCONF_GET_NUMPROCS_NAME "\n");
return false;
}
#elif HAVE_SYSCTL
int mib[2];

size_t sz = sizeof(nrcpus);
mib[0] = CTL_HW;
mib[1] = HW_NCPU;
int rc = sysctl(mib, 2, &nrcpus, &sz, NULL, 0);
if (rc != 0)
{
ASSERT_UNCONDITIONALLY("sysctl failed for HW_NCPU\n");
return false;
}
#endif // HAVE_SYSCONF

g_RhSystemInfo.dwNumberOfProcessors = nrcpus;

return true;
}

extern "C" void FlushProcessWriteBuffers()
{
GCToOSInterface::FlushProcessWriteBuffers();
Expand Down
5 changes: 0 additions & 5 deletions src/coreclr/nativeaot/Runtime/unix/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,13 @@
#cmakedefine01 HAVE_PTHREAD_GETTHREADID_NP

#cmakedefine01 HAVE_CLOCK_NANOSLEEP
#cmakedefine01 HAVE_SYSCTL
#cmakedefine01 HAVE_SYSCONF

#cmakedefine01 HAVE_GREGSET_T
#cmakedefine01 HAVE___GREGSET_T

#cmakedefine01 HAVE_SIGINFO_T
#cmakedefine01 HAVE_UCONTEXT_T

#cmakedefine01 HAVE__SC_PHYS_PAGES
#cmakedefine01 HAVE__SC_AVPHYS_PAGES

#cmakedefine01 HAVE_LWP_SELF
#cmakedefine01 HAVE_SCHED_GETCPU
#cmakedefine01 HAVE_CLOCK_MONOTONIC
Expand Down
Loading

0 comments on commit e28a392

Please sign in to comment.