How to compose PCs for semi-real time control.

  • Thread starter Yamashita Taiichiro none
  • Start date
V

Vladimir Bunyakin

> I have got delays of about maximum 2 seconds on my (quite
> unfriendly) test. The test lasted for about 10 minutes so
...
> Please note: I was definitively NOT fair to the OS in this test
> and the about 2 second delay occured one or two times. My test
> program took as much processor time as it could and measured ...

Tests differ... :)
We are probably talking about different 'delays'.
My test runs idle thread with such (not exactly) loop
while(1)
{
QueryPerformanceCounter(Time1);
Sleep(10);
QueryPerformanceCounter(Time2);
}
and a histogram of delays is built while test is running. Value [(Time2-Time1)-10 ms] is referred as 'delay'. The idea is to evaluate how the OS and the applications run at _normal_ priority affect the "control program" (consisting of 'Sleep' function in this case). I.e. the program asks the OS to perform certain activity (call
'QueryPerformanceCounter' function) at certain time (Time1 + 10 ms), and it is OS's responsibility to fulfil program's request. Programmer's responsibility is to write proper codes besides 'Sleep' :)
Of course applications run during the testing provided CPU usage about 100%, memory usage above physical memory and extensive disk activity.

--
Vladimir Bunyakin
 
Y

Yamashita Taiichiro

Hello, lists, this is Yamashita.

> Tests differ... :)
> We are probably talking about different 'delays'.
> My test runs idle thread with such (not exactly) loop
> while(1)
> {
> QueryPerformanceCounter(Time1);
> Sleep(10);
> QueryPerformanceCounter(Time2);
> }
> and a histogram of delays is built while test is running. Value
> [(Time2-Time1)-10 ms] is referred as 'delay'. The idea is to evaluate

Excuse me, I wanna ask you to explain this more in detail. I tried this code, but I don know what is this "Time1" and "Time2"'s unit. When I tried this, the return values was bigger than about 11800. The value of this objects, or Time1.QuadPart, is millisecond frame(reffer to
MSDN, this would be right), or microseconds ?
And if the time unit is millisecond frame, what in the world this code mean ?
Or how to fit the value of "Time1" and "Time2" to milliseconds frame ?

Best regards.
----
Yamashita
 
The point made by Mr. Acharya is well founded. At this food plant we have converted all of our "mature" horizontal flow wrappers (Hayssen RTs) to PLC control. We anticipated that fluctuating scan times would play havoc with cut off registration control and could impact the visual appeal of our products... this could not be allowed.

Given a machine speed of 150 units per minute at a cut off length of 8" means you are moving 1200" of packaging film per minute or 500 mm per second
or .5 mm per ms. So... if a registration action is delayed by say... 13ms, due to scan time delays, we have an additional 6.5 mm of wrap where it does not belong. This would in fact make our package length random in nature.

So we had five possible ways of addressing this issue.

1) Fix the scan time at an arbitrary speed. An suffer the corresponding lack of response time in other areas of the program.

2) Use a compiler directive that forces these functions into a type of time interrupt driven sub program. Better... but I/O update depends upon main scan.

3) Convince our Quality group that a random package length was attractive... ROFL.

4) Install a RT PLC to cover this one issue. Big Bucks...

5) Install an external discreet control to handle registration and then allow the PLC to spy on the control's operation.

Option 5 was selected and implemented. It has proven to be an excellent solution. If option 4 had been implemented and we were to still see changes in wrap length due to an occasional "over scan"... well there would have been an upset quality group yelling at our group who would have yelled at the RT PLC vendor.

To me... Real Time means a response to an event executes within the same time frame each and every event, anything less then this can not claim to be "Real Time".

Best Regards... Rick Kelly

Chief Technician
Natural Cuts
Cheese Operations
Kraft Canada
(613) 537-8069 V
(613) 537-8057 F
[email protected]
http://trondata.on.ca
 
L

Linas Kardasevicius

