Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 333871
b: refs/heads/master
c: b3c869d
h: refs/heads/master
i:
  333869: 294b429
  333867: 786c8c4
  333863: dbab111
  333855: 88ced72
v: v3
  • Loading branch information
John Stultz committed Sep 24, 2012
1 parent cf093cb commit e5ad334
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 15 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: 7916a1f14f06ac93e4cec81139fe4f7ec13b572c
refs/heads/master: b3c869d35b9b014f63ac0beacd31c57372084d01
3 changes: 3 additions & 0 deletions trunk/arch/x86/kernel/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
#include <linux/percpu.h>
#include <linux/crash_dump.h>
#include <linux/tboot.h>
#include <linux/jiffies.h>

#include <video/edid.h>

Expand Down Expand Up @@ -1034,6 +1035,8 @@ void __init setup_arch(char **cmdline_p)
mcheck_init();

arch_init_ideal_nops();

register_refined_jiffies(CLOCK_TICK_RATE);
}

#ifdef CONFIG_X86_32
Expand Down
15 changes: 2 additions & 13 deletions trunk/include/linux/jiffies.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,10 @@
#define SH_DIV(NOM,DEN,LSH) ( (((NOM) / (DEN)) << (LSH)) \
+ ((((NOM) % (DEN)) << (LSH)) + (DEN) / 2) / (DEN))

#ifdef CLOCK_TICK_RATE
/* LATCH is used in the interval timer and ftape setup. */
# define LATCH ((CLOCK_TICK_RATE + HZ/2) / HZ) /* For divider */

/*
* HZ is the requested value. However the CLOCK_TICK_RATE may not allow
* for exactly HZ. So SHIFTED_HZ is high res HZ ("<< 8" is for accuracy)
*/
# define SHIFTED_HZ (SH_DIV(CLOCK_TICK_RATE, LATCH, 8))
#else
# define SHIFTED_HZ (HZ << 8)
#endif
extern int register_refined_jiffies(long clock_tick_rate);

/* TICK_NSEC is the time between ticks in nsec assuming SHIFTED_HZ */
#define TICK_NSEC (SH_DIV(1000000UL * 1000, SHIFTED_HZ, 8))
#define TICK_NSEC ((NSEC_PER_SEC+HZ/2)/HZ)

/* TICK_USEC is the time between ticks in usec assuming fake USER_HZ */
#define TICK_USEC ((1000000UL + USER_HZ/2) / USER_HZ)
Expand Down
32 changes: 31 additions & 1 deletion trunk/kernel/time/jiffies.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* requested HZ value. It is also not recommended
* for "tick-less" systems.
*/
#define NSEC_PER_JIFFY ((u32)((((u64)NSEC_PER_SEC)<<8)/SHIFTED_HZ))
#define NSEC_PER_JIFFY ((NSEC_PER_SEC+HZ/2)/HZ)

/* Since jiffies uses a simple NSEC_PER_JIFFY multiplier
* conversion, the .shift value could be zero. However
Expand Down Expand Up @@ -95,3 +95,33 @@ struct clocksource * __init __weak clocksource_default_clock(void)
{
return &clocksource_jiffies;
}

struct clocksource refined_jiffies;

int register_refined_jiffies(long cycles_per_second)
{
u64 nsec_per_tick, shift_hz;
long cycles_per_tick;



refined_jiffies = clocksource_jiffies;
refined_jiffies.name = "refined-jiffies";
refined_jiffies.rating++;

/* Calc cycles per tick */
cycles_per_tick = (cycles_per_second + HZ/2)/HZ;
/* shift_hz stores hz<<8 for extra accuracy */
shift_hz = (u64)cycles_per_second << 8;
shift_hz += cycles_per_tick/2;
do_div(shift_hz, cycles_per_tick);
/* Calculate nsec_per_tick using shift_hz */
nsec_per_tick = (u64)NSEC_PER_SEC << 8;
nsec_per_tick += (u32)shift_hz/2;
do_div(nsec_per_tick, (u32)shift_hz);

refined_jiffies.mult = ((u32)nsec_per_tick) << JIFFIES_SHIFT;

clocksource_register(&refined_jiffies);
return 0;
}

0 comments on commit e5ad334

Please sign in to comment.