* [PATCH igt] igt/perf_pmu: Avoid underflow in measured_sleep()
@ 2017-11-22 20:14 Chris Wilson
2017-11-23 7:04 ` Tvrtko Ursulin
2017-11-23 17:03 ` ✗ Fi.CI.BAT: failure for " Patchwork
0 siblings, 2 replies; 3+ messages in thread
From: Chris Wilson @ 2017-11-22 20:14 UTC (permalink / raw)
To: intel-gfx
Be careful not to underflow into a very large positive usec value and so
sleep forever^W until boredom kicks in.
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
---
tests/perf_pmu.c | 23 +++++++++--------------
1 file changed, 9 insertions(+), 14 deletions(-)
diff --git a/tests/perf_pmu.c b/tests/perf_pmu.c
index 5d5f2b30..e153aaf3 100644
--- a/tests/perf_pmu.c
+++ b/tests/perf_pmu.c
@@ -111,22 +111,17 @@ static void pmu_read_multi(int fd, unsigned int num, uint64_t *val)
*/
static unsigned int measured_usleep(unsigned int usec)
{
- uint64_t slept = 0;
-
- while (usec > 0) {
- struct timespec start = { };
- uint64_t this_sleep;
+ struct timespec ts = { };
+ unsigned int slept;
- igt_nsec_elapsed(&start);
- usleep(usec);
- this_sleep = igt_nsec_elapsed(&start);
- slept += this_sleep;
- if (this_sleep > usec * 1000)
- break;
- usec -= this_sleep;
- }
+ slept = igt_nsec_elapsed(&ts);
+ igt_assert(slept == 0);
+ do {
+ usleep(usec - slept);
+ slept = igt_nsec_elapsed(&ts) / 1000;
+ } while (slept < usec);
- return slept;
+ return igt_nsec_elapsed(&ts);
}
static unsigned int e2ring(int gem_fd, const struct intel_execution_engine2 *e)
--
2.15.0
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH igt] igt/perf_pmu: Avoid underflow in measured_sleep()
2017-11-22 20:14 [PATCH igt] igt/perf_pmu: Avoid underflow in measured_sleep() Chris Wilson
@ 2017-11-23 7:04 ` Tvrtko Ursulin
2017-11-23 17:03 ` ✗ Fi.CI.BAT: failure for " Patchwork
1 sibling, 0 replies; 3+ messages in thread
From: Tvrtko Ursulin @ 2017-11-23 7:04 UTC (permalink / raw)
To: Chris Wilson, intel-gfx
On 22/11/2017 20:14, Chris Wilson wrote:
> Be careful not to underflow into a very large positive usec value and so
> sleep forever^W until boredom kicks in.
>
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
> ---
> tests/perf_pmu.c | 23 +++++++++--------------
> 1 file changed, 9 insertions(+), 14 deletions(-)
>
> diff --git a/tests/perf_pmu.c b/tests/perf_pmu.c
> index 5d5f2b30..e153aaf3 100644
> --- a/tests/perf_pmu.c
> +++ b/tests/perf_pmu.c
> @@ -111,22 +111,17 @@ static void pmu_read_multi(int fd, unsigned int num, uint64_t *val)
> */
> static unsigned int measured_usleep(unsigned int usec)
> {
> - uint64_t slept = 0;
> -
> - while (usec > 0) {
> - struct timespec start = { };
> - uint64_t this_sleep;
> + struct timespec ts = { };
> + unsigned int slept;
>
> - igt_nsec_elapsed(&start);
> - usleep(usec);
> - this_sleep = igt_nsec_elapsed(&start);
> - slept += this_sleep;
> - if (this_sleep > usec * 1000)
> - break;
> - usec -= this_sleep;
> - }
> + slept = igt_nsec_elapsed(&ts);
> + igt_assert(slept == 0);
> + do {
> + usleep(usec - slept);
> + slept = igt_nsec_elapsed(&ts) / 1000;
> + } while (slept < usec);
>
> - return slept;
> + return igt_nsec_elapsed(&ts);
> }
>
> static unsigned int e2ring(int gem_fd, const struct intel_execution_engine2 *e)
>
Looks OK. Silly bug of mine and I wonder how I was so lucky not to hit
it all this time.
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Regards,
Tvrtko
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
^ permalink raw reply [flat|nested] 3+ messages in thread
* ✗ Fi.CI.BAT: failure for igt/perf_pmu: Avoid underflow in measured_sleep()
2017-11-22 20:14 [PATCH igt] igt/perf_pmu: Avoid underflow in measured_sleep() Chris Wilson
2017-11-23 7:04 ` Tvrtko Ursulin
@ 2017-11-23 17:03 ` Patchwork
1 sibling, 0 replies; 3+ messages in thread
From: Patchwork @ 2017-11-23 17:03 UTC (permalink / raw)
To: Chris Wilson; +Cc: intel-gfx
== Series Details ==
Series: igt/perf_pmu: Avoid underflow in measured_sleep()
URL : https://patchwork.freedesktop.org/series/34252/
State : failure
== Summary ==
Series 34252 revision 1 was fully merged or fully failed: no git log
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-11-23 17:03 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-22 20:14 [PATCH igt] igt/perf_pmu: Avoid underflow in measured_sleep() Chris Wilson
2017-11-23 7:04 ` Tvrtko Ursulin
2017-11-23 17:03 ` ✗ Fi.CI.BAT: failure for " Patchwork
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.