Unsolved seems no one discuss SetProcessAffinityMask(), can I put thread to different cpu core in Windows?
-
HI, guys.
I must write an efficient program to control a machine through servo-motors on Windows 7 @ i5 processor.
I think move different thread to different CPU core will work better.
as we know , SetProcessAffinityMask() can move thread to a core, so , in QT how can i do that?
will QTConcurrent satisfy me?
thank you. -
@QtTester said in seems no one discuss SetProcessAffinityMask(), can I put thread to different cpu core in Windows?:
I think
You think or your know?
Do you have concrete issues or is this an attempt of premature optimisation? -
Hi
How do you control these motors ?
And no, i dont think QTConcurrent will make you happy. -
thanks for replying , I have some PCI control card, the card will send pulse to controller.
Windows will only run my program except himself process.
So I would like to control Intel CPU like ARM cortex series, I would like to occupy all cpu core to assure my program to run at highest priority. -
@QtTester So is it currently not the case? What's your problem why you need to do such low level things instead trusting the OS doing the right thing? Do you actually have any problems?
-
@Christian-Ehrlicher
You need to consider the architecture before writing the code.
for example:
Core1: Gui thread
Core2: Control thread1
Core3: Control thread2
Core4: Control thread3 -
@QtTester Why do you think you need to control which thread is running on which core?
And you did not say whether you have any real issues."You need to consider the architecture before writing the code" - why do you have to consider which thread is running on which core? Why don't you let the OS do it's job? What is the issue?
-
@jsulm OK, We can talk about in another way:
we know Windows is not a real-time OS, so ,how to make it real-time? -
@QtTester said in seems no one discuss SetProcessAffinityMask(), can I put thread to different cpu core in Windows?:
Windows is not a real-time OS, so ,how to make it real-time?
You ask a question and answer it by yourself in the sentence before...
Why do you need real-time? What is 'real-time' in your use-case?
-
@QtTester said in seems no one discuss SetProcessAffinityMask(), can I put thread to different cpu core in Windows?:
We can talk about in another way
We should first talk about what you really need and whether you have any REAL issues (you refuse to answer this question). I have the impression that you're trying to solve a non-existent issue...
-
@jsulm Hi jsulm.
Recently I get in touch with kithara.com and codesys.com.
They design a real-time kernel under Windows kernel.
Basically the software is to occupy a separate core and run the task.
That's why i need to run my task in a separate cpu core. they already did what i want.
In a motion and machine-vision application , you will need the realtime task. -
@QtTester said in seems no one discuss SetProcessAffinityMask(), can I put thread to different cpu core in Windows?:
SetProcessAffinityMask() can move thread to a core, so , in QT how can i do that?
SetProcessAffinityMask, and the related GetProcessAffinityMask, is a Windows API call that will limit all the threads of a process to specific processors. It does not drive single threads, that's SetThreadAffinityMask. You do it in your C++/C code by including winbase.h and calling the functions. Nothing to do with Qt.
I would like to occupy all cpu core to assure my program to run at highest priority.
By default the threads of your program will run on any suitable core when it reaches the top of the scheduler queue. This has nothing to do with scheduling priority, i.e. your thread always get run before any other pending thread, which seems to be what you are thinking.
To quote Microsoft:
Thread affinity forces a thread to run on a specific subset of processors. Setting thread affinity should generally be avoided, because it can interfere with the scheduler's ability to schedule threads effectively across processors. This can decrease the performance gains produced by parallel processing. An appropriate use of thread affinity is testing each processor.
I have some PCI control card, the card will send pulse to controller.
Then, in all likelihood, all the real time activity, i.e sending 1ms pulses at a certain duty cycle and sensing the result, is happening on the card and your process is merely supervising and sending high-level commands. Your code, in that case, does not need special consideration.
If you want to drive the Intel CPU directly then you can do so, but you don't use Windows.