LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Timer Callback Question

Hi,

My OS is Windows 2000 Pro and I''m using CVI 6.0. I've noticed that an
application I'm developing uses ~97% CPU time if I have an active Timer
Callback. If I disable the timer then CPU usage drops to 0%. The timer is
set to .025 ms.

In order to test if it was the timer callback itself or the code executed
within, I tried using a shell that simply did a return 0 from the callback.
I also inserted my code and tried the same experiment. In both cases the
result was the same: the Timer Callback, for some reason, is consuming a lot
of CPU usage.

Any tips on how to reduce this overhead are appreciated.

Thanks,
George Hodgson
0 Kudos
Message 1 of 4
(2,848 Views)
Hi George,

First, I'm assuming you mean .025 seconds rather than ms. If you are really trying to use .025 ms then that definitely explains your problem (getting better than about 1 ms of resolution for events on almost any windows box is highly unlikely). Assuming that you are using .025 seconds, then it's just a function of your computer's hardware setup. Doing the same program on my computer with the callback set to .025 seconds only uses about 40% of the processor. If all you want is to reduce your processor usage (generally not neccessary, ideally you should be using as much of your processor as possible at any given time, Windows is a preemptive OS, and will take the processor away if other things need it. However if you are running a parallel application wh
ich you need to maximize performance on then it might be good to reduce CVI's processor usage) you can change CVI's sleep policy to "Sleep More" using SetSleepPolicy (this can also be set under Options->Environment in CVI 7.0, but I'm not sure if or where the option is in 6.0). This will reduce the performance of your CVI code, but should cause it to use the processor less.

Hope that helps,
Ryan K.
0 Kudos
Message 2 of 4
(2,848 Views)
Ryan,

Thanks for your response. Yes, I mean .025 seconds and not milliseconds. My
mistake.
I've tried the SetSleepPolicy at all three setting (none, some and more) and
this
didn't seem to have much of an affect but changing the timer to .050 seconds
did reduce
CPU usage to under 40%. I may have to live with that and adjust the events I
process
within the Timer Callback accordingly.

The reason I wanted to reduce CPU usage is that I run a separate process
that acts as
a server for multiple clients and I allow one client to reside on the same
computer. I've
experienced slowdowns receiving TCP/IP messages on the client side (the one
resident
on the server computer) and was looking for ways to reduce overhead.

Once again, thanks. Your comments are appreciated.

George Hodgson

"ryank" wrote in message
news:506500000005000000BB9C0100-1079395200000@exchange.ni.com...
> Hi George,
>
> First, I'm assuming you mean .025 seconds rather than ms. If you are
> really trying to use .025 ms then that definitely explains your
> problem (getting better than about 1 ms of resolution for events on
> almost any windows box is highly unlikely). Assuming that you are
> using .025 seconds, then it's just a function of your computer's
> hardware setup. Doing the same program on my computer with the
> callback set to .025 seconds only uses about 40% of the processor. If
> all you want is to reduce your processor usage (generally not
> neccessary, ideally you should be using as much of your processor as
> possible at any given time, Windows is a preemptive OS, and will take
> the processor away if other things need it. However if you are
> running a parallel application which you need to maximize performance
> on then it might be good to reduce CVI's processor usage) you can
> change CVI's sleep policy to "Sleep More" using SetSleepPolicy (this
> can also be set under Options->Environment in CVI 7.0, but I'm not
> sure if or where the option is in 6.0). This will reduce the
> performance of your CVI code, but should cause it to use the processor
> less.
>
> Hope that helps,
> Ryan K.
0 Kudos
Message 3 of 4
(2,848 Views)
Additionally, the asynchronous timers available as a separate fp in Measurement Studio are a lot
more efficient (and reliable).
And ultimately you can use native windows timers (I did that a couple years ago when I needed
better than ms precision).
--
Guillaume Dargaud
http://www.gdargaud.net/
"It is a far, far better thing to have a firm anchor in nonsense than to put out on the troubled
seas of thought." ? John K. Galbraith.
0 Kudos
Message 4 of 4
(2,848 Views)