<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://tech-pubs.net/wiki/index.php?action=history&amp;feed=atom&amp;title=Kernel%3AKernel_Timers</id>
	<title>Kernel:Kernel Timers - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://tech-pubs.net/wiki/index.php?action=history&amp;feed=atom&amp;title=Kernel%3AKernel_Timers"/>
	<link rel="alternate" type="text/html" href="http://tech-pubs.net/wiki/index.php?title=Kernel:Kernel_Timers&amp;action=history"/>
	<updated>2026-04-14T16:11:15Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.44.2</generator>
	<entry>
		<id>http://tech-pubs.net/wiki/index.php?title=Kernel:Kernel_Timers&amp;diff=442&amp;oldid=prev</id>
		<title>Raion: Initial</title>
		<link rel="alternate" type="text/html" href="http://tech-pubs.net/wiki/index.php?title=Kernel:Kernel_Timers&amp;diff=442&amp;oldid=prev"/>
		<updated>2025-12-29T20:49:16Z</updated>

		<summary type="html">&lt;p&gt;Initial&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;# IRIX Kernel Timers&lt;br /&gt;
&lt;br /&gt;
The IRIX kernel implements a **high-resolution, per-thread timer subsystem** designed to track the time threads spend in various modes (user, system, interrupt, etc.) with hardware-specific accuracy. This subsystem differs from Illumos/OpenSolaris in several notable ways due to differences in hardware assumptions and kernel design.&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
## Overview&lt;br /&gt;
&lt;br /&gt;
IRIX kernel timers are responsible for:&lt;br /&gt;
&lt;br /&gt;
* Maintaining **accumulated time** for individual threads across multiple timer modes.&lt;br /&gt;
* Providing **high-resolution snapshots** of thread execution time.&lt;br /&gt;
* Handling **timer switching** and accumulation safely in SMP or multi-threaded contexts.&lt;br /&gt;
* Measuring proportional **thread sleep/wait times**.&lt;br /&gt;
* Converting low-level hardware ticks into standard time units (seconds and nanoseconds).&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
## Key Concepts&lt;br /&gt;
&lt;br /&gt;
### Snapshots&lt;br /&gt;
&lt;br /&gt;
* Each thread maintains a **timer snapshot**, representing its current time state.&lt;br /&gt;
* Snapshots may consist of:&lt;br /&gt;
&lt;br /&gt;
  * A single high-resolution counter (if the platform supports absolute, monotonic timers), or&lt;br /&gt;
  * A combination of seconds and hardware-specific ticks to handle short-wrap timers.&lt;br /&gt;
* Snapshots are used to compute deltas between timer updates and to detect timer wrap-around.&lt;br /&gt;
&lt;br /&gt;
### Timer Accumulation&lt;br /&gt;
&lt;br /&gt;
* Each thread has a **per-thread timer package** that tracks:&lt;br /&gt;
&lt;br /&gt;
  * The currently active timer mode.&lt;br /&gt;
  * Accumulated time for all supported timers.&lt;br /&gt;
  * The last snapshot for delta calculations.&lt;br /&gt;
* When switching timers, IRIX computes the delta between the last snapshot and the current time, adding it to the accumulator for the previous timer mode.&lt;br /&gt;
&lt;br /&gt;
### Timer Switching&lt;br /&gt;
&lt;br /&gt;
* Threads can switch between different timer modes explicitly.&lt;br /&gt;
* Timer switching involves:&lt;br /&gt;
&lt;br /&gt;
  * Snapshotting the current timer.&lt;br /&gt;
  * Updating the accumulator of the previously active timer.&lt;br /&gt;
  * Setting the new timer as active.&lt;br /&gt;
