Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VirtualAlloc and affinity settings #71

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
35 changes: 35 additions & 0 deletions inc/cxplat_winkernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ CxPlatLogAssert(
#define CXPLAT_ALLOC_PAGED(Size, Tag) ExAllocatePool2(POOL_FLAG_PAGED | POOL_FLAG_UNINITIALIZED, Size, Tag)
#define CXPLAT_ALLOC_NONPAGED(Size, Tag) ExAllocatePool2(POOL_FLAG_NON_PAGED | POOL_FLAG_UNINITIALIZED, Size, Tag)
#define CXPLAT_FREE(Mem, Tag) ExFreePoolWithTag((void*)Mem, Tag)
#define CXPLAT_VIRTUAL_ALLOC(Size, TypeFlags, ProtectionFlags, Tag) \
CXPLAT_ALLOC_NONPAGED(Size, Tag)
#define CXPLAT_VIRTUAL_FREE(Mem, Size, Type, Tag) CXPLAT_FREE(Mem, Tag);

#define CxPlatZeroMemory RtlZeroMemory
#define CxPlatCopyMemory RtlCopyMemory
Expand Down Expand Up @@ -603,6 +606,38 @@ CxPlatThreadCreate(
typedef ULONG_PTR CXPLAT_THREAD_ID;
#define CxPlatCurThreadID() ((CXPLAT_THREAD_ID)PsGetCurrentThreadId())

inline
BOOLEAN
CxPlatSetThreadNodeAffinity(
LONG NodeAffinity
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not use Windows style all caps types like LONG.

Suggested change
LONG NodeAffinity
uint32_t NodeAffinity

)
{
GROUP_AFFINITY group;

KeQueryNodeActiveAffinity((USHORT)NodeAffinity, &group, NULL);
KeSetSystemGroupAffinityThread(&group, NULL);

return TRUE;
}

inline
BOOLEAN
CxPlatSetThreadGroupAffinity(
LONG GroupNumber,
DWORD_PTR CpuAffinity
)
{
GROUP_AFFINITY group = {0};

group.Mask = CpuAffinity;
group.Group = (USHORT)GroupNumber;

KeSetSystemGroupAffinityThread(&group, NULL);
Comment on lines +630 to +635
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
GROUP_AFFINITY group = {0};
group.Mask = CpuAffinity;
group.Group = (USHORT)GroupNumber;
KeSetSystemGroupAffinityThread(&group, NULL);
GROUP_AFFINITY group = { (KAFFINITY)CpuAffinity, GroupNumber, 0 };
KeSetSystemGroupAffinityThread(&group, NULL);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And make the similar changes to user mode.


return TRUE;
}


Comment on lines +639 to +640
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

nit: only 1 trailing blank newline

//
// Crypto Interfaces
//
Expand Down
43 changes: 43 additions & 0 deletions inc/cxplat_winuser.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ CxPlatFree(
#define CXPLAT_ALLOC_PAGED(Size, Tag) CxPlatAlloc(Size, Tag)
#define CXPLAT_ALLOC_NONPAGED(Size, Tag) CxPlatAlloc(Size, Tag)
#define CXPLAT_FREE(Mem, Tag) CxPlatFree((void*)Mem, Tag)
#define CXPLAT_VIRTUAL_ALLOC(Size, TypeFlags, ProtectionFlags, Tag) \
VirtualAlloc(NULL, Size, TypeFlags, ProtectionFlags)
#define CXPLAT_VIRTUAL_FREE(Mem, Size, Type, Tag) VirtualFree(Mem, Size, Type);

#define CxPlatZeroMemory RtlZeroMemory
#define CxPlatCopyMemory RtlCopyMemory
Expand Down Expand Up @@ -597,6 +600,46 @@ CxPlatThreadWaitWithTimeout(
typedef uint32_t CXPLAT_THREAD_ID;
#define CxPlatCurThreadID() GetCurrentThreadId()

inline
BOOLEAN
CxPlatSetThreadNodeAffinity(
LONG NodeAffinity
)
{
GROUP_AFFINITY group;

if (!GetNumaNodeProcessorMaskEx((USHORT)NodeAffinity, &group)) {
CXPLAT_DBG_ASSERT(FALSE);
return FALSE;
}
if (!SetThreadGroupAffinity(GetCurrentThread(), &group, NULL)) {
CXPLAT_DBG_ASSERT(FALSE);
return FALSE;
}

return TRUE;
}

inline
BOOLEAN
CxPlatSetThreadGroupAffinity(
LONG GroupNumber,
DWORD_PTR CpuAffinity
)
{
GROUP_AFFINITY group = {0};

group.Mask = CpuAffinity;
group.Group = (WORD)GroupNumber;
if (!SetThreadGroupAffinity(GetCurrentThread(), &group, NULL)) {
CXPLAT_DBG_ASSERT(FALSE);
return FALSE;
}

return TRUE;
}


Comment on lines +641 to +642
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

nit: only 1 trailing blank newline

//
// Crypto Interfaces
//
Expand Down