1

I'm building a non-GPL kernel module (non-negotiable) and in order to get timing information everywhere I look here and elsewhere tells me to use the new ktime_* API, but when I build I get this error:

FATAL: modpost: GPL-incompatible module xxx.ko uses GPL-only symbol 'ktime_get'

All the older APIs have been removed from the kernel, so how can I get something more accurate than jiffies?

4
  • just curious why non-GPL kernel module? Commented Oct 8 at 2:38
  • @iot_builder Our legal department says so. I won't go into any more detail. Commented Oct 8 at 4:02
  • Oh, ok good luck! Commented Oct 8 at 5:15
  • 3
    Perhaps you should ask your legal department then. Commented Oct 8 at 13:58

1 Answer 1

1

I'm on ARM, so I got an ARM-only solution.

This page shows how to interface to the timer, and this page has sample code that I could use (it's in a GPL library, so I'm OK to borrow for internal evaluation only!) - for the record, this is the code:

unsigned long notrace timer_read_counter(void)
{
    unsigned long cntpct;

    isb();
    asm volatile("mrs %0, cntpct_el0" : "=r" (cntpct));

    return cntpct;
}

Thre's also the companion:

unsigned long notrace get_tbclk(void)
{
    unsigned long cntfrq;
    asm volatile("mrs %0, cntfrq_el0" : "=r" (cntfrq));
    return cntfrq;
}

On my hardware this returns 19.2MHz, or about 52 nanoseconds per tick, which is good enough for me.

Sign up to request clarification or add additional context in comments.

1 Comment

You need an isb inst. Every example I have seen has one including the one you linked to.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.