]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
gpu_sysman: make freq & mem handling more consistent
authorEero Tamminen <eero.t.tamminen@intel.com>
Tue, 8 Nov 2022 17:06:54 +0000 (19:06 +0200)
committerMatthias Runge <mrunge@matthias-runge.de>
Wed, 1 Feb 2023 06:55:27 +0000 (07:55 +0100)
Readability/consistency improvement: change frequency and memory
metric handling to use new "reported" boolean instead of cache index,
for checking when metrics need to be submitted.  This is more
consistent how other metric functions handle that.

Signed-off-by: Eero Tamminen <eero.t.tamminen@intel.com>
src/gpu_sysman.c

index dcc86bca575014365bd9a6bd968ff7a08683e146..7c37cbb0c637edb3ad8c9a7aba287798629b21c7 100644 (file)
@@ -1023,7 +1023,7 @@ static bool gpu_mems(gpu_device_t *gpu, unsigned int cache_idx) {
   };
   metric_t metric = {0};
 
-  bool reported_ratio = false, ok = false;
+  bool reported_ratio = false, reported = false, ok = false;
   for (i = 0; i < mem_count; i++) {
     /* fetch memory samples */
     if (ret = zesMemoryGetState(mems[i], &(gpu->memory[cache_idx][i])),
@@ -1084,6 +1084,7 @@ static bool gpu_mems(gpu_device_t *gpu, unsigned int cache_idx) {
         metric_family_metric_append(&fam_ratio, metric);
         reported_ratio = true;
       }
+      reported = true;
     } else {
       /* find min & max values for memory free from
        * (the configured number of) samples
@@ -1119,9 +1120,10 @@ static bool gpu_mems(gpu_device_t *gpu, unsigned int cache_idx) {
         metric_family_metric_append(&fam_ratio, metric);
         reported_ratio = true;
       }
+      reported = true;
     }
   }
-  if (ok && cache_idx == 0) {
+  if (reported) {
     metric_reset(&metric);
     gpu_submit(gpu, &fam_bytes);
     if (reported_ratio) {
@@ -1385,8 +1387,6 @@ static bool gpu_freqs(gpu_device_t *gpu, unsigned int cache_idx) {
       ok = false;
       break;
     }
-
-    bool freq_ok = false;
     double value;
 
     if (config.samples < 2) {
@@ -1404,7 +1404,7 @@ static bool gpu_freqs(gpu_device_t *gpu, unsigned int cache_idx) {
           metric_family_metric_append(&fam_ratio, metric);
           reported_ratio = true;
         }
-        freq_ok = true;
+        reported = true;
       }
       value = gpu->frequency[0][i].actual;
       if (value >= 0) {
@@ -1416,7 +1416,7 @@ static bool gpu_freqs(gpu_device_t *gpu, unsigned int cache_idx) {
           metric_family_metric_append(&fam_ratio, metric);
           reported_ratio = true;
         }
-        freq_ok = true;
+        reported = true;
       }
     } else {
       /* find min & max values for actual frequency & its request
@@ -1461,7 +1461,7 @@ static bool gpu_freqs(gpu_device_t *gpu, unsigned int cache_idx) {
           metric_family_metric_append(&fam_ratio, metric);
           reported_ratio = true;
         }
-        freq_ok = true;
+        reported = true;
       }
       if (act_max >= 0.0) {
         metric.value.gauge = act_min;
@@ -1481,12 +1481,10 @@ static bool gpu_freqs(gpu_device_t *gpu, unsigned int cache_idx) {
           metric_family_metric_append(&fam_ratio, metric);
           reported_ratio = true;
         }
-        freq_ok = true;
+        reported = true;
       }
     }
-    if (freq_ok) {
-      reported = true;
-    } else {
+    if (!reported) {
       ERROR(PLUGIN_NAME ": neither requests nor actual frequencies supported "
                         "for domain %d",
             i);