[PATCH skeleton 1/3] Don't make pointless sensor update method calls

OpenBMC Patches openbmc-patches at stwcx.xyz
Mon Jun 6 14:10:57 AEST 2016


From: Brad Bishop <bradleyb at fuzziesquirrel.com>

Cut down on dbus traffic by keeping a little cache of hwmon sensor
attributes.  Only call the sensor manager if the value has actually
changed.

Signed-off-by: Brad Bishop <bradleyb at fuzziesquirrel.com>
---
 bin/hwmon.py | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/bin/hwmon.py b/bin/hwmon.py
index 08c6f06..1209d46 100755
--- a/bin/hwmon.py
+++ b/bin/hwmon.py
@@ -44,6 +44,7 @@ class Hwmons():
 		self.hwmon_root = { }
 		self.scanDirectory()
 		gobject.timeout_add(DIR_POLL_INTERVAL, self.scanDirectory)   
+		self.cache = {}
 
 	def readAttribute(self,filename):
 		val = ""
@@ -56,17 +57,29 @@ class Hwmons():
 		with open(filename, 'w') as f:
 			f.write(str(value)+'\n')
 
+	def should_update(attribute, value):
+		if attribute not in self.cache:
+			self.cache[attribute] = value
+			return True
+
+		update = (value != self.cache[attribute])
+		self.cache[attribute] = value
+
+		return update
 
 	def poll(self,objpath,attribute):
 		try:
 			raw_value = int(self.readAttribute(attribute))
-			obj = bus.get_object(SENSOR_BUS,objpath,introspect=False)
-			intf = dbus.Interface(obj,HwmonSensor.IFACE_NAME)
-			rtn = intf.setByPoll(raw_value)
-			if (rtn[0] == True):
-				self.writeAttribute(attribute,rtn[1])
+			if self.should_update(attribute, raw_value):
+				obj = bus.get_object(SENSOR_BUS,objpath,introspect=False)
+				intf = dbus.Interface(obj,HwmonSensor.IFACE_NAME)
+				rtn = intf.setByPoll(raw_value)
+				if (rtn[0] == True):
+					self.writeAttribute(attribute,rtn[1])
 		except:
 			print "HWMON: Attibute no longer exists: "+attribute
+			if attribute in self.cache:
+				del self.cache[attribute]
 			return False
 
 
-- 
2.8.3




More information about the openbmc mailing list