LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-18-2006, 08:50 AM   #1
nathan2225
LQ Newbie
 
Registered: Jun 2006
Posts: 27

Rep: Reputation: 0
clock_gettime(CLOCK_MONOTONIC,..) fails


Hi i want to use a high resolution clock to support my realtime app.
I was using gettimeofday() b4, but now i want to sync time at some machines and now this timebase is no longer a stable one.

So i tried to use not CLOCK_REALTIME and found CLOCK_MONOTONIC.

Had to link librt to my app, compiles fine but :

If i call clock_gettime with clockid CLOCK_MONOTONIC on my target machine, i got a retval of -1, meaning this is not supported by the system.
Running my app with the same kernel on my developing machine, this works quite fine but on the target system (a cyrix C3-2) it just returns -1 !!

Can somebody explain me, why on my cyrix machine it does not work and on a plain P4 desktop it does (with the same (self-compiled) kernel)? Can it be a problem with glibc or really with the hardware ?

I also found out, that on the cyrix, the clock_getres for REALTIME gaves me about 10ms and on the P4 it says about 1ms .....

Does someone know other methods to get a monothonic clock with at least 1ms res ?

Btw, i'm using kernel 2.6.16-16

Greetings
Robert

Last edited by nathan2225; 07-18-2006 at 10:26 AM.
 
Old 07-18-2006, 10:43 AM   #2
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
Moved: This thread is more suitable in programming and has been moved accordingly to help your thread/question get the exposure it deserves.
 
Old 07-18-2006, 10:44 AM   #3
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
Check if the symbol _POSIX_MONOTONIC_CLOCK is defined. If not, your glibc is insufficiently new. Also, what does errno show? EINVAL?
 
Old 07-18-2006, 03:23 PM   #4
nathan2225
LQ Newbie
 
Registered: Jun 2006
Posts: 27

Original Poster
Rep: Reputation: 0
Good idea, i'll check tomorrow.

How can i test if these options are defined in the glibc
(At runtime, by cmdline check) ?
 
Old 07-18-2006, 03:31 PM   #5
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
Try something like:
Code:
#ifndef _POSIX_MONOTONIC_CLOCK
#error No monotonic clock available!
#endif
 
Old 07-19-2006, 02:06 AM   #6
nathan2225
LQ Newbie
 
Registered: Jun 2006
Posts: 27

Original Poster
Rep: Reputation: 0
Hmm, the include files (bits/posix_opt.h) say :

#define _POSIX_MONOTONIC_CLOCK 0

which has to say : monotonic clock might be available, has to be checked at runtime !

OK, so i tried the sysconf call sysconf(_SC_MONOTONIC_CLOCK) :

And surprise, surprise, running my app on target system (VIA/Cyrix C3-2 CPU) with glibc-2.3.6, it says : -1 (not available)

running app on my workstation delivers : 1 !!!

So whom can i blame for this ? The glibc, the kernel, the hardware ????

----


And because u asked: the retval of clock_gettime is : Invalid argument (errno 22)

Last edited by nathan2225; 07-19-2006 at 03:07 AM.
 
Old 07-21-2006, 04:52 AM   #7
nathan2225
LQ Newbie
 
Registered: Jun 2006
Posts: 27

Original Poster
Rep: Reputation: 0
Success !

OK, i've found out : It was the glibc

Somehow all the slackware packages (i'm using slackware tgz packages) were compiled with emulated timers, not using the timers offered by the OS.
I tried a debian compiled glibc package and it suddenly worked, hurray !!

Thanks to Matir for the hints !

Greetings
Robert
 
Old 07-21-2006, 09:35 AM   #8
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
No problem. I learned quite a bit from this thread myself. I'm glad we were able to help you out.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
clock_gettime() issue AndreiCiprian Programming 0 03-28-2006 06:04 PM
POSIX.4 clock_gettime function collinss Programming 2 09-13-2005 06:55 AM
DHCP fails, IP fails, packet framing errors? alonsomosely Fedora 2 09-17-2004 11:22 AM
Encrypted Reiserfs Fails to Mount -- Reiserfsck Fails as Well antic Linux - Hardware 0 07-30-2004 04:32 PM
POSIX.4 clock_gettime function collinss Linux - General 1 11-24-2003 12:12 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration