Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/dlls/mscordac/mscordac_unixexports.src
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ PAL_GetPALDirectoryW
PAL_GetResourceString
PAL_get_stdout
PAL_get_stderr
PAL_GetCurrentThread
PAL_GetSymbolModuleBase
PAL_GetTransportPipeName
PAL_InitializeDLL
Expand Down
4 changes: 0 additions & 4 deletions src/gc/gc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5151,7 +5151,6 @@ void gc_heap::destroy_thread_support ()
}
}

#if !defined(FEATURE_PAL)
void set_thread_group_affinity_for_heap(int heap_number, GCThreadAffinity* affinity)
{
affinity->Group = GCThreadAffinity::None;
Expand Down Expand Up @@ -5231,7 +5230,6 @@ void set_thread_affinity_mask_for_heap(int heap_number, GCThreadAffinity* affini
}
}
}
#endif // !FEATURE_PAL

bool gc_heap::create_gc_thread ()
{
Expand All @@ -5241,7 +5239,6 @@ bool gc_heap::create_gc_thread ()
affinity.Group = GCThreadAffinity::None;
affinity.Processor = GCThreadAffinity::None;

#if !defined(FEATURE_PAL)
if (!gc_thread_no_affinitize_p)
{
// We are about to set affinity for GC threads. It is a good place to set up NUMA and
Expand All @@ -5252,7 +5249,6 @@ bool gc_heap::create_gc_thread ()
else
set_thread_affinity_mask_for_heap(heap_number, &affinity);
}
#endif // !FEATURE_PAL

return GCToOSInterface::CreateThread(gc_thread_stub, this, &affinity);
}
Expand Down
4 changes: 2 additions & 2 deletions src/inc/utilcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -1380,7 +1380,7 @@ class NumaNodeInfo
static BOOL CanEnableGCNumaAware();
static void InitNumaNodeInfo();

#if !defined(FEATURE_REDHAWK)&& !defined(FEATURE_PAL)
#if !defined(FEATURE_REDHAWK)
private: // apis types

//GetNumaHighestNodeNumber()
Expand Down Expand Up @@ -1448,7 +1448,7 @@ class CPUGroupInfo
static DWORD CalculateCurrentProcessorNumber();
//static void PopulateCPUUsageArray(void * infoBuffer, ULONG infoSize);

