summaryrefslogtreecommitdiffstats
path: root/Documentation/driver-api/ioctl.rst
diff options
context:
space:
mode:
authorGeert Uytterhoeven <geert+renesas@glider.be>2023-06-02 10:50:36 +0200
committerGeert Uytterhoeven <geert+renesas@glider.be>2023-06-05 15:35:13 +0200
commitb407460ee99033503993ac7437d593451fcdfe44 (patch)
tree378552cb4ef8145abdd336768e6a37f20f44c959 /Documentation/driver-api/ioctl.rst
parentac9a78681b921877518763ba0e89202254349d1b (diff)
downloadlinux-b407460ee99033503993ac7437d593451fcdfe44.tar.gz
linux-b407460ee99033503993ac7437d593451fcdfe44.tar.bz2
linux-b407460ee99033503993ac7437d593451fcdfe44.zip
iopoll: Call cpu_relax() in busy loops
It is considered good practice to call cpu_relax() in busy loops, see Documentation/process/volatile-considered-harmful.rst. This can not only lower CPU power consumption or yield to a hyperthreaded twin processor, but also allows an architecture to mitigate hardware issues (e.g. ARM Erratum 754327 for Cortex-A9 prior to r2p0) in the architecture-specific cpu_relax() implementation. In addition, cpu_relax() is also a compiler barrier. It is not immediately obvious that the @op argument "function" will result in an actual function call (e.g. in case of inlining). Where a function call is a C sequence point, this is lost on inlining. Therefore, with agressive enough optimization it might be possible for the compiler to hoist the: (val) = op(args); "load" out of the loop because it doesn't see the value changing. The addition of cpu_relax() would inhibit this. As the iopoll helpers lack calls to cpu_relax(), people are sometimes reluctant to use them, and may fall back to open-coded polling loops (including cpu_relax() calls) instead. Fix this by adding calls to cpu_relax() to the iopoll helpers: - For the non-atomic case, it is sufficient to call cpu_relax() in case of a zero sleep-between-reads value, as a call to usleep_range() is a safe barrier otherwise. However, it doesn't hurt to add the call regardless, for simplicity, and for similarity with the atomic case below. - For the atomic case, cpu_relax() must be called regardless of the sleep-between-reads value, as there is no guarantee all architecture-specific implementations of udelay() handle this. Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Acked-by: Arnd Bergmann <arnd@arndb.de> Reviewed-by: Tony Lindgren <tony@atomide.com> Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org> Link: https://lore.kernel.org/r/45c87bec3397fdd704376807f0eec5cc71be440f.1685692810.git.geert+renesas@glider.be
Diffstat (limited to 'Documentation/driver-api/ioctl.rst')
0 files changed, 0 insertions, 0 deletions