public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Nick Piggin <piggin@cyberone.com.au>
To: Neil Brown <neilb@cse.unsw.edu.au>, Andrew Morton <akpm@zip.com.au>
Cc: Matthew Wilcox <willy@debian.org>,
	Bernardo Innocenti <bernie@develer.com>,
	linux-kernel@vger.kernel.org
Subject: Re: do_div vs sector_t (patch)
Date: Sat, 12 Jul 2003 10:14:17 +1000	[thread overview]
Message-ID: <3F0F52D9.70802@cyberone.com.au> (raw)
In-Reply-To: <16143.15690.106092.770785@gargle.gargle.HOWL>

[-- Attachment #1: Type: text/plain, Size: 1647 bytes --]



Neil Brown wrote:

>On Friday July 11, willy@debian.org wrote:
>
>># define do_div(n,base) ({                              \
>>        uint32_t __base = (base);                       \
>>        uint32_t __rem;                                 \
>>        if (likely(((n) >> 32) == 0)) {                 \
>>
>>so if we call do_div() on a u32, the compiler emits nasal daemons.
>>and we do this -- in the antcipatory scheduler:
>>
>>                if (aic->seek_samples) {
>>                        aic->seek_mean = aic->seek_total + 128;
>>                        do_div(aic->seek_mean, aic->seek_samples);
>>                }
>>
>>seek_mean is a sector_t so sometimes it's 64-bit on a 32-bit platform.
>>so we can't avoid calling do_div().
>>
>>This almost works (the warning is harmless since gcc optimises away the call)
>>
>># define do_div(n,base) ({                                              \
>>        uint32_t __base = (base);                                       \
>>        uint32_t __rem;                                                 \
>>        if ((sizeof(n) < 8) || (likely(((n) >> 32) == 0))) {            \
>>                __rem = (uint32_t)(n) % __base;                         \
>>                (n) = (uint32_t)(n) / __base;                           \
>>        } else                                                          \
>>                __rem = __div64_32(&(n), __base);                       \
>>        __rem;                                                          \
>> })
>>
>>Better ideas?
>>
>
>sector_div, defined in blkdev.h, is probably what you want.
>

Looks right. Following patch alright?


[-- Attachment #2: as-do-div --]
[-- Type: text/plain, Size: 510 bytes --]

--- linux-2.5/drivers/block/as-iosched.c.orig	2003-07-12 10:12:20.000000000 +1000
+++ linux-2.5/drivers/block/as-iosched.c	2003-07-12 10:12:28.000000000 +1000
@@ -837,7 +837,7 @@ static void as_update_iohist(struct as_i
 		aic->seek_total += 256*seek_dist;
 		if (aic->seek_samples) {
 			aic->seek_mean = aic->seek_total + 128;
-			do_div(aic->seek_mean, aic->seek_samples);
+			sector_div(aic->seek_mean, aic->seek_samples);
 		}
 		aic->seek_samples = (aic->seek_samples>>1)
 					+ (aic->seek_samples>>2);

  reply	other threads:[~2003-07-12  0:00 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-07-11 22:33 do_div vs sector_t Matthew Wilcox
2003-07-11 22:34 ` Andrew Morton
2003-07-11 22:42 ` Neil Brown
2003-07-12  0:14   ` Nick Piggin [this message]
2003-07-12  6:52 ` Christoph Hellwig
2003-07-12  6:58   ` Andrew Morton
2003-07-13 17:26 ` Richard Henderson
2003-07-13 17:39   ` Russell King
2003-07-13 19:14   ` Bernardo Innocenti
2003-07-13 20:04     ` Matthew Wilcox
2003-07-14  4:07 ` Peter Chubb

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3F0F52D9.70802@cyberone.com.au \
    --to=piggin@cyberone.com.au \
    --cc=akpm@zip.com.au \
    --cc=bernie@develer.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=neilb@cse.unsw.edu.au \
    --cc=willy@debian.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox