• Updated 2023-07-12: Hello, Guest! Welcome back, and be sure to check out this follow-up post about our outage a week or so ago.

68k CPU frequency detection?

cy384

Well-known member
I want to detect the CPU frequency on 68k machines. There's a gestalt selector 'pclk' aka gestaltProcClkSpeed, but this seems to only work on PPC machines. I know this must be possible, what's the trick to it?
 

Bolle

Well-known member
I don't think there's an easy way to find this out.
Best way to find out is to look into how Clockometer and TattleTech do it. Pretty sure they are doing a set of fixed operations and monitor how long it takes to calculate the clock speed from that.
Depending on the CPU type and if there's external cache the clock speed calculation goes horribly wrong on both of those two und certain circumstances.
You'd want to do something along the lines of:
-find out the CPU type you're running on
-run a fixed set of operations (probably want this to be dependant on CPU type because different caching behavior on different CPU types)
-measure how long it takes and from that conclude the speed the CPU must be running at
 

Crutch

Well-known member
Motorola docs tell you how many clock cycles each instruction takes. Don’t forget to adjust for effective address calculation time, if any.

So yeah, I would do it by turning off interrupts, starting a VIA timer, then seeing how long it takes me to do 32767 DBFs. Might be a fun little project actually. Is it possible to turn off instruction caching on an 040? If not you could run it as a totally unrolled loop probably … like literally a thousand or so DBFs in a row.
 

Crutch

Well-known member
Sorry of course I meant like 1000 SUBs or whatever in the loop-unrolled case, it was late. The point is to maybe avoid looping back to a cached instruction. There is probably a better way.

on a plain old 68000 you don’t have to worry about any of that and this is easy.
 
Top