All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bo Hansen <bh@newtec.dk>
To: Remy Bohmer <linux@bohmer.net>
Cc: rt-users <linux-rt-users@vger.kernel.org>
Subject: Re: hrtimer problem on AT91RM9200
Date: Fri, 21 Aug 2009 15:16:50 +0200	[thread overview]
Message-ID: <4A8E9E42.6080802@newtec.dk> (raw)
In-Reply-To: <3efb10970908191121u3e88d35fs2606dcb76d877ac@mail.gmail.com>

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

Remy Bohmer wrote:
> Hi,
>
>   
>> 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");
> }
> -------------------------------------------------------------------------------------
>
>   
>> 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.
>
>   
>> 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
>   
>
> ------------------------------------------------------------------------
>

  parent reply	other threads:[~2009-08-21 13:16 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-19 16:40 Re[2]: hrtimer problem on AT91RM9200 Bo Hansen
     [not found] ` <3efb10970908191121u3e88d35fs2606dcb76d877ac@mail.gmail.com>
2009-08-21 13:16   ` Bo Hansen [this message]
  -- strict thread matches above, loose matches on Subject: below --
2009-08-19 12:24 Bo Hansen
2009-08-19 15:33 ` Remy Bohmer
2009-08-20 19:52 ` Uwe Kleine-König
2009-08-21 12:57   ` Bo Hansen
     [not found]     ` <fae6a9700908232327u65fca65bt97bb8c43a91345cd@mail.gmail.com>
2009-08-24  6:30       ` Vivek Satpute
2009-09-03 14:12     ` Uwe Kleine-König
2009-09-10  6:44       ` Bo Hansen
2009-09-10  9:51         ` Uwe Kleine-König
2009-09-11 15:20           ` Uwe Kleine-König
2009-09-11 23:07             ` Uwe Kleine-König
2009-09-14 10:50               ` Bo Hansen
2009-09-14 11:10                 ` Uwe Kleine-König
2009-09-14  9:09             ` Bo Hansen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4A8E9E42.6080802@newtec.dk \
    --to=bh@newtec.dk \
    --cc=linux-rt-users@vger.kernel.org \
    --cc=linux@bohmer.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.