#include <linux/module.h>
#include <linux/init.h>
#include <linux/ktime.h>

struct hrtimer hrt_monotonic, hrt_realtime;

static int print_jiffies( struct hrtimer *hrt )
{
   printk("%ld jiffies ( %p )\n", jiffies, hrt );
   return HRTIMER_NORESTART;
}

static int __init mod_init(void)
{
   struct timespec tp;
   ktime_t tim;

   hrtimer_init( &hrt_monotonic, CLOCK_MONOTONIC, HRTIMER_REL );
   hrtimer_init( &hrt_realtime, CLOCK_REALTIME, HRTIMER_ABS );
   hrt_monotonic.function = print_jiffies;
   hrt_realtime.function = print_jiffies;
   tim = ktime_set( 20, 0 );
   hrtimer_start( &hrt_monotonic, tim, HRTIMER_REL );
   tim = ktime_add( ktime_get_real(), tim );
   hrtimer_start( &hrt_realtime, tim, HRTIMER_ABS );
   printk("Timer activated at %ld jiffies\n", jiffies );
   return 0;
}

static void __exit mod_exit(void)
{
   hrtimer_cancel( &hrt_monotonic );
   hrtimer_cancel( &hrt_realtime );
}

module_init( mod_init );
module_exit( mod_exit );

MODULE_LICENSE("GPL");
