From 68aede7861c5e04497b6b299565fa5b4103240a9 Mon Sep 17 00:00:00 2001 From: Thomas Bertschinger Date: Thu, 13 Jul 2023 18:32:52 -0400 Subject: [PATCH] LU-16766 obdclass: trim kernel thread names in jobids When collecting jobstats on operations coming from kernel threads, it is more useful and reduces the noisiness of the data if the names of kernel threads are trimmed so that all "kworker/CPU:ID" threads are collected under "kworker", all "ll_sa_PID" threads under ll_sa, etc. Lustre-change: https://review.whamcloud.com/51919 Lustre-commit: 8a9c503c002d08d0587894a748761e30c1b9a445 Signed-off-by: Thomas Bertschinger Change-Id: Icd82a99c1153de0277ea5ed3f4b1d92535809921 Reviewed-by: Patrick Farrell Reviewed-by: Andreas Dilger Reviewed-on: https://review.whamcloud.com/c/ex/lustre-release/+/53801 Tested-by: jenkins Tested-by: Maloo --- lustre/obdclass/jobid.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/lustre/obdclass/jobid.c b/lustre/obdclass/jobid.c index ab35998..6ba4033 100644 --- a/lustre/obdclass/jobid.c +++ b/lustre/obdclass/jobid.c @@ -631,6 +631,31 @@ out: } /* + * jobid_print_current_comm() + * + * Print current comm name into the provided jobid buffer, and trim names of + * kernel threads like "kworker/0:0" to "kworker" or "ll_sa_12345" to "ll_sa" + * + * Return: number of chars printed to jobid + */ +static int jobid_print_current_comm(char *jobid, ssize_t joblen) +{ + const char *const names[] = {"kworker", "kswapd", "ll_sa", "ll_agl", + "ldlm_bl", NULL}; + int i; + + if (current->flags & PF_KTHREAD) { + for (i = 0; names[i] != NULL; i++) { + if (strncmp(current->comm, names[i], + strlen(names[i])) == 0) + return snprintf(jobid, joblen, "%s", names[i]); + } + } + + return snprintf(jobid, joblen, "%s", current->comm); +} + +/* * jobid_interpret_string() * * Interpret the jobfmt string to expand specified fields, like coredumps do: @@ -670,7 +695,7 @@ static int jobid_interpret_string(const char *jobfmt, char *jobid, switch ((f = *jobfmt++)) { case 'e': /* executable name */ - l = snprintf(jobid, joblen, "%s", current->comm); + l = jobid_print_current_comm(jobid, joblen); break; case 'g': /* group ID */ l = snprintf(jobid, joblen, "%u", -- 1.8.3.1