OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Apr 18, 2024 7:17 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: PIT ticking unreasonably slow
PostPosted: Thu Jun 21, 2018 4:20 am 
Offline
Member
Member
User avatar

Joined: Mon Dec 28, 2015 11:11 am
Posts: 401
Hi,
I had this problem both on the Nutoak and on my new Quartz Operating System, the fact that the PIT without the "realtime" Bochs setting is too quick, with it it's ticking too slow (~5 times slower than it was set to be), and with "slowdown" even further in the deep abyss of slowness.

Related code:
pit.asm (MASM)
Code:
PUBLIC __usleep
PUBLIC __tckc
_intend PROTO
.data
   __tckc DWORD 0
.code
_pit_irqHandler:
   inc [__tckc]
   push eax
   push ebx ;These two registers are used in _intend.
   push 0
   call _intend
   pop ebx
   pop eax
   iretd
__usleep:
   push ebp
   mov ebp, esp
   push ebx
   push ecx
   push edx
   mov edx, [__tckc]
   mov ecx, [ebp+8]
   add ecx, edx
   _loop:
   cmp ecx, edx
   jle outfc
   hlt
   mov edx, [__tckc]
   jmp _loop
   outfc:
   pop edx
   pop ecx
   pop ebx
   xor eax, eax
   mov esi, [ebp+4]
   pop ebp
   add esp, 4
   jmp esi
END


PIT initialization related code:
Code:
#define PIT_FREQ 1193180
unsigned pit_initCounter(unsigned freq, unsigned counter, unsigned char mode_bin)
{
   unsigned char counter_bin;
   unsigned char rcounter_bin;
   switch (counter)
   {
   case 0:
      counter_bin = x86_PIT_OCW_COUNTER_0;
      rcounter_bin = x86_PIT_RCOUNTER0;
   case 1:
      counter_bin = x86_PIT_OCW_COUNTER_1;
      rcounter_bin = x86_PIT_RCOUNTER1;
      break;
   case 2:
      counter_bin = x86_PIT_OCW_COUNTER_2;
      rcounter_bin = x86_PIT_RCOUNTER2;
      break;
   }
   unsigned short tpf = PIT_FREQ / freq;
   outb(x86_PIT_COMMAND, counter_bin | x86_PIT_OCW_RL_DATA | mode_bin);
   outb(rcounter_bin, tpf);
   outb(rcounter_bin, tpf >> 8);
   _tckc = 0;
   return counter;
}
...
pit_initCounter(100, 0, x86_PIT_OCW_MODE_SQUAREWAVEGEN);

Although if any of these was actually a problem the PIT would probably not send any IRQs at all.
The code I use for testing:
Code:

for (int i = 0; i < 10; i++)
{
   _usleep(100); //Sleep one second
   if(i%2) v_term_write('t');
   else v_term_write('T');
}
v_term_write('e');

The delay between a 'T' and a 't' is ~5 seconds.
Did anybody had such problem or know a proper solution to this?
I'll appreciate any of your help.


Attachments:
File comment: Entire repository
Quartz-master.zip [43.4 KiB]
Downloaded 11 times
Top
 Profile  
 
 Post subject: Re: PIT ticking unreasonably slow
PostPosted: Thu Jun 21, 2018 12:42 pm 
Offline
Member
Member
User avatar

Joined: Sat Jan 15, 2005 12:00 am
Posts: 8561
Location: At his keyboard!
Hi,

Lukand wrote:
I had this problem both on the Nutoak and on my new Quartz Operating System, the fact that the PIT without the "realtime" Bochs setting is too quick, with it it's ticking too slow (~5 times slower than it was set to be), and with "slowdown" even further in the deep abyss of slowness.


What does it do on other computers (e.g. is it too slow on a real computer)?

Also, it might help to try "clock: sync=slowdown" and reduce your IPS setting by about 10 (e.g. if you currently have "cpu: count=2, ips=12345678" then see what happens if you use "cpu: count=2, ips=1234567" instead).

Note: I couldn't see a problem in your code.


Cheers,

Brendan

_________________
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.


Top
 Profile  
 
 Post subject: PIT ticking unreasonably slow (Fixed)
PostPosted: Sun Jun 24, 2018 5:43 am 
Offline
Member
Member
User avatar

Joined: Mon Dec 28, 2015 11:11 am
Posts: 401
Due to lack of time, and work on some other parts of the operating system, I could not have responded to your post Brendan. Thanks anyway.
There was no break at case 0 in the pit_initCounter().


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 90 guests


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group