Commit 1e45e9a9 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 updates from Thomas Gleixner:
 "The timers departement more or less proudly presents:

   - More Y2038 timekeeping work mostly in the core code. The work is
     slowly, but steadily targeting the actuall syscalls.

   - Enhanced timekeeping suspend/resume support by utilizing
     clocksources which do not stop during suspend, but are otherwise
     not the main timekeeping clocksources.

   - Make NTP adjustmets more accurate and immediate when the frequency
     is set directly and not incrementally.

   - Sanitize the overrung handing of posix timers

   - A new timer driver for Mediatek SoCs

   - The usual pile of fixes and updates all over the place"

* 'timers-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (32 commits)
  clockevents: Warn if cpu_all_mask is used as cpumask
  tick/broadcast-hrtimer: Use cpu_possible_mask for ce_broadcast_hrtimer
  clocksource/drivers/arm_arch_timer: Fix bogus cpu_all_mask usage
  clocksource: ti-32k: Remove CLOCK_SOURCE_SUSPEND_NONSTOP flag
  timers: Clear timer_base::must_forward_clk with timer_base::lock held
  clocksource/drivers/sprd: Register one always-on timer to compensate suspend time
  clocksource/drivers/timer-mediatek: Add support for system timer
  clocksource/drivers/timer-mediatek: Convert the driver to timer-of
  clocksource/drivers/timer-mediatek: Use specific prefix for GPT
  clocksource/drivers/timer-mediatek: Rename mtk_timer to timer-mediatek
  clocksource/drivers/timer-mediatek: Add system timer bindings
  clocksource/drivers: Set clockevent device cpumask to cpu_possible_mask
  time: Introduce one suspend clocksource to compensate the suspend time
  time: Fix extra sleeptime injection when suspend fails
  timekeeping/ntp: Constify some function arguments
  ntp: Use kstrtos64 for s64 variable
  ntp: Remove redundant arguments
  timer: Fix coding style
  ktime: Provide typesafe ktime_to_ns()
  hrtimer: Improve kernel message printing
  ...
