Linux 4.9.243
[linux/fpc-iii.git] / arch / x86 / kernel / tracepoint.c
blob2bb5ee464df3ea1855ee38e7232a38c3d10c5794
1 /*
2 * Code for supporting irq vector tracepoints.
4 * Copyright (C) 2013 Seiji Aguchi <seiji.aguchi@hds.com>
6 */
7 #include <asm/hw_irq.h>
8 #include <asm/desc.h>
9 #include <linux/atomic.h>
11 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
12 __aligned(PAGE_SIZE)
13 struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
14 (unsigned long) trace_idt_table };
16 /* No need to be aligned, but done to keep all IDTs defined the same way. */
17 __aligned(PAGE_SIZE)
18 gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
20 static int trace_irq_vector_refcount;
21 static DEFINE_MUTEX(irq_vector_mutex);
23 static void set_trace_idt_ctr(int val)
25 atomic_set(&trace_idt_ctr, val);
26 /* Ensure the trace_idt_ctr is set before sending IPI */
27 wmb();
30 static void switch_idt(void *arg)
32 unsigned long flags;
34 local_irq_save(flags);
35 load_current_idt();
36 local_irq_restore(flags);
39 void trace_irq_vector_regfunc(void)
41 mutex_lock(&irq_vector_mutex);
42 if (!trace_irq_vector_refcount) {
43 set_trace_idt_ctr(1);
44 smp_call_function(switch_idt, NULL, 0);
45 switch_idt(NULL);
47 trace_irq_vector_refcount++;
48 mutex_unlock(&irq_vector_mutex);
51 void trace_irq_vector_unregfunc(void)
53 mutex_lock(&irq_vector_mutex);
54 trace_irq_vector_refcount--;
55 if (!trace_irq_vector_refcount) {
56 set_trace_idt_ctr(0);
57 smp_call_function(switch_idt, NULL, 0);
58 switch_idt(NULL);
60 mutex_unlock(&irq_vector_mutex);