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

Commit 7214597d authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes Icdf08b8e,Ie460d666 into main

* changes:
  Add libbpf_prog gpuWork.bpf target
  Add libbpf_prog gpuMem.bpf target
parents d8326192 638b8355
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -24,4 +24,15 @@ package {
bpf {
    name: "gpuMem.o",
    srcs: ["gpuMem.c"],
    include_dirs: [
        "system/bpf/include/defs",
    ],
}

libbpf_prog {
    name: "gpuMem.bpf",
    srcs: ["gpuMem.c"],
    header_libs: [
        "android_bpf_defs",
    ],
}
+7 −2
Original line number Diff line number Diff line
@@ -14,7 +14,11 @@
 * limitations under the License.
 */

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

#ifdef ENABLE_LIBBPF
#include <stdint.h>
#endif  // ENABLE_LIBBPF

/*
 * On Android the number of active processes using gpu is limited.
@@ -48,7 +52,8 @@ struct gpu_mem_total_args {
 * Pass AID_GRAPHICS as gid since gpuservice is in the graphics group.
 * Upon seeing size 0, the corresponding KEY needs to be cleaned up.
 */
DEFINE_BPF_PROG("tracepoint/gpu_mem/gpu_mem_total", AID_ROOT, AID_GRAPHICS, tp_gpu_mem_total)
DEFINE_BPF_PROG("tracepoint/gpu_mem/gpu_mem_total", AID_ROOT, AID_GRAPHICS,
                tracepoint_gpu_mem_gpu_mem_total)
(struct gpu_mem_total_args* args) {
    uint64_t key = 0;
    uint64_t cur_val = 0;
+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.
Loading