Marc Zyngier | 985c067 | 2012-03-05 11:49:30 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Based on arch/arm/kernel/time.c |
| 3 | * |
| 4 | * Copyright (C) 1991, 1992, 1995 Linus Torvalds |
| 5 | * Modifications for ARM (C) 1994-2001 Russell King |
| 6 | * Copyright (C) 2012 ARM Ltd. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License version 2 as |
| 10 | * published by the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | */ |
| 20 | |
| 21 | #include <linux/export.h> |
| 22 | #include <linux/kernel.h> |
| 23 | #include <linux/interrupt.h> |
| 24 | #include <linux/time.h> |
| 25 | #include <linux/init.h> |
| 26 | #include <linux/sched.h> |
| 27 | #include <linux/smp.h> |
| 28 | #include <linux/timex.h> |
| 29 | #include <linux/errno.h> |
| 30 | #include <linux/profile.h> |
| 31 | #include <linux/syscore_ops.h> |
| 32 | #include <linux/timer.h> |
| 33 | #include <linux/irq.h> |
Mark Rutland | 1aee5d7 | 2012-11-20 10:06:00 +0000 | [diff] [blame] | 34 | #include <linux/delay.h> |
Rob Herring | 0583fe4 | 2013-04-10 18:27:51 -0500 | [diff] [blame] | 35 | #include <linux/clocksource.h> |
Marc Zyngier | 985c067 | 2012-03-05 11:49:30 +0000 | [diff] [blame] | 36 | |
Mark Rutland | 1aee5d7 | 2012-11-20 10:06:00 +0000 | [diff] [blame] | 37 | #include <clocksource/arm_arch_timer.h> |
Marc Zyngier | 985c067 | 2012-03-05 11:49:30 +0000 | [diff] [blame] | 38 | |
| 39 | #include <asm/thread_info.h> |
| 40 | #include <asm/stacktrace.h> |
| 41 | |
| 42 | #ifdef CONFIG_SMP |
| 43 | unsigned long profile_pc(struct pt_regs *regs) |
| 44 | { |
| 45 | struct stackframe frame; |
| 46 | |
| 47 | if (!in_lock_functions(regs->pc)) |
| 48 | return regs->pc; |
| 49 | |
| 50 | frame.fp = regs->regs[29]; |
| 51 | frame.sp = regs->sp; |
| 52 | frame.pc = regs->pc; |
| 53 | do { |
| 54 | int ret = unwind_frame(&frame); |
| 55 | if (ret < 0) |
| 56 | return 0; |
| 57 | } while (in_lock_functions(frame.pc)); |
| 58 | |
| 59 | return frame.pc; |
| 60 | } |
| 61 | EXPORT_SYMBOL(profile_pc); |
| 62 | #endif |
| 63 | |
Mark Rutland | 1aee5d7 | 2012-11-20 10:06:00 +0000 | [diff] [blame] | 64 | static u64 sched_clock_mult __read_mostly; |
| 65 | |
| 66 | unsigned long long notrace sched_clock(void) |
| 67 | { |
| 68 | return arch_timer_read_counter() * sched_clock_mult; |
| 69 | } |
| 70 | |
Marc Zyngier | 985c067 | 2012-03-05 11:49:30 +0000 | [diff] [blame] | 71 | void __init time_init(void) |
| 72 | { |
Mark Rutland | 1aee5d7 | 2012-11-20 10:06:00 +0000 | [diff] [blame] | 73 | u32 arch_timer_rate; |
| 74 | |
Rob Herring | 0583fe4 | 2013-04-10 18:27:51 -0500 | [diff] [blame] | 75 | clocksource_of_init(); |
Mark Rutland | 1aee5d7 | 2012-11-20 10:06:00 +0000 | [diff] [blame] | 76 | |
| 77 | arch_timer_rate = arch_timer_get_rate(); |
Rob Herring | 0583fe4 | 2013-04-10 18:27:51 -0500 | [diff] [blame] | 78 | if (!arch_timer_rate) |
| 79 | panic("Unable to initialise architected timer.\n"); |
Mark Rutland | 1aee5d7 | 2012-11-20 10:06:00 +0000 | [diff] [blame] | 80 | |
| 81 | /* Cache the sched_clock multiplier to save a divide in the hot path. */ |
| 82 | sched_clock_mult = NSEC_PER_SEC / arch_timer_rate; |
| 83 | |
| 84 | /* Calibrate the delay loop directly */ |
| 85 | lpj_fine = arch_timer_rate / HZ; |
Marc Zyngier | 985c067 | 2012-03-05 11:49:30 +0000 | [diff] [blame] | 86 | } |