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

TOMOYO Linux Cross Reference
Linux/tools/perf/util/trigger.h

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ 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.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* SPDX-License-Identifier: GPL-2.0 */
  2 #ifndef __TRIGGER_H_
  3 #define __TRIGGER_H_ 1
  4 
  5 #include "asm/bug.h"
  6 
  7 /*
  8  * Use trigger to model operations which need to be executed when
  9  * an event (a signal, for example) is observed.
 10  *
 11  * States and transits:
 12  *
 13  *
 14  *  OFF--> ON --> READY --(hit)--> HIT
 15  *                 ^               |
 16  *                 |            (ready)
 17  *                 |               |
 18  *                  \_____________/
 19  *
 20  * is_hit and is_ready are two key functions to query the state of
 21  * a trigger. is_hit means the event already happen; is_ready means the
 22  * trigger is waiting for the event.
 23  */
 24 
 25 struct trigger {
 26         volatile enum {
 27                 TRIGGER_ERROR           = -2,
 28                 TRIGGER_OFF             = -1,
 29                 TRIGGER_ON              = 0,
 30                 TRIGGER_READY           = 1,
 31                 TRIGGER_HIT             = 2,
 32         } state;
 33         const char *name;
 34 };
 35 
 36 #define TRIGGER_WARN_ONCE(t, exp) \
 37         WARN_ONCE(t->state != exp, "trigger '%s' state transist error: %d in %s()\n", \
 38                   t->name, t->state, __func__)
 39 
 40 static inline bool trigger_is_available(struct trigger *t)
 41 {
 42         return t->state >= 0;
 43 }
 44 
 45 static inline bool trigger_is_error(struct trigger *t)
 46 {
 47         return t->state <= TRIGGER_ERROR;
 48 }
 49 
 50 static inline void trigger_on(struct trigger *t)
 51 {
 52         TRIGGER_WARN_ONCE(t, TRIGGER_OFF);
 53         t->state = TRIGGER_ON;
 54 }
 55 
 56 static inline void trigger_ready(struct trigger *t)
 57 {
 58         if (!trigger_is_available(t))
 59                 return;
 60         t->state = TRIGGER_READY;
 61 }
 62 
 63 static inline void trigger_hit(struct trigger *t)
 64 {
 65         if (!trigger_is_available(t))
 66                 return;
 67         TRIGGER_WARN_ONCE(t, TRIGGER_READY);
 68         t->state = TRIGGER_HIT;
 69 }
 70 
 71 static inline void trigger_off(struct trigger *t)
 72 {
 73         if (!trigger_is_available(t))
 74                 return;
 75         t->state = TRIGGER_OFF;
 76 }
 77 
 78 static inline void trigger_error(struct trigger *t)
 79 {
 80         t->state = TRIGGER_ERROR;
 81 }
 82 
 83 static inline bool trigger_is_ready(struct trigger *t)
 84 {
 85         return t->state == TRIGGER_READY;
 86 }
 87 
 88 static inline bool trigger_is_hit(struct trigger *t)
 89 {
 90         return t->state == TRIGGER_HIT;
 91 }
 92 
 93 #define DEFINE_TRIGGER(n) \
 94 struct trigger n = {.state = TRIGGER_OFF, .name = #n}
 95 #endif
 96 

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

kernel.org | git.kernel.org | LWN.net | Project Home | 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.

sflogo.php