-
Notifications
You must be signed in to change notification settings - Fork 7.3k
soc: mps2_an385: Added support for MPU #7035
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
soc: mps2_an385: Added support for MPU #7035
Conversation
Codecov Report
@@ Coverage Diff @@
## master #7035 +/- ##
======================================
Coverage 52.5% 52.5%
======================================
Files 213 213
Lines 26140 26140
Branches 5634 5634
======================================
Hits 13726 13726
Misses 10159 10159
Partials 2255 2255 Continue to review full report at Codecov.
|
arch/arm/core/cortex_m/mpu/arm_mpu.c
Outdated
@@ -43,6 +43,13 @@ static inline u32_t _size_to_mpu_rasr_size(u32_t size) | |||
return REGION_32B; | |||
} | |||
|
|||
#ifdef CONFIG_SOC_SERIES_MPS2 |
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.
This is because of QEMU, not the actual hardware for MPS2_AN385
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.
Could we perhaps make this a Kconfig instead? And set to 1024 in the qemu_cortex_m3 defconfig
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.
How can I inform the build system that I am using qemu rather than a real hardware.
Is that I need to create a new board for this, say qemu_mps2_an385?
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.
no, just change qemu_cortex_m3 to use this SOC definition instead of the other one.
And then ifdef this based on BOARD=qemu_cortex_m3
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.
This causes build failures on all Bluetooth related tests/samples. This change would be backward incompatible.
So another solution may be something like BOARD=qemu_cortex_m3_mpu
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.
The various places that test against SOC_SERIES_MPS2 aren't correct, the actual hw is fine, its QEMU that has the 1k limitation.
arch/arm/core/cortex_m/mpu/arm_mpu.c
Outdated
@@ -43,6 +43,13 @@ static inline u32_t _size_to_mpu_rasr_size(u32_t size) | |||
return REGION_32B; | |||
} | |||
|
|||
#ifdef CONFIG_SOC_SERIES_MPS2 |
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.
Could we perhaps make this a Kconfig instead? And set to 1024 in the qemu_cortex_m3 defconfig
#userspace | ||
CONFIG_ARCH_HAS_USERSPACE=y | ||
CONFIG_ARM_MPU=y | ||
CONFIG_MAIN_STACK_SIZE=2048 |
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.
Why do we need to override the main/idle/privileged stack size from defaults?
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.
Qemu cant handle stacks lesser than 1024. This will be a region i need to congfigure in the MPU and the qemu has a 1k limitation.
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.
then why aren't you changing this in qemu_cortex_m3 board definition?
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.
These stack size changes need to be moved out of the mps2_an385 configuration, I can't merge this since this is really something that affects QEMU and not the actual mps2_an385 board.
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.
@AdithyaBaglody you never addressed the comment above.
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.
oh I had actually addressed it before. Now after enabling the userspace(in the last 2days) this came back in.
will fix it. Thanks for catching this.
scripts/gen_alignment_script.py
Outdated
if bit_len: | ||
align_size = 1 << bit_len | ||
if "CONFIG_SOC_SERIES_MPS2" in syms and bit_len < 10: |
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.
yeah another hack here -- let's just pull this out of kconfig
@@ -324,7 +324,11 @@ static void pass_noperms_object(void) | |||
|
|||
__kernel struct k_thread kthread_thread; | |||
|
|||
#ifdef CONFIG_SOC_SERIES_MPS2 | |||
#define STACKSIZE 1024 |
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.
just make this 1024 for everyone IMO, 512 was selected at random IIRC and it's not like MPU-enabled devices have really tiny amounts of RAM
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.
i agree. i always wondered about that. If people want to minimize that stuff they can add pare it back down sub <1k.
69c8ba2
to
eafab3e
Compare
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.
Getting close, but a few changes still needed.
Any details on the bluetooth issues you are seeing?
#userspace | ||
CONFIG_ARCH_HAS_USERSPACE=y | ||
CONFIG_ARM_MPU=y | ||
CONFIG_MAIN_STACK_SIZE=2048 |
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.
These stack size changes need to be moved out of the mps2_an385 configuration, I can't merge this since this is really something that affects QEMU and not the actual mps2_an385 board.
scripts/gen_alignment_script.py
Outdated
else: | ||
align_size = 32 | ||
align_size = min_region_size |
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.
indentation is incorrect here.
#include <soc.h> | ||
#include <arch/arm/cortex_m/mpu/arm_mpu.h> | ||
|
||
#define FLASH_BASE_ADDRESS (0x00000000) |
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.
Why aren't these coming from DT?
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.
yes this should come from DTS
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.
we do not have a DTS file for mps2_an385. So currently this will be kept here until we have one.
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.
I'm going to defer to @galak on whether this is permissible.
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.
we do not have a DTS file for mps2_an385. So currently this will be kept here until we have one.
boards/arm/mps2_an385/mps2_an385.dts ???
eafab3e
to
ce81a11
Compare
4a2b732
to
b1ebc50
Compare
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.
Dependencies: QEMU version 2.12
This should NOT be dependent on QEMU 2.12.
Separate out any work in QEMU 2.12 into another PR.
The mps3_an385 is a real piece of hardware with a working MPU.
Issues with QEMU are separate and need to be dealt with separately.
#userspace | ||
CONFIG_MAIN_STACK_SIZE=2048 | ||
CONFIG_IDLE_STACK_SIZE=1024 | ||
CONFIG_PRIVILEGED_STACK_SIZE=1024 |
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.
this is unacceptable, you are hacking the stack sizes because of QEMU limitations and not the mps2_am385
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.
we have quite a lot of memory on the actual board. So if someone wants to run it on qemu he shouldn't face the issue i did when i started out.
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.
No, do not change the configuration for the real mps2_an385 board. This belongs in the qemu_cortex_m3 defconfig once it is updated to use the MPU.
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.
ditto
@@ -10,7 +10,7 @@ | |||
#include <misc/printk.h> | |||
|
|||
/* size of stack area used by each thread */ | |||
#define STACKSIZE 1024 | |||
#define STACKSIZE CONFIG_MAIN_STACK_SIZE |
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.
why is this changed? this has the effect of making the stack size smaller on other boards.
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.
This is one of the smiplest ways to get it to work on qemu. this sample needs 2k of stack and i didn't want to do a #if def CONFIG_BOARD_QEMU_m3. Maybe i will end up doing just that.
@@ -1,5 +1,6 @@ | |||
tests: | |||
benchmark.kernel: | |||
arch_exclude: nios2 riscv32 xtensa | |||
platform_exclude: qemu_cortex_m3 |
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.
why is this removed?
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.
the prj.conf streches the time between timer interrupts. This on qemu will overflow the counter.
And what is the point in running a benchmark on an emulation platform?
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.
the prj.conf streches the time between timer interrupts. This on qemu will overflow the counter
Why is this not a problem on any of our other emulated platforms?
And what is the point in running a benchmark on an emulation platform?
Because the test still reports success or failure, and sanitycheck only runs on emulated platforms. If there is some functional issue that causes this test to crash we need to know about it.
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.
Why is this not a problem on any of our other emulated platforms?
In arm we have only 24 bits to represent the count value. This maybe one reason. The other the clock speed on other platforms might be lesser. So it ends up streaching the timer Interrupts according to the prj.conf.
Because the test still reports success or failure, and sanitycheck only runs on emulated platforms. If there is some functional issue that causes this test to crash we need to know about it.
As mentioned above, this is to do with the timer interrupts. One workaround would be to create a new prj.conf for qemu_cortex_m3.
#include <soc.h> | ||
#include <arch/arm/cortex_m/mpu/arm_mpu.h> | ||
|
||
#define FLASH_BASE_ADDRESS (0x00000000) |
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.
yes this should come from DTS
15ba70d
to
74befe7
Compare
@andrewboie That description was a old one. I have already split the PR |
74befe7
to
9beba80
Compare
samples/philosophers/src/main.c
Outdated
@@ -83,7 +83,7 @@ | |||
/* end - control behaviour of the demo */ | |||
/***************************************/ | |||
|
|||
#define STACK_SIZE 768 | |||
#define STACK_SIZE 1024 |
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.
I'm trying to understand something here.
IIRC, On ARM, the guard region for stacks is taken from the existing stack size. It is not added like on x86.
Wouldn't a stack size of 1024 be entirely consumed by the guard area, leaving no room for the actual stack buffer?
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.
yes. if the MPU guard is enabled it will consume 1K out of the stack size.
but I want to create a warning that will inform the users of this limitation when we refactor qemu_cortex_m3.
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.
You lost me.
If 1K is taken out of the stack, and we only have 1K for STACK_SIZE, how does this work??
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.
MPU Stack guard is not enabled by default. Hence this works.
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.
MPU stack guard is now enabled by default for tests.
We don't have the 1K limitation any more, correct?
bc79c66
to
31b15d1
Compare
@@ -3,3 +3,7 @@ tests: | |||
arch_exclude: nios2 riscv32 xtensa | |||
min_ram: 32 | |||
tags: benchmark | |||
benchmark.kernel.qemu_cortex_m3: |
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.
not sure how this is related to this PR.
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.
Some of these patches are need to keep the sanity when we move to the new QEMU.
So such patches need to be ready before we update the SDK with the new QEMU.
@@ -0,0 +1,8 @@ | |||
CONFIG_TEST=y |
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.
do not use number in file names, call it with something meaningful
31b15d1
to
82ae816
Compare
@AdithyaBaglody 2 tests are failing for me: tests/kernel/mem_pool/mem_pool_threadsafe/kernel.memory_pool |
0fff2c6
to
f3e6d2e
Compare
Anas can you please check with this rebase. I am not seeing this issue on my end. |
tests/kernel/mem_pool/mem_pool_threadsafe still fails, the syscalls one is probably expected to fault, we see this in other places. @dcpleung |
I ran sanitycheck with QEMU 3.0.0 couple times in a row. Every time it fails of different set of tests. Maybe it's a QEMU issue? |
i am running qemu from head, so post 3.0.0 |
I grabbed QEMU from git this morning (v3.0.0-614-g19b599f766), and it still gave me different set of failures between sanitycheck runs. Some of them are related to timers (e.g. too many ticks elapsed waiting for a task). However, I got a few USAGE FAULTs complaining about illegal use of EPSR and a few BUS FAULTS also. |
So if you want to run it on qemu. you need to add the following to the defconfig After adding these changes on the latest qemu and it is working fine. |
3aab0b3
to
aa839c2
Compare
@AdithyaBaglody this now only failed on one test: samples/basic/userspace/shared_mem
|
aa839c2
to
f6f4f8b
Compare
@@ -0,0 +1,8 @@ | |||
CONFIG_TEST=y |
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.
Please remove this patch from this PR, not related to mps2_an385
tags: benchmark qemu_cortex_m3 |
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.
remove this change to this file, not sure why we have qemu_cortex_m3 in the tags
Increasing the stack size to 1024. Signed-off-by: Adithya Baglody <[email protected]>
Added required files/support for the MPU in MPS2-AN358 (Cortex-M3). Signed-off-by: Adithya Baglody <[email protected]> Signed-off-by: Anas Nashif <[email protected]>
The code assumes that when the systick counter hits zero, the timer interrupt will be taken before the loop can read the LOAD/VAL registers, but this is not architecturally guaranteed, and so the code can see a post-reload SysTick->VAL and a pre-reload clock_accumulated_count, which causes it to return an incorrectly small cycle count. By adding a ISB we overcome this issue. Signed-off-by: Adithya Baglody <[email protected]>
This patch will enable the MPU in MPS2_AN385 soc. Signed-off-by: Adithya Baglody <[email protected]> Signed-off-by: Anas Nashif <[email protected]>
This patch will enable the userspace. Signed-off-by: Adithya Baglody <[email protected]>
Now the stack size is a function of CONFIG_TEST_EXTRA_STACKSIZE. Signed-off-by: Adithya Baglody <[email protected]>
This patch updates the alignment for the memory domain partitions. Also update the stack size for qemu_cortex_m3. Signed-off-by: Adithya Baglody <[email protected]>
The test case was supposed to access the privileged stack area but instead it was accessing the stack guard region. Signed-off-by: Adithya Baglody <[email protected]>
The total number of loops being executed were taking far too long to finish executing the test case. This was causing the timer handler to execute in the middle of the test case. Thereby causing a test case failure. Now the number of loops have been reduced and this will make sure the test case completes. This change has no effect on the time being calculated by the benchmark. Signed-off-by: Adithya Baglody <[email protected]>
The header should check if the macro _MPU_PRESENT is defined and create it only if not defined. Signed-off-by: Adithya Baglody <[email protected]>
f6f4f8b
to
33af085
Compare
Added MPU support for MPS2_AN385