need help with getting uptime in a 32-bit kernel

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
orcapet3910YT
Posts: 7
Joined: Fri Mar 06, 2026 12:27 pm

need help with getting uptime in a 32-bit kernel

Post by orcapet3910YT »

Hi, I've been developing an OS kernel for a while now (which as of now is x86-32 only) and I've been wondering what I can do to get (count) the uptime - I don't know that much about timers yet because I'm still quite new to OS dev.
I also couldn't find a good example or explanation about timer hardware and the good OS kernel repos I looked at (like old Linux) used stuff like a function calling a function calling a function to finally get the uptime in a data type I don't even know.
The kernel doesn't really have multi-core features either (obviously).
Does anyone know how to get something like that done or at least a good source explaining this?
Octocontrabass
Member
Member
Posts: 6249
Joined: Mon Mar 25, 2013 7:01 pm

Re: need help with getting uptime in a 32-bit kernel

Post by Octocontrabass »

Pick one of the time sources available to you (PIT, RTC, TSC, HPET, APIC, ACPI...). Figure out whether it runs at a constant frequency, and if so, what frequency it runs at. For some timers, you may want or need to program the timer to generate a periodic interrupt, and your interrupt handler can increment a counter to keep track of how many interrupts the timer has generated.

When you want to check the uptime, you either read the timer directly or read the interrupt counter, then do some math to convert the value to whatever unit of time you prefer.
orcapet3910YT
Posts: 7
Joined: Fri Mar 06, 2026 12:27 pm

Re: need help with getting uptime in a 32-bit kernel

Post by orcapet3910YT »

Octocontrabass wrote: Fri Mar 06, 2026 1:15 pm Pick one of the time sources available to you (PIT, RTC, TSC, HPET, APIC, ACPI...). Figure out whether it runs at a constant frequency, and if so, what frequency it runs at. For some timers, you may want or need to program the timer to generate a periodic interrupt, and your interrupt handler can increment a counter to keep track of how many interrupts the timer has generated.

When you want to check the uptime, you either read the timer directly or read the interrupt counter, then do some math to convert the value to whatever unit of time you prefer.
Yeah, but the problem is I haven't figured out interrupts yet.
Octocontrabass
Member
Member
Posts: 6249
Joined: Mon Mar 25, 2013 7:01 pm

Re: need help with getting uptime in a 32-bit kernel

Post by Octocontrabass »

orcapet3910YT wrote: Fri Mar 06, 2026 2:52 pmYeah, but the problem is I haven't figured out interrupts yet.
Perhaps you should start with interrupts and worry about getting uptime later.
orcapet3910YT
Posts: 7
Joined: Fri Mar 06, 2026 12:27 pm

Re: need help with getting uptime in a 32-bit kernel

Post by orcapet3910YT »

Okay, will do soon. Just implemented `printf`.
orcapet3910YT
Posts: 7
Joined: Fri Mar 06, 2026 12:27 pm

Re: need help with getting uptime in a 32-bit kernel

Post by orcapet3910YT »

Update 2 days later.
Holy dang, I just got interrupts to work and fire. I'm in shock.
Post Reply