Rev 5270 | Rev 6934 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5270 | Rev 6082 | ||
---|---|---|---|
Line 290... | Line 290... | ||
290 | static inline u64 jiffies_to_nsecs(const unsigned long j) |
290 | static inline u64 jiffies_to_nsecs(const unsigned long j) |
291 | { |
291 | { |
292 | return (u64)jiffies_to_usecs(j) * NSEC_PER_USEC; |
292 | return (u64)jiffies_to_usecs(j) * NSEC_PER_USEC; |
293 | } |
293 | } |
Line 294... | Line 294... | ||
294 | 294 | ||
- | 295 | extern unsigned long __msecs_to_jiffies(const unsigned int m); |
|
- | 296 | #if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ) |
|
- | 297 | /* |
|
- | 298 | * HZ is equal to or smaller than 1000, and 1000 is a nice round |
|
- | 299 | * multiple of HZ, divide with the factor between them, but round |
|
- | 300 | * upwards: |
|
- | 301 | */ |
|
- | 302 | static inline unsigned long _msecs_to_jiffies(const unsigned int m) |
|
- | 303 | { |
|
- | 304 | return (m + (MSEC_PER_SEC / HZ) - 1) / (MSEC_PER_SEC / HZ); |
|
- | 305 | } |
|
- | 306 | #elif HZ > MSEC_PER_SEC && !(HZ % MSEC_PER_SEC) |
|
- | 307 | /* |
|
- | 308 | * HZ is larger than 1000, and HZ is a nice round multiple of 1000 - |
|
- | 309 | * simply multiply with the factor between them. |
|
- | 310 | * |
|
- | 311 | * But first make sure the multiplication result cannot overflow: |
|
- | 312 | */ |
|
- | 313 | static inline unsigned long _msecs_to_jiffies(const unsigned int m) |
|
- | 314 | { |
|
- | 315 | if (m > jiffies_to_msecs(MAX_JIFFY_OFFSET)) |
|
- | 316 | return MAX_JIFFY_OFFSET; |
|
- | 317 | return m * (HZ / MSEC_PER_SEC); |
|
- | 318 | } |
|
- | 319 | #else |
|
- | 320 | /* |
|
- | 321 | * Generic case - multiply, round and divide. But first check that if |
|
- | 322 | * we are doing a net multiplication, that we wouldn't overflow: |
|
- | 323 | */ |
|
- | 324 | static inline unsigned long _msecs_to_jiffies(const unsigned int m) |
|
- | 325 | { |
|
- | 326 | if (HZ > MSEC_PER_SEC && m > jiffies_to_msecs(MAX_JIFFY_OFFSET)) |
|
- | 327 | return MAX_JIFFY_OFFSET; |
|
- | 328 | ||
- | 329 | return (MSEC_TO_HZ_MUL32 * m + MSEC_TO_HZ_ADJ32) >> MSEC_TO_HZ_SHR32; |
|
- | 330 | } |
|
- | 331 | #endif |
|
- | 332 | /** |
|
- | 333 | * msecs_to_jiffies: - convert milliseconds to jiffies |
|
- | 334 | * @m: time in milliseconds |
|
- | 335 | * |
|
- | 336 | * conversion is done as follows: |
|
- | 337 | * |
|
- | 338 | * - negative values mean 'infinite timeout' (MAX_JIFFY_OFFSET) |
|
- | 339 | * |
|
- | 340 | * - 'too large' values [that would result in larger than |
|
- | 341 | * MAX_JIFFY_OFFSET values] mean 'infinite timeout' too. |
|
- | 342 | * |
|
- | 343 | * - all other values are converted to jiffies by either multiplying |
|
- | 344 | * the input value by a factor or dividing it with a factor and |
|
- | 345 | * handling any 32-bit overflows. |
|
- | 346 | * for the details see __msecs_to_jiffies() |
|
- | 347 | * |
|
- | 348 | * msecs_to_jiffies() checks for the passed in value being a constant |
|
- | 349 | * via __builtin_constant_p() allowing gcc to eliminate most of the |
|
- | 350 | * code, __msecs_to_jiffies() is called if the value passed does not |
|
- | 351 | * allow constant folding and the actual conversion must be done at |
|
- | 352 | * runtime. |
|
- | 353 | * the HZ range specific helpers _msecs_to_jiffies() are called both |
|
- | 354 | * directly here and from __msecs_to_jiffies() in the case where |
|
- | 355 | * constant folding is not possible. |
|
- | 356 | */ |
|
- | 357 | static inline unsigned long msecs_to_jiffies(const unsigned int m) |
|
- | 358 | { |
|
- | 359 | if (__builtin_constant_p(m)) { |
|
- | 360 | if ((int)m < 0) |
|
- | 361 | return MAX_JIFFY_OFFSET; |
|
- | 362 | return _msecs_to_jiffies(m); |
|
- | 363 | } else { |
|
- | 364 | return __msecs_to_jiffies(m); |
|
- | 365 | } |
|
- | 366 | } |
|
295 | extern unsigned long msecs_to_jiffies(const unsigned int m); |
367 | |
- | 368 | extern unsigned long __usecs_to_jiffies(const unsigned int u); |
|
- | 369 | #if !(USEC_PER_SEC % HZ) |
|
- | 370 | static inline unsigned long _usecs_to_jiffies(const unsigned int u) |
|
- | 371 | { |
|
- | 372 | return (u + (USEC_PER_SEC / HZ) - 1) / (USEC_PER_SEC / HZ); |
|
- | 373 | } |
|
- | 374 | #else |
|
- | 375 | static inline unsigned long _usecs_to_jiffies(const unsigned int u) |
|
- | 376 | { |
|
- | 377 | return (USEC_TO_HZ_MUL32 * u + USEC_TO_HZ_ADJ32) |
|
- | 378 | >> USEC_TO_HZ_SHR32; |
|
- | 379 | } |
|
- | 380 | #endif |
|
- | 381 | ||
- | 382 | /** |
|
- | 383 | * usecs_to_jiffies: - convert microseconds to jiffies |
|
- | 384 | * @u: time in microseconds |
|
- | 385 | * |
|
- | 386 | * conversion is done as follows: |
|
- | 387 | * |
|
- | 388 | * - 'too large' values [that would result in larger than |
|
- | 389 | * MAX_JIFFY_OFFSET values] mean 'infinite timeout' too. |
|
- | 390 | * |
|
- | 391 | * - all other values are converted to jiffies by either multiplying |
|
- | 392 | * the input value by a factor or dividing it with a factor and |
|
- | 393 | * handling any 32-bit overflows as for msecs_to_jiffies. |
|
- | 394 | * |
|
- | 395 | * usecs_to_jiffies() checks for the passed in value being a constant |
|
- | 396 | * via __builtin_constant_p() allowing gcc to eliminate most of the |
|
- | 397 | * code, __usecs_to_jiffies() is called if the value passed does not |
|
- | 398 | * allow constant folding and the actual conversion must be done at |
|
- | 399 | * runtime. |
|
- | 400 | * the HZ range specific helpers _usecs_to_jiffies() are called both |
|
- | 401 | * directly here and from __msecs_to_jiffies() in the case where |
|
- | 402 | * constant folding is not possible. |
|
- | 403 | */ |
|
- | 404 | static __always_inline unsigned long usecs_to_jiffies(const unsigned int u) |
|
- | 405 | { |
|
- | 406 | if (__builtin_constant_p(u)) { |
|
- | 407 | if (u > jiffies_to_usecs(MAX_JIFFY_OFFSET)) |
|
- | 408 | return MAX_JIFFY_OFFSET; |
|
- | 409 | return _usecs_to_jiffies(u); |
|
- | 410 | } else { |
|
- | 411 | return __usecs_to_jiffies(u); |
|
- | 412 | } |
|
- | 413 | } |
|
296 | extern unsigned long usecs_to_jiffies(const unsigned int u); |
414 | |
297 | extern unsigned long timespec_to_jiffies(const struct timespec *value); |
415 | extern unsigned long timespec64_to_jiffies(const struct timespec64 *value); |
298 | extern void jiffies_to_timespec(const unsigned long jiffies, |
416 | extern void jiffies_to_timespec64(const unsigned long jiffies, |
- | 417 | struct timespec64 *value); |
|
- | 418 | static inline unsigned long timespec_to_jiffies(const struct timespec *value) |
|
- | 419 | { |
|
- | 420 | struct timespec64 ts = timespec_to_timespec64(*value); |
|
- | 421 | ||
- | 422 | return timespec64_to_jiffies(&ts); |
|
- | 423 | } |
|
- | 424 | ||
- | 425 | static inline void jiffies_to_timespec(const unsigned long jiffies, |
|
- | 426 | struct timespec *value) |
|
- | 427 | { |
|
- | 428 | struct timespec64 ts; |
|
- | 429 | ||
- | 430 | jiffies_to_timespec64(jiffies, &ts); |
|
- | 431 | *value = timespec64_to_timespec(ts); |
|
- | 432 | } |
|
299 | struct timespec *value); |
433 | |
300 | extern unsigned long timeval_to_jiffies(const struct timeval *value); |
434 | extern unsigned long timeval_to_jiffies(const struct timeval *value); |
301 | extern void jiffies_to_timeval(const unsigned long jiffies, |
435 | extern void jiffies_to_timeval(const unsigned long jiffies, |
Line 302... | Line 436... | ||
302 | struct timeval *value); |
436 | struct timeval *value); |