summaryrefslogtreecommitdiff
path: root/services/gpuservice/gpuwork/bpfprogs/include/gpuwork/gpu_work.h
blob: 57338f4c9104aed48837ed60949f180f09a4e4c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
 * Copyright 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include <stdint.h>

#ifdef __cplusplus
#include <type_traits>

namespace android {
namespace gpuwork {
#endif

typedef struct  {
    uint32_t gpu_id;
    uint32_t uid;
} GpuIdUid;

typedef struct {
    // The end time of the previous period where the GPU was active for the UID,
    // in nanoseconds.
    uint64_t previous_active_end_time_ns;

    // The total amount of time the GPU has spent running work for the UID, in
    // nanoseconds.
    uint64_t total_active_duration_ns;

    // The total amount of time of the "gaps" between "continuous" GPU work for
    // the UID, in nanoseconds. This is estimated by ignoring large gaps between
    // GPU work for this UID.
    uint64_t total_inactive_duration_ns;

    // The number of errors detected due to |GpuWorkPeriodEvent| events for the
    // UID violating the specification in some way. E.g. periods with a zero or
    // negative duration.
    uint32_t error_count;

} UidTrackingInfo;

typedef struct {
    // We cannot query the number of entries in BPF map |gpu_work_map|. We track
    // the number of entries (approximately) using a counter so we can check if
    // the map is nearly full.
    uint64_t num_map_entries;
} GlobalData;

// The maximum number of tracked GPU ID and UID pairs (|GpuIdUid|).
static const uint32_t kMaxTrackedGpuIdUids = 512;

#ifdef __cplusplus
} // namespace gpuwork
} // namespace android
#endif