mm: fix exec activate_mm vs TLB shootdown and lazy tlb switching race
[linux/fpc-iii.git] / arch / mn10300 / kernel / time.c
blob06b83b17c5f1976f5c782d4db013442fcc5f1b5a
1 /* MN10300 Low level time management
3 * Copyright (C) 2007-2008 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 * - Derived from arch/i386/kernel/time.c
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public Licence
9 * as published by the Free Software Foundation; either version
10 * 2 of the Licence, or (at your option) any later version.
12 #include <linux/sched.h>
13 #include <linux/sched/clock.h>
14 #include <linux/kernel.h>
15 #include <linux/interrupt.h>
16 #include <linux/time.h>
17 #include <linux/init.h>
18 #include <linux/smp.h>
19 #include <linux/profile.h>
20 #include <linux/cnt32_to_63.h>
21 #include <linux/clocksource.h>
22 #include <linux/clockchips.h>
23 #include <asm/irq.h>
24 #include <asm/div64.h>
25 #include <asm/processor.h>
26 #include <asm/intctl-regs.h>
27 #include <asm/rtc.h>
28 #include "internal.h"
30 static unsigned long mn10300_last_tsc; /* time-stamp counter at last time
31 * interrupt occurred */
33 static unsigned long sched_clock_multiplier;
36 * scheduler clock - returns current time in nanosec units.
38 unsigned long long sched_clock(void)
40 union {
41 unsigned long long ll;
42 unsigned l[2];
43 } tsc64, result;
44 unsigned long tmp;
45 unsigned product[3]; /* 96-bit intermediate value */
47 /* cnt32_to_63() is not safe with preemption */
48 preempt_disable();
50 /* expand the tsc to 64-bits.
51 * - sched_clock() must be called once a minute or better or the
52 * following will go horribly wrong - see cnt32_to_63()
54 tsc64.ll = cnt32_to_63(get_cycles()) & 0x7fffffffffffffffULL;
56 preempt_enable();
58 /* scale the 64-bit TSC value to a nanosecond value via a 96-bit
59 * intermediate
61 asm("mulu %2,%0,%3,%0 \n" /* LSW * mult -> 0:%3:%0 */
62 "mulu %2,%1,%2,%1 \n" /* MSW * mult -> %2:%1:0 */
63 "add %3,%1 \n"
64 "addc 0,%2 \n" /* result in %2:%1:%0 */
65 : "=r"(product[0]), "=r"(product[1]), "=r"(product[2]), "=r"(tmp)
66 : "0"(tsc64.l[0]), "1"(tsc64.l[1]), "2"(sched_clock_multiplier)
67 : "cc");
69 result.l[0] = product[1] << 16 | product[0] >> 16;
70 result.l[1] = product[2] << 16 | product[1] >> 16;
72 return result.ll;
76 * initialise the scheduler clock
78 static void __init mn10300_sched_clock_init(void)
80 sched_clock_multiplier =
81 __muldiv64u(NSEC_PER_SEC, 1 << 16, MN10300_TSCCLK);
84 /**
85 * local_timer_interrupt - Local timer interrupt handler
87 * Handle local timer interrupts for this CPU. They may have been propagated
88 * to this CPU from the CPU that actually gets them by way of an IPI.
90 irqreturn_t local_timer_interrupt(void)
92 profile_tick(CPU_PROFILING);
93 update_process_times(user_mode(get_irq_regs()));
94 return IRQ_HANDLED;
98 * initialise the various timers used by the main part of the kernel
100 void __init time_init(void)
102 /* we need the prescalar running to be able to use IOCLK/8
103 * - IOCLK runs at 1/4 (ST5 open) or 1/8 (ST5 closed) internal CPU clock
104 * - IOCLK runs at Fosc rate (crystal speed)
106 TMPSCNT |= TMPSCNT_ENABLE;
108 init_clocksource();
110 printk(KERN_INFO
111 "timestamp counter I/O clock running at %lu.%02lu"
112 " (calibrated against RTC)\n",
113 MN10300_TSCCLK / 1000000, (MN10300_TSCCLK / 10000) % 100);
115 mn10300_last_tsc = read_timestamp_counter();
117 init_clockevents();
119 #ifdef CONFIG_MN10300_WD_TIMER
120 /* start the watchdog timer */
121 watchdog_go();
122 #endif
124 mn10300_sched_clock_init();