From: arnd@arndb.de (Arnd Bergmann)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v4 1/2] iopoll: Introduce memory-mapped IO polling macros
Date: Wed, 08 Oct 2014 15:40:46 +0200 [thread overview]
Message-ID: <2434048.k6JtGScJfe@wuerfel> (raw)
In-Reply-To: <vnkwoatngwmo.fsf@mitchelh-linux.qualcomm.com>
On Tuesday 07 October 2014 18:47:59 Mitchel Humpherys wrote:
> On Wed, Oct 01 2014 at 01:25:33 AM, Arnd Bergmann <arnd@arndb.de> wrote:
> > On Tuesday 30 September 2014 18:28:12 Mitchel Humpherys wrote:
> >> + */
> >> +#define readl_poll_timeout(addr, val, cond, sleep_us, timeout_us) \
> >> +({ \
> >> + ktime_t timeout = ktime_add_us(ktime_get(), timeout_us); \
> >> + might_sleep_if(timeout_us); \
> >
> > Does it make sense to call this with timeout_us = 0?
>
> Yes, the idea there being to "never timeout". That mode should, of
> course, be used with extreme caution since never timing out is not
> really "playing nice" with the system.
But then you certainly still 'might_sleep' here. The
might_sleep_if(timeout_us) line suggests that it won't sleep, but
that isn't the case.
> >
> >> + for (;;) { \
> >> + (val) = readl(addr); \
> >> + if (cond) \
> >> + break; \
> >> + if (timeout_us && ktime_compare(ktime_get(), timeout) > 0) { \
> >> + (val) = readl(addr); \
> >> + break; \
> >> + } \
> >> + if (sleep_us) \
> >> + usleep_range(DIV_ROUND_UP(sleep_us, 4), sleep_us); \
> >> + } \
> >> + (cond) ? 0 : -ETIMEDOUT; \
> >> +})
> >
> > I think it would be better to tie the 'range' argument to the timeout. Also
> > doing a division seems expensive here.
>
> We may have cases where the HW spec says something like "the foo widget
> response time is on average 5us, with a worst case of 100us." In such a
> case we may want to poll the bit very frequently to optimize for the
> common case of a very fast lock time, but we may not want to error out
> due to a timeout unless we've been waiting 100us.
Ok.
> Regarding the division, for the overwhelmingly common case where the
> user of the API passes in a constant for sleep_us the compiler optimizes
> out this calculation altogether and just sticks the final result in (I
> verified this with gcc 4.9 and the kernel build system's built-in
> support for generating .s files). Conveying semantic meaning by using
> `DIV_ROUND_UP' is nice but if you feel strongly about it we can make
> this a shift instead.
The more important question is probably if you want to keep the _ROUND_UP
part. If that's not significant, I think a shift would be better.
Arnd
next prev parent reply other threads:[~2014-10-08 13:40 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-01 1:28 [PATCH v4 0/2] iommu/arm-smmu: hard iova_to_phys Mitchel Humpherys
2014-10-01 1:28 ` [PATCH v4 1/2] iopoll: Introduce memory-mapped IO polling macros Mitchel Humpherys
2014-10-01 8:25 ` Arnd Bergmann
2014-10-08 1:47 ` Mitchel Humpherys
2014-10-08 13:40 ` Arnd Bergmann [this message]
2014-10-10 19:44 ` Mitchel Humpherys
2014-10-10 19:50 ` Arnd Bergmann
2014-10-10 20:24 ` Mitchel Humpherys
2014-10-09 22:45 ` Mitchel Humpherys
2014-10-01 1:28 ` [PATCH v4 2/2] iommu/arm-smmu: add support for iova_to_phys through ATS1PR Mitchel Humpherys
2014-10-01 8:27 ` Arnd Bergmann
2014-10-01 19:52 ` Mitchel Humpherys
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=2434048.k6JtGScJfe@wuerfel \
--to=arnd@arndb.de \
--cc=linux-arm-kernel@lists.infradead.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