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, 01 Oct 2014 10:25:33 +0200 [thread overview]
Message-ID: <23910474.oJQUXZsx4W@wuerfel> (raw)
In-Reply-To: <1412126893-15796-2-git-send-email-mitchelh@codeaurora.org>
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?
> + 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.
> +/**
> + * readl_poll_timeout_atomic - Periodically poll an address until a condition is met or a timeout occurs
> + * @addr: Address to poll
> + * @val: Variable to read the value into
> + * @cond: Break condition (usually involving @val)
> + * @max_reads: Maximum number of reads before giving up
> + * @time_between_us: Time to udelay() between successive reads
> + *
> + * Returns 0 on success and -ETIMEDOUT upon a timeout.
> + */
> +#define readl_poll_timeout_atomic(addr, val, cond, max_reads, time_between_us) \
> +({ \
> + int count; \
> + for (count = (max_reads); count > 0; count--) { \
> + (val) = readl(addr); \
> + if (cond) \
> + break; \
> + udelay(time_between_us); \
> + } \
> + (cond) ? 0 : -ETIMEDOUT; \
> +})
udelay has a large variability, I think it would be better to also use
ktime_compare here and make the interface the same as the other one.
You might want to add a warning if someone tries to pass more than a few
microseconds as the timeout.
More generally speaking, using 'readl' seems fairly specific. I suspect
that we'd have to add the entire range of accessors over time if this
catches on: readb, readw, readq, readb_relaxed, readw_relaxed, readl_relaxed,
readq_relaxed, ioread8, ioread16, ioread16be, ioread32, ioread32be,
inb, inb_p, inw, inw_p, inw, inl, inl_p, and possibly more of those.
Would it make sense to pass that operation as an argument?
Arnd
next prev parent reply other threads:[~2014-10-01 8:25 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 [this message]
2014-10-08 1:47 ` Mitchel Humpherys
2014-10-08 13:40 ` Arnd Bergmann
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=23910474.oJQUXZsx4W@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