Skip to content

Commit 8531a35

Browse files
Kevin D. Kissellralfbaechle
authored andcommitted
[MIPS] SMTC: Fix SMTC dyntick support.
Rework of SMTC support to make it work with the new clock event system, allowing "tickless" operation, and to make it compatible with the use of the "wait_irqoff" idle loop. The new clocking scheme means that the previously optional IPI instant replay mechanism is now required, and has been made more robust. Signed-off-by: Kevin D. Kissell <kevink@paralogos.com> Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
1 parent d2bb01b commit 8531a35

11 files changed

Lines changed: 597 additions & 279 deletions

File tree

‎arch/mips/Kconfig‎

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,7 +1403,6 @@ config MIPS_MT_SMTC
14031403
depends on CPU_MIPS32_R2
14041404
#depends on CPU_MIPS64_R2 # once there is hardware ...
14051405
depends on SYS_SUPPORTS_MULTITHREADING
1406-
select GENERIC_CLOCKEVENTS_BROADCAST
14071406
select CPU_MIPSR2_IRQ_VI
14081407
select CPU_MIPSR2_IRQ_EI
14091408
select MIPS_MT
@@ -1451,32 +1450,17 @@ config MIPS_VPE_LOADER
14511450
Includes a loader for loading an elf relocatable object
14521451
onto another VPE and running it.
14531452

1454-
config MIPS_MT_SMTC_INSTANT_REPLAY
1455-
bool "Low-latency Dispatch of Deferred SMTC IPIs"
1456-
depends on MIPS_MT_SMTC && !PREEMPT
1457-
default y
1458-
help
1459-
SMTC pseudo-interrupts between TCs are deferred and queued
1460-
if the target TC is interrupt-inhibited (IXMT). In the first
1461-
SMTC prototypes, these queued IPIs were serviced on return
1462-
to user mode, or on entry into the kernel idle loop. The
1463-
INSTANT_REPLAY option dispatches them as part of local_irq_restore()
1464-
processing, which adds runtime overhead (hence the option to turn
1465-
it off), but ensures that IPIs are handled promptly even under
1466-
heavy I/O interrupt load.
1467-
14681453
config MIPS_MT_SMTC_IM_BACKSTOP
14691454
bool "Use per-TC register bits as backstop for inhibited IM bits"
14701455
depends on MIPS_MT_SMTC
1471-
default y
1456+
default n
14721457
help
14731458
To support multiple TC microthreads acting as "CPUs" within
14741459
a VPE, VPE-wide interrupt mask bits must be specially manipulated
14751460
during interrupt handling. To support legacy drivers and interrupt
14761461
controller management code, SMTC has a "backstop" to track and
14771462
if necessary restore the interrupt mask. This has some performance
1478-
impact on interrupt service overhead. Disable it only if you know
1479-
what you are doing.
1463+
impact on interrupt service overhead.
14801464

