read core 0 not work well on kernel

daniel02x 26 Reputation points
2022-09-27T14:09:36.38+00:00

im trying read rdtsc 1 nanosecond on kernel but the problem i cant read core 0 properly by those apis KeSetSystemGroupAffinityThread KeSetSystemAffinityThreadEx KeSetAffinityThread all those apis fail to read core 0 the only one that work for me was to create systemthread by using PsCreateSystemThread then read core 0 from ZwSetInformationThread may i ask why those apis fail to read core 0?

int64_t readcore()  
{  
	KAFFINITY affinity = (1ULL);  
	return (int64_t)KeSetSystemAffinityThreadEx(affinity);  
}  
  
void readcore()  
{  
const ULONG numberOfProcessors = KeQueryActiveProcessorCountEx(ALL_PROCESSOR_GROUPS);  
	PROCESSOR_NUMBER processorNumber;  
  
	NTSTATUS status = KeGetProcessorNumberFromIndex(numberOfProcessors - 1, &processorNumber);  
	if (!NT_SUCCESS(status))  
	{  
		return;  
	}  
  
	GROUP_AFFINITY affinity, oldAffinity;  
	affinity.Group = processorNumber.Group;  
	affinity.Mask = 1ULL << processorNumber.Number;  
	affinity.Reserved[0] = affinity.Reserved[1] = affinity.Reserved[2] = 0;  
	KeSetSystemGroupAffinityThread(&affinity, &oldAffinity);  
}  
  
  
VOID switchToCPU(CCHAR cpu)  
{  
	UNICODE_STRING ustrKeSetAffinityThread;  
  
	RtlInitUnicodeString(&ustrKeSetAffinityThread, L"KeSetAffinityThread");  
	KeSetAffinityThread = (_KeSetAffinityThread)MmGetSystemRoutineAddress(&ustrKeSetAffinityThread);  
	KeSetAffinityThread(KeGetCurrentThread(), 1 << cpu);  
}  
  
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,544 questions
Windows Hardware Performance
Windows Hardware Performance
Windows: A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.Hardware Performance: Delivering / providing hardware or hardware systems or adjusting / adapting hardware or hardware systems.
1,551 questions
0 comments No comments
{count} votes