Skip to content

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

Merged
merged 10 commits into from
Sep 21, 2018

Conversation

AdithyaBaglody
Copy link
Contributor

@AdithyaBaglody AdithyaBaglody commented Apr 12, 2018

Added MPU support for MPS2_AN385

@codecov-io
Copy link

codecov-io commented Apr 12, 2018

Codecov Report

Merging #7035 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@          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.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a013ce3...33af085. Read the comment docs.

@carlescufi carlescufi requested a review from ioannisg April 12, 2018 10:42
@@ -43,6 +43,13 @@ static inline u32_t _size_to_mpu_rasr_size(u32_t size)
return REGION_32B;
}

#ifdef CONFIG_SOC_SERIES_MPS2
Copy link
Collaborator

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

Copy link
Contributor

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

Copy link
Contributor Author

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?

Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Collaborator

@galak galak left a 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.

@@ -43,6 +43,13 @@ static inline u32_t _size_to_mpu_rasr_size(u32_t size)
return REGION_32B;
}

#ifdef CONFIG_SOC_SERIES_MPS2
Copy link
Contributor

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
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

if bit_len:
align_size = 1 << bit_len
if "CONFIG_SOC_SERIES_MPS2" in syms and bit_len < 10:
Copy link
Contributor

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
Copy link
Contributor

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

Copy link
Collaborator

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.

Copy link
Contributor

@andrewboie andrewboie left a 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
Copy link
Contributor

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.

else:
align_size = 32
align_size = min_region_size
Copy link
Contributor

Choose a reason for hiding this comment

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

indentation is incorrect here.

galak
galak previously requested changes Apr 26, 2018
#include <soc.h>
#include <arch/arm/cortex_m/mpu/arm_mpu.h>

#define FLASH_BASE_ADDRESS (0x00000000)
Copy link
Collaborator

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?

Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Member

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 ???

Copy link
Contributor

@andrewboie andrewboie left a 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
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Member

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
Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this removed?

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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)
Copy link
Contributor

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

@AdithyaBaglody
Copy link
Contributor Author

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.

@andrewboie That description was a old one. I have already split the PR

@@ -83,7 +83,7 @@
/* end - control behaviour of the demo */
/***************************************/

#define STACK_SIZE 768
#define STACK_SIZE 1024
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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??

Copy link
Contributor Author

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.

Copy link
Contributor

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?

@AdithyaBaglody AdithyaBaglody force-pushed the qemu_cortex_mpu branch 3 times, most recently from bc79c66 to 31b15d1 Compare May 10, 2018 08:25
@@ -3,3 +3,7 @@ tests:
arch_exclude: nios2 riscv32 xtensa
min_ram: 32
tags: benchmark
benchmark.kernel.qemu_cortex_m3:
Copy link
Member

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.

Copy link
Contributor Author

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
Copy link
Member

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

@nashif
Copy link
Member

nashif commented Aug 27, 2018

@AdithyaBaglody 2 tests are failing for me:

tests/kernel/mem_pool/mem_pool_threadsafe/kernel.memory_pool
and
tests/kernel/mem_protect/syscalls/kernel.memory_protection.syscalls

@AdithyaBaglody
Copy link
Contributor Author

@AdithyaBaglody 2 tests are failing for me:
tests/kernel/mem_pool/mem_pool_threadsafe/kernel.memory_pool
and
tests/kernel/mem_protect/syscalls/kernel.memory_protection.syscalls

Anas can you please check with this rebase. I am not seeing this issue on my end.

@nashif
Copy link
Member

nashif commented Aug 28, 2018

tests/kernel/mem_pool/mem_pool_threadsafe still fails, the syscalls one is probably expected to fault, we see this in other places. @dcpleung

@nashif nashif added this to the v1.14.0 milestone Aug 29, 2018
@dcpleung
Copy link
Member

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?

@nashif
Copy link
Member

nashif commented Aug 29, 2018

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

@AdithyaBaglody
Copy link
Contributor Author

@dcpleung You need to take the latest code i.e the repo head. Needed for MPU to work correctly.
@nashif I am using a qemu that is 1/2 week old. There it seems to work just fine. Let me check with the latest repo head.

@dcpleung
Copy link
Member

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.

@AdithyaBaglody
Copy link
Contributor Author

AdithyaBaglody commented Sep 10, 2018

So if you want to run it on qemu. you need to add the following to the defconfig
CONFIG_MAIN_STACK_SIZE=1024
CONFIG_IDLE_STACK_SIZE=1024
CONFIG_PRIVILEGED_STACK_SIZE=1024
CONFIG_TEST_EXTRA_STACKSIZE=1024

After adding these changes on the latest qemu and it is working fine.

@nashif nashif force-pushed the qemu_cortex_mpu branch 2 times, most recently from 3aab0b3 to aa839c2 Compare September 15, 2018 03:16
@nashif
Copy link
Member

nashif commented Sep 15, 2018

@AdithyaBaglody this now only failed on one test:

samples/basic/userspace/shared_mem

QEMU: ***** Booting Zephyr OS zephyr-v1.13.0-146-gaa839c2245 *****
QEMU: init partitions complete
QEMU: init app memory complete
QEMU: ENC Thread Created 200008b0
QEMU: init domain complete
QEMU: Partitions added to dom1
QEMU: dom1 Created
QEMU: PT Thread Created 20000a00
QEMU: dom0 Created
QEMU: CT Thread Created 20000974
QEMU: dom2 Created
QEMU: ***** MPU FAULT *****
QEMU: Data Access Violation
QEMU: MMFAR Address: 0x200000a0
QEMU: ***** Hardware exception *****
QEMU: Current thread ID = 0x200008b0
QEMU: Faulting instruction address = 0x4f6
QEMU: Fatal fault in thread 0x200008b0! Aborting.
QEMU: ENC thread started
QEMU: PT thread started
QEMU complete (timeout) after 60.059631 seconds
MAKE: 'sanity_test_finished mps2_an385/samples/basic/userspace/shared_mem/kernel.memory_protection.userspace'

@AdithyaBaglody
Copy link
Contributor Author

@nashif this was not a problem on qemu. It seems like it caught an issue which was unnoticed till now.
Created a PR for the solution #10087

@@ -0,0 +1,8 @@
CONFIG_TEST=y
Copy link
Member

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
Copy link
Member

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]>
@nashif nashif merged commit 31c8817 into zephyrproject-rtos:master Sep 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants