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

Commit 1c007996 authored by T.J. Mercier's avatar T.J. Mercier
Browse files

libprocessgroup: Use pid_t consistently for TIDs

Test: m
Change-Id: I6e95870e6c5855bfe03be3be8f7a8884147bc15d
parent d6fb2259
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -104,7 +104,7 @@ std::string CgroupController::GetProcsFilePath(const std::string& rel_path, uid_
    return proc_path.append(CGROUP_PROCS_FILE);
}

bool CgroupController::GetTaskGroup(int tid, std::string* group) const {
bool CgroupController::GetTaskGroup(pid_t tid, std::string* group) const {
    std::string file_name = StringPrintf("/proc/%d/cgroup", tid);
    std::string content;
    if (!android::base::ReadFileToString(file_name, &content)) {
+2 −1
Original line number Diff line number Diff line
@@ -43,7 +43,8 @@ class CgroupController {

    std::string GetTasksFilePath(const std::string& path) const;
    std::string GetProcsFilePath(const std::string& path, uid_t uid, pid_t pid) const;
    bool GetTaskGroup(int tid, std::string* group) const;
    bool GetTaskGroup(pid_t tid, std::string* group) const;

  private:
    enum ControllerState {
        UNKNOWN = 0,
+6 −5
Original line number Diff line number Diff line
@@ -33,19 +33,20 @@ bool CgroupsAvailable();
bool CgroupGetControllerPath(const std::string& cgroup_name, std::string* path);
bool CgroupGetControllerFromPath(const std::string& path, std::string* cgroup_name);
bool CgroupGetAttributePath(const std::string& attr_name, std::string* path);
bool CgroupGetAttributePathForTask(const std::string& attr_name, int tid, std::string* path);
bool CgroupGetAttributePathForTask(const std::string& attr_name, pid_t tid, std::string* path);

bool SetTaskProfiles(int tid, const std::vector<std::string>& profiles, bool use_fd_cache = false);
bool SetTaskProfiles(pid_t tid, const std::vector<std::string>& profiles,
                     bool use_fd_cache = false);
bool SetProcessProfiles(uid_t uid, pid_t pid, const std::vector<std::string>& profiles);
bool SetUserProfiles(uid_t uid, const std::vector<std::string>& profiles);

__END_DECLS

bool SetTaskProfiles(int tid, std::initializer_list<std::string_view> profiles,
bool SetTaskProfiles(pid_t tid, std::initializer_list<std::string_view> profiles,
                     bool use_fd_cache = false);
bool SetProcessProfiles(uid_t uid, pid_t pid, std::initializer_list<std::string_view> profiles);
#if _LIBCPP_STD_VER > 17
bool SetTaskProfiles(int tid, std::span<const std::string_view> profiles,
bool SetTaskProfiles(pid_t tid, std::span<const std::string_view> profiles,
                     bool use_fd_cache = false);
bool SetProcessProfiles(uid_t uid, pid_t pid, std::span<const std::string_view> profiles);
#endif
@@ -91,7 +92,7 @@ void removeAllEmptyProcessGroups(void);

// Provides the path for an attribute in a specific process group
// Returns false in case of error, true in case of success
bool getAttributePathForTask(const std::string& attr_name, int tid, std::string* path);
bool getAttributePathForTask(const std::string& attr_name, pid_t tid, std::string* path);

// Check if a profile can be applied without failing.
// Returns true if it can be applied without failing, false otherwise
+7 −6
Original line number Diff line number Diff line
@@ -147,7 +147,7 @@ bool CgroupGetAttributePath(const std::string& attr_name, std::string* path) {
    return true;
}

bool CgroupGetAttributePathForTask(const std::string& attr_name, int tid, std::string* path) {
bool CgroupGetAttributePathForTask(const std::string& attr_name, pid_t tid, std::string* path) {
    const TaskProfiles& tp = TaskProfiles::GetInstance();
    const IProfileAttribute* attr = tp.GetAttribute(attr_name);

@@ -198,17 +198,18 @@ bool SetProcessProfilesCached(uid_t uid, pid_t pid, const std::vector<std::strin
            uid, pid, std::span<const std::string>(profiles), true);
}

bool SetTaskProfiles(int tid, const std::vector<std::string>& profiles, bool use_fd_cache) {
bool SetTaskProfiles(pid_t tid, const std::vector<std::string>& profiles, bool use_fd_cache) {
    return TaskProfiles::GetInstance().SetTaskProfiles(tid, std::span<const std::string>(profiles),
                                                       use_fd_cache);
}

bool SetTaskProfiles(int tid, std::initializer_list<std::string_view> profiles, bool use_fd_cache) {
bool SetTaskProfiles(pid_t tid, std::initializer_list<std::string_view> profiles,
                     bool use_fd_cache) {
    return TaskProfiles::GetInstance().SetTaskProfiles(
            tid, std::span<const std::string_view>(profiles), use_fd_cache);
}

bool SetTaskProfiles(int tid, std::span<const std::string_view> profiles, bool use_fd_cache) {
bool SetTaskProfiles(pid_t tid, std::span<const std::string_view> profiles, bool use_fd_cache) {
    return TaskProfiles::GetInstance().SetTaskProfiles(tid, profiles, use_fd_cache);
}

@@ -712,7 +713,7 @@ int createProcessGroup(uid_t uid, pid_t initialPid, bool memControl) {
    return createProcessGroupInternal(uid, initialPid, cgroup, true);
}

static bool SetProcessGroupValue(int tid, const std::string& attr_name, int64_t value) {
static bool SetProcessGroupValue(pid_t tid, const std::string& attr_name, int64_t value) {
    if (!isMemoryCgroupSupported()) {
        LOG(ERROR) << "Memcg is not mounted.";
        return false;
@@ -743,7 +744,7 @@ bool setProcessGroupLimit(uid_t, pid_t pid, int64_t limit_in_bytes) {
    return SetProcessGroupValue(pid, "MemLimit", limit_in_bytes);
}

bool getAttributePathForTask(const std::string& attr_name, int tid, std::string* path) {
bool getAttributePathForTask(const std::string& attr_name, pid_t tid, std::string* path) {
    return CgroupGetAttributePathForTask(attr_name, tid, path);
}

+4 −4
Original line number Diff line number Diff line
@@ -38,7 +38,7 @@ static inline SchedPolicy _policy(SchedPolicy p) {

#if defined(__ANDROID__)

int set_cpuset_policy(int tid, SchedPolicy policy) {
int set_cpuset_policy(pid_t tid, SchedPolicy policy) {
    if (tid == 0) {
        tid = GetThreadId();
    }
@@ -64,7 +64,7 @@ int set_cpuset_policy(int tid, SchedPolicy policy) {
    return 0;
}

int set_sched_policy(int tid, SchedPolicy policy) {
int set_sched_policy(pid_t tid, SchedPolicy policy) {
    if (tid == 0) {
        tid = GetThreadId();
    }
@@ -154,7 +154,7 @@ bool schedboost_enabled() {
    return enabled;
}

static int getCGroupSubsys(int tid, const char* subsys, std::string& subgroup) {
static int getCGroupSubsys(pid_t tid, const char* subsys, std::string& subgroup) {
    auto controller = CgroupMap::GetInstance().FindController(subsys);

    if (!controller.IsUsable()) return -1;
@@ -185,7 +185,7 @@ static int get_sched_policy_from_group(const std::string& group, SchedPolicy* po
    return 0;
}

int get_sched_policy(int tid, SchedPolicy* policy) {
int get_sched_policy(pid_t tid, SchedPolicy* policy) {
    if (tid == 0) {
        tid = GetThreadId();
    }
Loading