danielealbano / cachegrand

cachegrand - a modern data ingestion, processing and serving platform built for today's hardware
BSD 3-Clause "New" or "Revised" License
975 stars 34 forks source link

Switch clock monotonic to tsc #311

Closed danielealbano closed 1 year ago

danielealbano commented 1 year ago

This PR switches the backend of the clock_monotonic* functions to use the CPU TSC introducing a mechanism to calibrate the amount of cycles per second and then using this value to convert the TSC (timestamp / cycles counter) to uptime.

The clock tests have been updated a new set of tests have been introduced to validate the calibration that read the value from /proc/cpuinfo allowing up to a 2% of tollerance, which is fine because it's not a realtime clock but a monotonic one so if there is a slightly difference with the system one is fine.