Time

This is a discussion on Time within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by matsp Because it sits on a PCI device (southbridge), it takes quite a few cycles to "get ...

  1. #16
    Registered User
    Join Date
    Nov 2006
    Posts
    519
    Quote Originally Posted by matsp View Post
    Because it sits on a PCI device (southbridge), it takes quite a few cycles to "get there", so it's not a good idea to read it frequently, thus the OS won't do that.
    Are you shure Mats? The Linux kernel has HPET_TIMER for ... over a year? ... now. And it's explained with:

    This enables the use of the HPET for the kernel's internal timer. [...]
    Also I think wrapping is not a problem. HPET can be used as callback timer, so it calls functions (also userspace ones) at defined intervals
    Last edited by pheres; 02-12-2008 at 04:01 AM.

  2. #17
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by pheres View Post
    Are you shure Mats? The Linux kernel has HPET_TIMER for ... over a year? ... now. And it's explained with:



    Also I think wrapping is not a problem. HPET can be used as callback timer, so it calls functions (also userspace ones) at defined intervals
    Yes, that's EXACTLY what it is for - to get code in the user-mode application to run in a timely manner, and as long as you don't expect it to be VERY precise[1], it will work just fine.

    My point was about using the HPET for precise timing excercises, such as measuring the time of a function, which is what the original post asked for. Reading a HPET timer from a PCI bus is not something you want to do several times in a microsecond - each access will take several PCI cycles, which are 30ns each - perhaps as much as 200 ns - we are now talking 20% of a microsecond.


    [1] Linux is not a RTOS, so interrupt latency and kernel to user-mode latency is not in the "single digit or fractions of microseconds region", which a dedicated RTOS on a 100MHz processor should be quite capable of as a worst case, and better on average numbers.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to get current time
    By tsubasa in forum C Programming
    Replies: 3
    Last Post: 05-01-2009, 02:03 AM
  2. Replies: 11
    Last Post: 03-29-2009, 12:27 PM
  3. Help with assignment!
    By RVDFan85 in forum C++ Programming
    Replies: 12
    Last Post: 12-02-2006, 11:46 PM
  4. calculating user time and time elapsed
    By Neildadon in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2003, 05:00 PM
  5. time class
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-11-2001, 09:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21