Re: [PATCH v3] rt-tests: hwlatdetect: Gracefully handle lack of /dev/cpu_dma_latency

Punit Agrawal
2021-09-29T22:28:17Z

John Kacur <jkacur@redhat.com> writes:

> On Wed, 29 Sep 2021, Punit Agrawal wrote:
>
>> From: Punit Agrawal <punit1.agrawal@toshiba.co.jp>
>>
>> On systems where cpu idle is disabled to reduce latencies,
>> "/dev/cpu_dma_latency" does not exist and leads to the following
>> exception report from python when using hwlatdetect.py -
>>
>> FileNotFoundError: [Errno 2] No such file or directory: '/dev/cpu_dma_latency
>>
>> Update hwlatdetect to check whether the file exists before attemping
>> to write values to it. Also, make the related debug output conditional
>> to c-states support being enabled in the kernel.
>>
>> While we are touching this part of the code, also address a couple of
>> minor issues in the code such as -
>> * correct typos
>> * reflow comment to fit 80-char column limit
>>
>> Reported-by: Suresh Hegde <suresh.c11@toshiba-tsip.com>
>> Signed-off-by: Punit Agrawal <punit1.agrawal@toshiba.co.jp>
>> ---
>> v2 -> v3:
>> * Address issues in comment
>> * Initialise self.dma_latency_handle in init()
>> * Make debug() statements conditional to /dev/cpu_dma_latency
>> ---
>> src/hwlatdetect/hwlatdetect.py | 16 ++++++++++------
>> 1 file changed, 10 insertions(+), 6 deletions(-)
>>
>> diff --git a/src/hwlatdetect/hwlatdetect.py b/src/hwlatdetect/hwlatdetect.py
>> index 12228f45f852..56fd2af8641d 100755
>> --- a/src/hwlatdetect/hwlatdetect.py
>> +++ b/src/hwlatdetect/hwlatdetect.py
>> @@ -200,6 +200,7 @@ class Detector(object):
>> if os.path.exists('/usr/sbin/rdmsr'):
>> self.have_msr = True
>> self.initsmi = self.getsmicounts()
>> + self.dma_latency_handle = None
>>
>> def getsmicounts(self):
>> counts = []
>> @@ -210,20 +211,23 @@ class Detector(object):
>> return counts
>>
>> # methods for preventing/enabling c-state transitions
>> - # openinging /dev/cpu_dma_latency and writeing a 32-bit zero to that file will prevent
>> - # c-state transitions while the file descriptor is open.
>> + #
>> + # opening /dev/cpu_dma_latency and writing a 32-bit zero to that file will
>> + # prevent c-state transitions while the file descriptor is open.
>> + #
>> # use c_states_off() to disable c-state transitions
>> # use c_states_on() to close the file descriptor and re-enable c-states
>> #
>> def c_states_off(self):
>> - self.dma_latency_handle = os.open("/dev/cpu_dma_latency", os.O_WRONLY)
>> - os.write(self.dma_latency_handle, b'\x00\x00\x00\x00')
>> - debug("c-states disabled")
>> + if os.path.exists("/dev/cpu_dma_latency"):
>> + self.dma_latency_handle = os.open("/dev/cpu_dma_latency", os.O_WRONLY)
>> + os.write(self.dma_latency_handle, b'\x00\x00\x00\x00')
>> + debug("c-states disabled")
>>
>> def c_states_on(self):
>> if self.dma_latency_handle:
>> os.close(self.dma_latency_handle)
>> - debug("c-states enabled")
>> + debug("c-states enabled")
>>
>> def cleanup(self):
>> raise RuntimeError("must override base method 'cleanup'!")
>> --
>> 2.32.0
>>
>>
>
> Signed-off-by: John Kacur <jkacur@redhat.com>

Thanks for applying the patch!