Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[ace-users] Repeated timer scheduling on Ubuntu Linux not reliable

4 views
Skip to first unread message

Alberto Salmerón Moreno

unread,
May 18, 2007, 1:24:06 PM5/18/07
to ace-...@cse.wustl.edu
Hi all,

I've been experiencing a strange behavior regarding repeated timers on
Ubuntu Linux. Although it should be fired every 2 ms, the average
dispatch time is around 12 ms. Different versions of Ubuntu Linux and
ACE yield different averages. Problem report follows.

Thanks in advance,
Alberto

ACE VERSION: 5.5.8

HOST MACHINE and OPERATING SYSTEM: Intel Pentium D, Ubuntu Linux Feisty Fawn
7.04 (kernel version: 2.6.20-15-generic)

TARGET MACHINE and OPERATING SYSTEM, if different from HOST:

COMPILER NAME AND VERSION (AND PATCHLEVEL): GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)

THE $ACE_ROOT/ace/config.h FILE: I used the configure script,
resulting config.h is 64Kb. I will post it if needed

THE $ACE_ROOT/include/makeinclude/platform_macros.GNU FILE:

CONTENTS OF $ACE_ROOT/bin/MakeProjectCreator/config/default.features:

AREA/CLASS/EXAMPLE AFFECTED:

DOES THE PROBLEM AFFECT: EXECUTION of application

SYNOPSIS:
The average dispatch time for a repeated timer scheduled on a reactor is
very different from the expected time.

DESCRIPTION:
An application under development has a timer which has to fire every 2 ms. The
average dispatch time is expected to be around 2 ms. However, using Ubuntu Linux
7.04 the average ends up beign 12 ms. Is the desired interval time is increased
from 2 ms towards 12 ms, the average also increases at a different rate, e.g. a
16 ms average instead of the inteded 8 ms.

Oddly enough, that real average time is different depending on the Ubuntu and
ACE version used. For instance, using Ubuntu 7.04 and ACE 5.4.7 from the Ubuntu
respositories yields an average of 4 ms; Ubuntu 6.10 and ACE 5.5.6 yields 16 ms.
On Ubuntu 6.10 and ACE 5.4.7-9 from the Ubuntu repositories (the environment on
which the development of the application started) the average was exactly as
intended: 2ms. A quick test on Windows XP and ACE 5.5.8 also gave a
good average around 2ms.

There are several variables here, but I guess the problem might lay in the OS.
Could the Ubuntu Linux kernel have been configured in a way that prevents ACE
from getting the clock times right? Or maybe it is the configuration
of ACE? Any idea will be greatly appreciated.

REPEAT BY:

Sample program follows. The first parameter, if any, is the interval time in
microseconds. The second, if any, is a file on which log messages will be
written:

/* test.cpp - start *********************/
#include "ace/High_Res_Timer.h"
#include "ace/Log_Msg.h"
#include "ace/OS.h"
#include "ace/Reactor.h"
#include "ace/streams.h"
#include "ace/Timer_Heap.h"
#include "ace/Timer_Queue.h"

class TimerHandler : public ACE_Event_Handler {
public:
int handle_timeout(const ACE_Time_Value &cur_time, const void * = 0) {
ACE_DEBUG((LM_DEBUG, "[Phy] %T\n"));
return 0;
}
};

int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) {
int time = argc > 1 ? ACE_OS::atoi(argv[1]) : 2000; // 2ms
if (argc > 2) {
ACE_OSTREAM_TYPE *output = new std::ofstream (argv[2]);
ACE_LOG_MSG->msg_ostream(output, 1);
ACE_LOG_MSG->set_flags(ACE_Log_Msg::OSTREAM);
ACE_LOG_MSG->clr_flags(ACE_Log_Msg::STDERR);
}

ACE_High_Res_Timer::global_scale_factor();
ACE_Reactor reactor;
reactor.timer_queue()->gettimeofday(&ACE_High_Res_Timer::gettimeofday_hr);
TimerHandler *handler = new TimerHandler();
ACE_Time_Value interval (0, time);
ACE_Time_Value initialDelay = ACE_Time_Value(0, 0);
reactor.schedule_timer(handler, 0, initialDelay, interval);
if (reactor.run_reactor_event_loop() == -1) {
ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "run_reactor_event_loop()"), 1);
}
return 0;
}
/* test.cpp - end ***********************/

SAMPLE FIX/WORKAROUND:

--
Alberto Salmerón Moreno
Departamento de Lenguajes y Ciencias de la Computación
Universidad de Málaga, ETSI Informática
salm...@lcc.uma.es

Douglas C. Schmidt

unread,
May 18, 2007, 1:32:11 PM5/18/07
to Alberto Salmerón Moreno, ace-...@cse.wustl.edu

Hi Alberto,

Thanks for using the PRF!

> ACE VERSION: 5.5.8
>
> HOST MACHINE and OPERATING SYSTEM: Intel Pentium D, Ubuntu Linux Feisty Fawn
> 7.04 (kernel version: 2.6.20-15-generic)
>
> TARGET MACHINE and OPERATING SYSTEM, if different from HOST:
>
> COMPILER NAME AND VERSION (AND PATCHLEVEL): GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)
>
> THE $ACE_ROOT/ace/config.h FILE: I used the configure script,
> resulting config.h is 64Kb. I will post it if needed
>
> THE $ACE_ROOT/include/makeinclude/platform_macros.GNU FILE:
>
> CONTENTS OF $ACE_ROOT/bin/MakeProjectCreator/config/default.features:
>
> AREA/CLASS/EXAMPLE AFFECTED:
>
> DOES THE PROBLEM AFFECT: EXECUTION of application
>
> SYNOPSIS:
> The average dispatch time for a repeated timer scheduled on a reactor is
> very different from the expected time.

Have you tried running your test application in the "real-time schedule
class" on Linux? That should make it more predictable. Check out

http://lldn.timesys.com/docs/real_time

for some info on how this all works.

Thanks,

Doug

> _______________________________________________
> ace-users mailing list
> ace-...@mail.cse.wustl.edu
> http://mail.cse.wustl.edu/mailman/listinfo/ace-users

Matthew Gillen

unread,
May 18, 2007, 1:33:53 PM5/18/07
to Alberto Salmerón Moreno, ace-...@cse.wustl.edu
Hi Alberto,

Alberto Salmerón Moreno wrote:
> Hi all,
>
> I've been experiencing a strange behavior regarding repeated timers on
> Ubuntu Linux. Although it should be fired every 2 ms, the average
> dispatch time is around 12 ms. Different versions of Ubuntu Linux and
> ACE yield different averages. Problem report follows.


This has come up before on this list. Check these links:
http://groups.google.com/group/comp.soft-sys.ace/browse_thread/thread/1142d827c781c2cf/b17e175064fac101?lnk=st&q=ace-users+gillen+timer&rnum=6#b17e175064fac101
http://groups.google.com/group/comp.soft-sys.ace/browse_thread/thread/9a54a10c7a1a6f59/c59e402e388ecc35?lnk=st&q=ace-users+gillen&rnum=4#c59e402e388ecc35

Basically, you're not going to get predictable timers every 2ms with a stock
linux kernel, and there's nothing ACE can do to improve that situation.

You need to use a hard-real-time OS. There are versions of linux that /can/
do timers at that granularity, but they may or may not use POSIX interfaces
for them (and that affects where ACE would use them out-of-the-box)

HTH,
Matt

0 new messages