tracing_user.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright (c) 2020 Lexmark International, Inc.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include <tracing_user.h>
  7. #include <kernel_internal.h>
  8. #include <ksched.h>
  9. static int nested_interrupts;
  10. void __weak sys_trace_thread_switched_in_user(struct k_thread *thread) {}
  11. void __weak sys_trace_thread_switched_out_user(struct k_thread *thread) {}
  12. void __weak sys_trace_isr_enter_user(void) {}
  13. void __weak sys_trace_isr_exit_user(void) {}
  14. void __weak sys_trace_idle_user(void) {}
  15. void sys_trace_k_thread_switched_in(void)
  16. {
  17. int key = irq_lock();
  18. __ASSERT_NO_MSG(nested_interrupts == 0);
  19. sys_trace_thread_switched_in_user(k_current_get());
  20. irq_unlock(key);
  21. }
  22. void sys_trace_k_thread_switched_out(void)
  23. {
  24. int key = irq_lock();
  25. __ASSERT_NO_MSG(nested_interrupts == 0);
  26. sys_trace_thread_switched_out_user(k_current_get());
  27. irq_unlock(key);
  28. }
  29. void sys_trace_isr_enter(void)
  30. {
  31. int key = irq_lock();
  32. if (nested_interrupts == 0) {
  33. sys_trace_isr_enter_user();
  34. }
  35. nested_interrupts++;
  36. irq_unlock(key);
  37. }
  38. void sys_trace_isr_exit(void)
  39. {
  40. int key = irq_lock();
  41. nested_interrupts--;
  42. if (nested_interrupts == 0) {
  43. sys_trace_isr_exit_user();
  44. }
  45. irq_unlock(key);
  46. }
  47. void sys_trace_idle(void)
  48. {
  49. sys_trace_idle_user();
  50. }