wip.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/ftrace.h>
  3. #include <linux/tracepoint.h>
  4. #include <linux/kernel.h>
  5. #include <linux/module.h>
  6. #include <linux/init.h>
  7. #include <linux/rv.h>
  8. #include <rv/instrumentation.h>
  9. #include <rv/da_monitor.h>
  10. #define MODULE_NAME "wip"
  11. #include <trace/events/rv.h>
  12. #include <trace/events/sched.h>
  13. #include <trace/events/preemptirq.h>
  14. #include "wip.h"
  15. static struct rv_monitor rv_wip;
  16. DECLARE_DA_MON_PER_CPU(wip, unsigned char);
  17. static void handle_preempt_disable(void *data, unsigned long ip, unsigned long parent_ip)
  18. {
  19. da_handle_event_wip(preempt_disable_wip);
  20. }
  21. static void handle_preempt_enable(void *data, unsigned long ip, unsigned long parent_ip)
  22. {
  23. da_handle_start_event_wip(preempt_enable_wip);
  24. }
  25. static void handle_sched_waking(void *data, struct task_struct *task)
  26. {
  27. da_handle_event_wip(sched_waking_wip);
  28. }
  29. static int enable_wip(void)
  30. {
  31. int retval;
  32. retval = da_monitor_init_wip();
  33. if (retval)
  34. return retval;
  35. rv_attach_trace_probe("wip", preempt_enable, handle_preempt_enable);
  36. rv_attach_trace_probe("wip", sched_waking, handle_sched_waking);
  37. rv_attach_trace_probe("wip", preempt_disable, handle_preempt_disable);
  38. return 0;
  39. }
  40. static void disable_wip(void)
  41. {
  42. rv_wip.enabled = 0;
  43. rv_detach_trace_probe("wip", preempt_disable, handle_preempt_disable);
  44. rv_detach_trace_probe("wip", preempt_enable, handle_preempt_enable);
  45. rv_detach_trace_probe("wip", sched_waking, handle_sched_waking);
  46. da_monitor_destroy_wip();
  47. }
  48. static struct rv_monitor rv_wip = {
  49. .name = "wip",
  50. .description = "wakeup in preemptive per-cpu testing monitor.",
  51. .enable = enable_wip,
  52. .disable = disable_wip,
  53. .reset = da_monitor_reset_all_wip,
  54. .enabled = 0,
  55. };
  56. static int __init register_wip(void)
  57. {
  58. rv_register_monitor(&rv_wip);
  59. return 0;
  60. }
  61. static void __exit unregister_wip(void)
  62. {
  63. rv_unregister_monitor(&rv_wip);
  64. }
  65. module_init(register_wip);
  66. module_exit(unregister_wip);
  67. MODULE_LICENSE("GPL");
  68. MODULE_AUTHOR("Daniel Bristot de Oliveira <bristot@kernel.org>");
  69. MODULE_DESCRIPTION("wip: wakeup in preemptive - per-cpu sample monitor.");