2018-10-31 18:21:09 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2007-02-16 09:28:03 +00:00
|
|
|
/*
|
|
|
|
* This file contains functions which manage high resolution tick
|
|
|
|
* related events.
|
|
|
|
*
|
|
|
|
* Copyright(C) 2005-2006, Thomas Gleixner <tglx@linutronix.de>
|
|
|
|
* Copyright(C) 2005-2007, Red Hat, Inc., Ingo Molnar
|
|
|
|
* Copyright(C) 2006-2007, Timesys Corp., Thomas Gleixner
|
|
|
|
*/
|
|
|
|
#include <linux/cpu.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/hrtimer.h>
|
[S390] genirq/clockevents: move irq affinity prototypes/inlines to interrupt.h
> Generic code is not supposed to include irq.h. Replace this include
> by linux/hardirq.h instead and add/replace an include of linux/irq.h
> in asm header files where necessary.
> This change should only matter for architectures that make use of
> GENERIC_CLOCKEVENTS.
> Architectures in question are mips, x86, arm, sh, powerpc, uml and sparc64.
>
> I did some cross compile tests for mips, x86_64, arm, powerpc and sparc64.
> This patch fixes also build breakages caused by the include replacement in
> tick-common.h.
I generally dislike adding optional linux/* includes in asm/* includes -
I'm nervous about this causing include loops.
However, there's a separate point to be discussed here.
That is, what interfaces are expected of every architecture in the kernel.
If generic code wants to be able to set the affinity of interrupts, then
that needs to become part of the interfaces listed in linux/interrupt.h
rather than linux/irq.h.
So what I suggest is this approach instead (against Linus' tree of a
couple of days ago) - we move irq_set_affinity() and irq_can_set_affinity()
to linux/interrupt.h, change the linux/irq.h includes to linux/interrupt.h
and include asm/irq_regs.h where needed (asm/irq_regs.h is supposed to be
rarely used include since not much touches the stacked parent context
registers.)
Build tested on ARM PXA family kernels and ARM's Realview platform
kernels which both use genirq.
[ tglx@linutronix.de: add GENERIC_HARDIRQ dependencies ]
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
2008-04-17 05:46:24 +00:00
|
|
|
#include <linux/interrupt.h>
|
2007-02-16 09:28:03 +00:00
|
|
|
#include <linux/percpu.h>
|
|
|
|
#include <linux/profile.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
|
|
|
|
#include "tick-internal.h"
|
|
|
|
|
2008-09-03 21:37:03 +00:00
|
|
|
/**
|
2023-01-03 03:28:49 +00:00
|
|
|
* tick_program_event - program the CPU local timer device for the next event
|
2008-09-03 21:37:03 +00:00
|
|
|
*/
|
|
|
|
int tick_program_event(ktime_t expires, int force)
|
|
|
|
{
|
2010-12-08 15:22:55 +00:00
|
|
|
struct clock_event_device *dev = __this_cpu_read(tick_cpu_device.evtdev);
|
2008-09-03 21:37:03 +00:00
|
|
|
|
2016-12-25 10:38:40 +00:00
|
|
|
if (unlikely(expires == KTIME_MAX)) {
|
2015-04-03 03:34:05 +00:00
|
|
|
/*
|
|
|
|
* We don't need the clock event device any more, stop it.
|
|
|
|
*/
|
2015-06-02 12:08:46 +00:00
|
|
|
clockevents_switch_state(dev, CLOCK_EVT_STATE_ONESHOT_STOPPED);
|
2017-10-26 18:37:22 +00:00
|
|
|
dev->next_event = KTIME_MAX;
|
2015-04-03 03:34:05 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-05-21 08:03:46 +00:00
|
|
|
if (unlikely(clockevent_state_oneshot_stopped(dev))) {
|
2015-04-03 03:34:05 +00:00
|
|
|
/*
|
|
|
|
* We need the clock event again, configure it in ONESHOT mode
|
|
|
|
* before using it.
|
|
|
|
*/
|
2015-06-02 12:08:46 +00:00
|
|
|
clockevents_switch_state(dev, CLOCK_EVT_STATE_ONESHOT);
|
2015-04-03 03:34:05 +00:00
|
|
|
}
|
|
|
|
|
2011-08-23 13:29:42 +00:00
|
|
|
return clockevents_program_event(dev, expires, force);
|
2008-09-03 21:37:03 +00:00
|
|
|
}
|
|
|
|
|
2007-03-16 23:25:52 +00:00
|
|
|
/**
|
2021-03-22 21:39:03 +00:00
|
|
|
* tick_resume_oneshot - resume oneshot mode
|
2007-03-16 23:25:52 +00:00
|
|
|
*/
|
|
|
|
void tick_resume_oneshot(void)
|
|
|
|
{
|
2011-08-23 13:29:42 +00:00
|
|
|
struct clock_event_device *dev = __this_cpu_read(tick_cpu_device.evtdev);
|
2007-03-16 23:25:52 +00:00
|
|
|
|
2015-06-02 12:08:46 +00:00
|
|
|
clockevents_switch_state(dev, CLOCK_EVT_STATE_ONESHOT);
|
2011-08-23 13:29:42 +00:00
|
|
|
clockevents_program_event(dev, ktime_get(), true);
|
2007-03-16 23:25:52 +00:00
|
|
|
}
|
|
|
|
|
2007-02-16 09:28:03 +00:00
|
|
|
/**
|
|
|
|
* tick_setup_oneshot - setup the event device for oneshot mode (hres or nohz)
|
|
|
|
*/
|
|
|
|
void tick_setup_oneshot(struct clock_event_device *newdev,
|
|
|
|
void (*handler)(struct clock_event_device *),
|
|
|
|
ktime_t next_event)
|
|
|
|
{
|
|
|
|
newdev->event_handler = handler;
|
2015-06-02 12:08:46 +00:00
|
|
|
clockevents_switch_state(newdev, CLOCK_EVT_STATE_ONESHOT);
|
2011-08-23 13:29:42 +00:00
|
|
|
clockevents_program_event(newdev, next_event, true);
|
2007-02-16 09:28:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* tick_switch_to_oneshot - switch to oneshot mode
|
|
|
|
*/
|
|
|
|
int tick_switch_to_oneshot(void (*handler)(struct clock_event_device *))
|
|
|
|
{
|
2014-08-17 17:30:25 +00:00
|
|
|
struct tick_device *td = this_cpu_ptr(&tick_cpu_device);
|
2007-02-16 09:28:03 +00:00
|
|
|
struct clock_event_device *dev = td->evtdev;
|
|
|
|
|
|
|
|
if (!dev || !(dev->features & CLOCK_EVT_FEAT_ONESHOT) ||
|
2007-07-21 11:37:36 +00:00
|
|
|
!tick_device_is_functional(dev)) {
|
|
|
|
|
2018-04-05 15:26:58 +00:00
|
|
|
pr_info("Clockevents: could not switch to one-shot mode:");
|
2007-07-21 11:37:36 +00:00
|
|
|
if (!dev) {
|
2018-04-05 15:26:58 +00:00
|
|
|
pr_cont(" no tick device\n");
|
2007-07-21 11:37:36 +00:00
|
|
|
} else {
|
|
|
|
if (!tick_device_is_functional(dev))
|
2018-04-05 15:26:58 +00:00
|
|
|
pr_cont(" %s is not functional.\n", dev->name);
|
2007-07-21 11:37:36 +00:00
|
|
|
else
|
2018-04-05 15:26:58 +00:00
|
|
|
pr_cont(" %s does not support one-shot mode.\n",
|
|
|
|
dev->name);
|
2007-07-21 11:37:36 +00:00
|
|
|
}
|
2007-02-16 09:28:03 +00:00
|
|
|
return -EINVAL;
|
2007-07-21 11:37:36 +00:00
|
|
|
}
|
2007-02-16 09:28:03 +00:00
|
|
|
|
|
|
|
td->mode = TICKDEV_MODE_ONESHOT;
|
|
|
|
dev->event_handler = handler;
|
2015-06-02 12:08:46 +00:00
|
|
|
clockevents_switch_state(dev, CLOCK_EVT_STATE_ONESHOT);
|
2007-02-16 09:28:03 +00:00
|
|
|
tick_broadcast_switch_to_oneshot();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-06-12 09:29:27 +00:00
|
|
|
/**
|
2023-01-03 03:28:49 +00:00
|
|
|
* tick_oneshot_mode_active - check whether the system is in oneshot mode
|
2009-06-12 09:29:27 +00:00
|
|
|
*
|
|
|
|
* returns 1 when either nohz or highres are enabled. otherwise 0.
|
|
|
|
*/
|
|
|
|
int tick_oneshot_mode_active(void)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
local_irq_save(flags);
|
2010-12-08 15:22:55 +00:00
|
|
|
ret = __this_cpu_read(tick_cpu_device.mode) == TICKDEV_MODE_ONESHOT;
|
2009-06-12 09:29:27 +00:00
|
|
|
local_irq_restore(flags);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-02-16 09:28:03 +00:00
|
|
|
#ifdef CONFIG_HIGH_RES_TIMERS
|
|
|
|
/**
|
|
|
|
* tick_init_highres - switch to high resolution mode
|
|
|
|
*
|
|
|
|
* Called with interrupts disabled.
|
|
|
|
*/
|
|
|
|
int tick_init_highres(void)
|
|
|
|
{
|
|
|
|
return tick_switch_to_oneshot(hrtimer_interrupt);
|
|
|
|
}
|
|
|
|
#endif
|