>> while(1)
>> {
>> QueryPerformanceCounter(Time1);
>> Sleep(10);
>> QueryPerformanceCounter(Time2);
>> }
>> and a histogram of delays is built while test is running. Value
>> [(Time2-Time1)-10 ms] is referred as 'delay'. The idea is to evaluate
>
>Excuse me, I wanna ask you to explain this more in detail.
>I tried this code, but I don know what is this "Time1" and "Time2"'s unit.
>When I tried this, the return values was bigger than about 11800.

Function QueryPerformanceCounter returns time in computer timer ticks,
which is aproximately 0.838 microseconds. You can use function
QueryPerformanceFrequency() to get the frequency of the timer,
but it will return 1193182 on any PC based platform.
Therefrore you should use (Time2-Time1)/1193 - 10 to get the
delay in the code above.

By the way, I wrote some C++ code to simplify time measurement
using QueryPerformanceCounter(),that can be downloaded
from http://www.bbdsoft.com/downloads/win32/profiler.zip
Using Profiler class code above could be writted as:

#include "profiler.hpp"

void someFunction ()
{
while (1)
{
Profiler aTest ("sleeptest.txt", 200);
Sleep (10);
}
}

The execution times of Sleep(10) statement would be written to
file sleeptest.txt every 200 iterations.

Linas Kardasevicius
UAB BBDSoft
http://www.bbdsoft.com/
 
V

Vladimir Bunyakin

Yamashita Taiichiro wrote:
...
> The value of this objects, or Time1.QuadPart, is millisecond frame(reffer to
> MSDN, this would be right), or microseconds ?

"lpPerformanceCount
Pointer to a variable that the function sets, in counts, to the current
^^^^^^^^^
performance-counter value..."

So, not milli- or microseconds, but "counts" corresponding to frequency returned by
QueryPerformanceFrequency function.

> And if the time unit is millisecond frame, what in the world this code mean
> ?
> Or how to fit the value of "Time1" and "Time2" to milliseconds frame ?

I can send you source codes, it is simple console program. Let me know by e-mail ([email protected]) if you are interested.

--
Vladimir Bunyakin
 
J

Johan Bengtsson

I don't agree.

The definitions as I have understood them:

Hard real time:
Response must be before the desired time.
It is ok to get response earlier, but not later for any reason.
This is not possible with plain Windows NT some extensions operating below the kernel might however fix this.

Soft real time:
Response should be before the desired time in most cases. This is definitely possible with a soft PLC in Win NT without any other than the normal windows kernel if the desired time is at least som 100ms, possibly even shorter.
it is not possible in plain NT if the desired time is less than some 16ms.

For hard real time you can definitely say
"yes" or "no", for soft real time you can say "ok" or "not ok" depending on your needs.

Even a hard real time system might have variable scan time, but it is NEVER allowed to be greater than the desired time.
A soft real time system have a goal to not have scan times greater than a certain value, but no absolute guarantee. It does however normally not exceed that time.


A PLC is normally not realtime by any of these definitions since you usually don't say what time you want, you normally just let it run.
Some PLC:s have a setting for the scan-time, but that are generally the minimun scan time, not the maximum. No actual guarantee!


/Johan Bengtsson

