# What's the easist way to access hardware timer/CLKs/ whatever, of a CPU ?

#### DarthVolta

Joined Jan 27, 2015
521
So I'm running Linux on a modern intel CPU. Whats the easiest way to "reach into" the CPU, with commands, or a program, and get a CLK a clock signal , that's not some software program making a clock. And in theory you could put a oscilloscope probe on ?

I'm just wondering out loud, since I've seen the desktop clock lag before (visually on screen anyways)......and the CPU and everything else in a PC must be full of clock signals.

So is there an easy way to see any actual hardware CLK from desktop commands ? Like in the linux terminal, ?

What do most programs do when they need a CLK?

I'm aware of a microprocessor block diagram, and ports and timers, etc.....like arduino. And I'm on a much higher level machine running Linux, but where's all the clocks in the background.....I want to see 1, I suppose as a text/data list stream by. Where's the super dianosigic mode that shows all sorts of internal workings ??

#### BobTPH

Joined Jun 5, 2013
2,751
Really don’t understand what you are asking for. The clock signals inside the CPU are way too fast to be of use to a user program.

OSs typically implement a real time clock based on periodic interrupts of a timer. This you can access through a system call.

Bob

#### MrChips

Joined Oct 2, 2009
22,555
Think of you PC like an automotive engine. You don't connect a pulley to operate your ice cream maker.
Maybe you can connect a food processor via an inverter to an auxiliary 12V outlet.

#### nsaspook

Joined Aug 27, 2009
7,896
If you want to understand the current Linux timer model, read this: https://lwn.net/Articles/646950/

The high-resolution timer ("hrtimer") mechanism is something you use at the kernel/user level for drivers usually: https://www.kernel.org/doc/Documentation/timers/hrtimers.txt

The high-resolution timer here sets the transfer speed for a analog output data stream
C:
/*
*/

{
struct comedi_device *dev = (void*) data;
struct comedi_subdevice *s = &dev->subdevices[2];
struct daqgert_private *devpriv = dev->private;
struct spi_param_type *spi_data = s->private;
struct spi_device *spi = spi_data->spi;
struct comedi_spigert *pdata = spi->dev.platform_data;

if (!dev)
return -EFAULT;

if (likely(test_bit(AO_CMD_RUNNING, &devpriv->state_bits))) {
daqgert_handle_ao_eoc(dev, s);
pdata->kmin = ktime_set(0, pdata->delay_nsecs);
schedule_hrtimeout_range(&pdata->kmin, 0,
HRTIMER_MODE_REL_PINNED);
} else {
clear_bit(SPI_AO_RUN, &devpriv->state_bits);
smp_mb__after_atomic();
smp_mb__before_atomic();
set_bit(SPI_AO_RUN, &devpriv->state_bits);
smp_mb__after_atomic();
}
}

return 0;
}
x86 clock sources: https://0xax.gitbooks.io/linux-insides/content/Timers/linux-timers-6.html

#### Papabravo

Joined Feb 24, 2006
14,876
So I'm running Linux on a modern intel CPU. Whats the easiest way to "reach into" the CPU, with commands, or a program, and get a CLK a clock signal , that's not some software program making a clock. And in theory you could put a oscilloscope probe on ?

I'm just wondering out loud, since I've seen the desktop clock lag before (visually on screen anyways)......and the CPU and everything else in a PC must be full of clock signals.

So is there an easy way to see any actual hardware CLK from desktop commands ? Like in the linux terminal, ?

What do most programs do when they need a CLK?

I'm aware of a microprocessor block diagram, and ports and timers, etc.....like arduino. And I'm on a much higher level machine running Linux, but where's all the clocks in the background.....I want to see 1, I suppose as a text/data list stream by. Where's the super dianosigic mode that shows all sorts of internal workings ??
Unfortunately there is no general purpose, one size fits all answer to your question. A CPU is generally designed to have minimal interaction with it's surroundings. It is limited to memory, peripheral chips, and DMA controllers. It is in the peripheral chips that you will find usable resources like general purpose I/O pins, Counter/timers, Input Capture, Output Compare and so on. Withing those general categories there area a myriad of implementation solutions to read about, learn how to use, and understand. To the extent that a particular operating system would allow access to such resources you probably have to take a pretty deep dive into the OS internals. On a RPi they do have such an interface and at least one OS (Raspian) allows access to such resources.

