The IBM PC has had a pulse generator/timer from the beginning (which also used to drive the PC speaker.) In the olden days, before LSI, it was its own separate chip attached to the data bus. It was very flexible, but generally configured to generate hardware interrupts at 18ms intervals. This hardware interrupt is an IRQ, pretty much hardwired into the CPU, causing it to stop whatever it's doing and jump to a hardwired location in RAM. The OS can do whatever it pleases with that interrupt by putting code in that location.
The hardware is going to be very different on non-PC architectures but the idea is the same, a pulse generator wired to the CPU.
If you're really curious about historical PC architecture, and have a bent towards electronics, I suggest
The 8088 book. The 8088 as much as anything else is responsible for why the PC is the way it is.