-
Notifications
You must be signed in to change notification settings - Fork 3k
Fix greentea test failure on Renesas Cortex-A9 targets #7139
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
Conversation
cc @adbridge |
@toyowata I dont fully understand what is this fixing - the commit msg does not specify why dummy needs volatile and how it fails currently. Please add more details for the bugfix
This would be good to have it in there |
mbed-os/cmsis/TARGET_CORTEX_A/cmsis_armcc.h Line 455 in 4fcaa56
So the following block gets optimized out : mbed-os/cmsis/TARGET_CORTEX_A/core_ca.h Lines 976 to 985 in 4fcaa56
All (most ?) functions from mbed-os/cmsis/TARGET_CORTEX_A/cmsis_cp15.h Lines 444 to 445 in 4fcaa56
writing the following also fixes the issue and probably fixes all other uses of CP. #define __set_CP(cp, op1, Rt, CRn, CRm, op2) do { register volatile uint32_t tmp __ASM("cp" # cp ":" # op1 ":c" # CRn ":c" # CRm ":" # op2); tmp = (Rt); } while(0) (note the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
functions in cmsis_cp15.h
expect __get_CP
and __set_CP
to expand as __ASM volatile
.
it should be added to these functions instead of the Dummy
variable.
@JonatanAntoni this one needs your attention :) |
Add volatile modifier to prevent ARM compiler to remove inline function calls for __set_CP and __get_CP.
Squashed the commits. |
We have the __ASM volatile for all other compilers as well, so it looks correct to me at the first glance. May I ask you to upstream this change to CMSIS, please? Note that we have the volatile modifier after the __ASM, typically. Just to clearly state its the assembly instruction and not the variable in this case. |
As discussed with @JonatanAntoni, the syntax in c37875c is right one for armcc. |
@JonatanAntoni @ithinuel @ithinuel Can you review this and accept the commit, because this is a blocker for Renesas Cortex-A platforms? |
@0xc0170 bump |
It is actually the variable being marked volatile, and that's giving you the semantics. It's not eliminating the read because the variable you're reading is volatile. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While it's logical that these register variables mapped to coprocessor controls should be declared volatile, the ARMCC documentation examples show similar use without volatile
, implying it shouldn't be necessary - as if they were implicitly volatile. Is the documentation wrong/misleading?
@kjbracey-arm that's exactly what I have in mind as well. The compiler already knows that this variable is intended to access a register which is volatile by nature. I try to get a confirmation from the compiler team. |
Not all hard registers necessarily have side-effects. The same mechanism can be used to access many different types of register. So I can perfectly understand the logic of leaving But the examples suggest that's not what they were intending:
Anyway, |
Sure, but typically they have. That's what they are normally used for. And that's the big difference to ordinary memory. But of course adding |
@JonatanAntoni @kjbracey-arm I was reading gcc's doc on In the PR made against CMSIS_5, I only added the volatile to the write instruction because we want to tell the compiler not to optimise write to this. |
I think having default volatile in the CP macro for both set/get is safest. Avoids potential mistakes. And I can't see any CP15 use being in performance critical places where volatile would hurt. I see the compiler writer's point of view about not volatile by default, but a CP15 helper macro should include the volatiles. I'm not aware of any CP15 registers that are read-sensitive, but maybe sequencing of the read relative to other accesses might be significant. |
Can you please let me know at which level of optimization you observe the issues? We have named registers without volatile in many other places. I expect issues all around. Surprising that nobody raised issues so far. |
Checked with :
looking for the missing inner loop. |
Thx. I confirm it's reproducible with CMSIS CoreValidation tests. Unfortunately we currently run all the tests with -O0, only. |
@ithinuel @kjbracey-arm What do we run in which we compile to -O3? |
@cmonr we compile everything with
|
/morph build |
Build : SUCCESSBuild number : 2333 Triggering tests/morph test |
Exporter Build : SUCCESSBuild number : 1955 |
Test : SUCCESSBuild number : 2113 |
ARM-software/CMSIS_5#376 has been merged upstream too. |
Description
This fix is to prevent optimization code removal (only ARM build) for Renesas Cortex-A9 targets (GR-PEACH and GR-LYCHEE).
The problem
was accidentally introducedpotentially existed and was surfaced with this PR #6273d8cb72a#diff-bf05db1901365d4d793784baf718227eR953
The ARM compiler removed
__set_CP
inlined functions (__set_DCISW
,__set_DCCSW
and__set_DCCISW
) by optimization and target startup in theSystemInit()
does not work properly. i.e. just hangs at startupThis fix prevents unnecessary compiler optimization and startup code initialize cache memory as expected.
You can see codegen difference by armcc here.
codegen_diff.txt
It should fix #7065 and ARMmbed/mbed-os-example-blinky#124
Pull request type
Test result
mbed-test_gr_lychee_arm.txt
mbed-test_rz_a1h_arm.txt