Re: function for clockticks since 1980?



On 2007-07-29 01:16, nsa.usa@xxxxxxxxx <nsa.usa@xxxxxxxxx> wrote:
On Jul 29, 2:58 am, Ben Bacarisse <ben.use...@xxxxxxxxx> wrote:

#include <time.h>
time_t time(time_t *timer);

The time function determines the current calendar time. The
encoding of the value is unspecified.

so you can't rely on much variability there (it *may* be fine, but the
solution would not be portable).

Yeah, this one seems to be down to the second only, and so when the
app is run 100 times (or even just 2 times) within the same second,
then I got a prob =:-)

Since there is not ideal portable solution, your best bet may well be
to accept that go fully platform dependent. A small 'get_random_seed'
function will be a couple of lines long and can be written easily for
(reasonable) platform on which a web application might run. Post in a
newsgroup for your which every platform you are currently using for
ideas about getting a good random seed.

I might try the /dev/random for linux platform as was suggested by Xu
earlier.

/dev/random is guarantueed to return random numbers - if there is not
enough entropy in the pool it will block until more entropy is
collected. On a busy web server you will probably rapidly running out of
entropy, and you probably don't need that level of randomness, so you
should use /dev/urandom instead.

Just worried about the overhead on that one though. App is
only planned to run on linux on i32 or platform, so I only need it to
work on this (for now..).

Linux and other POSIX-compatible systems have the gettimeofday function,
which returns the time in seconds and microseconds since the epoch. Be
warned that the actual resolution of the clock can be much coarser:
Linux/x86 actually uses a microsecond clock, but some other Unixes have
resolutions of something between 1/60 to 1/1024 of a second.

Im pretty sure there is an interrupt to give this amount of
milliseconds since 1980 on that cpu, but then again I'd hate to stick
in cpu specific stuff..

These things are rarely CPU-specific. They are, however, OS-specific and
in some cases system specific. (BTW, the epoch on POSIX systems is 1970,
not 1980)

Somehow I thought this function would be standard in C (I'm not so
used to C)... oh well :-)

The C standard specifies a baseline which all implementations must
conform to. It is therefore very conservative and doesn't mandate
functions which might be impossible to implement on some systems (e.g.,
not every system has a clock with millisecond resolution). You will
notice that the standard doesn't make any guarantuees about the
resolution of time_t: It may have a resolution of nanoseconds, or only
of minutes.

hp


--
_ | Peter J. Holzer | I know I'd be respectful of a pirate
|_|_) | Sysadmin WSR | with an emu on his shoulder.
| | | hjp@xxxxxx |
__/ | http://www.hjp.at/ | -- Sam in "Freefall"
.



Relevant Pages

  • Re: wait for x seconds
    ... The resolution of the clock ... is platform specific. ... Fractional pauses of 0.01 seconds ...
    (comp.soft-sys.matlab)
  • Re: [patch 00/21] hrtimer - High-resolution timer subsystem
    ... Right now the primary function of the state is to tell whether the timer ... > Of course if you consider the possibility of including high resolution ... problem requires solving problems in the clock abstraction first, ...
    (Linux-Kernel)
  • Re: [PATCH] ktimers subsystem 2.6.14-rc2-kt5
    ... > a clock with a better resolution. ... > resolution than the physical clock has. ... reaches this count the timer is expired. ... OTOH We could also do this at the timer interrupt: ...
    (Linux-Kernel)
  • Re: Need to implement a calendar clock with millisecond resolution, please help.
    ... true, as I am a newbie, not even a real programmer), but I need to ... implement a calendar time clock with a millisecond resolution. ... system include clock, delay(), gettimeofday, msleep, ...
    (comp.lang.c)
  • Re: Signal timing problem
    ... We are using a MicroBlaze core with some user IP modules and some Xilinx modules attached through the OPB bus. ... All was working fine unitl we placed an extension board on our platform. ... This effectively makes the external path from the "part" to the FPGA much longer. ... active clock edge that will register it. ...
    (comp.arch.fpga)