~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/include/linux/context_tracking.h

Version: ~ [ linux-5.8 ] ~ [ linux-5.7.12 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.55 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.136 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.191 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.232 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.232 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.85 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #ifndef _LINUX_CONTEXT_TRACKING_H
  2 #define _LINUX_CONTEXT_TRACKING_H
  3 
  4 #include <linux/sched.h>
  5 #include <linux/vtime.h>
  6 #include <linux/context_tracking_state.h>
  7 #include <asm/ptrace.h>
  8 
  9 
 10 #ifdef CONFIG_CONTEXT_TRACKING
 11 extern void context_tracking_cpu_set(int cpu);
 12 
 13 /* Called with interrupts disabled.  */
 14 extern void __context_tracking_enter(enum ctx_state state);
 15 extern void __context_tracking_exit(enum ctx_state state);
 16 
 17 extern void context_tracking_enter(enum ctx_state state);
 18 extern void context_tracking_exit(enum ctx_state state);
 19 extern void context_tracking_user_enter(void);
 20 extern void context_tracking_user_exit(void);
 21 
 22 static inline void user_enter(void)
 23 {
 24         if (context_tracking_is_enabled())
 25                 context_tracking_enter(CONTEXT_USER);
 26 
 27 }
 28 static inline void user_exit(void)
 29 {
 30         if (context_tracking_is_enabled())
 31                 context_tracking_exit(CONTEXT_USER);
 32 }
 33 
 34 static inline enum ctx_state exception_enter(void)
 35 {
 36         enum ctx_state prev_ctx;
 37 
 38         if (!context_tracking_is_enabled())
 39                 return 0;
 40 
 41         prev_ctx = this_cpu_read(context_tracking.state);
 42         if (prev_ctx != CONTEXT_KERNEL)
 43                 context_tracking_exit(prev_ctx);
 44 
 45         return prev_ctx;
 46 }
 47 
 48 static inline void exception_exit(enum ctx_state prev_ctx)
 49 {
 50         if (context_tracking_is_enabled()) {
 51                 if (prev_ctx != CONTEXT_KERNEL)
 52                         context_tracking_enter(prev_ctx);
 53         }
 54 }
 55 
 56 
 57 /**
 58  * ct_state() - return the current context tracking state if known
 59  *
 60  * Returns the current cpu's context tracking state if context tracking
 61  * is enabled.  If context tracking is disabled, returns
 62  * CONTEXT_DISABLED.  This should be used primarily for debugging.
 63  */
 64 static inline enum ctx_state ct_state(void)
 65 {
 66         return context_tracking_is_enabled() ?
 67                 this_cpu_read(context_tracking.state) : CONTEXT_DISABLED;
 68 }
 69 #else
 70 static inline void user_enter(void) { }
 71 static inline void user_exit(void) { }
 72 static inline enum ctx_state exception_enter(void) { return 0; }
 73 static inline void exception_exit(enum ctx_state prev_ctx) { }
 74 static inline enum ctx_state ct_state(void) { return CONTEXT_DISABLED; }
 75 #endif /* !CONFIG_CONTEXT_TRACKING */
 76 
 77 #define CT_WARN_ON(cond) WARN_ON(context_tracking_is_enabled() && (cond))
 78 
 79 #ifdef CONFIG_CONTEXT_TRACKING_FORCE
 80 extern void context_tracking_init(void);
 81 #else
 82 static inline void context_tracking_init(void) { }
 83 #endif /* CONFIG_CONTEXT_TRACKING_FORCE */
 84 
 85 
 86 #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
 87 static inline void guest_enter(void)
 88 {
 89         if (vtime_accounting_cpu_enabled())
 90                 vtime_guest_enter(current);
 91         else
 92                 current->flags |= PF_VCPU;
 93 
 94         if (context_tracking_is_enabled())
 95                 __context_tracking_enter(CONTEXT_GUEST);
 96 }
 97 
 98 static inline void guest_exit(void)
 99 {
100         if (context_tracking_is_enabled())
101                 __context_tracking_exit(CONTEXT_GUEST);
102 
103         if (vtime_accounting_cpu_enabled())
104                 vtime_guest_exit(current);
105         else
106                 current->flags &= ~PF_VCPU;
107 }
108 
109 #else
110 static inline void guest_enter(void)
111 {
112         /*
113          * This is running in ioctl context so its safe
114          * to assume that it's the stime pending cputime
115          * to flush.
116          */
117         vtime_account_system(current);
118         current->flags |= PF_VCPU;
119 }
120 
121 static inline void guest_exit(void)
122 {
123         /* Flush the guest cputime we spent on the guest */
124         vtime_account_system(current);
125         current->flags &= ~PF_VCPU;
126 }
127 #endif /* CONFIG_VIRT_CPU_ACCOUNTING_GEN */
128 
129 #endif
130 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp