All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] block, bfq: improve arithmetic division in bfq_delta()
@ 2020-01-20 10:04 Wen Yang
  2020-01-22 17:34 ` Jens Axboe
  0 siblings, 1 reply; 2+ messages in thread
From: Wen Yang @ 2020-01-20 10:04 UTC (permalink / raw)
  To: Paolo Valente; +Cc: Wen Yang, Jens Axboe, linux-block, linux-kernel

do_div() does a 64-by-32 division. Use div64_ul() instead of it
if the divisor is unsigned long, to avoid truncation to 32-bit.
And as a nice side effect also cleans up the function a bit.

Signed-off-by: Wen Yang <wenyang@linux.alibaba.com>
Cc: Paolo Valente <paolo.valente@linaro.org>
Cc: Jens Axboe <axboe@fb.com>
Cc: linux-block@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
 block/bfq-wf2q.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/block/bfq-wf2q.c b/block/bfq-wf2q.c
index 05f0bf4a1144..ffe9ce9faa89 100644
--- a/block/bfq-wf2q.c
+++ b/block/bfq-wf2q.c
@@ -277,10 +277,7 @@ struct bfq_queue *bfq_entity_to_bfqq(struct bfq_entity *entity)
  */
 static u64 bfq_delta(unsigned long service, unsigned long weight)
 {
-	u64 d = (u64)service << WFQ_SERVICE_SHIFT;
-
-	do_div(d, weight);
-	return d;
+	return div64_ul((u64)service << WFQ_SERVICE_SHIFT, weight);
 }
 
 /**
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] block, bfq: improve arithmetic division in bfq_delta()
  2020-01-20 10:04 [PATCH] block, bfq: improve arithmetic division in bfq_delta() Wen Yang
@ 2020-01-22 17:34 ` Jens Axboe
  0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2020-01-22 17:34 UTC (permalink / raw)
  To: Wen Yang, Paolo Valente; +Cc: linux-block, linux-kernel

On 1/20/20 3:04 AM, Wen Yang wrote:
> do_div() does a 64-by-32 division. Use div64_ul() instead of it
> if the divisor is unsigned long, to avoid truncation to 32-bit.
> And as a nice side effect also cleans up the function a bit.

Applied, thanks.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-01-22 17:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-20 10:04 [PATCH] block, bfq: improve arithmetic division in bfq_delta() Wen Yang
2020-01-22 17:34 ` Jens Axboe

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.