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

Commit 3cb0ea20 authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Snap for 6610691 from 109ad715 to rvc-release

Change-Id: If2e58aab72a51022294e8ae616df37bf8323a5ea
parents 50d20801 109ad715
Loading
Loading
Loading
Loading
+7 −17
Original line number Diff line number Diff line
@@ -88,16 +88,6 @@ static int comparePolicyFiles(const struct dirent **d1, const struct dirent **d2
    return policyN1 - policyN2;
}

static int bpf_obj_get_wronly(const char *pathname) {
    union bpf_attr attr;

    memset(&attr, 0, sizeof(attr));
    attr.pathname = ptr_to_u64((void *)pathname);
    attr.file_flags = BPF_F_WRONLY;

    return syscall(__NR_bpf, BPF_OBJ_GET, &attr, sizeof(attr));
}

static bool initGlobals() {
    std::lock_guard<std::mutex> guard(gInitializedMutex);
    if (gInitialized) return true;
@@ -156,7 +146,7 @@ static bool initGlobals() {
static bool attachTracepointProgram(const std::string &eventType, const std::string &eventName) {
    std::string path = StringPrintf(BPF_FS_PATH "prog_time_in_state_tracepoint_%s_%s",
                                    eventType.c_str(), eventName.c_str());
    int prog_fd = bpfFdGet(path.c_str(), BPF_F_RDONLY);
    int prog_fd = retrieveProgram(path.c_str());
    if (prog_fd < 0) return false;
    return bpf_attach_tracepoint(prog_fd, eventType.c_str(), eventName.c_str()) >= 0;
}
@@ -183,7 +173,7 @@ bool startTrackingUidTimes() {
    if (!initGlobals()) return false;
    if (gTracking) return true;

    unique_fd cpuPolicyFd(bpf_obj_get_wronly(BPF_FS_PATH "map_time_in_state_cpu_policy_map"));
    unique_fd cpuPolicyFd(mapRetrieveWO(BPF_FS_PATH "map_time_in_state_cpu_policy_map"));
    if (cpuPolicyFd < 0) return false;

    for (uint32_t i = 0; i < gPolicyCpus.size(); ++i) {
@@ -192,7 +182,7 @@ bool startTrackingUidTimes() {
        }
    }

    unique_fd freqToIdxFd(bpf_obj_get_wronly(BPF_FS_PATH "map_time_in_state_freq_to_idx_map"));
    unique_fd freqToIdxFd(mapRetrieveWO(BPF_FS_PATH "map_time_in_state_freq_to_idx_map"));
    if (freqToIdxFd < 0) return false;
    freq_idx_key_t key;
    for (uint32_t i = 0; i < gNPolicies; ++i) {
@@ -207,23 +197,23 @@ bool startTrackingUidTimes() {
        }
    }

    unique_fd cpuLastUpdateFd(bpf_obj_get_wronly(BPF_FS_PATH "map_time_in_state_cpu_last_update_map"));
    unique_fd cpuLastUpdateFd(mapRetrieveWO(BPF_FS_PATH "map_time_in_state_cpu_last_update_map"));
    if (cpuLastUpdateFd < 0) return false;
    std::vector<uint64_t> zeros(get_nprocs_conf(), 0);
    uint32_t zero = 0;
    if (writeToMapEntry(cpuLastUpdateFd, &zero, zeros.data(), BPF_ANY)) return false;

    unique_fd nrActiveFd(bpf_obj_get_wronly(BPF_FS_PATH "map_time_in_state_nr_active_map"));
    unique_fd nrActiveFd(mapRetrieveWO(BPF_FS_PATH "map_time_in_state_nr_active_map"));
    if (nrActiveFd < 0) return false;
    if (writeToMapEntry(nrActiveFd, &zero, &zero, BPF_ANY)) return false;

    unique_fd policyNrActiveFd(bpf_obj_get_wronly(BPF_FS_PATH "map_time_in_state_policy_nr_active_map"));
    unique_fd policyNrActiveFd(mapRetrieveWO(BPF_FS_PATH "map_time_in_state_policy_nr_active_map"));
    if (policyNrActiveFd < 0) return false;
    for (uint32_t i = 0; i < gNPolicies; ++i) {
        if (writeToMapEntry(policyNrActiveFd, &i, &zero, BPF_ANY)) return false;
    }

    unique_fd policyFreqIdxFd(bpf_obj_get_wronly(BPF_FS_PATH "map_time_in_state_policy_freq_idx_map"));
    unique_fd policyFreqIdxFd(mapRetrieveWO(BPF_FS_PATH "map_time_in_state_policy_freq_idx_map"));
    if (policyFreqIdxFd < 0) return false;
    for (uint32_t i = 0; i < gNPolicies; ++i) {
        auto freqIdx = getPolicyFreqIdx(i);
+29 −1
Original line number Diff line number Diff line
@@ -40,6 +40,13 @@
#include <string>
#include <thread>

// TODO(b/159240322): Extend this to x86 ABI.
#if defined(__LP64__)
#define UPDATABLE_DRIVER_ABI "arm64-v8a"
#else
#define UPDATABLE_DRIVER_ABI "armeabi-v7a"
#endif // defined(__LP64__)

// TODO(ianelliott@): Get the following from an ANGLE header:
#define CURRENT_ANGLE_API_VERSION 2 // Current API verion we are targetting
// Version-2 API:
@@ -583,9 +590,30 @@ android_namespace_t* GraphicsEnv::getDriverNamespace() {
        return mDriverNamespace;
    }

    if (mDriverPath.empty()) {
        // For an application process, driver path is empty means this application is not opted in
        // to use updatable driver. Application process doesn't have the ability to set up
        // environment variables and hence before `getenv` call will return.
        // For a process that is not an application process, if it's run from an environment,
        // for example shell, where environment variables can be set, then it can opt into using
        // udpatable driver by setting UPDATABLE_GFX_DRIVER to 1. By setting to 1 the developer
        // driver will be used currently.
        // TODO(b/159240322) Support the production updatable driver.
        const char* id = getenv("UPDATABLE_GFX_DRIVER");
        if (id == nullptr || std::strcmp(id, "1")) {
            return nullptr;
        }
        const sp<IGpuService> gpuService = getGpuService();
        if (!gpuService) {
            return nullptr;
        }
        mDriverPath = gpuService->getUpdatableDriverPath();
        if (mDriverPath.empty()) {
            return nullptr;
        }
        mDriverPath.append(UPDATABLE_DRIVER_ABI);
        ALOGI("Driver path is setup via UPDATABLE_GFX_DRIVER: %s", mDriverPath.c_str());
    }

    auto vndkNamespace = android_get_exported_namespace("vndk");
    if (!vndkNamespace) {
+43 −7
Original line number Diff line number Diff line
@@ -27,11 +27,11 @@ class BpGpuService : public BpInterface<IGpuService> {
public:
    explicit BpGpuService(const sp<IBinder>& impl) : BpInterface<IGpuService>(impl) {}

    virtual void setGpuStats(const std::string& driverPackageName,
                             const std::string& driverVersionName, uint64_t driverVersionCode,
                             int64_t driverBuildTime, const std::string& appPackageName,
                             const int32_t vulkanVersion, GpuStatsInfo::Driver driver,
                             bool isDriverLoaded, int64_t driverLoadingTime) {
    void setGpuStats(const std::string& driverPackageName, const std::string& driverVersionName,
                     uint64_t driverVersionCode, int64_t driverBuildTime,
                     const std::string& appPackageName, const int32_t vulkanVersion,
                     GpuStatsInfo::Driver driver, bool isDriverLoaded,
                     int64_t driverLoadingTime) override {
        Parcel data, reply;
        data.writeInterfaceToken(IGpuService::getInterfaceDescriptor());

@@ -48,8 +48,8 @@ public:
        remote()->transact(BnGpuService::SET_GPU_STATS, data, &reply, IBinder::FLAG_ONEWAY);
    }

    virtual void setTargetStats(const std::string& appPackageName, const uint64_t driverVersionCode,
                                const GpuStatsInfo::Stats stats, const uint64_t value) {
    void setTargetStats(const std::string& appPackageName, const uint64_t driverVersionCode,
                        const GpuStatsInfo::Stats stats, const uint64_t value) override {
        Parcel data, reply;
        data.writeInterfaceToken(IGpuService::getInterfaceDescriptor());

@@ -60,6 +60,27 @@ public:

        remote()->transact(BnGpuService::SET_TARGET_STATS, data, &reply, IBinder::FLAG_ONEWAY);
    }

    void setUpdatableDriverPath(const std::string& driverPath) override {
        Parcel data, reply;
        data.writeInterfaceToken(IGpuService::getInterfaceDescriptor());
        data.writeUtf8AsUtf16(driverPath);

        remote()->transact(BnGpuService::SET_UPDATABLE_DRIVER_PATH, data, &reply,
                           IBinder::FLAG_ONEWAY);
    }

    std::string getUpdatableDriverPath() override {
        Parcel data, reply;
        data.writeInterfaceToken(IGpuService::getInterfaceDescriptor());

        status_t error = remote()->transact(BnGpuService::GET_UPDATABLE_DRIVER_PATH, data, &reply);
        std::string driverPath;
        if (error == OK) {
            error = reply.readUtf8FromUtf16(&driverPath);
        }
        return driverPath;
    }
};

IMPLEMENT_META_INTERFACE(GpuService, "android.graphicsenv.IGpuService");
@@ -126,6 +147,21 @@ status_t BnGpuService::onTransact(uint32_t code, const Parcel& data, Parcel* rep

            return OK;
        }
        case SET_UPDATABLE_DRIVER_PATH: {
            CHECK_INTERFACE(IGpuService, data, reply);

            std::string driverPath;
            if ((status = data.readUtf8FromUtf16(&driverPath)) != OK) return status;

            setUpdatableDriverPath(driverPath);
            return OK;
        }
        case GET_UPDATABLE_DRIVER_PATH: {
            CHECK_INTERFACE(IGpuService, data, reply);

            std::string driverPath = getUpdatableDriverPath();
            return reply->writeUtf8AsUtf16(driverPath);
        }
        case SHELL_COMMAND_TRANSACTION: {
            int in = data.readFileDescriptor();
            int out = data.readFileDescriptor();
+6 −0
Original line number Diff line number Diff line
@@ -42,6 +42,10 @@ public:
    // set target stats.
    virtual void setTargetStats(const std::string& appPackageName, const uint64_t driverVersionCode,
                                const GpuStatsInfo::Stats stats, const uint64_t value = 0) = 0;

    // setter and getter for updatable driver path.
    virtual void setUpdatableDriverPath(const std::string& driverPath) = 0;
    virtual std::string getUpdatableDriverPath() = 0;
};

class BnGpuService : public BnInterface<IGpuService> {
@@ -49,6 +53,8 @@ public:
    enum IGpuServiceTag {
        SET_GPU_STATS = IBinder::FIRST_CALL_TRANSACTION,
        SET_TARGET_STATS,
        SET_UPDATABLE_DRIVER_PATH,
        GET_UPDATABLE_DRIVER_PATH,
        // Always append new enum to the end.
    };

+8 −0
Original line number Diff line number Diff line
@@ -62,6 +62,14 @@ void GpuService::setTargetStats(const std::string& appPackageName, const uint64_
    mGpuStats->insertTargetStats(appPackageName, driverVersionCode, stats, value);
}

void GpuService::setUpdatableDriverPath(const std::string& driverPath) {
    developerDriverPath = driverPath;
}

std::string GpuService::getUpdatableDriverPath() {
    return developerDriverPath;
}

status_t GpuService::shellCommand(int /*in*/, int out, int err, std::vector<String16>& args) {
    ATRACE_CALL();

Loading