Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. seems no one discuss SetProcessAffinityMask(), can I put thread to different cpu core in Windows?

seems no one discuss SetProcessAffinityMask(), can I put thread to different cpu core in Windows?

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 5 Posters 1.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    QtTester
    wrote on last edited by
    #1

    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.

    jsulmJ 1 Reply Last reply
    0
    • Q QtTester

      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.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi
        How do you control these motors ?
        And no, i dont think QTConcurrent will make you happy.

        1 Reply Last reply
        0
        • Q Offline
          Q Offline
          QtTester
          wrote on last edited by
          #4

          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.

          Christian EhrlicherC 1 Reply Last reply
          0
          • Q QtTester

            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.

            Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @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?

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            Q 1 Reply Last reply
            1
            • Christian EhrlicherC Christian Ehrlicher

              @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?

              Q Offline
              Q Offline
              QtTester
              wrote on last edited by
              #6

              @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

              jsulmJ 1 Reply Last reply
              0
              • Q QtTester

                @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

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by jsulm
                #7

                @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?

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                Q 1 Reply Last reply
                0
                • jsulmJ jsulm

                  @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?

                  Q Offline
                  Q Offline
                  QtTester
                  wrote on last edited by
                  #8

                  @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?

                  Christian EhrlicherC jsulmJ 2 Replies Last reply
                  -1
                  • Q QtTester

                    @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?

                    Christian EhrlicherC Offline
                    Christian EhrlicherC Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @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?

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    1 Reply Last reply
                    2
                    • Q QtTester

                      @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?

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @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...

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      Q 1 Reply Last reply
                      2
                      • jsulmJ jsulm

                        @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...

                        Q Offline
                        Q Offline
                        QtTester
                        wrote on last edited by QtTester
                        #11

                        @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.

                        alt text

                        1 Reply Last reply
                        0
                        • C Offline
                          C Offline
                          ChrisW67
                          wrote on last edited by
                          #12

                          @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.

                          1 Reply Last reply
                          1

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved