News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

CPU Frequency Program

Started by dedndave, August 06, 2009, 02:10:47 AM

Previous topic - Next topic

Slugsnack

oh that's quite odd. i guess that's occuring cause the video is running or partially doing so on the core that was maxed out running dedndave's program. that would probably make the most sense

dedndave

in the current version, there is a loop that sets a count and repeatedly reads QueryPerformanceCounter until the terminal count is met
this is all happening with process priority at REALTIME_PRIORITY_CLASS and thread priority at THREAD_PRIORITY_TIME_CRITICAL
in order to give the system a breather, i put a Sleep,1000 in the key-press loop
i am working on a new version that will use Sleep to consume the time (rather than a loop) and use QueryPerformanceounter to measure
it also uses shorter test intervals
this should resolve the hang issues
i also want to use a rolling average to stabilize the readings

qWord

just for addition: In the registry you can also read out cpu's frequency. Take a look at "HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\0" -> "~MHz".

qWord
FPU in a trice: SmplMath
It's that simple!

dedndave

that may not be the actual frequency
i am fairly certain that is the CPU's maximum spec

MichaelW

On my Windows 2000 system it's apparently a measured frequency (the value is ~503 MHz, where I measure 503.52 MHz). DxDiag also shows the value ~503 MHz. What does it show on a system with a variable clock speed?
eschew obfuscation

dedndave

that is interesting
mine says 3000 Mhz, so i just figured it was the max
i wonder if it is set one time at OS installation, or if it is updated regularly (like when the OS throttles)

or, maybe intel had a sale on MHz and Michael has a 503 Mhz chip - lol

qWord

Quote from: dedndave on August 07, 2009, 06:40:33 PM
i wonder if it is set one time at OS installation, or if it is updated regularly (like when the OS throttles)
it seems like the measurement (of maximum frequency) takes place at start up: first start: 2135MHz ,second: 2145MHz (Intel c2d)

Quote from: dedndave on August 07, 2009, 05:07:52 PM
that may not be the actual frequency
I don't think that you can measure the current frequency with an loop-based algorithm, because the workload of this algorithm force the CPU\OS to change it frequency.
FPU in a trice: SmplMath
It's that simple!

dedndave

we seem to have had some success in doing so
we just need to refine our techniques a little
i think the version i am working on now will be fairly accurate and shouldn't cause any system problems
well, that's what i am shooting for, at least   :lol
strictly speaking, version 2 is loop-based - it does work on most machines, but hangs on a few
this new one isn't loop-based - a little better approach

Slugsnack

don't know about 'maximum' frequency cause mine displayed higher than what it was supposed to be lol

dedndave

accuracy is not critical for a cpu - variation from the oscillator design freq of +/-0.5% is not unusual
although, running faster can result in more heat, such a small variation is hardly worth mentioning
Hutch has a later version P4 that cuts back the clock frequency when it runs too hot, which is cool   :lol

sinsi

Well, I tried a window and get 2433.5xx/2433.6xx using WM_TIMER with a 1 second period (how accurate is that anyway?). Yours gives me 2400.6xx
I would say yours is more accurate, but it uses a lot of CPU time whereas mine uses bugger-all.
What is the best way to trigger something once a second? In dos I just reprogram the timer, but in win32 (on win64)? Wait functions, timers, ...?

edit: added the (crap) source. qnd.

[attachment deleted by admin]
Light travels faster than sound, that's why some people seem bright until you hear them.

dedndave

you could set up a timer callback event
i don't think that is neccessary, though, nor is it going to be all that precise
if you look at my last post on the first page of this thread, you will see what i am woking toward
i am adding a few refinements, though
i intend to use a short measurement period to avoid hogging the cpu
then, i am using a rolling average to acquire accuracy, which should bring stability and resolution with it
that method also allows the display to be updated more often
depending on the rolling average length, it will appear as though the measurement has been taken over a longer period
time permitting, i may finish it today
if someone wants to play with timer events...
http://msdn.microsoft.com/en-us/library/ms644901(VS.85).aspx

Sinsi - on my machine, your program is reading 2.976 to 3.020 Ghz and jumps around quite a bit
you might try applying a rolling average - it may not be all that far off
i like the window, though   :bg

dedndave

i have been playing with QueryPerformanceCounter and QueryPerformanceFrequency
first, the counter is using the cput clock as a time base
second, the frequency always reports the same value, no matter what
any calculations made with those two functions are going to be boggies
i have managed to make GetSystemTimeAsFileTime give me some meaningful values (with a trick or two)
i seem to be getting fairly accurate values in 100 ms intervals
it will be nice to see how it looks with the rolling average
notice how it alternates between short and long readings (iambic)
i will use the deltas between each set to calculate a new rolling average update value

time   clocks
937500 281258640
312500 93747495
937500 281262165
312500 93757388
937500 281264078
312500 93759900
937500 281253563
312500 93757470
937500 281261392
312500 93757583
937500 281262938
312500 93745283
937500 281256442
312500 93748388
937500 281265158
312500 93733035
937500 281263373
312500 93741075
937500 281260110
312500 93759442
937500 281261873
312500 93760418

MichaelW

Quote
first, the counter is using the cput clock as a time base
second, the frequency always reports the same value, no matter what
any calculations made with those two functions are going to be boggies

What is "cput" and why do you expect the performance frequency to vary? IIRC it's 1193182 (the nominal frequency of the PIT clock) under Windows 9x, and 3579546 (1193182*3) under Windows 2000 and later.
eschew obfuscation

dedndave

cput = central processing unit typo - lol
well, on my machine, for example, it reports 3000002000
if i try to calculate cpu(t) frequency using CountTSC * FrequencyHP / CountHP,
i will always wind up with 3000002000 +/- (variations in measurement code)
not really what we are after
not to worry - GetSystemTimeAsFileTime is working great