0

I'm fairly new to Linux kernel module development, so I apologize in advance if I'm missing something really obvious here. I'm trying to write a simple module using the OMAP3730's GP timer in order to benchmark/timestamp on the Beagleboard-xm with more resolution.

The relevant code looks like this:

static struct omap_dm_timer *timer_ptr; // Global timer
EXPORT_SYMBOL(timer_ptr); 

static int hrt_init(void)
{
    int result = 0;

    printk("hrt: inserting module\n");

    /* Register device with our requested major */
    result = register_chrdev(hrt_major, "hrt", &hrt_fops);
    if (result < 0) {
        printk("hrt: error: can't obtain major number %d\n", hrt_major);
        return result;
    }

    /* Reserve a timer */
    timer_ptr = omap_dm_timer_request();                                          

    if (timer_ptr == NULL){
        printk("hrt: error: no timer is available\n");
        return -1;
    }

    /* Set clock source to system clock, prescaler to 1:1, start the timer */
    if (omap_dm_timer_set_source(timer_ptr, OMAP_TIMER_SRC_SYS_CLK) < 0)
    {
        printk("hrt: error setting OPMAP_TIMER_SRC_SYS_CLK\n");
        return -1;
    }
    omap_dm_timer_set_prescaler(timer_ptr, 0);
    omap_dm_timer_set_load_start(timer_ptr, 1, 0);

    /* Success */
    return 0;
}

static void hrt_exit(void)
{
    printk("hrt: removing module\n");

    /* Stop and release the timer */
    omap_dm_timer_stop(timer_ptr);
    omap_dm_timer_free(timer_ptr);
    timer_ptr = 0;

    /* Unregister the char device */
    unregister_chrdev(hrt_major, "hrt");
}

I'm compiling under Angstrom on

Linux beagleboard 3.6.7+ #1 SMP armv7l GNU/Linux

The first time I insert the module, it works fine. I can also remove it, and verify that the hrt_exit() function is run in the log. The problem comes when I try to re-insert it, and consequently re-allocate a timer. I get the following from the kernel:

[ 2546.762268] hrt: inserting module
[ 2546.765960] omap_dm_timer_set_source: failed to set timer_32k_ck as parent
[ 2546.773345] hrt: error: no timer is available
insmod: error inserting 'HRT.ko': -1 Operation not permitted

I haven't been able to find any info around the web on this particular error, I'm a little confused because I'm not trying to set_source until after I allocate the timer, but that message appears before the allocation failure error. In any case, I don't see why it is failing to allocate another timer, especially given that there are several on the SoC. Any ideas? Need more info? Thank you!

  • Apparently `hrt_exit()` is not performing a thorough job of deallocating all resources that the driver has acquired. – sawdust Oct 11 '13 at 22:46
  • This platform has 12 GP timers, only one of which (AFAIK) is used by the kernel already. omap_dm_timer_request() allocates one of these 12 dynamically. So even if my module is not deallocating it properly (which I believe it is, according to TI's examples) I should in theory be able to allocate 10 more timers before it fails. – nearengine Oct 12 '13 at 00:00
  • Did you ever resolve this issue? I'm running into the same problem writing a kernel module for a PandaBoard (which has the same OMAP processor). – xiii1408 Nov 06 '15 at 20:54
  • Unfortunately I was never able to resolve this, and TI's forums weren't very helpful when I cross posted this question over there. Since this was mainly for benchmarking use and didn't need to be fault tolerant I wasn't able to spend much more time debugging it. I would be interested in the solution if you figure it out! Sorry I couldn't be of any more help. – nearengine Nov 07 '15 at 19:25

0 Answers0