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?
need help with getting uptime in a 32-bit kernel
-
orcapet3910YT
- Posts: 7
- Joined: Fri Mar 06, 2026 12:27 pm
-
Octocontrabass
- Member

- Posts: 6249
- Joined: Mon Mar 25, 2013 7:01 pm
Re: need help with getting uptime in a 32-bit kernel
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.
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
Yeah, but the problem is I haven't figured out interrupts yet.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.
-
Octocontrabass
- Member

- Posts: 6249
- Joined: Mon Mar 25, 2013 7:01 pm
Re: need help with getting uptime in a 32-bit kernel
Perhaps you should start with interrupts and worry about getting uptime later.orcapet3910YT wrote: ↑Fri Mar 06, 2026 2:52 pmYeah, but the problem is I haven't figured out interrupts yet.
-
orcapet3910YT
- Posts: 7
- Joined: Fri Mar 06, 2026 12:27 pm
Re: need help with getting uptime in a 32-bit kernel
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
Update 2 days later.
Holy dang, I just got interrupts to work and fire. I'm in shock.
Holy dang, I just got interrupts to work and fire. I'm in shock.