context_tracking_state.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #ifndef _LINUX_CONTEXT_TRACKING_STATE_H
  2. #define _LINUX_CONTEXT_TRACKING_STATE_H
  3. #include <linux/percpu.h>
  4. #include <linux/static_key.h>
  5. struct context_tracking {
  6. /*
  7. * When active is false, probes are unset in order
  8. * to minimize overhead: TIF flags are cleared
  9. * and calls to user_enter/exit are ignored. This
  10. * may be further optimized using static keys.
  11. */
  12. bool active;
  13. enum ctx_state {
  14. IN_KERNEL = 0,
  15. IN_USER,
  16. } state;
  17. };
  18. #ifdef CONFIG_CONTEXT_TRACKING
  19. extern struct static_key context_tracking_enabled;
  20. DECLARE_PER_CPU(struct context_tracking, context_tracking);
  21. static inline bool context_tracking_is_enabled(void)
  22. {
  23. return static_key_false(&context_tracking_enabled);
  24. }
  25. static inline bool context_tracking_cpu_is_enabled(void)
  26. {
  27. return __this_cpu_read(context_tracking.active);
  28. }
  29. static inline bool context_tracking_in_user(void)
  30. {
  31. return __this_cpu_read(context_tracking.state) == IN_USER;
  32. }
  33. #else
  34. static inline bool context_tracking_in_user(void) { return false; }
  35. static inline bool context_tracking_active(void) { return false; }
  36. #endif /* CONFIG_CONTEXT_TRACKING */
  37. #endif