How to run code on a specific CPU

How to run code on a specific CPU

mguptamel's picture

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

Regards
Gupta

3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.
Tim Prince's picture

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

mguptamel's picture

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.

Login to leave a comment.