Blame SOURCES/0071-rasdaemon-ras-mc-ctl-add-option-to-show-error-counts.patch

431d88
From 60a91e4da4f2daf2b10143fc148a8043312b61e5 Mon Sep 17 00:00:00 2001
431d88
From: Aristeu Rozanski <aris@redhat.com>
431d88
Date: Wed, 1 Aug 2018 16:29:58 -0400
431d88
Subject: [PATCH] rasdaemon: ras-mc-ctl: add option to show error counts
431d88
431d88
In some scenarios it might not be desirable to have a daemon running
431d88
to parse and store the errors provided by EDAC and only having the
431d88
number of CEs and UEs is enough. This patch implements this feature
431d88
as an ras-mc-ctl option.
431d88
431d88
Signed-off-by: Aristeu Rozanski <arozansk@redhat.com>
431d88
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
431d88
---
431d88
 util/ras-mc-ctl.in | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
431d88
 1 file changed, 73 insertions(+), 2 deletions(-)
431d88
431d88
diff --git a/util/ras-mc-ctl.in b/util/ras-mc-ctl.in
431d88
index 38b7824..aee431a 100755
431d88
--- a/util/ras-mc-ctl.in
431d88
+++ b/util/ras-mc-ctl.in
431d88
@@ -50,6 +50,8 @@ my %dimm_location = ();
431d88
 my %csrow_size  = ();
431d88
 my %rank_size   = ();
431d88
 my %csrow_ranks = ();
431d88
+my %dimm_ce_count = ();
431d88
+my %dimm_ue_count = ();
431d88
 
431d88
 my @layers;
431d88
 my @max_pos;
431d88
@@ -76,6 +78,7 @@ Usage: $prog [OPTIONS...]
431d88
  --layout           Display the memory layout.
431d88
  --summary          Presents a summary of the logged errors.
431d88
  --errors           Shows the errors stored at the error database.
431d88
+ --error-count      Shows the corrected and uncorrected error counts using sysfs.
431d88
  --help             This help message.
431d88
 EOF
431d88
 
431d88
@@ -83,7 +86,7 @@ parse_cmdline();
431d88
 
431d88
 if (  $conf{opt}{mainboard} || $conf{opt}{print_labels}
431d88
    || $conf{opt}{register_labels} || $conf{opt}{display_memory_layout}
431d88
-   || $conf{opt}{guess_dimm_label}) {
431d88
+   || $conf{opt}{guess_dimm_label} || $conf{opt}{error_count}) {
431d88
 
431d88
     get_mainboard_info();
431d88
 
431d88
@@ -105,6 +108,9 @@ if (  $conf{opt}{mainboard} || $conf{opt}{print_labels}
431d88
     if ($conf{opt}{guess_dimm_label}) {
431d88
         guess_dimm_label ();
431d88
     }
431d88
+    if ($conf{opt}{error_count}) {
431d88
+        display_error_count ();
431d88
+    }
431d88
 }
431d88
 
431d88
 if ($conf{opt}{status}) {
431d88
@@ -134,6 +140,7 @@ sub parse_cmdline
431d88
     $conf{opt}{guess_dimm_label} = 0;
431d88
     $conf{opt}{summary} = 0;
431d88
     $conf{opt}{errors} = 0;
431d88
+    $conf{opt}{error_count} = 0;
431d88
 
431d88
     my $rref = \$conf{opt}{report};
431d88
     my $mref = \$conf{opt}{mainboard};
431d88
@@ -150,7 +157,8 @@ sub parse_cmdline
431d88
                          "status" =>          \$conf{opt}{status},
431d88
                          "layout" =>          \$conf{opt}{display_memory_layout},
431d88
                          "summary" =>         \$conf{opt}{summary},
431d88
-                         "errors" =>          \$conf{opt}{errors}
431d88
+                         "errors" =>          \$conf{opt}{errors},
431d88
+                         "error-count" =>     \$conf{opt}{error_count}
431d88
             );
431d88
 
431d88
     usage(1) if !$rc;
431d88
@@ -284,6 +292,30 @@ sub parse_dimm_nodes
431d88
         $dimm_label_file{$str_loc} = $file;
431d88
         $dimm_location{$str_loc} = $location;
431d88
 
431d88
+        my $count;
431d88
+
431d88
+        $file =~s/dimm_label/dimm_ce_count/;
431d88
+        if (-e $file) {
431d88
+                open IN, $file;
431d88
+                chomp($count = <IN>);
431d88
+                close IN;
431d88
+        } else {
431d88
+                log_error ("dimm_ce_count not found in sysfs. Old kernel?\n");
431d88
+                exit -1;
431d88
+        }
431d88
+        $dimm_ce_count{$str_loc} = $count;
431d88
+
431d88
+        $file =~s/dimm_ce_count/dimm_ue_count/;
431d88
+        if (-e $file) {
431d88
+                open IN, $file;
431d88
+                chomp($count = <IN>);
431d88
+                close IN;
431d88
+        } else {
431d88
+                log_error ("dimm_ue_count not found in sysfs. Old kernel?\n");
431d88
+                exit -1;
431d88
+        }
431d88
+        $dimm_ue_count{$str_loc} = $count;
431d88
+
431d88
         return;
431d88
     }
431d88
 }
431d88
@@ -906,6 +938,45 @@ sub display_memory_layout
431d88
     dimm_display_mem();
431d88
 }
431d88
 
431d88
+sub display_error_count
431d88
+{
431d88
+    my $sysfs_dir = "/sys/devices/system/edac/mc";
431d88
+    my $key;
431d88
+    my $max_width = 0;
431d88
+    my %dimm_labels = ();
431d88
+
431d88
+    find ({wanted => \&parse_dimm_nodes, no_chdir => 1}, $sysfs_dir);
431d88
+
431d88
+    if (!scalar(keys %dimm_node)) {
431d88
+        log_error ("No DIMMs found in /sys or new sysfs EDAC interface not found.\n");
431d88
+        exit -1;
431d88
+    }
431d88
+
431d88
+    foreach $key (keys %dimm_node) {
431d88
+        my $label_width;
431d88
+
431d88
+        open IN, $dimm_label_file{$key};
431d88
+        chomp(my $label = <IN>);
431d88
+        close IN;
431d88
+        $label_width = length $label;
431d88
+
431d88
+        if ($label_width > $max_width) {
431d88
+            $max_width = $label_width;
431d88
+        }
431d88
+        $dimm_labels{$key} = $label;
431d88
+    }
431d88
+    my $string = "Label";
431d88
+    $string .= " " x ($max_width - length $string);
431d88
+    print($string . "\tCE\tUE\n");
431d88
+
431d88
+    foreach $key (keys %dimm_node) {
431d88
+        my $ce_count = $dimm_ce_count{$key};
431d88
+        my $ue_count = $dimm_ue_count{$key};
431d88
+
431d88
+        print("$dimm_labels{$key}\t$ce_count\t$ue_count\n");
431d88
+    }
431d88
+}
431d88
+
431d88
 sub find_prog
431d88
 {
431d88
     my ($file) = @_;
431d88
-- 
431d88
1.8.3.1
431d88