1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <inttypes.h>
18 
19 #define BPF_FS_PATH "/sys/fs/bpf/"
20 
21 // Number of frequencies for which a UID's times can be tracked in a single map entry. If some CPUs
22 // have more than 32 freqs available, a single UID is tracked using 2 or more entries.
23 #define FREQS_PER_ENTRY 32
24 // Number of distinct CPU counts for which a UID's concurrent time stats can be tracked in a single
25 // map entry. On systems with more than 8 CPUs, a single UID is tracked using 2 or more entries.
26 #define CPUS_PER_ENTRY 8
27 
28 typedef struct {
29     uint32_t uid;
30     uint32_t bucket;
31 } time_key_t;
32 
33 typedef struct {
34     uint64_t ar[FREQS_PER_ENTRY];
35 } tis_val_t;
36 
37 typedef struct {
38     uint64_t active[CPUS_PER_ENTRY];
39     uint64_t policy[CPUS_PER_ENTRY];
40 } concurrent_val_t;
41 
42 typedef struct {
43     uint32_t policy;
44     uint32_t freq;
45 } freq_idx_key_t;
46