----------------------------------------
P&L, the Academy of Automation
Box 252, S-281 23 H{ssleholm SWEDEN
Tel: +46 451 49 460, Fax: +46 451 89 833
E-mail: [email protected]
Internet: http://www.pol.se/
----------------------------------------
 
J

Johan Bengtsson

There is one huge difference between your test and mine. Amount of processor used.
The Sleep instruction pauses the thread and passes execution to other threads and programs and you end up with a system using nearly 0% of the processor(s). My (unfair) test was at the other end of the scale using 100% of the processor.
In reality you will of course appear somewhere between those ends of the scale, but nevertheless testing with Sleep is too easy for the OS to give any interesting results. Ok my test (100% processor use) might not be really interesting either. I have other code making better tests but that one is longer...

In reality you will get variations in length, but not that much (at least if you run with a priority high enough)


/Johan Bengtsson

----------------------------------------
P&L, the Academy of Automation
Box 252, S-281 23 H{ssleholm SWEDEN
Tel: +46 451 49 460, Fax: +46 451 89 833
E-mail: [email protected]
Internet: http://www.pol.se/
----------------------------------------
 
E

E. Douglas Jensen

Unfortunately, practitioners almost always use terms like "hard" and "soft" real-time in vague and contradictory ways. Imagine if the concepts and terms that are fundamental to your company's business (chemical engineering, discrete
manufacturing, etc.) were just as ill-defined -- how would you ever build cost-effective systems?

It is possible to define and use real-time concepts and terms in a precise manner. An existence proof can be seen on my website http://www.real- time.org/presentations/dagstuhl/dagstuhl2.pdf
The precise concepts and terms there have made it possible to build successful and cost-effective real-time computing systems that would be impossible using the sloppy ideas that are commonly used.

Hard real-time as you used it is a reasonable definition (although what are you proposing to do about the cases where too soon is just as bad as too late?). However, that doesn't imply that NT can't be used for hard real-time. What matters is the variance (more precisely, the coefficient of variation) of NT's behavior timing with respect to
the "desired times" (say, deadlines). There are many systems with hard deadlines -- including those that if missed will cause loss of property
or human life -- that are measured in tens or hundreds of seconds. I can give you lots of examples from my DoD application domain. So if NT
has tens or hundreds or even thousands of mS of jitter in its response times, that may not be significantly detrimental to its meeting these
safety and life critical deadlines.

I have a lot more to say about the rest of your post but I will just let this be enough for now.

Doug

--
E. Douglas Jensen (at home)
[email protected], http://www.real-time.org
Home voice 508-653-5653, home fax 508-653-3342
Cell phone 781-929-6234 and [email protected]
Pager 888-916-9802 and http://www.skytel.com/paging (PIN 8889169802)
Office voice 781-271-2514, office Fax 781-271-4686
 
V

Vladimir Bunyakin

Johan Bengtsson P&L Automatik AB wrote:
>
> There is one huge difference between your test and mine.
> Amount of processor used.
notice: _by_this_thread_ (I called it 'idle')

> The Sleep instruction pauses the thread and passes execution
> to other threads and programs and you end up with a system
> using nearly 0% of the processor(s)

The system (OS+applications+(drivers+hardware) = all things being tested) can use as much processor(s) time as it needs. Old good 'Pinball' successfully eats ~100% of processor time, why not to use it as tool for loading of the processor?

...
> ... but nevertheless testing with Sleep is too
> easy for the OS to give any interesting results.

Easy? I am not sure. Load the system (or its parts - CPU, networks, storage, video - what are you interested in) heavily; run the thread
containing Sleep loop at priorities from 1 to 31; compare the results - they may be interesting. I found they even useful in several cases.

--
Sincerely,
Vladimir Bunyakin
 
J

Johan Bengtsson

Ok that is right, but I still think the thread you are interested in needs to do some work (That is what you will do eventually anyway isn't it?) and then of course sleep for some time (the time remaining until expected start of the next cycle, or somewhat less).

One reason for this is that you will find that the time spent from start to end of the work most often vary more than the sleep statement does. I normally passes a sleep-time that is adjusted to how long time it did take to do the work (or
actually, adjusted according to the miss in the previous sleep + time for work) The whole thing does of course depend much on priorities and other load. Especially it depends on other
processes and threads priority compared to the one you are interested in. If a lower priority thread is trying to use the entire processor it will not disturb a higher priority thread very much. But if this lower priority thread don't get enough of the processor during some time, because the higher priority threads use too much it will disturb them occasionally.

Whatever tests you and I do like this will will not cover it up anyway, let's drop it.


/Johan Bengtsson

----------------------------------------
P&L, the Academy of Automation
Box 252, S-281 23 H{ssleholm SWEDEN
Tel: +46 451 49 460, Fax: +46 451 89 833
E-mail: [email protected]
Internet: http://www.pol.se/
----------------------------------------
 
Top