lkml.org 
[lkml]   [2015]   [Nov]   [13]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [PATCH 1/4] ktime: add a roundup function
From
On Fri, Nov 13, 2015 at 11:53 AM, Jacob Pan
<jacob.jun.pan@linux.intel.com> wrote:
> ktime roundup function can be used to keep timer aligned and
> prevent drift for recurring timeouts.
>
> Signed-off-by: Jacob Pan <jacob.jun.pan@linux.intel.com>
> ---
> include/linux/ktime.h | 10 ++++++++++
> 1 file changed, 10 insertions(+)
>
> diff --git a/include/linux/ktime.h b/include/linux/ktime.h
> index 2b6a204..2e293fa 100644
> --- a/include/linux/ktime.h
> +++ b/include/linux/ktime.h
> @@ -233,6 +233,16 @@ static inline ktime_t ktime_sub_us(const ktime_t kt, const u64 usec)
>
> extern ktime_t ktime_add_safe(const ktime_t lhs, const ktime_t rhs);
>
> +static inline ktime_t ktime_roundup(ktime_t x, ktime_t y)
> +{
> + u64 temp_tv64;
> +
> + temp_tv64 = x.tv64 + y.tv64 - 1;
> + temp_tv64 = div64_u64(temp_tv64, y.tv64);
> + x.tv64 = temp_tv64 * y.tv64;
> +
> + return x;
> +}

Could you add a comment as to what the function does, and use some
better variable names here to make it more immediately obvious what is
being done here?

Something like:
/**
* ktime_roundup - Rounds value up to interval chunk
* @ value: Value to be rounded up
* @ interval: interval size to round up to
*
* Rounds a value up to the next higher multiple of an interval size
*/
static inline ktime ktime_roundup(ktime_t value, ktime_t interval)

thanks
-john


\
 
 \ /
  Last update: 2015-11-13 21:21    [W:1.493 / U:0.076 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site