* Race conditions are carefully handled by verifying that snapshots are consistent during the update.&lt;br /&gt;
&lt;br /&gt;
### Reading Timers&lt;br /&gt;
&lt;br /&gt;
* Timer reads return the accumulated time for a specific thread and timer mode.&lt;br /&gt;
* If the requested timer is currently active, IRIX computes the time since the last snapshot and adds it to the accumulator.&lt;br /&gt;
* Reading is designed to be **race-resilient**, looping until a consistent snapshot is obtained.&lt;br /&gt;
&lt;br /&gt;
### Sleep Time Measurement&lt;br /&gt;
&lt;br /&gt;
* IRIX provides a measure of **thread sleep/wait time**, representing how long a thread has been idle.&lt;br /&gt;
* This measure is proportional to real time but does not guarantee absolute accuracy.&lt;br /&gt;
* Threads in active timer modes (user, system, or interrupt) report zero sleep time.&lt;br /&gt;
&lt;br /&gt;
### Conversion to Standard Time&lt;br /&gt;
&lt;br /&gt;
* Low-level hardware ticks are converted into **seconds and nanoseconds** for user-facing APIs.&lt;br /&gt;
* Conversion uses hardware-specific frequency and unit scaling, reflecting differences in RTC or high-resolution counters.&lt;br /&gt;
&lt;br /&gt;
### SMP and Atomic Operations&lt;br /&gt;
&lt;br /&gt;
* On multi-processor systems, atomic operations ensure correct accumulation of timers.&lt;br /&gt;
* IRIX distinguishes **CELL IRIX** systems, which use specific atomic add instructions for timer updates.&lt;br /&gt;
* Non-CELL SMP systems rely on standard atomic or interrupt-safe mechanisms.&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
## Differences from Illumos/OpenSolaris&lt;br /&gt;
&lt;br /&gt;
| Feature              | IRIX                                       | Illumos/OpenSolaris                     | Notes                                                                           |&lt;br /&gt;
| -------------------- | ------------------------------------------ | --------------------------------------- | ------------------------------------------------------------------------------- |&lt;br /&gt;
| Timer representation | Hardware-specific ticks, may wrap          | 64-bit monotonic nanoseconds (`hrtime`) | IRIX handles wrap-around; Solaris simpler                                       |&lt;br /&gt;
| Snapshots            | Stored as ticks or [seconds + ticks]       | Stored as cumulative `hrtime`           | IRIX explicitly tracks dual-field snapshots for wrap detection                  |&lt;br /&gt;
| Timer switching      | Explicit per-thread function               | Handled by scheduler/context switch     | IRIX exposes manual switching, Solaris hides it internally                      |&lt;br /&gt;
| Sleep time           | Computed dynamically from snapshots        | Maintained in thread scheduler counters | IRIX calculates on-demand; Solaris updates in scheduler                         |&lt;br /&gt;
| SMP safety           | Explicit atomic operations (CELL-specific) | Generic atomic operations               | IRIX has platform-specific atomic paths; Solaris uses uniform atomic ops        |&lt;br /&gt;
| Time conversion      | Scaled using hardware frequency            | Division of nanoseconds                 | IRIX converts hardware ticks; Solaris works directly with `hrtime`              |&lt;br /&gt;
| Race handling        | Looping snapshot checks                    | Scheduler guarantees consistency        | IRIX implements explicit consistency checks; Solaris relies on locks/atomic ops |&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
## Key Takeaways&lt;br /&gt;
&lt;br /&gt;
* IRIX kernel timers are **hardware-conscious**, designed for platforms with wrapping high-resolution counters.&lt;br /&gt;
* The subsystem provides **manual control** over timer modes and accumulators.&lt;br /&gt;
* It carefully manages **race conditions and SMP safety**, including platform-specific atomic operations.&lt;br /&gt;
* Unlike Illumos/OpenSolaris, IRIX must scale raw hardware ticks into standard time units and detect timer wrap-around.&lt;br /&gt;
* Sleep time and deltas are **computed dynamically** rather than tracked in scheduler-maintained counters.&lt;/div&gt;</summary>
		<author><name>Raion</name></author>
	</entry>
</feed>