Unexpected timer_gettime error

bridged with qdn.public.qnxrtp.x86
Post Reply
M. Hagerman

Unexpected timer_gettime error

Post by M. Hagerman » Sun Jun 08, 2003 2:14 pm

I am running QNX 6.1 on a x86 system.

I am running five identical threads each with it's own timer. The first call
to timer_gettime(...) almost always returns with error 22. (Invalid
argument). Any subsequent call to timer_gettime on the timer works and
returns good data. The timerID is the same for both calls within the same
thread.

David Gibbs

Re: Unexpected timer_gettime error

Post by David Gibbs » Tue Jun 10, 2003 11:03 pm

M. Hagerman <hagerman@battelle.org> wrote:
I am running QNX 6.1 on a x86 system.

I am running five identical threads each with it's own timer. The first call
to timer_gettime(...) almost always returns with error 22. (Invalid
argument). Any subsequent call to timer_gettime on the timer works and
returns good data. The timerID is the same for both calls within the same
thread.
Are you calling timer_gettime() before calling timer_settime()?

-David
--
QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.

M. Hagerman

Re: Unexpected timer_gettime error

Post by M. Hagerman » Tue Jun 17, 2003 7:47 pm

No, I am calling timer_settime first in all cases. In fact if timer_gettime
fails I call it again immediately and the expected time is returned.


"David Gibbs" <dagibbs@qnx.com> wrote in message
news:bc5o3q$c66$3@nntp.qnx.com...
M. Hagerman <hagerman@battelle.org> wrote:
I am running QNX 6.1 on a x86 system.

I am running five identical threads each with it's own timer. The first
call
to timer_gettime(...) almost always returns with error 22. (Invalid
argument). Any subsequent call to timer_gettime on the timer works and
returns good data. The timerID is the same for both calls within the
same
thread.

Are you calling timer_gettime() before calling timer_settime()?

-David
--
QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.

M. Hagerman

Re: Unexpected timer_gettime error

Post by M. Hagerman » Wed Jul 23, 2003 12:01 pm

After extended system testing we have experienced the timer_gettime function
failing at different times and locations in our code. Online documents do
not give any information on the possible cause of this functions failure.


"David Gibbs" <dagibbs@qnx.com> wrote in message
news:bc5o3q$c66$3@nntp.qnx.com...
M. Hagerman <hagerman@battelle.org> wrote:
I am running QNX 6.1 on a x86 system.

I am running five identical threads each with it's own timer. The first
call
to timer_gettime(...) almost always returns with error 22. (Invalid
argument). Any subsequent call to timer_gettime on the timer works and
returns good data. The timerID is the same for both calls within the
same
thread.

Are you calling timer_gettime() before calling timer_settime()?

-David
--
QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.

Adam Mallory

Re: Unexpected timer_gettime error

Post by Adam Mallory » Wed Jul 23, 2003 2:07 pm

M. Hagerman <hagerman@battelle.org> wrote in message
news:bflsts$3c7$1@inn.qnx.com...
After extended system testing we have experienced the timer_gettime
function
failing at different times and locations in our code. Online documents do
not give any information on the possible cause of this functions failure.
Sounds like you have some race condition somewhere.

EINVAL is returned only if the timer doesn't exist (or is invalid).

-Adam

M. Hagerman

Re: Unexpected timer_gettime error

Post by M. Hagerman » Wed Jul 23, 2003 4:09 pm

But, if I immediatley call get_time again after the error the function
returns the correct value. If the timer did'nt exist or was invalid,
wouldn't the next call fail as well.


"Adam Mallory" <amallory@qnx.com> wrote in message
news:bfm4sk$g83$1@nntp.qnx.com...
M. Hagerman <hagerman@battelle.org> wrote in message
news:bflsts$3c7$1@inn.qnx.com...
After extended system testing we have experienced the timer_gettime
function
failing at different times and locations in our code. Online documents
do
not give any information on the possible cause of this functions
failure.

Sounds like you have some race condition somewhere.

EINVAL is returned only if the timer doesn't exist (or is invalid).

-Adam

Adam Mallory

Re: Unexpected timer_gettime error

Post by Adam Mallory » Wed Jul 23, 2003 5:01 pm

M. Hagerman <hagerman@battelle.org> wrote in message
news:bfmbeh$drt$1@inn.qnx.com...
But, if I immediatley call get_time again after the error the function
returns the correct value. If the timer did'nt exist or was invalid,
wouldn't the next call fail as well.
I'm not familar with your code, but if another thread happened to make a
timer, the ID might be reused.

If it's this basic, post a test case illustrating the problem so we can take
a look.

-Adam

M. Hagerman

Re: Unexpected timer_gettime error

Post by M. Hagerman » Thu Jul 24, 2003 2:13 pm

The code uses multiple threads with timers. We do not share timers between
threads. The code does not always fail when timer_gettime is called, but
when it does the next timer_gettime call works. The return values for sec
and nsec are zero and the return code is 22, Invalid Argument.

long sec, nsec, time;
struct itimerspec m_itime, m_value;
struct sigevent m_event;

SIGEV_NONE_INIT(&m_event);
timer_create(CLOCK_REALTIME, &m_event, &m_timer_id);

m_itime.it_value.tv_sec = 10;
m_itime.it_value.tv_nsec = 0;

m_itime.it_interval.tv_sec = 0;
m_itime.it_interval.tv_nsec = 0;

timer_settime(m_timer_id, 0, &m_itime, NULL);

// Some code for about 5 seconds

if (timer_gettime(m_timer_id, &m_value) != 0)
{
trace(TRDEV, TRACE_ERROR,"timer_gettime failed %s", strerror(errno));
if (timer_gettime(m_timer_id, &m_value) != 0)
{
trace(TRDEV, TRACE_ERROR,"timer_gettime failed again %s",
strerror(errno));
}
}
sec = m_value.it_value.tv_sec;
nsec = m_value.it_value.tv_nsec;

