ideas for delaying os
Re:ideas for delaying os
I mean that a program can call the scheduler and then the timer var becomes inaccurate!
Edit:
By timer I mean a var I can use to wake up threads after a given time!
Edit:
By timer I mean a var I can use to wake up threads after a given time!
Re:ideas for delaying os
If you only ever update the current time variable inside your IRQ0 handler, the time will be as accurate as the PIT is (which is as accurate as you need unless your threads start sleeping for hours).
Re:ideas for delaying os
It has come time to implement my delay function design. I have taken a look ay gazOS delay function and its almost what I want in a design. Looking through the sourcecode, it says that there are many ways to calibrating the delay loop. He uses the Linux way which uses a two-stage method for calibrating.
I like the design approach except that I want my delay function to not only determine the correct time delay for that machine, but to also set the delay to that timing and call each delay in my code. I want to be able to not have to enter a delay timing in the actual function that would get called each time I want to delay a device or message. It would be too much of a pain to have to change the timing each time you tested the code on another machine.
What are some other ways to calibrate a delay loop? What do you think of this two-stage design?
Also, I have written a basic delay that is similar to the one on this previous post http://www.mega-tokyo.com/forum/index.php?board=1;action=display;threadid=5117 and it does nothing when I call it. I have even made sure that interrupts were enabled before I ran it. What could possibly cause the delay to do nothing?
Design of two-stage method is posted below.
[attachment deleted by admin]
I like the design approach except that I want my delay function to not only determine the correct time delay for that machine, but to also set the delay to that timing and call each delay in my code. I want to be able to not have to enter a delay timing in the actual function that would get called each time I want to delay a device or message. It would be too much of a pain to have to change the timing each time you tested the code on another machine.
What are some other ways to calibrate a delay loop? What do you think of this two-stage design?
Also, I have written a basic delay that is similar to the one on this previous post http://www.mega-tokyo.com/forum/index.php?board=1;action=display;threadid=5117 and it does nothing when I call it. I have even made sure that interrupts were enabled before I ran it. What could possibly cause the delay to do nothing?
Design of two-stage method is posted below.
[attachment deleted by admin]
Re:ideas for delaying os
Update: Does anybody have anything to add to this post. Im still trying to write a delay for my os. Any help would be apreciated.
Re:ideas for delaying os
No, I don't have anything to add here.
You can either "calibrate" the cpu, see the Linux sources, or you can use the IRQ 0 handler to do this.
You can either "calibrate" the cpu, see the Linux sources, or you can use the IRQ 0 handler to do this.
Re:ideas for delaying os
Hi
I have not try this,but what about useing the Vertical retrace of the the monitor, to time it, When i was into programming games,this was a good way to make game run at the same speed on high or low speck pc.
It is the same on most pc.
ASHLEY4.
I have not try this,but what about useing the Vertical retrace of the the monitor, to time it, When i was into programming games,this was a good way to make game run at the same speed on high or low speck pc.
It is the same on most pc.
ASHLEY4.
Re:ideas for delaying os
Ah, you mean (in basic, sorry ):ASHLEY4 wrote: Hi
I have not try this,but what about useing the Vertical retrace of the the monitor, to time it, When i was into programming games,this was a good way to make game run at the same speed on high or low speck pc.
It is the same on most pc.
ASHLEY4.
Code: Select all
WAIT &H3DA,8
Re:ideas for delaying os
beyondsociety wrote: Update: Does anybody have anything to add to this post. Im still trying to write a delay for my os. Any help would be apreciated.
Code: Select all
[[section .text]]
; ______________________________________________
;/ \
;This is used to initialize the timer with a 100hz freq*
;so this generates a IRQ every 10 ms this means that at *
; every IRQ 10 ms are over so after 100 IRQs 1 second *
;is over *
;\______________________________________________/
init_Timer:
push eax
mov al,0x36 ; control word 0011_0110b
out TIMER_CTRL_PORT,al
mov al,0x9C ; count LSB
out TIMER_CNTR_0,al
mov al,0x2E ; count MSB
out TIMER_CNTR_0,al;
pop eax
ret
; ______________________________________________
;/ \
; This is the IRQ handler *
; At every call it increments the 'ticks' and if the 'ticks' *
; is greater than 100 then means one second is over so *
; increments the 'uptime' var *
;\_______________________________________________/
TimerHandler:
ISR_HEAD
mov eax,DATA_SEL
mov ds,eax
inc dword [uptime]
.end:
mov al,0x20 ;EOI
out 0x20,al
ISR_TAIL
iret
[[section .data]]
uptime dd 0 ; up time incremented every IRQ
the code for delay is here
Code: Select all
#define MILLISECONDS_PER_TICK 10
void delay(DWORD ms)
{
DWORD end= uptime + (ms / MILLISECONDS_PER_TICK);
while(uptime < end)
;
}
HTH.
Only Human
Re:ideas for delaying os
I have tested the retrace code, and it WORKS! ;D.
Giving me a 1 second delay for 70 retraces on all my pc (10 in number from p100 to p4 3ghz) in text mode,and the in asm is very small,
Let me know if you want me to post the asm code.
ASHLEY4.
Giving me a 1 second delay for 70 retraces on all my pc (10 in number from p100 to p4 3ghz) in text mode,and the in asm is very small,
Let me know if you want me to post the asm code.
ASHLEY4.
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:ideas for delaying os
wooow. That was a long-burried thread ... Thou summonned Old Daemons to come back to life
http://www.osdev.org/osfaq2/index.php/S ... 0Processes
So far, is the 'state of the art' for the problem of delaying/sleeping.
@ashley: polling on the screen is indeed a nice method to get consistent delays on several systems ... provided that the refresh rate of those systems are equivalent. On my old pentium i had a screen that was running at 50Hz in text mode and when i switched to a 17" screen, it appeared that my ASM games were running faster and some delays for hardware (SB initialisation) didn't work anymore ... for the screen was displaying the same mode at 70Hz
So here again, calibration/configuration might indeed be required though it could be easier to achieve.
I dunno how well that method will behave on BOCHS or other pc emulators, though
http://www.osdev.org/osfaq2/index.php/S ... 0Processes
So far, is the 'state of the art' for the problem of delaying/sleeping.
@ashley: polling on the screen is indeed a nice method to get consistent delays on several systems ... provided that the refresh rate of those systems are equivalent. On my old pentium i had a screen that was running at 50Hz in text mode and when i switched to a 17" screen, it appeared that my ASM games were running faster and some delays for hardware (SB initialisation) didn't work anymore ... for the screen was displaying the same mode at 70Hz
So here again, calibration/configuration might indeed be required though it could be easier to achieve.
I dunno how well that method will behave on BOCHS or other pc emulators, though
Re:ideas for delaying os
And what about calibrating the CPU ?
How does it work ? ::)
(Maybe I could say it else: how to determine the cpu speed ? ??? )
How does it work ? ::)
(Maybe I could say it else: how to determine the cpu speed ? ??? )
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:ideas for delaying os
rather than (poorly) trying to re-explain it once again, i'll just suggest you to check:
http://www.mega-tokyo.com/forum/index.p ... 22;start=0
http://www.mega-tokyo.com/forum/index.p ... 67;start=0
i think i'll gather a few more links and report my result in the FAQ
http://www.mega-tokyo.com/forum/index.p ... 22;start=0
http://www.mega-tokyo.com/forum/index.p ... 67;start=0
i think i'll gather a few more links and report my result in the FAQ
Re:ideas for delaying os
I think 90% pc would be 60-70Hz on boot up and if its for things like print to screen wait and print some thing els.
It Will be fine (I'm go to convert for none critical delays.)
ASHLEY4.
It Will be fine (I'm go to convert for none critical delays.)
ASHLEY4.
Re:ideas for delaying os
90% is way less than reliable. 99.999% of Windows 95/NT computers never reach 49 days, yet those that do crash because of the short-sightedness of some developer. And even then, at least I have 3 computers under my adminning, two of which do 60, one does 85 and one does 100. Severely screws up the testing doesn't it?ASHLEY4 wrote: I think 90% pc would be 60-70Hz on boot up and if its for things like print to screen wait and print some thing els.
It Will be fine (I'm go to convert for none critical delays.)
ASHLEY4.
Why use the vertical retrace when the PIT works better?
[edit]Yep, the PIT. [me=Candy]needs to get enough sleep someday...[/edit][/me]
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:ideas for delaying os
Candy meant PIT, not PIC, of course
(or at least i guess he does)
Everything depends of course on *why* you want a delay... if you wish to wait 500ms for a server to respond, you should not wait 250ms ... If you just wish to wait "some time so that the user saw a very important message and had the time to hit a key" or "some time so that the sound you're playing through the speaker can be heard", it will certainly be unfriendly to half/double times but using CRT as a synchronization mean remains a good alternative.
And if you want to play a smooth animation, then W8VR is *the* solution ...
(or at least i guess he does)
Everything depends of course on *why* you want a delay... if you wish to wait 500ms for a server to respond, you should not wait 250ms ... If you just wish to wait "some time so that the user saw a very important message and had the time to hit a key" or "some time so that the sound you're playing through the speaker can be heard", it will certainly be unfriendly to half/double times but using CRT as a synchronization mean remains a good alternative.
And if you want to play a smooth animation, then W8VR is *the* solution ...