Commit 161f7a71 authored by Linus Torvalds's avatar Linus Torvalds

Merge branch 'timers-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull timer changes for v3.4 from Ingo Molnar

* 'timers-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (32 commits)
  ntp: Fix integer overflow when setting time
  math: Introduce div64_long
  cs5535-clockevt: Allow the MFGPT IRQ to be shared
  cs5535-clockevt: Don't ignore MFGPT on SMP-capable kernels
  x86/time: Eliminate unused irq0_irqs counter
  clocksource: scx200_hrt: Fix the build
  x86/tsc: Reduce the TSC sync check time for core-siblings
  timer: Fix bad idle check on irq entry
  nohz: Remove ts->Einidle checks before restarting the tick
  nohz: Remove update_ts_time_stat from tick_nohz_start_idle
  clockevents: Leave the broadcast device in shutdown mode when not needed
  clocksource: Load the ACPI PM clocksource asynchronously
  clocksource: scx200_hrt: Convert scx200 to use clocksource_register_hz
  clocksource: Get rid of clocksource_calc_mult_shift()
  clocksource: dbx500: convert to clocksource_register_hz()
  clocksource: scx200_hrt:  use pr_<level> instead of printk
  time: Move common updates to a function
  time: Reorder so the hot data is together
  time: Remove most of xtime_lock usage in timekeeping.c
  ntp: Add ntp_lock to replace xtime_locking
  ...
