[Leaplist] Re: need some jiffies
Doug Jones
eaglebeakster at gmail.com
Tue Oct 9 19:06:52 EDT 2007
Thanks for replies
>
> Message: 6
> Date: Mon, 8 Oct 2007 22:56:43 -0400
> From: John Simpson <jms1 at jms1.net>
> Subject: Re: [Leaplist] need some jiffies
> To: This is the Leap Main List <leaplist at leap-cf.org>
> Message-ID: <1D0879AE-08FE-4B7B-B06B-F69ADE4B73E2 at jms1.net>
> Content-Type: text/plain; charset="us-ascii"
>
> On 2007-10-08, at 1813, Doug Jones wrote:
> >
> > ... I need to do a little medium resolution
> > timing. My current learning experience is to try to get the linux
> > heartbeat
> > system tic known as 'jiffies' rather than system time since jan 1,
> > 1970.
> > The jiffies would put me back in paradigm I'm used to in embedded
> > stuff.
> >
> > So my question, anyone got a good C example of how to get jiffies
> > from user
> > space?
>
> the easiest way is to read /proc/uptime. the first number is total
> seconds since the system came up, and the other is the total number
> of "idle" seconds since the system came up.
>
> and since a "jiffy" is 1/100th of a second, remove the period from
> the number and you have the count in jiffies rather than seconds.
>
> > I've found linux/jiffies.h but when i include i get a bazillion
> > compile errors. I just need a simple example that shows all the
> > include
> > files. Yes, I googled and ended up in kernel development too much
> > (head
> > exploded).
>
> i don't have that header on my system, probably because i don't have
> (or need) the kernel sources at all.
>
> what is it you're trying to do? could you do what you need using
> nanosleep() or setitimer() instead?
>
> > Hopefully I'll see some of y'all at the redhat thing tomorrow (9oct).
>
> i'm signed up to go, but that's reeeeeeally early for me... i don't
> honestly know if i'll be there or not.
>
> ----------------------------------------------------------------
> | John M. Simpson --- KG4ZOW --- Programmer At Large |
> | http://www.jms1.net/ <jms1 at jms1.net> |
> ----------------------------------------------------------------
> | http://video.google.com/videoplay?docid=-1656880303867390173 |
> ----------------------------------------------------------------
>
>
> ------------------------------
>
> Message: 8
> Date: Tue, 9 Oct 2007 10:52:34 -0400 (EDT)
> From: "Richard F. Ostrow Jr." <kshots at warfaresdl.com>
> Subject: Re: [Leaplist] need some jiffies
> To: "This is the Leap Main List" <leaplist at leap-cf.org>
> Message-ID:
> <12678.160.142.1.16.1191941554.squirrel at www.warfaresdl.com>
> Content-Type: text/plain;charset=iso-8859-1
>
> Hmm... the last time I'd heard of the word "jiffies" was back when I was
> coding on the C64 when I was 12 years old. I believe the definition back
> then was more linked to machine cycles than any measurement of time... so
> a jiffy on one machine will be different than a jiffy on another
> machine(hence a "jiffy" is not equal to x microseconds).
>
> Given that definition, would you really want to use jiffies? I'd think
> you'd want a more uniform measurement of time. Are you trying to measure
> how much time passed? Are you trying to wait a specific amount of time?
> What is it you're trying to do?
> --
> Life without passion is death in disguise
Right now I'm just chasing the jiffies as an exercise to understand
timing in linux a bit better. I'm trying to do it in a way that is
familiar to me since I usually work on embedded systems that do not
have a real time clock. Usually, it's something I've designed and
it's only got a system tick that I make from a hardware timer
interrupt. In such systems before i put a layer of RTOS, I usually
just have soft real time functions that keep track of the last time
they ran in the form of system ticks. These functions get called from
"the big loop", check how long it's been since they ran, if not time
just return. It's so simple a cave man can do it (that's the way I
usually think). So anyway, Just trying to get the jiffies as a way to
do exactly the same thing. I'm accomplishing that now with some
system time calls but it's nasty;
if (gettimeofday(&tv_lcl_now, NULL) == -1) {time_failed++; exit(0);}
diff_usec = tv_lcl_now.tv_usec - tv_last_serv.tv_usec + 1000000 *
(tv_lcl_now.tv_sec - tv_last_serv.tv_sec);
if (diff_usec > 200000){ TIMED_THANG }
That does good job of running TIMED_THANG at 200ms period. BUT,
there's a few linux capable boards I'm seeing that don't have RTCs on
board so I'm not sure how the distros shoehorned on those boards will
handle gettimeofday. Just getting the jiffies without a call to read
a file system (like the /proc/uptime) will get me the cave man
functionality that I want.
And yes Richard, jiffies are diff from machine to machine, kernel to
kernel but it _appears_ that the real duration is specified in that
/usr/include/jiffies.h
End game is to have threads that have nanosleeps but I haven't
convinced myself yet that thread plus nanosleep will make threads run
at independent periodicities. There's probably something mandated by
POSIX compliant that does all this for me but I'm not there yet. I do
have good thread examples that compile so that'll probably be the
solution soon.
Thanks
dj
More information about the Leaplist
mailing list