Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 638b8355 authored by Motomu Utsumi's avatar Motomu Utsumi
Browse files

Add libbpf_prog gpuWork.bpf target

kMaxTrackedGpuIdUids is used for the number of entry of bpf map which
caused "variable length array folded to constant array" error.
This CL fixes the issue by using #define instead of static const.

This is a preparation for migrating to the Rust platform bpfloader.

Flag: EXEMPT gpuWork.bpf is not used
Bug: 410982483
Test: m gpuWork.bpf
Change-Id: Icdf08b8eee39c98a0ab88e887109632d62de10e1
parent 2a6ea2ce
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -479,7 +479,7 @@ void GpuWork::clearMapIfNeeded() {
    uint64_t numEntries = globalData.value().num_map_entries;

    // If the map is <=75% full, we do nothing.
    if (numEntries <= (kMaxTrackedGpuIdUids / 4) * 3) {
    if (numEntries <= (MAX_TRACKED_GPU_ID_UIDS / 4) * 3) {
        return;
    }

@@ -511,7 +511,7 @@ void GpuWork::clearMap() {

    base::Result<GpuIdUid> key = mGpuWorkMap.getFirstKey();

    for (size_t i = 0; i < kMaxTrackedGpuIdUids; ++i) {
    for (size_t i = 0; i < MAX_TRACKED_GPU_ID_UIDS; ++i) {
        if (!key.ok()) {
            break;
        }
+11 −0
Original line number Diff line number Diff line
@@ -23,6 +23,17 @@ bpf {
        "-Wthread-safety",
        "-Wunreachable-code",
    ],
    include_dirs: [
        "system/bpf/include/defs",
    ],
}

libbpf_prog {
    name: "gpuWork.bpf",
    srcs: ["gpuWork.c"],
    header_libs: [
        "android_bpf_defs",
    ],
}

cc_library_headers {
+4 −3
Original line number Diff line number Diff line
@@ -20,13 +20,13 @@
#include <stddef.h>
#include <stdint.h>

#include <bpf_helpers.h>
#include <android_bpf_defs.h>

#define S_IN_NS (1000000000)
#define SMALL_TIME_GAP_LIMIT_NS (S_IN_NS)

// A map from GpuIdUid (GPU ID and application UID) to |UidTrackingInfo|.
DEFINE_BPF_MAP_GRW(gpu_work_map, HASH, GpuIdUid, UidTrackingInfo, kMaxTrackedGpuIdUids,
DEFINE_BPF_MAP_GRW(gpu_work_map, HASH, GpuIdUid, UidTrackingInfo, MAX_TRACKED_GPU_ID_UIDS,
                   AID_GRAPHICS);

// A map containing a single entry of |GlobalData|.
@@ -174,7 +174,8 @@ _Static_assert(offsetof(GpuWorkPeriodEvent, gpu_id) == 8 &&
               "must match the tracepoint field offsets found via adb shell cat "
               "/sys/kernel/tracing/events/power/gpu_work_period/format");

DEFINE_BPF_PROG("tracepoint/power/gpu_work_period", AID_ROOT, AID_GRAPHICS, tp_gpu_work_period)
DEFINE_BPF_PROG("tracepoint/power/gpu_work_period", AID_ROOT, AID_GRAPHICS,
                tracepoint_power_gpu_work_period)
(GpuWorkPeriodEvent* const period) {
    // Note: In eBPF programs, |__sync_fetch_and_add| is translated to an atomic
    // add.
+3 −3
Original line number Diff line number Diff line
@@ -18,6 +18,9 @@

#include <stdint.h>

// The maximum number of tracked GPU ID and UID pairs (|GpuIdUid|).
#define MAX_TRACKED_GPU_ID_UIDS 512

#ifdef __cplusplus
#include <type_traits>

@@ -60,9 +63,6 @@ typedef struct {
    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