Linux Audio

Check our new training course

Loading...
v3.15
  1/*
  2 * linux/kernel/time/tick-oneshot.c
  3 *
  4 * This file contains functions which manage high resolution tick
  5 * related events.
  6 *
  7 * Copyright(C) 2005-2006, Thomas Gleixner <tglx@linutronix.de>
  8 * Copyright(C) 2005-2007, Red Hat, Inc., Ingo Molnar
  9 * Copyright(C) 2006-2007, Timesys Corp., Thomas Gleixner
 10 *
 11 * This code is licenced under the GPL version 2. For details see
 12 * kernel-base/COPYING.
 13 */
 14#include <linux/cpu.h>
 15#include <linux/err.h>
 16#include <linux/hrtimer.h>
 17#include <linux/interrupt.h>
 18#include <linux/percpu.h>
 19#include <linux/profile.h>
 20#include <linux/sched.h>
 21
 22#include "tick-internal.h"
 23
 24/**
 25 * tick_program_event
 26 */
 27int tick_program_event(ktime_t expires, int force)
 28{
 29	struct clock_event_device *dev = __this_cpu_read(tick_cpu_device.evtdev);
 30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 31	return clockevents_program_event(dev, expires, force);
 32}
 33
 34/**
 35 * tick_resume_onshot - resume oneshot mode
 36 */
 37void tick_resume_oneshot(void)
 38{
 39	struct clock_event_device *dev = __this_cpu_read(tick_cpu_device.evtdev);
 40
 41	clockevents_set_mode(dev, CLOCK_EVT_MODE_ONESHOT);
 42	clockevents_program_event(dev, ktime_get(), true);
 43}
 44
 45/**
 46 * tick_setup_oneshot - setup the event device for oneshot mode (hres or nohz)
 47 */
 48void tick_setup_oneshot(struct clock_event_device *newdev,
 49			void (*handler)(struct clock_event_device *),
 50			ktime_t next_event)
 51{
 52	newdev->event_handler = handler;
 53	clockevents_set_mode(newdev, CLOCK_EVT_MODE_ONESHOT);
 54	clockevents_program_event(newdev, next_event, true);
 55}
 56
 57/**
 58 * tick_switch_to_oneshot - switch to oneshot mode
 59 */
 60int tick_switch_to_oneshot(void (*handler)(struct clock_event_device *))
 61{
 62	struct tick_device *td = &__get_cpu_var(tick_cpu_device);
 63	struct clock_event_device *dev = td->evtdev;
 64
 65	if (!dev || !(dev->features & CLOCK_EVT_FEAT_ONESHOT) ||
 66		    !tick_device_is_functional(dev)) {
 67
 68		printk(KERN_INFO "Clockevents: "
 69		       "could not switch to one-shot mode:");
 70		if (!dev) {
 71			printk(" no tick device\n");
 72		} else {
 73			if (!tick_device_is_functional(dev))
 74				printk(" %s is not functional.\n", dev->name);
 75			else
 76				printk(" %s does not support one-shot mode.\n",
 77				       dev->name);
 78		}
 79		return -EINVAL;
 80	}
 81
 82	td->mode = TICKDEV_MODE_ONESHOT;
 83	dev->event_handler = handler;
 84	clockevents_set_mode(dev, CLOCK_EVT_MODE_ONESHOT);
 85	tick_broadcast_switch_to_oneshot();
 86	return 0;
 87}
 88
 89/**
 90 * tick_check_oneshot_mode - check whether the system is in oneshot mode
 91 *
 92 * returns 1 when either nohz or highres are enabled. otherwise 0.
 93 */
 94int tick_oneshot_mode_active(void)
 95{
 96	unsigned long flags;
 97	int ret;
 98
 99	local_irq_save(flags);
100	ret = __this_cpu_read(tick_cpu_device.mode) == TICKDEV_MODE_ONESHOT;
101	local_irq_restore(flags);
102
103	return ret;
104}
105
106#ifdef CONFIG_HIGH_RES_TIMERS
107/**
108 * tick_init_highres - switch to high resolution mode
109 *
110 * Called with interrupts disabled.
111 */
112int tick_init_highres(void)
113{
114	return tick_switch_to_oneshot(hrtimer_interrupt);
115}
116#endif
v4.6
  1/*
  2 * linux/kernel/time/tick-oneshot.c
  3 *
  4 * This file contains functions which manage high resolution tick
  5 * related events.
  6 *
  7 * Copyright(C) 2005-2006, Thomas Gleixner <tglx@linutronix.de>
  8 * Copyright(C) 2005-2007, Red Hat, Inc., Ingo Molnar
  9 * Copyright(C) 2006-2007, Timesys Corp., Thomas Gleixner
 10 *
 11 * This code is licenced under the GPL version 2. For details see
 12 * kernel-base/COPYING.
 13 */
 14#include <linux/cpu.h>
 15#include <linux/err.h>
 16#include <linux/hrtimer.h>
 17#include <linux/interrupt.h>
 18#include <linux/percpu.h>
 19#include <linux/profile.h>
 20#include <linux/sched.h>
 21
 22#include "tick-internal.h"
 23
 24/**
 25 * tick_program_event
 26 */
 27int tick_program_event(ktime_t expires, int force)
 28{
 29	struct clock_event_device *dev = __this_cpu_read(tick_cpu_device.evtdev);
 30
 31	if (unlikely(expires.tv64 == KTIME_MAX)) {
 32		/*
 33		 * We don't need the clock event device any more, stop it.
 34		 */
 35		clockevents_switch_state(dev, CLOCK_EVT_STATE_ONESHOT_STOPPED);
 36		return 0;
 37	}
 38
 39	if (unlikely(clockevent_state_oneshot_stopped(dev))) {
 40		/*
 41		 * We need the clock event again, configure it in ONESHOT mode
 42		 * before using it.
 43		 */
 44		clockevents_switch_state(dev, CLOCK_EVT_STATE_ONESHOT);
 45	}
 46
 47	return clockevents_program_event(dev, expires, force);
 48}
 49
 50/**
 51 * tick_resume_onshot - resume oneshot mode
 52 */
 53void tick_resume_oneshot(void)
 54{
 55	struct clock_event_device *dev = __this_cpu_read(tick_cpu_device.evtdev);
 56
 57	clockevents_switch_state(dev, CLOCK_EVT_STATE_ONESHOT);
 58	clockevents_program_event(dev, ktime_get(), true);
 59}
 60
 61/**
 62 * tick_setup_oneshot - setup the event device for oneshot mode (hres or nohz)
 63 */
 64void tick_setup_oneshot(struct clock_event_device *newdev,
 65			void (*handler)(struct clock_event_device *),
 66			ktime_t next_event)
 67{
 68	newdev->event_handler = handler;
 69	clockevents_switch_state(newdev, CLOCK_EVT_STATE_ONESHOT);
 70	clockevents_program_event(newdev, next_event, true);
 71}
 72
 73/**
 74 * tick_switch_to_oneshot - switch to oneshot mode
 75 */
 76int tick_switch_to_oneshot(void (*handler)(struct clock_event_device *))
 77{
 78	struct tick_device *td = this_cpu_ptr(&tick_cpu_device);
 79	struct clock_event_device *dev = td->evtdev;
 80
 81	if (!dev || !(dev->features & CLOCK_EVT_FEAT_ONESHOT) ||
 82		    !tick_device_is_functional(dev)) {
 83
 84		printk(KERN_INFO "Clockevents: "
 85		       "could not switch to one-shot mode:");
 86		if (!dev) {
 87			printk(" no tick device\n");
 88		} else {
 89			if (!tick_device_is_functional(dev))
 90				printk(" %s is not functional.\n", dev->name);
 91			else
 92				printk(" %s does not support one-shot mode.\n",
 93				       dev->name);
 94		}
 95		return -EINVAL;
 96	}
 97
 98	td->mode = TICKDEV_MODE_ONESHOT;
 99	dev->event_handler = handler;
100	clockevents_switch_state(dev, CLOCK_EVT_STATE_ONESHOT);
101	tick_broadcast_switch_to_oneshot();
102	return 0;
103}
104
105/**
106 * tick_check_oneshot_mode - check whether the system is in oneshot mode
107 *
108 * returns 1 when either nohz or highres are enabled. otherwise 0.
109 */
110int tick_oneshot_mode_active(void)
111{
112	unsigned long flags;
113	int ret;
114
115	local_irq_save(flags);
116	ret = __this_cpu_read(tick_cpu_device.mode) == TICKDEV_MODE_ONESHOT;
117	local_irq_restore(flags);
118
119	return ret;
120}
121
122#ifdef CONFIG_HIGH_RES_TIMERS
123/**
124 * tick_init_highres - switch to high resolution mode
125 *
126 * Called with interrupts disabled.
127 */
128int tick_init_highres(void)
129{
130	return tick_switch_to_oneshot(hrtimer_interrupt);
131}
132#endif