blob: f30d3a6a9c6812d8ae14e77c4112fc625756ad44 [file] [log] [blame]
Jon Medhurst15ce78d2014-04-10 09:02:02 +01001 /**
Jon Medhurstb1d07442015-05-08 12:04:18 +01002 * Copyright (C) ARM Limited 2013-2015. All rights reserved.
Jon Medhurst15ce78d2014-04-10 09:02:02 +01003 *
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
Jon Medhurst96b56152014-10-30 18:01:15 +000012#include <stdint.h>
13
Jon Medhurst15ce78d2014-04-10 09:02:02 +010014// 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
19class Buffer;
20class Monitor;
21class PerfBuffer;
22
23enum 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,
Jon Medhurste31266f2014-08-04 15:47:44 +010029 PERF_GROUP_PER_CPU = 1 << 5,
Jon Medhurstb1d07442015-05-08 12:04:18 +010030 PERF_GROUP_LEADER = 1 << 6,
31 PERF_GROUP_CPU = 1 << 7,
Jon Medhurst15ce78d2014-04-10 09:02:02 +010032};
33
Jon Medhurst96b56152014-10-30 18:01:15 +000034enum {
35 PG_SUCCESS = 0,
36 PG_FAILURE,
37 PG_CPU_OFFLINE,
38};
39
Jon Medhurst15ce78d2014-04-10 09:02:02 +010040class PerfGroup {
41public:
42 PerfGroup(PerfBuffer *const pb);
43 ~PerfGroup();
44
Jon Medhurstb1d07442015-05-08 12:04:18 +010045 bool createCpuGroup(const uint64_t currTime, Buffer *const buffer);
Jon Medhurst96b56152014-10-30 18:01:15 +000046 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);
Jon Medhurst15ce78d2014-04-10 09:02:02 +010047 // Safe to call concurrently
Jon Medhurst96b56152014-10-30 18:01:15 +000048 int prepareCPU(const int cpu, Monitor *const monitor);
Jon Medhurst15ce78d2014-04-10 09:02:02 +010049 // Not safe to call concurrently. Returns the number of events enabled
Jon Medhurstb1d07442015-05-08 12:04:18 +010050 int onlineCPU(const uint64_t currTime, const int cpu, const bool enable, Buffer *const buffer);
Jon Medhurst15ce78d2014-04-10 09:02:02 +010051 bool offlineCPU(int cpu);
52 bool start();
53 void stop();
54
55private:
Jon Medhurstb1d07442015-05-08 12:04:18 +010056 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];
Jon Medhurst15ce78d2014-04-10 09:02:02 +010061 PerfBuffer *const mPb;
Jon Medhurstb1d07442015-05-08 12:04:18 +010062 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;
Jon Medhurst15ce78d2014-04-10 09:02:02 +010068
69 // Intentionally undefined
70 PerfGroup(const PerfGroup &);
71 PerfGroup &operator=(const PerfGroup &);
72};
73
74#endif // PERF_GROUP