Skip to content

Commit

Permalink
Merge branch 'timers-clocksource-for-linus' of git://git.kernel.org/p…
Browse files Browse the repository at this point in the history
…ub/scm/linux/kernel/git/tip/linux-2.6-tip

* 'timers-clocksource-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip:
  clocksource: convert mips to generic i8253 clocksource
  clocksource: convert x86 to generic i8253 clocksource
  clocksource: convert footbridge to generic i8253 clocksource
  clocksource: add common i8253 PIT clocksource
  blackfin: convert to clocksource_register_hz
  mips: convert to clocksource_register_hz/khz
  sparc: convert to clocksource_register_hz/khz
  alpha: convert to clocksource_register_hz
  microblaze: convert to clocksource_register_hz/khz
  ia64: convert to clocksource_register_hz/khz
  x86: Convert remaining x86 clocksources to clocksource_register_hz/khz
  Make clocksource name const
  • Loading branch information
torvalds committed May 20, 2011
2 parents 80fe02b + a18f22a commit 0f1bdc1
Show file tree
Hide file tree
Showing 38 changed files with 157 additions and 355 deletions.
15 changes: 15 additions & 0 deletions arch/arm/include/asm/i8253.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef __ASMARM_I8253_H
#define __ASMARM_I8253_H

/* i8253A PIT registers */
#define PIT_MODE 0x43
#define PIT_CH0 0x40

#define PIT_LATCH ((PIT_TICK_RATE + HZ / 2) / HZ)

extern raw_spinlock_t i8253_lock;

#define outb_pit outb_p
#define inb_pit inb_p

#endif
2 changes: 2 additions & 0 deletions arch/arm/mach-footbridge/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ menu "Footbridge Implementations"

config ARCH_CATS
bool "CATS"
select CLKSRC_I8253
select FOOTBRIDGE_HOST
select ISA
select ISA_DMA
Expand Down Expand Up @@ -59,6 +60,7 @@ config ARCH_EBSA285_HOST

config ARCH_NETWINDER
bool "NetWinder"
select CLKSRC_I8253
select FOOTBRIDGE_HOST
select ISA
select ISA_DMA
Expand Down
45 changes: 4 additions & 41 deletions arch/arm/mach-footbridge/isa-timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,53 +10,16 @@
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/io.h>
#include <linux/spinlock.h>
#include <linux/timex.h>

#include <asm/irq.h>

#include <asm/i8253.h>
#include <asm/mach/time.h>

#include "common.h"

#define PIT_MODE 0x43
#define PIT_CH0 0x40

#define PIT_LATCH ((PIT_TICK_RATE + HZ / 2) / HZ)

static cycle_t pit_read(struct clocksource *cs)
{
unsigned long flags;
static int old_count;
static u32 old_jifs;
int count;
u32 jifs;

raw_local_irq_save(flags);

jifs = jiffies;
outb_p(0x00, PIT_MODE); /* latch the count */
count = inb_p(PIT_CH0); /* read the latched count */
count |= inb_p(PIT_CH0) << 8;

if (count > old_count && jifs == old_jifs)
count = old_count;

old_count = count;
old_jifs = jifs;

raw_local_irq_restore(flags);

count = (PIT_LATCH - 1) - count;

return (cycle_t)(jifs * PIT_LATCH) + count;
}

static struct clocksource pit_cs = {
.name = "pit",
.rating = 110,
.read = pit_read,
.mask = CLOCKSOURCE_MASK(32),
};
DEFINE_RAW_SPINLOCK(i8253_lock);

static void pit_set_mode(enum clock_event_mode mode,
struct clock_event_device *evt)
Expand Down Expand Up @@ -121,7 +84,7 @@ static void __init isa_timer_init(void)
pit_ce.max_delta_ns = clockevent_delta2ns(0x7fff, &pit_ce);
pit_ce.min_delta_ns = clockevent_delta2ns(0x000f, &pit_ce);

clocksource_register_hz(&pit_cs, PIT_TICK_RATE);
clocksource_i8253_init();

setup_irq(pit_ce.irq, &pit_timer_irq);
clockevents_register_device(&pit_ce);
Expand Down
35 changes: 2 additions & 33 deletions arch/blackfin/kernel/time-ts.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,6 @@
#include <asm/gptimers.h>
#include <asm/nmi.h>