14811465
config MIPS_MT_SMTC_IRQAFF
14821466
bool "Support IRQ affinity API"
@@ -1486,10 +1470,8 @@ config MIPS_MT_SMTC_IRQAFF
14861470
Enables SMP IRQ affinity API (/proc/irq/*/smp_affinity, etc.)
14871471
for SMTC Linux kernel. Requires platform support, of which
14881472
an example can be found in the MIPS kernel i8259 and Malta
1489-
platform code. It is recommended that MIPS_MT_SMTC_INSTANT_REPLAY
1490-
be enabled if MIPS_MT_SMTC_IRQAFF is used. Adds overhead to
1491-
interrupt dispatch, and should be used only if you know what
1492-
you are doing.
1473+
platform code. Adds some overhead to interrupt dispatch, and
1474+
should be used only if you know what you are doing.
14931475

14941476
config MIPS_VPE_LOADER_TOM
14951477
bool "Load VPE program into memory hidden from linux"

‎arch/mips/kernel/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ obj-y += cpu-probe.o branch.o entry.o genex.o irq.o process.o \
1010

1111
obj-$(CONFIG_CEVT_BCM1480) += cevt-bcm1480.o
1212
obj-$(CONFIG_CEVT_R4K) += cevt-r4k.o
13+
obj-$(CONFIG_MIPS_MT_SMTC) += cevt-smtc.o
1314
obj-$(CONFIG_CEVT_DS1287) += cevt-ds1287.o
1415
obj-$(CONFIG_CEVT_GT641XX) += cevt-gt641xx.o
1516
obj-$(CONFIG_CEVT_SB1250) += cevt-sb1250.o

‎arch/mips/kernel/cevt-r4k.c‎

Lines changed: 48 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -12,67 +12,42 @@
1212

1313
#include <asm/smtc_ipi.h>
1414
#include <asm/time.h>
15+
#include <asm/cevt-r4k.h>
16+
17+
/*
18+
* The SMTC Kernel for the 34K, 1004K, et. al. replaces several
19+
* of these routines with SMTC-specific variants.
20+
*/
21+
22+
#ifndef CONFIG_MIPS_MT_SMTC
1523

1624
static int mips_next_event(unsigned long delta,
1725
struct clock_event_device *evt)
1826
{
1927
unsigned int cnt;
2028
int res;
2129

22-
#ifdef CONFIG_MIPS_MT_SMTC
23-
{
24-
unsigned long flags, vpflags;
25-
local_irq_save(flags);
26-
vpflags = dvpe();
27-
#endif
2830
cnt = read_c0_count();
2931
cnt += delta;
3032
write_c0_compare(cnt);
3133
res = ((int)(read_c0_count() - cnt) > 0) ? -ETIME : 0;
32-
#ifdef CONFIG_MIPS_MT_SMTC
33-
evpe(vpflags);
34-
local_irq_restore(flags);
35-
}
36-
#endif
3734
return res;
3835
}
3936

40-
static void mips_set_mode(enum clock_event_mode mode,
41-
struct clock_event_device *evt)
37+
#endif /* CONFIG_MIPS_MT_SMTC */
38+
39+
void mips_set_clock_mode(enum clock_event_mode mode,
40+
struct clock_event_device *evt)
4241
{
4342
/* Nothing to do ... */
4443
}
4544

46-
static DEFINE_PER_CPU(struct clock_event_device, mips_clockevent_device);
47-
static int cp0_timer_irq_installed;
45+
DEFINE_PER_CPU(struct clock_event_device, mips_clockevent_device);
46+
int cp0_timer_irq_installed;
4847

49-
/*
50-
* Timer ack for an R4k-compatible timer of a known frequency.
51-
*/
52-
static void c0_timer_ack(void)
53-
{
54-
write_c0_compare(read_c0_compare());
55-
}
48+
#ifndef CONFIG_MIPS_MT_SMTC
5649

57-
/*
58-
* Possibly handle a performance counter interrupt.
59-
* Return true if the timer interrupt should not be checked
60-
*/
61-
static inline int handle_perf_irq(int r2)
62-
{
63-
/*
64-
* The performance counter overflow interrupt may be shared with the
65-
* timer interrupt (cp0_perfcount_irq < 0). If it is and a
66-
* performance counter has overflowed (perf_irq() == IRQ_HANDLED)
67-
* and we can't reliably determine if a counter interrupt has also
68-
* happened (!r2) then don't check for a timer interrupt.
69-
*/
70-
return (cp0_perfcount_irq < 0) &&
71-
perf_irq() == IRQ_HANDLED &&
72-
!r2;
73-
}
74-
75-
static irqreturn_t c0_compare_interrupt(int irq, void *dev_id)
50+
irqreturn_t c0_compare_interrupt(int irq, void *dev_id)
7651
{
7752
const int r2 = cpu_has_mips_r2;
7853
struct clock_event_device *cd;
@@ -93,12 +68,8 @@ static irqreturn_t c0_compare_interrupt(int irq, void *dev_id)
9368
* interrupt. Being the paranoiacs we are we check anyway.
9469
*/
9570
if (!r2 || (read_c0_cause() & (1 << 30))) {
96-
c0_timer_ack();
97-
#ifdef CONFIG_MIPS_MT_SMTC
98-
if (cpu_data[cpu].vpe_id)
99-
goto out;
100-
cpu = 0;
101-
#endif
71+
/* Clear Count/Compare Interrupt */
72+
write_c0_compare(read_c0_compare());
10273
cd = &per_cpu(mips_clockevent_device, cpu);
10374
cd->event_handler(cd);
10475
}
@@ -107,65 +78,16 @@ static irqreturn_t c0_compare_interrupt(int irq, void *dev_id)
10778
return IRQ_HANDLED;
10879
}
10980

110-
static struct irqaction c0_compare_irqaction = {
81+
#endif /* Not CONFIG_MIPS_MT_SMTC */
82+
83+
struct irqaction c0_compare_irqaction = {
11184
.handler = c0_compare_interrupt,
112-
#ifdef CONFIG_MIPS_MT_SMTC
113-
.flags = IRQF_DISABLED,
114-
#else
11585
.flags = IRQF_DISABLED | IRQF_PERCPU,
116-
#endif
11786
.name = "timer",
11887
};
11988

120-
#ifdef CONFIG_MIPS_MT_SMTC
121-
DEFINE_PER_CPU(struct clock_event_device, smtc_dummy_clockevent_device);
122-
123-
static void smtc_set_mode(enum clock_event_mode mode,
124-
struct clock_event_device *evt)
125-
{
126-
}
127-
128-
static void mips_broadcast(cpumask_t mask)
129-
{
130-
unsigned int cpu;
131-
132-
for_each_cpu_mask(cpu, mask)
133-
smtc_send_ipi(cpu, SMTC_CLOCK_TICK, 0);
134-
}
135-
136-
static void setup_smtc_dummy_clockevent_device(void)
137-
{
138-
//uint64_t mips_freq = mips_hpt_^frequency;
139-
unsigned int cpu = smp_processor_id();
140-
struct clock_event_device *cd;
14189

142-
cd = &per_cpu(smtc_dummy_clockevent_device, cpu);
143-
144-
cd->name = "SMTC";
145-
cd->features = CLOCK_EVT_FEAT_DUMMY;
146-
147-
/* Calculate the min / max delta */
148-
cd->mult = 0; //div_sc((unsigned long) mips_freq, NSEC_PER_SEC, 32);
149-
cd->shift = 0; //32;
150-
cd->max_delta_ns = 0; //clockevent_delta2ns(0x7fffffff, cd);
151-
cd->min_delta_ns = 0; //clockevent_delta2ns(0x30, cd);
152-
153-
cd->rating = 200;
154-
cd->irq = 17; //-1;
155-
// if (cpu)
156-
// cd->cpumask = CPU_MASK_ALL; // cpumask_of_cpu(cpu);
157-
// else
158-
cd->cpumask = cpumask_of_cpu(cpu);
159-
160-
cd->set_mode = smtc_set_mode;
161-
162-
cd->broadcast = mips_broadcast;
163-
164-
clockevents_register_device(cd);
165-
}
166-
#endif
167-
168-
static void mips_event_handler(struct clock_event_device *dev)
90+
void mips_event_handler(struct clock_event_device *dev)
16991
{
17092
}
17193

@@ -177,7 +99,23 @@ static int c0_compare_int_pending(void)
17799
return (read_c0_cause() >> cp0_compare_irq) & 0x100;
178100
}
179101

180-
static int c0_compare_int_usable(void)
102+
/*
103+
* Compare interrupt can be routed and latched outside the core,
104+
* so a single execution hazard barrier may not be enough to give
105+
* it time to clear as seen in the Cause register. 4 time the
106+
* pipeline depth seems reasonably conservative, and empirically
107+
* works better in configurations with high CPU/bus clock ratios.
108+
*/
109+
110+
#define compare_change_hazard() \
111+
do { \
112+
irq_disable_hazard(); \
113+
irq_disable_hazard(); \
114+
irq_disable_hazard(); \
115+
irq_disable_hazard(); \
116+
} while (0)
117+
118+
int c0_compare_int_usable(void)
181119
{
182120
unsigned int delta;
183121
unsigned int cnt;
@@ -187,7 +125,7 @@ static int c0_compare_int_usable(void)
187125
*/
188126
if (c0_compare_int_pending()) {
189127
write_c0_compare(read_c0_count());
190-
irq_disable_hazard();
128+
compare_change_hazard();
191129
if (c0_compare_int_pending())
192130
return 0;
193131
}
@@ -196,7 +134,7 @@ static int c0_compare_int_usable(void)
196134
cnt = read_c0_count();
197135
cnt += delta;
198136
write_c0_compare(cnt);
199-
irq_disable_hazard();
137+
compare_change_hazard();
200138
if ((int)(read_c0_count() - cnt) < 0)
201139
break;
202140
/* increase delta if the timer was already expired */
@@ -205,11 +143,12 @@ static int c0_compare_int_usable(void)
205143
while ((int)(read_c0_count() - cnt) <= 0)
206144
; /* Wait for expiry */
207145

146+
compare_change_hazard();
208147
if (!c0_compare_int_pending())
209148
return 0;
210149

211150
write_c0_compare(read_c0_count());
212-
irq_disable_hazard();
151+
compare_change_hazard();
213152
if (c0_compare_int_pending())
214153
return 0;
215154

@@ -219,6 +158,8 @@ static int c0_compare_int_usable(void)
219158
return 1;
220159
}
221160

161+
#ifndef CONFIG_MIPS_MT_SMTC
162+
222163
int __cpuinit mips_clockevent_init(void)
223164
{
224165
uint64_t mips_freq = mips_hpt_frequency;
@@ -229,17 +170,6 @@ int __cpuinit mips_clockevent_init(void)
229170
if (!cpu_has_counter || !mips_hpt_frequency)
230171
return -ENXIO;
231172

232-
#ifdef CONFIG_MIPS_MT_SMTC
233-
setup_smtc_dummy_clockevent_device();
234-
235-
/*
236-
* On SMTC we only register VPE0's compare interrupt as clockevent
237-
* device.
238-
*/
239-
if (cpu)
240-
return 0;
241-
#endif
242-
243173
if (!c0_compare_int_usable())
244174
return -ENXIO;
245175

@@ -265,13 +195,9 @@ int __cpuinit mips_clockevent_init(void)
265195

266196
cd->rating = 300;
267197
cd->irq = irq;
268-
#ifdef CONFIG_MIPS_MT_SMTC
269-
cd->cpumask = CPU_MASK_ALL;
270-
#else
271198
cd->cpumask = cpumask_of_cpu(cpu);
272-
#endif
273199
cd->set_next_event = mips_next_event;
274-
cd->set_mode = mips_set_mode;
200+
cd->set_mode = mips_set_clock_mode;
275201
cd->event_handler = mips_event_handler;
276202

277203
clockevents_register_device(cd);
@@ -281,12 +207,9 @@ int __cpuinit mips_clockevent_init(void)
281207

282208
cp0_timer_irq_installed = 1;
283209

284-
#ifdef CONFIG_MIPS_MT_SMTC
285-
#define CPUCTR_IMASKBIT (0x100 << cp0_compare_irq)
286-
setup_irq_smtc(irq, &c0_compare_irqaction, CPUCTR_IMASKBIT);
287-
#else
288210
setup_irq(irq, &c0_compare_irqaction);
289-
#endif
290211

291212
return 0;
292213
}
214+
215+
#endif /* Not CONFIG_MIPS_MT_SMTC */

0 commit comments

Comments
 (0)