mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-05-16 06:41:39 -04:00
We want to reuse the same increased sleep logic in other places. To avoid code duplication, move it to the helper. Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com> Reviewed-by: Matthew Brost <matthew.brost@intel.com> Link: https://patch.msgid.link/20260127193727.601-3-michal.wajdeczko@intel.com
58 lines
1.3 KiB
C
58 lines
1.3 KiB
C
/* SPDX-License-Identifier: MIT */
|
|
/*
|
|
* Copyright © 2026 Intel Corporation
|
|
*/
|
|
|
|
#ifndef _XE_SLEEP_H_
|
|
#define _XE_SLEEP_H_
|
|
|
|
#include <linux/delay.h>
|
|
#include <linux/math64.h>
|
|
|
|
/**
|
|
* xe_sleep_relaxed_ms() - Sleep for an approximate time.
|
|
* @delay_ms: time in msec to sleep
|
|
*
|
|
* For smaller timeouts, sleep with 0.5ms accuracy.
|
|
*/
|
|
static inline void xe_sleep_relaxed_ms(unsigned int delay_ms)
|
|
{
|
|
unsigned long min_us, max_us;
|
|
|
|
if (!delay_ms)
|
|
return;
|
|
|
|
if (delay_ms > 20) {
|
|
msleep(delay_ms);
|
|
return;
|
|
}
|
|
|
|
min_us = mul_u32_u32(delay_ms, 1000);
|
|
max_us = min_us + 500;
|
|
|
|
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
|