<font face="Default Sans Serif,Verdana,Arial,Helvetica,sans-serif" size="2">Hi Andrew,<br><br>Thank you for the comment.<br><br>After some thoughts I would like to abandon this patch, since sensor_manager2.py will be invoked before OCC becomes active.<br>So searching hwmon sysfs for "user_powercap" attribute will always fail, since only after OCC becomes active, the OCC hwmon sysfs attributes can be created.<br><br>I will resubmit a patch.<br><br>For your comments, please see bellow:<br><br><font color="#990099">-----"openbmc" <<a target="_blank" href="mailto:openbmc-bounces+shliyi=cn.ibm.com@lists.ozlabs.org">openbmc-bounces+shliyi=cn.ibm.com@lists.ozlabs.org</a>> wrote: -----</font><br><br>>To: OpenBMC Patches <<a target="_blank" href="mailto:openbmc-patches@stwcx.xyz">openbmc-patches@stwcx.xyz</a>>,<br>><a target="_blank" href="mailto:openbmc@lists.ozlabs.org">openbmc@lists.ozlabs.org</a><br>>From: Andrew Jeffery <br>>Sent by: "openbmc" <br>>Date: 02/22/2016 09:33AM<br>>Subject: Re: [PATCH skeleton] skeleton: fixed hard-coding for master<br>>OCC hwmon sysfs path<br>><br>>Hi Yi Li,<br>><br>>On Fri, 2016-02-19 at 13:10 -0600, OpenBMC Patches wrote:<br>>> From: Yi Li <<a target="_blank" href="mailto:adamliyi@msn.com">adamliyi@msn.com</a>><br>>> <br><br>>> > > obj_path = OBJ_PATH+"/host/PowerCap"<br>>> > > sensor_obj = Sensors.PowerCap(bus,obj_path)<br>>> -> > ## hwmon3 is default for master OCC on Barreleye.<br>>> -> > ## should rewrite sensor_manager to remove hardcode<br>>> -> > sensor_obj.sysfs_attr =<br>>"/sys/class/hwmon/hwmon3/user_powercap"<br>>> +> > ## scan hwmon sysfs for master occ's user_powercap attribute<br>>> +> > for pcap_file in<br>>glob.glob('/sys/class/hwmon/*/user_powercap'):<br>>> +> > > occ_i2c_dev = os.path.dirname(pcap_file)+'/device'<br>>> +> > > occ_i2c_dev =<br>>os.path.realpath(occ_i2c_dev).split('/').pop()<br>>> +> > > # master OCC address<br>>> +> > > if occ_i2c_dev == '3-0050':<br>>> +> > > > sensor_obj.sysfs_attr = pcap_file<br>><br>>Have you tested the code in the for loop? Because running the body in<br>>a<br>>Python shell doesn't give me confidence the if-condition will ever be<br>>satisfied:<br>><br><br>The skeleton creates sensors in the order following BMC states, see Barreleye.py.<br>When I did test, I manually booted the host. But when obmc actually boots, sensor_manger2.py will be invoked before OCC becomes active.<br>"glob.glob()" search will return empty list.<br><br>I will need to fix this.<br><br>> andrew@keelia :~$ python<br>> Python 2.7.10 (default, Oct 14 2015, 16:09:02) <br>> [GCC 5.2.1 20151010] on linux2<br>> Type "help", "copyright", "credits" or "license" for more<br>>information.<br>> >>> import os<br>> >>> pcap_file = "/sys/class/hwmon/hwmon3/user_powercap"<br>>>>> os.path.dirname(pcap_file)+"/device"<br>>'/sys/class/hwmon/hwmon3/device'<br>>>>> os.path.realpath(_).split('/')<br>>['', 'sys', 'class', 'hwmon', 'hwmon3', 'device']<br>>>>> _.pop()<br>>'device'<br>>>>> <br>><br>>I can't see how occ_i2c_dev will ever take the value '3-0050'? Are we<br>>missing additional globbing and/or reading of files?<br>><br><br>"os.path.realpath()" will resolve the symbol link to real file path, e.g:"/sys/class/hwmon3/device", the real path will be e.g:"/sys/class/i2c-adaptor/... ... /3-0050".<br><br>>> root_sensor.add(obj_path,sensor_obj)<br>><br>>Have you given consideration to what should be done if the<br>>if-condition<br>>in the for loop above never fires? Is it still valid to add<br>>sensor_obj?<br>><br><br>Yes. In Sensor.py, I assigned a default path to "sysfs_attr"<br><br>"CONTROL_IFACE = 'org.openbmc.Control'<br>class PowerCap(VirtualSensor):<br> def __init__(self, bus, name):<br> VirtualSensor.__init__(self, bus, name)<br> SensorValue.setValue(self, 0)<br> self.sysfs_attr = "/sys/class/hwmon/hwmon3/user_powercap"<br>"<br><br>Thanks,<br>-Yi<br></font><BR>