#if !defined(FEATURE_REDHAWK) && !defined(FEATURE_PAL)
#if !defined(FEATURE_REDHAWK)
private:
//GetLogicalProcessorInforomationEx()
typedef BOOL
Expand Down
155 changes: 155 additions & 0 deletions src/pal/inc/pal.h
Original file line number Diff line number Diff line change
Expand Up @@ -4825,6 +4825,161 @@ RegisterEventSourceW (
#define RegisterEventSource RegisterEventSourceA
#endif // !UNICODE

//
// NUMA related APIs
//

typedef enum _PROCESSOR_CACHE_TYPE {
CacheUnified,
CacheInstruction,
CacheData,
CacheTrace
} PROCESSOR_CACHE_TYPE;

typedef struct _PROCESSOR_NUMBER {
WORD Group;
BYTE Number;
BYTE Reserved;
} PROCESSOR_NUMBER, *PPROCESSOR_NUMBER;

typedef enum _LOGICAL_PROCESSOR_RELATIONSHIP {
RelationProcessorCore,
RelationNumaNode,
RelationCache,
RelationProcessorPackage,
RelationGroup,
RelationAll = 0xffff
} LOGICAL_PROCESSOR_RELATIONSHIP;

typedef ULONG_PTR KAFFINITY;

#define ANYSIZE_ARRAY 1

typedef struct _GROUP_AFFINITY {
KAFFINITY Mask;
WORD Group;
WORD Reserved[3];
} GROUP_AFFINITY, *PGROUP_AFFINITY;

typedef struct _PROCESSOR_GROUP_INFO {
BYTE MaximumProcessorCount;
BYTE ActiveProcessorCount;
BYTE Reserved[38];
KAFFINITY ActiveProcessorMask;
} PROCESSOR_GROUP_INFO, *PPROCESSOR_GROUP_INFO;

typedef struct _PROCESSOR_RELATIONSHIP {
BYTE Flags;
BYTE EfficiencyClass;
BYTE Reserved[21];
WORD GroupCount;
GROUP_AFFINITY GroupMask[ANYSIZE_ARRAY];
} PROCESSOR_RELATIONSHIP, *PPROCESSOR_RELATIONSHIP;

typedef struct _GROUP_RELATIONSHIP {
WORD MaximumGroupCount;
WORD ActiveGroupCount;
BYTE Reserved[20];
PROCESSOR_GROUP_INFO GroupInfo[ANYSIZE_ARRAY];
} GROUP_RELATIONSHIP, *PGROUP_RELATIONSHIP;

typedef struct _NUMA_NODE_RELATIONSHIP {
DWORD NodeNumber;
BYTE Reserved[20];
GROUP_AFFINITY GroupMask;
} NUMA_NODE_RELATIONSHIP, *PNUMA_NODE_RELATIONSHIP;

typedef struct _CACHE_RELATIONSHIP {
BYTE Level;
BYTE Associativity;
WORD LineSize;
DWORD CacheSize;
PROCESSOR_CACHE_TYPE Type;
BYTE Reserved[20];
GROUP_AFFINITY GroupMask;
} CACHE_RELATIONSHIP, *PCACHE_RELATIONSHIP;

typedef struct _SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX {
LOGICAL_PROCESSOR_RELATIONSHIP Relationship;
DWORD Size;
union {
PROCESSOR_RELATIONSHIP Processor;
NUMA_NODE_RELATIONSHIP NumaNode;
CACHE_RELATIONSHIP Cache;
GROUP_RELATIONSHIP Group;
};
} SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX, *PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX;


PALIMPORT
BOOL
PALAPI
GetNumaHighestNodeNumber(
OUT PULONG HighestNodeNumber
);

PALIMPORT
BOOL
PALAPI
GetNumaProcessorNodeEx(
IN PPROCESSOR_NUMBER Processor,
OUT PUSHORT NodeNumber
);

PALIMPORT
LPVOID
PALAPI
VirtualAllocExNuma(
IN HANDLE hProcess,
IN OPTIONAL LPVOID lpAddress,
IN SIZE_T dwSize,
IN DWORD flAllocationType,
IN DWORD flProtect,
IN DWORD nndPreferred
);

PALIMPORT
BOOL
PALAPI
GetLogicalProcessorInformationEx(
IN LOGICAL_PROCESSOR_RELATIONSHIP RelationshipType,
OUT OPTIONAL PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX Buffer,
IN OUT PDWORD ReturnedLength
);

PALIMPORT
BOOL
PALAPI
SetThreadGroupAffinity(
IN HANDLE hThread,
IN const GROUP_AFFINITY *GroupAffinity,
OUT OPTIONAL PGROUP_AFFINITY PreviousGroupAffinity
);

PALIMPORT
BOOL
PALAPI
GetThreadGroupAffinity(
IN HANDLE hThread,
OUT PGROUP_AFFINITY GroupAffinity
);

PALIMPORT
VOID
PALAPI
GetCurrentProcessorNumberEx(
OUT PPROCESSOR_NUMBER ProcNumber
);

PALIMPORT
BOOL
PALAPI
GetProcessAffinityMask(
IN HANDLE hProcess,
OUT PDWORD_PTR lpProcessAffinityMask,
OUT PDWORD_PTR lpSystemAffinityMask
);

//
// The types of events that can be logged.
//
Expand Down
7 changes: 7 additions & 0 deletions src/pal/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ set(SOURCES
misc/sysinfo.cpp
misc/time.cpp
misc/utils.cpp
numa/numa.cpp
objmgr/palobjbase.cpp
objmgr/shmobject.cpp
objmgr/shmobjectmanager.cpp
Expand Down Expand Up @@ -372,6 +373,12 @@ if(CMAKE_SYSTEM_NAME STREQUAL NetBSD)
)
endif(CMAKE_SYSTEM_NAME STREQUAL NetBSD)

if(HAVE_NUMA_H)
target_link_libraries(coreclrpal
numa
)
endif(HAVE_NUMA_H)

add_subdirectory(examples)

if(FEATURE_EVENT_TRACE)
Expand Down
5 changes: 5 additions & 0 deletions src/pal/src/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#cmakedefine01 HAVE_SYS_SYSCTL_H
#cmakedefine01 HAVE_GNU_LIBNAMES_H
#cmakedefine01 HAVE_PRCTL_H
#cmakedefine01 HAVE_NUMA_H
#cmakedefine01 HAVE_PTHREAD_NP_H

#cmakedefine01 HAVE_KQUEUE
#cmakedefine01 HAVE_GETPWUID_R
Expand All @@ -33,6 +35,8 @@
#cmakedefine01 HAVE_PTHREAD_GETATTR_NP
#cmakedefine01 HAVE_PTHREAD_GETCPUCLOCKID
#cmakedefine01 HAVE_PTHREAD_SIGQUEUE
#cmakedefine01 HAVE_PTHREAD_GETAFFINITY_NP
#cmakedefine01 HAVE_CPUSET_T
#cmakedefine01 HAVE_SIGRETURN
#cmakedefine01 HAVE__THREAD_SYS_SIGRETURN
#cmakedefine01 HAVE_COPYSIGN
Expand All @@ -57,6 +61,7 @@
#cmakedefine01 HAS_SYSV_SEMAPHORES
#cmakedefine01 HAS_PTHREAD_MUTEXES
#cmakedefine01 HAVE_TTRACE
#cmakedefine01 HAVE_SCHED_GETAFFINITY
#cmakedefine HAVE_UNW_GET_SAVE_LOC
#cmakedefine HAVE_UNW_GET_ACCESSORS
#cmakedefine01 HAVE_XSWDEV
Expand Down
11 changes: 11 additions & 0 deletions src/pal/src/configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ check_include_files(libunwind.h HAVE_LIBUNWIND_H)
check_include_files(runetype.h HAVE_RUNETYPE_H)
check_include_files(semaphore.h HAVE_SEMAPHORE_H)
check_include_files(sys/prctl.h HAVE_PRCTL_H)
check_include_files(numa.h HAVE_NUMA_H)
check_include_files(pthread_np.h HAVE_PTHREAD_NP_H)

if(NOT CMAKE_SYSTEM_NAME STREQUAL FreeBSD AND NOT CMAKE_SYSTEM_NAME STREQUAL NetBSD)
set(CMAKE_REQUIRED_FLAGS "-ldl")
Expand Down Expand Up @@ -69,6 +71,7 @@ check_library_exists(${PTHREAD_LIBRARY} pthread_attr_get_np "" HAVE_PTHREAD_ATTR
check_library_exists(${PTHREAD_LIBRARY} pthread_getattr_np "" HAVE_PTHREAD_GETATTR_NP)
check_library_exists(${PTHREAD_LIBRARY} pthread_getcpuclockid "" HAVE_PTHREAD_GETCPUCLOCKID)
check_library_exists(${PTHREAD_LIBRARY} pthread_sigqueue "" HAVE_PTHREAD_SIGQUEUE)
check_library_exists(${PTHREAD_LIBRARY} pthread_getaffinity_np "" HAVE_PTHREAD_GETAFFINITY_NP)

check_function_exists(sigreturn HAVE_SIGRETURN)
check_function_exists(_thread_sys_sigreturn HAVE__THREAD_SYS_SIGRETURN)
Expand Down Expand Up @@ -119,6 +122,14 @@ int main(int argc, char **argv) {
}" HAVE_UNW_GET_ACCESSORS)
set(CMAKE_REQUIRED_LIBRARIES)

check_cxx_source_compiles("
#include <pthread_np.h>
int main(int argc, char **argv) {
cpuset_t cpuSet;

return 0;
}" HAVE_CPUSET_T)

check_struct_has_member ("struct stat" st_atimespec "sys/types.h;sys/stat.h" HAVE_STAT_TIMESPEC)
check_struct_has_member ("struct stat" st_atimensec "sys/types.h;sys/stat.h" HAVE_STAT_NSEC)
check_struct_has_member ("struct tm" tm_gmtoff time.h HAVE_TM_GMTOFF)
Expand Down
2 changes: 1 addition & 1 deletion src/pal/src/include/pal/dbgmsg.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ typedef enum
#ifdef FEATURE_PAL_SXS
DCI_SXS,
#endif // FEATURE_PAL_SXS

DCI_NUMA,
DCI_LAST
} DBG_CHANNEL_ID;

Expand Down
39 changes: 39 additions & 0 deletions src/pal/src/include/pal/numa.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

/*++



Module Name:

include/pal/numa.h

Abstract:

Header file for the NUMA functions.



--*/

#ifndef _PAL_NUMA_H_
#define _PAL_NUMA_H_

#ifdef __cplusplus
extern "C"
{
#endif // __cplusplus

BOOL
NUMASupportInitialize();

VOID
NUMASupportCleanup();

#ifdef __cplusplus
}
#endif // __cplusplus

#endif /* _PAL_CRITSECT_H_ */
8 changes: 8 additions & 0 deletions src/pal/src/init/pal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ SET_DEFAULT_DEBUG_CHANNEL(PAL); // some headers have code with asserts, so do th
#include "pal/debug.h"
#include "pal/locale.h"
#include "pal/init.h"
#include "pal/numa.h"
#include "pal/stackstring.hpp"

#if HAVE_MACH_EXCEPTIONS
Expand Down Expand Up @@ -523,6 +524,12 @@ Initialize(
goto CLEANUP15;
}

if (FALSE == NUMASupportInitialize())
{
ERROR("Unable to initialize NUMA support\n");
goto CLEANUP15;
}

TRACE("First-time PAL initialization complete.\n");
init_count++;

Expand All @@ -548,6 +555,7 @@ Initialize(
}
goto done;

NUMASupportCleanup();
/* No cleanup required for CRTInitStdStreams */
CLEANUP15:
FILECleanupStdHandles();
Expand Down
1 change: 0 additions & 1 deletion src/pal/src/map/virtual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1280,7 +1280,6 @@ VirtualAlloc(
return pRetVal;
}


/*++
Function:
VirtualFree
Expand Down
Loading