@@ -483,61 +483,40 @@ struct timespec64 ns_to_timespec64(const s64 nsec)
483
483
}
484
484
EXPORT_SYMBOL (ns_to_timespec64 );
485
485
#endif
486
- /*
487
- * When we convert to jiffies then we interpret incoming values
488
- * the following way:
486
+ /**
487
+ * msecs_to_jiffies: - convert milliseconds to jiffies
488
+ * @m: time in milliseconds
489
+ *
490
+ * conversion is done as follows:
489
491
*
490
492
* - negative values mean 'infinite timeout' (MAX_JIFFY_OFFSET)
491
493
*
492
494
* - 'too large' values [that would result in larger than
493
495
* MAX_JIFFY_OFFSET values] mean 'infinite timeout' too.
494
496
*
495
497
* - all other values are converted to jiffies by either multiplying
496
- * the input value by a factor or dividing it with a factor
497
- *
498
- * We must also be careful about 32-bit overflows.
498
+ * the input value by a factor or dividing it with a factor and
499
+ * handling any 32-bit overflows.
500
+ * for the details see __msecs_to_jiffies()
501
+ *
502
+ * msecs_to_jiffies() checks for the passed in value being a constant
503
+ * via __builtin_constant_p() allowing gcc to eliminate most of the
504
+ * code, __msecs_to_jiffies() is called if the value passed does not
505
+ * allow constant folding and the actual conversion must be done at
506
+ * runtime.
507
+ * the _msecs_to_jiffies helpers are the HZ dependent conversion
508
+ * routines found in include/linux/jiffies.h
499
509
*/
500
- unsigned long msecs_to_jiffies (const unsigned int m )
510
+ unsigned long __msecs_to_jiffies (const unsigned int m )
501
511
{
502
512
/*
503
513
* Negative value, means infinite timeout:
504
514
*/
505
515
if ((int )m < 0 )
506
516
return MAX_JIFFY_OFFSET ;
507
-
508
- #if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ )
509
- /*
510
- * HZ is equal to or smaller than 1000, and 1000 is a nice
511
- * round multiple of HZ, divide with the factor between them,
512
- * but round upwards:
513
- */
514
- return (m + (MSEC_PER_SEC / HZ ) - 1 ) / (MSEC_PER_SEC / HZ );
515
- #elif HZ > MSEC_PER_SEC && !(HZ % MSEC_PER_SEC )
516
- /*
517
- * HZ is larger than 1000, and HZ is a nice round multiple of
518
- * 1000 - simply multiply with the factor between them.
519
- *
520
- * But first make sure the multiplication result cannot
521
- * overflow:
522
- */
523
- if (m > jiffies_to_msecs (MAX_JIFFY_OFFSET ))
524
- return MAX_JIFFY_OFFSET ;
525
-
526
- return m * (HZ / MSEC_PER_SEC );
527
- #else
528
- /*
529
- * Generic case - multiply, round and divide. But first
530
- * check that if we are doing a net multiplication, that
531
- * we wouldn't overflow:
532
- */
533
- if (HZ > MSEC_PER_SEC && m > jiffies_to_msecs (MAX_JIFFY_OFFSET ))
534
- return MAX_JIFFY_OFFSET ;
535
-
536
- return (MSEC_TO_HZ_MUL32 * m + MSEC_TO_HZ_ADJ32 )
537
- >> MSEC_TO_HZ_SHR32 ;
538
- #endif
517
+ return _msecs_to_jiffies (m );
539
518
}
540
- EXPORT_SYMBOL (msecs_to_jiffies );
519
+ EXPORT_SYMBOL (__msecs_to_jiffies );
541
520
542
521
unsigned long usecs_to_jiffies (const unsigned int u )
543
522
{
0 commit comments