flat assembler
Message board for the users of flat assembler.

Index > Windows > frequency counter

Goto page Previous  1, 2
Author
Thread Post new topic Reply to topic
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
Jmac,

OK, rdtsc apparently should be present («chkcpu /v» should say something like Time Stamp Counter: Yes). Did you modify cpuspeed#4.asm before compiling? Without sources or binary I can only guess.
Post 28 May 2010, 12:46
View user's profile Send private message Reply with quote
Jmac



Joined: 23 Nov 2009
Posts: 54
Jmac
Hi...

Nope did not change a thing...

I might try his other version which was for a earlier chip....I think.
Its either the PIT chip....or something happening when talking to the dos window...


anyway...dont put anymore of your time into my problem....I thank you for your help so far..
Post 28 May 2010, 13:45
View user's profile Send private message Reply with quote
Jmac



Joined: 23 Nov 2009
Posts: 54
Jmac
Hi....

Just for trying things...I tried another 2 pieces of code for finding cpu freq..

out of 3.....1 worked on the XP......2 did not...

all 3 failed on my win95 computer.....and 1 has totally frozen the computer...cant reset...cant turn it off...nothing.....hahaha......jst waiting for the power to run down....hahah
Post 28 May 2010, 14:26
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
Jmac,

I wrote simple program that uses rdtsc but doesn't reprogram PIT. Try it:
Code:
        org     0x100
        include "Macro\If.Inc"

macro .repeat [args] {
common
  .repeat
  args
}

        xor     ax, ax
        mov     es, ax
bios_ticks equ es:0x046C

        mov     ah, 0x0F
        int     0x10            ; get active page into bh
        mov     eax, [bios_ticks]
.repeat mov     esi, [bios_ticks]
.until  esi<>eax                ; wait for tick count to change
        cpuid
        rdtsc
        mov     [start.l], eax
        mov     [start.h], edx
.repeat .until esi<>[bios_ticks] ; wait for next tick
        cpuid
        rdtsc
        sub     eax, [start.l]
        sbb     edx, [start.h]  ; edx:eax == TSC delta for ~55 ms
        mov     ecx, 54925      ; 54925.4 or 54924.6 µs, depends on PIT initial count
        div     ecx             ; convert TSC delta to MHz
        cmp     dx, (54925+1)/2 ; can use dx because division is unsigned
        sbb     eax, -1         ; round to nearest
        xor     edx, edx        ; unsigned cdq
        xor     bl, bl          ; no significant digits yet
        mov     si, _MHz
        mov     ecx, 1'000'000'000
conv:   div     ecx
        test    al, al
        jnz     non_0
        test    bl, bl          ; have significant digits already?
        jz      next
non_0:  or      al, '0'
        mov     bl, 0x07        ; for graphics mode (significant digits flag too)
output: mov     ah, 0x0E
        int     0x10
next:   mov     eax, ecx
        mov     ecx, edx
        xor     edx, edx
        idiv    [_10]
        test    eax, eax
        xchg    eax, ecx        ; eax == remainder, ecx == divisor
        jnz     conv            ; divisor nonzero, repeat
        lodsb                   ; output "MHz" trailer
        test    al, al
        jnz     output
        ret

_MHz    db      "MHz", 13, 10, 0
label _10 dword at $-2          ; uses 10 from _MHz
        dw      0
        align   4
start.l rd      1
start.h rd      1    
In DOS it gives pretty stable and reliable results. Under XP numbers are ~8% higher than under DOS and less stable. If it will work under Win95, you can be quite sure that GPF is related to PIT programming.
Post 28 May 2010, 18:10
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4238
Location: 2018
edfed
pit don't bring problems to be reprogrammed, even under xp.
i use pit in v86 mode, then, maybe it is not really pit...
Post 28 May 2010, 19:40
View user's profile Send private message Visit poster's website Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
edfed wrote:
i use pit in v86 mode
Under XP you can use I/O instructions either in NTVDM, or in kernel mode. Latter gives you access to real hardware, former emulates it. With the same level of success you can use “real PIT” in Bochs/DosBox/VMware/whatever.

The problem is in different approach to emulation in NT and 9x. When NT simply dumps bothering application in trash can, 9x tries to do its best for compatibility (often at a price of stability). VTD.VXD, virtual timer device driver that performs system-wide (i.e. scheduler uses it too) virtualization of PIT, in Win98SE is barely 14 KiB. And when it drops the ball (probably due to some program fiddling with ports)… well, IRQ0 has highest priority, without its proper handling all other IRQs wither and die.
Post 28 May 2010, 23:48
View user's profile Send private message Reply with quote
Jmac



Joined: 23 Nov 2009
Posts: 54
Jmac
Hi all..


well I tried that code you provided....it does not work on my XP...DOS window comes up but nothing displays in it....then closes very quick

On the win95 it gives the same error as the other one..


ok....its looking like the win95 computer may not have a PIT....is that at all possible as its used for other system timing as far as I know...

is there a simple test to see if there is one.....something similar to test the eax register to check rdtsc and others...


john
Post 29 May 2010, 01:32
View user's profile Send private message Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 764
Location: Massachusetts, USA
bitshifter
Either run it on console (to pause) or add this code to wait 4 key...
Code:
mov ah,0
int 0x16
ret     

I got a speedy 3181mhz single core Razz
Post 29 May 2010, 01:38
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
Jmac wrote:
On the win95 it gives the same error as the other one.
GPF again? Be more precise, at which address? Try to run it from Win95 safe mode command prompt (i.e. from DOS).
bitshifter wrote:
I got a speedy 3181mhz single core Razz
Is this result stable?
Post 29 May 2010, 07:22
View user's profile Send private message Reply with quote
Jmac



Joined: 23 Nov 2009
Posts: 54
Jmac
hi...

ahh....the GPF was at location 0A11:011A
Post 29 May 2010, 11:30
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
Jmac,

It's rdtsc again. Reboot to safe mode command prompt and try again. Post chkcpu /v output here.
Post 29 May 2010, 12:45
View user's profile Send private message Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 764
Location: Massachusetts, USA
bitshifter
baldr wrote:
Is this result stable?

Yep, it is within around 5% accuracy when i ran it a few times on XP2

_________________
Coding a 3D game engine with fasm is like trying to eat an elephant,
you just have to keep focused and take it one 'byte' at a time.
Post 29 May 2010, 12:49
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
bitshifter,

And what is the real frequency? Or you're telling about 5% difference from it?
Post 29 May 2010, 16:14
View user's profile Send private message Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 764
Location: Massachusetts, USA
bitshifter
Its rated at 2.66ghz.
Post 30 May 2010, 00:16
View user's profile Send private message Reply with quote
Jmac



Joined: 23 Nov 2009
Posts: 54
Jmac
Hi all...

Just an update.....I tried a simpler code just using the rdtsc and Sleep function......also I went with opening a MessageBox to display the speed and it comes up with the right speed...well close enough to say its working...not accurate..but cant expect much using the Sleep......it was just a test of the rdtsc function more than anything....

So it would seem it does work.....and the DOS window maybe the problem.

John
Post 31 May 2010, 09:19
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.