From 1bd95983b2703cb313ea301367ff3199fabd1f9d Mon Sep 17 00:00:00 2001 From: Nathan Scott Date: Fri, 6 Aug 2021 16:45:30 +1000 Subject: Add columns for process autogroup identifier and nice value Adds AGRP (autogroup) and ANI (autogroup nice) columns that report the information from /proc/PID/autogroup, as well as handlers for '{' and '}' to change the autogroup nice value. This is guarded by /proc/sys/kernel/sched_autogroup_enabled such that sampling and/or changing values wont be attempted unless the kernel feature is enabled. Fixes: #720 --- linux/LinuxProcessList.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'linux/LinuxProcessList.c') diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index e1b923d6..d3463b51 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -909,6 +909,23 @@ static void LinuxProcessList_readOomData(LinuxProcess* process, openat_arg_t pro fclose(file); } +static void LinuxProcessList_readAutogroup(LinuxProcess* process, openat_arg_t procFd) { + process->autogroup_id = -1; + + char autogroup[64]; // space for two numeric values and fixed length strings + ssize_t amtRead = xReadfileat(procFd, "autogroup", autogroup, sizeof(autogroup)); + if (amtRead < 0) + return; + + long int identity; + int nice; + int ok = sscanf(autogroup, "/autogroup-%ld nice %d", &identity, &nice); + if (ok == 2) { + process->autogroup_id = identity; + process->autogroup_nice = nice; + } +} + static void LinuxProcessList_readCtxtData(LinuxProcess* process, openat_arg_t procFd) { FILE* file = fopenat(procFd, "status", "r"); if (!file) @@ -1521,6 +1538,10 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, openat_arg_ LinuxProcessList_readCwd(lp, procFd); } + if ((settings->flags & PROCESS_FLAG_LINUX_AUTOGROUP) && this->haveAutogroup) { + LinuxProcessList_readAutogroup(lp, procFd); + } + if (proc->state == 'Z' && !proc->cmdline && statCommand[0]) { Process_updateCmdline(proc, statCommand, 0, strlen(statCommand)); } else if (Process_isThread(proc)) { @@ -2071,6 +2092,16 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { return; } + if (settings->flags & PROCESS_FLAG_LINUX_AUTOGROUP) { + // Refer to sched(7) 'autogroup feature' section + // The kernel feature can be enabled/disabled through procfs at + // any time, so check for it at the start of each sample - only + // read from per-process procfs files if it's globally enabled. + this->haveAutogroup = LinuxProcess_isAutogroupEnabled(); + } else { + this->haveAutogroup = false; + } + /* PROCDIR is an absolute path */ assert(PROCDIR[0] == '/'); #ifdef HAVE_OPENAT -- cgit v1.2.3