From: Christoph Hellwig <hch@infradead.org>
To: Anson Jacob <Anson.Jacob@amd.com>
Cc: Bhawanpreet.Lakha@amd.com,
Harry Wentland <harry.wentland@amd.com>,
Sunpeng.Li@amd.com, qingqing.zhuo@amd.com,
Rodrigo.Siqueira@amd.com, linux-kernel@vger.kernel.org,
amd-gfx@lists.freedesktop.org, roman.li@amd.com,
Christoph Hellwig <hch@infradead.org>,
Aurabindo.Pillai@amd.com, paulus@samba.org,
linuxppc-dev@lists.ozlabs.org,
Christian K??nig <christian.koenig@amd.com>,
bindu.r@amd.com
Subject: Re: [RFC v2 1/2] ppc/fpu: Add generic FPU api similar to x86
Date: Wed, 21 Jul 2021 07:58:10 +0100 [thread overview]
Message-ID: <YPfFgkD+kcRaH8Ow@infradead.org> (raw)
In-Reply-To: <20210721044801.840501-2-Anson.Jacob@amd.com>
> +
> +/*
> + * Use kernel_fpu_begin/end() if you intend to use FPU in kernel context. It
> + * disables preemption so be careful if you intend to use it for long periods
> + * of time.
> + * TODO: If you intend to use the FPU in irq/softirq you need to check first with
> + * irq_fpu_usable() if it is possible.
Please avoid the overly lone lines comments.
> +extern bool kernel_fpu_enabled(void);
> +extern void kernel_fpu_begin(void);
> +extern void kernel_fpu_end(void);
No need for the externs.
> +/*
> + * Track whether the kernel is using the FPU state
> + * currently.
This all fits on a single line.
> +static bool fpu_support(void)
> +{
> + if (cpu_has_feature(CPU_FTR_VSX_COMP)) {
> + return true;
> + } else if (cpu_has_feature(CPU_FTR_ALTIVEC_COMP)) {
> + return true;
> + } else if (!cpu_has_feature(CPU_FTR_FPU_UNAVAILABLE)) {
> + return true;
> + }
No need for the braces, or else after a return. In fact this could
be simplified down to:
return cpu_has_feature(CPU_FTR_VSX_COMP) ||
cpu_has_feature(CPU_FTR_ALTIVEC_COMP) ||
cpu_has_feature(CPU_FTR_FPU_UNAVAILABLE));
> + preempt_disable();
> +
> +#ifdef CONFIG_VSX
> + if (cpu_has_feature(CPU_FTR_VSX_COMP)) {
> + enable_kernel_vsx();
> + return;
> + }
> +#endif
> +
> +#ifdef CONFIG_ALTIVEC
> + if (cpu_has_feature(CPU_FTR_ALTIVEC_COMP)) {
> + enable_kernel_altivec();
> + return;
> + }
> +#endif
> +
> +#ifdef CONFIG_PPC_FPU
> + if (!cpu_has_feature(CPU_FTR_FPU_UNAVAILABLE)) {
> + enable_kernel_fp();
> + return;
> + }
> +#endif
All the features are defined away if not supported (and we already rely
on that in fpu_support()). So this could become:
if (cpu_has_feature(CPU_FTR_VSX_COMP))
enable_kernel_vsx();
else if (cpu_has_feature(CPU_FTR_ALTIVEC_COMP))
enable_kernel_altivec();
else if (!cpu_has_feature(CPU_FTR_FPU_UNAVAILABLE))
enable_kernel_fp();
Same for the disable path.
next prev parent reply other threads:[~2021-07-21 6:59 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-21 4:47 [RFC v2 0/2] PPC: Add generic FPU api similar to x86 Anson Jacob
2021-07-21 4:48 ` [RFC v2 1/2] ppc/fpu: " Anson Jacob
2021-07-21 6:58 ` Christoph Hellwig [this message]
2021-07-21 4:48 ` [RFC v2 2/2] drm/amd/display: Use PPC FPU functions Anson Jacob
2021-07-21 6:29 ` Christian König
2021-07-21 6:51 ` Christoph Hellwig
2021-07-21 9:24 ` Christian König
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=YPfFgkD+kcRaH8Ow@infradead.org \
--to=hch@infradead.org \
--cc=Anson.Jacob@amd.com \
--cc=Aurabindo.Pillai@amd.com \
--cc=Bhawanpreet.Lakha@amd.com \
--cc=Rodrigo.Siqueira@amd.com \
--cc=Sunpeng.Li@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=bindu.r@amd.com \
--cc=christian.koenig@amd.com \
--cc=harry.wentland@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=paulus@samba.org \
--cc=qingqing.zhuo@amd.com \
--cc=roman.li@amd.com \
/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;
as well as URLs for NNTP newsgroup(s).