[igt-dev] [PATCH i-g-t 01/01] lib/igt_pm: dump runtime pm status on timeout

Vanshidhar Konda vanshidhar.r.konda at intel.com
Thu Oct 3 21:53:30 UTC 2019


On Thu, Oct 03, 2019 at 02:43:11PM -0700, Hiatt, Don wrote:
>
>________________________________________
>From: Konda, Vanshidhar R
>Sent: Wednesday, October 02, 2019 1:56 PM
>To: Hiatt, Don
>Cc: igt-dev at lists.freedesktop.org
>Subject: Re: [igt-dev] [PATCH i-g-t 01/01] lib/igt_pm: dump runtime pm status on timeout
>
>On Wed, Oct 02, 2019 at 09:58:04AM -0700, don.hiatt at intel.com wrote:
>>From: Don Hiatt <don.hiatt at intel.com>
>>
>>Display the runtime pm status if we timeout waiting for status.
>>
>>Signed-off-by: Don Hiatt <don.hiatt at intel.com>
>>---
>> lib/igt_pm.c | 16 ++++++++++++----
>> lib/igt_pm.h |  2 +-
>> 2 files changed, 13 insertions(+), 5 deletions(-)
>>
>>diff --git a/lib/igt_pm.c b/lib/igt_pm.c
>>index 64ce240e093f..0d3561fdf821 100644
>>--- a/lib/igt_pm.c
>>+++ b/lib/igt_pm.c
>>@@ -658,16 +658,17 @@ void igt_disable_runtime_pm(void)
>>
>> /**
>>  * igt_get_runtime_pm_status:
>>+ * @buf: buffer to place pm status string in
>>+ * @len: length of buf
>>  *
>>  * Returns: The current runtime PM status.
>>  */
>>-enum igt_runtime_pm_status igt_get_runtime_pm_status(void)
>>+enum igt_runtime_pm_status igt_get_runtime_pm_status(char *buf, int len)
>> {
>>       ssize_t n_read;
>>-      char buf[32];
>>
>>       lseek(pm_status_fd, 0, SEEK_SET);
>>-      n_read = read(pm_status_fd, buf, ARRAY_SIZE(buf) - 1);
>>+      n_read = read(pm_status_fd, buf, len - 1);
>>       igt_assert(n_read >= 0);
>
>> May be we should add an assert here that makes sure n_read < len?
>>
>>Vanshi
>
>Hi Vanshi,
>
>read() can never return more than the size requested, see 'man 3 read':
>  ssize_t pread(int fildes, void *buf, size_t nbyte, off_t offset);
>  "This number shall never be greater than nbyte."
>

Ah! You are right. I missed that.

Reviewed-by: Vanshidhar Konda <vanshidhar.r.konda at intel.com>

>Thanks,
>
>don
>
>
>>       buf[n_read] = '\0';
>>
>>@@ -697,7 +698,14 @@ enum igt_runtime_pm_status igt_get_runtime_pm_status(void)
>>  */
>> bool igt_wait_for_pm_status(enum igt_runtime_pm_status status)
>> {
>>-      return igt_wait(igt_get_runtime_pm_status() == status, 10000, 100);
>>+      bool ret;
>>+      char buf[32];
>>+
>>+      ret = igt_wait(igt_get_runtime_pm_status(buf, ARRAY_SIZE(buf)) == status, 10000, 100);
>>+      if (!ret)
>>+              igt_warn("timeout: pm_status=%s", buf);
>>+
>>+      return ret;
>> }
>>
>> /**
>>diff --git a/lib/igt_pm.h b/lib/igt_pm.h
>>index 7dc241749180..b2ff835e8a33 100644
>>--- a/lib/igt_pm.h
>>+++ b/lib/igt_pm.h
>>@@ -49,7 +49,7 @@ enum igt_runtime_pm_status {
>> bool igt_setup_runtime_pm(void);
>> void igt_disable_runtime_pm(void);
>> void igt_restore_runtime_pm(void);
>>-enum igt_runtime_pm_status igt_get_runtime_pm_status(void);
>>+enum igt_runtime_pm_status igt_get_runtime_pm_status(char *buf, int len);
>> bool igt_wait_for_pm_status(enum igt_runtime_pm_status status);
>> bool igt_pm_dmc_loaded(int debugfs);
>> bool igt_pm_pc8_plus_residencies_enabled(int msr_fd);
>>--
>>2.20.1
>>
>>_______________________________________________
>>igt-dev mailing list
>>igt-dev at lists.freedesktop.org
>>https://lists.freedesktop.org/mailman/listinfo/igt-dev
>


More information about the igt-dev mailing list