From: leoy@marvell.com (Leo Yan)
To: linux-arm-kernel@lists.infradead.org
Subject: [RFC PATCH v2] clockevents: re-calculate event when cpu enter idle
Date: Tue, 9 Sep 2014 16:55:49 +0800 [thread overview]
Message-ID: <540EC095.8060901@marvell.com> (raw)
In-Reply-To: <1409793933-29938-1-git-send-email-leoy@marvell.com>
On 09/04/2014 09:25 AM, Leo Yan wrote:
> Below flow will have the redundant interrupts for broadcast timer:
>
> 1. Process A starts a hrtimer with 100ms timeout, then Process A will
> wait on the waitqueue to sleep;
> 2. The CPU which Process A runs on will enter idle and call notify
> CLOCK_EVT_NOTIFY_BROADCAST_ENTER, so the CPU will shutdown its local
> and set broadcast timer's next event with delta for 100ms timeout;
> 3. After 70ms later, the CPU is waken up by other peripheral's interrupt
> and Process A will be waken up as well; Process A will cancel the hrtimer
> at this point, kernel will remove the timer event from the event queue
> but it will not really disable broadcast timer;
> 4. So after 30ms later, the broadcast timer interrupt will be triggered
> even though the timer has been cancelled by s/w in step 3.
>
> To fix this issue, in theory cpu can check this situation when the cpu
> enter and exit idle; So it can iterate the related idle cpus to calculate
> the correct broadcast event value.
>
> But with upper method, it has the side effect. Due the cpu enter and exit
> idle state very frequently in short time, so can optimize to only calculate
> the correct state only when the cpu join into broadcast timer and set the
> next event after calculate a different event compare to previous time.
>
> Signed-off-by: Leo Yan <leoy@marvell.com>
hi Thomas and all,
Could u take time to review this patch, do u think this patch is
adorable? we have do some testing and looks like it's health. But i
still want to know if u have any comment or suggestion, or we can merge
this patch into mainline.
Thanks,
Leo Yan
> ---
> kernel/time/tick-broadcast.c | 56 +++++++++++++++++++++++++++++++++++++-------
> 1 file changed, 48 insertions(+), 8 deletions(-)
>
> diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
> index 64c5990..52f8879 100644
> --- a/kernel/time/tick-broadcast.c
> +++ b/kernel/time/tick-broadcast.c
> @@ -324,6 +324,31 @@ unlock:
> raw_spin_unlock(&tick_broadcast_lock);
> }
>
> +static void tick_broadcast_oneshot_get_earlier_event(void)
> +{
> + struct clock_event_device *bc;
> + struct tick_device *td;
> + ktime_t next_event;
> + int cpu, next_cpu = 0;
> +
> + next_event.tv64 = KTIME_MAX;
> +
> + /* iterate all expired events */
> + for_each_cpu(cpu, tick_broadcast_oneshot_mask) {
> +
> + td = &per_cpu(tick_cpu_device, cpu);
> + if (td->evtdev->next_event.tv64 < next_event.tv64) {
> + next_event.tv64 = td->evtdev->next_event.tv64;
> + next_cpu = cpu;
> + }
> + }
> +
> + bc = tick_broadcast_device.evtdev;
> + if (next_event.tv64 != KTIME_MAX &&
> + next_event.tv64 != bc->next_event.tv64)
> + tick_broadcast_set_event(bc, next_cpu, next_event, 0);
> +}
> +
> /*
> * Powerstate information: The system enters/leaves a state, where
> * affected devices might stop
> @@ -717,17 +742,32 @@ int tick_broadcast_oneshot_control(unsigned long reason)
> if (!cpumask_test_and_set_cpu(cpu, tick_broadcast_oneshot_mask)) {
> WARN_ON_ONCE(cpumask_test_cpu(cpu, tick_broadcast_pending_mask));
> broadcast_shutdown_local(bc, dev);
> +
> + /*
> + * We only reprogram the broadcast timer if we did not
> + * mark ourself in the force mask; If the current CPU
> + * is in the force mask, then we are going to be woken
> + * by the IPI right away.
> + */
> + if (cpumask_test_cpu(cpu, tick_broadcast_force_mask))
> + goto out;
> +
> /*
> - * We only reprogram the broadcast timer if we
> - * did not mark ourself in the force mask and
> - * if the cpu local event is earlier than the
> - * broadcast event. If the current CPU is in
> - * the force mask, then we are going to be
> - * woken by the IPI right away.
> + * Reprogram the broadcast timer if the cpu local event
> + * is earlier than the broadcast event;
> */
> - if (!cpumask_test_cpu(cpu, tick_broadcast_force_mask) &&
> - dev->next_event.tv64 < bc->next_event.tv64)
> + if (dev->next_event.tv64 < bc->next_event.tv64) {
> tick_broadcast_set_event(bc, cpu, dev->next_event, 1);
> + goto out;
> + }
> +
> + /*
> + * It's possible the cpu has cancelled the timer which
> + * has set the broadcast event at last time, so
> + * re-calculate the broadcast timer according to all
> + * related cpus' expire events.
> + */
> + tick_broadcast_oneshot_get_earlier_event();
> }
> /*
> * If the current CPU owns the hrtimer broadcast
>
WARNING: multiple messages have this Message-ID (diff)
From: Leo Yan <leoy@marvell.com>
To: "tglx@linutronix.de" <tglx@linutronix.de>,
"linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [RFC PATCH v2] clockevents: re-calculate event when cpu enter idle
Date: Tue, 9 Sep 2014 16:55:49 +0800 [thread overview]
Message-ID: <540EC095.8060901@marvell.com> (raw)
In-Reply-To: <1409793933-29938-1-git-send-email-leoy@marvell.com>
On 09/04/2014 09:25 AM, Leo Yan wrote:
> Below flow will have the redundant interrupts for broadcast timer:
>
> 1. Process A starts a hrtimer with 100ms timeout, then Process A will
> wait on the waitqueue to sleep;
> 2. The CPU which Process A runs on will enter idle and call notify
> CLOCK_EVT_NOTIFY_BROADCAST_ENTER, so the CPU will shutdown its local
> and set broadcast timer's next event with delta for 100ms timeout;
> 3. After 70ms later, the CPU is waken up by other peripheral's interrupt
> and Process A will be waken up as well; Process A will cancel the hrtimer
> at this point, kernel will remove the timer event from the event queue
> but it will not really disable broadcast timer;
> 4. So after 30ms later, the broadcast timer interrupt will be triggered
> even though the timer has been cancelled by s/w in step 3.
>
> To fix this issue, in theory cpu can check this situation when the cpu
> enter and exit idle; So it can iterate the related idle cpus to calculate
> the correct broadcast event value.
>
> But with upper method, it has the side effect. Due the cpu enter and exit
> idle state very frequently in short time, so can optimize to only calculate
> the correct state only when the cpu join into broadcast timer and set the
> next event after calculate a different event compare to previous time.
>
> Signed-off-by: Leo Yan <leoy@marvell.com>
hi Thomas and all,
Could u take time to review this patch, do u think this patch is
adorable? we have do some testing and looks like it's health. But i
still want to know if u have any comment or suggestion, or we can merge
this patch into mainline.
Thanks,
Leo Yan
> ---
> kernel/time/tick-broadcast.c | 56 +++++++++++++++++++++++++++++++++++++-------
> 1 file changed, 48 insertions(+), 8 deletions(-)
>
> diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
> index 64c5990..52f8879 100644
> --- a/kernel/time/tick-broadcast.c
> +++ b/kernel/time/tick-broadcast.c
> @@ -324,6 +324,31 @@ unlock:
> raw_spin_unlock(&tick_broadcast_lock);
> }
>
> +static void tick_broadcast_oneshot_get_earlier_event(void)
> +{
> + struct clock_event_device *bc;
> + struct tick_device *td;
> + ktime_t next_event;
> + int cpu, next_cpu = 0;
> +
> + next_event.tv64 = KTIME_MAX;
> +
> + /* iterate all expired events */
> + for_each_cpu(cpu, tick_broadcast_oneshot_mask) {
> +
> + td = &per_cpu(tick_cpu_device, cpu);
> + if (td->evtdev->next_event.tv64 < next_event.tv64) {
> + next_event.tv64 = td->evtdev->next_event.tv64;
> + next_cpu = cpu;
> + }
> + }
> +
> + bc = tick_broadcast_device.evtdev;
> + if (next_event.tv64 != KTIME_MAX &&
> + next_event.tv64 != bc->next_event.tv64)
> + tick_broadcast_set_event(bc, next_cpu, next_event, 0);
> +}
> +
> /*
> * Powerstate information: The system enters/leaves a state, where
> * affected devices might stop
> @@ -717,17 +742,32 @@ int tick_broadcast_oneshot_control(unsigned long reason)
> if (!cpumask_test_and_set_cpu(cpu, tick_broadcast_oneshot_mask)) {
> WARN_ON_ONCE(cpumask_test_cpu(cpu, tick_broadcast_pending_mask));
> broadcast_shutdown_local(bc, dev);
> +
> + /*
> + * We only reprogram the broadcast timer if we did not
> + * mark ourself in the force mask; If the current CPU
> + * is in the force mask, then we are going to be woken
> + * by the IPI right away.
> + */
> + if (cpumask_test_cpu(cpu, tick_broadcast_force_mask))
> + goto out;
> +
> /*
> - * We only reprogram the broadcast timer if we
> - * did not mark ourself in the force mask and
> - * if the cpu local event is earlier than the
> - * broadcast event. If the current CPU is in
> - * the force mask, then we are going to be
> - * woken by the IPI right away.
> + * Reprogram the broadcast timer if the cpu local event
> + * is earlier than the broadcast event;
> */
> - if (!cpumask_test_cpu(cpu, tick_broadcast_force_mask) &&
> - dev->next_event.tv64 < bc->next_event.tv64)
> + if (dev->next_event.tv64 < bc->next_event.tv64) {
> tick_broadcast_set_event(bc, cpu, dev->next_event, 1);
> + goto out;
> + }
> +
> + /*
> + * It's possible the cpu has cancelled the timer which
> + * has set the broadcast event at last time, so
> + * re-calculate the broadcast timer according to all
> + * related cpus' expire events.
> + */
> + tick_broadcast_oneshot_get_earlier_event();
> }
> /*
> * If the current CPU owns the hrtimer broadcast
>
next prev parent reply other threads:[~2014-09-09 8:55 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-04 1:25 [RFC PATCH v2] clockevents: re-calculate event when cpu enter idle Leo Yan
2014-09-04 1:25 ` Leo Yan
2014-09-09 8:55 ` Leo Yan [this message]
2014-09-09 8:55 ` Leo Yan
2014-09-09 10:35 ` Thomas Gleixner
2014-09-09 10:35 ` Thomas Gleixner
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=540EC095.8060901@marvell.com \
--to=leoy@marvell.com \
--cc=linux-arm-kernel@lists.infradead.org \
/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.