Whamcloud - gitweb
LU-16766 obdclass: trim kernel thread names in jobids 19/51919/2
authorThomas Bertschinger <bertschinger@lanl.gov>
Thu, 13 Jul 2023 22:32:52 +0000 (18:32 -0400)
committerOleg Drokin <green@whamcloud.com>
Thu, 31 Aug 2023 06:38:01 +0000 (06:38 +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.

Signed-off-by: Thomas Bertschinger <bertschinger@lanl.gov>
Change-Id: Icd82a99c1153de0277ea5ed3f4b1d92535809921
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/51919
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Patrick Farrell <pfarrell@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/obdclass/jobid.c

index e72280b..1fccfdd 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",