power_utils: Add PSR status tracking for ARM

This adds tracking of PSR residency for ARM systems that support the
functionality.

BUG=b:35578918
TEST=power_LoadTest on kevin and samus
check that percent_psr_residency in the results/keyval file is
non-zero

Change-Id: I0a2fb03e3d7b5c02a9358fc22d698dde01e37c8b
Signed-off-by: Derek Basehore <dbasehore@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/455263
Commit-Ready: Sonny Rao <sonnyrao@chromium.org>
Reviewed-by: Todd Broch <tbroch@chromium.org>
diff --git a/client/cros/power_utils.py b/client/cros/power_utils.py
index 58580c2..8926669 100644
--- a/client/cros/power_utils.py
+++ b/client/cros/power_utils.py
@@ -768,11 +768,9 @@
 
 
 class DisplayPanelSelfRefresh(object):
-    """Class for control and monitoring of display's PSR.
-
-    TODO(tbroch) support devices that don't use i915 drivers but have PSR
-    """
-    psr_status_file = '/sys/kernel/debug/dri/0/i915_edp_psr_status'
+    """Class for control and monitoring of display's PSR."""
+    _PSR_STATUS_FILE_X86 = '/sys/kernel/debug/dri/0/i915_edp_psr_status'
+    _PSR_STATUS_FILE_ARM = '/sys/kernel/debug/dri/*/psr_active_ms'
 
     def __init__(self, init_time=time.time()):
         """Initializer.
@@ -785,6 +783,16 @@
             _init_counter: integer of initial value of residency counter.
             _keyvals: dictionary of keyvals
         """
+        if os.path.exists(self._PSR_STATUS_FILE_X86):
+            self._psr_path = self._PSR_STATUS_FILE_X86
+            self._psr_parse_prefix = 'Performance_Counter:'
+        else:
+            paths = glob.glob(self._PSR_STATUS_FILE_ARM)
+            if paths:
+                # Should be only one PSR file
+                self._psr_path = paths[0]
+                self._psr_parse_prefix = ''
+
         self._init_time = init_time
         self._init_counter = self._get_counter()
         self._keyvals = {}
@@ -799,8 +807,8 @@
         the performance counter can't be read.
         """
         try:
-            count = utils.get_field(utils.read_file(self.psr_status_file), 0,
-                                    linestart='Performance_Counter:')
+            count = utils.get_field(utils.read_file(self._psr_path),
+                                    0, linestart=self._psr_parse_prefix)
         except IOError:
             logging.info("Can't find or read PSR status file")
             return None