Commit eec43f36 authored by Michal Wajdeczko's avatar Michal Wajdeczko
Browse files

drm/xe: Move exponential sleep logic to helper



We want to reuse the same increased sleep logic in other places.
To avoid code duplication, move it to the helper.

Signed-off-by: default avatarMichal Wajdeczko <michal.wajdeczko@intel.com>
Reviewed-by: default avatarMatthew Brost <matthew.brost@intel.com>
Link: https://patch.msgid.link/20260127193727.601-3-michal.wajdeczko@intel.com
parent 94a2ceb1
Loading
Loading
Loading
Loading
+1 −4
Original line number Diff line number Diff line
@@ -1049,10 +1049,7 @@ static int wq_wait_for_space(struct xe_exec_queue *q, u32 wqi_size)
				return -ENODEV;
			}

			msleep(sleep_period_ms);
			sleep_total_ms += sleep_period_ms;
			if (sleep_period_ms < 64)
				sleep_period_ms <<= 1;
			sleep_total_ms += xe_sleep_exponential_ms(&sleep_period_ms, 64);
			goto try_again;
		}
	}
+21 −0
Original line number Diff line number Diff line
@@ -33,4 +33,25 @@ static inline void xe_sleep_relaxed_ms(unsigned int delay_ms)
	usleep_range(min_us, max_us);
}

/**
 * xe_sleep_exponential_ms() - Sleep for a exponentially increased time.
 * @sleep_period_ms: current time in msec to sleep
 * @max_sleep_ms: maximum time in msec to sleep
 *
 * Sleep for the @sleep_period_ms and exponentially increase this time for the
 * next loop, unless reaching the @max_sleep_ms limit.
 *
 * Return: approximate time in msec the task was delayed.
 */
static inline unsigned int xe_sleep_exponential_ms(unsigned int *sleep_period_ms,
						   unsigned int max_sleep_ms)
{
	unsigned int delay_ms = *sleep_period_ms;
	unsigned int next_delay_ms = 2 * delay_ms;

	xe_sleep_relaxed_ms(delay_ms);
	*sleep_period_ms = min(next_delay_ms, max_sleep_ms);
	return delay_ms;
}

#endif