Skip to content

Commit cf910e8

Browse files
Seiji AguchiH. Peter Anvin
authored andcommitted
x86, trace: Add irq vector tracepoints
[Purpose of this patch] As Vaibhav explained in the thread below, tracepoints for irq vectors are useful. http://www.spinics.net/lists/mm-commits/msg85707.html <snip> The current interrupt traces from irq_handler_entry and irq_handler_exit provide when an interrupt is handled. They provide good data about when the system has switched to kernel space and how it affects the currently running processes. There are some IRQ vectors which trigger the system into kernel space, which are not handled in generic IRQ handlers. Tracing such events gives us the information about IRQ interaction with other system events. The trace also tells where the system is spending its time. We want to know which cores are handling interrupts and how they are affecting other processes in the system. Also, the trace provides information about when the cores are idle and which interrupts are changing that state. <snip> On the other hand, my usecase is tracing just local timer event and getting a value of instruction pointer. I suggested to add an argument local timer event to get instruction pointer before. But there is another way to get it with external module like systemtap. So, I don't need to add any argument to irq vector tracepoints now. [Patch Description] Vaibhav's patch shared a trace point ,irq_vector_entry/irq_vector_exit, in all events. But there is an above use case to trace specific irq_vector rather than tracing all events. In this case, we are concerned about overhead due to unwanted events. So, add following tracepoints instead of introducing irq_vector_entry/exit. so that we can enable them independently. - local_timer_vector - reschedule_vector - call_function_vector - call_function_single_vector - irq_work_entry_vector - error_apic_vector - thermal_apic_vector - threshold_apic_vector - spurious_apic_vector - x86_platform_ipi_vector Also, introduce a logic switching IDT at enabling/disabling time so that a time penalty makes a zero when tracepoints are disabled. Detailed explanations are as follows. - Create trace irq handlers with entering_irq()/exiting_irq(). - Create a new IDT, trace_idt_table, at boot time by adding a logic to _set_gate(). It is just a copy of original idt table. - Register the new handlers for tracpoints to the new IDT by introducing macros to alloc_intr_gate() called at registering time of irq_vector handlers. - Add checking, whether irq vector tracing is on/off, into load_current_idt(). This has to be done below debug checking for these reasons. - Switching to debug IDT may be kicked while tracing is enabled. - On the other hands, switching to trace IDT is kicked only when debugging is disabled. In addition, the new IDT is created only when CONFIG_TRACING is enabled to avoid being used for other purposes. Signed-off-by: Seiji Aguchi <seiji.aguchi@hds.com> Link: http://lkml.kernel.org/r/51C323ED.5050708@hds.com Signed-off-by: H. Peter Anvin <hpa@linux.intel.com> Cc: Steven Rostedt <rostedt@goodmis.org>
1 parent 629f4f9 commit cf910e8

20 files changed

Lines changed: 422 additions & 15 deletions

File tree

‎arch/x86/include/asm/desc.h‎

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,19 @@ static inline void set_nmi_gate(int gate, void *addr)
320320
}
321321
#endif
322322

323+
#ifdef CONFIG_TRACING
324+
extern struct desc_ptr trace_idt_descr;
325+
extern gate_desc trace_idt_table[];
326+
static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
327+
{
328+
write_idt_entry(trace_idt_table, entry, gate);
329+
}
330+
#else
331+
static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
332+
{
333+
}
334+
#endif
335+
323336
static inline void _set_gate(int gate, unsigned type, void *addr,
324337
unsigned dpl, unsigned ist, unsigned seg)
325338
{
@@ -331,6 +344,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
331344
* setup time
332345
*/
333346
write_idt_entry(idt_table, gate, &s);
347+
write_trace_idt_entry(gate, &s);
334348
}
335349

336350
/*
@@ -360,12 +374,39 @@ static inline void alloc_system_vector(int vector)
360374
}
361375
}
362376

363-
static inline void alloc_intr_gate(unsigned int n, void *addr)
377+
#ifdef CONFIG_TRACING
378+
static inline void trace_set_intr_gate(unsigned int gate, void *addr)
379+
{
380+
gate_desc s;
381+
382+
pack_gate(&s, GATE_INTERRUPT, (unsigned long)addr, 0, 0, __KERNEL_CS);
383+
write_idt_entry(trace_idt_table, gate, &s);
384+
}
385+
386+
static inline void __trace_alloc_intr_gate(unsigned int n, void *addr)
387+
{
388+
trace_set_intr_gate(n, addr);
389+
}
390+
#else
391+
static inline void trace_set_intr_gate(unsigned int gate, void *addr)
392+
{
393+
}
394+
395+
#define __trace_alloc_intr_gate(n, addr)
396+
#endif
397+
398+
static inline void __alloc_intr_gate(unsigned int n, void *addr)
364399
{
365-
alloc_system_vector(n);
366400
set_intr_gate(n, addr);
367401
}
368402

403+
#define alloc_intr_gate(n, addr) \
404+
do { \
405+
alloc_system_vector(n); \
406+
__alloc_intr_gate(n, addr); \
407+
__trace_alloc_intr_gate(n, trace_##addr); \
408+
} while (0)
409+
369410
/*
370411
* This routine sets up an interrupt gate at directory privilege level 3.
371412
*/
@@ -430,6 +471,31 @@ static inline void load_debug_idt(void)
430471
}
431472
#endif
432473

