Make ARM's sched_clock generic + 64 bit friendly
Subsystems (18)
v2 cover Make ARM's sched_clock generic + 64 bit friendly
This is mostly a resend of a patch series I sent a little over a month ago. I've reordered the patches so that John can pick up the first three and get a generic sched_clock layer without having to take the 64 bit patches. The last three patches add 64 bit support and move the architected timers on ARM64 and ARM to use it.
Stephen Boyd (6):
ARM: sched_clock: Remove unused needs_suspend member
ARM: sched_clock: Return suspended count earlier
sched_clock: Make ARM's sched_clock generic for all architectures
sched_clock: Add support for >32 bit sched_clock
ARM: arch_timer: Move to setup_sched_clock_64()
arm64: Move to generic sched_clock infrastructure
arch/arm/Kconfig | 1 +
arch/arm/common/timer-sp.c | 2 +-
arch/arm/kernel/Makefile | 2 +-
arch/arm/kernel/arch_timer.c | 16 +--
arch/arm/kernel/time.c | 4 +-
arch/arm/mach-davinci/time.c | 2 +-
arch/arm/mach-imx/time.c | 2 +-
arch/arm/mach-integrator/integrator_ap.c | 2 +-
arch/arm/mach-ixp4xx/common.c | 2 +-
arch/arm/mach-mmp/time.c | 2 +-
arch/arm/mach-msm/timer.c | 2 +-
arch/arm/mach-omap1/time.c | 2 +-
arch/arm/mach-omap2/timer.c | 2 +-
arch/arm/mach-pxa/time.c | 2 +-
arch/arm/mach-sa1100/time.c | 2 +-
arch/arm/mach-u300/timer.c | 2 +-
arch/arm/plat-iop/time.c | 2 +-
arch/arm/plat-omap/counter_32k.c | 2 +-
arch/arm/plat-orion/time.c | 2 +-
arch/arm/plat-samsung/samsung-time.c | 2 +-
arch/arm/plat-versatile/sched-clock.c | 2 +-
arch/arm64/Kconfig | 1 +
arch/arm64/kernel/time.c | 11 +-
drivers/clocksource/bcm2835_timer.c | 2 +-
drivers/clocksource/clksrc-dbx500-prcmu.c | 3 +-
drivers/clocksource/dw_apb_timer_of.c | 2 +-
drivers/clocksource/mxs_timer.c | 2 +-
drivers/clocksource/nomadik-mtu.c | 2 +-
drivers/clocksource/samsung_pwm_timer.c | 2 +-
drivers/clocksource/tegra20_timer.c | 2 +-
drivers/clocksource/time-armada-370-xp.c | 2 +-
drivers/clocksource/timer-marco.c | 2 +-
drivers/clocksource/timer-prima2.c | 2 +-
.../include/asm => include/linux}/sched_clock.h | 14 ++-
init/Kconfig | 3 +
init/main.c | 2 +
kernel/time/Makefile | 1 +
{arch/arm/kernel => kernel/time}/sched_clock.c | 114 +++++++++++++++------
38 files changed, 132 insertions(+), 92 deletions(-)
rename {arch/arm/include/asm => include/linux}/sched_clock.h (62%)
rename {arch/arm/kernel => kernel/time}/sched_clock.c (74%)Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation
PATCH v2 1/6 ARM: sched_clock: Remove unused needs_suspend member
The needs_suspend member is unused now that we always do the suspend/resume handling (see 6a4dae5 (ARM: 7565/1: sched: stop sched_clock() during suspend, 2012-10-23)).
--- arch/arm/kernel/sched_clock.c | 1 - 1 file changed, 1 deletion(-)
arch/arm/kernel/sched_clock.c +0 -1
@@ -24,7 +24,6 @@ struct clock_data {u32 mult;u32 shift;bool suspended; -bool needs_suspend; };static void sched_clock_poll (unsigned long wrap_ticks);
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation
PATCH v2 2/6 ARM: sched_clock: Return suspended count earlier
In reply to Stephen BoydIf we're suspended and sched_clock() is called we're going to read the hardware one more time and throw away that value and return back the cached value we saved during the suspend callback. This is wasteful. Let's short circuit all that and return the cached value as early as possible if we're suspended.
--- arch/arm/kernel/sched_clock.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/arm/kernel/sched_clock.c +3 -3
@@ -55,9 +55,6 @@ static unsigned long long notrace cyc_to_sched_clock(u32 cyc, u32 mask)u64 epoch_ns;u32 epoch_cyc; -if (cd.suspended) -return cd.epoch_ns; -/* * Load the epoch_cyc and epoch_ns atomically. We do this by * ensuring that we always write epoch_cyc, epoch_ns and
@@ -174,6 +171,9 @@ unsigned long long __read_mostly (*sched_clock_func)(void) = sched_clock_32;unsigned long long notrace sched_clock (void ) { +if (cd.suspended) +return cd.epoch_ns; +return sched_clock_func (); }
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation
PATCH v2 3/6 sched_clock: Make ARM's sched_clock generic for all architectures
In reply to Stephen BoydNothing about the sched_clock implementation in the ARM port is specific to the architecture. Generalize the code so that other architectures can use it by selecting GENERIC_SCHED_CLOCK.
---
arch/arm/Kconfig | 1 +
arch/arm/common/timer-sp.c | 2 +-
arch/arm/kernel/Makefile | 2 +-
arch/arm/kernel/arch_timer.c | 2 +-
arch/arm/kernel/time.c | 4 +---
arch/arm/mach-davinci/time.c | 2 +-
arch/arm/mach-imx/time.c | 2 +-
arch/arm/mach-integrator/integrator_ap.c | 2 +-
arch/arm/mach-ixp4xx/common.c | 2 +-
arch/arm/mach-mmp/time.c | 2 +-
arch/arm/mach-msm/timer.c | 2 +-
arch/arm/mach-omap1/time.c | 2 +-
arch/arm/mach-omap2/timer.c | 2 +-
arch/arm/mach-pxa/time.c | 2 +-
arch/arm/mach-sa1100/time.c | 2 +-
arch/arm/mach-u300/timer.c | 2 +-
arch/arm/plat-iop/time.c | 2 +-
arch/arm/plat-omap/counter_32k.c | 2 +-
arch/arm/plat-orion/time.c | 2 +-
arch/arm/plat-samsung/samsung-time.c | 2 +-
arch/arm/plat-versatile/sched-clock.c | 2 +-
drivers/clocksource/bcm2835_timer.c | 2 +-
drivers/clocksource/clksrc-dbx500-prcmu.c | 3 +--
drivers/clocksource/dw_apb_timer_of.c | 2 +-
drivers/clocksource/mxs_timer.c | 2 +-
drivers/clocksource/nomadik-mtu.c | 2 +-
drivers/clocksource/samsung_pwm_timer.c | 2 +-
drivers/clocksource/tegra20_timer.c | 2 +-
drivers/clocksource/time-armada-370-xp.c | 2 +-
drivers/clocksource/timer-marco.c | 2 +-
drivers/clocksource/timer-prima2.c | 2 +-
{arch/arm/include/asm => include/linux}/sched_clock.h | 9 +++++++--
init/Kconfig | 3 +++
init/main.c | 2 ++
kernel/time/Makefile | 1 +
{arch/arm/kernel => kernel/time}/sched_clock.c | 3 +--
36 files changed, 45 insertions(+), 37 deletions(-)
rename {arch/arm/include/asm => include/linux}/sched_clock.h (75%)
rename {arch/arm/kernel => kernel/time}/sched_clock.c (99%)arch/arm/Kconfig +1 -0
@@ -14,6 +14,7 @@ config ARM select GENERIC_IRQ_PROBE select GENERIC_IRQ_SHOW select GENERIC_PCI_IOMAP + select GENERIC_SCHED_CLOCK select GENERIC_SMP_IDLE_THREAD select GENERIC_IDLE_POLL_SETUP select GENERIC_STRNCPY_FROM_USER
arch/arm/common/timer-sp.c +1 -1
@@ -28,8 +28,8 @@#include <linux/of.h> #include <linux/of_address.h> #include <linux/of_irq.h> +#include <linux/sched_clock.h> -#include <asm/sched_clock.h> #include <asm/hardware/arm_timer.h> #include <asm/hardware/timer-sp.h>
arch/arm/kernel/Makefile +1 -1
@@ -16,7 +16,7 @@ CFLAGS_REMOVE_return_address.o = -pg # Object file lists. obj-y := elf.o entry-armv.o entry-common.o irq.o opcodes.o \ - process.o ptrace.o return_address.o sched_clock.o \ + process.o ptrace.o return_address.o \ setup.o signal.o stacktrace.o sys_arm.o time.o traps.o obj-$(CONFIG_ATAGS) += atags_parse.o
arch/arm/kernel/arch_timer.c +1 -1
@@ -11,9 +11,9 @@#include <linux/init.h> #include <linux/types.h> #include <linux/errno.h> +#include <linux/sched_clock.h> #include <asm/delay.h> -#include <asm/sched_clock.h> #include <clocksource/arm_arch_timer.h>
arch/arm/kernel/time.c +1 -3
@@ -24,9 +24,9 @@#include <linux/timer.h> #include <linux/clocksource.h> #include <linux/irq.h> +#include <linux/sched_clock.h> #include <asm/thread_info.h> -#include <asm/sched_clock.h> #include <asm/stacktrace.h> #include <asm/mach/arch.h> #include <asm/mach/time.h>
@@ -120,6 +120,4 @@ void __init time_init(void) machine_desc->init_time (); elseclocksource_of_init (); - -sched_clock_postinit (); }
arch/arm/mach-davinci/time.c +1 -1
@@ -18,8 +18,8 @@#include <linux/clk.h> #include <linux/err.h> #include <linux/platform_device.h> +#include <linux/sched_clock.h> -#include <asm/sched_clock.h> #include <asm/mach/irq.h> #include <asm/mach/time.h>
arch/arm/mach-imx/time.c +1 -1
@@ -26,8 +26,8 @@#include <linux/clockchips.h> #include <linux/clk.h> #include <linux/err.h> +#include <linux/sched_clock.h> -#include <asm/sched_clock.h> #include <asm/mach/time.h> #include "common.h"
arch/arm/mach-integrator/integrator_ap.c +1 -1
@@ -41,6 +41,7 @@#include <linux/stat.h> #include <linux/sys_soc.h> #include <linux/termios.h> +#include <linux/sched_clock.h> #include <video/vga.h> #include <mach/hardware.h>
@@ -49,7 +50,6 @@#include <asm/setup.h> #include <asm/param.h> /* HZ */ #include <asm/mach-types.h> -#include <asm/sched_clock.h> #include <mach/lm.h> #include <mach/irqs.h>
arch/arm/mach-ixp4xx/common.c +1 -1
@@ -30,6 +30,7 @@#include <linux/export.h> #include <linux/gpio.h> #include <linux/cpu.h> +#include <linux/sched_clock.h> #include <mach/udc.h> #include <mach/hardware.h>
@@ -38,7 +39,6 @@#include <asm/pgtable.h> #include <asm/page.h> #include <asm/irq.h> -#include <asm/sched_clock.h> #include <asm/system_misc.h> #include <asm/mach/map.h>
arch/arm/mach-mmp/time.c +1 -1
@@ -28,8 +28,8 @@#include <linux/of.h> #include <linux/of_address.h> #include <linux/of_irq.h> +#include <linux/sched_clock.h> -#include <asm/sched_clock.h> #include <mach/addr-map.h> #include <mach/regs-timers.h> #include <mach/regs-apbc.h>
arch/arm/mach-msm/timer.c +1 -1
@@ -23,10 +23,10 @@#include <linux/of.h> #include <linux/of_address.h> #include <linux/of_irq.h> +#include <linux/sched_clock.h> #include <asm/mach/time.h> #include <asm/localtimer.h> -#include <asm/sched_clock.h> #include "common.h"
arch/arm/mach-omap1/time.c +1 -1
@@ -43,9 +43,9 @@#include <linux/clocksource.h> #include <linux/clockchips.h> #include <linux/io.h> +#include <linux/sched_clock.h> #include <asm/irq.h> -#include <asm/sched_clock.h> #include <mach/hardware.h> #include <asm/mach/irq.h>
arch/arm/mach-omap2/timer.c +1 -1
@@ -41,10 +41,10 @@#include <linux/of_irq.h> #include <linux/platform_device.h> #include <linux/platform_data/dmtimer-omap.h> +#include <linux/sched_clock.h> #include <asm/mach/time.h> #include <asm/smp_twd.h> -#include <asm/sched_clock.h> #include "omap_hwmod.h" #include "omap_device.h"
arch/arm/mach-pxa/time.c +1 -1
@@ -16,11 +16,11 @@#include <linux/init.h> #include <linux/interrupt.h> #include <linux/clockchips.h> +#include <linux/sched_clock.h> #include <asm/div64.h> #include <asm/mach/irq.h> #include <asm/mach/time.h> -#include <asm/sched_clock.h> #include <mach/regs-ost.h> #include <mach/irqs.h>
arch/arm/mach-sa1100/time.c +1 -1
@@ -14,9 +14,9 @@#include <linux/irq.h> #include <linux/timex.h> #include <linux/clockchips.h> +#include <linux/sched_clock.h> #include <asm/mach/time.h> -#include <asm/sched_clock.h> #include <mach/hardware.h> #include <mach/irqs.h>
arch/arm/mach-u300/timer.c +1 -1
@@ -18,12 +18,12 @@#include <linux/clk.h> #include <linux/err.h> #include <linux/irq.h> +#include <linux/sched_clock.h> #include <mach/hardware.h> #include <mach/irqs.h> /* Generic stuff */ -#include <asm/sched_clock.h> #include <asm/mach/map.h> #include <asm/mach/time.h>
arch/arm/plat-iop/time.c +1 -1
@@ -22,9 +22,9 @@#include <linux/clocksource.h> #include <linux/clockchips.h> #include <linux/export.h> +#include <linux/sched_clock.h> #include <mach/hardware.h> #include <asm/irq.h> -#include <asm/sched_clock.h> #include <asm/uaccess.h> #include <asm/mach/irq.h> #include <asm/mach/time.h>
arch/arm/plat-omap/counter_32k.c +1 -1
@@ -18,9 +18,9 @@#include <linux/err.h> #include <linux/io.h> #include <linux/clocksource.h> +#include <linux/sched_clock.h> #include <asm/mach/time.h> -#include <asm/sched_clock.h> #include <plat/counter-32k.h>
arch/arm/plat-orion/time.c +1 -1
@@ -16,7 +16,7 @@#include <linux/clockchips.h> #include <linux/interrupt.h> #include <linux/irq.h> -#include <asm/sched_clock.h> +#include <linux/sched_clock.h> /* * MBus bridge block registers.
arch/arm/plat-samsung/samsung-time.c +1 -1
@@ -15,12 +15,12 @@#include <linux/clk.h> #include <linux/clockchips.h> #include <linux/platform_device.h> +#include <linux/sched_clock.h> #include <asm/smp_twd.h> #include <asm/mach/time.h> #include <asm/mach/arch.h> #include <asm/mach/map.h> -#include <asm/sched_clock.h> #include <mach/map.h> #include <plat/devs.h>
arch/arm/plat-versatile/sched-clock.c +1 -1
@@ -20,8 +20,8 @@*/ #include <linux/kernel.h> #include <linux/io.h> +#include <linux/sched_clock.h> -#include <asm/sched_clock.h> #include <plat/sched_clock.h> static void __iomem *ctr;
drivers/clocksource/bcm2835_timer.c +1 -1
@@ -28,8 +28,8 @@#include <linux/of_platform.h> #include <linux/slab.h> #include <linux/string.h> +#include <linux/sched_clock.h> -#include <asm/sched_clock.h> #include <asm/irq.h> #define REG_CONTROL 0x00
drivers/clocksource/clksrc-dbx500-prcmu.c +1 -2
@@ -14,8 +14,7 @@*/ #include <linux/clockchips.h> #include <linux/clksrc-dbx500-prcmu.h> - -#include <asm/sched_clock.h> +#include <linux/sched_clock.h> #define RATE_32K 32768
drivers/clocksource/dw_apb_timer_of.c +1 -1
@@ -20,9 +20,9 @@#include <linux/of.h> #include <linux/of_address.h> #include <linux/of_irq.h> +#include <linux/sched_clock.h> #include <asm/mach/time.h> -#include <asm/sched_clock.h> static void timer_get_base_and_rate (struct device_node *np,void __iomem **base,u32 *rate)
drivers/clocksource/mxs_timer.c +1 -1
@@ -29,9 +29,9 @@#include <linux/of_address.h> #include <linux/of_irq.h> #include <linux/stmp_device.h> +#include <linux/sched_clock.h> #include <asm/mach/time.h> -#include <asm/sched_clock.h> /* * There are 2 versions of the timrot on Freescale MXS-based SoCs.
drivers/clocksource/nomadik-mtu.c +1 -1
@@ -18,8 +18,8 @@#include <linux/delay.h> #include <linux/err.h> #include <linux/platform_data/clocksource-nomadik-mtu.h> +#include <linux/sched_clock.h> #include <asm/mach/time.h> -#include <asm/sched_clock.h> /* * The MTU device hosts four different counters, with 4 set of
drivers/clocksource/samsung_pwm_timer.c +1 -1
@@ -21,10 +21,10 @@#include <linux/of_irq.h> #include <linux/platform_device.h> #include <linux/slab.h> +#include <linux/sched_clock.h> #include <clocksource/samsung_pwm.h> -#include <asm/sched_clock.h> /* * Clocksource driver
drivers/clocksource/tegra20_timer.c +1 -1
@@ -26,10 +26,10 @@#include <linux/io.h> #include <linux/of_address.h> #include <linux/of_irq.h> +#include <linux/sched_clock.h> #include <asm/mach/time.h> #include <asm/smp_twd.h> -#include <asm/sched_clock.h> #define RTC_SECONDS 0x08#define RTC_SHADOW_SECONDS 0x0c
drivers/clocksource/time-armada-370-xp.c +1 -1
@@ -27,8 +27,8 @@#include <linux/of_address.h> #include <linux/irq.h> #include <linux/module.h> +#include <linux/sched_clock.h> -#include <asm/sched_clock.h> #include <asm/localtimer.h> #include <linux/percpu.h> /*
drivers/clocksource/timer-marco.c +1 -1
@@ -17,7 +17,7 @@#include <linux/of.h> #include <linux/of_irq.h> #include <linux/of_address.h> -#include <asm/sched_clock.h> +#include <linux/sched_clock.h> #include <asm/localtimer.h> #include <asm/mach/time.h>
drivers/clocksource/timer-prima2.c +1 -1
@@ -18,7 +18,7 @@#include <linux/of.h> #include <linux/of_irq.h> #include <linux/of_address.h> -#include <asm/sched_clock.h> +#include <linux/sched_clock.h> #include <asm/mach/time.h> #define SIRFSOC_TIMER_COUNTER_LO 0x0000
include/linux/sched_clock.h renamed from arch/arm/include/asm/sched_clock.h +7 -2
@@ -5,10 +5,15 @@* it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. */ -#ifndef ASM_SCHED_CLOCK -#define ASM_SCHED_CLOCK +#ifndef LINUX_SCHED_CLOCK +#define LINUX_SCHED_CLOCK +#ifdef CONFIG_GENERIC_SCHED_CLOCK extern void sched_clock_postinit (void ); +#else +static inline void sched_clock_postinit (void ) { } +#endif +extern void setup_sched_clock (u32 (*read)(void ),int bits,unsigned long rate);extern unsigned long long (*sched_clock_func)(void );
init/Kconfig +3 -0
@@ -757,6 +757,9 @@ config LOG_BUF_SHIFT config HAVE_UNSTABLE_SCHED_CLOCK bool +config GENERIC_SCHED_CLOCK + bool + # # For architectures that want to enable the support for NUMA-affine scheduler # balancing logic:
init/main.c +2 -0
@@ -74,6 +74,7 @@#include <linux/ptrace.h> #include <linux/blkdev.h> #include <linux/elevator.h> +#include <linux/sched_clock.h> #include <asm/io.h> #include <asm/bugs.h>
@@ -555,6 +556,7 @@ asmlinkage void __init start_kernel(void)softirq_init ();timekeeping_init ();time_init (); +sched_clock_postinit ();profile_init ();call_function_init ();WARN (!irqs_disabled (),"Interrupts were enabled early\n" );
kernel/time/Makefile +1 -0
@@ -4,6 +4,7 @@ obj-y += timeconv.o posix-clock.o alarmtimer.o obj-$(CONFIG_GENERIC_CLOCKEVENTS_BUILD) += clockevents.o obj-$(CONFIG_GENERIC_CLOCKEVENTS) += tick-common.o obj-$(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) += tick-broadcast.o +obj-$(CONFIG_GENERIC_SCHED_CLOCK) += sched_clock.o obj-$(CONFIG_TICK_ONESHOT) += tick-oneshot.o obj-$(CONFIG_TICK_ONESHOT) += tick-sched.o obj-$(CONFIG_TIMER_STATS) += timer_stats.o
kernel/time/sched_clock.c renamed from arch/arm/kernel/sched_clock.c +1 -2
@@ -13,8 +13,7 @@#include <linux/sched.h> #include <linux/syscore_ops.h> #include <linux/timer.h> - -#include <asm/sched_clock.h> +#include <linux/sched_clock.h> struct clock_data {u64 epoch_ns;
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation
Re: [PATCHv2 3/6] sched_clock: Make ARM's sched_clock generic for all architectures
Hi Stephen,
Quoted 30 lines · Stephen Boyd
Nothing about the
sched_clockimplementation in the ARM port is specific to the architecture. Generalize the code so that other architectures can use it by selectingGENERIC_SCHED_CLOCK.Signed-off-by Stephen Boyd <[email protected]>--- arch/arm/Kconfig | 1 + arch/arm/common/timer-sp.c | 2 +- arch/arm/kernel/Makefile | 2 +- arch/arm/kernel/arch_timer.c | 2 +- arch/arm/kernel/time.c | 4 +--- arch/arm/mach-davinci/time.c | 2 +- arch/arm/mach-imx/time.c | 2 +- arch/arm/mach-integrator/integrator_ap.c | 2 +- arch/arm/mach-ixp4xx/common.c | 2 +- arch/arm/mach-mmp/time.c | 2 +- arch/arm/mach-msm/timer.c | 2 +- arch/arm/mach-omap1/time.c | 2 +- arch/arm/mach-omap2/timer.c | 2 +- arch/arm/mach-pxa/time.c | 2 +- arch/arm/mach-sa1100/time.c | 2 +- arch/arm/mach-u300/timer.c | 2 +- arch/arm/plat-iop/time.c | 2 +- arch/arm/plat-omap/counter_32k.c | 2 +- arch/arm/plat-orion/time.c | 2 +- arch/arm/plat-samsung/samsung-time.c | 2 +- arch/arm/plat-versatile/sched-clock.c | 2 +- drivers/clocksource/bcm2835_timer.c | 2 +- drivers/clocksource/clksrc-dbx500-prcmu.c | 3 +-- drivers/clocksource/dw_apb_timer_of.c | 2 +-
Quoted 8 lines
drivers/clocksource/mxs_timer.c | 2 +-
drivers/clocksource/nomadik-mtu.c | 2 +-
drivers/clocksource/samsung_pwm_timer.c | 2 +-
drivers/clocksource/tegra20_timer.c | 2 +-
drivers/clocksource/time-armada-370-xp.c | 2 +-
drivers/clocksource/timer-marco.c | 2 +-
drivers/clocksource/timer-prima2.c | 2 +-
{arch/arm/include/asm => include/linux}/sched_clock.h | 9 +++++++--Shouldn't we just merge this header into the existing linux/sched.h?
baruch
Quoted 7 lines
init/Kconfig | 3 +++
init/main.c | 2 ++
kernel/time/Makefile | 1 +
{arch/arm/kernel => kernel/time}/sched_clock.c | 3 +--
36 files changed, 45 insertions(+), 37 deletions(-)
rename {arch/arm/include/asm => include/linux}/sched_clock.h (75%)
rename {arch/arm/kernel => kernel/time}/sched_clock.c (99%)Signature · 3 lines
http://baruch.siach.name/blog/ ~. .~ Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
- baruch at tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -Re: [PATCHv2 3/6] sched_clock: Make ARM's sched_clock generic for all architectures
Quoted 41 lines · Baruch Siach
Hi Stephen,
Quoted 30 lines · Stephen Boyd
Nothing about the
sched_clockimplementation in the ARM port is specific to the architecture. Generalize the code so that other architectures can use it by selectingGENERIC_SCHED_CLOCK.Signed-off-by Stephen Boyd <[email protected]>--- arch/arm/Kconfig | 1 + arch/arm/common/timer-sp.c | 2 +- arch/arm/kernel/Makefile | 2 +- arch/arm/kernel/arch_timer.c | 2 +- arch/arm/kernel/time.c | 4 +--- arch/arm/mach-davinci/time.c | 2 +- arch/arm/mach-imx/time.c | 2 +- arch/arm/mach-integrator/integrator_ap.c | 2 +- arch/arm/mach-ixp4xx/common.c | 2 +- arch/arm/mach-mmp/time.c | 2 +- arch/arm/mach-msm/timer.c | 2 +- arch/arm/mach-omap1/time.c | 2 +- arch/arm/mach-omap2/timer.c | 2 +- arch/arm/mach-pxa/time.c | 2 +- arch/arm/mach-sa1100/time.c | 2 +- arch/arm/mach-u300/timer.c | 2 +- arch/arm/plat-iop/time.c | 2 +- arch/arm/plat-omap/counter_32k.c | 2 +- arch/arm/plat-orion/time.c | 2 +- arch/arm/plat-samsung/samsung-time.c | 2 +- arch/arm/plat-versatile/sched-clock.c | 2 +- drivers/clocksource/bcm2835_timer.c | 2 +- drivers/clocksource/clksrc-dbx500-prcmu.c | 3 +-- drivers/clocksource/dw_apb_timer_of.c | 2 +-Quoted 8 lines
drivers/clocksource/mxs_timer.c | 2 +- drivers/clocksource/nomadik-mtu.c | 2 +- drivers/clocksource/samsung_pwm_timer.c | 2 +- drivers/clocksource/tegra20_timer.c | 2 +- drivers/clocksource/time-armada-370-xp.c | 2 +- drivers/clocksource/timer-marco.c | 2 +- drivers/clocksource/timer-prima2.c | 2 +- {arch/arm/include/asm => include/linux}/sched_clock.h | 9 +++++++--
Quoted 1 line
Shouldn't we just merge this header into the existing
linux/sched.h?
I don't know. John/Thomas, any thoughts? One benefit with it this way is that we don't have to recompile all the timer drivers if we change sched.h for other reasons.
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Re: [PATCHv2 3/6] sched_clock: Make ARM's sched_clock generic for all architectures
Quoted 9 lines · Stephen Boyd
Quoted 5 lines · Baruch Siach
Hi Stephen,
Quoted 1 line · Stephen Boyd
{arch/arm/include/asm => include/linux}/sched_clock.h | 9 +++++++--Shouldn't we just merge this header into the existing
linux/sched.h?I don't know. John/Thomas, any thoughts? One benefit with it this way is that we don't have to recompile all the timer drivers if we change
sched.hfor other reasons.
Yea, I'm fine keeping it separate for now. We can merge them together if we see fit later.
But if anyone feels particularly strongly, let me know.
thanks
-john
Re: [PATCHv2 3/6] sched_clock: Make ARM's sched_clock generic for all architectures
Quoted 7 lines · John Stultz
Quoted 6 lines · Stephen Boyd
Quoted 5 lines · Baruch Siach
Hi Stephen,
Quoted 1 line · Stephen Boyd
{arch/arm/include/asm => include/linux}/sched_clock.h | 9 +++++++--Shouldn't we just merge this header into the existing
linux/sched.h?
Quoted 8 lines
Quoted 3 lines
I don't know. John/Thomas, any thoughts? One benefit with it this way is that we don't have to recompile all the timer drivers if we change
sched.hfor other reasons.Yea, I'm fine keeping it separate for now. We can merge them together if we see fit later.
But if anyone feels particularly strongly, let me know.
I'd suggest keeping it separate. linux/sched.h is already a big source of rebuilds because it's included by virtually the entire kernel. Having linux/sched.h carved up into smaller chunks (maybe moving the definition of task_struct and associated bits out of it) would probably be a good idea.
Re: [PATCHv2 3/6] sched_clock: Make ARM's sched_clock generic for all architectures
In reply to Stephen BoydQuoted 34 lines · Stephen Boyd
Nothing about the
sched_clockimplementation in the ARM port is specific to the architecture. Generalize the code so that other architectures can use it by selectingGENERIC_SCHED_CLOCK.Signed-off-by Stephen Boyd <[email protected]>--- arch/arm/Kconfig | 1 + arch/arm/common/timer-sp.c | 2 +- arch/arm/kernel/Makefile | 2 +- arch/arm/kernel/arch_timer.c | 2 +- arch/arm/kernel/time.c | 4 +--- arch/arm/mach-davinci/time.c | 2 +- arch/arm/mach-imx/time.c | 2 +- arch/arm/mach-integrator/integrator_ap.c | 2 +- arch/arm/mach-ixp4xx/common.c | 2 +- arch/arm/mach-mmp/time.c | 2 +- arch/arm/mach-msm/timer.c | 2 +- arch/arm/mach-omap1/time.c | 2 +- arch/arm/mach-omap2/timer.c | 2 +- arch/arm/mach-pxa/time.c | 2 +- arch/arm/mach-sa1100/time.c | 2 +- arch/arm/mach-u300/timer.c | 2 +- arch/arm/plat-iop/time.c | 2 +- arch/arm/plat-omap/counter_32k.c | 2 +- arch/arm/plat-orion/time.c | 2 +- arch/arm/plat-samsung/samsung-time.c | 2 +- arch/arm/plat-versatile/sched-clock.c | 2 +- drivers/clocksource/bcm2835_timer.c | 2 +- drivers/clocksource/clksrc-dbx500-prcmu.c | 3 +-- drivers/clocksource/dw_apb_timer_of.c | 2 +- drivers/clocksource/mxs_timer.c | 2 +- drivers/clocksource/nomadik-mtu.c | 2 +- drivers/clocksource/samsung_pwm_timer.c | 2 +- drivers/clocksource/tegra20_timer.c | 2 +-
Quoted 8 lines
drivers/clocksource/time-armada-370-xp.c | 2 +-
drivers/clocksource/timer-marco.c | 2 +-
drivers/clocksource/timer-prima2.c | 2 +-
{arch/arm/include/asm => include/linux}/sched_clock.h | 9 +++++++--
init/Kconfig | 3 +++
init/main.c | 2 ++
kernel/time/Makefile | 1 +
{arch/arm/kernel => kernel/time}/sched_clock.c | 3 +--This causes build failures when doing a simple merge with the arm-soc tree:
==> build/clps711x_defconfig/faillog <== /git/arm-soc/arch/arm/mach-clps711x/common.c:37:29: fatal error: asm/sched_clock.h: No such file or directory
#include <asm/sched_clock.h>
^==> build/imx_v6_v7_defconfig/faillog <== /git/arm-soc/drivers/clocksource/vf_pit_timer.c:15:29: fatal error: asm/sched_clock.h: No such file or directory
#include <asm/sched_clock.h>
How about adding back a temporary arch/arm/include/asm/sched_clock.h that only contains "#include <linux/sched_clock.h>" so we can change those two files after the merge and still get a bisectible history?
Arnd
Re: [PATCHv2 3/6] sched_clock: Make ARM's sched_clock generic for all architectures
Quoted 8 lines · Arnd Bergmann
This causes build failures when doing a simple merge with the arm-soc tree:
==> build/clps711x_defconfig/faillog <== /git/arm-soc/arch/arm/mach-clps711x/common.c:37:29: fatal error:
asm/sched_clock.h: No such file or directory#include <asm/sched_clock.h> ^
Quoted 8 lines
==> build/imx_v6_v7_defconfig/faillog <== /git/arm-soc/drivers/clocksource/vf_pit_timer.c:15:29: fatal error:
asm/sched_clock.h: No such file or directory
#include <asm/sched_clock.h>How about adding back a temporary
arch/arm/include/asm/sched_clock.hthat only contains "#include <linux/sched_clock.h>" so we can change those two files after the merge and still get a bisectible history?
Sounds fine. John can you add this patch on top?
----8<-----
Subject: [PATCH] sched_clock: Add temporary asm/sched_clock.h
Some new users of the ARM sched_clock framework are going through the arm-soc tree. Before 38ff87f (sched_clock: Make ARM's sched_clock generic for all architectures, 2013-06-01) the header file was in asm, but now it's in linux. One solution would be to do an evil merge of the arm-soc tree and fix up the asm users, but it's easier to add a temporary asm header that we can remove along with the few stragglers after the merge window is over.
--- arch/arm/include/asm/sched_clock.h | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 arch/arm/include/asm/sched_clock.h
arch/arm/include/asm/sched_clock.h new file +4 -0
@@ -0,0 +1,4 @@ +/* You shouldn't include this file. Use linux/sched_clock.h instead. +* Temporary file until all asm/sched_clock.h users are gone +*/ +#include <linux/sched_clock.h>
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Re: [PATCHv2 3/6] sched_clock: Make ARM's sched_clock generic for all architectures
Quoted 12 lines · Stephen Boyd
Quoted 11 lines · Arnd Bergmann
This causes build failures when doing a simple merge with the arm-soc tree:
==> build/clps711x_defconfig/faillog <== /git/arm-soc/arch/arm/mach-clps711x/common.c:37:29: fatal error:
asm/sched_clock.h: No such file or directory#include <asm/sched_clock.h> ^==> build/imx_v6_v7_defconfig/faillog <== /git/arm-soc/drivers/clocksource/vf_pit_timer.c:15:29: fatal error:
asm/sched_clock.h: No such file or directory
#include <asm/sched_clock.h>
Quoted 5 lines
Quoted 4 lines
How about adding back a temporary
arch/arm/include/asm/sched_clock.hthat only contains "#include <linux/sched_clock.h>" so we can change those two files after the merge and still get a bisectible history?Sounds fine. John can you add this patch on top?
Thanks. I've queued this and will send it on to Thomas here shortly.
thanks
-john
Re: [PATCHv2 3/6] sched_clock: Make ARM's sched_clock generic for all architectures
Quoted 15 lines · John Stultz
Quoted 14 lines · Stephen Boyd
Quoted 13 lines · Arnd Bergmann
This causes build failures when doing a simple merge with the arm-soc tree:
==> build/clps711x_defconfig/faillog <== /git/arm-soc/arch/arm/mach-clps711x/common.c:37:29: fatal error:
asm/sched_clock.h: No such file or directory#include <asm/sched_clock.h> ^==> build/imx_v6_v7_defconfig/faillog <== /git/arm-soc/drivers/clocksource/vf_pit_timer.c:15:29: fatal error:
asm/sched_clock.h: No such file or directory
#include <asm/sched_clock.h>
Quoted 7 lines
Quoted 5 lines
Quoted 4 lines
How about adding back a temporary
arch/arm/include/asm/sched_clock.hthat only contains "#include <linux/sched_clock.h>" so we can change those two files after the merge and still get a bisectible history?Sounds fine. John can you add this patch on top?
Thanks. I've queued this and will send it on to Thomas here shortly.
Thanks John. Can you send this off to the tip tree? I think we'll need to merge tip/timers into arm-soc so I can send the rest of my "kill ARM local timer API" series through and this patch helps make that more palatable.
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Re: [PATCHv2 3/6] sched_clock: Make ARM's sched_clock generic for all architectures
Quoted 20 lines · Stephen Boyd
Quoted 19 lines · John Stultz
Quoted 18 lines · Stephen Boyd
Quoted 17 lines · Arnd Bergmann
This causes build failures when doing a simple merge with the arm-soc tree:
==> build/clps711x_defconfig/faillog <== /git/arm-soc/arch/arm/mach-clps711x/common.c:37:29: fatal error:
asm/sched_clock.h: No such file or directory#include <asm/sched_clock.h> ^==> build/imx_v6_v7_defconfig/faillog <== /git/arm-soc/drivers/clocksource/vf_pit_timer.c:15:29: fatal error:
asm/sched_clock.h: No such file or directory
#include <asm/sched_clock.h>How about adding back a temporary
arch/arm/include/asm/sched_clock.hthat only contains "#include <linux/sched_clock.h>" so we can change those two files after the merge and still get a bisectible history?
Quoted 6 lines
Quoted 2 lines
Quoted 1 line
Sounds fine. John can you add this patch on top?
Thanks. I've queued this and will send it on to Thomas here shortly.
Thanks John. Can you send this off to the tip tree? I think we'll need to merge tip/timers into arm-soc so I can send the rest of my "kill ARM local timer API" series through and this patch helps make that more palatable.
Thanks for the reminder! Just sent the pull request.
thanks
-john
PATCH v2 4/6 sched_clock: Add support for >32 bit sched_clock
In reply to Stephen BoydThe ARM architected system counter has at least 56 useable bits. Add support for counters with more than 32 bits to the generic sched_clock implementation so we can avoid the complexity of dealing with wrap-around on these devices while benefiting from the irqtime accounting and suspend/resume handling that the generic sched_clock code already has.
--- include/linux/sched_clock.h | 2 + kernel/time/sched_clock.c | 101 ++++++++++++++++++++++++++++++++------------ 2 files changed, 77 insertions(+), 26 deletions(-)
include/linux/sched_clock.h +2 -0
@@ -18,4 +18,6 @@ extern void setup_sched_clock(u32 (*read)(void), int bits, unsigned long rate);extern unsigned long long (*sched_clock_func)(void ); +extern void setup_sched_clock_64 (u64 (*read)(void ),int bits, +unsigned long rate);#endif
kernel/time/sched_clock.c +75 -26
157 lines not on this page · raw message
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation
Re: [PATCHv2 4/6] sched_clock: Add support for >32 bit sched_clock
Quoted 6 lines · Stephen Boyd
The ARM architected system counter has at least 56 useable bits. Add support for counters with more than 32 bits to the generic
sched_clockimplementation so we can avoid the complexity of dealing with wrap-around on these devices while benefiting from the irqtime accounting and suspend/resume handling that the genericsched_clockcode already has.
This looks like a horrid hack to me.
kernel/time/sched_clock.c static unsigned long long notrace sched_clock_32(void) · line 188
Quoted 4 lines
kernel/time/sched_clock.c +4
-0+static unsigned long long notrace sched_clock_64 (void ) +{ +u64 cyc =read_sched_clock_64 () - cd.epoch_ns; +return cyc * cd.mult;
So, the use of cd.mult implies that the return value from read_sched_clock_64() is not nanoseconds but something else. But then we subtract it from the nanoseconds epoch - which has to be nanoseconds because you simply return that when suspended.
Quoted 4 lines
kernel/time/sched_clock.c +4
-0+} + +void __init +setup_sched_clock_64 (u64 (*read)(void ),int bits,unsigned long rate)
kernel/time/sched_clock.c static unsigned long long notrace sched_clock_32(void) · line 202
Quoted 10 lines
kernel/time/sched_clock.c +10
-0+{ +if (cd.rate > rate) +return ; + +BUG_ON (bits <=32 ); +WARN_ON (!irqs_disabled ()); + read_sched_clock_64 = read; + sched_clock_func = sched_clock_64; + cd.rate = rate; + cd.mult =NSEC_PER_SEC / rate;
Here, you don't check that the (2^bits) * mult results in a wrap of the resulting 64-bit number, which is a _basic_ requirement for sched_clock (hence all the code for <=32bit clocks, otherwise we wouldn't need this complexity in the first place.)
So, I think this whole approach is broken.
Re: [PATCHv2 4/6] sched_clock: Add support for >32 bit sched_clock
Quoted 9 lines · Russell King - ARM Linux
kernel/time/sched_clock.c static unsigned long long notrace sched_clock_32(void) · line 188
Quoted 4 lines · Stephen Boyd
kernel/time/sched_clock.c +4
-0+static unsigned long long notrace sched_clock_64 (void ) +{ +u64 cyc =read_sched_clock_64 () - cd.epoch_ns; +return cyc * cd.mult;So, the use of cd.mult implies that the return value from
read_sched_clock_64()is not nanoseconds but something else. But then we subtract it from the nanoseconds epoch - which has to be nanoseconds because you simply return that when suspended.
You're right, it is confusing and broken. I was thinking we may need a union for epoch_ns but I will try to make it always nanoseconds and see if that makes the code clearer.
Quoted 11 lines
Quoted 11 lines
kernel/time/sched_clock.c +10
-0+} + +void __init +setup_sched_clock_64 (u64 (*read)(void ),int bits,unsigned long rate) +{ +if (cd.rate > rate) +return ; + +BUG_ON (bits <=32 ); +WARN_ON (!irqs_disabled ());
Quoted 8 lines
kernel/time/sched_clock.c static unsigned long long notrace sched_clock_32(void) · line 202
Quoted 4 lines
kernel/time/sched_clock.c +4
-0+ read_sched_clock_64 = read; + sched_clock_func = sched_clock_64; + cd.rate = rate; + cd.mult =NSEC_PER_SEC / rate;Here, you don't check that the (2^bits) * mult results in a wrap of the resulting 64-bit number, which is a _basic_ requirement for
sched_clock(hence all the code for <=32bit clocks, otherwise we wouldn't need this complexity in the first place.)
Ok I will use clocks_calc_mult_shift() here.
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Re: [PATCHv2 4/6] sched_clock: Add support for >32 bit sched_clock
Quoted 21 lines · Stephen Boyd
Quoted 11 lines · Russell King - ARM Linux
Quoted 10 lines · Stephen Boyd
kernel/time/sched_clock.c +10
-0+} + +void __init +setup_sched_clock_64 (u64 (*read)(void ),int bits,unsigned long rate) +{ +if (cd.rate > rate) +return ; + +BUG_ON (bits <=32 ); +WARN_ON (!irqs_disabled ());Quoted 8 lines
kernel/time/sched_clock.c static unsigned long long notrace sched_clock_32(void) · line 202
Quoted 4 lines
kernel/time/sched_clock.c +4
-0+ read_sched_clock_64 = read; + sched_clock_func = sched_clock_64; + cd.rate = rate; + cd.mult =NSEC_PER_SEC / rate;Here, you don't check that the (2^bits) * mult results in a wrap of the resulting 64-bit number, which is a _basic_ requirement for
sched_clock(hence all the code for <=32bit clocks, otherwise we wouldn't need this complexity in the first place.)
Quoted 1 line
Ok I will use
clocks_calc_mult_shift()here.
No, that's not the problem.
If you have a 56-bit clock which ticks at a period of 1ns, then cd.rate = 1, and your sched_clock() values will be truncated to 56-bits. The scheduler always _requires_ 64-bits from sched_clock. That's why we have the complicated code to extend the 32-bits-or-less to a _full_ 64-bit value.
Let me make this clearer: sched_clock() return values _must_ without exception monotonically increment from zero to 2^64-1 and then wrap back to zero. No other behaviour is acceptable for sched_clock().
Re: [PATCHv2 4/6] sched_clock: Add support for >32 bit sched_clock
Quoted 30 lines · Russell King - ARM Linux
Quoted 20 lines · Stephen Boyd
Quoted 11 lines · Russell King - ARM Linux
Quoted 10 lines · Stephen Boyd
kernel/time/sched_clock.c +10
-0+} + +void __init +setup_sched_clock_64 (u64 (*read)(void ),int bits,unsigned long rate) +{ +if (cd.rate > rate) +return ; + +BUG_ON (bits <=32 ); +WARN_ON (!irqs_disabled ());Quoted 8 lines
kernel/time/sched_clock.c static unsigned long long notrace sched_clock_32(void) · line 202
Quoted 4 lines
kernel/time/sched_clock.c +4
-0+ read_sched_clock_64 = read; + sched_clock_func = sched_clock_64; + cd.rate = rate; + cd.mult =NSEC_PER_SEC / rate;Here, you don't check that the (2^bits) * mult results in a wrap of the resulting 64-bit number, which is a _basic_ requirement for
sched_clock(hence all the code for <=32bit clocks, otherwise we wouldn't need this complexity in the first place.)Quoted 1 line
Ok I will use
clocks_calc_mult_shift()here.No, that's not the problem.
If you have a 56-bit clock which ticks at a period of 1ns, then cd.rate = 1, and your
sched_clock()values will be truncated to 56-bits. The scheduler always _requires_ 64-bits fromsched_clock. That's why we have the complicated code to extend the 32-bits-or-less to a _full_ 64-bit value.
Quoted 3 lines
Let me make this clearer:
sched_clock()return values _must_ without exception monotonically increment from zero to 2^64-1 and then wrap back to zero. No other behaviour is acceptable forsched_clock().
Ok so you're saying if we have less than 64 bits of useable information we _must_ do something to find where the wraparound will occur and adjust for it so that epoch_ns is always incrementing until 2^64-1. Fair enough. I was trying to avoid more work because on arm architected timer platforms it takes many years for that to happen.
I'll see what I can do.
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Re: [PATCHv2 4/6] sched_clock: Add support for >32 bit sched_clock
Quoted 11 lines · Stephen Boyd
Quoted 9 lines · Russell King - ARM Linux
If you have a 56-bit clock which ticks at a period of 1ns, then cd.rate = 1, and your
sched_clock()values will be truncated to 56-bits. The scheduler always _requires_ 64-bits fromsched_clock. That's why we have the complicated code to extend the 32-bits-or-less to a _full_ 64-bit value.Let me make this clearer:
sched_clock()return values _must_ without exception monotonically increment from zero to 2^64-1 and then wrap back to zero. No other behaviour is acceptable forsched_clock().
Quoted 7 lines
Ok so you're saying if we have less than 64 bits of useable information we _must_ do something to find where the wraparound will occur and adjust for it so that
epoch_nsis always incrementing until 2^64-1. Fair enough. I was trying to avoid more work because on arm architected timer platforms it takes many years for that to happen.I'll see what I can do.
Well, 56 bits at 1ns intervals is 833 days (2^56 / (1000000000*60*60*24)). We used to say that 497 days was enough several years ago, and that got fixed. We used to say 640K was enough memory for anything, and that got fixed.
Whenever there's a limit, that limit will always be exceeded. 833 days uptime has already been exceeded by ARM machines - I have one at the moment:
11:17:58 up 1082 days, 11:53, 14 users, load average: 1.20, 1.28, 1.32
and I would not be surprised if there were others around.
Re: [PATCHv2 4/6] sched_clock: Add support for >32 bit sched_clock
Quoted 18 lines · Russell King - ARM Linux
Quoted 17 lines · Stephen Boyd
Quoted 9 lines · Russell King - ARM Linux
If you have a 56-bit clock which ticks at a period of 1ns, then cd.rate = 1, and your
sched_clock()values will be truncated to 56-bits. The scheduler always _requires_ 64-bits fromsched_clock. That's why we have the complicated code to extend the 32-bits-or-less to a _full_ 64-bit value.Let me make this clearer:
sched_clock()return values _must_ without exception monotonically increment from zero to 2^64-1 and then wrap back to zero. No other behaviour is acceptable forsched_clock().Ok so you're saying if we have less than 64 bits of useable information we _must_ do something to find where the wraparound will occur and adjust for it so that
epoch_nsis always incrementing until 2^64-1. Fair enough. I was trying to avoid more work because on arm architected timer platforms it takes many years for that to happen.
Quoted 6 lines
Quoted 1 line
I'll see what I can do.
Well, 56 bits at 1ns intervals is 833 days (2^56 / (1000000000*60*60*24)). We used to say that 497 days was enough several years ago, and that got fixed. We used to say 640K was enough memory for anything, and that got fixed.
The ARM ARM states a minimum resolution of 40 years AND at least 56-bits of resolution. So a 1Gz counter would have to have more that 56 bits.
Rob
Catalin Marinas
maintainerRe: [PATCHv2 4/6] sched_clock: Add support for >32 bit sched_clock
Quoted 21 lines · Rob Herring
Quoted 20 lines · Russell King - ARM Linux
Quoted 18 lines · Stephen Boyd
Quoted 9 lines · Russell King - ARM Linux
If you have a 56-bit clock which ticks at a period of 1ns, then cd.rate = 1, and your
sched_clock()values will be truncated to 56-bits. The scheduler always _requires_ 64-bits fromsched_clock. That's why we have the complicated code to extend the 32-bits-or-less to a _full_ 64-bit value.Let me make this clearer:
sched_clock()return values _must_ without exception monotonically increment from zero to 2^64-1 and then wrap back to zero. No other behaviour is acceptable forsched_clock().Ok so you're saying if we have less than 64 bits of useable information we _must_ do something to find where the wraparound will occur and adjust for it so that
epoch_nsis always incrementing until 2^64-1. Fair enough. I was trying to avoid more work because on arm architected timer platforms it takes many years for that to happen.I'll see what I can do.
Quoted 7 lines
Quoted 4 lines
Well, 56 bits at 1ns intervals is 833 days (2^56 / (1000000000*60*60*24)). We used to say that 497 days was enough several years ago, and that got fixed. We used to say 640K was enough memory for anything, and that got fixed.
The ARM ARM states a minimum resolution of 40 years AND at least 56-bits of resolution. So a 1Gz counter would have to have more that 56 bits.
At a quick calculation, with a full 64-bit counter and 40-year roll-over we can have maximum 14.6GHz clock. So we shouldn't just mask the top 8-bit of the counter as the bottom 56 could roll over in much less time.
Signature · 1 line
Catalin
Re: [PATCHv2 4/6] sched_clock: Add support for >32 bit sched_clock
In reply to Russell King - ARM LinuxQuoted 32 lines · Russell King - ARM Linux
Quoted 21 lines · Stephen Boyd
Quoted 11 lines · Russell King - ARM Linux
Quoted 10 lines · Stephen Boyd
kernel/time/sched_clock.c +10
-0+} + +void __init +setup_sched_clock_64 (u64 (*read)(void ),int bits,unsigned long rate) +{ +if (cd.rate > rate) +return ; + +BUG_ON (bits <=32 ); +WARN_ON (!irqs_disabled ());Quoted 8 lines
kernel/time/sched_clock.c static unsigned long long notrace sched_clock_32(void) · line 202
Quoted 4 lines
kernel/time/sched_clock.c +4
-0+ read_sched_clock_64 = read; + sched_clock_func = sched_clock_64; + cd.rate = rate; + cd.mult =NSEC_PER_SEC / rate;Here, you don't check that the (2^bits) * mult results in a wrap of the resulting 64-bit number, which is a _basic_ requirement for
sched_clock(hence all the code for <=32bit clocks, otherwise we wouldn't need this complexity in the first place.)Quoted 1 line
Ok I will use
clocks_calc_mult_shift()here.No, that's not the problem.
If you have a 56-bit clock which ticks at a period of 1ns, then cd.rate = 1, and your
sched_clock()values will be truncated to 56-bits. The scheduler always _requires_ 64-bits fromsched_clock. That's why we have the complicated code to extend the 32-bits-or-less to a _full_ 64-bit value.
Quoted 3 lines
Let me make this clearer:
sched_clock()return values _must_ without exception monotonically increment from zero to 2^64-1 and then wrap back to zero. No other behaviour is acceptable forsched_clock().
Probably a trivial question.I was wondering why this particular requirement exists in the first place.I looked into this commit 112f38a4a3 but couldn't gather the reason.
Quoted 5 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCHv2 4/6] sched_clock: Add support for >32 bit sched_clock
Quoted 3 lines · anish singh
Probably a trivial question.I was wondering why this particular requirement exists in the first place.I looked into this commit
112f38a4a3but couldn't gather the reason.
You're looking at a commit introducing an implementation. The requirement isn't driven by the implementation. It's driven by the code and the maths in the core scheduler, and its been a requirement for years.
sched_clock() needs to be monotonic, and needs to wrap at 64-bit, because calculations are done by comparing the difference of two 64-bit values returned from this function.
Let's take a trivial example - if you have a 16 bit counter, and you have a value of 0xc000 ns, and next time you read it, it has value 0x0001 ns, then what value do you end up with when you calculate the time passed using 64-bit maths.
That's 0x0000000000000001 - 0x000000000000c000. The answer is a very big number which is not the correct 16385. This means that things like process timeslice counting and scheduler fairness is compromised - I'd expect even more so if you're running RT and this is being used to provide guarantees.
Re: [PATCHv2 4/6] sched_clock: Add support for >32 bit sched_clock
On Mon, Jun 10, 2013 at 9:08 PM, Russell King - ARM Linux <[email protected]> wrote:
Least I can do is to say "Thanks".
Quoted 5 lines · anish singh
Quoted 3 lines
Probably a trivial question.I was wondering why this particular requirement exists in the first place.I looked into this commit
112f38a4a3but couldn't gather the reason.
Quoted 7 lines
You're looking at a commit introducing an implementation. The requirement isn't driven by the implementation. It's driven by the code and the maths in the core scheduler, and its been a requirement for years.
sched_clock()needs to be monotonic, and needs to wrap at 64-bit, because calculations are done by comparing the difference of two 64-bit values returned from this function.
Yes, and this is the question.If it is 32 bit then also it can overflow but it will happen relatively fast.So I guess that is the reason why we use 64 bit and this will avoid recalculations for recalibration.
Quoted 9 lines
Let's take a trivial example - if you have a 16 bit counter, and you have a value of
0xc000ns, and next time you read it, it has value0x0001ns, then what value do you end up with when you calculate the time passed using 64-bit maths.That's
0x0000000000000001-0x000000000000c000. The answer is a very big number which is not the correct 16385. This means that things like process timeslice counting and scheduler fairness is compromised - I'd expect even
So you mean when counter overflows the scheduler doesn't handle it?
Quoted 1 line
more so if you're running RT and this is being used to provide guarantees.
Re: [PATCHv2 4/6] sched_clock: Add support for >32 bit sched_clock
Quoted 13 lines · anish singh
On Mon, Jun 10, 2013 at 9:08 PM, Russell King - ARM Linux <[email protected]> wrote:
Least I can do is to say "Thanks".
Quoted 9 lines · anish singh
Quoted 3 lines
Probably a trivial question.I was wondering why this particular requirement exists in the first place.I looked into this commit
112f38a4a3but couldn't gather the reason.You're looking at a commit introducing an implementation. The requirement isn't driven by the implementation. It's driven by the code and the maths in the core scheduler, and its been a requirement for years.
Quoted 7 lines
Quoted 3 lines
sched_clock()needs to be monotonic, and needs to wrap at 64-bit, because calculations are done by comparing the difference of two 64-bit values returned from this function.Yes, and this is the question.If it is 32 bit then also it can overflow but it will happen relatively fast.So I guess that is the reason why we use 64 bit and this will avoid recalculations for recalibration.
And that's why 112f38a4a3 is there - to ensure that we extend a 32-bit or smaller counter all the way up to the full 64-bits. This replaces the previous generation code which only extended it to 63-bits. Problems were reported!
Quoted 10 lines
Quoted 8 lines
Let's take a trivial example - if you have a 16 bit counter, and you have a value of
0xc000ns, and next time you read it, it has value0x0001ns, then what value do you end up with when you calculate the time passed using 64-bit maths.That's
0x0000000000000001-0x000000000000c000. The answer is a very big number which is not the correct 16385. This means that things like process timeslice counting and scheduler fairness is compromised - I'd expect evenSo you mean when counter overflows the scheduler doesn't handle it?
There is no handling of counter overflows at scheduler level because the specification for sched_clock() is that this function _will_ return a monotonically increasing 64-bit value from 0 to the maximum 64-bit value.
The reason for this is that there are popular architectures around which do this natively, so the powers that be do not want additional useless code cluttering their architectures.
PATCH v2 5/6 ARM: arch_timer: Move to setup_sched_clock_64()
In reply to Stephen BoydRegister with the ARM sched_clock framework now that it supports 64 bits. This fixes two problems with the current sched_clock support for machines using the architected timers. First off, we don't subtract the start value from subsequent sched_clock calls so we can potentially start off with sched_clock returning gigantic numbers. Second, there is no support for suspend/resume handling so problems such as discussed in 6a4dae5 (ARM: 7565/1:
sched: stop sched_clock() during suspend, 2012-10-23) can happen without this patch.
--- arch/arm/kernel/arch_timer.c | 14 ++------------ include/linux/sched_clock.h | 3 --- kernel/time/sched_clock.c | 3 ++- 3 files changed, 4 insertions(+), 16 deletions(-)
arch/arm/kernel/arch_timer.c +2 -12
@@ -22,13 +22,6 @@ static unsigned long arch_timer_read_counter_long(void)return arch_timer_read_counter (); } -static u32 sched_clock_mult__read_mostly ; - -static unsigned long long notrace arch_timer_sched_clock (void ) -{ -return arch_timer_read_counter () * sched_clock_mult; -} -static struct delay_timer arch_delay_timer;static void __init arch_timer_delay_timer_register (void )
@@ -48,11 +41,8 @@ int __init arch_timer_arch_init(void)arch_timer_delay_timer_register (); -/* Cache the sched_clock multiplier to save a divide in the hot path. */ - sched_clock_mult =NSEC_PER_SEC / arch_timer_rate; - sched_clock_func = arch_timer_sched_clock; -pr_info ("sched_clock: ARM arch timer >56 bits at %ukHz, resolution %uns\n" , - arch_timer_rate /1000 , sched_clock_mult); +/* 56 bits minimum, so we assume worst case rollover */ +setup_sched_clock_64 (arch_timer_read_counter,56 , arch_timer_rate);return 0 ; }
include/linux/sched_clock.h +0 -3
@@ -15,9 +15,6 @@ static inline void sched_clock_postinit(void) { }#endif extern void setup_sched_clock (u32 (*read)(void ),int bits,unsigned long rate); - -extern unsigned long long (*sched_clock_func)(void ); -extern void setup_sched_clock_64 (u64 (*read)(void ),int bits,unsigned long rate);#endif
kernel/time/sched_clock.c +2 -1
@@ -180,7 +180,8 @@ static unsigned long long notrace sched_clock_32(void)return cyc_to_sched_clock (cyc, sched_clock_mask); } -unsigned long long __read_mostly (*sched_clock_func)(void ) = sched_clock_32; +static unsigned long long __read_mostly +(*sched_clock_func)(void ) = sched_clock_32;static unsigned long long notrace sched_clock_64 (void ) {
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation
PATCH v2 6/6 arm64: Move to generic sched_clock infrastructure
In reply to Stephen BoydUse the generic sched_clock infrastructure instead of rolling our own. This has the added benefit of fixing suspend/resume as outlined in 6a4dae5 (ARM: 7565/1: sched: stop sched_clock() during suspend, 2012-10-23) and correcting the timestamps when the hardware returns a value instead of 0 upon the first read.
--- arch/arm64/Kconfig | 1 + arch/arm64/kernel/time.c | 11 ++--------- 2 files changed, 3 insertions(+), 9 deletions(-)
arch/arm64/Kconfig +1 -0
@@ -13,6 +13,7 @@ config ARM64 select GENERIC_IOMAP select GENERIC_IRQ_PROBE select GENERIC_IRQ_SHOW + select GENERIC_SCHED_CLOCK select GENERIC_SMP_IDLE_THREAD select GENERIC_TIME_VSYSCALL select HARDIRQS_SW_RESEND
arch/arm64/kernel/time.c +2 -9
@@ -33,6 +33,7 @@#include <linux/irq.h> #include <linux/delay.h> #include <linux/clocksource.h> +#include <linux/sched_clock.h> #include <clocksource/arm_arch_timer.h>
@@ -61,13 +62,6 @@ unsigned long profile_pc(struct pt_regs *regs)EXPORT_SYMBOL (profile_pc);#endif -static u64 sched_clock_mult__read_mostly ; - -unsigned long long notrace sched_clock (void ) -{ -return arch_timer_read_counter () * sched_clock_mult; -} -int read_current_timer (unsigned long *timer_value) { *timer_value =arch_timer_read_counter ();
@@ -84,8 +78,7 @@ void __init time_init(void)if (!arch_timer_rate)panic ("Unable to initialise architected timer.\n" ); -/* Cache the sched_clock multiplier to save a divide in the hot path. */ - sched_clock_mult =NSEC_PER_SEC / arch_timer_rate; +setup_sched_clock_64 (arch_timer_read_counter,56 , arch_timer_rate);/* Calibrate the delay loop directly */ lpj_fine = arch_timer_rate /HZ ;
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation
Hi Stephen,
Quoted 5 lines · Stephen Boyd
This is mostly a resend of a patch series I sent a little over a month ago. I've reordered the patches so that John can pick up the first three and get a generic
sched_clocklayer without having to take the 64 bit patches. The last three patches add 64 bit support and move the architected timers on ARM64 and ARM to use it.
You can have my
for xtensa target, with the dw_apb_timer driver (no real hardware yet).
Thanks for pushing this series.
baruch
Quoted 59 lines
Stephen Boyd (6):
ARM:sched_clock: Remove unusedneeds_suspendmember
ARM:sched_clock: Return suspended count earlier
sched_clock: Make ARM'ssched_clockgeneric for all architectures
sched_clock: Add support for >32 bitsched_clock
ARM:arch_timer: Move tosetup_sched_clock_64()
arm64: Move to genericsched_clockinfrastructurearch/arm/Kconfig | 1 + arch/arm/common/timer-sp.c | 2 +- arch/arm/kernel/Makefile | 2 +- arch/arm/kernel/arch_timer.c | 16 +-- arch/arm/kernel/time.c | 4 +- arch/arm/mach-davinci/time.c | 2 +- arch/arm/mach-imx/time.c | 2 +- arch/arm/mach-integrator/integrator_ap.c | 2 +- arch/arm/mach-ixp4xx/common.c | 2 +- arch/arm/mach-mmp/time.c | 2 +- arch/arm/mach-msm/timer.c | 2 +- arch/arm/mach-omap1/time.c | 2 +- arch/arm/mach-omap2/timer.c | 2 +- arch/arm/mach-pxa/time.c | 2 +- arch/arm/mach-sa1100/time.c | 2 +- arch/arm/mach-u300/timer.c | 2 +- arch/arm/plat-iop/time.c | 2 +- arch/arm/plat-omap/counter_32k.c | 2 +- arch/arm/plat-orion/time.c | 2 +- arch/arm/plat-samsung/samsung-time.c | 2 +- arch/arm/plat-versatile/sched-clock.c | 2 +- arch/arm64/Kconfig | 1 + arch/arm64/kernel/time.c | 11 +- drivers/clocksource/bcm2835_timer.c | 2 +- drivers/clocksource/clksrc-dbx500-prcmu.c | 3 +- drivers/clocksource/dw_apb_timer_of.c | 2 +- drivers/clocksource/mxs_timer.c | 2 +- drivers/clocksource/nomadik-mtu.c | 2 +- drivers/clocksource/samsung_pwm_timer.c | 2 +- drivers/clocksource/tegra20_timer.c | 2 +- drivers/clocksource/time-armada-370-xp.c | 2 +- drivers/clocksource/timer-marco.c | 2 +- drivers/clocksource/timer-prima2.c | 2 +- .../include/asm => include/linux}/sched_clock.h | 14 ++- init/Kconfig | 3 + init/main.c | 2 + kernel/time/Makefile | 1 + {arch/arm/kernel => kernel/time}/sched_clock.c | 114 +++++++++++++++------ 38 files changed, 132 insertions(+), 92 deletions(-) rename {arch/arm/include/asm => include/linux}/sched_clock.h (62%) rename {arch/arm/kernel => kernel/time}/sched_clock.c (74%)Signature · 8 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel at lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Signature · 3 lines
http://baruch.siach.name/blog/ ~. .~ Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
- baruch at tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -Quoted 5 lines · Stephen Boyd
This is mostly a resend of a patch series I sent a little over a month ago. I've reordered the patches so that John can pick up the first three and get a generic
sched_clocklayer without having to take the 64 bit patches. The last three patches add 64 bit support and move the architected timers on ARM64 and ARM to use it.
Yea, so from the initial look over it, I think I'm happy with queuing the first three patches, although I'd like to get some acks from arm folks on at least the first two, just so no one is surprised with it going through the -tip tree.
It looks like the arm64 bit stuff needs a few more iterations w/ Russell, so I'll not touch those.
We still have a ways to go to consolidate x86 into this (need to handle pv hooks), but it should provide a base to get some of the simpler arches sharing the same infrastructure.
Also I suspect we can maybe further combine this with the kernel/sched/clock.c code, but I think this is a good start for now.
thanks
-john
Will Deacon
Acked-byQuoted 8 lines · John Stultz
Quoted 5 lines · Stephen Boyd
This is mostly a resend of a patch series I sent a little over a month ago. I've reordered the patches so that John can pick up the first three and get a generic
sched_clocklayer without having to take the 64 bit patches. The last three patches add 64 bit support and move the architected timers on ARM64 and ARM to use it.
Quoted 4 lines
Yea, so from the initial look over it, I think I'm happy with queuing the first three patches, although I'd like to get some acks from arm folks on at least the first two, just so no one is surprised with it going through the -tip tree.
The first two patches are pretty simple so, FWIW, you can add my ack on those:
Will
Quoted 8 lines · Will Deacon
Quoted 7 lines · John Stultz
Quoted 5 lines · Stephen Boyd
This is mostly a resend of a patch series I sent a little over a month ago. I've reordered the patches so that John can pick up the first three and get a generic
sched_clocklayer without having to take the 64 bit patches. The last three patches add 64 bit support and move the architected timers on ARM64 and ARM to use it.
Quoted 7 lines
Quoted 4 lines
Yea, so from the initial look over it, I think I'm happy with queuing the first three patches, although I'd like to get some acks from arm folks on at least the first two, just so no one is surprised with it going through the -tip tree.
The first two patches are pretty simple so, FWIW, you can add my ack on those:
Acked-by Will Deacon <[email protected]>
Thanks! Added to the commits.
-john
Hi John,
Quoted 9 lines · John Stultz
Quoted 8 lines · Will Deacon
Quoted 7 lines · John Stultz
Quoted 5 lines · Stephen Boyd
This is mostly a resend of a patch series I sent a little over a month ago. I've reordered the patches so that John can pick up the first three and get a generic
sched_clocklayer without having to take the 64 bit patches. The last three patches add 64 bit support and move the architected timers on ARM64 and ARM to use it.
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines
Yea, so from the initial look over it, I think I'm happy with queuing the first three patches, although I'd like to get some acks from arm folks on at least the first two, just so no one is surprised with it going through the -tip tree.
The first two patches are pretty simple so, FWIW, you can add my ack on those:
Acked-by Will Deacon <[email protected]>Thanks! Added to the commits.
What is the status of this series then? Is there a chance of seeing it in 3.11? I want to base some xtensa architecture work on this, so I'd like to know whether there is a stable base to start from.
baruch
Signature · 3 lines
http://baruch.siach.name/blog/ ~. .~ Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
- baruch at tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -Quoted 15 lines · Baruch Siach
Hi John,
Quoted 12 lines · John Stultz
Quoted 11 lines · Will Deacon
Quoted 10 lines · John Stultz
Quoted 5 lines · Stephen Boyd
This is mostly a resend of a patch series I sent a little over a month ago. I've reordered the patches so that John can pick up the first three and get a generic
sched_clocklayer without having to take the 64 bit patches. The last three patches add 64 bit support and move the architected timers on ARM64 and ARM to use it.Yea, so from the initial look over it, I think I'm happy with queuing the first three patches, although I'd like to get some acks from arm folks on at least the first two, just so no one is surprised with it going through the -tip tree.
Quoted 7 lines
Quoted 4 lines
Quoted 3 lines
The first two patches are pretty simple so, FWIW, you can add my ack on those:
Acked-by Will Deacon <[email protected]>Thanks! Added to the commits.
What is the status of this series then? Is there a chance of seeing it in 3.11? I want to base some xtensa architecture work on this, so I'd like to know whether there is a stable base to start from.
I've got the first three in my internal tree, and was going to send it by Thomas for 3.11 this week.
Thanks for the ping!
-john
Hi John,
Quoted 16 lines · John Stultz
Quoted 15 lines · Baruch Siach
Quoted 14 lines · John Stultz
Quoted 13 lines · Will Deacon
Quoted 10 lines · John Stultz
Quoted 5 lines · Stephen Boyd
This is mostly a resend of a patch series I sent a little over a month ago. I've reordered the patches so that John can pick up the first three and get a generic
sched_clocklayer without having to take the 64 bit patches. The last three patches add 64 bit support and move the architected timers on ARM64 and ARM to use it.Yea, so from the initial look over it, I think I'm happy with queuing the first three patches, although I'd like to get some acks from arm folks on at least the first two, just so no one is surprised with it going through the -tip tree.
The first two patches are pretty simple so, FWIW, you can add my ack on those:
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Quoted 1 line
Acked-by Will Deacon <[email protected]>Thanks! Added to the commits.
What is the status of this series then? Is there a chance of seeing it in 3.11? I want to base some xtensa architecture work on this, so I'd like to know whether there is a stable base to start from.
I've got the first three in my internal tree, and was going to send it by Thomas for 3.11 this week.
Good, thanks. This means that the xtensa ccount sched_clock patch
(http://lists.linux-xtensa.org/pipermail/linux-xtensa/Week-of-Mon-20130617/001077.html)
that depends on the third patch in this series, can go in for 3.11, if the xtensa maintainer acks it (added to Cc). How should we handle the dependency then?
baruch
Signature · 3 lines
http://baruch.siach.name/blog/ ~. .~ Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
- baruch at tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -Quoted 7 lines · Baruch Siach
Quoted 2 lines
to send
Quoted 1 line
it by Thomas for 3.11 this week.
Good, thanks. This means that the xtensa ccount
sched_clockpatch
(http://lists.linux-xtensa.org/pipermail/linux-xtensa/Week-of-Mon-20130617/001077.html)
that depends on the third patch in this series, can go in for 3.11, if the xtensa maintainer acks it (added to Cc). How should we handle the dependency then?
Well, Thomas hasn't picked them up yet, so he could still object, so no promises yet :)
As for the dependency, either you can base your patches off of tip/timers/core (once the patches land there) and send a pull request to the maintainer (so he gets the dependencies in -tip), or we can see about queuing your changes via tip/timers/core (assuming you get maintainer acks).
thanks
-john