Whamcloud - gitweb
LU-16766 obdclass: trim kernel thread names in jobids
authorThomas Bertschinger <bertschinger@lanl.gov>
Thu, 13 Jul 2023 22:32:52 +0000 (18:32 -0400)
committerAndreas Dilger <adilger@whamcloud.com>
Mon, 29 Jan 2024 08:51:20 +0000 (08:51 +0000)
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 <bertschinger@lanl.gov>
Change-Id: Icd82a99c1153de0277ea5ed3f4b1d92535809921
Reviewed-by: Patrick Farrell <pfarrell@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-on: https://review.whamcloud.com/c/ex/lustre-release/+/53801
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
lustre/obdclass/jobid.c

index ab35998..6ba4033 100644 (file)
@@ -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",