Rev 1899 | Rev 2067 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1899 | Rev 2044 | ||
---|---|---|---|
Line 50... | Line 50... | ||
50 | { |
50 | { |
51 | tick_compare_reg_t compare; |
51 | tick_compare_reg_t compare; |
52 | 52 | ||
53 | interrupt_register(14, "tick_int", tick_interrupt); |
53 | interrupt_register(14, "tick_int", tick_interrupt); |
54 | compare.int_dis = false; |
54 | compare.int_dis = false; |
55 | compare.tick_cmpr = CPU->arch.clock_frequency/HZ; |
55 | compare.tick_cmpr = CPU->arch.clock_frequency / HZ; |
- | 56 | CPU->arch.next_tick_cmpr = compare.tick_cmpr; |
|
56 | tick_compare_write(compare.value); |
57 | tick_compare_write(compare.value); |
57 | tick_write(0); |
58 | tick_write(0); |
58 | } |
59 | } |
59 | 60 | ||
60 | /** Process tick interrupt. |
61 | /** Process tick interrupt. |
Line 63... | Line 64... | ||
63 | * @param istate Interrupted state. |
64 | * @param istate Interrupted state. |
64 | */ |
65 | */ |
65 | void tick_interrupt(int n, istate_t *istate) |
66 | void tick_interrupt(int n, istate_t *istate) |
66 | { |
67 | { |
67 | softint_reg_t softint, clear; |
68 | softint_reg_t softint, clear; |
68 | uint64_t next, compare, start, stop; |
69 | uint64_t drift; |
69 | 70 | ||
70 | softint.value = softint_read(); |
71 | softint.value = softint_read(); |
71 | 72 | ||
72 | /* |
73 | /* |
73 | * Make sure we are servicing interrupt_level_14 |
74 | * Make sure we are servicing interrupt_level_14 |
Line 85... | Line 86... | ||
85 | clear.value = 0; |
86 | clear.value = 0; |
86 | clear.tick_int = 1; |
87 | clear.tick_int = 1; |
87 | clear_softint_write(clear.value); |
88 | clear_softint_write(clear.value); |
88 | 89 | ||
89 | /* |
90 | /* |
90 | * Restart counter. |
91 | * Reprogram the compare register. |
- | 92 | * For now, we can ignore the potential of the registers to overflow. |
|
- | 93 | * On a 360MHz Ultra 60, the 63-bit compare counter will overflow in |
|
- | 94 | * about 812 years. If there was a 2GHz UltraSPARC computer, it would |
|
- | 95 | * overflow only in 146 years. |
|
91 | */ |
96 | */ |
92 | compare = CPU->arch.clock_frequency/HZ; |
97 | drift = tick_read() - CPU->arch.next_tick_cmpr; |
93 | start = tick_read(); |
- | |
94 | next = start - compare; |
- | |
95 | while (next >= compare - TICK_RESTART_TIME) { |
98 | while (drift > CPU->arch.clock_frequency / HZ) { |
96 | next -= compare; |
99 | drift -= CPU->arch.clock_frequency / HZ; |
97 | CPU->missed_clock_ticks++; |
100 | CPU->missed_clock_ticks++; |
98 | } |
101 | } |
- | 102 | CPU->arch.next_tick_cmpr = tick_read() + (CPU->arch.clock_frequency / HZ) |
|
99 | stop = tick_read(); |
103 | - drift; |
100 | tick_write(next + (stop - start)); |
104 | tick_compare_write(CPU->arch.next_tick_cmpr); |
101 | - | ||
102 | clock(); |
105 | clock(); |
103 | } |
106 | } |
104 | 107 | ||
105 | /** @} |
108 | /** @} |
106 | */ |
109 | */ |