Skip to content
Merged
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
6 changes: 6 additions & 0 deletions src/coreclr/src/vm/comsynchronizable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1450,6 +1450,12 @@ FCIMPL0(INT32, ThreadNative::GetCurrentProcessorNumber)
{
FCALL_CONTRACT;

#ifndef FEATURE_PAL
PROCESSOR_NUMBER proc_no_cpu_group;
GetCurrentProcessorNumberEx(&proc_no_cpu_group);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it OK if ThreadNative::GetCurrentProcessorNumber might return an index that is larger than total number of active processors on the system?

Copy link
Member Author

@VSadov VSadov Dec 5, 2019

Choose a reason for hiding this comment

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

Yes. What we return to the user is technically “ID correlated with last core we ran on”. We may even default to ThreadID if OS API is not functional. (PAL may return -1).

Are process groups contiguous? (1,2,3, ...)

Copy link
Member Author

Choose a reason for hiding this comment

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

To answer my question - yes, OS "packs" cores into as few process groups as possible and considers topology when assigning.
https://docs.microsoft.com/en-us/windows/win32/procthread/processor-groups

return (proc_no_cpu_group.Group << 6) | proc_no_cpu_group.Number;
#else
return ::GetCurrentProcessorNumber();
#endif //!FEATURE_PAL
}
FCIMPLEND;