parents 8603596a fbfa9260
Mediatek MT6577, MT6572 and MT6589 Timers Mediatek Timers
--------------------------------------- ---------------
Mediatek SoCs have two different timers on different platforms,
- GPT (General Purpose Timer)
- SYST (System Timer)
The proper timer will be selected automatically by driver.
Required properties: Required properties:
- compatible should contain: - compatible should contain:
* "mediatek,mt2701-timer" for MT2701 compatible timers * "mediatek,mt2701-timer" for MT2701 compatible timers (GPT)
* "mediatek,mt6580-timer" for MT6580 compatible timers * "mediatek,mt6580-timer" for MT6580 compatible timers (GPT)
* "mediatek,mt6589-timer" for MT6589 compatible timers * "mediatek,mt6589-timer" for MT6589 compatible timers (GPT)
* "mediatek,mt7623-timer" for MT7623 compatible timers * "mediatek,mt7623-timer" for MT7623 compatible timers (GPT)
* "mediatek,mt8127-timer" for MT8127 compatible timers * "mediatek,mt8127-timer" for MT8127 compatible timers (GPT)
* "mediatek,mt8135-timer" for MT8135 compatible timers * "mediatek,mt8135-timer" for MT8135 compatible timers (GPT)
* "mediatek,mt8173-timer" for MT8173 compatible timers * "mediatek,mt8173-timer" for MT8173 compatible timers (GPT)
* "mediatek,mt6577-timer" for MT6577 and all above compatible timers * "mediatek,mt6577-timer" for MT6577 and all above compatible timers (GPT)
- reg: Should contain location and length for timers register. * "mediatek,mt6765-timer" for MT6765 compatible timers (SYST)
- clocks: Clocks driving the timer hardware. This list should include two - reg: Should contain location and length for timer register.
clocks. The order is system clock and as second clock the RTC clock. - clocks: Should contain system clock.
Examples: Examples:
...@@ -21,5 +27,5 @@ Examples: ...@@ -21,5 +27,5 @@ Examples:
compatible = "mediatek,mt6577-timer"; compatible = "mediatek,mt6577-timer";
reg = <0x10008000 0x80>; reg = <0x10008000 0x80>;
interrupts = <GIC_SPI 113 IRQ_TYPE_LEVEL_LOW>; interrupts = <GIC_SPI 113 IRQ_TYPE_LEVEL_LOW>;
clocks = <&system_clk>, <&rtc_clk>; clocks = <&system_clk>;
}; };
...@@ -49,7 +49,7 @@ obj-$(CONFIG_CLKSRC_SAMSUNG_PWM) += samsung_pwm_timer.o ...@@ -49,7 +49,7 @@ obj-$(CONFIG_CLKSRC_SAMSUNG_PWM) += samsung_pwm_timer.o
obj-$(CONFIG_FSL_FTM_TIMER) += fsl_ftm_timer.o obj-$(CONFIG_FSL_FTM_TIMER) += fsl_ftm_timer.o
obj-$(CONFIG_VF_PIT_TIMER) += vf_pit_timer.o obj-$(CONFIG_VF_PIT_TIMER) += vf_pit_timer.o
obj-$(CONFIG_CLKSRC_QCOM) += qcom-timer.o obj-$(CONFIG_CLKSRC_QCOM) += qcom-timer.o
obj-$(CONFIG_MTK_TIMER) += mtk_timer.o obj-$(CONFIG_MTK_TIMER) += timer-mediatek.o
obj-$(CONFIG_CLKSRC_PISTACHIO) += time-pistachio.o obj-$(CONFIG_CLKSRC_PISTACHIO) += time-pistachio.o
obj-$(CONFIG_CLKSRC_TI_32K) += timer-ti-32k.o obj-$(CONFIG_CLKSRC_TI_32K) += timer-ti-32k.o
obj-$(CONFIG_CLKSRC_NPS) += timer-nps.o obj-$(CONFIG_CLKSRC_NPS) += timer-nps.o
......
/*
* Mediatek SoCs General-Purpose Timer handling.
*
* Copyright (C) 2014 Matthias Brugger
*
* Matthias Brugger <matthias.bgg@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/clk.h>
#include <linux/clockchips.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/irqreturn.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include <linux/of_irq.h>
#include <linux/sched_clock.h>
#include <linux/slab.h>
#define GPT_IRQ_EN_REG 0x00
#define GPT_IRQ_ENABLE(val) BIT((val) - 1)
#define GPT_IRQ_ACK_REG 0x08
#define GPT_IRQ_ACK(val) BIT((val) - 1)
#define TIMER_CTRL_REG(val) (0x10 * (val))
#define TIMER_CTRL_OP(val) (((val) & 0x3) << 4)
#define TIMER_CTRL_OP_ONESHOT (0)
#define TIMER_CTRL_OP_REPEAT (1)
#define TIMER_CTRL_OP_FREERUN (3)
#define TIMER_CTRL_CLEAR (2)
#define TIMER_CTRL_ENABLE (1)
#define TIMER_CTRL_DISABLE (0)
#define TIMER_CLK_REG(val) (0x04 + (0x10 * (val)))
#define TIMER_CLK_SRC(val) (((val) & 0x1) << 4)
#define TIMER_CLK_SRC_SYS13M (0)
#define TIMER_CLK_SRC_RTC32K (1)
#define TIMER_CLK_DIV1 (0x0)
#define TIMER_CLK_DIV2 (0x1)
#define TIMER_CNT_REG(val) (0x08 + (0x10 * (val)))
#define TIMER_CMP_REG(val) (0x0C + (0x10 * (val)))
#define GPT_CLK_EVT 1
#define GPT_CLK_SRC 2
struct mtk_clock_event_device {
void __iomem *gpt_base;
u32 ticks_per_jiffy;
struct clock_event_device dev;
};
static void __iomem *gpt_sched_reg __read_mostly;
static u64 notrace mtk_read_sched_clock(void)
{
return readl_relaxed(gpt_sched_reg);
}
static inline struct mtk_clock_event_device *to_mtk_clk(
struct clock_event_device *c)
{
return container_of(c, struct mtk_clock_event_device, dev);
}
static void mtk_clkevt_time_stop(struct mtk_clock_event_device *evt, u8 timer)
{
u32 val;
val = readl(evt->gpt_base + TIMER_CTRL_REG(timer));
writel(val & ~TIMER_CTRL_ENABLE, evt->gpt_base +
TIMER_CTRL_REG(timer));
}
static void mtk_clkevt_time_setup(struct mtk_clock_event_device *evt,
unsigned long delay, u8 timer)
{
writel(delay, evt->gpt_base + TIMER_CMP_REG(timer));
}
static void mtk_clkevt_time_start(struct mtk_clock_event_device *evt,
bool periodic, u8 timer)
{
u32 val;
/* Acknowledge interrupt */
writel(GPT_IRQ_ACK(timer), evt->gpt_base + GPT_IRQ_ACK_REG);
val = readl(evt->gpt_base + TIMER_CTRL_REG(timer));
/* Clear 2 bit timer operation mode field */
val &= ~TIMER_CTRL_OP(0x3);
if (periodic)
val |= TIMER_CTRL_OP(TIMER_CTRL_OP_REPEAT);
else
val |= TIMER_CTRL_OP(TIMER_CTRL_OP_ONESHOT);
writel(val | TIMER_CTRL_ENABLE | TIMER_CTRL_CLEAR,
evt->gpt_base + TIMER_CTRL_REG(timer));
}
static int mtk_clkevt_shutdown(struct clock_event_device *clk)
{
mtk_clkevt_time_stop(to_mtk_clk(clk), GPT_CLK_EVT);
return 0;
}
static int mtk_clkevt_set_periodic(struct clock_event_device *clk)
{
struct mtk_clock_event_device *evt = to_mtk_clk(clk);
mtk_clkevt_time_stop(evt, GPT_CLK_EVT);
mtk_clkevt_time_setup(evt, evt->ticks_per_jiffy, GPT_CLK_EVT);
mtk_clkevt_time_start(evt, true, GPT_CLK_EVT);
return 0;
}
static int mtk_clkevt_next_event(unsigned long event,
struct clock_event_device *clk)
{
struct mtk_clock_event_device *evt = to_mtk_clk(clk);
mtk_clkevt_time_stop(evt, GPT_CLK_EVT);
mtk_clkevt_time_setup(evt, event, GPT_CLK_EVT);
mtk_clkevt_time_start(evt, false, GPT_CLK_EVT);
return 0;
}
static irqreturn_t mtk_timer_interrupt(int irq, void *dev_id)
{
struct mtk_clock_event_device *evt = dev_id;
/* Acknowledge timer0 irq */
writel(GPT_IRQ_ACK(GPT_CLK_EVT), evt->gpt_base + GPT_IRQ_ACK_REG);
evt->dev.event_handler(&evt->dev);
return IRQ_HANDLED;
}
static void
__init mtk_timer_setup(struct mtk_clock_event_device *evt, u8 timer, u8 option)
{
writel(TIMER_CTRL_CLEAR | TIMER_CTRL_DISABLE,
evt->gpt_base + TIMER_CTRL_REG(timer));
writel(TIMER_CLK_SRC(TIMER_CLK_SRC_SYS13M) | TIMER_CLK_DIV1,
evt->gpt_base + TIMER_CLK_REG(timer));
writel(0x0, evt->gpt_base + TIMER_CMP_REG(timer));
writel(TIMER_CTRL_OP(option) | TIMER_CTRL_ENABLE,
evt->gpt_base + TIMER_CTRL_REG(timer));
}
static void mtk_timer_enable_irq(struct mtk_clock_event_device *evt, u8 timer)
{
u32 val;
/* Disable all interrupts */
writel(0x0, evt->gpt_base + GPT_IRQ_EN_REG);
/* Acknowledge all spurious pending interrupts */
writel(0x3f, evt->gpt_base + GPT_IRQ_ACK_REG);
val = readl(evt->gpt_base + GPT_IRQ_EN_REG);
writel(val | GPT_IRQ_ENABLE(timer),
evt->gpt_base + GPT_IRQ_EN_REG);
}
static int __init mtk_timer_init(struct device_node *node)
{
struct mtk_clock_event_device *evt;
struct resource res;
unsigned long rate = 0;
struct clk *clk;
evt = kzalloc(sizeof(*evt), GFP_KERNEL);
if (!evt)
return -ENOMEM;
evt->dev.name = "mtk_tick";
evt->dev.rating = 300;
evt->dev.features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT;
evt->dev.set_state_shutdown = mtk_clkevt_shutdown;
evt->dev.set_state_periodic = mtk_clkevt_set_periodic;
evt->dev.set_state_oneshot = mtk_clkevt_shutdown;
evt->dev.tick_resume = mtk_clkevt_shutdown;
evt->dev.set_next_event = mtk_clkevt_next_event;
evt->dev.cpumask = cpu_possible_mask;
evt->gpt_base = of_io_request_and_map(node, 0, "mtk-timer");
if (IS_ERR(evt->gpt_base)) {
pr_err("Can't get resource\n");
goto err_kzalloc;
}
evt->dev.irq = irq_of_parse_and_map(node, 0);
if (evt->dev.irq <= 0) {
pr_err("Can't parse IRQ\n");
goto err_mem;
}
clk = of_clk_get(node, 0);
if (IS_ERR(clk)) {
pr_err("Can't get timer clock\n");
goto err_irq;
}
if (clk_prepare_enable(clk)) {
pr_err("Can't prepare clock\n");
goto err_clk_put;
}
rate = clk_get_rate(clk);
if (request_irq(evt->dev.irq, mtk_timer_interrupt,
IRQF_TIMER | IRQF_IRQPOLL, "mtk_timer", evt)) {
pr_err("failed to setup irq %d\n", evt->dev.irq);
goto err_clk_disable;
}
evt->ticks_per_jiffy = DIV_ROUND_UP(rate, HZ);
/* Configure clock source */
mtk_timer_setup(evt, GPT_CLK_SRC, TIMER_CTRL_OP_FREERUN);
clocksource_mmio_init(evt->gpt_base + TIMER_CNT_REG(GPT_CLK_SRC),
node->name, rate, 300, 32, clocksource_mmio_readl_up);
gpt_sched_reg = evt->gpt_base + TIMER_CNT_REG(GPT_CLK_SRC);
sched_clock_register(mtk_read_sched_clock, 32, rate);
/* Configure clock event */
mtk_timer_setup(evt, GPT_CLK_EVT, TIMER_CTRL_OP_REPEAT);
clockevents_config_and_register(&evt->dev, rate, 0x3,
0xffffffff);
mtk_timer_enable_irq(evt, GPT_CLK_EVT);
return 0;
err_clk_disable:
clk_disable_unprepare(clk);
err_clk_put:
clk_put(clk);
err_irq:
irq_dispose_mapping(evt->dev.irq);
err_mem:
iounmap(evt->gpt_base);
of_address_to_resource(node, 0, &res);
release_mem_region(res.start, resource_size(&res));
err_kzalloc:
kfree(evt);
return -EINVAL;
}
TIMER_OF_DECLARE(mtk_mt6577, "mediatek,mt6577-timer", mtk_timer_init);
...@@ -230,7 +230,7 @@ static int __init tegra20_init_timer(struct device_node *np) ...@@ -230,7 +230,7 @@ static int __init tegra20_init_timer(struct device_node *np)
return ret; return ret;
} }
tegra_clockevent.cpumask = cpu_all_mask; tegra_clockevent.cpumask = cpu_possible_mask;
tegra_clockevent.irq = tegra_timer_irq.irq; tegra_clockevent.irq = tegra_timer_irq.irq;
clockevents_config_and_register(&tegra_clockevent, 1000000, clockevents_config_and_register(&tegra_clockevent, 1000000,
0x1, 0x1fffffff); 0x1, 0x1fffffff);
......
...@@ -185,7 +185,7 @@ static struct timer_of to = { ...@@ -185,7 +185,7 @@ static struct timer_of to = {
.set_state_oneshot = atcpit100_clkevt_set_oneshot, .set_state_oneshot = atcpit100_clkevt_set_oneshot,
.tick_resume = atcpit100_clkevt_shutdown, .tick_resume = atcpit100_clkevt_shutdown,
.set_next_event = atcpit100_clkevt_next_event, .set_next_event = atcpit100_clkevt_next_event,
.cpumask = cpu_all_mask, .cpumask = cpu_possible_mask,
}, },
.of_irq = { .of_irq = {
......
...@@ -211,7 +211,7 @@ static int __init keystone_timer_init(struct device_node *np) ...@@ -211,7 +211,7 @@ static int __init keystone_timer_init(struct device_node *np)
event_dev->set_state_shutdown = keystone_shutdown; event_dev->set_state_shutdown = keystone_shutdown;
event_dev->set_state_periodic = keystone_set_periodic; event_dev->set_state_periodic = keystone_set_periodic;
event_dev->set_state_oneshot = keystone_shutdown; event_dev->set_state_oneshot = keystone_shutdown;
event_dev->cpumask = cpu_all_mask; event_dev->cpumask = cpu_possible_mask;
event_dev->owner = THIS_MODULE; event_dev->owner = THIS_MODULE;
event_dev->name = TIMER_NAME; event_dev->name = TIMER_NAME;
event_dev->irq = irq; event_dev->irq = irq;
......
/*
* Mediatek SoCs General-Purpose Timer handling.
*
* Copyright (C) 2014 Matthias Brugger
*
* Matthias Brugger <matthias.bgg@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/clockchips.h>
#include <linux/clocksource.h>
#include <linux/interrupt.h>
#include <linux/irqreturn.h>
#include <linux/sched_clock.h>
#include <linux/slab.h>
#include "timer-of.h"
#define TIMER_CLK_EVT (1)
#define TIMER_CLK_SRC (2)
#define TIMER_SYNC_TICKS (3)
/* gpt */
#define GPT_IRQ_EN_REG 0x00
#define GPT_IRQ_ENABLE(val) BIT((val) - 1)
#define GPT_IRQ_ACK_REG 0x08
#define GPT_IRQ_ACK(val) BIT((val) - 1)
#define GPT_CTRL_REG(val) (0x10 * (val))
#define GPT_CTRL_OP(val) (((val) & 0x3) << 4)
#define GPT_CTRL_OP_ONESHOT (0)
#define GPT_CTRL_OP_REPEAT (1)
#define GPT_CTRL_OP_FREERUN (3)
#define GPT_CTRL_CLEAR (2)
#define GPT_CTRL_ENABLE (1)
#define GPT_CTRL_DISABLE (0)
#define GPT_CLK_REG(val) (0x04 + (0x10 * (val)))
#define GPT_CLK_SRC(val) (((val) & 0x1) << 4)
#define GPT_CLK_SRC_SYS13M (0)
#define GPT_CLK_SRC_RTC32K (1)
#define GPT_CLK_DIV1 (0x0)
#define GPT_CLK_DIV2 (0x1)
#define GPT_CNT_REG(val) (0x08 + (0x10 * (val)))
#define GPT_CMP_REG(val) (0x0C + (0x10 * (val)))
/* system timer */
#define SYST_BASE (0x40)
#define SYST_CON (SYST_BASE + 0x0)
#define SYST_VAL (SYST_BASE + 0x4)
#define SYST_CON_REG(to) (timer_of_base(to) + SYST_CON)
#define SYST_VAL_REG(to) (timer_of_base(to) + SYST_VAL)
/*
* SYST_CON_EN: Clock enable. Shall be set to
* - Start timer countdown.
* - Allow timeout ticks being updated.
* - Allow changing interrupt functions.
*
* SYST_CON_IRQ_EN: Set to allow interrupt.
*
* SYST_CON_IRQ_CLR: Set to clear interrupt.
*/
#define SYST_CON_EN BIT(0)
#define SYST_CON_IRQ_EN BIT(1)
#define SYST_CON_IRQ_CLR BIT(4)
static void __iomem *gpt_sched_reg __read_mostly;
static void mtk_syst_ack_irq(struct timer_of *to)
{
/* Clear and disable interrupt */
writel(SYST_CON_IRQ_CLR | SYST_CON_EN, SYST_CON_REG(to));
}
static irqreturn_t mtk_syst_handler(int irq, void *dev_id)
{
struct clock_event_device *clkevt = dev_id;
struct timer_of *to = to_timer_of(clkevt);
mtk_syst_ack_irq(to);
clkevt->event_handler(clkevt);
return IRQ_HANDLED;
}
static int mtk_syst_clkevt_next_event(unsigned long ticks,
struct clock_event_device *clkevt)
{
struct timer_of *to = to_timer_of(clkevt);
/* Enable clock to allow timeout tick update later */
writel(SYST_CON_EN, SYST_CON_REG(to));
/*
* Write new timeout ticks. Timer shall start countdown
* after timeout ticks are updated.
*/
writel(ticks, SYST_VAL_REG(to));
/* Enable interrupt */
writel(SYST_CON_EN | SYST_CON_IRQ_EN, SYST_CON_REG(to));
return 0;
}
static int mtk_syst_clkevt_shutdown(struct clock_event_device *clkevt)
{
/* Disable timer */
writel(0, SYST_CON_REG(to_timer_of(clkevt)));
return 0;
}
static int mtk_syst_clkevt_resume(struct clock_event_device *clkevt)
{
return mtk_syst_clkevt_shutdown(clkevt);
}
static int mtk_syst_clkevt_oneshot(struct clock_event_device *clkevt)
{
return 0;
}
static u64 notrace mtk_gpt_read_sched_clock(void)
{
return readl_relaxed(gpt_sched_reg);
}
static void mtk_gpt_clkevt_time_stop(struct timer_of *to, u8 timer)
{
u32 val;
val = readl(timer_of_base(to) + GPT_CTRL_REG(timer));
writel(val & ~GPT_CTRL_ENABLE, timer_of_base(to) +
GPT_CTRL_REG(timer));
}
static void mtk_gpt_clkevt_time_setup(struct timer_of *to,
unsigned long delay, u8 timer)
{
writel(delay, timer_of_base(to) + GPT_CMP_REG(timer));
}
static void mtk_gpt_clkevt_time_start(struct timer_of *to,
bool periodic, u8 timer)
{
u32 val;
/* Acknowledge interrupt */
writel(GPT_IRQ_ACK(timer), timer_of_base(to) + GPT_IRQ_ACK_REG);
val = readl(timer_of_base(to) + GPT_CTRL_REG(timer));
/* Clear 2 bit timer operation mode field */
val &= ~GPT_CTRL_OP(0x3);
if (periodic)
val |= GPT_CTRL_OP(GPT_CTRL_OP_REPEAT);
else
val |= GPT_CTRL_OP(GPT_CTRL_OP_ONESHOT);
writel(val | GPT_CTRL_ENABLE | GPT_CTRL_CLEAR,
timer_of_base(to) + GPT_CTRL_REG(timer));
}
static int mtk_gpt_clkevt_shutdown(struct clock_event_device *clk)
{
mtk_gpt_clkevt_time_stop(to_timer_of(clk), TIMER_CLK_EVT);
return 0;
}
static int mtk_gpt_clkevt_set_periodic(struct clock_event_device *clk)
{
struct timer_of *to = to_timer_of(clk);
mtk_gpt_clkevt_time_stop(to, TIMER_CLK_EVT);
mtk_gpt_clkevt_time_setup(to, to->of_clk.period, TIMER_CLK_EVT);
mtk_gpt_clkevt_time_start(to, true, TIMER_CLK_EVT);
return 0;
}
static int mtk_gpt_clkevt_next_event(unsigned long event,
struct clock_event_device *clk)
{
struct timer_of *to = to_timer_of(clk);
mtk_gpt_clkevt_time_stop(to, TIMER_CLK_EVT);
mtk_gpt_clkevt_time_setup(to, event, TIMER_CLK_EVT);
mtk_gpt_clkevt_time_start(to, false, TIMER_CLK_EVT);
return 0;
}
static irqreturn_t mtk_gpt_interrupt(int irq, void *dev_id)
{
struct clock_event_device *clkevt = (struct clock_event_device *)dev_id;
struct timer_of *to = to_timer_of(clkevt);
/* Acknowledge timer0 irq */
writel(GPT_IRQ_ACK(TIMER_CLK_EVT), timer_of_base(to) + GPT_IRQ_ACK_REG);
clkevt->event_handler(clkevt);
return IRQ_HANDLED;
}
static void
__init mtk_gpt_setup(struct timer_of *to, u8 timer, u8 option)
{
writel(GPT_CTRL_CLEAR | GPT_CTRL_DISABLE,
timer_of_base(to) + GPT_CTRL_REG(timer));
writel(GPT_CLK_SRC(GPT_CLK_SRC_SYS13M) | GPT_CLK_DIV1,
timer_of_base(to) + GPT_CLK_REG(timer));
writel(0x0, timer_of_base(to) + GPT_CMP_REG(timer));
writel(GPT_CTRL_OP(option) | GPT_CTRL_ENABLE,
timer_of_base(to) + GPT_CTRL_REG(timer));
}
static void mtk_gpt_enable_irq(struct timer_of *to, u8 timer)
{
u32 val;
/* Disable all interrupts */
writel(0x0, timer_of_base(to) + GPT_IRQ_EN_REG);
/* Acknowledge all spurious pending interrupts */
writel(0x3f, timer_of_base(to) + GPT_IRQ_ACK_REG);
val = readl(timer_of_base(to) + GPT_IRQ_EN_REG);
writel(val | GPT_IRQ_ENABLE(timer),
timer_of_base(to) + GPT_IRQ_EN_REG);
}
static struct timer_of to = {
.flags = TIMER_OF_IRQ | TIMER_OF_BASE | TIMER_OF_CLOCK,
.clkevt = {
.name = "mtk-clkevt",
.rating = 300,
.cpumask = cpu_possible_mask,
},
.of_irq = {
.flags = IRQF_TIMER | IRQF_IRQPOLL,
},
};
static int __init mtk_syst_init(struct device_node *node)
{
int ret;
to.clkevt.features = CLOCK_EVT_FEAT_DYNIRQ | CLOCK_EVT_FEAT_ONESHOT;
to.clkevt.set_state_shutdown = mtk_syst_clkevt_shutdown;
to.clkevt.set_state_oneshot = mtk_syst_clkevt_oneshot;
to.clkevt.tick_resume = mtk_syst_clkevt_resume;
to.clkevt.set_next_event = mtk_syst_clkevt_next_event;
to.of_irq.handler = mtk_syst_handler;
ret = timer_of_init(node, &to);
if (ret)
goto err;
clockevents_config_and_register(&to.clkevt, timer_of_rate(&to),
TIMER_SYNC_TICKS, 0xffffffff);
return 0;
err:
timer_of_cleanup(&to);
return ret;
}
static int __init mtk_gpt_init(struct device_node *node)
{
int ret;
to.clkevt.features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT;
to.clkevt.set_state_shutdown = mtk_gpt_clkevt_shutdown;
to.clkevt.set_state_periodic = mtk_gpt_clkevt_set_periodic;
to.clkevt.set_state_oneshot = mtk_gpt_clkevt_shutdown;
to.clkevt.tick_resume = mtk_gpt_clkevt_shutdown;
to.clkevt.set_next_event = mtk_gpt_clkevt_next_event;
to.of_irq.handler = mtk_gpt_interrupt;
ret = timer_of_init(node, &to);
if (ret)
goto err;
/* Configure clock source */
mtk_gpt_setup(&to, TIMER_CLK_SRC, GPT_CTRL_OP_FREERUN);
clocksource_mmio_init(timer_of_base(&to) + GPT_CNT_REG(TIMER_CLK_SRC),
node->name, timer_of_rate(&to), 300, 32,
clocksource_mmio_readl_up);
gpt_sched_reg = timer_of_base(&to) + GPT_CNT_REG(TIMER_CLK_SRC);
sched_clock_register(mtk_gpt_read_sched_clock, 32, timer_of_rate(&to));
/* Configure clock event */
mtk_gpt_setup(&to, TIMER_CLK_EVT, GPT_CTRL_OP_REPEAT);
clockevents_config_and_register(&to.clkevt, timer_of_rate(&to),
TIMER_SYNC_TICKS, 0xffffffff);
mtk_gpt_enable_irq(&to, TIMER_CLK_EVT);
return 0;
err:
timer_of_cleanup(&to);
return ret;
}
TIMER_OF_DECLARE(mtk_mt6577, "mediatek,mt6577-timer", mtk_gpt_init);
TIMER_OF_DECLARE(mtk_mt6765, "mediatek,mt6765-timer", mtk_syst_init);
...@@ -156,4 +156,54 @@ static int __init sprd_timer_init(struct device_node *np) ...@@ -156,4 +156,54 @@ static int __init sprd_timer_init(struct device_node *np)
return 0; return 0;
} }
static struct timer_of suspend_to = {
.flags = TIMER_OF_BASE | TIMER_OF_CLOCK,
};
static u64 sprd_suspend_timer_read(struct clocksource *cs)
{
return ~(u64)readl_relaxed(timer_of_base(&suspend_to) +
TIMER_VALUE_SHDW_LO) & cs->mask;
}
static int sprd_suspend_timer_enable(struct clocksource *cs)
{
sprd_timer_update_counter(timer_of_base(&suspend_to),
TIMER_VALUE_LO_MASK);
sprd_timer_enable(timer_of_base(&suspend_to), TIMER_CTL_PERIOD_MODE);
return 0;
}
static void sprd_suspend_timer_disable(struct clocksource *cs)
{
sprd_timer_disable(timer_of_base(&suspend_to));
}
static struct clocksource suspend_clocksource = {
.name = "sprd_suspend_timer",
.rating = 200,
.read = sprd_suspend_timer_read,
.enable = sprd_suspend_timer_enable,
.disable = sprd_suspend_timer_disable,
.mask = CLOCKSOURCE_MASK(32),
.flags = CLOCK_SOURCE_IS_CONTINUOUS | CLOCK_SOURCE_SUSPEND_NONSTOP,
};
static int __init sprd_suspend_timer_init(struct device_node *np)
{
int ret;
ret = timer_of_init(np, &suspend_to);
if (ret)
return ret;
clocksource_register_hz(&suspend_clocksource,
timer_of_rate(&suspend_to));
return 0;
}
TIMER_OF_DECLARE(sc9860_timer, "sprd,sc9860-timer", sprd_timer_init); TIMER_OF_DECLARE(sc9860_timer, "sprd,sc9860-timer", sprd_timer_init);
TIMER_OF_DECLARE(sc9860_persistent_timer, "sprd,sc9860-suspend-timer",
sprd_suspend_timer_init);
...@@ -78,8 +78,7 @@ static struct ti_32k ti_32k_timer = { ...@@ -78,8 +78,7 @@ static struct ti_32k ti_32k_timer = {
.rating = 250, .rating = 250,
.read = ti_32k_read_cycles, .read = ti_32k_read_cycles,
.mask = CLOCKSOURCE_MASK(32), .mask = CLOCKSOURCE_MASK(32),
.flags = CLOCK_SOURCE_IS_CONTINUOUS | .flags = CLOCK_SOURCE_IS_CONTINUOUS,
CLOCK_SOURCE_SUSPEND_NONSTOP,
}, },
}; };
......
...@@ -162,7 +162,7 @@ static int __init zevio_timer_add(struct device_node *node) ...@@ -162,7 +162,7 @@ static int __init zevio_timer_add(struct device_node *node)
timer->clkevt.set_state_oneshot = zevio_timer_set_oneshot; timer->clkevt.set_state_oneshot = zevio_timer_set_oneshot;
timer->clkevt.tick_resume = zevio_timer_set_oneshot; timer->clkevt.tick_resume = zevio_timer_set_oneshot;
timer->clkevt.rating = 200; timer->clkevt.rating = 200;
timer->clkevt.cpumask = cpu_all_mask; timer->clkevt.cpumask = cpu_possible_mask;
timer->clkevt.features = CLOCK_EVT_FEAT_ONESHOT; timer->clkevt.features = CLOCK_EVT_FEAT_ONESHOT;
timer->clkevt.irq = irqnr; timer->clkevt.irq = irqnr;
......
...@@ -533,8 +533,8 @@ static int do_timerfd_gettime(int ufd, struct itimerspec64 *t) ...@@ -533,8 +533,8 @@ static int do_timerfd_gettime(int ufd, struct itimerspec64 *t)
} }
SYSCALL_DEFINE4(timerfd_settime, int, ufd, int, flags, SYSCALL_DEFINE4(timerfd_settime, int, ufd, int, flags,
const struct itimerspec __user *, utmr, const struct __kernel_itimerspec __user *, utmr,
struct itimerspec __user *, otmr) struct __kernel_itimerspec __user *, otmr)
{ {
struct itimerspec64 new, old; struct itimerspec64 new, old;
int ret; int ret;
...@@ -550,7 +550,7 @@ SYSCALL_DEFINE4(timerfd_settime, int, ufd, int, flags, ...@@ -550,7 +550,7 @@ SYSCALL_DEFINE4(timerfd_settime, int, ufd, int, flags,
return ret; return ret;
} }
SYSCALL_DEFINE2(timerfd_gettime, int, ufd, struct itimerspec __user *, otmr) SYSCALL_DEFINE2(timerfd_gettime, int, ufd, struct __kernel_itimerspec __user *, otmr)
{ {
struct itimerspec64 kotmr; struct itimerspec64 kotmr;
int ret = do_timerfd_gettime(ufd, &kotmr); int ret = do_timerfd_gettime(ufd, &kotmr);
...@@ -559,7 +559,7 @@ SYSCALL_DEFINE2(timerfd_gettime, int, ufd, struct itimerspec __user *, otmr) ...@@ -559,7 +559,7 @@ SYSCALL_DEFINE2(timerfd_gettime, int, ufd, struct itimerspec __user *, otmr)
return put_itimerspec64(&kotmr, otmr) ? -EFAULT : 0; return put_itimerspec64(&kotmr, otmr) ? -EFAULT : 0;
} }
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT_32BIT_TIME
COMPAT_SYSCALL_DEFINE4(timerfd_settime, int, ufd, int, flags, COMPAT_SYSCALL_DEFINE4(timerfd_settime, int, ufd, int, flags,
const struct compat_itimerspec __user *, utmr, const struct compat_itimerspec __user *, utmr,
struct compat_itimerspec __user *, otmr) struct compat_itimerspec __user *, otmr)
......
...@@ -194,6 +194,9 @@ extern void clocksource_suspend(void); ...@@ -194,6 +194,9 @@ extern void clocksource_suspend(void);
extern void clocksource_resume(void); extern void clocksource_resume(void);
extern struct clocksource * __init clocksource_default_clock(void); extern struct clocksource * __init clocksource_default_clock(void);
extern void clocksource_mark_unstable(struct clocksource *cs); extern void clocksource_mark_unstable(struct clocksource *cs);
extern void
clocksource_start_suspend_timing(struct clocksource *cs, u64 start_cycles);
extern u64 clocksource_stop_suspend_timing(struct clocksource *cs, u64 now);
extern u64 extern u64
clocks_calc_max_nsecs(u32 mult, u32 shift, u32 maxadj, u64 mask, u64 *max_cycles); clocks_calc_max_nsecs(u32 mult, u32 shift, u32 maxadj, u64 mask, u64 *max_cycles);
......
...@@ -115,11 +115,6 @@ typedef compat_ulong_t compat_aio_context_t; ...@@ -115,11 +115,6 @@ typedef compat_ulong_t compat_aio_context_t;
struct compat_sel_arg_struct; struct compat_sel_arg_struct;
struct rusage; struct rusage;
struct compat_itimerspec {
struct compat_timespec it_interval;
struct compat_timespec it_value;
};
struct compat_utimbuf { struct compat_utimbuf {
compat_time_t actime; compat_time_t actime;
compat_time_t modtime; compat_time_t modtime;
...@@ -300,10 +295,6 @@ extern int compat_get_timespec(struct timespec *, const void __user *); ...@@ -300,10 +295,6 @@ extern int compat_get_timespec(struct timespec *, const void __user *);
extern int compat_put_timespec(const struct timespec *, void __user *); extern int compat_put_timespec(const struct timespec *, void __user *);
extern int compat_get_timeval(struct timeval *, const void __user *); extern int compat_get_timeval(struct timeval *, const void __user *);
extern int compat_put_timeval(const struct timeval *, void __user *); extern int compat_put_timeval(const struct timeval *, void __user *);
extern int get_compat_itimerspec64(struct itimerspec64 *its,
const struct compat_itimerspec __user *uits);
extern int put_compat_itimerspec64(const struct itimerspec64 *its,
struct compat_itimerspec __user *uits);
struct compat_iovec { struct compat_iovec {
compat_uptr_t iov_base; compat_uptr_t iov_base;
......
...@@ -17,7 +17,16 @@ struct compat_timeval { ...@@ -17,7 +17,16 @@ struct compat_timeval {
s32 tv_usec; s32 tv_usec;
}; };
struct compat_itimerspec {
struct compat_timespec it_interval;
struct compat_timespec it_value;
};
extern int compat_get_timespec64(struct timespec64 *, const void __user *); extern int compat_get_timespec64(struct timespec64 *, const void __user *);
extern int compat_put_timespec64(const struct timespec64 *, void __user *); extern int compat_put_timespec64(const struct timespec64 *, void __user *);
extern int get_compat_itimerspec64(struct itimerspec64 *its,
const struct compat_itimerspec __user *uits);
extern int put_compat_itimerspec64(const struct itimerspec64 *its,
struct compat_itimerspec __user *uits);
#endif /* _LINUX_COMPAT_TIME_H */ #endif /* _LINUX_COMPAT_TIME_H */
...@@ -93,8 +93,11 @@ static inline ktime_t timeval_to_ktime(struct timeval tv) ...@@ -93,8 +93,11 @@ static inline ktime_t timeval_to_ktime(struct timeval tv)
/* Map the ktime_t to timeval conversion to ns_to_timeval function */ /* Map the ktime_t to timeval conversion to ns_to_timeval function */
#define ktime_to_timeval(kt) ns_to_timeval((kt)) #define ktime_to_timeval(kt) ns_to_timeval((kt))
/* Convert ktime_t to nanoseconds - NOP in the scalar storage format: */ /* Convert ktime_t to nanoseconds */
#define ktime_to_ns(kt) (kt) static inline s64 ktime_to_ns(const ktime_t kt)
{
return kt;
}
/** /**
* ktime_compare - Compares two ktime_t variables for less, greater or equal * ktime_compare - Compares two ktime_t variables for less, greater or equal
......
...@@ -95,8 +95,8 @@ struct k_itimer { ...@@ -95,8 +95,8 @@ struct k_itimer {
clockid_t it_clock; clockid_t it_clock;
timer_t it_id; timer_t it_id;
int it_active; int it_active;
int it_overrun; s64 it_overrun;
int it_overrun_last; s64 it_overrun_last;
int it_requeue_pending; int it_requeue_pending;
int it_sigev_notify; int it_sigev_notify;
ktime_t it_interval; ktime_t it_interval;
......
...@@ -506,9 +506,9 @@ asmlinkage long sys_sync_file_range(int fd, loff_t offset, loff_t nbytes, ...@@ -506,9 +506,9 @@ asmlinkage long sys_sync_file_range(int fd, loff_t offset, loff_t nbytes,
/* fs/timerfd.c */ /* fs/timerfd.c */
asmlinkage long sys_timerfd_create(int clockid, int flags); asmlinkage long sys_timerfd_create(int clockid, int flags);
asmlinkage long sys_timerfd_settime(int ufd, int flags, asmlinkage long sys_timerfd_settime(int ufd, int flags,
const struct itimerspec __user *utmr, const struct __kernel_itimerspec __user *utmr,
struct itimerspec __user *otmr); struct __kernel_itimerspec __user *otmr);
asmlinkage long sys_timerfd_gettime(int ufd, struct itimerspec __user *otmr); asmlinkage long sys_timerfd_gettime(int ufd, struct __kernel_itimerspec __user *otmr);
/* fs/utimes.c */ /* fs/utimes.c */
asmlinkage long sys_utimensat(int dfd, const char __user *filename, asmlinkage long sys_utimensat(int dfd, const char __user *filename,
...@@ -573,10 +573,10 @@ asmlinkage long sys_timer_create(clockid_t which_clock, ...@@ -573,10 +573,10 @@ asmlinkage long sys_timer_create(clockid_t which_clock,
struct sigevent __user *timer_event_spec, struct sigevent __user *timer_event_spec,
timer_t __user * created_timer_id); timer_t __user * created_timer_id);
asmlinkage long sys_timer_gettime(timer_t timer_id, asmlinkage long sys_timer_gettime(timer_t timer_id,
struct itimerspec __user *setting); struct __kernel_itimerspec __user *setting);
asmlinkage long sys_timer_getoverrun(timer_t timer_id); asmlinkage long sys_timer_getoverrun(timer_t timer_id);
asmlinkage long sys_timer_settime(timer_t timer_id, int flags, asmlinkage long sys_timer_settime(timer_t timer_id, int flags,
const struct itimerspec __user *new_setting, const struct __kernel_itimerspec __user *new_setting,
struct itimerspec __user *old_setting); struct itimerspec __user *old_setting);
asmlinkage long sys_timer_delete(timer_t timer_id); asmlinkage long sys_timer_delete(timer_t timer_id);
asmlinkage long sys_clock_settime(clockid_t which_clock, asmlinkage long sys_clock_settime(clockid_t which_clock,
......
...@@ -14,9 +14,9 @@ int get_timespec64(struct timespec64 *ts, ...@@ -14,9 +14,9 @@ int get_timespec64(struct timespec64 *ts,
int put_timespec64(const struct timespec64 *ts, int put_timespec64(const struct timespec64 *ts,
struct __kernel_timespec __user *uts); struct __kernel_timespec __user *uts);
int get_itimerspec64(struct itimerspec64 *it, int get_itimerspec64(struct itimerspec64 *it,
const struct itimerspec __user *uit); const struct __kernel_itimerspec __user *uit);
int put_itimerspec64(const struct itimerspec64 *it, int put_itimerspec64(const struct itimerspec64 *it,
struct itimerspec __user *uit); struct __kernel_itimerspec __user *uit);
extern time64_t mktime64(const unsigned int year, const unsigned int mon, extern time64_t mktime64(const unsigned int year, const unsigned int mon,
const unsigned int day, const unsigned int hour, const unsigned int day, const unsigned int hour,
......
...@@ -12,6 +12,7 @@ typedef __u64 timeu64_t; ...@@ -12,6 +12,7 @@ typedef __u64 timeu64_t;
*/ */
#ifndef CONFIG_64BIT_TIME #ifndef CONFIG_64BIT_TIME
#define __kernel_timespec timespec #define __kernel_timespec timespec
#define __kernel_itimerspec itimerspec
#endif #endif
#include <uapi/linux/time.h> #include <uapi/linux/time.h>
......
...@@ -177,7 +177,7 @@ static inline time64_t ktime_get_clocktai_seconds(void) ...@@ -177,7 +177,7 @@ static inline time64_t ktime_get_clocktai_seconds(void)
extern bool timekeeping_rtc_skipsuspend(void); extern bool timekeeping_rtc_skipsuspend(void);
extern bool timekeeping_rtc_skipresume(void); extern bool timekeeping_rtc_skipresume(void);
extern void timekeeping_inject_sleeptime64(struct timespec64 *delta); extern void timekeeping_inject_sleeptime64(const struct timespec64 *delta);
/* /*
* struct system_time_snapshot - simultaneous raw/real time capture with * struct system_time_snapshot - simultaneous raw/real time capture with
......
...@@ -49,6 +49,13 @@ struct __kernel_timespec { ...@@ -49,6 +49,13 @@ struct __kernel_timespec {
}; };
#endif #endif
#ifndef __kernel_itimerspec
struct __kernel_itimerspec {
struct __kernel_timespec it_interval; /* timer period */
struct __kernel_timespec it_value; /* timer expiration */
};
#endif
/* /*
* legacy timeval structure, only embedded in structures that * legacy timeval structure, only embedded in structures that
* traditionally used 'timeval' to pass time intervals (not absolute * traditionally used 'timeval' to pass time intervals (not absolute
......
...@@ -324,35 +324,6 @@ COMPAT_SYSCALL_DEFINE3(sched_getaffinity, compat_pid_t, pid, unsigned int, len, ...@@ -324,35 +324,6 @@ COMPAT_SYSCALL_DEFINE3(sched_getaffinity, compat_pid_t, pid, unsigned int, len,
return ret; return ret;
} }
/* Todo: Delete these extern declarations when get/put_compat_itimerspec64()
* are moved to kernel/time/time.c .
*/
extern int __compat_get_timespec64(struct timespec64 *ts64,
const struct compat_timespec __user *cts);
extern int __compat_put_timespec64(const struct timespec64 *ts64,
struct compat_timespec __user *cts);
int get_compat_itimerspec64(struct itimerspec64 *its,
const struct compat_itimerspec __user *uits)
{
if (__compat_get_timespec64(&its->it_interval, &uits->it_interval) ||
__compat_get_timespec64(&its->it_value, &uits->it_value))
return -EFAULT;
return 0;
}
EXPORT_SYMBOL_GPL(get_compat_itimerspec64);
int put_compat_itimerspec64(const struct itimerspec64 *its,
struct compat_itimerspec __user *uits)
{
if (__compat_put_timespec64(&its->it_interval, &uits->it_interval) ||
__compat_put_timespec64(&its->it_value, &uits->it_value))
return -EFAULT;
return 0;
}
EXPORT_SYMBOL_GPL(put_compat_itimerspec64);
/* /*
* We currently only need the following fields from the sigevent * We currently only need the following fields from the sigevent
* structure: sigev_value, sigev_signo, sig_notify and (sometimes * structure: sigev_value, sigev_signo, sig_notify and (sometimes
......
...@@ -2512,11 +2512,11 @@ static int do_sysinfo(struct sysinfo *info) ...@@ -2512,11 +2512,11 @@ static int do_sysinfo(struct sysinfo *info)
{ {
unsigned long mem_total, sav_total; unsigned long mem_total, sav_total;
unsigned int mem_unit, bitcount; unsigned int mem_unit, bitcount;
struct timespec tp; struct timespec64 tp;
memset(info, 0, sizeof(struct sysinfo)); memset(info, 0, sizeof(struct sysinfo));
get_monotonic_boottime(&tp); ktime_get_boottime_ts64(&tp);
info->uptime = tp.tv_sec + (tp.tv_nsec ? 1 : 0); info->uptime = tp.tv_sec + (tp.tv_nsec ? 1 : 0);
get_avenrun(info->loads, 0, SI_LOAD_SHIFT - FSHIFT); get_avenrun(info->loads, 0, SI_LOAD_SHIFT - FSHIFT);
......
...@@ -581,11 +581,11 @@ static void alarm_timer_rearm(struct k_itimer *timr) ...@@ -581,11 +581,11 @@ static void alarm_timer_rearm(struct k_itimer *timr)
* @timr: Pointer to the posixtimer data struct * @timr: Pointer to the posixtimer data struct
* @now: Current time to forward the timer against * @now: Current time to forward the timer against
*/ */
static int alarm_timer_forward(struct k_itimer *timr, ktime_t now) static s64 alarm_timer_forward(struct k_itimer *timr, ktime_t now)
{ {
struct alarm *alarm = &timr->it.alarm.alarmtimer; struct alarm *alarm = &timr->it.alarm.alarmtimer;
return (int) alarm_forward(alarm, timr->it_interval, now); return alarm_forward(alarm, timr->it_interval, now);
} }
/** /**
...@@ -808,7 +808,8 @@ static int alarm_timer_nsleep(const clockid_t which_clock, int flags, ...@@ -808,7 +808,8 @@ static int alarm_timer_nsleep(const clockid_t which_clock, int flags,
/* Convert (if necessary) to absolute time */ /* Convert (if necessary) to absolute time */
if (flags != TIMER_ABSTIME) { if (flags != TIMER_ABSTIME) {
ktime_t now = alarm_bases[type].gettime(); ktime_t now = alarm_bases[type].gettime();
exp = ktime_add(now, exp);
exp = ktime_add_safe(now, exp);
} }
ret = alarmtimer_do_nsleep(&alarm, exp, type); ret = alarmtimer_do_nsleep(&alarm, exp, type);
......
...@@ -463,6 +463,12 @@ void clockevents_register_device(struct clock_event_device *dev) ...@@ -463,6 +463,12 @@ void clockevents_register_device(struct clock_event_device *dev)
dev->cpumask = cpumask_of(smp_processor_id()); dev->cpumask = cpumask_of(smp_processor_id());
} }
if (dev->cpumask == cpu_all_mask) {
WARN(1, "%s cpumask == cpu_all_mask, using cpu_possible_mask instead\n",
dev->name);
dev->cpumask = cpu_possible_mask;
}
raw_spin_lock_irqsave(&clockevents_lock, flags); raw_spin_lock_irqsave(&clockevents_lock, flags);
list_add(&dev->list, &clockevent_devices); list_add(&dev->list, &clockevent_devices);
......
...@@ -94,6 +94,8 @@ EXPORT_SYMBOL_GPL(clocks_calc_mult_shift); ...@@ -94,6 +94,8 @@ EXPORT_SYMBOL_GPL(clocks_calc_mult_shift);
/*[Clocksource internal variables]--------- /*[Clocksource internal variables]---------
* curr_clocksource: * curr_clocksource:
* currently selected clocksource. * currently selected clocksource.
* suspend_clocksource:
* used to calculate the suspend time.
* clocksource_list: * clocksource_list:
* linked list with the registered clocksources * linked list with the registered clocksources
* clocksource_mutex: * clocksource_mutex:
...@@ -102,10 +104,12 @@ EXPORT_SYMBOL_GPL(clocks_calc_mult_shift); ...@@ -102,10 +104,12 @@ EXPORT_SYMBOL_GPL(clocks_calc_mult_shift);
* Name of the user-specified clocksource. * Name of the user-specified clocksource.
*/ */
static struct clocksource *curr_clocksource; static struct clocksource *curr_clocksource;
static struct clocksource *suspend_clocksource;
static LIST_HEAD(clocksource_list); static LIST_HEAD(clocksource_list);
static DEFINE_MUTEX(clocksource_mutex); static DEFINE_MUTEX(clocksource_mutex);
static char override_name[CS_NAME_LEN]; static char override_name[CS_NAME_LEN];
static int finished_booting; static int finished_booting;
static u64 suspend_start;
#ifdef CONFIG_CLOCKSOURCE_WATCHDOG #ifdef CONFIG_CLOCKSOURCE_WATCHDOG
static void clocksource_watchdog_work(struct work_struct *work); static void clocksource_watchdog_work(struct work_struct *work);
...@@ -447,6 +451,140 @@ static inline void clocksource_watchdog_unlock(unsigned long *flags) { } ...@@ -447,6 +451,140 @@ static inline void clocksource_watchdog_unlock(unsigned long *flags) { }
#endif /* CONFIG_CLOCKSOURCE_WATCHDOG */ #endif /* CONFIG_CLOCKSOURCE_WATCHDOG */
static bool clocksource_is_suspend(struct clocksource *cs)
{
return cs == suspend_clocksource;
}
static void __clocksource_suspend_select(struct clocksource *cs)
{
/*
* Skip the clocksource which will be stopped in suspend state.
*/
if (!(cs->flags & CLOCK_SOURCE_SUSPEND_NONSTOP))
return;
/*
* The nonstop clocksource can be selected as the suspend clocksource to
* calculate the suspend time, so it should not supply suspend/resume
* interfaces to suspend the nonstop clocksource when system suspends.
*/
if (cs->suspend || cs->resume) {
pr_warn("Nonstop clocksource %s should not supply suspend/resume interfaces\n",
cs->name);
}
/* Pick the best rating. */
if (!suspend_clocksource || cs->rating > suspend_clocksource->rating)
suspend_clocksource = cs;
}
/**
* clocksource_suspend_select - Select the best clocksource for suspend timing
* @fallback: if select a fallback clocksource
*/
static void clocksource_suspend_select(bool fallback)
{
struct clocksource *cs, *old_suspend;
old_suspend = suspend_clocksource;
if (fallback)
suspend_clocksource = NULL;
list_for_each_entry(cs, &clocksource_list, list) {
/* Skip current if we were requested for a fallback. */
if (fallback && cs == old_suspend)
continue;
__clocksource_suspend_select(cs);
}
}
/**
* clocksource_start_suspend_timing - Start measuring the suspend timing
* @cs: current clocksource from timekeeping
* @start_cycles: current cycles from timekeeping
*
* This function will save the start cycle values of suspend timer to calculate
* the suspend time when resuming system.
*
* This function is called late in the suspend process from timekeeping_suspend(),
* that means processes are freezed, non-boot cpus and interrupts are disabled
* now. It is therefore possible to start the suspend timer without taking the
* clocksource mutex.
*/
void clocksource_start_suspend_timing(struct clocksource *cs, u64 start_cycles)
{
if (!suspend_clocksource)
return;
/*
* If current clocksource is the suspend timer, we should use the
* tkr_mono.cycle_last value as suspend_start to avoid same reading
* from suspend timer.
*/
if (clocksource_is_suspend(cs)) {
suspend_start = start_cycles;
return;
}
if (suspend_clocksource->enable &&
suspend_clocksource->enable(suspend_clocksource)) {
pr_warn_once("Failed to enable the non-suspend-able clocksource.\n");
return;
}
suspend_start = suspend_clocksource->read(suspend_clocksource);
}
/**
* clocksource_stop_suspend_timing - Stop measuring the suspend timing
* @cs: current clocksource from timekeeping
* @cycle_now: current cycles from timekeeping
*
* This function will calculate the suspend time from suspend timer.
*
* Returns nanoseconds since suspend started, 0 if no usable suspend clocksource.
*
* This function is called early in the resume process from timekeeping_resume(),
* that means there is only one cpu, no processes are running and the interrupts
* are disabled. It is therefore possible to stop the suspend timer without
* taking the clocksource mutex.
*/
u64 clocksource_stop_suspend_timing(struct clocksource *cs, u64 cycle_now)
{
u64 now, delta, nsec = 0;
if (!suspend_clocksource)
return 0;
/*
* If current clocksource is the suspend timer, we should use the
* tkr_mono.cycle_last value from timekeeping as current cycle to
* avoid same reading from suspend timer.
*/
if (clocksource_is_suspend(cs))
now = cycle_now;
else
now = suspend_clocksource->read(suspend_clocksource);
if (now > suspend_start) {
delta = clocksource_delta(now, suspend_start,
suspend_clocksource->mask);
nsec = mul_u64_u32_shr(delta, suspend_clocksource->mult,
suspend_clocksource->shift);
}
/*
* Disable the suspend timer to save power if current clocksource is
* not the suspend timer.
*/
if (!clocksource_is_suspend(cs) && suspend_clocksource->disable)
suspend_clocksource->disable(suspend_clocksource);
return nsec;
}
/** /**
* clocksource_suspend - suspend the clocksource(s) * clocksource_suspend - suspend the clocksource(s)
*/ */
...@@ -792,6 +930,7 @@ int __clocksource_register_scale(struct clocksource *cs, u32 scale, u32 freq) ...@@ -792,6 +930,7 @@ int __clocksource_register_scale(struct clocksource *cs, u32 scale, u32 freq)
clocksource_select(); clocksource_select();
clocksource_select_watchdog(false); clocksource_select_watchdog(false);
__clocksource_suspend_select(cs);
mutex_unlock(&clocksource_mutex); mutex_unlock(&clocksource_mutex);
return 0; return 0;
} }
...@@ -820,6 +959,7 @@ void clocksource_change_rating(struct clocksource *cs, int rating) ...@@ -820,6 +959,7 @@ void clocksource_change_rating(struct clocksource *cs, int rating)
clocksource_select(); clocksource_select();
clocksource_select_watchdog(false); clocksource_select_watchdog(false);
clocksource_suspend_select(false);
mutex_unlock(&clocksource_mutex); mutex_unlock(&clocksource_mutex);
} }
EXPORT_SYMBOL(clocksource_change_rating); EXPORT_SYMBOL(clocksource_change_rating);
...@@ -845,6 +985,15 @@ static int clocksource_unbind(struct clocksource *cs) ...@@ -845,6 +985,15 @@ static int clocksource_unbind(struct clocksource *cs)
return -EBUSY; return -EBUSY;
} }
if (clocksource_is_suspend(cs)) {
/*
* Select and try to install a replacement suspend clocksource.
* If no replacement suspend clocksource, we will just let the
* clocksource go and have no suspend clocksource.
*/
clocksource_suspend_select(true);
}
clocksource_watchdog_lock(&flags); clocksource_watchdog_lock(&flags);
clocksource_dequeue_watchdog(cs); clocksource_dequeue_watchdog(cs);
list_del_init(&cs->list); list_del_init(&cs->list);
......
...@@ -718,8 +718,8 @@ static void hrtimer_switch_to_hres(void) ...@@ -718,8 +718,8 @@ static void hrtimer_switch_to_hres(void)
struct hrtimer_cpu_base *base = this_cpu_ptr(&hrtimer_bases); struct hrtimer_cpu_base *base = this_cpu_ptr(&hrtimer_bases);
if (tick_init_highres()) { if (tick_init_highres()) {
printk(KERN_WARNING "Could not switch to high resolution " pr_warn("Could not switch to high resolution mode on CPU %u\n",
"mode on CPU %d\n", base->cpu); base->cpu);
return; return;
} }
base->hres_active = 1; base->hres_active = 1;
...@@ -1573,8 +1573,7 @@ void hrtimer_interrupt(struct clock_event_device *dev) ...@@ -1573,8 +1573,7 @@ void hrtimer_interrupt(struct clock_event_device *dev)
else else
expires_next = ktime_add(now, delta); expires_next = ktime_add(now, delta);
tick_program_event(expires_next, 1); tick_program_event(expires_next, 1);
printk_once(KERN_WARNING "hrtimer: interrupt took %llu ns\n", pr_warn_once("hrtimer: interrupt took %llu ns\n", ktime_to_ns(delta));
ktime_to_ns(delta));
} }
/* called with interrupts disabled */ /* called with interrupts disabled */
......
...@@ -502,7 +502,7 @@ static void sched_sync_hw_clock(struct timespec64 now, ...@@ -502,7 +502,7 @@ static void sched_sync_hw_clock(struct timespec64 now,
{ {
struct timespec64 next; struct timespec64 next;
getnstimeofday64(&next); ktime_get_real_ts64(&next);
if (!fail) if (!fail)
next.tv_sec = 659; next.tv_sec = 659;
else { else {
...@@ -537,7 +537,7 @@ static void sync_rtc_clock(void) ...@@ -537,7 +537,7 @@ static void sync_rtc_clock(void)
if (!IS_ENABLED(CONFIG_RTC_SYSTOHC)) if (!IS_ENABLED(CONFIG_RTC_SYSTOHC))
return; return;
getnstimeofday64(&now); ktime_get_real_ts64(&now);
adjust = now; adjust = now;
if (persistent_clock_is_local) if (persistent_clock_is_local)
...@@ -591,7 +591,7 @@ static bool sync_cmos_clock(void) ...@@ -591,7 +591,7 @@ static bool sync_cmos_clock(void)
* Architectures are strongly encouraged to use rtclib and not * Architectures are strongly encouraged to use rtclib and not
* implement this legacy API. * implement this legacy API.
*/ */
getnstimeofday64(&now); ktime_get_real_ts64(&now);
if (rtc_tv_nsec_ok(-1 * target_nsec, &adjust, &now)) { if (rtc_tv_nsec_ok(-1 * target_nsec, &adjust, &now)) {
if (persistent_clock_is_local) if (persistent_clock_is_local)
adjust.tv_sec -= (sys_tz.tz_minuteswest * 60); adjust.tv_sec -= (sys_tz.tz_minuteswest * 60);
...@@ -642,7 +642,7 @@ void ntp_notify_cmos_timer(void) ...@@ -642,7 +642,7 @@ void ntp_notify_cmos_timer(void)
/* /*
* Propagate a new txc->status value into the NTP state: * Propagate a new txc->status value into the NTP state:
*/ */
static inline void process_adj_status(struct timex *txc, struct timespec64 *ts) static inline void process_adj_status(const struct timex *txc)
{ {
if ((time_status & STA_PLL) && !(txc->status & STA_PLL)) { if ((time_status & STA_PLL) && !(txc->status & STA_PLL)) {
time_state = TIME_OK; time_state = TIME_OK;
...@@ -665,12 +665,10 @@ static inline void process_adj_status(struct timex *txc, struct timespec64 *ts) ...@@ -665,12 +665,10 @@ static inline void process_adj_status(struct timex *txc, struct timespec64 *ts)
} }
static inline void process_adjtimex_modes(struct timex *txc, static inline void process_adjtimex_modes(const struct timex *txc, s32 *time_tai)
struct timespec64 *ts,
s32 *time_tai)
{ {
if (txc->modes & ADJ_STATUS) if (txc->modes & ADJ_STATUS)
process_adj_status(txc, ts); process_adj_status(txc);
if (txc->modes & ADJ_NANO) if (txc->modes & ADJ_NANO)
time_status |= STA_NANO; time_status |= STA_NANO;
...@@ -718,7 +716,7 @@ static inline void process_adjtimex_modes(struct timex *txc, ...@@ -718,7 +716,7 @@ static inline void process_adjtimex_modes(struct timex *txc,
* adjtimex mainly allows reading (and writing, if superuser) of * adjtimex mainly allows reading (and writing, if superuser) of
* kernel time-keeping variables. used by xntpd. * kernel time-keeping variables. used by xntpd.
*/ */
int __do_adjtimex(struct timex *txc, struct timespec64 *ts, s32 *time_tai) int __do_adjtimex(struct timex *txc, const struct timespec64 *ts, s32 *time_tai)
{ {
int result; int result;
...@@ -735,7 +733,7 @@ int __do_adjtimex(struct timex *txc, struct timespec64 *ts, s32 *time_tai) ...@@ -735,7 +733,7 @@ int __do_adjtimex(struct timex *txc, struct timespec64 *ts, s32 *time_tai)
/* If there are input parameters, then process them: */ /* If there are input parameters, then process them: */
if (txc->modes) if (txc->modes)
process_adjtimex_modes(txc, ts, time_tai); process_adjtimex_modes(txc, time_tai);
txc->offset = shift_right(time_offset * NTP_INTERVAL_FREQ, txc->offset = shift_right(time_offset * NTP_INTERVAL_FREQ,
NTP_SCALE_SHIFT); NTP_SCALE_SHIFT);
...@@ -1022,12 +1020,11 @@ void __hardpps(const struct timespec64 *phase_ts, const struct timespec64 *raw_t ...@@ -1022,12 +1020,11 @@ void __hardpps(const struct timespec64 *phase_ts, const struct timespec64 *raw_t
static int __init ntp_tick_adj_setup(char *str) static int __init ntp_tick_adj_setup(char *str)
{ {
int rc = kstrtol(str, 0, (long *)&ntp_tick_adj); int rc = kstrtos64(str, 0, &ntp_tick_adj);
if (rc) if (rc)
return rc; return rc;
ntp_tick_adj <<= NTP_SCALE_SHIFT;
ntp_tick_adj <<= NTP_SCALE_SHIFT;
return 1; return 1;
} }
......
...@@ -8,6 +8,6 @@ extern void ntp_clear(void); ...@@ -8,6 +8,6 @@ extern void ntp_clear(void);
extern u64 ntp_tick_length(void); extern u64 ntp_tick_length(void);
extern ktime_t ntp_get_next_leap(void); extern ktime_t ntp_get_next_leap(void);
extern int second_overflow(time64_t secs); extern int second_overflow(time64_t secs);
extern int __do_adjtimex(struct timex *, struct timespec64 *, s32 *); extern int __do_adjtimex(struct timex *txc, const struct timespec64 *ts, s32 *time_tai);
extern void __hardpps(const struct timespec64 *, const struct timespec64 *); extern void __hardpps(const struct timespec64 *phase_ts, const struct timespec64 *raw_ts);
#endif /* _LINUX_NTP_INTERNAL_H */ #endif /* _LINUX_NTP_INTERNAL_H */
...@@ -85,7 +85,7 @@ static void bump_cpu_timer(struct k_itimer *timer, u64 now) ...@@ -85,7 +85,7 @@ static void bump_cpu_timer(struct k_itimer *timer, u64 now)
continue; continue;
timer->it.cpu.expires += incr; timer->it.cpu.expires += incr;
timer->it_overrun += 1 << i; timer->it_overrun += 1LL << i;
delta -= incr; delta -= incr;
} }
} }
......
...@@ -81,7 +81,7 @@ int do_clock_gettime(clockid_t which_clock, struct timespec64 *tp) ...@@ -81,7 +81,7 @@ int do_clock_gettime(clockid_t which_clock, struct timespec64 *tp)
ktime_get_ts64(tp); ktime_get_ts64(tp);
break; break;
case CLOCK_BOOTTIME: case CLOCK_BOOTTIME:
get_monotonic_boottime64(tp); ktime_get_boottime_ts64(tp);
break; break;
default: default:
return -EINVAL; return -EINVAL;
......
...@@ -228,21 +228,21 @@ static int posix_ktime_get_ts(clockid_t which_clock, struct timespec64 *tp) ...@@ -228,21 +228,21 @@ static int posix_ktime_get_ts(clockid_t which_clock, struct timespec64 *tp)
*/ */
static int posix_get_monotonic_raw(clockid_t which_clock, struct timespec64 *tp) static int posix_get_monotonic_raw(clockid_t which_clock, struct timespec64 *tp)
{ {
getrawmonotonic64(tp); ktime_get_raw_ts64(tp);
return 0; return 0;
} }
static int posix_get_realtime_coarse(clockid_t which_clock, struct timespec64 *tp) static int posix_get_realtime_coarse(clockid_t which_clock, struct timespec64 *tp)
{ {
*tp = current_kernel_time64(); ktime_get_coarse_real_ts64(tp);
return 0; return 0;
} }
static int posix_get_monotonic_coarse(clockid_t which_clock, static int posix_get_monotonic_coarse(clockid_t which_clock,
struct timespec64 *tp) struct timespec64 *tp)
{ {
*tp = get_monotonic_coarse64(); ktime_get_coarse_ts64(tp);
return 0; return 0;
} }
...@@ -254,13 +254,13 @@ static int posix_get_coarse_res(const clockid_t which_clock, struct timespec64 * ...@@ -254,13 +254,13 @@ static int posix_get_coarse_res(const clockid_t which_clock, struct timespec64 *
static int posix_get_boottime(const clockid_t which_clock, struct timespec64 *tp) static int posix_get_boottime(const clockid_t which_clock, struct timespec64 *tp)
{ {
get_monotonic_boottime64(tp); ktime_get_boottime_ts64(tp);
return 0; return 0;
} }
static int posix_get_tai(clockid_t which_clock, struct timespec64 *tp) static int posix_get_tai(clockid_t which_clock, struct timespec64 *tp)
{ {
timekeeping_clocktai64(tp); ktime_get_clocktai_ts64(tp);
return 0; return 0;
} }
...@@ -283,6 +283,17 @@ static __init int init_posix_timers(void) ...@@ -283,6 +283,17 @@ static __init int init_posix_timers(void)
} }
__initcall(init_posix_timers); __initcall(init_posix_timers);
/*
* The siginfo si_overrun field and the return value of timer_getoverrun(2)
* are of type int. Clamp the overrun value to INT_MAX
*/
static inline int timer_overrun_to_int(struct k_itimer *timr, int baseval)
{
s64 sum = timr->it_overrun_last + (s64)baseval;
return sum > (s64)INT_MAX ? INT_MAX : (int)sum;
}
static void common_hrtimer_rearm(struct k_itimer *timr) static void common_hrtimer_rearm(struct k_itimer *timr)
{ {
struct hrtimer *timer = &timr->it.real.timer; struct hrtimer *timer = &timr->it.real.timer;
...@@ -290,9 +301,8 @@ static void common_hrtimer_rearm(struct k_itimer *timr) ...@@ -290,9 +301,8 @@ static void common_hrtimer_rearm(struct k_itimer *timr)
if (!timr->it_interval) if (!timr->it_interval)
return; return;
timr->it_overrun += (unsigned int) hrtimer_forward(timer, timr->it_overrun += hrtimer_forward(timer, timer->base->get_time(),
timer->base->get_time(), timr->it_interval);
timr->it_interval);
hrtimer_restart(timer); hrtimer_restart(timer);
} }
...@@ -321,10 +331,10 @@ void posixtimer_rearm(struct siginfo *info) ...@@ -321,10 +331,10 @@ void posixtimer_rearm(struct siginfo *info)
timr->it_active = 1; timr->it_active = 1;
timr->it_overrun_last = timr->it_overrun; timr->it_overrun_last = timr->it_overrun;
timr->it_overrun = -1; timr->it_overrun = -1LL;
++timr->it_requeue_pending; ++timr->it_requeue_pending;
info->si_overrun += timr->it_overrun_last; info->si_overrun = timer_overrun_to_int(timr, info->si_overrun);
} }
unlock_timer(timr, flags); unlock_timer(timr, flags);
...@@ -418,9 +428,8 @@ static enum hrtimer_restart posix_timer_fn(struct hrtimer *timer) ...@@ -418,9 +428,8 @@ static enum hrtimer_restart posix_timer_fn(struct hrtimer *timer)
now = ktime_add(now, kj); now = ktime_add(now, kj);
} }
#endif #endif
timr->it_overrun += (unsigned int) timr->it_overrun += hrtimer_forward(timer, now,
hrtimer_forward(timer, now, timr->it_interval);
timr->it_interval);
ret = HRTIMER_RESTART; ret = HRTIMER_RESTART;
++timr->it_requeue_pending; ++timr->it_requeue_pending;
timr->it_active = 1; timr->it_active = 1;
...@@ -524,7 +533,7 @@ static int do_timer_create(clockid_t which_clock, struct sigevent *event, ...@@ -524,7 +533,7 @@ static int do_timer_create(clockid_t which_clock, struct sigevent *event,
new_timer->it_id = (timer_t) new_timer_id; new_timer->it_id = (timer_t) new_timer_id;
new_timer->it_clock = which_clock; new_timer->it_clock = which_clock;
new_timer->kclock = kc; new_timer->kclock = kc;
new_timer->it_overrun = -1; new_timer->it_overrun = -1LL;
if (event) { if (event) {
rcu_read_lock(); rcu_read_lock();
...@@ -645,11 +654,11 @@ static ktime_t common_hrtimer_remaining(struct k_itimer *timr, ktime_t now) ...@@ -645,11 +654,11 @@ static ktime_t common_hrtimer_remaining(struct k_itimer *timr, ktime_t now)
return __hrtimer_expires_remaining_adjusted(timer, now); return __hrtimer_expires_remaining_adjusted(timer, now);
} }
static int common_hrtimer_forward(struct k_itimer *timr, ktime_t now) static s64 common_hrtimer_forward(struct k_itimer *timr, ktime_t now)
{ {
struct hrtimer *timer = &timr->it.real.timer; struct hrtimer *timer = &timr->it.real.timer;
return (int)hrtimer_forward(timer, now, timr->it_interval); return hrtimer_forward(timer, now, timr->it_interval);
} }
/* /*
...@@ -743,7 +752,7 @@ static int do_timer_gettime(timer_t timer_id, struct itimerspec64 *setting) ...@@ -743,7 +752,7 @@ static int do_timer_gettime(timer_t timer_id, struct itimerspec64 *setting)
/* Get the time remaining on a POSIX.1b interval timer. */ /* Get the time remaining on a POSIX.1b interval timer. */
SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id, SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id,
struct itimerspec __user *, setting) struct __kernel_itimerspec __user *, setting)
{ {
struct itimerspec64 cur_setting; struct itimerspec64 cur_setting;
...@@ -755,7 +764,8 @@ SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id, ...@@ -755,7 +764,8 @@ SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id,
return ret; return ret;
} }
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT_32BIT_TIME
COMPAT_SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id, COMPAT_SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id,
struct compat_itimerspec __user *, setting) struct compat_itimerspec __user *, setting)
{ {
...@@ -768,6 +778,7 @@ COMPAT_SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id, ...@@ -768,6 +778,7 @@ COMPAT_SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id,
} }
return ret; return ret;
} }
#endif #endif
/* /*
...@@ -789,7 +800,7 @@ SYSCALL_DEFINE1(timer_getoverrun, timer_t, timer_id) ...@@ -789,7 +800,7 @@ SYSCALL_DEFINE1(timer_getoverrun, timer_t, timer_id)
if (!timr) if (!timr)
return -EINVAL; return -EINVAL;
overrun = timr->it_overrun_last; overrun = timer_overrun_to_int(timr, 0);
unlock_timer(timr, flags); unlock_timer(timr, flags);
return overrun; return overrun;
...@@ -906,8 +917,8 @@ static int do_timer_settime(timer_t timer_id, int flags, ...@@ -906,8 +917,8 @@ static int do_timer_settime(timer_t timer_id, int flags,
/* Set a POSIX.1b interval timer */ /* Set a POSIX.1b interval timer */
SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags, SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags,
const struct itimerspec __user *, new_setting, const struct __kernel_itimerspec __user *, new_setting,
struct itimerspec __user *, old_setting) struct __kernel_itimerspec __user *, old_setting)
{ {
struct itimerspec64 new_spec, old_spec; struct itimerspec64 new_spec, old_spec;
struct itimerspec64 *rtn = old_setting ? &old_spec : NULL; struct itimerspec64 *rtn = old_setting ? &old_spec : NULL;
...@@ -927,7 +938,7 @@ SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags, ...@@ -927,7 +938,7 @@ SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags,
return error; return error;
} }
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT_32BIT_TIME
COMPAT_SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags, COMPAT_SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags,
struct compat_itimerspec __user *, new, struct compat_itimerspec __user *, new,
struct compat_itimerspec __user *, old) struct compat_itimerspec __user *, old)
......
...@@ -19,7 +19,7 @@ struct k_clock { ...@@ -19,7 +19,7 @@ struct k_clock {
void (*timer_get)(struct k_itimer *timr, void (*timer_get)(struct k_itimer *timr,
struct itimerspec64 *cur_setting); struct itimerspec64 *cur_setting);
void (*timer_rearm)(struct k_itimer *timr); void (*timer_rearm)(struct k_itimer *timr);
int (*timer_forward)(struct k_itimer *timr, ktime_t now); s64 (*timer_forward)(struct k_itimer *timr, ktime_t now);
ktime_t (*timer_remaining)(struct k_itimer *timr, ktime_t now); ktime_t (*timer_remaining)(struct k_itimer *timr, ktime_t now);
int (*timer_try_to_cancel)(struct k_itimer *timr); int (*timer_try_to_cancel)(struct k_itimer *timr);
void (*timer_arm)(struct k_itimer *timr, ktime_t expires, void (*timer_arm)(struct k_itimer *timr, ktime_t expires,
......
...@@ -90,7 +90,7 @@ static struct clock_event_device ce_broadcast_hrtimer = { ...@@ -90,7 +90,7 @@ static struct clock_event_device ce_broadcast_hrtimer = {
.max_delta_ticks = ULONG_MAX, .max_delta_ticks = ULONG_MAX,
.mult = 1, .mult = 1,
.shift = 0, .shift = 0,
.cpumask = cpu_all_mask, .cpumask = cpu_possible_mask,
}; };
static enum hrtimer_restart bc_handler(struct hrtimer *t) static enum hrtimer_restart bc_handler(struct hrtimer *t)
......
...@@ -64,7 +64,7 @@ EXPORT_SYMBOL(sys_tz); ...@@ -64,7 +64,7 @@ EXPORT_SYMBOL(sys_tz);
*/ */
SYSCALL_DEFINE1(time, time_t __user *, tloc) SYSCALL_DEFINE1(time, time_t __user *, tloc)
{ {
time_t i = get_seconds(); time_t i = (time_t)ktime_get_real_seconds();
if (tloc) { if (tloc) {
if (put_user(i,tloc)) if (put_user(i,tloc))
...@@ -107,11 +107,9 @@ SYSCALL_DEFINE1(stime, time_t __user *, tptr) ...@@ -107,11 +107,9 @@ SYSCALL_DEFINE1(stime, time_t __user *, tptr)
/* compat_time_t is a 32 bit "long" and needs to get converted. */ /* compat_time_t is a 32 bit "long" and needs to get converted. */
COMPAT_SYSCALL_DEFINE1(time, compat_time_t __user *, tloc) COMPAT_SYSCALL_DEFINE1(time, compat_time_t __user *, tloc)
{ {
struct timeval tv;
compat_time_t i; compat_time_t i;
do_gettimeofday(&tv); i = (compat_time_t)ktime_get_real_seconds();
i = tv.tv_sec;
if (tloc) { if (tloc) {
if (put_user(i,tloc)) if (put_user(i,tloc))
...@@ -931,7 +929,7 @@ int compat_put_timespec64(const struct timespec64 *ts, void __user *uts) ...@@ -931,7 +929,7 @@ int compat_put_timespec64(const struct timespec64 *ts, void __user *uts)
EXPORT_SYMBOL_GPL(compat_put_timespec64); EXPORT_SYMBOL_GPL(compat_put_timespec64);
int get_itimerspec64(struct itimerspec64 *it, int get_itimerspec64(struct itimerspec64 *it,
const struct itimerspec __user *uit) const struct __kernel_itimerspec __user *uit)
{ {
int ret; int ret;
...@@ -946,7 +944,7 @@ int get_itimerspec64(struct itimerspec64 *it, ...@@ -946,7 +944,7 @@ int get_itimerspec64(struct itimerspec64 *it,
EXPORT_SYMBOL_GPL(get_itimerspec64); EXPORT_SYMBOL_GPL(get_itimerspec64);
int put_itimerspec64(const struct itimerspec64 *it, int put_itimerspec64(const struct itimerspec64 *it,
struct itimerspec __user *uit) struct __kernel_itimerspec __user *uit)
{ {
int ret; int ret;
...@@ -959,3 +957,24 @@ int put_itimerspec64(const struct itimerspec64 *it, ...@@ -959,3 +957,24 @@ int put_itimerspec64(const struct itimerspec64 *it,
return ret; return ret;
} }
EXPORT_SYMBOL_GPL(put_itimerspec64); EXPORT_SYMBOL_GPL(put_itimerspec64);
int get_compat_itimerspec64(struct itimerspec64 *its,
const struct compat_itimerspec __user *uits)
{
if (__compat_get_timespec64(&its->it_interval, &uits->it_interval) ||
__compat_get_timespec64(&its->it_value, &uits->it_value))
return -EFAULT;
return 0;
}
EXPORT_SYMBOL_GPL(get_compat_itimerspec64);
int put_compat_itimerspec64(const struct itimerspec64 *its,
struct compat_itimerspec __user *uits)
{
if (__compat_put_timespec64(&its->it_interval, &uits->it_interval) ||
__compat_put_timespec64(&its->it_value, &uits->it_value))
return -EFAULT;
return 0;
}
EXPORT_SYMBOL_GPL(put_compat_itimerspec64);
This diff is collapsed.
...@@ -70,7 +70,7 @@ static int __init tk_debug_sleep_time_init(void) ...@@ -70,7 +70,7 @@ static int __init tk_debug_sleep_time_init(void)
} }
late_initcall(tk_debug_sleep_time_init); late_initcall(tk_debug_sleep_time_init);
void tk_debug_account_sleep_time(struct timespec64 *t) void tk_debug_account_sleep_time(const struct timespec64 *t)
{ {
/* Cap bin index so we don't overflow the array */ /* Cap bin index so we don't overflow the array */
int bin = min(fls(t->tv_sec), NUM_BINS-1); int bin = min(fls(t->tv_sec), NUM_BINS-1);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include <linux/time.h> #include <linux/time.h>
#ifdef CONFIG_DEBUG_FS #ifdef CONFIG_DEBUG_FS
extern void tk_debug_account_sleep_time(struct timespec64 *t); extern void tk_debug_account_sleep_time(const struct timespec64 *t);
#else #else
#define tk_debug_account_sleep_time(x) #define tk_debug_account_sleep_time(x)
#endif #endif
......
...@@ -581,7 +581,7 @@ trigger_dyntick_cpu(struct timer_base *base, struct timer_list *timer) ...@@ -581,7 +581,7 @@ trigger_dyntick_cpu(struct timer_base *base, struct timer_list *timer)
* wheel: * wheel:
*/ */
base->next_expiry = timer->expires; base->next_expiry = timer->expires;
wake_up_nohz_cpu(base->cpu); wake_up_nohz_cpu(base->cpu);
} }
static void static void
...@@ -1657,6 +1657,22 @@ static inline void __run_timers(struct timer_base *base) ...@@ -1657,6 +1657,22 @@ static inline void __run_timers(struct timer_base *base)
raw_spin_lock_irq(&base->lock); raw_spin_lock_irq(&base->lock);
/*
* timer_base::must_forward_clk must be cleared before running
* timers so that any timer functions that call mod_timer() will
* not try to forward the base. Idle tracking / clock forwarding
* logic is only used with BASE_STD timers.
*
* The must_forward_clk flag is cleared unconditionally also for
* the deferrable base. The deferrable base is not affected by idle
* tracking and never forwarded, so clearing the flag is a NOOP.
*
* The fact that the deferrable base is never forwarded can cause
* large variations in granularity for deferrable timers, but they
* can be deferred for long periods due to idle anyway.
*/
base->must_forward_clk = false;
while (time_after_eq(jiffies, base->clk)) { while (time_after_eq(jiffies, base->clk)) {
levels = collect_expired_timers(base, heads); levels = collect_expired_timers(base, heads);
...@@ -1676,19 +1692,6 @@ static __latent_entropy void run_timer_softirq(struct softirq_action *h) ...@@ -1676,19 +1692,6 @@ static __latent_entropy void run_timer_softirq(struct softirq_action *h)
{ {
struct timer_base *base = this_cpu_ptr(&timer_bases[BASE_STD]); struct timer_base *base = this_cpu_ptr(&timer_bases[BASE_STD]);
/*
* must_forward_clk must be cleared before running timers so that any
* timer functions that call mod_timer will not try to forward the
* base. idle trcking / clock forwarding logic is only used with
* BASE_STD timers.
*
* The deferrable base does not do idle tracking at all, so we do
* not forward it. This can result in very large variations in
* granularity for deferrable timers, but they can be deferred for
* long periods due to idle.
*/
base->must_forward_clk = false;
__run_timers(base); __run_timers(base);
if (IS_ENABLED(CONFIG_NO_HZ_COMMON)) if (IS_ENABLED(CONFIG_NO_HZ_COMMON))
__run_timers(this_cpu_ptr(&timer_bases[BASE_DEF])); __run_timers(this_cpu_ptr(&timer_bases[BASE_DEF]));
......
...@@ -134,6 +134,11 @@ int main(int argv, char **argc) ...@@ -134,6 +134,11 @@ int main(int argv, char **argc)
printf(" %lld.%i(act)", ppm/1000, abs((int)(ppm%1000))); printf(" %lld.%i(act)", ppm/1000, abs((int)(ppm%1000)));
if (llabs(eppm - ppm) > 1000) { if (llabs(eppm - ppm) > 1000) {
if (tx1.offset || tx2.offset ||
tx1.freq != tx2.freq || tx1.tick != tx2.tick) {
printf(" [SKIP]\n");
return ksft_exit_skip("The clock was adjusted externally. Shutdown NTPd or other time sync daemons\n");
}
printf(" [FAILED]\n"); printf(" [FAILED]\n");
return ksft_exit_fail(); return ksft_exit_fail();
} }
......
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