6 Replies
      Latest reply on Dec 12, 2019 6:49 AM by avitzur
      Jones Level 1 Level 1 (0 points)

        Hi,

        I'm facing an interessting effect within my application when using multiple pthreads that execute computation intensive tasks. When the threads start processing the data, the main thread function takes ~20 ms for a single loop of processing. This time stays constant for a couple of seconds. After that, the computation time rises to ~80 ms. The thread is sill doing the same kind of work, just with different values, so I would expect the execution time to stay constant.

        The initial approach to resolve this was to specify a Quality of Service Class for the pthreads involved. This indeed solved the problem for that time. Now the amount of data to process is getting bigger and the QOS setting seems to not work anymore. I'm now facing the same execution time changes as at the beginning.

        Is there anything else I can do except of setting the QOS when the pthreads are created?

         

        That's the API I'm using to set the QOS class for the pthread.

        pthread_attr_set_qos_class_np(&qos_attr, QOS_CLASS_USER_INTERACTIVE, 0);

         

        I'm running the application with standard Release build configuration.

         

        THX!

        • Re: pthreads and Quality of Service Classes
          eskimo Apple Staff Apple Staff (13,425 points)

          I'm facing an interessting effect within my application when using multiple pthreads that execute computation intensive tasks. When the threads start processing the data, the main thread function takes ~20 ms for a single loop of processing.

          I’m confused by your terminology here.  Normally when folks say “main thread” they’re referring to, well, the main thread, the thing running the GUI.  In this context, however, it seems like you’re using it to mean the main thread of your background computation code.

          Please clarify.

          Share and Enjoy

          Quinn “The Eskimo!”
          Apple Developer Relations, Developer Technical Support, Core OS/Hardware
          let myEmail = "eskimo" + "1" + "@apple.com"

          WWDC runs Mon, 13 Jun through to Fri, 17 Jun.  During that time all of DTS will be at the conference, helping folks out face-to-face. http://developer.apple.com/wwdc/

            • Re: pthreads and Quality of Service Classes
              Jones Level 1 Level 1 (0 points)

              Hi Quinn,
              Sorry for the confusion. I refer to the function the pthread was created with. Inside that function we have a while loop calling our data processing algorithm.

               

              Thx,

              Andreas

                • Re: pthreads and Quality of Service Classes
                  eskimo Apple Staff Apple Staff (13,425 points)

                  I refer to the function the pthread was created with.

                  OK.

                  With that in mind, re-reading your original post it doesn’t sound like a QoS of QOS_CLASS_USER_INTERACTIVE is right here.  That QoS is appropriate when the work is directly responsible for keeping the UI responsive.  To quote <sys/qos.h>:

                  A QOS class which indicates work performed by this thread

                  Such work is requested to run at high priority relative to other work on the system. Specifying this QOS class is a request to run with nearly all available system CPU and I/O bandwidth even under contention. This is not an energy-efficient QOS class to use for large tasks. The use of this QOS class should be limited to critical interaction with the user such as handling events on the main event loop, view drawing, animation, etc.

                  Is that an accurate description of the relationship between this work and your UI?

                  Share and Enjoy

                  Quinn “The Eskimo!”
                  Apple Developer Relations, Developer Technical Support, Core OS/Hardware
                  let myEmail = "eskimo" + "1" + "@apple.com"

                  WWDC runs Mon, 13 Jun through to Fri, 17 Jun.  During that time all of DTS will be at the conference, helping folks out face-to-face. http://developer.apple.com/wwdc/

                    • Re: pthreads and Quality of Service Classes
                      Jones Level 1 Level 1 (0 points)

                      Hi Quinn,
                      ```QOS_CLASS_USER_INTERACTIVE``` is correct here because the calculation is needed to update OpenGL rendering @30 or 60 fps.

                       

                      Is there some kind of debug interface / logging for anything threading/scheduler related?

                       

                      thx,

                      Andreas

                        • Re: pthreads and Quality of Service Classes
                          eskimo Apple Staff Apple Staff (13,425 points)

                          QOS_CLASS_USER_INTERACTIVE is correct here because the calculation is needed to update OpenGL rendering @30 or 60 fps.

                          OK then.

                          Is there some kind of debug interface / logging for anything threading/scheduler related?

                          Take a look at the System Trace instrument.

                          Share and Enjoy

                          Quinn “The Eskimo!”
                          Apple Developer Relations, Developer Technical Support, Core OS/Hardware
                          let myEmail = "eskimo" + "1" + "@apple.com"

                          WWDC runs Mon, 13 Jun through to Fri, 17 Jun.  During that time all of DTS will be at the conference, helping folks out face-to-face. http://developer.apple.com/wwdc/

                          • Re: pthreads and Quality of Service Classes
                            avitzur Level 1 Level 1 (0 points)

                            I'm encountering the same behavior here in my app in similar circumstance, having tried QOS_CLASS DEFAULT, USER_INITIATED, and USER_INTERACTIVE. Have you found a satisfying resolution to your problem?