/* Accelerators for sched_clock()
* convert from cycles(64bits) => nanoseconds (64bits)
* basic equation:
* ns = cycles / (freq / ns_per_sec)
* ns = cycles * (ns_per_sec / freq)
* ns = cycles * (10^9 / (cpu_khz * 10^3))
* ns = cycles * (10^6 / cpu_khz)
*
* Then we use scaling math (suggested by [email protected]) to get:
* ns = cycles * (10^6 * SC / cpu_khz) / SC
* ns = cycles * cyc2ns_scale / SC
*
* And since SC is a constant power of two, we can convert the div
* into a shift.
*
* We can use khz divisor instead of mhz to keep a better precision, since
* cyc2ns_scale is limited to 10^6 * 2^10, which fits in 32 bits.
* ([email protected])
*
* [email protected] "math is hard, lets go shopping!"
*/

#define CYC2NS_SCALE_FACTOR 10 /* 2^10, carefully chosen */

#if defined(CONFIG_CYCLES_CLOCKSOURCE)

Expand All @@ -63,7 +40,6 @@ static struct clocksource bfin_cs_cycles = {
.rating = 400,
.read = bfin_read_cycles,
.mask = CLOCKSOURCE_MASK(64),
.shift = CYC2NS_SCALE_FACTOR,
.flags = CLOCK_SOURCE_IS_CONTINUOUS,
};

Expand All @@ -75,10 +51,7 @@ static inline unsigned long long bfin_cs_cycles_sched_clock(void)

