How to run code on a specific CPU

How to run code on a specific CPU

Imagen de mguptamel

Hi all,

I have multi-core processor (Core -2 duo) which has 4 logical processors. I would like to switch processor to run the code. For example,

;Assuming code is running on CPU-0
mov eax, ecx

; I want to switchto CPU-1 (don't know how to go about it)
mov ebx, eax

; Switch back to CPU-0 here
mov ecx, eax

Note: Above is just a sample code. My intentions are to learn how to switch b/w CPU's and to set code affinity to a specific CPU

Help appreciated


publicaciones de 3 / 0 nuevos
Último envío
Para obtener más información sobre las optimizaciones del compilador, consulte el aviso sobre la optimización.
Imagen de Tim Prince

This question might be handled better on the threading forum, but you should specify your OS and more about what you wish to accomplish.

Imagen de mguptamel

Thanks Tim. I will re-ask this question in threading forum.

I was writing a test driver in Windows OS, and came across KeSetProcessorAffinity function which was forcing the code to run on a specific processor. After the call, the code somehow started running on CPU [0-3]. That made me think what could be logic behind this function call. And that was my original question.

After reading through Intel documentation, I know how interrupt routines can be executed on a dedicated processor (by setting destination bits in IOREDIRECT table - IOAPIC), but I don't know exactly how a running thread can be executed on a specific processor.

Inicie sesión para dejar un comentario.