cpu management in hyperthreading

I work with a single processor with hyperthreading activated
I have 2 questions :

  1. I want to launch a thread on the cpu 2 with maximum 63 priority (in order to get the same performance than I have on a single processor without any OS). Most of the time my thread is automatically launch on cpu2, but because I got some freezes, I suspect that sometime my thread is launched on cpu1. I want to force it on cpu 2 (or on the cpu that does not run the OS scheduler).

Processor affinity mask seems not to be in the thread attributes, which command should I use to launch the thread on the right cpu ?

  1. With hyperthreading (assuming there is not two real processors), will my cpu2 thread will have the priority of use on the sharing of the processor internal ressources (in concurrence with other threads of cpu1). Should I look to the intel documentation (in the case the processor has its own processor ressource sheduling), or does the Neutrino can answer to the question ? I guess that cpu1 may have the internal ressource priority, is that right ?, in this case how could I cleanly swap the processors to set my thread on cpu1 ?

Thanks for your help


  1. The function “ThreadCtl(_NTO_TCTL_RUNMASK, mask)” allow you “bind” the calling thread to a
    specific cpu (set).

  2. Not sure what you are asking for. Hyperthreading on Neutrino is just operate the same
    as a SMP machine. The fact it is “hypertheading”, could affect to some scheduling decision,
    but I believe from the discussion I’ve seen, the schedule decision is highly depends on
    whatis the thread doing. So, there isn’t a “best for all case” thing yet.

  1. When the thread is launched it may be “randomly” run to a cpu or another, what actually do ThreadCtl(_NTO_TCTL_RUNMASK, TWO) if the calling thread is on cpu ONE, is it moved to cpu TWO at the next schedule ? Is there any way to prepare the thread to go on the desire cpu before creating it ?

  2. Hyperthreading simulate roughly smp, but in fact the cpu internal resources are shared. My question is : will a thread with higher priority have priority over the internal resources of the unique cpu, or does it depends of something else ?

The rule on SMP is that the highest priority thread that is ready to run will be running. Not the highest 2 (or more), just the highest. Neutrino does a very good job trying to assure that the threads don’t migrate between CPUs unless the cost isn’t going to be noticeable anyways. On a HT machine there actually isn’t much cost moving between the two virtual CPUs so ti doesn’t really matter.

Why exactly do you want to lock a thread to the CPU? That isn’t going to allow you do take as much advantage of having the virtualized CPU.

I agree that Neutrino make a very good job, I just invetigate to know how to be optimal

I have two thread : one for intensive computation and IO with a 15 microsec computation loop and a real time reactivity constraint (that used to be just ok with 100% cpu ) and one for human interface and communication.

My computation code was running without any OS support and used 100% of the cpu. I want to use QNX to get new features (human interface and network communication) but keeping the previous performance. To succeed in porting the code to QNX I need to be as closest as possible of my previous developpement. That is the reason.

Until now my port is not to bad but I guess it could be better by mastering cpu allocation, (even logical for now) but which will become physical in dual processor platform.

Do you have any answer to my previous questions ?

  1. it’s a runmask. by default, the mask is like 0xffffffff, so the thread could go every CPU.
    if you set it to 0x00000002, then the calling thread could only run on CPU 2.

  2. I am not the expert but I think those “internal resources” you are talking about, is
    somehow transparent to the OS. At least Neutrino only treat it AS IF this is a 2 CPU

  1. Ok

  2. When I disable interrupt on cpu2, the computer hangs !
    Why and how to cure that ? I guess that some part of Neutrino also execute on cpu2 even when I set the maximum priority. Is that normal ? Is it because the inter(logical)processor interrupts are also disabled ? How can I avoid that ? Is it the same on a real bi-processor ?

I suspect it is the same since I believe only CPU0 handles interrupt dispatching. So the problem is not that the kernel is running on CPU1, but rather that the parts of os always run on CPU0.

Sorry I don’t anderstand

Why would you want to disable interrupts?

To make it works like I want :

cpu1 : Neutrino+Human interface+Communication
cpu2 : 100% computation code + I/O && NO OS feature at all

Isn’t it posssible to configure like that ? How ?

Try not running the SMP kernel so QNX is not aware of the second CPU and then start it yourself. It might be doable, but you would have to configure everything yourself and make sure you know how QNX deals with SMP to make it work. There would probably be issues with the APIC, but without spending some time thinking about it, I am not sure whether it would work or not.

And it really won’t be worth while. If you sent the runmask for the computational thread that is running at 100% CPU to the second CPU nothing else will get scheduledd for that one (as long as you run it at the higest priority in the system).
We actually do this to “simulate” less CPUs when testing other code (run 100% CPU threads on the CPUs we want to disable).