parents 2ba68940 a078c6d0
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
typedef struct { typedef struct {
unsigned int __softirq_pending; unsigned int __softirq_pending;
unsigned int __nmi_count; /* arch dependent */ unsigned int __nmi_count; /* arch dependent */
unsigned int irq0_irqs;
#ifdef CONFIG_X86_LOCAL_APIC #ifdef CONFIG_X86_LOCAL_APIC
unsigned int apic_timer_irqs; /* arch dependent */ unsigned int apic_timer_irqs; /* arch dependent */
unsigned int irq_spurious_count; unsigned int irq_spurious_count;
......
...@@ -57,9 +57,6 @@ EXPORT_SYMBOL(profile_pc); ...@@ -57,9 +57,6 @@ EXPORT_SYMBOL(profile_pc);
*/ */
static irqreturn_t timer_interrupt(int irq, void *dev_id) static irqreturn_t timer_interrupt(int irq, void *dev_id)
{ {
/* Keep nmi watchdog up to date */
inc_irq_stat(irq0_irqs);
global_clock_event->event_handler(global_clock_event); global_clock_event->event_handler(global_clock_event);
/* MCA bus quirk: Acknowledge irq0 by setting bit 7 in port 0x61 */ /* MCA bus quirk: Acknowledge irq0 by setting bit 7 in port 0x61 */
......
...@@ -42,7 +42,7 @@ static __cpuinitdata int nr_warps; ...@@ -42,7 +42,7 @@ static __cpuinitdata int nr_warps;
/* /*
* TSC-warp measurement loop running on both CPUs: * TSC-warp measurement loop running on both CPUs:
*/ */
static __cpuinit void check_tsc_warp(void) static __cpuinit void check_tsc_warp(unsigned int timeout)
{ {
cycles_t start, now, prev, end; cycles_t start, now, prev, end;
int i; int i;
...@@ -51,9 +51,9 @@ static __cpuinit void check_tsc_warp(void) ...@@ -51,9 +51,9 @@ static __cpuinit void check_tsc_warp(void)
start = get_cycles(); start = get_cycles();
rdtsc_barrier(); rdtsc_barrier();
/* /*
* The measurement runs for 20 msecs: * The measurement runs for 'timeout' msecs:
*/ */
end = start + tsc_khz * 20ULL; end = start + (cycles_t) tsc_khz * timeout;
now = start; now = start;
for (i = 0; ; i++) { for (i = 0; ; i++) {
...@@ -98,6 +98,25 @@ static __cpuinit void check_tsc_warp(void) ...@@ -98,6 +98,25 @@ static __cpuinit void check_tsc_warp(void)
now-start, end-start); now-start, end-start);
} }
/*
* If the target CPU coming online doesn't have any of its core-siblings
* online, a timeout of 20msec will be used for the TSC-warp measurement
* loop. Otherwise a smaller timeout of 2msec will be used, as we have some
* information about this socket already (and this information grows as we
* have more and more logical-siblings in that socket).
*
* Ideally we should be able to skip the TSC sync check on the other
* core-siblings, if the first logical CPU in a socket passed the sync test.
* But as the TSC is per-logical CPU and can potentially be modified wrongly
* by the bios, TSC sync test for smaller duration should be able
* to catch such errors. Also this will catch the condition where all the
* cores in the socket doesn't get reset at the same time.
*/
static inline unsigned int loop_timeout(int cpu)
{
return (cpumask_weight(cpu_core_mask(cpu)) > 1) ? 2 : 20;
}
/* /*
* Source CPU calls into this - it waits for the freshly booted * Source CPU calls into this - it waits for the freshly booted
* target CPU to arrive and then starts the measurement: * target CPU to arrive and then starts the measurement:
...@@ -135,7 +154,7 @@ void __cpuinit check_tsc_sync_source(int cpu) ...@@ -135,7 +154,7 @@ void __cpuinit check_tsc_sync_source(int cpu)
*/ */
atomic_inc(&start_count); atomic_inc(&start_count);
check_tsc_warp(); check_tsc_warp(loop_timeout(cpu));
while (atomic_read(&stop_count) != cpus-1) while (atomic_read(&stop_count) != cpus-1)
cpu_relax(); cpu_relax();
...@@ -183,7 +202,7 @@ void __cpuinit check_tsc_sync_target(void) ...@@ -183,7 +202,7 @@ void __cpuinit check_tsc_sync_target(void)
while (atomic_read(&start_count) != cpus) while (atomic_read(&start_count) != cpus)
cpu_relax(); cpu_relax();
check_tsc_warp(); check_tsc_warp(loop_timeout(smp_processor_id()));
/* /*
* Ok, we are done: * Ok, we are done:
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/pci.h> #include <linux/pci.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/async.h>
#include <asm/io.h> #include <asm/io.h>
/* /*
...@@ -179,17 +180,15 @@ static int verify_pmtmr_rate(void) ...@@ -179,17 +180,15 @@ static int verify_pmtmr_rate(void)
/* Number of reads we try to get two different values */ /* Number of reads we try to get two different values */
#define ACPI_PM_READ_CHECKS 10000 #define ACPI_PM_READ_CHECKS 10000
static int __init init_acpi_pm_clocksource(void) static void __init acpi_pm_clocksource_async(void *unused, async_cookie_t cookie)
{ {
cycle_t value1, value2; cycle_t value1, value2;
unsigned int i, j = 0; unsigned int i, j = 0;
if (!pmtmr_ioport)
return -ENODEV;
/* "verify" this timing source: */ /* "verify" this timing source: */
for (j = 0; j < ACPI_PM_MONOTONICITY_CHECKS; j++) { for (j = 0; j < ACPI_PM_MONOTONICITY_CHECKS; j++) {
udelay(100 * j); usleep_range(100 * j, 100 * j + 100);
value1 = clocksource_acpi_pm.read(&clocksource_acpi_pm); value1 = clocksource_acpi_pm.read(&clocksource_acpi_pm);
for (i = 0; i < ACPI_PM_READ_CHECKS; i++) { for (i = 0; i < ACPI_PM_READ_CHECKS; i++) {
value2 = clocksource_acpi_pm.read(&clocksource_acpi_pm); value2 = clocksource_acpi_pm.read(&clocksource_acpi_pm);
...@@ -203,25 +202,34 @@ static int __init init_acpi_pm_clocksource(void) ...@@ -203,25 +202,34 @@ static int __init init_acpi_pm_clocksource(void)
" 0x%#llx, 0x%#llx - aborting.\n", " 0x%#llx, 0x%#llx - aborting.\n",
value1, value2); value1, value2);
pmtmr_ioport = 0; pmtmr_ioport = 0;
return -EINVAL; return;
} }
if (i == ACPI_PM_READ_CHECKS) { if (i == ACPI_PM_READ_CHECKS) {
printk(KERN_INFO "PM-Timer failed consistency check " printk(KERN_INFO "PM-Timer failed consistency check "
" (0x%#llx) - aborting.\n", value1); " (0x%#llx) - aborting.\n", value1);
pmtmr_ioport = 0; pmtmr_ioport = 0;
return -ENODEV; return;
} }
} }
if (verify_pmtmr_rate() != 0){ if (verify_pmtmr_rate() != 0){
pmtmr_ioport = 0; pmtmr_ioport = 0;
return -ENODEV; return;
} }
return clocksource_register_hz(&clocksource_acpi_pm, clocksource_register_hz(&clocksource_acpi_pm,
PMTMR_TICKS_PER_SEC); PMTMR_TICKS_PER_SEC);
} }
static int __init init_acpi_pm_clocksource(void)
{
if (!pmtmr_ioport)
return -ENODEV;
async_schedule(acpi_pm_clocksource_async, NULL);
return 0;
}
/* We use fs_initcall because we want the PCI fixups to have run /* We use fs_initcall because we want the PCI fixups to have run
* but we still need to load before device_initcall * but we still need to load before device_initcall
*/ */
......
...@@ -52,7 +52,6 @@ static struct clocksource clocksource_dbx500_prcmu = { ...@@ -52,7 +52,6 @@ static struct clocksource clocksource_dbx500_prcmu = {
.name = "dbx500-prcmu-timer", .name = "dbx500-prcmu-timer",
.rating = 300, .rating = 300,
.read = clksrc_dbx500_prcmu_read, .read = clksrc_dbx500_prcmu_read,
.shift = 10,
.mask = CLOCKSOURCE_MASK(32), .mask = CLOCKSOURCE_MASK(32),
.flags = CLOCK_SOURCE_IS_CONTINUOUS, .flags = CLOCK_SOURCE_IS_CONTINUOUS,
}; };
...@@ -90,7 +89,5 @@ void __init clksrc_dbx500_prcmu_init(void __iomem *base) ...@@ -90,7 +89,5 @@ void __init clksrc_dbx500_prcmu_init(void __iomem *base)
setup_sched_clock(dbx500_prcmu_sched_clock_read, setup_sched_clock(dbx500_prcmu_sched_clock_read,
32, RATE_32K); 32, RATE_32K);
#endif #endif
clocksource_calc_mult_shift(&clocksource_dbx500_prcmu, clocksource_register_hz(&clocksource_dbx500_prcmu, RATE_32K);
RATE_32K, SCHED_CLOCK_MIN_WRAP);
clocksource_register(&clocksource_dbx500_prcmu);
} }
...@@ -100,7 +100,6 @@ static struct clock_event_device cs5535_clockevent = { ...@@ -100,7 +100,6 @@ static struct clock_event_device cs5535_clockevent = {
.set_mode = mfgpt_set_mode, .set_mode = mfgpt_set_mode,
.set_next_event = mfgpt_next_event, .set_next_event = mfgpt_next_event,
.rating = 250, .rating = 250,
.cpumask = cpu_all_mask,
.shift = 32 .shift = 32
}; };
...@@ -133,7 +132,7 @@ static irqreturn_t mfgpt_tick(int irq, void *dev_id) ...@@ -133,7 +132,7 @@ static irqreturn_t mfgpt_tick(int irq, void *dev_id)
static struct irqaction mfgptirq = { static struct irqaction mfgptirq = {
.handler = mfgpt_tick, .handler = mfgpt_tick,
.flags = IRQF_DISABLED | IRQF_NOBALANCING | IRQF_TIMER, .flags = IRQF_DISABLED | IRQF_NOBALANCING | IRQF_TIMER | IRQF_SHARED,
.name = DRV_NAME, .name = DRV_NAME,
}; };
......
...@@ -55,11 +55,11 @@ static int __init init_cyclone_clocksource(void) ...@@ -55,11 +55,11 @@ static int __init init_cyclone_clocksource(void)
} }
/* even on 64bit systems, this is only 32bits: */ /* even on 64bit systems, this is only 32bits: */
base = readl(reg); base = readl(reg);
iounmap(reg);
if (!base) { if (!base) {
printk(KERN_ERR "Summit chipset: Could not find valid CBAR value.\n"); printk(KERN_ERR "Summit chipset: Could not find valid CBAR value.\n");
return -ENODEV; return -ENODEV;
} }
iounmap(reg);
/* setup PMCC: */ /* setup PMCC: */
offset = base + CYCLONE_PMCC_OFFSET; offset = base + CYCLONE_PMCC_OFFSET;
......
...@@ -49,9 +49,6 @@ static cycle_t read_hrt(struct clocksource *cs) ...@@ -49,9 +49,6 @@ static cycle_t read_hrt(struct clocksource *cs)
return (cycle_t) inl(scx200_cb_base + SCx200_TIMER_OFFSET); return (cycle_t) inl(scx200_cb_base + SCx200_TIMER_OFFSET);
} }
#define HRT_SHIFT_1 22
#define HRT_SHIFT_27 26
static struct clocksource cs_hrt = { static struct clocksource cs_hrt = {
.name = "scx200_hrt", .name = "scx200_hrt",
.rating = 250, .rating = 250,
...@@ -63,6 +60,7 @@ static struct clocksource cs_hrt = { ...@@ -63,6 +60,7 @@ static struct clocksource cs_hrt = {
static int __init init_hrt_clocksource(void) static int __init init_hrt_clocksource(void)
{ {
u32 freq;
/* Make sure scx200 has initialized the configuration block */ /* Make sure scx200 has initialized the configuration block */
if (!scx200_cb_present()) if (!scx200_cb_present())
return -ENODEV; return -ENODEV;
...@@ -71,7 +69,7 @@ static int __init init_hrt_clocksource(void) ...@@ -71,7 +69,7 @@ static int __init init_hrt_clocksource(void)
if (!request_region(scx200_cb_base + SCx200_TIMER_OFFSET, if (!request_region(scx200_cb_base + SCx200_TIMER_OFFSET,
SCx200_TIMER_SIZE, SCx200_TIMER_SIZE,
"NatSemi SCx200 High-Resolution Timer")) { "NatSemi SCx200 High-Resolution Timer")) {
printk(KERN_WARNING NAME ": unable to lock timer region\n"); pr_warn("unable to lock timer region\n");
return -ENODEV; return -ENODEV;
} }
...@@ -79,19 +77,13 @@ static int __init init_hrt_clocksource(void) ...@@ -79,19 +77,13 @@ static int __init init_hrt_clocksource(void)
outb(HR_TMEN | (mhz27 ? HR_TMCLKSEL : 0), outb(HR_TMEN | (mhz27 ? HR_TMCLKSEL : 0),
scx200_cb_base + SCx200_TMCNFG_OFFSET); scx200_cb_base + SCx200_TMCNFG_OFFSET);
if (mhz27) { freq = (HRT_FREQ + ppm);
cs_hrt.shift = HRT_SHIFT_27; if (mhz27)
cs_hrt.mult = clocksource_hz2mult((HRT_FREQ + ppm) * 27, freq *= 27;
cs_hrt.shift);
} else { pr_info("enabling scx200 high-res timer (%s MHz +%d ppm)\n", mhz27 ? "27":"1", ppm);
cs_hrt.shift = HRT_SHIFT_1;
cs_hrt.mult = clocksource_hz2mult(HRT_FREQ + ppm,
cs_hrt.shift);
}
printk(KERN_INFO "enabling scx200 high-res timer (%s MHz +%d ppm)\n",
mhz27 ? "27":"1", ppm);
return clocksource_register(&cs_hrt); return clocksource_register_hz(&cs_hrt, freq);
} }
module_init(init_hrt_clocksource); module_init(init_hrt_clocksource);
......
...@@ -73,6 +73,8 @@ int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm) ...@@ -73,6 +73,8 @@ int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm)
err = -EINVAL; err = -EINVAL;
mutex_unlock(&rtc->ops_lock); mutex_unlock(&rtc->ops_lock);
/* A timer might have just expired */
schedule_work(&rtc->irqwork);
return err; return err;
} }
EXPORT_SYMBOL_GPL(rtc_set_time); EXPORT_SYMBOL_GPL(rtc_set_time);
...@@ -112,6 +114,8 @@ int rtc_set_mmss(struct rtc_device *rtc, unsigned long secs) ...@@ -112,6 +114,8 @@ int rtc_set_mmss(struct rtc_device *rtc, unsigned long secs)
err = -EINVAL; err = -EINVAL;
mutex_unlock(&rtc->ops_lock); mutex_unlock(&rtc->ops_lock);
/* A timer might have just expired */
schedule_work(&rtc->irqwork);
return err; return err;
} }
...@@ -380,18 +384,27 @@ EXPORT_SYMBOL_GPL(rtc_set_alarm); ...@@ -380,18 +384,27 @@ EXPORT_SYMBOL_GPL(rtc_set_alarm);
int rtc_initialize_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) int rtc_initialize_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
{ {
int err; int err;
struct rtc_time now;
err = rtc_valid_tm(&alarm->time); err = rtc_valid_tm(&alarm->time);
if (err != 0) if (err != 0)
return err; return err;
err = rtc_read_time(rtc, &now);
if (err)
return err;
err = mutex_lock_interruptible(&rtc->ops_lock); err = mutex_lock_interruptible(&rtc->ops_lock);
if (err) if (err)
return err; return err;
rtc->aie_timer.node.expires = rtc_tm_to_ktime(alarm->time); rtc->aie_timer.node.expires = rtc_tm_to_ktime(alarm->time);
rtc->aie_timer.period = ktime_set(0, 0); rtc->aie_timer.period = ktime_set(0, 0);
if (alarm->enabled) {
/* Alarm has to be enabled & in the futrure for us to enqueue it */
if (alarm->enabled && (rtc_tm_to_ktime(now).tv64 <
rtc->aie_timer.node.expires.tv64)) {
rtc->aie_timer.enabled = 1; rtc->aie_timer.enabled = 1;
timerqueue_add(&rtc->timerqueue, &rtc->aie_timer.node); timerqueue_add(&rtc->timerqueue, &rtc->aie_timer.node);
} }
...@@ -763,6 +776,14 @@ static int rtc_timer_enqueue(struct rtc_device *rtc, struct rtc_timer *timer) ...@@ -763,6 +776,14 @@ static int rtc_timer_enqueue(struct rtc_device *rtc, struct rtc_timer *timer)
return 0; return 0;
} }
static void rtc_alarm_disable(struct rtc_device *rtc)
{
if (!rtc->ops || !rtc->ops->alarm_irq_enable)
return;
rtc->ops->alarm_irq_enable(rtc->dev.parent, false);
}
/** /**
* rtc_timer_remove - Removes a rtc_timer from the rtc_device timerqueue * rtc_timer_remove - Removes a rtc_timer from the rtc_device timerqueue
* @rtc rtc device * @rtc rtc device
...@@ -784,8 +805,10 @@ static void rtc_timer_remove(struct rtc_device *rtc, struct rtc_timer *timer) ...@@ -784,8 +805,10 @@ static void rtc_timer_remove(struct rtc_device *rtc, struct rtc_timer *timer)
struct rtc_wkalrm alarm; struct rtc_wkalrm alarm;
int err; int err;
next = timerqueue_getnext(&rtc->timerqueue); next = timerqueue_getnext(&rtc->timerqueue);
if (!next) if (!next) {
rtc_alarm_disable(rtc);
return; return;
}
alarm.time = rtc_ktime_to_tm(next->expires); alarm.time = rtc_ktime_to_tm(next->expires);
alarm.enabled = 1; alarm.enabled = 1;
err = __rtc_set_alarm(rtc, &alarm); err = __rtc_set_alarm(rtc, &alarm);
...@@ -847,7 +870,8 @@ void rtc_timer_do_work(struct work_struct *work) ...@@ -847,7 +870,8 @@ void rtc_timer_do_work(struct work_struct *work)
err = __rtc_set_alarm(rtc, &alarm); err = __rtc_set_alarm(rtc, &alarm);
if (err == -ETIME) if (err == -ETIME)
goto again; goto again;
} } else
rtc_alarm_disable(rtc);
mutex_unlock(&rtc->ops_lock); mutex_unlock(&rtc->ops_lock);
} }
......
...@@ -319,13 +319,6 @@ static inline void __clocksource_updatefreq_khz(struct clocksource *cs, u32 khz) ...@@ -319,13 +319,6 @@ static inline void __clocksource_updatefreq_khz(struct clocksource *cs, u32 khz)
__clocksource_updatefreq_scale(cs, 1000, khz); __clocksource_updatefreq_scale(cs, 1000, khz);
} }
static inline void
clocksource_calc_mult_shift(struct clocksource *cs, u32 freq, u32 minsec)
{
return clocks_calc_mult_shift(&cs->mult, &cs->shift, freq,
NSEC_PER_SEC, minsec);
}
#ifdef CONFIG_GENERIC_TIME_VSYSCALL #ifdef CONFIG_GENERIC_TIME_VSYSCALL
extern void extern void
update_vsyscall(struct timespec *ts, struct timespec *wtm, update_vsyscall(struct timespec *ts, struct timespec *wtm,
......
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
#if BITS_PER_LONG == 64 #if BITS_PER_LONG == 64
#define div64_long(x,y) div64_s64((x),(y))
/** /**
* div_u64_rem - unsigned 64bit divide with 32bit divisor with remainder * div_u64_rem - unsigned 64bit divide with 32bit divisor with remainder
* *
...@@ -45,6 +47,8 @@ static inline s64 div64_s64(s64 dividend, s64 divisor) ...@@ -45,6 +47,8 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
#elif BITS_PER_LONG == 32 #elif BITS_PER_LONG == 32
#define div64_long(x,y) div_s64((x),(y))
#ifndef div_u64_rem #ifndef div_u64_rem
static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder) static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
{ {
......
...@@ -234,23 +234,9 @@ struct timex { ...@@ -234,23 +234,9 @@ struct timex {
extern unsigned long tick_usec; /* USER_HZ period (usec) */ extern unsigned long tick_usec; /* USER_HZ period (usec) */
extern unsigned long tick_nsec; /* ACTHZ period (nsec) */ extern unsigned long tick_nsec; /* ACTHZ period (nsec) */
/*
* phase-lock loop variables
*/
extern int time_status; /* clock synchronization status bits */
extern void ntp_init(void); extern void ntp_init(void);
extern void ntp_clear(void); extern void ntp_clear(void);
/**
* ntp_synced - Returns 1 if the NTP status is not UNSYNC
*
*/
static inline int ntp_synced(void)
{
return !(time_status & STA_UNSYNC);
}
/* Required to safely shift negative values */ /* Required to safely shift negative values */
#define shift_right(x, s) ({ \ #define shift_right(x, s) ({ \
__typeof__(x) __x = (x); \ __typeof__(x) __x = (x); \
...@@ -264,10 +250,9 @@ static inline int ntp_synced(void) ...@@ -264,10 +250,9 @@ static inline int ntp_synced(void)
#define NTP_INTERVAL_LENGTH (NSEC_PER_SEC/NTP_INTERVAL_FREQ) #define NTP_INTERVAL_LENGTH (NSEC_PER_SEC/NTP_INTERVAL_FREQ)
/* Returns how long ticks are at present, in ns / 2^NTP_SCALE_SHIFT. */ /* Returns how long ticks are at present, in ns / 2^NTP_SCALE_SHIFT. */
extern u64 tick_length; extern u64 ntp_tick_length(void);
extern void second_overflow(void); extern void second_overflow(void);
extern void update_ntp_one_tick(void);
extern int do_adjtimex(struct timex *); extern int do_adjtimex(struct timex *);
extern void hardpps(const struct timespec *, const struct timespec *); extern void hardpps(const struct timespec *, const struct timespec *);
......
...@@ -297,7 +297,7 @@ void irq_enter(void) ...@@ -297,7 +297,7 @@ void irq_enter(void)
int cpu = smp_processor_id(); int cpu = smp_processor_id();
rcu_irq_enter(); rcu_irq_enter();
if (idle_cpu(cpu) && !in_interrupt()) { if (is_idle_task(current) && !in_interrupt()) {
/* /*
* Prevent raise_softirq from needlessly waking up ksoftirqd * Prevent raise_softirq from needlessly waking up ksoftirqd
* here, as softirq will be serviced on return from interrupt. * here, as softirq will be serviced on return from interrupt.
......
...@@ -22,13 +22,16 @@ ...@@ -22,13 +22,16 @@
* NTP timekeeping variables: * NTP timekeeping variables:
*/ */
DEFINE_SPINLOCK(ntp_lock);
/* USER_HZ period (usecs): */ /* USER_HZ period (usecs): */
unsigned long tick_usec = TICK_USEC; unsigned long tick_usec = TICK_USEC;
/* ACTHZ period (nsecs): */ /* ACTHZ period (nsecs): */
unsigned long tick_nsec; unsigned long tick_nsec;
u64 tick_length; static u64 tick_length;
static u64 tick_length_base; static u64 tick_length_base;
static struct hrtimer leap_timer; static struct hrtimer leap_timer;
...@@ -49,7 +52,7 @@ static struct hrtimer leap_timer; ...@@ -49,7 +52,7 @@ static struct hrtimer leap_timer;
static int time_state = TIME_OK; static int time_state = TIME_OK;
/* clock status bits: */ /* clock status bits: */
int time_status = STA_UNSYNC; static int time_status = STA_UNSYNC;
/* TAI offset (secs): */ /* TAI offset (secs): */
static long time_tai; static long time_tai;
...@@ -133,7 +136,7 @@ static inline void pps_reset_freq_interval(void) ...@@ -133,7 +136,7 @@ static inline void pps_reset_freq_interval(void)
/** /**
* pps_clear - Clears the PPS state variables * pps_clear - Clears the PPS state variables
* *
* Must be called while holding a write on the xtime_lock * Must be called while holding a write on the ntp_lock
*/ */
static inline void pps_clear(void) static inline void pps_clear(void)
{ {
...@@ -149,7 +152,7 @@ static inline void pps_clear(void) ...@@ -149,7 +152,7 @@ static inline void pps_clear(void)
* the last PPS signal. When it reaches 0, indicate that PPS signal is * the last PPS signal. When it reaches 0, indicate that PPS signal is
* missing. * missing.
* *
* Must be called while holding a write on the xtime_lock * Must be called while holding a write on the ntp_lock
*/ */
static inline void pps_dec_valid(void) static inline void pps_dec_valid(void)
{ {
...@@ -233,6 +236,17 @@ static inline void pps_fill_timex(struct timex *txc) ...@@ -233,6 +236,17 @@ static inline void pps_fill_timex(struct timex *txc)
#endif /* CONFIG_NTP_PPS */ #endif /* CONFIG_NTP_PPS */
/**
* ntp_synced - Returns 1 if the NTP status is not UNSYNC
*
*/
static inline int ntp_synced(void)
{
return !(time_status & STA_UNSYNC);
}
/* /*
* NTP methods: * NTP methods:
*/ */
...@@ -275,7 +289,7 @@ static inline s64 ntp_update_offset_fll(s64 offset64, long secs) ...@@ -275,7 +289,7 @@ static inline s64 ntp_update_offset_fll(s64 offset64, long secs)
time_status |= STA_MODE; time_status |= STA_MODE;
return div_s64(offset64 << (NTP_SCALE_SHIFT - SHIFT_FLL), secs); return div64_long(offset64 << (NTP_SCALE_SHIFT - SHIFT_FLL), secs);
} }
static void ntp_update_offset(long offset) static void ntp_update_offset(long offset)
...@@ -330,11 +344,13 @@ static void ntp_update_offset(long offset) ...@@ -330,11 +344,13 @@ static void ntp_update_offset(long offset)
/** /**
* ntp_clear - Clears the NTP state variables * ntp_clear - Clears the NTP state variables
*
* Must be called while holding a write on the xtime_lock
*/ */
void ntp_clear(void) void ntp_clear(void)
{ {
unsigned long flags;
spin_lock_irqsave(&ntp_lock, flags);
time_adjust = 0; /* stop active adjtime() */ time_adjust = 0; /* stop active adjtime() */
time_status |= STA_UNSYNC; time_status |= STA_UNSYNC;
time_maxerror = NTP_PHASE_LIMIT; time_maxerror = NTP_PHASE_LIMIT;
...@@ -347,8 +363,23 @@ void ntp_clear(void) ...@@ -347,8 +363,23 @@ void ntp_clear(void)
/* Clear PPS state variables */ /* Clear PPS state variables */
pps_clear(); pps_clear();
spin_unlock_irqrestore(&ntp_lock, flags);
} }
u64 ntp_tick_length(void)
{
unsigned long flags;
s64 ret;
spin_lock_irqsave(&ntp_lock, flags);
ret = tick_length;
spin_unlock_irqrestore(&ntp_lock, flags);
return ret;
}
/* /*
* Leap second processing. If in leap-insert state at the end of the * Leap second processing. If in leap-insert state at the end of the
* day, the system clock is set back one second; if in leap-delete * day, the system clock is set back one second; if in leap-delete
...@@ -357,14 +388,15 @@ void ntp_clear(void) ...@@ -357,14 +388,15 @@ void ntp_clear(void)
static enum hrtimer_restart ntp_leap_second(struct hrtimer *timer) static enum hrtimer_restart ntp_leap_second(struct hrtimer *timer)
{ {
enum hrtimer_restart res = HRTIMER_NORESTART; enum hrtimer_restart res = HRTIMER_NORESTART;
unsigned long flags;
int leap = 0;
write_seqlock(&xtime_lock); spin_lock_irqsave(&ntp_lock, flags);
switch (time_state) { switch (time_state) {
case TIME_OK: case TIME_OK:
break; break;
case TIME_INS: case TIME_INS:
timekeeping_leap_insert(-1); leap = -1;
time_state = TIME_OOP; time_state = TIME_OOP;
printk(KERN_NOTICE printk(KERN_NOTICE
"Clock: inserting leap second 23:59:60 UTC\n"); "Clock: inserting leap second 23:59:60 UTC\n");
...@@ -372,7 +404,7 @@ static enum hrtimer_restart ntp_leap_second(struct hrtimer *timer) ...@@ -372,7 +404,7 @@ static enum hrtimer_restart ntp_leap_second(struct hrtimer *timer)
res = HRTIMER_RESTART; res = HRTIMER_RESTART;
break; break;
case TIME_DEL: case TIME_DEL:
timekeeping_leap_insert(1); leap = 1;
time_tai--; time_tai--;
time_state = TIME_WAIT; time_state = TIME_WAIT;
printk(KERN_NOTICE printk(KERN_NOTICE
...@@ -387,8 +419,14 @@ static enum hrtimer_restart ntp_leap_second(struct hrtimer *timer) ...@@ -387,8 +419,14 @@ static enum hrtimer_restart ntp_leap_second(struct hrtimer *timer)
time_state = TIME_OK; time_state = TIME_OK;
break; break;
} }
spin_unlock_irqrestore(&ntp_lock, flags);
write_sequnlock(&xtime_lock); /*
* We have to call this outside of the ntp_lock to keep
* the proper locking hierarchy
*/
if (leap)
timekeeping_leap_insert(leap);
return res; return res;
} }
...@@ -404,6 +442,9 @@ static enum hrtimer_restart ntp_leap_second(struct hrtimer *timer) ...@@ -404,6 +442,9 @@ static enum hrtimer_restart ntp_leap_second(struct hrtimer *timer)
void second_overflow(void) void second_overflow(void)
{ {
s64 delta; s64 delta;
unsigned long flags;
spin_lock_irqsave(&ntp_lock, flags);
/* Bump the maxerror field */ /* Bump the maxerror field */
time_maxerror += MAXFREQ / NSEC_PER_USEC; time_maxerror += MAXFREQ / NSEC_PER_USEC;
...@@ -423,23 +464,25 @@ void second_overflow(void) ...@@ -423,23 +464,25 @@ void second_overflow(void)
pps_dec_valid(); pps_dec_valid();
if (!time_adjust) if (!time_adjust)
return; goto out;
if (time_adjust > MAX_TICKADJ) { if (time_adjust > MAX_TICKADJ) {
time_adjust -= MAX_TICKADJ; time_adjust -= MAX_TICKADJ;
tick_length += MAX_TICKADJ_SCALED; tick_length += MAX_TICKADJ_SCALED;
return; goto out;
} }
if (time_adjust < -MAX_TICKADJ) { if (time_adjust < -MAX_TICKADJ) {
time_adjust += MAX_TICKADJ; time_adjust += MAX_TICKADJ;
tick_length -= MAX_TICKADJ_SCALED; tick_length -= MAX_TICKADJ_SCALED;
return; goto out;
} }
tick_length += (s64)(time_adjust * NSEC_PER_USEC / NTP_INTERVAL_FREQ) tick_length += (s64)(time_adjust * NSEC_PER_USEC / NTP_INTERVAL_FREQ)
<< NTP_SCALE_SHIFT; << NTP_SCALE_SHIFT;
time_adjust = 0; time_adjust = 0;
out:
spin_unlock_irqrestore(&ntp_lock, flags);
} }
#ifdef CONFIG_GENERIC_CMOS_UPDATE #ifdef CONFIG_GENERIC_CMOS_UPDATE
...@@ -663,7 +706,7 @@ int do_adjtimex(struct timex *txc) ...@@ -663,7 +706,7 @@ int do_adjtimex(struct timex *txc)
getnstimeofday(&ts); getnstimeofday(&ts);
write_seqlock_irq(&xtime_lock); spin_lock_irq(&ntp_lock);
if (txc->modes & ADJ_ADJTIME) { if (txc->modes & ADJ_ADJTIME) {
long save_adjust = time_adjust; long save_adjust = time_adjust;
...@@ -705,7 +748,7 @@ int do_adjtimex(struct timex *txc) ...@@ -705,7 +748,7 @@ int do_adjtimex(struct timex *txc)
/* fill PPS status fields */ /* fill PPS status fields */
pps_fill_timex(txc); pps_fill_timex(txc);
write_sequnlock_irq(&xtime_lock); spin_unlock_irq(&ntp_lock);
txc->time.tv_sec = ts.tv_sec; txc->time.tv_sec = ts.tv_sec;
txc->time.tv_usec = ts.tv_nsec; txc->time.tv_usec = ts.tv_nsec;
...@@ -903,7 +946,7 @@ void hardpps(const struct timespec *phase_ts, const struct timespec *raw_ts) ...@@ -903,7 +946,7 @@ void hardpps(const struct timespec *phase_ts, const struct timespec *raw_ts)
pts_norm = pps_normalize_ts(*phase_ts); pts_norm = pps_normalize_ts(*phase_ts);
write_seqlock_irqsave(&xtime_lock, flags); spin_lock_irqsave(&ntp_lock, flags);
/* clear the error bits, they will be set again if needed */ /* clear the error bits, they will be set again if needed */
time_status &= ~(STA_PPSJITTER | STA_PPSWANDER | STA_PPSERROR); time_status &= ~(STA_PPSJITTER | STA_PPSWANDER | STA_PPSERROR);
...@@ -916,7 +959,7 @@ void hardpps(const struct timespec *phase_ts, const struct timespec *raw_ts) ...@@ -916,7 +959,7 @@ void hardpps(const struct timespec *phase_ts, const struct timespec *raw_ts)
* just start the frequency interval */ * just start the frequency interval */
if (unlikely(pps_fbase.tv_sec == 0)) { if (unlikely(pps_fbase.tv_sec == 0)) {
pps_fbase = *raw_ts; pps_fbase = *raw_ts;
write_sequnlock_irqrestore(&xtime_lock, flags); spin_unlock_irqrestore(&ntp_lock, flags);
return; return;
} }
...@@ -931,7 +974,7 @@ void hardpps(const struct timespec *phase_ts, const struct timespec *raw_ts) ...@@ -931,7 +974,7 @@ void hardpps(const struct timespec *phase_ts, const struct timespec *raw_ts)
time_status |= STA_PPSJITTER; time_status |= STA_PPSJITTER;
/* restart the frequency calibration interval */ /* restart the frequency calibration interval */
pps_fbase = *raw_ts; pps_fbase = *raw_ts;
write_sequnlock_irqrestore(&xtime_lock, flags); spin_unlock_irqrestore(&ntp_lock, flags);
pr_err("hardpps: PPSJITTER: bad pulse\n"); pr_err("hardpps: PPSJITTER: bad pulse\n");
return; return;
} }
...@@ -948,7 +991,7 @@ void hardpps(const struct timespec *phase_ts, const struct timespec *raw_ts) ...@@ -948,7 +991,7 @@ void hardpps(const struct timespec *phase_ts, const struct timespec *raw_ts)
hardpps_update_phase(pts_norm.nsec); hardpps_update_phase(pts_norm.nsec);
write_sequnlock_irqrestore(&xtime_lock, flags); spin_unlock_irqrestore(&ntp_lock, flags);
} }
EXPORT_SYMBOL(hardpps); EXPORT_SYMBOL(hardpps);
......
...@@ -575,11 +575,15 @@ void tick_broadcast_switch_to_oneshot(void) ...@@ -575,11 +575,15 @@ void tick_broadcast_switch_to_oneshot(void)
unsigned long flags; unsigned long flags;
raw_spin_lock_irqsave(&tick_broadcast_lock, flags); raw_spin_lock_irqsave(&tick_broadcast_lock, flags);
if (cpumask_empty(tick_get_broadcast_mask()))
goto end;
tick_broadcast_device.mode = TICKDEV_MODE_ONESHOT; tick_broadcast_device.mode = TICKDEV_MODE_ONESHOT;
bc = tick_broadcast_device.evtdev; bc = tick_broadcast_device.evtdev;
if (bc) if (bc)
tick_broadcast_setup_oneshot(bc); tick_broadcast_setup_oneshot(bc);
end:
raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags); raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags);
} }
......
...@@ -182,11 +182,7 @@ static void tick_nohz_stop_idle(int cpu, ktime_t now) ...@@ -182,11 +182,7 @@ static void tick_nohz_stop_idle(int cpu, ktime_t now)
static ktime_t tick_nohz_start_idle(int cpu, struct tick_sched *ts) static ktime_t tick_nohz_start_idle(int cpu, struct tick_sched *ts)
{ {
ktime_t now; ktime_t now = ktime_get();
now = ktime_get();
update_ts_time_stats(cpu, ts, now, NULL);
ts->idle_entrytime = now; ts->idle_entrytime = now;
ts->idle_active = 1; ts->idle_active = 1;
...@@ -562,20 +558,21 @@ void tick_nohz_idle_exit(void) ...@@ -562,20 +558,21 @@ void tick_nohz_idle_exit(void)
local_irq_disable(); local_irq_disable();
if (ts->idle_active || (ts->inidle && ts->tick_stopped)) WARN_ON_ONCE(!ts->inidle);
ts->inidle = 0;
if (ts->idle_active || ts->tick_stopped)
now = ktime_get(); now = ktime_get();
if (ts->idle_active) if (ts->idle_active)
tick_nohz_stop_idle(cpu, now); tick_nohz_stop_idle(cpu, now);
if (!ts->inidle || !ts->tick_stopped) { if (!ts->tick_stopped) {
ts->inidle = 0;
local_irq_enable(); local_irq_enable();
return; return;
} }
ts->inidle = 0;
/* Update jiffies first */ /* Update jiffies first */
select_nohz_load_balancer(0); select_nohz_load_balancer(0);
tick_do_update_jiffies64(now); tick_do_update_jiffies64(now);
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment