tracepoint.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Code for supporting irq vector tracepoints.
  3. *
  4. * Copyright (C) 2013 Seiji Aguchi <seiji.aguchi@hds.com>
  5. *
  6. */
  7. #include <asm/hw_irq.h>
  8. #include <asm/desc.h>
  9. #include <linux/atomic.h>
  10. atomic_t trace_idt_ctr = ATOMIC_INIT(0);
  11. __aligned(PAGE_SIZE)
  12. struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
  13. (unsigned long) trace_idt_table };
  14. /* No need to be aligned, but done to keep all IDTs defined the same way. */
  15. __aligned(PAGE_SIZE)
  16. gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
  17. static int trace_irq_vector_refcount;
  18. static DEFINE_MUTEX(irq_vector_mutex);
  19. static void set_trace_idt_ctr(int val)
  20. {
  21. atomic_set(&trace_idt_ctr, val);
  22. /* Ensure the trace_idt_ctr is set before sending IPI */
  23. wmb();
  24. }
  25. static void switch_idt(void *arg)
  26. {
  27. unsigned long flags;
  28. local_irq_save(flags);
  29. load_current_idt();
  30. local_irq_restore(flags);
  31. }
  32. void trace_irq_vector_regfunc(void)
  33. {
  34. mutex_lock(&irq_vector_mutex);
  35. if (!trace_irq_vector_refcount) {
  36. set_trace_idt_ctr(1);
  37. smp_call_function(switch_idt, NULL, 0);
  38. switch_idt(NULL);
  39. }
  40. trace_irq_vector_refcount++;
  41. mutex_unlock(&irq_vector_mutex);
  42. }
  43. void trace_irq_vector_unregfunc(void)
  44. {
  45. mutex_lock(&irq_vector_mutex);
  46. trace_irq_vector_refcount--;
  47. if (!trace_irq_vector_refcount) {
  48. set_trace_idt_ctr(0);
  49. smp_call_function(switch_idt, NULL, 0);
  50. switch_idt(NULL);
  51. }
  52. mutex_unlock(&irq_vector_mutex);
  53. }