Click here to Skip to main content
16,004,887 members
Home / Discussions / C#
   

C#

 
AnswerIt is probably hardware specific Pin
Ennis Ray Lynch, Jr.25-Aug-06 17:29
Ennis Ray Lynch, Jr.25-Aug-06 17:29 
GeneralRe: It is probably hardware specific Pin
likefood25-Aug-06 17:47
likefood25-Aug-06 17:47 
AnswerRe: question about Timer Tick event Pin
Robert Rohde25-Aug-06 21:30
Robert Rohde25-Aug-06 21:30 
GeneralRe: question about Timer Tick event Pin
likefood26-Aug-06 13:31
likefood26-Aug-06 13:31 
AnswerRe: question about Timer Tick event Pin
Mike Dimmick26-Aug-06 2:34
Mike Dimmick26-Aug-06 2:34 
GeneralRe: question about Timer Tick event Pin
likefood26-Aug-06 13:47
likefood26-Aug-06 13:47 
GeneralRe: question about Timer Tick event Pin
Mike Dimmick26-Aug-06 14:32
Mike Dimmick26-Aug-06 14:32 
GeneralRe: question about Timer Tick event [modified] Pin
Mike Dimmick27-Aug-06 11:00
Mike Dimmick27-Aug-06 11:00 
I'm replying here because, although I got the notification message, your other post didn't show up on the forum!

Heritos Gger wrote:
Don't get me wrong, I'm not arguing with you. You obviously know a lot more about it than me, I admit.

However, I still don't understand how you would say that the "system timer" has a resolution of 15 milliseconds and the "system clock time" has a resolution of 100ns. System.Windows.Forms.Timer has a resolution of one millisecond (better than 15). Are these three different timers we're talking about?(100ns,1ms,15ms resolution)

I was under the impression that there's one clock in the CPU, and everything gets chronological measurements from that (although, now that I've typed that, it sounds way too simple for CPU guts).

Thank you for your patience with me!


I need to point you to Raymond Chen's blog post, "Precision is not the same thing as accuracy"[^].

The system's clock measurements are based entirely around the Programmable Interval Timer component. This component, on x86/x64 computers, dates back to the original IBM PC, in which it was an Intel 8253 chip. In modern computers it's a circuit somewhere in one of the chipset chips (on my Intel 850-based P4 system it's hanging off the Low-Pin-Count controller, according to Device Manager where it appears as 'System timer' - this is the successor of the antique ISA bus, for devices that aren't expected to handle the complexities of PCI!)

(I've seen documentation on Wikipedia that this interval timer function is actually now performed by the Local APIC, which is a circuit of the processor which manages interrupts, so this may not be completely accurate, if your system also has an I/O APIC and Windows is using it, which most modern systems do. This would explain why the 'System timer' is shown as being in power state D3, which is the state with highest power savings and effectively means 'off'.)

Anyway, this timer component is programmed to interrupt the processor on a regular basis, by default every 15.625ms on my system. (You can find out the clock resolution using the ClockRes[^] utility.) Why the odd number? It's actually 1/64th of a second.

The SetTimer API (and hence System.Windows.Forms.Timer) accepts an interval specified in milliseconds, GetTickCount and GetSystemTime offer a multiple of milliseconds as their result, and GetSystemTimeAsFileTime (hence DateTime.Now.Ticks) offers multiples of 100ns. However, none of these APIs can offer this actual resolution. They're all tied to the programmable interval timer circuit's tick rate.

The system also has a real-time clock circuit introduced in the IBM AT, but that is useless for actual timekeeping since it requires a total of 6 I/O bus write/I/O bus read pairs to retrieve the actual time, and it only counts in 1 second intervals anyway. The operating system only reads from it at startup and writes to it when adjusting the clock (SetSystemTime or SetLocalTime, not every tick from the PIT circuit!) and on shutdown.

Why does the FILETIME structure (hence Ticks) have such an absurdly high resolution? I assume it's because NT was meant to be, and was, portable to other architectures which didn't have such lame timer capabilities. You'd need at least microsecond resolution with that default clock rate; if you only had millisecond resolution and added 15ms every tick, your clock would be 4% slow, losing nearly 2 1/2 minutes every hour. If the clock is varied down to approx 1ms (which would be implemented on the PIT as 1/1024 seconds, 976.5625us) you're starting to hit the actual resolution of the structure. 62.5ns will be lost every time the timer ticks in this case, but that's less than one part per million, far better than the hardware can actually do.

-- modified at 17:17 Sunday 27th August, 2006 (messed up closing format tag)

Stability. What an interesting concept. -- Chris Maunder

GeneralRe: question about Timer Tick event Pin
likefood27-Aug-06 12:50
likefood27-Aug-06 12:50 
QuestionDateTime format Pin
kani9825-Aug-06 11:55
kani9825-Aug-06 11:55 
AnswerRe: DateTime format Pin
Ravi Bhavnani25-Aug-06 12:18
professionalRavi Bhavnani25-Aug-06 12:18 
AnswerRe: DateTime format Pin
drdavef25-Aug-06 12:29
drdavef25-Aug-06 12:29 
AnswerRe: DateTime format Pin
AnshShar25-Aug-06 12:43
AnshShar25-Aug-06 12:43 
AnswerRe: DateTime format Pin
Scott Dorman1-Sep-06 13:29
professionalScott Dorman1-Sep-06 13:29 
Questioncan someone help plz: threading the PingReply Pin
Jassim Rahma25-Aug-06 8:30
Jassim Rahma25-Aug-06 8:30 
AnswerRe: can someone help plz: threading the PingReply Pin
Not Active25-Aug-06 8:43
mentorNot Active25-Aug-06 8:43 
QuestionC# ::: receive FAX Pin
Yetinger25-Aug-06 8:21
Yetinger25-Aug-06 8:21 
AnswerRe: C# ::: receive FAX Pin
Nader Elshehabi25-Aug-06 10:29
Nader Elshehabi25-Aug-06 10:29 
GeneralRe: C# ::: receive FAX Pin
Yetinger25-Aug-06 22:29
Yetinger25-Aug-06 22:29 
AnswerRe: C# ::: receive FAX Pin
Nader Elshehabi26-Aug-06 0:59
Nader Elshehabi26-Aug-06 0:59 
AnswerRe: C# ::: receive FAX Pin
Yetinger27-Aug-06 5:28
Yetinger27-Aug-06 5:28 
QuestionCrystal Reports and Windows Applications Pin
ebonaba25-Aug-06 7:59
ebonaba25-Aug-06 7:59 
QuestionPrinting to an Okidata printer Pin
tigerButterfly25-Aug-06 7:52
tigerButterfly25-Aug-06 7:52 
Question"Unadvising" Event Sink in VB6 Pin
Ilia Blank25-Aug-06 7:46
Ilia Blank25-Aug-06 7:46 
GeneralRe: "Unadvising" Event Sink in VB6 Pin
Guffa25-Aug-06 8:54
Guffa25-Aug-06 8:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.