Jump to content

Deque Element polling rate?


Recommended Posts

So lately I have been more interested in scheduling. Two methods I am aware of are below.

This is in the context of Windows OS btw.

  • Active Waiting (polling) 
    • Know for High CPU usage
    • Accurate to less than 1ms
  • Yielding OS wait (Thread telling OS give someone else my time slice)
    • Very low CPU usage
    • Takes OS integration (e.g. less portable)
    • Much less time accurate jitter etc.
    • expect best performance to be 1ms resolution

So I have been curious about the timeout function of the deque element for a while. To me waiting on this seems to take little to no CPU usage. but has much better than 1ms resolution. 30us +- 10us in the example below.

How can I replicate this kind of performance? Is there a secret method I am not aware of (reality says yes)?

image.png.87e80d0d2b8a6296021f783856bd646d.png

image.png.aa236ed9458cdbba429e9b96e7036c16.png

Link to comment

In a setup like this I might not even have a timeout or rather have a -1 timeout.  This allows the dequeue function to just sit idle waiting for a request to take an action.  That action might be to quit or something else.  Another common thing you might see in examples is to use the error out of the dequeue and have it stop the loop.  If the queue reference is destroyed while waiting, it will return an error and that can be a way to tell the loop to shutdown.  A better method is to use a quit message of some kind but it is seen in several NI examples.

Link to comment

In the example above I'm more interested in how NI implemented the waiting on the queue. It seems to have better performance than I would imagine possible. I probably made some bad assumptions on the example. 

Assumption 1: Two while loops run on different threads.

Assumption 2: If threads yield to OS response of queue would be > 1ms on average.

Assumption 3: If threads actively wait CPU usage would be high.

Assumption 4: Neither of these methods make sense with the information collected.

Link to comment

In cases like these I assume (possibly incorrectly) that NI's compiler can handle these lower level operations better than me.  They have more intimate knowledge about what is happening, and can make performance improvements to handle the delay and notification of data to dequeue better than me.  Then again I know more about what my application needs than NI, and maybe I could write more specific software for a queue, and NI needs a more general purpose solution.  I don't really have any more information on how NI implemented or handles queues and polling.  I'm just glad that over the years it seems to be pretty robust, and works well on the various platforms supported.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.