]> git.proxmox.com Git - rustc.git/blob - src/compiler-rt/lib/esan/esan_sideline.h
New upstream version 1.19.0+dfsg3
[rustc.git] / src / compiler-rt / lib / esan / esan_sideline.h
1 //===-- esan_sideline.h -----------------------------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file is a part of EfficiencySanitizer, a family of performance tuners.
11 //
12 // Esan sideline thread support.
13 //===----------------------------------------------------------------------===//
14
15 #ifndef ESAN_SIDELINE_H
16 #define ESAN_SIDELINE_H
17
18 #include "sanitizer_common/sanitizer_atomic.h"
19 #include "sanitizer_common/sanitizer_internal_defs.h"
20
21 namespace __esan {
22
23 typedef void (*SidelineFunc)(void *Arg);
24
25 // Currently only one sideline thread is supported.
26 // It calls the SidelineFunc passed to launchThread once on each sample at the
27 // given frequency in real time (i.e., wall clock time).
28 class SidelineThread {
29 public:
30 // We cannot initialize any fields in the constructor as it will be called
31 // *after* launchThread for a static instance, as esan.module_ctor is called
32 // before static initializers.
33 SidelineThread() {}
34 ~SidelineThread() {}
35
36 // To simplify declaration in sanitizer code where we want to avoid
37 // heap allocations, the constructor and destructor do nothing and
38 // launchThread and joinThread do the real work.
39 // They should each be called just once.
40 bool launchThread(SidelineFunc takeSample, void *Arg, u32 FreqMilliSec);
41 bool joinThread();
42
43 // Must be called from the sideline thread itself.
44 bool adjustTimer(u32 FreqMilliSec);
45
46 private:
47 static int runSideline(void *Arg);
48 static void registerSignal(int SigNum);
49 static void handleSidelineSignal(int SigNum, void *SigInfo, void *Ctx);
50
51 char *Stack;
52 SidelineFunc sampleFunc;
53 void *FuncArg;
54 u32 Freq;
55 uptr SidelineId;
56 atomic_uintptr_t SidelineExit;
57 };
58
59 } // namespace __esan
60
61 #endif // ESAN_SIDELINE_H