Connor O'Brien | 85087ae | 2019-09-03 14:53:51 -0700 | [diff] [blame] | 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> |
Dmitri Plotnikov | 7c31522 | 2020-10-17 21:29:09 -0700 | [diff] [blame] | 18 | #include <sys/types.h> |
Connor O'Brien | 85087ae | 2019-09-03 14:53:51 -0700 | [diff] [blame] | 19 | |
| 20 | #define BPF_FS_PATH "/sys/fs/bpf/" |
| 21 | |
Rafal Slawik | 2e2e54f | 2021-01-05 18:44:36 +0000 | [diff] [blame] | 22 | // Number of frequencies tracked in the array with total time. If some CPUs have |
| 23 | // more than 64 freqs |
| 24 | // // available, the overflow is stored in the last entry. |
| 25 | #define MAX_FREQS_FOR_TOTAL 64 |
Connor O'Brien | 85087ae | 2019-09-03 14:53:51 -0700 | [diff] [blame] | 26 | // Number of frequencies for which a UID's times can be tracked in a single map entry. If some CPUs |
| 27 | // have more than 32 freqs available, a single UID is tracked using 2 or more entries. |
| 28 | #define FREQS_PER_ENTRY 32 |
| 29 | // Number of distinct CPU counts for which a UID's concurrent time stats can be tracked in a single |
| 30 | // map entry. On systems with more than 8 CPUs, a single UID is tracked using 2 or more entries. |
| 31 | #define CPUS_PER_ENTRY 8 |
| 32 | |
| 33 | typedef struct { |
| 34 | uint32_t uid; |
| 35 | uint32_t bucket; |
| 36 | } time_key_t; |
| 37 | |
| 38 | typedef struct { |
| 39 | uint64_t ar[FREQS_PER_ENTRY]; |
| 40 | } tis_val_t; |
| 41 | |
| 42 | typedef struct { |
| 43 | uint64_t active[CPUS_PER_ENTRY]; |
| 44 | uint64_t policy[CPUS_PER_ENTRY]; |
| 45 | } concurrent_val_t; |
| 46 | |
| 47 | typedef struct { |
| 48 | uint32_t policy; |
| 49 | uint32_t freq; |
| 50 | } freq_idx_key_t; |
Dmitri Plotnikov | 7c31522 | 2020-10-17 21:29:09 -0700 | [diff] [blame] | 51 | |
Dmitri Plotnikov | 4f50ca4 | 2020-11-23 15:57:02 -0800 | [diff] [blame] | 52 | // Maximum number of processes whose thread CPU time-in-state can be tracked simultaneously. |
| 53 | #define MAX_TRACKED_PIDS 8 |
| 54 | |
| 55 | // Indicates that the pid_tracked_map item is unused and further items in the array are also |
| 56 | // unused |
| 57 | #define TRACKED_PID_STATE_UNUSED 0 |
| 58 | // Indicates that the pid_tracked_map item contains a PID that is currently tracked |
| 59 | #define TRACKED_PID_STATE_ACTIVE 1 |
| 60 | // Indicates that the pid_tracked_map item is vacant, but further items in the array may |
| 61 | // contain tracked PIDs |
| 62 | #define TRACKED_PID_STATE_EXITED 2 |
| 63 | |
| 64 | typedef struct { |
| 65 | pid_t pid; |
| 66 | // TRACKED_PID_STATE_UNUSED, TRACKED_PID_STATE_ACTIVE or TRACKED_PID_STATE_EXITED |
| 67 | uint8_t state; |
| 68 | } tracked_pid_t; |
| 69 | |
Dmitri Plotnikov | 7c31522 | 2020-10-17 21:29:09 -0700 | [diff] [blame] | 70 | typedef struct { |
| 71 | pid_t tgid; |
| 72 | uint16_t aggregation_key; |
| 73 | uint16_t bucket; |
| 74 | } aggregated_task_tis_key_t; |