Page 1 of 1

PIT ticking unreasonably slow

Posted: Thu Jun 21, 2018 4:20 am
by Ycep
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: Select all

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: Select all

#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: Select all


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.

Re: PIT ticking unreasonably slow

Posted: Thu Jun 21, 2018 12:42 pm
by Brendan
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

PIT ticking unreasonably slow (Fixed)

Posted: Sun Jun 24, 2018 5:43 am
by Ycep
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().