gator: Version 5.21.1
[firefly-linux-kernel-4.4.55.git] / tools / gator / daemon / PerfGroup.h
1  /**
2  * Copyright (C) ARM Limited 2013-2015. All rights reserved.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  */
8
9 #ifndef PERF_GROUP
10 #define PERF_GROUP
11
12 #include <stdint.h>
13
14 // Use a snapshot of perf_event.h as it may be more recent than what is on the target and if not newer features won't be supported anyways
15 #include "k/perf_event.h"
16
17 #include "Config.h"
18
19 class Buffer;
20 class Monitor;
21 class PerfBuffer;
22
23 enum PerfGroupFlags {
24         PERF_GROUP_MMAP          = 1 << 0,
25         PERF_GROUP_COMM          = 1 << 1,
26         PERF_GROUP_FREQ          = 1 << 2,
27         PERF_GROUP_TASK          = 1 << 3,
28         PERF_GROUP_SAMPLE_ID_ALL = 1 << 4,
29         PERF_GROUP_PER_CPU       = 1 << 5,
30         PERF_GROUP_LEADER        = 1 << 6,
31         PERF_GROUP_CPU           = 1 << 7,
32 };
33
34 enum {
35         PG_SUCCESS = 0,
36         PG_FAILURE,
37         PG_CPU_OFFLINE,
38 };
39
40 class PerfGroup {
41 public:
42         PerfGroup(PerfBuffer *const pb);
43         ~PerfGroup();
44
45         bool createCpuGroup(const uint64_t currTime, Buffer *const buffer);
46         bool add(const uint64_t currTime, Buffer *const buffer, const int key, const __u32 type, const __u64 config, const __u64 sample, const __u64 sampleType, const int flags);
47         // Safe to call concurrently
48         int prepareCPU(const int cpu, Monitor *const monitor);
49         // Not safe to call concurrently. Returns the number of events enabled
50         int onlineCPU(const uint64_t currTime, const int cpu, const bool enable, Buffer *const buffer);
51         bool offlineCPU(int cpu);
52         bool start();
53         void stop();
54
55 private:
56         int getEffectiveType(const int type, const int flags);
57         int doAdd(const uint64_t currTime, Buffer *const buffer, const int key, const __u32 type, const __u64 config, const __u64 sample, const __u64 sampleType, const int flags);
58
59         // 2* to be conservative for sched_switch, cpu_idle, hrtimer and non-CPU groups
60         struct perf_event_attr mAttrs[2*MAX_PERFORMANCE_COUNTERS];
61         PerfBuffer *const mPb;
62         int mFlags[2*MAX_PERFORMANCE_COUNTERS];
63         int mKeys[2*MAX_PERFORMANCE_COUNTERS];
64         int mFds[NR_CPUS * (2*MAX_PERFORMANCE_COUNTERS)];
65         // Offset in mAttrs, mFlags and mKeys of the group leaders for each perf type
66         int mLeaders[16];
67         int mSchedSwitchId;
68
69         // Intentionally undefined
70         PerfGroup(const PerfGroup &);
71         PerfGroup &operator=(const PerfGroup &);
72 };
73
74 #endif // PERF_GROUP