context_tracking.h 1.2 KB

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