Reputation: 21
Is there a way to adjust an hrtimer's parameters (specifically I want to adjust min_delta_ns) from within a kernel module?
I'm writing a kernel module that has some outputs driven by an hrtimer. Here's a rough outline of the basic code:
#include <linux/hrtimer.h>
#include <linux/sched.h>
#define MAXRUNS 300000
#define PERIOD_IN_NS 100000
static struct hrtimer hr_timer;
static ktime_t ktime_period_ns;
static volatile int runcount = 0;
static int some_function(parameters) {
ktime_period_ns= ktime_set( 0, PERIOD_IN_NS );
hrtimer_init ( &hr_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL );
htimer.function = timer_callback;
hrtimer_start( &hr_timer, ktime_period_ns, HRTIMER_MODE_REL );
return 0;
}
static enum hrtimer_restart timer_callback(struct hrtimer *timer)
{
runcount++;
if (runcount < MAXRUNS) {
// do stuff
hrtimer_forward_now(&hr_timer, ktime_period_ns);
return HRTIMER_RESTART;
} else {
runcount = 0;
return HRTIMER_NORESTART;
}
}
When I run it with PERIOD_IN_NS of 100,000 or greater everything works great. However, if I drop that value to say, 50,000, the period of my clamps at around 90,000 (ish) and output becomes unpredictable.
I ran cat /proc/timer_list to get the details of my timers and here are the details what I believe is the relevant timer:
Tick Device: mode: 1
Per CPU device: 0
Clock Event Device: mxc_timer1
max_delta_ns: 1431655752223
min_delta_ns: 85000
mult: 6442451
shift: 31
mode: 3
next_event: 13571723000000 nsecs
set_next_event: v2_set_next_event
set_mode: mxc_set_mode
event_handler: hrtimer_interrupt
retries: 0
From what I've read about how hrtimer works, that min_delta_ns of 85000 means that I can't run interrupts with a period any smaller than 85,000 nanoseconds. I'd like to try to decrease that value to see if I can get my code to cycle any faster without detrimental effects to the system (I'm running this on Raspberry-Pi-like dev board called the HummingBoard).
It looks like this clock is being initially configured in my specific architecture's version of time.c (line 180), but I can't figure out how to access and modify the values outside of that context in my custom kernel module.
Is there a way to adjust the values of an hrtimer's parameters from within my kernel module?
Upvotes: 2
Views: 618
Reputation: 180260
The min_delta_ns
value describes a property of the hardware device.
Even if you were able to change this value (which you cannot), the timer event would not actually arrive any faster.
Upvotes: 1