static int __init bfin_cs_cycles_init(void)
{
bfin_cs_cycles.mult = \
clocksource_hz2mult(get_cclk(), bfin_cs_cycles.shift);

if (clocksource_register(&bfin_cs_cycles))
if (clocksource_register_hz(&bfin_cs_cycles, get_cclk()))
panic("failed to register clocksource");

return 0;
Expand Down Expand Up @@ -111,7 +84,6 @@ static struct clocksource bfin_cs_gptimer0 = {
.rating = 350,
.read = bfin_read_gptimer0,
.mask = CLOCKSOURCE_MASK(32),
.shift = CYC2NS_SCALE_FACTOR,
.flags = CLOCK_SOURCE_IS_CONTINUOUS,
};

Expand All @@ -125,10 +97,7 @@ static int __init bfin_cs_gptimer0_init(void)
{
setup_gptimer0();

bfin_cs_gptimer0.mult = \
clocksource_hz2mult(get_sclk(), bfin_cs_gptimer0.shift);

if (clocksource_register(&bfin_cs_gptimer0))
if (clocksource_register_hz(&bfin_cs_gptimer0, get_sclk()))
panic("failed to register clocksource");

return 0;
Expand Down
6 changes: 1 addition & 5 deletions arch/ia64/kernel/cyclone.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ static struct clocksource clocksource_cyclone = {
.rating = 300,
.read = read_cyclone,
.mask = (1LL << 40) - 1,
.mult = 0, /*to be calculated*/
.shift = 16,
.flags = CLOCK_SOURCE_IS_CONTINUOUS,
};

Expand Down Expand Up @@ -118,9 +116,7 @@ int __init init_cyclone_clock(void)
/* initialize last tick */
cyclone_mc = cyclone_timer;
clocksource_cyclone.fsys_mmio = cyclone_timer;
clocksource_cyclone.mult = clocksource_hz2mult(CYCLONE_TIMER_FREQ,
clocksource_cyclone.shift);
clocksource_register(&clocksource_cyclone);
clocksource_register_hz(&clocksource_cyclone, CYCLONE_TIMER_FREQ);

return 0;
}
Expand Down
9 changes: 2 additions & 7 deletions arch/ia64/kernel/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ static struct clocksource clocksource_itc = {
.rating = 350,
.read = itc_get_cycles,
.mask = CLOCKSOURCE_MASK(64),
.mult = 0, /*to be calculated*/
.shift = 16,
.flags = CLOCK_SOURCE_IS_CONTINUOUS,
#ifdef CONFIG_PARAVIRT
.resume = paravirt_clocksource_resume,
Expand Down Expand Up @@ -365,11 +363,8 @@ ia64_init_itm (void)
ia64_cpu_local_tick();

if (!itc_clocksource) {
/* Sort out mult/shift values: */
clocksource_itc.mult =
clocksource_hz2mult(local_cpu_data->itc_freq,
clocksource_itc.shift);
clocksource_register(&clocksource_itc);
clocksource_register_hz(&clocksource_itc,
local_cpu_data->itc_freq);
itc_clocksource = &clocksource_itc;
}
}
Expand Down
6 changes: 1 addition & 5 deletions arch/ia64/sn/kernel/sn2/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ static struct clocksource clocksource_sn2 = {
.rating = 450,
.read = read_sn2,
.mask = (1LL << 55) - 1,
.mult = 0,
.shift = 10,
.flags = CLOCK_SOURCE_IS_CONTINUOUS,
};

Expand All @@ -57,9 +55,7 @@ ia64_sn_udelay (unsigned long usecs)
void __init sn_timer_init(void)
{
clocksource_sn2.fsys_mmio = RTC_COUNTER_ADDR;
clocksource_sn2.mult = clocksource_hz2mult(sn_rtc_cycles_per_second,
clocksource_sn2.shift);
clocksource_register(&clocksource_sn2);
clocksource_register_hz(&clocksource_sn2, sn_rtc_cycles_per_second);

ia64_udelay = &ia64_sn_udelay;
}
6 changes: 1 addition & 5 deletions arch/microblaze/kernel/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,16 +217,12 @@ static struct clocksource clocksource_microblaze = {
.rating = 300,
.read = microblaze_read,
.mask = CLOCKSOURCE_MASK(32),
.shift = 8, /* I can shift it */
.flags = CLOCK_SOURCE_IS_CONTINUOUS,
};

static int __init microblaze_clocksource_init(void)
{
clocksource_microblaze.mult =
clocksource_hz2mult(timer_clock_freq,
clocksource_microblaze.shift);
if (clocksource_register(&clocksource_microblaze))
if (clocksource_register_hz(&clocksource_microblaze, timer_clock_freq))
panic("failed to register clocksource");

/* stop timer1 */
Expand Down
1 change: 1 addition & 0 deletions arch/mips/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2395,6 +2395,7 @@ config MMU

config I8253
bool
select CLKSRC_I8253
select MIPS_EXTERNAL_TIMER

config ZONE_DMA32
Expand Down
3 changes: 1 addition & 2 deletions arch/mips/alchemy/common/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,7 @@ static int __init alchemy_time_init(unsigned int m2int)
goto cntr_err;

/* register counter1 clocksource and event device */
clocksource_set_clock(&au1x_counter1_clocksource, 32768);
clocksource_register(&au1x_counter1_clocksource);
clocksource_register_hz(&au1x_counter1_clocksource, 32768);

cd->shift = 32;
cd->mult = div_sc(32768, NSEC_PER_SEC, cd->shift);
Expand Down
3 changes: 1 addition & 2 deletions arch/mips/cavium-octeon/csrc-octeon.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ unsigned long long notrace sched_clock(void)
void __init plat_time_init(void)
{
clocksource_mips.rating = 300;
clocksource_set_clock(&clocksource_mips, octeon_get_clock_rate());
clocksource_register(&clocksource_mips);
clocksource_register_hz(&clocksource_mips, octeon_get_clock_rate());
}

static u64 octeon_udelay_factor;
Expand Down
5 changes: 5 additions & 0 deletions arch/mips/include/asm/i8253.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@
#define PIT_CH0 0x40
#define PIT_CH2 0x42

#define PIT_LATCH LATCH

extern raw_spinlock_t i8253_lock;

extern void setup_pit_timer(void);

#define inb_pit inb_p
#define outb_pit outb_p

#endif /* __ASM_I8253_H */
6 changes: 0 additions & 6 deletions arch/mips/include/asm/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,6 @@ static inline int init_mips_clocksource(void)
#endif
}

static inline void clocksource_set_clock(struct clocksource *cs,
unsigned int clock)
{
clocksource_calc_mult_shift(cs, clock, 4);
}

static inline void clockevent_set_clock(struct clock_event_device *cd,
unsigned int clock)
{
Expand Down
3 changes: 1 addition & 2 deletions arch/mips/jz4740/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ void __init plat_time_init(void)

clockevents_register_device(&jz4740_clockevent);

clocksource_set_clock(&jz4740_clocksource, clk_rate);
ret = clocksource_register(&jz4740_clocksource);
ret = clocksource_register_hz(&jz4740_clocksource, clk_rate);

if (ret)
printk(KERN_ERR "Failed to register clocksource: %d\n", ret);
Expand Down
3 changes: 1 addition & 2 deletions arch/mips/kernel/cevt-txx9.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ void __init txx9_clocksource_init(unsigned long baseaddr,
{
struct txx9_tmr_reg __iomem *tmrptr;

clocksource_set_clock(&txx9_clocksource.cs, TIMER_CLK(imbusclk));
clocksource_register(&txx9_clocksource.cs);
clocksource_register_hz(&txx9_clocksource.cs, TIMER_CLK(imbusclk));

tmrptr = ioremap(baseaddr, sizeof(struct txx9_tmr_reg));
__raw_writel(TCR_BASE, &tmrptr->tcr);
Expand Down
3 changes: 1 addition & 2 deletions arch/mips/kernel/csrc-bcm1480.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,5 @@ void __init sb1480_clocksource_init(void)

plldiv = G_BCM1480_SYS_PLL_DIV(__raw_readq(IOADDR(A_SCD_SYSTEM_CFG)));
zbbus = ((plldiv >> 1) * 50000000) + ((plldiv & 1) * 25000000);
clocksource_set_clock(cs, zbbus);
clocksource_register(cs);
clocksource_register_hz(cs, zbbus);
}
4 changes: 1 addition & 3 deletions arch/mips/kernel/csrc-ioasic.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,5 @@ void __init dec_ioasic_clocksource_init(void)
printk(KERN_INFO "I/O ASIC clock frequency %dHz\n", freq);

clocksource_dec.rating = 200 + freq / 10000000;
clocksource_set_clock(&clocksource_dec, freq);

clocksource_register(&clocksource_dec);
clocksource_register_hz(&clocksource_dec, freq);
}
35 changes: 3 additions & 32 deletions arch/mips/kernel/csrc-powertv.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ static void __init powertv_c0_hpt_clocksource_init(void)

clocksource_mips.rating = 200 + mips_hpt_frequency / 10000000;

clocksource_set_clock(&clocksource_mips, mips_hpt_frequency);

clocksource_register(&clocksource_mips);
clocksource_register_hz(&clocksource_mips, mips_hpt_frequency);
}

/**
Expand Down Expand Up @@ -130,43 +128,16 @@ static struct clocksource clocksource_tim_c = {
/**
* powertv_tim_c_clocksource_init - set up a clock source for the TIM_C clock
*
* The hard part here is coming up with a constant k and shift s such that
* the 48-bit TIM_C value multiplied by k doesn't overflow and that value,
* when shifted right by s, yields the corresponding number of nanoseconds.
* We know that TIM_C counts at 27 MHz/8, so each cycle corresponds to
* 1 / (27,000,000/8) seconds. Multiply that by a billion and you get the
* number of nanoseconds. Since the TIM_C value has 48 bits and the math is
* done in 64 bits, avoiding an overflow means that k must be less than
* 64 - 48 = 16 bits.
* 1 / (27,000,000/8) seconds.
*/
static void __init powertv_tim_c_clocksource_init(void)
{
int prescale;
unsigned long dividend;
unsigned long k;
int s;
const int max_k_bits = (64 - 48) - 1;
const unsigned long billion = 1000000000;
const unsigned long counts_per_second = 27000000 / 8;

prescale = BITS_PER_LONG - ilog2(billion) - 1;
dividend = billion << prescale;
k = dividend / counts_per_second;
s = ilog2(k) - max_k_bits;

if (s < 0)
s = prescale;

else {
k >>= s;
s += prescale;
}

clocksource_tim_c.mult = k;
clocksource_tim_c.shift = s;
clocksource_tim_c.rating = 200;

clocksource_register(&clocksource_tim_c);
clocksource_register_hz(&clocksource_tim_c, counts_per_second);
tim_c = (struct tim_c *) asic_reg_addr(tim_ch);
}

Expand Down
Loading

0 comments on commit 0f1bdc1

Please sign in to comment.