474+
#ifdef CONFIG_TRACING
475+
extern atomic_t trace_idt_ctr;
476+
static inline bool is_trace_idt_enabled(void)
477+
{
478+
if (atomic_read(&trace_idt_ctr))
479+
return true;
480+
481+
return false;
482+
}
483+
484+
static inline void load_trace_idt(void)
485+
{
486+
load_idt((const struct desc_ptr *)&trace_idt_descr);
487+
}
488+
#else
489+
static inline bool is_trace_idt_enabled(void)
490+
{
491+
return false;
492+
}
493+
494+
static inline void load_trace_idt(void)
495+
{
496+
}
497+
#endif
498+
433499
/*
434500
* the load_current_idt() is called with interrupt disabled by local_irq_save()
435501
* to avoid races. That way the IDT will always be set back to the expected
@@ -442,6 +508,8 @@ static inline void load_current_idt(void)
442508
local_irq_save(flags);
443509
if (is_debug_idt_enabled())
444510
load_debug_idt();
511+
else if (is_trace_idt_enabled())
512+
load_trace_idt();
445513
else
446514
load_idt((const struct desc_ptr *)&idt_descr);
447515
local_irq_restore(flags);

‎arch/x86/include/asm/entry_arch.h‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@
1313
BUILD_INTERRUPT(reschedule_interrupt,RESCHEDULE_VECTOR)
1414
BUILD_INTERRUPT(call_function_interrupt,CALL_FUNCTION_VECTOR)
1515
BUILD_INTERRUPT(call_function_single_interrupt,CALL_FUNCTION_SINGLE_VECTOR)
16-
BUILD_INTERRUPT(irq_move_cleanup_interrupt,IRQ_MOVE_CLEANUP_VECTOR)
17-
BUILD_INTERRUPT(reboot_interrupt,REBOOT_VECTOR)
16+
BUILD_INTERRUPT3(irq_move_cleanup_interrupt, IRQ_MOVE_CLEANUP_VECTOR,
17+
smp_irq_move_cleanup_interrupt)
18+
BUILD_INTERRUPT3(reboot_interrupt, REBOOT_VECTOR, smp_reboot_interrupt)
1819
#endif
1920

2021
BUILD_INTERRUPT(x86_platform_ipi, X86_PLATFORM_IPI_VECTOR)
2122

2223
#ifdef CONFIG_HAVE_KVM
23-
BUILD_INTERRUPT(kvm_posted_intr_ipi, POSTED_INTR_VECTOR)
24+
BUILD_INTERRUPT3(kvm_posted_intr_ipi, POSTED_INTR_VECTOR,
25+
smp_kvm_posted_intr_ipi)
2426
#endif
2527

2628
/*

‎arch/x86/include/asm/hw_irq.h‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,23 @@ extern void threshold_interrupt(void);
7777
extern void call_function_interrupt(void);
7878
extern void call_function_single_interrupt(void);
7979

80+
#ifdef CONFIG_TRACING
81+
/* Interrupt handlers registered during init_IRQ */
82+
extern void trace_apic_timer_interrupt(void);
83+
extern void trace_x86_platform_ipi(void);
84+
extern void trace_error_interrupt(void);
85+
extern void trace_irq_work_interrupt(void);
86+
extern void trace_spurious_interrupt(void);
87+
extern void trace_thermal_interrupt(void);
88+
extern void trace_reschedule_interrupt(void);
89+
extern void trace_threshold_interrupt(void);
90+
extern void trace_call_function_interrupt(void);
91+
extern void trace_call_function_single_interrupt(void);
92+
#define trace_irq_move_cleanup_interrupt irq_move_cleanup_interrupt
93+
#define trace_reboot_interrupt reboot_interrupt
94+
#define trace_kvm_posted_intr_ipi kvm_posted_intr_ipi
95+
#endif /* CONFIG_TRACING */
96+
8097
/* IOAPIC */
8198
#define IO_APIC_IRQ(x) (((x) >= NR_IRQS_LEGACY) || ((1<<(x)) & io_apic_irqs))
8299
extern unsigned long io_apic_irqs;

