source: mainline/kernel/arch/sparc64/src/drivers/tick.c

Last change on this file was 4760793, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 18 months ago

Add CPU_LOCAL alongside CPU and segregate fields that are only used locally

This makes it more clear which fields can be used without synchronization
and which need more care.

  • Property mode set to 100644
File size: 3.7 KB
Line 
1/*
2 * Copyright (c) 2005 Jakub Jermar
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup kernel_sparc64
30 * @{
31 */
32/** @file
33 */
34
35#include <arch/drivers/tick.h>
36#include <arch/interrupt.h>
37#include <arch/trap/interrupt.h>
38#include <arch/sparc64.h>
39#include <arch/asm.h>
40#include <arch/register.h>
41#include <arch/cpu.h>
42#include <arch/boot/boot.h>
43#include <time/clock.h>
44#include <arch.h>
45#include <assert.h>
46
47/** Initialize tick and stick interrupt. */
48void tick_init(void)
49{
50 /* initialize TICK interrupt */
51 tick_compare_reg_t compare;
52 softint_reg_t clear;
53
54 compare.int_dis = false;
55 compare.tick_cmpr = tick_counter_read() +
56 CPU->arch.clock_frequency / HZ;
57 CPU->arch.next_tick_cmpr = compare.tick_cmpr;
58 tick_compare_write(compare.value);
59
60 clear.value = 0;
61 clear.tick_int = 1;
62 clear_softint_write(clear.value);
63
64#if defined (US3) || defined (SUN4V)
65 /* disable STICK interrupts and clear any pending ones */
66 tick_compare_reg_t stick_compare;
67
68 stick_compare.value = stick_compare_read();
69 stick_compare.int_dis = true;
70 stick_compare.tick_cmpr = 0;
71 stick_compare_write(stick_compare.value);
72
73 clear.value = 0;
74 clear.stick_int = 1;
75 clear_softint_write(clear.value);
76#endif
77}
78
79/** Process tick interrupt.
80 *
81 * @param n Trap type (0x4e, can be ignored)
82 * @param istate Interrupted state.
83 *
84 */
85void tick_interrupt(unsigned int n, istate_t *istate)
86{
87 softint_reg_t softint, clear;
88 uint64_t drift;
89
90 softint.value = softint_read();
91
92 /*
93 * Make sure we are servicing interrupt_level_14
94 */
95 assert(n == TT_INTERRUPT_LEVEL_14);
96
97 /*
98 * Make sure we are servicing TICK_INT.
99 */
100 assert(softint.tick_int);
101
102 /*
103 * Clear tick interrupt.
104 */
105 clear.value = 0;
106 clear.tick_int = 1;
107 clear_softint_write(clear.value);
108
109 /*
110 * Reprogram the compare register.
111 * For now, we can ignore the potential of the registers to overflow.
112 * On a 360MHz Ultra 60, the 63-bit compare counter will overflow in
113 * about 812 years. If there was a 2GHz UltraSPARC computer, it would
114 * overflow only in 146 years.
115 */
116 drift = tick_counter_read() - CPU->arch.next_tick_cmpr;
117 while (drift > CPU->arch.clock_frequency / HZ) {
118 drift -= CPU->arch.clock_frequency / HZ;
119 CPU_LOCAL->missed_clock_ticks++;
120 }
121 CPU->arch.next_tick_cmpr = tick_counter_read() +
122 (CPU->arch.clock_frequency / HZ) - drift;
123 tick_compare_write(CPU->arch.next_tick_cmpr);
124 clock();
125}
126
127/** @}
128 */
Note: See TracBrowser for help on using the repository browser.