Skip to content

Commit 96a3d99

Browse files
committed
Merge branch 'x86-tracing-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 tracing updates from Ingo Molnar: "This tree adds IRQ vector tracepoints that are named after the handler and which output the vector #, based on a zero-overhead approach that relies on changing the IDT entries, by Seiji Aguchi. The new tracepoints look like this: # perf list | grep -i irq_vector irq_vectors:local_timer_entry [Tracepoint event] irq_vectors:local_timer_exit [Tracepoint event] irq_vectors:reschedule_entry [Tracepoint event] irq_vectors:reschedule_exit [Tracepoint event] irq_vectors:spurious_apic_entry [Tracepoint event] irq_vectors:spurious_apic_exit [Tracepoint event] irq_vectors:error_apic_entry [Tracepoint event] irq_vectors:error_apic_exit [Tracepoint event] [...]" * 'x86-tracing-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86/tracing: Add config option checking to the definitions of mce handlers trace,x86: Do not call local_irq_save() in load_current_idt() trace,x86: Move creation of irq tracepoints from apic.c to irq.c x86, trace: Add irq vector tracepoints x86: Rename variables for debugging x86, trace: Introduce entering/exiting_irq() tracing: Add DEFINE_EVENT_FN() macro
2 parents 3045f94 + 5236eb9 commit 96a3d99

24 files changed

Lines changed: 602 additions & 72 deletions

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <asm/fixmap.h>
1313
#include <asm/mpspec.h>
1414
#include <asm/msr.h>
15+
#include <asm/idle.h>
1516

1617
#define ARCH_APICTIMER_STOPS_ON_C3 1
1718

@@ -687,5 +688,31 @@ extern int default_check_phys_apicid_present(int phys_apicid);
687688
#endif
688689

689690
#endif /* CONFIG_X86_LOCAL_APIC */
691+
extern void irq_enter(void);
692+
extern void irq_exit(void);
693+
694+
static inline void entering_irq(void)
695+
{
696+
irq_enter();
697+
exit_idle();
698+
}
699+
700+
static inline void entering_ack_irq(void)
701+
{
702+
ack_APIC_irq();
703+
entering_irq();
704+
}
705+
706+
static inline void exiting_irq(void)
707+
{
708+
irq_exit();
709+
}
710+
711+
static inline void exiting_ack_irq(void)
712+
{
713+
irq_exit();
714+
/* Ack only at the end to avoid potential reentry */
715+
ack_APIC_irq();
716+
}
690717

691718
#endif /* _ASM_X86_APIC_H */

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

Lines changed: 112 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
3636

3737
extern struct desc_ptr idt_descr;
3838
extern gate_desc idt_table[];
39-
extern struct desc_ptr nmi_idt_descr;
40-
extern gate_desc nmi_idt_table[];
39+
extern struct desc_ptr debug_idt_descr;
40+
extern gate_desc debug_idt_table[];
4141

4242
struct gdt_page {
4343
struct desc_struct gdt[GDT_ENTRIES];
@@ -316,7 +316,20 @@ static inline void set_nmi_gate(int gate, void *addr)
316316
gate_desc s;
317317

318318
pack_gate(&s, GATE_INTERRUPT, (unsigned long)addr, 0, 0, __KERNEL_CS);
319-
write_idt_entry(nmi_idt_table, gate, &s);
319+
write_idt_entry(debug_idt_table, gate, &s);
320+
}
321+
#endif
322+
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+
{
320333
}
321334
#endif
322335

@@ -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
*/
@@ -405,4 +446,70 @@ static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
405446
_set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
406447
}
407448

449+
#ifdef CONFIG_X86_64
450+
DECLARE_PER_CPU(u32, debug_idt_ctr);
451+
static inline bool is_debug_idt_enabled(void)
452+
{
453+
if (this_cpu_read(debug_idt_ctr))
454+
return true;
455+
456+
return false;
457+
}
458+
459+
static inline void load_debug_idt(void)
460+
{
461+
load_idt((const struct desc_ptr *)&debug_idt_descr);
462+
}
463+
#else
464+
static inline bool is_debug_idt_enabled(void)
465+
{
466+
return false;
467+
}
468+
469+
static inline void load_debug_idt(void)
470+
{
471+
}
472+
#endif
473+
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+
499+
/*
500+
* The load_current_idt() must be called with interrupts disabled
501+
* to avoid races. That way the IDT will always be set back to the expected
502+
* descriptor. It's also called when a CPU is being initialized, and
503+
* that doesn't need to disable interrupts, as nothing should be
504+
* bothering the CPU then.
505+
*/
506+
static inline void load_current_idt(void)
507+
{
508+
if (is_debug_idt_enabled())
509+
load_debug_idt();
510+
else if (is_trace_idt_enabled())
511+
load_trace_idt();
512+
else
513+
load_idt((const struct desc_ptr *)&idt_descr);
514+
}
408515
#endif /* _ASM_X86_DESC_H */

‎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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ CFLAGS_REMOVE_ftrace.o = -pg
1616
CFLAGS_REMOVE_early_printk.o = -pg
1717
endif
1818

19+
CFLAGS_irq.o := -I$(src)/../include/asm/trace
20+
1921
obj-y := process_$(BITS).o signal.o entry_$(BITS).o
2022
obj-y += traps.o irq.o irq_$(BITS).o dumpstack_$(BITS).o
2123
obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
@@ -103,6 +105,7 @@ obj-$(CONFIG_OF) += devicetree.o
103105
obj-$(CONFIG_UPROBES) += uprobes.o
104106

105107
obj-$(CONFIG_PERF_EVENTS) += perf_regs.o
108+
obj-$(CONFIG_TRACING) += tracepoint.o
106109

107110
###
108111
# 64 bit specific files

0 commit comments

Comments
 (0)