‎arch/x86/include/asm/mshyperv.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ struct ms_hyperv_info {
1212
extern struct ms_hyperv_info ms_hyperv;
1313

1414
void hyperv_callback_vector(void);
15+
#ifdef CONFIG_TRACING
16+
#define trace_hyperv_callback_vector hyperv_callback_vector
17+
#endif
1518
void hyperv_vector_handler(struct pt_regs *regs);
1619
void hv_register_vmbus_handler(int irq, irq_handler_t handler);
1720

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
#undef TRACE_SYSTEM
2+
#define TRACE_SYSTEM irq_vectors
3+
4+
#if !defined(_TRACE_IRQ_VECTORS_H) || defined(TRACE_HEADER_MULTI_READ)
5+
#define _TRACE_IRQ_VECTORS_H
6+
7+
#include <linux/tracepoint.h>
8+
9+
extern void trace_irq_vector_regfunc(void);
10+
extern void trace_irq_vector_unregfunc(void);
11+
12+
DECLARE_EVENT_CLASS(x86_irq_vector,
13+
14+
TP_PROTO(int vector),
15+
16+
TP_ARGS(vector),
17+
18+
TP_STRUCT__entry(
19+
__field( int, vector )
20+
),
21+
22+
TP_fast_assign(
23+
__entry->vector = vector;
24+
),
25+
26+
TP_printk("vector=%d", __entry->vector) );
27+
28+
#define DEFINE_IRQ_VECTOR_EVENT(name) \
29+
DEFINE_EVENT_FN(x86_irq_vector, name##_entry, \
30+
TP_PROTO(int vector), \
31+
TP_ARGS(vector), \
32+
trace_irq_vector_regfunc, \
33+
trace_irq_vector_unregfunc); \
34+
DEFINE_EVENT_FN(x86_irq_vector, name##_exit, \
35+
TP_PROTO(int vector), \
36+
TP_ARGS(vector), \
37+
trace_irq_vector_regfunc, \
38+
trace_irq_vector_unregfunc);
39+
40+
41+
/*
42+
* local_timer - called when entering/exiting a local timer interrupt
43+
* vector handler
44+
*/
45+
DEFINE_IRQ_VECTOR_EVENT(local_timer);
46+
47+
/*
48+
* reschedule - called when entering/exiting a reschedule vector handler
49+
*/
50+
DEFINE_IRQ_VECTOR_EVENT(reschedule);
51+
52+
/*
53+
* spurious_apic - called when entering/exiting a spurious apic vector handler
54+
*/
55+
DEFINE_IRQ_VECTOR_EVENT(spurious_apic);
56+
57+
/*
58+
* error_apic - called when entering/exiting an error apic vector handler
59+
*/
60+
DEFINE_IRQ_VECTOR_EVENT(error_apic);
61+
62+
/*
63+
* x86_platform_ipi - called when entering/exiting a x86 platform ipi interrupt
64+
* vector handler
65+
*/
66+
DEFINE_IRQ_VECTOR_EVENT(x86_platform_ipi);
67+
68+
/*
69+
* irq_work - called when entering/exiting a irq work interrupt
70+
* vector handler
71+
*/
72+
DEFINE_IRQ_VECTOR_EVENT(irq_work);
73+
74+
/*
75+
* call_function - called when entering/exiting a call function interrupt
76+
* vector handler
77+
*/
78+
DEFINE_IRQ_VECTOR_EVENT(call_function);
79+
80+
/*
81+
* call_function_single - called when entering/exiting a call function
82+
* single interrupt vector handler
83+
*/
84+
DEFINE_IRQ_VECTOR_EVENT(call_function_single);
85+
86+
/*
87+
* threshold_apic - called when entering/exiting a threshold apic interrupt
88+
* vector handler
89+
*/
90+
DEFINE_IRQ_VECTOR_EVENT(threshold_apic);
91+
92+
/*
93+
* thermal_apic - called when entering/exiting a thermal apic interrupt
94+
* vector handler
95+
*/
96+
DEFINE_IRQ_VECTOR_EVENT(thermal_apic);
97+
98+
#undef TRACE_INCLUDE_PATH
99+
#define TRACE_INCLUDE_PATH .
100+
#define TRACE_INCLUDE_FILE irq_vectors
101+
#endif /* _TRACE_IRQ_VECTORS_H */
102+
103+
/* This part must be outside protection */
104+
#include <trace/define_trace.h>

‎arch/x86/include/asm/uv/uv_bau.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,9 @@ static inline void bau_cpubits_clear(struct bau_local_cpumask *dstp, int nbits)
731731
}
732732

