getting a PHC reference in a kernel module?

From: Spruyt, Randy
Date: Mon Sep 17 2018 - 13:09:40 EST


I'm new to kernel driver development, so I hope you bear with me on the question.

I'd like to timestamp an IRQ event in a kernel module using a PTP synchronized clock (e.g. the PHC from eth0 = /dev/ptp0). E.g. a GPIO pin goes high, I'd like to keep track of when this happened as accurate as we can. One option is to use getnstimeofday() and have phc2sys synchronize /dev/ptp0 with the system  clock.

This seems to work but I feel like there is a more direct way to just query the PHC clock e.g. using struct ptp_clock* and gettime64(). The question is how to get this pointer, find_driver()? Or something else? Perhaps this is not exposed for a reason?

If this is the wrong way to go about this, by all means, I'm open to suggestions.