uclampset: use lib/procfs.c

This commit is contained in:
Karel Zak 2021-09-07 17:39:33 +02:00
parent c704e680ed
commit 602f734ad3

View file

@ -27,7 +27,7 @@
#include "closestream.h" #include "closestream.h"
#include "path.h" #include "path.h"
#include "pathnames.h" #include "pathnames.h"
#include "procutils.h" #include "procfs.h"
#include "sched_attr.h" #include "sched_attr.h"
#include "strutils.h" #include "strutils.h"
@ -94,7 +94,7 @@ static void show_uclamp_pid_info(pid_t pid, char *cmd)
if (cmd) if (cmd)
comm = cmd; comm = cmd;
else else
comm = proc_get_command_name(pid); comm = pid_get_cmdname(pid);
printf(_("%s (%d) util_clamp: min: %d max: %d\n"), printf(_("%s (%d) util_clamp: min: %d max: %d\n"),
comm ? : "unknown", pid, sa.sched_util_min, sa.sched_util_max); comm ? : "unknown", pid, sa.sched_util_min, sa.sched_util_max);
@ -134,16 +134,17 @@ static void show_uclamp_info(struct uclampset *ctl)
if (ctl->system) { if (ctl->system) {
show_uclamp_system_info(); show_uclamp_system_info();
} else if (ctl->all_tasks) { } else if (ctl->all_tasks) {
DIR *sub = NULL;
pid_t tid; pid_t tid;
struct proc_tasks *ts = proc_open_tasks(ctl->pid); struct path_cxt *pc = ul_new_procfs_path(ctl->pid, NULL);
if (!ts) if (!pc)
err(EXIT_FAILURE, _("cannot obtain the list of tasks")); err(EXIT_FAILURE, _("cannot obtain the list of tasks"));
while (!proc_next_tid(ts, &tid)) while (procfs_process_next_tid(pc, &sub, &tid) == 0)
show_uclamp_pid_info(tid, NULL); show_uclamp_pid_info(tid, NULL);
proc_close_tasks(ts); ul_unref_path(pc);
} else { } else {
show_uclamp_pid_info(ctl->pid, ctl->cmd); show_uclamp_pid_info(ctl->pid, ctl->cmd);
} }
@ -175,17 +176,18 @@ static int set_uclamp_one(struct uclampset *ctl, pid_t pid)
static void set_uclamp_pid(struct uclampset *ctl) static void set_uclamp_pid(struct uclampset *ctl)
{ {
if (ctl->all_tasks) { if (ctl->all_tasks) {
DIR *sub = NULL;
pid_t tid; pid_t tid;
struct proc_tasks *ts = proc_open_tasks(ctl->pid); struct path_cxt *pc = ul_new_procfs_path(ctl->pid, NULL);
if (!ts) if (!pc)
err(EXIT_FAILURE, _("cannot obtain the list of tasks")); err(EXIT_FAILURE, _("cannot obtain the list of tasks"));
while (!proc_next_tid(ts, &tid)) while (procfs_process_next_tid(pc, &sub, &tid) == 0) {
if (set_uclamp_one(ctl, tid) == -1) if (set_uclamp_one(ctl, tid) == -1)
err(EXIT_FAILURE, _("failed to set tid %d's uclamp values"), tid); err(EXIT_FAILURE, _("failed to set tid %d's uclamp values"), tid);
}
proc_close_tasks(ts); ul_unref_path(pc);
} else if (set_uclamp_one(ctl, ctl->pid) == -1) { } else if (set_uclamp_one(ctl, ctl->pid) == -1) {
err(EXIT_FAILURE, _("failed to set pid %d's uclamp values"), ctl->pid); err(EXIT_FAILURE, _("failed to set pid %d's uclamp values"), ctl->pid);