rtc(4)
π rtc(4) β real-time clock π
okay so bestie, this is the manual page for rtc(4), from the Kernel Interfaces Manual section (section 4, kernel interfaces, you know the vibe). It's about the Real-Time Clock β yes, the actual tiny clock chip in your machine that keeps ticking even when everything else is asleep. Let's get into it π«Ά
πΈ NAME πΈ
rtc β real-time clock. That's it, that's the whole name. Short, iconic, no notes. π
β¨ SYNOPSIS β¨
#include <linux/rtc.h>
int ioctl(fd, RTC_request, param);
That's the whole entry point, bestie. You open the device, you fire ioctl(2) calls at it, you get clock. Simple. Slay. π₯
π¦ DESCRIPTION π¦
So listen β this is the interface to the drivers for real-time clocks (RTCs). That's the whole point of this page.
Most computers have one or more hardware clocks that record the current "wall clock" time, and those are what we call "Real Time Clocks" (RTCs). Usually one of them has battery backup power, so it keeps tracking the time even while the computer is turned off. Like, the computer is napping and the clock is still clocking. main character energy honestly. RTCs also often provide alarms and other interrupts.
All i386 PCs, and ACPI-based systems too, have an RTC that's compatible with the Motorola MC146818 chip from the original PC/AT. These days that RTC is usually integrated right into the mainboard's chipset (the south bridge, iykyk), and it runs off a replaceable coin-sized backup battery. πͺ
Non-PC systems β think embedded systems built around system-on-chip processors β use other implementations. They usually won't offer the same functionality as the RTC from a PC/AT. Different vibe, different features, no cap.
β° RTC vs system clock β°
Do not confuse RTCs with the system clock. The system clock is a software clock maintained by the kernel, and it's what implements gettimeofday(2) and time(2), plus it's the thing setting timestamps on your files, and so on. The system clock reports seconds and microseconds since a start point, defined to be the POSIX Epoch: 1970-01-01 00:00:00 +0000 (UTC). (One common implementation just counts timer interrupts, once per "jiffy", at a frequency of 100, 250, or 1000 Hz.) So basically it's supposed to report wall clock time β which is also what RTCs do. Same goal, different girlies.
The key difference: RTCs run even when the system is in a low power state (including "off"), and the system clock literally cannot. Until it gets initialized, the system clock can only report time since system boot, not since the POSIX Epoch. So at boot time, and after resuming from a system low power state, the system clock will often be set to the current wall clock time using an RTC. Systems with no RTC at all have to set the system clock using some other clock β maybe across the network, maybe by you typing that data in manually. π
π RTC functionality π
You can read and write RTCs with hwclock(8), or you can go direct with the ioctl(2) requests listed below. Choose your fighter. π
Besides tracking the date and time, lots of RTCs can also generate interrupts:
- on every clock update (i.e., once per second);
- at periodic intervals with a frequency that can be set to any power-of-2 multiple in the range
2 Hzto8192 Hz; - on reaching a previously specified alarm time.
Each one of those interrupt sources can be enabled or disabled separately. Obsessed with the modularity honestly.
On many systems, the alarm interrupt can be configured as a system wakeup event, which can resume the system from a low power state such as Suspend-to-RAM (STR, called S3 in ACPI systems), Hibernation (called S4 in ACPI systems), or even "off" (called S5 in ACPI systems). Waking your computer from the dead? It's giving necromancy β¨. On some systems, the battery backed RTC can't issue interrupts, but another one can. Messy but we move.
The /dev/rtc (or /dev/rtc0, /dev/rtc1, etc.) device can be opened only once (until it's closed) and it is read-only. On read(2) and select(2), the calling process is blocked until the next interrupt from that RTC comes in. Following the interrupt, the process can read a long integer β the least significant byte of it contains a bit mask encoding the types of interrupt that occurred, while the remaining 3 bytes contain the number of interrupts since the last read(2). Bit packing? We love to see it. π
π ioctl(2) interface π
These are the ioctl(2) requests defined on file descriptors connected to RTC devices:
RTC_RD_TIMEβ Returns this RTC's time in the following structure:
struct rtc_time {
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday; /* unused */
int tm_yday; /* unused */
int tm_isdst; /* unused */
};
The fields in this structure have the same meaning and ranges as for the tm structure described in gmtime(3). A pointer to this structure should be passed as the third ioctl(2) argument.
RTC_SET_TIMEβ Sets this RTC's time to the time specified by thertc_timestructure pointed to by the thirdioctl(2)argument. To set the RTC's time, the process must be privileged β i.e., it needs theCAP_SYS_TIMEcapability. πRTC_ALM_READ,RTC_ALM_SETβ Read and set the alarm time, for RTCs that support alarms. The alarm interrupt must be separately enabled or disabled using theRTC_AIE_ON,RTC_AIE_OFFrequests. The thirdioctl(2)argument is a pointer to anrtc_timestructure. Only thetm_sec,tm_min, andtm_hourfields of this structure are used.RTC_IRQP_READ,RTC_IRQP_SETβ Read and set the frequency for periodic interrupts, for RTCs that support periodic interrupts. The periodic interrupt must be separately enabled or disabled using theRTC_PIE_ON,RTC_PIE_OFFrequests. The thirdioctl(2)argument is anunsigned long *or anunsigned long, respectively. The value is the frequency in interrupts per second. The set of allowable frequencies is the multiples of two in the range2to8192. Only a privileged process (i.e., one having theCAP_SYS_RESOURCEcapability) can set frequencies above the value specified in/proc/sys/dev/rtc/max-user-freq. (This file contains the value64by default.)RTC_AIE_ON,RTC_AIE_OFFβ Enable or disable the alarm interrupt, for RTCs that support alarms. The thirdioctl(2)argument is ignored. π«RTC_UIE_ON,RTC_UIE_OFFβ Enable or disable the interrupt on every clock update, for RTCs that support this once-per-second interrupt. The thirdioctl(2)argument is ignored.RTC_PIE_ON,RTC_PIE_OFFβ Enable or disable the periodic interrupt, for RTCs that support these periodic interrupts. The thirdioctl(2)argument is ignored. Only a privileged process (i.e., one having theCAP_SYS_RESOURCEcapability) can enable the periodic interrupt if the frequency is currently set above the value specified in/proc/sys/dev/rtc/max-user-freq.RTC_EPOCH_READ,RTC_EPOCH_SETβ Many RTCs encode the year in an 8-bit register which is either interpreted as an 8-bit binary number or as a BCD number. In both cases, the number is interpreted relative to this RTC's Epoch. The RTC's Epoch is initialized to1900on most systems, but on Alpha and MIPS it might also be initialized to1952,1980, or2000, depending on the value of an RTC register for the year. With some RTCs, these operations can be used to read or to set the RTC's Epoch, respectively. The thirdioctl(2)argument is anunsigned long *or anunsigned long, respectively, and the value returned (or assigned) is the Epoch. To set the RTC's Epoch, the process must be privileged (i.e., have theCAP_SYS_TIMEcapability).RTC_WKALM_RD,RTC_WKALM_SETβ Some RTCs support a more powerful alarm interface, using these ioctls to read or write the RTC's alarm time (respectively) with this structure:
struct rtc_wkalrm {
unsigned char enabled;
unsigned char pending;
struct rtc_time time;
};
The enabled flag is used to enable or disable the alarm interrupt, or to read its current status; when using these calls, RTC_AIE_ON and RTC_AIE_OFF are not used. The pending flag is used by RTC_WKALM_RD to report a pending interrupt (so it's mostly useless on Linux, except when talking to the RTC managed by EFI firmware π). The time field is as used with RTC_ALM_READ and RTC_ALM_SET except that the tm_mday, tm_mon, and tm_year fields are also valid. A pointer to this structure should be passed as the third ioctl(2) argument.
π FILES π
/dev/rtc,/dev/rtc0,/dev/rtc1,...β the RTC special character device files. Get you a device node that does all four./proc/driver/rtcβ status of the (first) RTC. Peek inside, it's cute.
π§ NOTES π§
When the kernel's system time is synchronized with an external reference using adjtimex(2), it will update a designated RTC periodically, every 11 minutes. To do that, the kernel has to briefly turn off periodic interrupts β which might affect programs using that RTC. Heads up, bestie. β οΈ
An RTC's Epoch has nothing to do with the POSIX Epoch, which is used only for the system clock. Two different epochs, two different stories, don't mix them up.
If the year according to the RTC's Epoch and the year register is less than 1970, it is assumed to be 100 years later β that is, between 2000 and 2069. β³
Some RTCs support "wildcard" values in alarm fields, to support scenarios like periodic alarms at fifteen minutes after every hour, or on the first day of each month. Such usage is nonportable; portable user-space code expects only a single alarm interrupt, and will either disable or reinitialize the alarm after receiving it. So like, don't build your whole architecture on wildcard alarms, fr fr.
Some RTCs support periodic interrupts with periods that are multiples of a second rather than fractions of a second; plus multiple alarms; programmable output clock signals; nonvolatile memory; and other hardware capabilities that are not currently exposed by this API. So much untapped potential, lowkey tragic. π
π SEE ALSO π
Also: Documentation/rtc.rst in the Linux kernel source tree β go read it, it ate. π
aaaand that's the whole page, bestie π this one's from Linux man-pages 6.20, dated 2026-02-08. Stay clocked in and stay hydrated πβ¨
π¦ where this page comes from
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- π the page's license: GPL-2.0-or-later
- Copyright 2002, Urs Thuermann <urs@isnogud.escape.de>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms