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