This Linux kernel module provides the offset between clock_monotonic
and clock_realtime
via a device interface. It is a simple and efficient way to retrieve the time offset between these two clocks directly from the kernel space, ensuring high precision and low latency.
- Linux kernel headers installed. You can usually install them via your distribution's package manager. For example, on Ubuntu:
sudo apt install linux-headers-$(uname -r)
-
Clone the repository:
git clone https://github.com/HedgeHawk/realtime-offset.git cd realtime-offset
-
Build the module:
make
-
Insert the module into the kernel:
sudo insmod realtime_offset.ko
-
Check that the module has been loaded:
lsmod | grep realtime_offset
The module creates a device file at /dev/realtime_offset
. You can read from this file to get the current offset between clock_monotonic
and clock_realtime
.
Example:
cat /dev/realtime_offset
offset_init
: Initializes the kernel module, registers the device class and creates the device.offset_exit
: Cleans up when the module is removed, destroying the device and unregistering the device class.dev_open
: Called when the device is opened.dev_release
: Called when the device is released.dev_read
: Reads the offset betweenclock_monotonic
andclock_realtime
and returns it to the user space.
The file_operations
structure is defined with the following callbacks:
open
: Points todev_open
.read
: Points todev_read
.release
: Points todev_release
.
This project is licensed under the GPL License - see the LICENSE file for details.
Thanks to the Linux kernel community and all contributors who have helped in building and improving the kernel, making projects like this possible.