Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kernel: arch: introduce k_float_enable() #31816

Merged
merged 2 commits into from
Mar 25, 2021

Conversation

katsuster
Copy link
Member

This patch introduce new API to enable FPU of thread. This is pair of
existed k_float_disable() API. And also add empty arch_float_enable()
into each architectures that have arch_float_disable(). The arc and
riscv already implemented arch_float_enable() so I do not touch
these implementations.

Motivation: Current Zephyr implementation does not allow to use FPU
on main and other system threads like as work queue. Users need to
create an other thread with K_FP_REGS for floating point programs.
Users can use FPU more easily if they can enable FPU on running
threads.

@katsuster katsuster requested review from ioannisg and a user February 1, 2021 06:34
@github-actions github-actions bot added area: API Changes to public APIs area: ARC ARC Architecture area: ARM ARM (32-bit) Architecture area: Kernel area: X86 x86 Architecture (32-bit) labels Feb 1, 2021
@katsuster
Copy link
Member Author

checkpatch got angry if I used ENOSYS in arch_float_enalbe() stub functions...

Copy link
Member

@ioannisg ioannisg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to be in the right direction.

*
* The function is used to enable the preservation of floating
* point context information for a particular thread.
*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add some text, also, here, that this API is optional , and depends on the architecture.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added such text.

@ioannisg ioannisg added this to the v2.6.0 milestone Feb 1, 2021
@zephyrbot zephyrbot added area: RISCV RISCV Architecture (32-bit & 64-bit) area: SPARC SPARC Architecture labels Feb 1, 2021
@zephyrbot zephyrbot requested review from carlocaione, ceolin, evgeniy-paltsev and IRISZZW and removed request for aasthagr, jenmwms and a user February 1, 2021 21:34
@katsuster
Copy link
Member Author

Conflicting k_float_enable() on x86 platform... I will check.

@katsuster
Copy link
Member Author

katsuster commented Feb 12, 2021

Changes in v2.

  • x86/ia32: change k_float_enable() -> z_float_enable() and call it from arch_float_enable() same as arch_float_disable()
  • kernel: add "options" argument into k_float_enable()

@@ -179,7 +179,7 @@ static inline void FpCtxInit(struct k_thread *thread)
* The locking isn't really needed when the routine is called by a cooperative
* thread (since context switching can't occur), but it is harmless.
*/
void k_float_enable(struct k_thread *thread, unsigned int options)
void z_float_enable(struct k_thread *thread, unsigned int options)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renaming it to arch_float_enable() will get rid of the z_float_enable() redirection.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your review. Yes, right. This is to keep consistency with existed k_float_disable() implementation.
If change such k_float_*() redirection of x86, it's better to change in an other commit (or PR ?).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine to update it in another PR.

@ioannisg
Copy link
Member

@katsuster pls, take a look at the compliance check failures

@katsuster
Copy link
Member Author

@ioannisg
Thanks for comments. It seems scripts/checkpatch.pl always warned if we use ENOSYS in the C code.
I think we can ignore this compliance check error at this time.

@pabigot
Copy link
Collaborator

pabigot commented Mar 22, 2021

Regarding -ENOSYS #29806 and particularly #23727 may be relevant.

I have no position on this PR nor on whether the checkpatch diagnostics on -ENOSYS should be removed. Zephyr has been moving (if not entirely consistently) away from blindly following Linux coding standards, so any solution should be considered.

@pabigot
Copy link
Collaborator

pabigot commented Mar 23, 2021

Based on the information provided in #23727 I believe the Zephyr standard solution would be to use -ENOTSUP instead of -ENOSYS for the return value, avoiding the checkpatch error which is useful as it identifies cases where the return value is not consistent with Zephyr standard. (The diagnostic message could be improved, though.)

@carlescufi
Copy link
Member

@katsuster we concluded that you should replace ENOSYS with ENOTSUP.
#23727 (comment)

@katsuster
Copy link
Member Author

@pabigot Thanks for describing about ENOSYS and ENOTSUP.
@carlescufi Thanks a lot. I understand. I will fix my patch.

@pabigot
Copy link
Collaborator

pabigot commented Mar 23, 2021

#33637 updates the checkpatch behavior.

This patch introduce new API to enable FPU of thread. This is pair of
existed k_float_disable() API. And also add empty arch_float_enable()
into each architectures that have arch_float_disable(). The arc and
riscv already implemented arch_float_enable() so I do not touch
these implementations.

Motivation: Current Zephyr implementation does not allow to use FPU
on main and other system threads like as work queue. Users need to
create an other thread with K_FP_REGS for floating point programs.
Users can use FPU more easily if they can enable FPU on running
threads.

Signed-off-by: Katsuhiro Suzuki <katsuhiro@katsuster.net>
This patch replaces ENOSYS into ENOTSUP to keep consistency with
the return value specification of k_float_enable().

Signed-off-by: Katsuhiro Suzuki <katsuhiro@katsuster.net>
@github-actions github-actions bot added the area: Tests Issues related to a particular existing or missing test label Mar 24, 2021
@nashif
Copy link
Member

nashif commented Mar 25, 2021

@ruuddw @evgeniy-paltsev @abrodkin please review for arc

@ruuddw
Copy link
Member

ruuddw commented Mar 25, 2021

@ruuddw @evgeniy-paltsev @abrodkin please review for arc

The PR said "The arc and riscv already implemented arch_float_enable() so I do not touch these implementations." so I didn't pay much attention, thanks for explicitly asking. I see an "option" parameter has been added (used by x86), that's fine.

@carlescufi carlescufi merged commit 19db485 into zephyrproject-rtos:master Mar 25, 2021
@katsuster katsuster deleted the fpu_enable branch March 25, 2021 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: API Changes to public APIs area: ARC ARC Architecture area: ARM ARM (32-bit) Architecture area: Kernel area: RISCV RISCV Architecture (32-bit & 64-bit) area: SPARC SPARC Architecture area: Tests Issues related to a particular existing or missing test area: X86 x86 Architecture (32-bit)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants