time.c (4a4cfe3836916e12282ceb5c4bdd799dc71af567) | time.c (d831d0b83f205888f4be4dee0a074ad67ef809b3) |
---|---|
1/* 2 * Common time routines among all ppc machines. 3 * 4 * Written by Cort Dougan (cort@cs.nmt.edu) to merge 5 * Paul Mackerras' version and mine for PReP and Pmac. 6 * MPC8xx/MBX changes by Dan Malek (dmalek@jlc.net). 7 * Converted for 64-bit by Mike Corrigan (mikejc@us.ibm.com) 8 * --- 59 unchanged lines hidden (view full) --- 68#include <asm/firmware.h> 69#ifdef CONFIG_PPC_ISERIES 70#include <asm/iseries/it_lp_queue.h> 71#include <asm/iseries/hv_call_xm.h> 72#endif 73 74/* powerpc clocksource/clockevent code */ 75 | 1/* 2 * Common time routines among all ppc machines. 3 * 4 * Written by Cort Dougan (cort@cs.nmt.edu) to merge 5 * Paul Mackerras' version and mine for PReP and Pmac. 6 * MPC8xx/MBX changes by Dan Malek (dmalek@jlc.net). 7 * Converted for 64-bit by Mike Corrigan (mikejc@us.ibm.com) 8 * --- 59 unchanged lines hidden (view full) --- 68#include <asm/firmware.h> 69#ifdef CONFIG_PPC_ISERIES 70#include <asm/iseries/it_lp_queue.h> 71#include <asm/iseries/hv_call_xm.h> 72#endif 73 74/* powerpc clocksource/clockevent code */ 75 |
76#include <linux/clockchips.h> |
|
76#include <linux/clocksource.h> 77 78static cycle_t rtc_read(void); 79static struct clocksource clocksource_rtc = { 80 .name = "rtc", 81 .rating = 400, 82 .flags = CLOCK_SOURCE_IS_CONTINUOUS, 83 .mask = CLOCKSOURCE_MASK(64), --- 8 unchanged lines hidden (view full) --- 92 .rating = 400, 93 .flags = CLOCK_SOURCE_IS_CONTINUOUS, 94 .mask = CLOCKSOURCE_MASK(64), 95 .shift = 22, 96 .mult = 0, /* To be filled in */ 97 .read = timebase_read, 98}; 99 | 77#include <linux/clocksource.h> 78 79static cycle_t rtc_read(void); 80static struct clocksource clocksource_rtc = { 81 .name = "rtc", 82 .rating = 400, 83 .flags = CLOCK_SOURCE_IS_CONTINUOUS, 84 .mask = CLOCKSOURCE_MASK(64), --- 8 unchanged lines hidden (view full) --- 93 .rating = 400, 94 .flags = CLOCK_SOURCE_IS_CONTINUOUS, 95 .mask = CLOCKSOURCE_MASK(64), 96 .shift = 22, 97 .mult = 0, /* To be filled in */ 98 .read = timebase_read, 99}; 100 |
101#define DECREMENTER_MAX 0x7fffffff 102 103static int decrementer_set_next_event(unsigned long evt, 104 struct clock_event_device *dev); 105static void decrementer_set_mode(enum clock_event_mode mode, 106 struct clock_event_device *dev); 107 108static struct clock_event_device decrementer_clockevent = { 109 .name = "decrementer", 110 .rating = 200, 111 .shift = 32, 112 .mult = 0, /* To be filled in */ 113 .irq = 0, 114 .set_next_event = decrementer_set_next_event, 115 .set_mode = decrementer_set_mode, 116 .features = CLOCK_EVT_FEAT_ONESHOT, 117}; 118 119static DEFINE_PER_CPU(struct clock_event_device, decrementers); 120void init_decrementer_clockevent(void); 121 |
|
100#ifdef CONFIG_PPC_ISERIES 101static unsigned long __initdata iSeries_recal_titan; 102static signed long __initdata iSeries_recal_tb; 103 104/* Forward declaration is only needed for iSereis compiles */ 105void __init clocksource_init(void); 106#endif 107 --- 404 unchanged lines hidden (view full) --- 512 513/* 514 * timer_interrupt - gets called when the decrementer overflows, 515 * with interrupts disabled. 516 */ 517void timer_interrupt(struct pt_regs * regs) 518{ 519 struct pt_regs *old_regs; | 122#ifdef CONFIG_PPC_ISERIES 123static unsigned long __initdata iSeries_recal_titan; 124static signed long __initdata iSeries_recal_tb; 125 126/* Forward declaration is only needed for iSereis compiles */ 127void __init clocksource_init(void); 128#endif 129 --- 404 unchanged lines hidden (view full) --- 534 535/* 536 * timer_interrupt - gets called when the decrementer overflows, 537 * with interrupts disabled. 538 */ 539void timer_interrupt(struct pt_regs * regs) 540{ 541 struct pt_regs *old_regs; |
520 int next_dec; | |
521 int cpu = smp_processor_id(); | 542 int cpu = smp_processor_id(); |
522 unsigned long ticks; 523 u64 tb_next_jiffy; | 543 struct clock_event_device *evt = &per_cpu(decrementers, cpu); |
524 | 544 |
545 /* Ensure a positive value is written to the decrementer, or else 546 * some CPUs will continuue to take decrementer exceptions */ 547 set_dec(DECREMENTER_MAX); 548 |
|
525#ifdef CONFIG_PPC32 526 if (atomic_read(&ppc_n_lost_interrupts) != 0) 527 do_IRQ(regs); 528#endif 529 530 old_regs = set_irq_regs(regs); 531 irq_enter(); 532 | 549#ifdef CONFIG_PPC32 550 if (atomic_read(&ppc_n_lost_interrupts) != 0) 551 do_IRQ(regs); 552#endif 553 554 old_regs = set_irq_regs(regs); 555 irq_enter(); 556 |
533 profile_tick(CPU_PROFILING); | |
534 calculate_steal_time(); 535 536#ifdef CONFIG_PPC_ISERIES 537 if (firmware_has_feature(FW_FEATURE_ISERIES)) 538 get_lppaca()->int_dword.fields.decr_int = 0; 539#endif 540 | 557 calculate_steal_time(); 558 559#ifdef CONFIG_PPC_ISERIES 560 if (firmware_has_feature(FW_FEATURE_ISERIES)) 561 get_lppaca()->int_dword.fields.decr_int = 0; 562#endif 563 |
541 while ((ticks = tb_ticks_since(per_cpu(last_jiffy, cpu))) 542 >= tb_ticks_per_jiffy) { 543 /* Update last_jiffy */ 544 per_cpu(last_jiffy, cpu) += tb_ticks_per_jiffy; 545 /* Handle RTCL overflow on 601 */ 546 if (__USE_RTC() && per_cpu(last_jiffy, cpu) >= 1000000000) 547 per_cpu(last_jiffy, cpu) -= 1000000000; | 564 /* 565 * We cannot disable the decrementer, so in the period 566 * between this cpu's being marked offline in cpu_online_map 567 * and calling stop-self, it is taking timer interrupts. 568 * Avoid calling into the scheduler rebalancing code if this 569 * is the case. 570 */ 571 if (!cpu_is_offline(cpu)) 572 account_process_time(regs); |
548 | 573 |
549 /* 550 * We cannot disable the decrementer, so in the period 551 * between this cpu's being marked offline in cpu_online_map 552 * and calling stop-self, it is taking timer interrupts. 553 * Avoid calling into the scheduler rebalancing code if this 554 * is the case. 555 */ 556 if (!cpu_is_offline(cpu)) 557 account_process_time(regs); | 574 if (evt->event_handler) 575 evt->event_handler(evt); 576 else 577 evt->set_next_event(DECREMENTER_MAX, evt); |
558 | 578 |
559 /* 560 * No need to check whether cpu is offline here; boot_cpuid 561 * should have been fixed up by now. 562 */ 563 if (cpu != boot_cpuid) 564 continue; 565 566 write_seqlock(&xtime_lock); 567 tb_next_jiffy = tb_last_jiffy + tb_ticks_per_jiffy; 568 if (__USE_RTC() && tb_next_jiffy >= 1000000000) 569 tb_next_jiffy -= 1000000000; 570 if (per_cpu(last_jiffy, cpu) >= tb_next_jiffy) { 571 tb_last_jiffy = tb_next_jiffy; 572 do_timer(1); 573 } 574 write_sequnlock(&xtime_lock); 575 } 576 577 next_dec = tb_ticks_per_jiffy - ticks; 578 set_dec(next_dec); 579 | |
580#ifdef CONFIG_PPC_ISERIES 581 if (firmware_has_feature(FW_FEATURE_ISERIES) && hvlpevent_is_pending()) 582 process_hvlpevents(); 583#endif 584 585#ifdef CONFIG_PPC64 586 /* collect purr register values often, for accurate calculations */ 587 if (firmware_has_feature(FW_FEATURE_SPLPAR)) { --- 202 unchanged lines hidden (view full) --- 790 clock->name); 791 return; 792 } 793 794 printk(KERN_INFO "clocksource: %s mult[%x] shift[%d] registered\n", 795 clock->name, clock->mult, clock->shift); 796} 797 | 579#ifdef CONFIG_PPC_ISERIES 580 if (firmware_has_feature(FW_FEATURE_ISERIES) && hvlpevent_is_pending()) 581 process_hvlpevents(); 582#endif 583 584#ifdef CONFIG_PPC64 585 /* collect purr register values often, for accurate calculations */ 586 if (firmware_has_feature(FW_FEATURE_SPLPAR)) { --- 202 unchanged lines hidden (view full) --- 789 clock->name); 790 return; 791 } 792 793 printk(KERN_INFO "clocksource: %s mult[%x] shift[%d] registered\n", 794 clock->name, clock->mult, clock->shift); 795} 796 |
797static int decrementer_set_next_event(unsigned long evt, 798 struct clock_event_device *dev) 799{ 800 set_dec(evt); 801 return 0; 802} 803 804static void decrementer_set_mode(enum clock_event_mode mode, 805 struct clock_event_device *dev) 806{ 807 if (mode != CLOCK_EVT_MODE_ONESHOT) 808 decrementer_set_next_event(DECREMENTER_MAX, dev); 809} 810 811static void register_decrementer_clockevent(int cpu) 812{ 813 struct clock_event_device *dec = &per_cpu(decrementers, cpu); 814 815 *dec = decrementer_clockevent; 816 dec->cpumask = cpumask_of_cpu(cpu); 817 818 printk(KERN_ERR "clockevent: %s mult[%lx] shift[%d] cpu[%d]\n", 819 dec->name, dec->mult, dec->shift, cpu); 820 821 clockevents_register_device(dec); 822} 823 824void init_decrementer_clockevent(void) 825{ 826 int cpu = smp_processor_id(); 827 828 decrementer_clockevent.mult = div_sc(ppc_tb_freq, NSEC_PER_SEC, 829 decrementer_clockevent.shift); 830 decrementer_clockevent.max_delta_ns = 831 clockevent_delta2ns(DECREMENTER_MAX, &decrementer_clockevent); 832 decrementer_clockevent.min_delta_ns = 1000; 833 834 register_decrementer_clockevent(cpu); 835} 836 837void secondary_cpu_time_init(void) 838{ 839 /* FIME: Should make unrelatred change to move snapshot_timebase 840 * call here ! */ 841 register_decrementer_clockevent(smp_processor_id()); 842} 843 |
|
798/* This function is only called on the boot processor */ 799void __init time_init(void) 800{ 801 unsigned long flags; 802 struct div_result res; 803 u64 scale, x; 804 unsigned shift; 805 --- 97 unchanged lines hidden (view full) --- 903 time_freq = 0; 904 905 write_sequnlock_irqrestore(&xtime_lock, flags); 906 907 /* Register the clocksource, if we're not running on iSeries */ 908 if (!firmware_has_feature(FW_FEATURE_ISERIES)) 909 clocksource_init(); 910 | 844/* This function is only called on the boot processor */ 845void __init time_init(void) 846{ 847 unsigned long flags; 848 struct div_result res; 849 u64 scale, x; 850 unsigned shift; 851 --- 97 unchanged lines hidden (view full) --- 949 time_freq = 0; 950 951 write_sequnlock_irqrestore(&xtime_lock, flags); 952 953 /* Register the clocksource, if we're not running on iSeries */ 954 if (!firmware_has_feature(FW_FEATURE_ISERIES)) 955 clocksource_init(); 956 |
911 /* Not exact, but the timer interrupt takes care of this */ 912 set_dec(tb_ticks_per_jiffy); | 957 init_decrementer_clockevent(); |
913} 914 915 916#define FEBRUARY 2 917#define STARTOFTIME 1970 918#define SECDAY 86400L 919#define SECYR (SECDAY * 365) 920#define leapyear(year) ((year) % 4 == 0 && \ --- 139 unchanged lines hidden --- | 958} 959 960 961#define FEBRUARY 2 962#define STARTOFTIME 1970 963#define SECDAY 86400L 964#define SECYR (SECDAY * 365) 965#define leapyear(year) ((year) % 4 == 0 && \ --- 139 unchanged lines hidden --- |