Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 177246
b: refs/heads/master
c: ceb33be
h: refs/heads/master
v: v3
  • Loading branch information
Yi Li authored and Mike Frysinger committed Dec 15, 2009
1 parent c8f4960 commit 03c57ea
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: f7036d649c88ad14b482b2787ffb1063c8a719d7
refs/heads/master: ceb33be95afcfbc4079af334835a345288f9f6ca
43 changes: 33 additions & 10 deletions trunk/arch/blackfin/kernel/time-ts.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
#include <asm/time.h>
#include <asm/gptimers.h>

#if defined(CONFIG_CYCLES_CLOCKSOURCE)

/* Accelerators for sched_clock()
* convert from cycles(64bits) => nanoseconds (64bits)
* basic equation:
Expand All @@ -46,20 +44,23 @@
* -johnstul@us.ibm.com "math is hard, lets go shopping!"
*/

static unsigned long cyc2ns_scale;
#define CYC2NS_SCALE_FACTOR 10 /* 2^10, carefully chosen */

static inline void set_cyc2ns_scale(unsigned long cpu_khz)
static inline unsigned long cyc2ns_scale(unsigned long cpu_khz)
{
cyc2ns_scale = (1000000 << CYC2NS_SCALE_FACTOR) / cpu_khz;
return (1000000 << CYC2NS_SCALE_FACTOR) / cpu_khz;
}

static inline unsigned long long cycles_2_ns(cycle_t cyc)
static inline unsigned long long cycles_2_ns(cycle_t cyc, unsigned long cyc2ns_scale)
{
return (cyc * cyc2ns_scale) >> CYC2NS_SCALE_FACTOR;
}

static cycle_t bfin_read_cycles(struct clocksource *cs)
#if defined(CONFIG_CYCLES_CLOCKSOURCE)

static unsigned long cycles_cyc2ns_scale;

static notrace cycle_t bfin_read_cycles(struct clocksource *cs)
{
return __bfin_cycles_off + (get_cycles() << __bfin_cycles_mod);
}
Expand All @@ -73,14 +74,14 @@ static struct clocksource bfin_cs_cycles = {
.flags = CLOCK_SOURCE_IS_CONTINUOUS,
};

unsigned long long sched_clock(void)
static inline unsigned long long bfin_cs_cycles_sched_clock(void)
{
return cycles_2_ns(bfin_read_cycles(&bfin_cs_cycles));
return cycles_2_ns(bfin_read_cycles(&bfin_cs_cycles), cycles_cyc2ns_scale);
}

static int __init bfin_cs_cycles_init(void)
{
set_cyc2ns_scale(get_cclk() / 1000);
cycles_cyc2ns_scale = cyc2ns_scale(get_cclk() / 1000);

bfin_cs_cycles.mult = \
clocksource_hz2mult(get_cclk(), bfin_cs_cycles.shift);
Expand All @@ -96,6 +97,8 @@ static int __init bfin_cs_cycles_init(void)

#ifdef CONFIG_GPTMR0_CLOCKSOURCE

unsigned long gptimer0_cyc2ns_scale;

void __init setup_gptimer0(void)
{
disable_gptimers(TIMER0bit);
Expand All @@ -122,8 +125,15 @@ static struct clocksource bfin_cs_gptimer0 = {
.flags = CLOCK_SOURCE_IS_CONTINUOUS,
};

static inline unsigned long long bfin_cs_gptimer0_sched_clock(void)
{
return cycles_2_ns(bfin_read_TIMER0_COUNTER(), gptimer0_cyc2ns_scale);
}

static int __init bfin_cs_gptimer0_init(void)
{
gptimer0_cyc2ns_scale = cyc2ns_scale(get_sclk() / 1000);

setup_gptimer0();

bfin_cs_gptimer0.mult = \
Expand All @@ -138,6 +148,19 @@ static int __init bfin_cs_gptimer0_init(void)
# define bfin_cs_gptimer0_init()
#endif


#if defined(CONFIG_GPTMR0_CLOCKSOURCE) || defined(CONFIG_CYCLES_CLOCKSOURCE)
/* prefer to use cycles since it has higher rating */
notrace unsigned long long sched_clock(void)
{
#if defined(CONFIG_CYCLES_CLOCKSOURCE)
return bfin_cs_cycles_sched_clock();
#else
return bfin_cs_gptimer0_sched_clock();
#endif
}
#endif

#ifdef CONFIG_CORE_TIMER_IRQ_L1
__attribute__((l1_text))
#endif
Expand Down

0 comments on commit 03c57ea

Please sign in to comment.