1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef __PERF_COUNTER_H__
17 #define __PERF_COUNTER_H__
18 #include <cstdlib>
19 #include <unistd.h>
20 
21 constexpr int RECORD_NUM = 1024 * 32 * 16;
22 constexpr int NAME_LEN = 32;
23 
24 constexpr int TASK_NUM = 1;
25 
26 constexpr int MAX_COUNTERS = 7;
27 
28 struct Counters {
29     unsigned long nr;
30     unsigned long vals[MAX_COUNTERS];
31 };
32 
33 struct PerfRecord {
34     char name[NAME_LEN];
35     short beginFlag;
36     short endFlag;
37     struct Counters countersBegin;
38     struct Counters countersEnd;
39 };
40 
41 struct PerfTask {
42     unsigned long rd;
43 
44     struct PerfRecord perfRecord[RECORD_NUM];
45 };
46 
47 struct PerfStat {
48     int perfFD;
49     int nCounters;
50     pid_t pid;
51     int rsvd;
52     struct PerfTask perfTask[TASK_NUM];
53 };
54 
55 #define CPU_CYCLES 0x11
56 #define INST_RETIRED 0x08
57 #define INST_SPEC 0x1b
58 #define BR_RETIRED 0x21
59 #define BR_MIS_PRED_RETIRED 0x22
60 #define STALL_FRONTEND 0x23
61 #define STALL_BACKEND 0x24
62 
63 #endif