#### ci139

Joined Jul 11, 2016
1,696
you cant see the CPU clock's lag on your screen
you might be able to "see" the RTC lag (interrupt quantization delay/error)

the cpu clock is much likely internally replicated to higher frequency inside the cpu itself ... it does not quite define in https://en.wikipedia.org/wiki/CPU_multiplier , related https://en.wikipedia.org/wiki/Memory_divider
+ (for windows // i'm not linux)
https://docs.microsoft.com/en-us/windows/win32/sysinfo/time-functions ,
https://en.wikipedia.org/wiki/Real-time_clock

the bold search was to find if there is publicly known method under winows OS to acess RTC control/data registers (well directly)
the closest hint so far

Last edited:

#### MrSoftware

Joined Oct 29, 2013
1,959
The clock on many (most?) modern CPU's is variable, it is turned up and down in real time according to CPU load, for power efficiency. I would think all CPU's used for desktops, laptops, etc.. would have this, probably not as much for embedded processors. Also a modern CPU may have multiple clocks. On my AMD 1920x there are 12 cores that can all run at different frequencies independent of each other, I'm sure Intel processors are similar. I'm honestly not sure if they do this with different clocks or with dividers from a single main clock, but you've got parts of the chip clocked at different frequencies simultaneously. My point is, I'm not sure if you really want what you think you want. What is it exactly that you're trying to accomplish, maybe we can help more if we have that information.

Also consider that for a multi-tasking operating system like Linux, processes, including the processes that put things on the screen, wait for their slice of CPU time in a queue. Different processes get different priorities, and if the processor is busy then lower priority processes just have to wait while other more time critical parts are given higher priority and get CPU time more often. For example, the process for updating the picture of the clock on the GUI isn't really time critical, in a worst case the picture appears to freeze then jump ahead. The actual time keeps running on schedule. Frustrating to the user, but it doesn't really break anything. However the processes for servicing the WiFi adapter is time critical, if it doesn't get service in time then data packets are lost. So if the CPU is super busy, your GUI may have to take a back seat more time critical things, making the GUI appear sluggish. If you need something to happen on a rigid schedule then you want what is called a real time operating system.

#### DarthVolta

Joined Jan 27, 2015
521
Yeah it's just the on screen time that I've seen lagging on windows, normal stuff I'm sure.

I guess I'm wondering about the type of stuff that could be seen, if AMD/Intel takes a CPU and puts it in some test bed and can get signals out, like CLK signals that must be all over a CPU, to make sure it works.

I was just getting into Arduino but then I got totally sidetracked and have returned since. I'll have to start doing some again soon.

#### MrSoftware

Joined Oct 29, 2013
1,959
There is a ton of info available via. software, and a ton of settings that can be configured the same way. How much of it you can get to on any given machine will depend a good deal on the chipset, BIOS, drivers and utilities available. Check out gaming motherboards. Gamers are big on tweaking everything to squeeze as much performance as they can from their hardware, so higher end gaming hardware typically provides access to tons of settings; CPU clocks, bus clocks, memory clocks and timings, voltages, etc.. Whatever PC you have now, check to see if there are any utilities provided by the motherboard manufacturer. Also jump into BIOS and see what settings are in there. Some BIOS is significantly more feature rich than others, but it's worth a look. Just be careful what you play with, it's easy to break things.

#### ci139

Joined Jul 11, 2016
1,696
a late find (likely specifies all externally "visible" "clocks")
https://en.wikipedia.org/wiki/Platform_Controller_Hub

while i was wondering which is faster UDMA or AGP bridge ... became to realization that the entire PC is a bit traffic management exercise (not anything "sophisticated"/orderly/wise/(fully understood by hw/sw designers) as one might imagine)