discussion forum
message
| Name: |
unknown |
| Date: |
October 02, 2003 at 04:57:14 |
| Subject: |
Re: Question about RDTSC programming |
| In Reply To: |
Re: Question about RDTSC programming by unknown on October 01, 2003 at 16:46:38 |
| Text: |
||||||| To calculate the CPU speed you need to use the 8254 timer (ports 40h-43h) ||||||| It has a resolution of 838ns and is the same on all PCs and has been so ||||||| since the original IBM PC. Depending on what you're doing you might want ||||||| to just use the 8254 timer in your game engine. ||||||| ||||||| The link points to Intel's CPUID document which includes code to calculate ||||||| the CPU speed. Getting the bus speed and multiplier involves reading MSRs ||||||| and is different between processor families. You shouldn't really need that ||||||| info anyway in a game engine. ||||||| |||||| |||||| Hey thanks for getting back to me, I will look into that doc. Ya I shouldnt need to access the MSR but i thought I could get the speed by Bus x multiplier but if this way works thats great. How accurate is it? Thanks |||||| ||||| Using the 8254 timer and RDTSC to time a small sequence of code is very ||||| accurate. You can accurately calculate CPU speed to at least 0.1 Mhz, ||||| probably 0.01 Mhz. ||||| |||| |||| Does the method in the document you gave me a link to utilize 8245? I dont see any referance to it. I cant seem to find any article specific to this timer over at intels page. If it isnt utilized in that doc do you have any sources that would have information it it? Thanks |||| ||| They're using the BIOS timer tick counter (dword at offset 046Ch) which is ||| updated 18.2 times a second from 8254 timer 0 so they are using it but just ||| not directly. Some programs directly use 8254 timer 2 (port 42h) to time an ||| interval and use RDTSC to count cycles, basically it's the same thing - ||| count elasped cycles for a code sequence via RDTSC and find out how much ||| time it took via a known constant time reference (the 8254 timer) and compute ||| the CPU speed from the ratio. ||| || Hi again sorry to be bugging u guys so much hehe. I was reading over the doc again and noticed you needed ring 0 support so my next question i supose would be is it possible for me to get ring zero support in Windows and if so how? || Thanks || | You don't need ring 0 support. I've written DOS CPU info programs which | compute the CPU speed via the 8254 and RDTSC and they work fine under | win9x and win nt/2000 DOS boxes which are ring 3 V86 mode. You simply | need to do the timing several times and take the shortest time to account | for the fact that a ring 3 task can only disable its own interrupts and | that the OS can always interrupt it. That's one reason why you shouldn't | use the BIOS timer tick counter and instead directly use 8254 timer 2. | Thanks for your help but I think i need to step back for a sec and read up some more on assembly before I try this again (I understand how assembly works and understand the logic behind this problem but dont know the synatx well enough yet to implment this) as I cant even get the Intel version to compile in VS.Net. I do have my own version that uses sleeps that seems accurate enough to use for now untill I can learn more on this and try it again.Once again thanks for your help, it has made the solution to this problem clear to me. |
post a followup message
(Be nice... or be blocked. Be technical... or be erased.)
currently posted followup messages
(You may have to press the RELOAD button of your browser.)
- FDA by Peter, 20:56:06 2003/11/19
(0)
|
|