OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 9:05 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Do I really need to support PIT on a 64 bit kernel?
PostPosted: Fri Jul 30, 2021 10:51 pm 
Offline

Joined: Wed Jun 30, 2021 9:29 am
Posts: 7
This might be a stupid question, but in the real world, are there x86-64 CPUs that don't support HPET? I can't find any documentation claiming that it's a standard for x64 CPUs, but I'd rather not constantly have to develop/test two timers (HPET and PIT) at once if I don't have to.

Yes, I know the wiki says to check the MADT tables. I already parse them no problem, and the 4 computers I've tested on have HPET. I'm just getting kind of impatient and want to boot my other cores, but architecturally it seems better to do those one shot timings with the proper (best) timer.


Top
 Profile  
 
 Post subject: Re: Do I really need to support PIT on a 64 bit kernel?
PostPosted: Sat Jul 31, 2021 1:07 am 
Offline
Member
Member

Joined: Sat Nov 21, 2009 5:11 pm
Posts: 852
CPUs do not need to do anything special to support HPET. But any computer that was made in 2003 won't have a HPET, and it is also possible that the user has disabled the HPET in the BIOS.


Top
 Profile  
 
 Post subject: Re: Do I really need to support PIT on a 64 bit kernel?
PostPosted: Sat Jul 31, 2021 1:33 pm 
Offline
Member
Member

Joined: Thu May 17, 2007 1:27 pm
Posts: 999
Some general notes on timers on x86: by far the best timer is the TSC, if invariant TSC is available. Always use the TSC for time keeping in this case: it is generally faster to read from the CPU (two to three orders of magnitude faster than the HPET/PIT/APIC timer) and can be read from user space (makes a huge difference for programs that read the time frequently, e.g., instrumentation-based profiling). If TSC deadline mode is available, use the TSC for interrupts, too. Otherwise, use the local APIC timer in one-shot mode for interrupts.

Use HPET, PIT or the ACPI timer to calibrate the TSC and/or local APIC.

In case invariant TSC is not available, things become more complicated. I would suggest to set the local APIC timer to a fixed interval and to use that for scheduling and for time keeping (since the local APIC is also very fast to read). HPET can then be used to provide more precise interrupts (at time frames that are considerably shorter than the period that you set for the local APIC).

_________________
managarm: Microkernel-based OS capable of running a Wayland desktop (Discord: https://discord.gg/7WB6Ur3). My OS-dev projects: [mlibc: Portable C library for managarm, qword, Linux, Sigma, ...] [LAI: AML interpreter] [xbstrap: Build system for OS distributions].


Top
 Profile  
 
 Post subject: Re: Do I really need to support PIT on a 64 bit kernel?
PostPosted: Sat Jul 31, 2021 9:30 pm 
Offline

Joined: Wed Jun 30, 2021 9:29 am
Posts: 7
Somehow I had no idea that consistent TSC existed. Regardless, it sounds like I should prepare for any scenarios where any combination of clocks exist... but I'm likely overestimating how hard the implementation will be. I guess I don't even really need to implement how I'll use the clocks just for booting multiple cores, as I can just have simple one-shot primitives set up for multicore booting.

Just curious, with consistent TSC, when I boot more cores, will those cores have the same value in their own TSC registers?

Also, in your experience, how accurate do the delays need to be for SMP booting? Do I need to worry about the overhead of a few calls in C while delaying?
(Not sure if this is obvious, but I'm kind of running off the example here. https://wiki.osdev.org/SMP#Startup_Sequence)


Top
 Profile  
 
 Post subject: Re: Do I really need to support PIT on a 64 bit kernel?
PostPosted: Sat Jul 31, 2021 10:21 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
indigo256 wrote:
Also, in your experience, how accurate do the delays need to be for SMP booting? Do I need to worry about the overhead of a few calls in C while delaying?

It's fine if the delays are too long, but if the delays are too short, the APs may not start.

You can minimize the impact of the delays on startup time by starting multiple APs in parallel. The example code on the wiki won't work if you do this.


Top
 Profile  
 
 Post subject: Re: Do I really need to support PIT on a 64 bit kernel?
PostPosted: Sun Aug 01, 2021 12:51 am 
Offline

Joined: Wed Jun 30, 2021 9:29 am
Posts: 7
Quote:
It's fine if the delays are too long, but if the delays are too short, the APs may not start.

That's really good to know, otherwise I would have totally over-engineered booting the other APs by worrying about timers taking too long.


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], DotBot [Bot], Google [Bot] and 59 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