Skip to contentSkip to conversation

hrtimer problem on AT91RM9200

DISCUSSION Bo Hansen 1 participant 2 messages Aug 19, 2009 – Aug 21, 2009 1 message not in the archive

lore
Share & tools
lore

Bo Hansen

author
#0 lore raw

Hi Remy,

Quoted 14 lines

-----Original Besked-----
Fra: Remy Bohmer <[email protected]>
Til: Bo Hansen <[email protected]>
Cc: rt-users <[email protected]>
Dato: 19-08-2009 17:33
Emne: Re: hrtimer problem on AT91RM9200

Hi Bo,

Quoted 4 lines

I have tested with different options and the only one making a difference is disabling high resolution timers. Whenever this is disabled (RT patch or not) the system does not panic. This of course does not make the latency as good as I would like it to be.

Quoted 10 lines

Reading this I guess you want a timer accuracy better than about 1 millisecond on this processor.(at91rm9200)
Setting the CONFIG_HZ to 1000 and disabling HRT would give you about 1 millisecond accuracy.
But, timers in the order of 1 millisecond magnitude can easily have an system (interrupt+softirqs) overhead up to 250us while using HRT on this processor.
So, if you want sub-millisecond timers, then to me it seems that things are somewhat out of balance here.

I actually only want an accurate 10ms periodic time. If possible it would be nice with 1ms or even submillisecond in rare circumstances, but I know we are kind of limited with this CPU.
CONFIG_HZ is set to 128, but there seems to be quite some jitter e.g. on the execution of a thread based on the ordinary timers. That's why I turned to HRT to get the periodic time correct. But maybe I should try setting CONFIG_HZ to 1000 and set the timer to 10 jiffies in stead.

Quoted 4 lines

But, If you want an accurate period time for your realtime application, you can also use the TC-library to provide you a periodic interrupt on which you schedule your RT-task.
This will provide you much better latencies, and a much lower CPU-load.

The Timer counter library sounds interesting - I previously took a look at the source, but I miss some examples of how to use it. Do you know anywhere I can find some beside tcb_clksrc.c?
Correct me if I'm wrong but using TC you still have the RT patch applied, but just disabled HRT/dynticks?
Do you have any idea of the overhead of TC@1ms compared with CONFIG_HZ=1000?

Quoted 19 lines
Quoted 7 lines

A kernel panic from both an RT and non-RT kernel with high resolution timer has been attached. The source seems to vary from time to time.

I noticed than when I stress the system I sometimes get the following message:
hrtimer: interrupt too slow, forcing clock min delta to 52482 ns

This is exactly what I would expect, except that these 52us is still quite fast for this processor...

Quoted 5 lines

And often (but no always) the system panics a little while later. I guess it tells the system is too busy? but should it really end in a kernel panic? Using the RT patch I understand as we can set the priority as we like and stall the system completely, but on a non-RT kernel this should not be possible?

But anyway, it should not panic...

Quoted 7 lines

Kind regards,

Remy
--
To unsubscribe from this list: send the line "unsubscribe linux-rt-users" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Best regards,
Bo

author
#2 lore raw
In reply to a message not in the archive

Hi Remy,

Thank you for clarifying the setup.
The TC-block example was just what I was looking for. I have the timer working so I'll give it a try and see if I can fit it for our system.

Thank you for your time.

Best regards,
Bo

Quoted 116 lines · Remy Bohmer

Hi,

Quoted 4 lines

The Timer counter library sounds interesting - I previously took a look at the source, but I miss some examples of how to use it. Do you know anywhere I can find some beside tcb_clksrc.c?

Mailinglist archives?

But here is an example that produces a 400Hz (configurable) interrupt.
-------------------------------------------------------------------------------------
#include <linux/atmel_tc.h>

static struct atmel_tc *tc;
static int tc_clk_id = 0; /* 0..2 (3 timers per TC-block) */
static int tc_blk_id = 1; /* 0..1 (2 TC-blocks on rm9200,
0 is used by clocksrc/clockevent */
static int tc_timer_freq = 400; /* HZ */

static irqreturn_t tc_timer_interrupt(int irq, void *dummy)

{
        void __iomem    *tcaddr = tc->regs;
        unsigned int    sr = __raw_readl(tcaddr + ATMEL_TC_REG(tc_clk_id, SR));

        if (sr & ATMEL_TC_CPCS) {
                wakeup_my_thread(); /* Here you must wakeup your
RT-thread (use wake_up_process() !!! )*/
                return IRQ_HANDLED;
        }
        return IRQ_NONE;
}

static struct irqaction tc_irqaction = {

       .name           = "periodic-tc-timer",
       .flags          = IRQF_NODELAY | IRQF_DISABLED,
       .handler        = tc_timer_interrupt,

};

void install_tc_periodic_interrupt(void)

{
        void __iomem    *tcaddr;
        int             rate;
        int             res;

        /* allocate the timer block */
        tc = atmel_tc_alloc(tc_blk_id, tc_irqaction.name);
        if (!tc) {
                printk(KERN_ERR "can't alloc TC\n");
                return -ENODEV;
        }

        tcaddr = tc->regs;

        res = setup_irq(tc->irq[tc_clk_id], &tc_irqaction);
        if (res) {
                printk(KERN_ERR "%s: Failed to install timer interrupt:%i\n",
                        __func__, res);
                return res;
        }

        clk_enable(tc->clk[tc_clk_id]);

        rate = clk_get_rate(tc->clk[tc_clk_id]);

        /* Stop only the timer we will use */
        __raw_writel(0xff, tcaddr + ATMEL_TC_REG(tc_clk_id, IDR));
        __raw_writel(ATMEL_TC_CLKDIS, tcaddr + ATMEL_TC_REG(tc_clk_id, CCR));

        /* Use MCK/8 (->CLOCK2), count up to RC, then irq and restart */
        __raw_writel(ATMEL_TC_TIMER_CLOCK2
                        | ATMEL_TC_WAVE | ATMEL_TC_WAVESEL_UP_AUTO,
                        tcaddr + ATMEL_TC_REG(tc_clk_id, CMR));

        __raw_writel((rate/8) / tc_timer_freq,
                                tcaddr + ATMEL_TC_REG(tc_clk_id, RC));

        /* Enable clock and interrupts on RC compare */
        __raw_writel(ATMEL_TC_CPCS, tcaddr + ATMEL_TC_REG(tc_clk_id, IER));

        /* go go gadget! */
        __raw_writel(ATMEL_TC_CLKEN | ATMEL_TC_SWTRG,
                        tcaddr + ATMEL_TC_REG(tc_clk_id, CCR));
        printk(KERN_INFO "TC interrupt source installed.\n");
}

-------------------------------------------------------------------------------------

Quoted 3 lines

Correct me if I'm wrong but using TC you still have the RT patch applied, but just disabled HRT/dynticks?

Yes indeed. We use the RT-patch on these processors without HRT/dynticks. We only use the OS/Posix-timers for non-realtime applications, so CONFIG_HZ can be set low to reduce the timer interrupt load.

Quoted 3 lines

Do you have any idea of the overhead of TC@1ms compared with CONFIG_HZ=1000?

The difference between the 2 is that the kernel does not need to handle all the elapsed timers on every timer interrupt, but instead just waking up a single thread.
FYI, I made measurements of it some time ago that shows what happens on a single timer interrupt on this processor, and I attached a screenshot to this mail.

Have fun!

Remy

------------------------------------------------------------------------