1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
/*-
* Copyright (c) 2001 Matthew Dillon. This code is distributed under
* the BSD copyright, /usr/src/COPYRIGHT.
*
* $FreeBSD$
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/signalvar.h>
#include <sys/kernel.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/pcpu.h>
#include <sys/proc.h>
#include <sys/sysctl.h>
#include <sys/ucontext.h>
#include <machine/critical.h>
#ifdef SMP
#include <machine/privatespace.h>
#include <machine/smp.h>
#else
/*
* XXX this mess to get sched_ithd() and call_fast_unpend()
*/
#include <sys/bus.h>
#include <machine/apic.h>
#include <machine/frame.h>
#include <i386/isa/icu.h>
#include <i386/isa/intr_machdep.h>
#endif
void i386_unpend(void); /* NOTE: not static, called from assembly */
/*
* cpu_unpend() - called from critical_exit() inline after quick
* interrupt-pending check.
*/
void
cpu_unpend(void)
{
register_t eflags;
struct thread *td;
td = curthread;
eflags = intr_disable();
if (PCPU_GET(int_pending)) {
++td->td_intr_nesting_level;
i386_unpend();
--td->td_intr_nesting_level;
}
intr_restore(eflags);
}
/*
* cpu_critical_fork_exit() - cleanup after fork
*
* For i386 we do not have to do anything, td_critnest is
* handled by the fork trampoline code.
*/
void
cpu_critical_fork_exit(void)
{
}
/*
* cpu_thread_link() - thread linkup, initialize machine-dependant fields
*
* There are currently no machine-dependant fields that require
* initialization.
*/
void
cpu_thread_link(struct thread *td)
{
}
/*
* Called from cpu_unpend or called from the assembly vector code
* to process any interrupts which may have occured while we were in
* a critical section.
*
* - interrupts must be disabled
* - td_critnest must be 0
* - td_intr_nesting_level must be incremented by the caller
*
* NOT STATIC (called from assembly)
*/
void
i386_unpend(void)
{
KASSERT(curthread->td_critnest == 0, ("unpend critnest != 0"));
KASSERT((read_eflags() & PSL_I) == 0, ("unpend interrupts enabled1"));
curthread->td_critnest = 1;
for (;;) {
u_int32_t mask;
int irq;
/*
* Fast interrupts have priority
*/
if ((mask = PCPU_GET(fpending)) != 0) {
irq = bsfl(mask);
PCPU_SET(fpending, mask & ~(1 << irq));
call_fast_unpend(irq);
KASSERT((read_eflags() & PSL_I) == 0,
("unpend interrupts enabled2 %d", irq));
continue;
}
/*
* Threaded interrupts come next
*/
if ((mask = PCPU_GET(ipending)) != 0) {
irq = bsfl(mask);
PCPU_SET(ipending, mask & ~(1 << irq));
sched_ithd((void *)irq);
KASSERT((read_eflags() & PSL_I) == 0,
("unpend interrupts enabled3 %d", irq));
continue;
}
/*
* Software interrupts and delayed IPIs are last
*
* XXX give the bits #defined names. see also
* isa/xxx_vector.s
*/
if ((mask = PCPU_GET(spending)) != 0) {
irq = bsfl(mask);
PCPU_SET(spending, mask & ~(1 << irq));
switch(irq) {
case 0: /* bit 0 - hardclock */
mtx_lock_spin(&sched_lock);
hardclock_process(curthread, 0);
mtx_unlock_spin(&sched_lock);
break;
case 1: /* bit 1 - statclock */
mtx_lock_spin(&sched_lock);
statclock_process(curthread,
(register_t)i386_unpend, 0);
mtx_unlock_spin(&sched_lock);
break;
}
KASSERT((read_eflags() & PSL_I) == 0,
("unpend interrupts enabled4 %d", irq));
continue;
}
break;
}
/*
* Interrupts are still disabled, we can safely clear int_pending
* and td_critnest.
*/
KASSERT((read_eflags() & PSL_I) == 0, ("unpend interrupts enabled5"));
PCPU_SET(int_pending, 0);
curthread->td_critnest = 0;
}
|