We use timers in our code; I am just curious about the real implementation of it. Is there a timer in the CPU logic circuit or outside the CPU die – for example, an external clock or anything like that?
If not, then where is the timer? No need for any detailed explanation on how a hardware timer is made, just focus on locating the timer on the hardware board we have.
A computer's processor clock speed determines how quickly the central processing unit (CPU) can retrieve and interpret instructions. This helps your computer complete more tasks by getting them done faster. Clock speeds are measured in gigahertz (GHz), with a higher number equating to higher clock speed.
My understanding is that there is just ONE CLOCK inside a modern PC that regulates pretty much everything. It is an oscillator that depends on the vibration of a quartz crystal and it outputs a frequency of 100 MHz and a frequency of 133 MHz.
In order to synchronize all of a computer's operations, a system clock—a small quartz crystal located on the motherboard—is used. The system clock sends out a signal on a regular basis to all other computer components.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With