Is there a timer in the CPU?

There are many different types of clocks and timers in computer hardware. All basic computers will have a crystal like a digital watch which is used to synchronise the CPU and forms the "clock speed" in Hz.

Most CPUs have a number of timers built into them which use the clock speed to calculate the relative time between two points. This allows system programmers to set a timer that will "go off" in a certain number of clock cycles of the crystal. The timer alerts the CPU that the defined time has elapsed by raising an interrupt line, which the programmer attaches a piece of code to.

Operating Systems and programming languages usually abstract the interrupt timers so you don't have to work directly with them.

Most advanced computers like PCs have a Real Time Clock which can store the actual calendar time and date but is not often used for timing operations.

In answer to your question:

locating the timer on the hardware board we have

it's very dependant on your hardware and which timer you're interested in. You won't be able to physically see most timers or clocks but the crystal is often easy to find and looks like a small metal capsule - See http://www.electronicrepairguide.com/how-to-test-crystal.html


There are many timers on x86 machines. The most well known is the TSC (Time Stamp Counter). That one is inside the CPU. Then there are PITs (Programmable Interval Timer) as chips on the motherboard, like the Intel 8253 and 8254. I'm not sure whether they are still used though. Another timer is the HPET (High Precision Event Timer). It's not inside the CPU and is the newest of the three.

There's also the battery powered real time clock of course. Not sure if this counts as a timer. Probably not.

Which timer is used is determined by the operating system. On some systems the TSC is used, on other HPET is used. The TSC is usually preferred due to it being inside the CPU, which makes it very fast to access. You can't really access a specific timer directly from C code without assembly instructions that talk directly to the hardware.