733733
extern void uv_bau_message_intr1(void);
734+
#ifdef CONFIG_TRACING
735+
#define trace_uv_bau_message_intr1 uv_bau_message_intr1
736+
#endif
734737
extern void uv_bau_timeout_intr1(void);
735738

736739
struct atomic_short {

‎arch/x86/kernel/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ obj-$(CONFIG_OF) += devicetree.o
102102
obj-$(CONFIG_UPROBES) += uprobes.o
103103

104104
obj-$(CONFIG_PERF_EVENTS) += perf_regs.o
105+
obj-$(CONFIG_TRACING) += tracepoint.o
105106

106107
###
107108
# 64 bit specific files

‎arch/x86/kernel/apic/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Makefile for local APIC drivers and for the IO-APIC code
33
#
44

5+
CFLAGS_apic.o := -I$(src)/../../include/asm/trace
56
obj-$(CONFIG_X86_LOCAL_APIC) += apic.o apic_noop.o ipi.o
67
obj-y += hw_nmi.o
78

‎arch/x86/kernel/apic/apic.c‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@
5555
#include <asm/tsc.h>
5656
#include <asm/hypervisor.h>
5757

58+
#define CREATE_TRACE_POINTS
59+
#include <asm/trace/irq_vectors.h>
60+
5861
unsigned int num_processors;
5962

6063
unsigned disabled_cpus __cpuinitdata;
@@ -931,6 +934,27 @@ void __irq_entry smp_apic_timer_interrupt(struct pt_regs *regs)
931934
set_irq_regs(old_regs);
932935
}
933936

937+
void __irq_entry smp_trace_apic_timer_interrupt(struct pt_regs *regs)
938+
{
939+
struct pt_regs *old_regs = set_irq_regs(regs);
940+
941+
/*
942+
* NOTE! We'd better ACK the irq immediately,
943+
* because timer handling can be slow.
944+
*
945+
* update_process_times() expects us to have done irq_enter().
946+
* Besides, if we don't timer interrupts ignore the global
947+
* interrupt lock, which is the WrongThing (tm) to do.
948+
*/
949+
entering_ack_irq();
950+
trace_local_timer_entry(LOCAL_TIMER_VECTOR);
951+
local_apic_timer_interrupt();
952+
trace_local_timer_exit(LOCAL_TIMER_VECTOR);
953+
exiting_irq();
954+
955+
set_irq_regs(old_regs);
956+
}
957+
934958
int setup_profiling_timer(unsigned int multiplier)
935959
{
936960
return -EINVAL;
@@ -1931,6 +1955,15 @@ void smp_spurious_interrupt(struct pt_regs *regs)
19311955
exiting_irq();
19321956
}
19331957

1958+
void smp_trace_spurious_interrupt(struct pt_regs *regs)
1959+
{
1960+
entering_irq();
1961+
trace_spurious_apic_entry(SPURIOUS_APIC_VECTOR);
1962+
__smp_spurious_interrupt();
1963+
trace_spurious_apic_exit(SPURIOUS_APIC_VECTOR);
1964+
exiting_irq();
1965+
}
1966+
19341967
/*
19351968
* This interrupt should never happen with our APIC/SMP architecture
19361969
*/
@@ -1978,6 +2011,15 @@ void smp_error_interrupt(struct pt_regs *regs)
19782011
exiting_irq();
19792012
}
19802013

2014+
void smp_trace_error_interrupt(struct pt_regs *regs)
2015+
{
2016+
entering_irq();
2017+
trace_error_apic_entry(ERROR_APIC_VECTOR);
2018+
__smp_error_interrupt(regs);
2019+
trace_error_apic_exit(ERROR_APIC_VECTOR);
2020+
exiting_irq();
2021+
}
2022+
19812023
/**
19822024
* connect_bsp_APIC - attach the APIC to the interrupt system
19832025
*/

‎arch/x86/kernel/cpu/common.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,7 +1257,7 @@ void __cpuinit cpu_init(void)
12571257
switch_to_new_gdt(cpu);
12581258
loadsegment(fs, 0);
12591259

1260-
load_idt((const struct desc_ptr *)&idt_descr);
1260+
load_current_idt();
12611261

12621262
memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
12631263
syscall_init();
@@ -1334,7 +1334,7 @@ void __cpuinit cpu_init(void)
13341334
if (cpu_has_vme || cpu_has_tsc || cpu_has_de)
13351335
clear_in_cr4(X86_CR4_VME|X86_CR4_PVI|X86_CR4_TSD|X86_CR4_DE);
13361336

1337-
load_idt(&idt_descr);
1337+
load_current_idt();
13381338
switch_to_new_gdt(cpu);
13391339

13401340
/*

0 commit comments

Comments
 (0)