time = (long)((sec*1000.0) + (nsec/1000000.0)); // converts secs/nsecs to
msecs

return time;



"Adam Mallory" <amallory@qnx.com> wrote in message
news:bfmf3e$s5j$1@nntp.qnx.com...
M. Hagerman <hagerman@battelle.org> wrote in message
news:bfmbeh$drt$1@inn.qnx.com...
But, if I immediatley call get_time again after the error the function
returns the correct value. If the timer did'nt exist or was invalid,
wouldn't the next call fail as well.

I'm not familar with your code, but if another thread happened to make a
timer, the ID might be reused.

If it's this basic, post a test case illustrating the problem so we can
take
a look.

-Adam

Adam Mallory

Re: Unexpected timer_gettime error

Post by Adam Mallory » Thu Jul 24, 2003 3:10 pm

Looking through the old CVS logs there was some fixes make to the timer
code, that looks somewhat similar to your symptoms.

Try updating to Patch B for 6.1 and see if that helps.

-Adam

M. Hagerman <hagerman@battelle.org> wrote in message
news:bfoovo$9ii$1@inn.qnx.com...
The code uses multiple threads with timers. We do not share timers between
threads. The code does not always fail when timer_gettime is called, but
when it does the next timer_gettime call works. The return values for sec
and nsec are zero and the return code is 22, Invalid Argument.

long sec, nsec, time;
struct itimerspec m_itime, m_value;
struct sigevent m_event;

SIGEV_NONE_INIT(&m_event);
timer_create(CLOCK_REALTIME, &m_event, &m_timer_id);

m_itime.it_value.tv_sec = 10;
m_itime.it_value.tv_nsec = 0;

m_itime.it_interval.tv_sec = 0;
m_itime.it_interval.tv_nsec = 0;

timer_settime(m_timer_id, 0, &m_itime, NULL);

// Some code for about 5 seconds

if (timer_gettime(m_timer_id, &m_value) != 0)
{
trace(TRDEV, TRACE_ERROR,"timer_gettime failed %s", strerror(errno));
if (timer_gettime(m_timer_id, &m_value) != 0)
{
trace(TRDEV, TRACE_ERROR,"timer_gettime failed again %s",
strerror(errno));
}
}
sec = m_value.it_value.tv_sec;
nsec = m_value.it_value.tv_nsec;

time = (long)((sec*1000.0) + (nsec/1000000.0)); // converts secs/nsecs
to
msecs

return time;



"Adam Mallory" <amallory@qnx.com> wrote in message
news:bfmf3e$s5j$1@nntp.qnx.com...
M. Hagerman <hagerman@battelle.org> wrote in message
news:bfmbeh$drt$1@inn.qnx.com...
But, if I immediatley call get_time again after the error the function
returns the correct value. If the timer did'nt exist or was invalid,
wouldn't the next call fail as well.

I'm not familar with your code, but if another thread happened to make a
timer, the ID might be reused.

If it's this basic, post a test case illustrating the problem so we can
take
a look.

-Adam



John A. Murphy

Re: Unexpected timer_gettime error

Post by John A. Murphy » Thu Jul 24, 2003 3:36 pm

Speaking of "old CVS logs", when is http://cvs.qnx.com/ going to get
updated? It's getting very out of date, not to mention that a search
done there returns mostly broken links.

Murf

Adam Mallory wrote:
Looking through the old CVS logs there was some fixes make to the timer
code, that looks somewhat similar to your symptoms.

Try updating to Patch B for 6.1 and see if that helps.

-Adam

M. Hagerman <hagerman@battelle.org> wrote in message
news:bfoovo$9ii$1@inn.qnx.com...
The code uses multiple threads with timers. We do not share timers between
threads. The code does not always fail when timer_gettime is called, but
when it does the next timer_gettime call works. The return values for sec
and nsec are zero and the return code is 22, Invalid Argument.

long sec, nsec, time;
struct itimerspec m_itime, m_value;
struct sigevent m_event;

SIGEV_NONE_INIT(&m_event);
timer_create(CLOCK_REALTIME, &m_event, &m_timer_id);

m_itime.it_value.tv_sec = 10;
m_itime.it_value.tv_nsec = 0;

m_itime.it_interval.tv_sec = 0;
m_itime.it_interval.tv_nsec = 0;

timer_settime(m_timer_id, 0, &m_itime, NULL);

// Some code for about 5 seconds

if (timer_gettime(m_timer_id, &m_value) != 0)
{
trace(TRDEV, TRACE_ERROR,"timer_gettime failed %s", strerror(errno));
if (timer_gettime(m_timer_id, &m_value) != 0)
{
trace(TRDEV, TRACE_ERROR,"timer_gettime failed again %s",
strerror(errno));
}
}
sec = m_value.it_value.tv_sec;
nsec = m_value.it_value.tv_nsec;

time = (long)((sec*1000.0) + (nsec/1000000.0)); // converts secs/nsecs
to
msecs

return time;



"Adam Mallory" <amallory@qnx.com> wrote in message
news:bfmf3e$s5j$1@nntp.qnx.com...
M. Hagerman <hagerman@battelle.org> wrote in message
news:bfmbeh$drt$1@inn.qnx.com...
But, if I immediatley call get_time again after the error the function
returns the correct value. If the timer did'nt exist or was invalid,
wouldn't the next call fail as well.

I'm not familar with your code, but if another thread happened to make a
timer, the ID might be reused.

If it's this basic, post a test case illustrating the problem so we can
take
a look.

-Adam



Post Reply

Return to “qdn.public.qnxrtp.x86”