@@ -281,7 +281,34 @@ EXPORT_SYMBOL_GPL(schedule_hrtimeout);
281
281
282
282
/**
283
283
* msleep - sleep safely even with waitqueue interruptions
284
- * @msecs: Time in milliseconds to sleep for
284
+ * @msecs: Requested sleep duration in milliseconds
285
+ *
286
+ * msleep() uses jiffy based timeouts for the sleep duration. Because of the
287
+ * design of the timer wheel, the maximum additional percentage delay (slack) is
288
+ * 12.5%. This is only valid for timers which will end up in level 1 or a higher
289
+ * level of the timer wheel. For explanation of those 12.5% please check the
290
+ * detailed description about the basics of the timer wheel.
291
+ *
292
+ * The slack of timers which will end up in level 0 depends on sleep duration
293
+ * (msecs) and HZ configuration and can be calculated in the following way (with
294
+ * the timer wheel design restriction that the slack is not less than 12.5%):
295
+ *
296
+ * ``slack = MSECS_PER_TICK / msecs``
297
+ *
298
+ * When the allowed slack of the callsite is known, the calculation could be
299
+ * turned around to find the minimal allowed sleep duration to meet the
300
+ * constraints. For example:
301
+ *
302
+ * * ``HZ=1000`` with ``slack=25%``: ``MSECS_PER_TICK / slack = 1 / (1/4) = 4``:
303
+ * all sleep durations greater or equal 4ms will meet the constraints.
304
+ * * ``HZ=1000`` with ``slack=12.5%``: ``MSECS_PER_TICK / slack = 1 / (1/8) = 8``:
305
+ * all sleep durations greater or equal 8ms will meet the constraints.
306
+ * * ``HZ=250`` with ``slack=25%``: ``MSECS_PER_TICK / slack = 4 / (1/4) = 16``:
307
+ * all sleep durations greater or equal 16ms will meet the constraints.
308
+ * * ``HZ=250`` with ``slack=12.5%``: ``MSECS_PER_TICK / slack = 4 / (1/8) = 32``:
309
+ * all sleep durations greater or equal 32ms will meet the constraints.
310
+ *
311
+ * See also the signal aware variant msleep_interruptible().
285
312
*/
286
313
void msleep (unsigned int msecs )
287
314
{
@@ -294,7 +321,15 @@ EXPORT_SYMBOL(msleep);
294
321
295
322
/**
296
323
* msleep_interruptible - sleep waiting for signals
297
- * @msecs: Time in milliseconds to sleep for
324
+ * @msecs: Requested sleep duration in milliseconds
325
+ *
326
+ * See msleep() for some basic information.
327
+ *
328
+ * The difference between msleep() and msleep_interruptible() is that the sleep
329
+ * could be interrupted by a signal delivery and then returns early.
330
+ *
331
+ * Returns: The remaining time of the sleep duration transformed to msecs (see
332
+ * schedule_timeout() for details).
298
333
*/
299
334
unsigned long msleep_interruptible (unsigned int msecs )
300
335
{
@@ -312,11 +347,17 @@ EXPORT_SYMBOL(msleep_interruptible);
312
347
* @max: Maximum time in usecs to sleep
313
348
* @state: State of the current task that will be while sleeping
314
349
*
350
+ * usleep_range_state() sleeps at least for the minimum specified time but not
351
+ * longer than the maximum specified amount of time. The range might reduce
352
+ * power usage by allowing hrtimers to coalesce an already scheduled interrupt
353
+ * with this hrtimer. In the worst case, an interrupt is scheduled for the upper
354
+ * bound.
355
+ *
356
+ * The sleeping task is set to the specified state before starting the sleep.
357
+ *
315
358
* In non-atomic context where the exact wakeup time is flexible, use
316
- * usleep_range_state() instead of udelay(). The sleep improves responsiveness
317
- * by avoiding the CPU-hogging busy-wait of udelay(), and the range reduces
318
- * power usage by allowing hrtimers to take advantage of an already-
319
- * scheduled interrupt instead of scheduling a new one just for this sleep.
359
+ * usleep_range() or its variants instead of udelay(). The sleep improves
360
+ * responsiveness by avoiding the CPU-hogging busy-wait of udelay().
320
361
*/
321
362
void __sched usleep_range_state (unsigned long min , unsigned long max , unsigned int state )
322
363
{
0 commit comments