1484543d1Sopenharmony_ci/*
2484543d1Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
3484543d1Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4484543d1Sopenharmony_ci * you may not use this file except in compliance with the License.
5484543d1Sopenharmony_ci * You may obtain a copy of the License at
6484543d1Sopenharmony_ci *
7484543d1Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8484543d1Sopenharmony_ci *
9484543d1Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10484543d1Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11484543d1Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12484543d1Sopenharmony_ci * See the License for the specific language governing permissions and
13484543d1Sopenharmony_ci * limitations under the License.
14484543d1Sopenharmony_ci */
15484543d1Sopenharmony_ci
16484543d1Sopenharmony_ci#ifndef __PERF_COUNTER_H__
17484543d1Sopenharmony_ci#define __PERF_COUNTER_H__
18484543d1Sopenharmony_ci#include <cstdlib>
19484543d1Sopenharmony_ci#include <unistd.h>
20484543d1Sopenharmony_ci
21484543d1Sopenharmony_ciconstexpr int RECORD_NUM = 1024 * 32 * 16;
22484543d1Sopenharmony_ciconstexpr int NAME_LEN = 32;
23484543d1Sopenharmony_ci
24484543d1Sopenharmony_ciconstexpr int TASK_NUM = 1;
25484543d1Sopenharmony_ci
26484543d1Sopenharmony_ciconstexpr int MAX_COUNTERS = 7;
27484543d1Sopenharmony_ci
28484543d1Sopenharmony_cistruct Counters {
29484543d1Sopenharmony_ci    unsigned long nr;
30484543d1Sopenharmony_ci    unsigned long vals[MAX_COUNTERS];
31484543d1Sopenharmony_ci};
32484543d1Sopenharmony_ci
33484543d1Sopenharmony_cistruct PerfRecord {
34484543d1Sopenharmony_ci    char name[NAME_LEN];
35484543d1Sopenharmony_ci    short beginFlag;
36484543d1Sopenharmony_ci    short endFlag;
37484543d1Sopenharmony_ci    struct Counters countersBegin;
38484543d1Sopenharmony_ci    struct Counters countersEnd;
39484543d1Sopenharmony_ci};
40484543d1Sopenharmony_ci
41484543d1Sopenharmony_cistruct PerfTask {
42484543d1Sopenharmony_ci    unsigned long rd;
43484543d1Sopenharmony_ci
44484543d1Sopenharmony_ci    struct PerfRecord perfRecord[RECORD_NUM];
45484543d1Sopenharmony_ci};
46484543d1Sopenharmony_ci
47484543d1Sopenharmony_cistruct PerfStat {
48484543d1Sopenharmony_ci    int perfFD;
49484543d1Sopenharmony_ci    int nCounters;
50484543d1Sopenharmony_ci    pid_t pid;
51484543d1Sopenharmony_ci    int rsvd;
52484543d1Sopenharmony_ci    struct PerfTask perfTask[TASK_NUM];
53484543d1Sopenharmony_ci};
54484543d1Sopenharmony_ci
55484543d1Sopenharmony_ci#define CPU_CYCLES 0x11
56484543d1Sopenharmony_ci#define INST_RETIRED 0x08
57484543d1Sopenharmony_ci#define INST_SPEC 0x1b
58484543d1Sopenharmony_ci#define BR_RETIRED 0x21
59484543d1Sopenharmony_ci#define BR_MIS_PRED_RETIRED 0x22
60484543d1Sopenharmony_ci#define STALL_FRONTEND 0x23
61484543d1Sopenharmony_ci#define STALL_BACKEND 0x24
62484543d1Sopenharmony_ci
63484543d1Sopenharmony_ci#endif