2
0
mirror of https://github.com/edk2-porting/linux-next.git synced 2024-12-29 23:53:55 +08:00
linux-next/tools/perf/util/trigger.h
Adrian Hunter de19e5c3c5 perf tools: Fix trigger class trigger_on()
trigger_on() means that the trigger is available but not ready, however
trigger_on() was making it ready. That can segfault if the signal comes
before trigger_ready(). e.g. (USR2 signal delivery not shown)

  $ perf record -e intel_pt//u -S sleep 1
  perf: Segmentation fault
  Obtained 16 stack frames.
  /home/ahunter/bin/perf(sighandler_dump_stack+0x40) [0x4ec550]
  /lib/x86_64-linux-gnu/libc.so.6(+0x36caf) [0x7fa76411acaf]
  /home/ahunter/bin/perf(perf_evsel__disable+0x26) [0x4b9dd6]
  /home/ahunter/bin/perf() [0x43a45b]
  /lib/x86_64-linux-gnu/libc.so.6(+0x36caf) [0x7fa76411acaf]
  /lib/x86_64-linux-gnu/libc.so.6(__xstat64+0x15) [0x7fa7641d2cc5]
  /home/ahunter/bin/perf() [0x4ec6c9]
  /home/ahunter/bin/perf() [0x4ec73b]
  /home/ahunter/bin/perf() [0x4ec73b]
  /home/ahunter/bin/perf() [0x4ec73b]
  /home/ahunter/bin/perf() [0x4eca15]
  /home/ahunter/bin/perf(machine__create_kernel_maps+0x257) [0x4f0b77]
  /home/ahunter/bin/perf(perf_session__new+0xc0) [0x4f86f0]
  /home/ahunter/bin/perf(cmd_record+0x722) [0x43c132]
  /home/ahunter/bin/perf() [0x4a11ae]
  /home/ahunter/bin/perf(main+0x5d4) [0x427fb4]

Note, for testing purposes, this is hard to hit unless you add some sleep()
in builtin-record.c before record__open().

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Cc: stable@vger.kernel.org
Fixes: 3dcc4436fa ("perf tools: Introduce trigger class")
Link: http://lkml.kernel.org/r/1519807144-30694-1-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2018-03-06 11:31:14 -03:00

97 lines
2.0 KiB
C

/* SPDX-License-Identifier: GPL-2.0 */
#ifndef __TRIGGER_H_
#define __TRIGGER_H_ 1
#include "util/debug.h"
#include "asm/bug.h"
/*
* Use trigger to model operations which need to be executed when
* an event (a signal, for example) is observed.
*
* States and transits:
*
*
* OFF--> ON --> READY --(hit)--> HIT
* ^ |
* | (ready)
* | |
* \_____________/
*
* is_hit and is_ready are two key functions to query the state of
* a trigger. is_hit means the event already happen; is_ready means the
* trigger is waiting for the event.
*/
struct trigger {
volatile enum {
TRIGGER_ERROR = -2,
TRIGGER_OFF = -1,
TRIGGER_ON = 0,
TRIGGER_READY = 1,
TRIGGER_HIT = 2,
} state;
const char *name;
};
#define TRIGGER_WARN_ONCE(t, exp) \
WARN_ONCE(t->state != exp, "trigger '%s' state transist error: %d in %s()\n", \
t->name, t->state, __func__)
static inline bool trigger_is_available(struct trigger *t)
{
return t->state >= 0;
}
static inline bool trigger_is_error(struct trigger *t)
{
return t->state <= TRIGGER_ERROR;
}
static inline void trigger_on(struct trigger *t)
{
TRIGGER_WARN_ONCE(t, TRIGGER_OFF);
t->state = TRIGGER_ON;
}
static inline void trigger_ready(struct trigger *t)
{
if (!trigger_is_available(t))
return;
t->state = TRIGGER_READY;
}
static inline void trigger_hit(struct trigger *t)
{
if (!trigger_is_available(t))
return;
TRIGGER_WARN_ONCE(t, TRIGGER_READY);
t->state = TRIGGER_HIT;
}
static inline void trigger_off(struct trigger *t)
{
if (!trigger_is_available(t))
return;
t->state = TRIGGER_OFF;
}
static inline void trigger_error(struct trigger *t)
{
t->state = TRIGGER_ERROR;
}
static inline bool trigger_is_ready(struct trigger *t)
{
return t->state == TRIGGER_READY;
}
static inline bool trigger_is_hit(struct trigger *t)
{
return t->state == TRIGGER_HIT;
}
#define DEFINE_TRIGGER(n) \
struct trigger n = {.state = TRIGGER_OFF, .name = #n}
#endif