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. Processor occupancy
QtWS25 Last Chance

Processor occupancy

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 4 Posters 1.4k 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.
  • A Offline
    A Offline
    ADVUser
    wrote on last edited by
    #1

    Hi everyone,

    I have a problem with my processor occupancy.
    I am working on Windows 7, my processor is an Intel core i5 4460 (4 cores 4 threads).
    I created a cpp qt program with a main thread (GUI), and two others threads (one for an Ethernet communication and the other to read a file).
    I had a problem on this program (now solved) which occupied a lot the processor. But the maximal processor occupancy was 50%. I don't know why ...
    Do you have an idea ?

    Thank you !

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Hi! Did I get this right, you're basically complaining that your bug only fried a single core? :-D

      1 Reply Last reply
      3
      • D Offline
        D Offline
        DRoscoe
        wrote on last edited by
        #3

        I'm not sure I understand the problem, but you could be looking at a feature of the processor hardware. With i5 and i7 processors, it can actually split a single thread across more than one processor core. In theory this prevents poor performance from a processor-hungry process. Historically this was not done because the cache thrashing would negate any benefit. However, i5 and i7 has a cache for each core in addition to the L3 cache shared by all. I have seen this same behavior in my application. It employs a genetic algorithm which gobbles up 100% of the processor for 10+ seconds at a time. However, when I look at the performance tab of Task Manager, I see its actually splitting it across two cores at 50% each.

        1 Reply Last reply
        3
        • A Offline
          A Offline
          ADVUser
          wrote on last edited by
          #4

          I wanted to know why I can't go above 50%, while I have got 3 threads ...

          JohanSoloJ 1 Reply Last reply
          0
          • A ADVUser

            I wanted to know why I can't go above 50%, while I have got 3 threads ...

            JohanSoloJ Offline
            JohanSoloJ Offline
            JohanSolo
            wrote on last edited by
            #5

            @ADVUser said in Processor occupancy:

            I wanted to know why I can't go above 50%, while I have got 3 threads ...

            Maybe your processing has some blocking command, which result in an average usage of 2 threads running at full speed. Fortunately, N threads in a program does not necessarily in N / n cores used at 100%.

            `They did not know it was impossible, so they did it.'
            -- Mark Twain

            1 Reply Last reply
            0
            • ? Offline
              ? Offline
              A Former User
              wrote on last edited by A Former User
              #6

              Just as a test, the following should work:

              heater.h

              #ifndef HEATER_H
              #define HEATER_H
              
              #include <QObject>
              
              class Heater : public QObject
              {
                  Q_OBJECT
              public:
                  explicit Heater(QObject *parent = 0);
              public slots:
                  void process();
              };
              
              #endif // HEATER_H
              

              heater.cpp

              #include "heater.h"
              
              Heater::Heater(QObject *parent)
                  : QObject(parent)
              {
              }
              
              void Heater::process()
              {
                  auto a = 0;
                  auto b = 0;
                  while (true) {
                      a = ++b * ++a;
                  }
              }
              

              main.cpp

              #include <QCoreApplication>
              #include <QThread>
              
              #include "heater.h"
              
              int main(int argc, char *argv[])
              {
                  QCoreApplication a(argc, argv);
              
                  const auto thread_count = 8;
                  for (auto i=0; i<thread_count; ++i) {
                      QThread* thread = new QThread;
                      Heater* heater = new Heater();
                      heater->moveToThread(thread);
                      QObject::connect(thread, &QThread::started, heater, &Heater::process);
                      thread->start();
                  }
              
                  return a.exec();
              }
              
              1 Reply Last reply
              5
              • A Offline
                A Offline
                ADVUser
                wrote on last edited by
                #7

                Thank you for this code, it explains such things...
                It is interresting to modulate the thread count number
                Bye !

                1 Reply Last reply
                0

                • Login

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