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

arch/rv32i: Reduce PMP stack usage #2020

Merged
merged 1 commit into from Jul 17, 2020

Conversation

alistair23
Copy link
Contributor

Pull Request Overview

This is the first step to reducing the stack usage from the PMP config structs.

Before this patch the stack usage was:

720     _ZN68_$LT$rv32i..pmp..PMPConfig$u20$as$u20$kernel..platform..mpu..MPU$GT$13configure_mpu17h5967285bd6ec5881E

After this patch it is now:

592     _ZN68_$LT$rv32i..pmp..PMPConfig$u20$as$u20$kernel..platform..mpu..MPU$GT$13configure_mpu17h5967285bd6ec5881E

The configure_mpu() function is still the second highest user of the
stack (after reset_handler()) but this is an improvement.

This is a step to help fix: #2016

Testing Strategy

None.

TODO or Help Wanted

Documentation Updated

  • Updated the relevant files in /docs, or no updates are required.

Formatting

  • Ran make prepush.

This is the first step to reducing the stack usage from the PMP config structs.

Before this patch the stack usage was:

    720     _ZN68_$LT$rv32i..pmp..PMPConfig$u20$as$u20$kernel..platform..mpu..MPU$GT$13configure_mpu17h5967285bd6ec5881E

After this patch it is now:

    592     _ZN68_$LT$rv32i..pmp..PMPConfig$u20$as$u20$kernel..platform..mpu..MPU$GT$13configure_mpu17h5967285bd6ec5881E

The configure_mpu() function is still the second highest user of the
stack (after reset_handler()) but this is an improvement.

This is a step to help fix: tock#2016

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
@bradjc bradjc added risc-v RISC-V architecture last-call Final review period for a pull request. labels Jul 16, 2020
alistair23 added a commit to alistair23/tock that referenced this pull request Jul 17, 2020
Previously we would sort the PMP regions everytime we configured the
MPU. This was wasteful in terms of instructions but also wasted stack
space, probably because we cloned the PMPConfig regions.

This patch changes the sorting to only happen after a change is made to
the regions. This should save the number of times we have to sort,
remove sorting out of the critical path and saves a lot of stack space.

See below for the stack changes:

    ### Release build ###
    ## Before this patch ##
    80     _ZN68_$LT$rv32i..pmp..PMPConfig$u20$as$u20$kernel..platform..mpu..MPU$GT$15allocate_region17hb3b05a589563feedE
    0     _ZN68_$LT$rv32i..pmp..PMPConfig$u20$as$u20$kernel..platform..mpu..MPU$GT$24update_app_memory_region17hd6078caa7928d4d8E
    592     _ZN68_$LT$rv32i..pmp..PMPConfig$u20$as$u20$kernel..platform..mpu..MPU$GT$13configure_mpu17h5967285bd6ec5881E

    ## After this patch ##
    80     _ZN68_$LT$rv32i..pmp..PMPConfig$u20$as$u20$kernel..platform..mpu..MPU$GT$15allocate_region17hb3b05a589563feedE
    16     _ZN68_$LT$rv32i..pmp..PMPConfig$u20$as$u20$kernel..platform..mpu..MPU$GT$24update_app_memory_region17hd6078caa7928d4d8E
    80     _ZN68_$LT$rv32i..pmp..PMPConfig$u20$as$u20$kernel..platform..mpu..MPU$GT$13configure_mpu17h5967285bd6ec5881E

    ### Debug build ###
    ## Before this patch ##
    80     _ZN68_$LT$rv32i..pmp..PMPConfig$u20$as$u20$kernel..platform..mpu..MPU$GT$15allocate_region17h272c094b5b64d63bE
    96     _ZN68_$LT$rv32i..pmp..PMPConfig$u20$as$u20$kernel..platform..mpu..MPU$GT$26allocate_app_memory_region17h56b3decc4c649f8cE
    32     _ZN68_$LT$rv32i..pmp..PMPConfig$u20$as$u20$kernel..platform..mpu..MPU$GT$24update_app_memory_region17h55a48db93ba6d713E
    592     _ZN68_$LT$rv32i..pmp..PMPConfig$u20$as$u20$kernel..platform..mpu..MPU$GT$13configure_mpu17h32d25c65ffe73910E

    ## After this patch ##
    80     _ZN68_$LT$rv32i..pmp..PMPConfig$u20$as$u20$kernel..platform..mpu..MPU$GT$15allocate_region17h272c094b5b64d63bE
    96     _ZN68_$LT$rv32i..pmp..PMPConfig$u20$as$u20$kernel..platform..mpu..MPU$GT$26allocate_app_memory_region17h56b3decc4c649f8cE
    32     _ZN68_$LT$rv32i..pmp..PMPConfig$u20$as$u20$kernel..platform..mpu..MPU$GT$24update_app_memory_region17h55a48db93ba6d713E
    80     _ZN68_$LT$rv32i..pmp..PMPConfig$u20$as$u20$kernel..platform..mpu..MPU$GT$13configure_mpu17h32d25c65ffe73910E

NOTE: All above numbers already include: tock#2020

I haven't compared instruction diffs, but I'm assuming we reduce the
number of instructions run on app swap as well.

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
@bradjc
Copy link
Contributor

bradjc commented Jul 17, 2020

bors r+

@bors bors bot merged commit ce30c9d into tock:master Jul 17, 2020
@alistair23 alistair23 deleted the alistair/stack-usage-shrink branch July 17, 2020 18:00
bors bot added a commit that referenced this pull request Jul 20, 2020
2021: arch/rv32i: Don't sort PMP regions when we configure the MPU r=ppannuto a=alistair23

### Pull Request Overview

Previously we would sort the PMP regions everytime we configured the
MPU. This was wasteful in terms of instructions but also wasted stack
space, probably because we cloned the PMPConfig regions.

This patch changes the sorting to only happen after a change is made to
the regions. This should save the number of times we have to sort,
remove sorting out of the critical path and saves a lot of stack space.

See below for the stack changes:

    ### Release build ###
    ## Before this patch ##
    80     _ZN68_$LT$rv32i..pmp..PMPConfig$u20$as$u20$kernel..platform..mpu..MPU$GT$15allocate_region17hb3b05a589563feedE
    0     _ZN68_$LT$rv32i..pmp..PMPConfig$u20$as$u20$kernel..platform..mpu..MPU$GT$24update_app_memory_region17hd6078caa7928d4d8E
    592     _ZN68_$LT$rv32i..pmp..PMPConfig$u20$as$u20$kernel..platform..mpu..MPU$GT$13configure_mpu17h5967285bd6ec5881E

    ## After this patch ##
    80     _ZN68_$LT$rv32i..pmp..PMPConfig$u20$as$u20$kernel..platform..mpu..MPU$GT$15allocate_region17hb3b05a589563feedE
    16     _ZN68_$LT$rv32i..pmp..PMPConfig$u20$as$u20$kernel..platform..mpu..MPU$GT$24update_app_memory_region17hd6078caa7928d4d8E
    80     _ZN68_$LT$rv32i..pmp..PMPConfig$u20$as$u20$kernel..platform..mpu..MPU$GT$13configure_mpu17h5967285bd6ec5881E

    ### Debug build ###
    ## Before this patch ##
    80     _ZN68_$LT$rv32i..pmp..PMPConfig$u20$as$u20$kernel..platform..mpu..MPU$GT$15allocate_region17h272c094b5b64d63bE
    96     _ZN68_$LT$rv32i..pmp..PMPConfig$u20$as$u20$kernel..platform..mpu..MPU$GT$26allocate_app_memory_region17h56b3decc4c649f8cE
    32     _ZN68_$LT$rv32i..pmp..PMPConfig$u20$as$u20$kernel..platform..mpu..MPU$GT$24update_app_memory_region17h55a48db93ba6d713E
    592     _ZN68_$LT$rv32i..pmp..PMPConfig$u20$as$u20$kernel..platform..mpu..MPU$GT$13configure_mpu17h32d25c65ffe73910E

    ## After this patch ##
    80     _ZN68_$LT$rv32i..pmp..PMPConfig$u20$as$u20$kernel..platform..mpu..MPU$GT$15allocate_region17h272c094b5b64d63bE
    96     _ZN68_$LT$rv32i..pmp..PMPConfig$u20$as$u20$kernel..platform..mpu..MPU$GT$26allocate_app_memory_region17h56b3decc4c649f8cE
    32     _ZN68_$LT$rv32i..pmp..PMPConfig$u20$as$u20$kernel..platform..mpu..MPU$GT$24update_app_memory_region17h55a48db93ba6d713E
    80     _ZN68_$LT$rv32i..pmp..PMPConfig$u20$as$u20$kernel..platform..mpu..MPU$GT$13configure_mpu17h32d25c65ffe73910E

NOTE: All above numbers already include: #2020

I haven't compared instruction diffs, but I'm assuming we reduce the
number of instructions run on app swap as well.

### Testing Strategy

Tested running apps on QEMU OpenTitan.

### TODO or Help Wanted

### Documentation Updated

- [X] Updated the relevant files in `/docs`, or no updates are required.

### Formatting

- [X] Ran `make prepush`.


Co-authored-by: Alistair Francis <alistair.francis@wdc.com>
hudson-ayers pushed a commit that referenced this pull request Mar 7, 2022
Previously we would sort the PMP regions everytime we configured the
MPU. This was wasteful in terms of instructions but also wasted stack
space, probably because we cloned the PMPConfig regions.

This patch changes the sorting to only happen after a change is made to
the regions. This should save the number of times we have to sort,
remove sorting out of the critical path and saves a lot of stack space.

See below for the stack changes:

    ### Release build ###
    ## Before this patch ##
    80     _ZN68_$LT$rv32i..pmp..PMPConfig$u20$as$u20$kernel..platform..mpu..MPU$GT$15allocate_region17hb3b05a589563feedE
    0     _ZN68_$LT$rv32i..pmp..PMPConfig$u20$as$u20$kernel..platform..mpu..MPU$GT$24update_app_memory_region17hd6078caa7928d4d8E
    592     _ZN68_$LT$rv32i..pmp..PMPConfig$u20$as$u20$kernel..platform..mpu..MPU$GT$13configure_mpu17h5967285bd6ec5881E

    ## After this patch ##
    80     _ZN68_$LT$rv32i..pmp..PMPConfig$u20$as$u20$kernel..platform..mpu..MPU$GT$15allocate_region17hb3b05a589563feedE
    16     _ZN68_$LT$rv32i..pmp..PMPConfig$u20$as$u20$kernel..platform..mpu..MPU$GT$24update_app_memory_region17hd6078caa7928d4d8E
    80     _ZN68_$LT$rv32i..pmp..PMPConfig$u20$as$u20$kernel..platform..mpu..MPU$GT$13configure_mpu17h5967285bd6ec5881E

    ### Debug build ###
    ## Before this patch ##
    80     _ZN68_$LT$rv32i..pmp..PMPConfig$u20$as$u20$kernel..platform..mpu..MPU$GT$15allocate_region17h272c094b5b64d63bE
    96     _ZN68_$LT$rv32i..pmp..PMPConfig$u20$as$u20$kernel..platform..mpu..MPU$GT$26allocate_app_memory_region17h56b3decc4c649f8cE
    32     _ZN68_$LT$rv32i..pmp..PMPConfig$u20$as$u20$kernel..platform..mpu..MPU$GT$24update_app_memory_region17h55a48db93ba6d713E
    592     _ZN68_$LT$rv32i..pmp..PMPConfig$u20$as$u20$kernel..platform..mpu..MPU$GT$13configure_mpu17h32d25c65ffe73910E

    ## After this patch ##
    80     _ZN68_$LT$rv32i..pmp..PMPConfig$u20$as$u20$kernel..platform..mpu..MPU$GT$15allocate_region17h272c094b5b64d63bE
    96     _ZN68_$LT$rv32i..pmp..PMPConfig$u20$as$u20$kernel..platform..mpu..MPU$GT$26allocate_app_memory_region17h56b3decc4c649f8cE
    32     _ZN68_$LT$rv32i..pmp..PMPConfig$u20$as$u20$kernel..platform..mpu..MPU$GT$24update_app_memory_region17h55a48db93ba6d713E
    80     _ZN68_$LT$rv32i..pmp..PMPConfig$u20$as$u20$kernel..platform..mpu..MPU$GT$13configure_mpu17h32d25c65ffe73910E

NOTE: All above numbers already include: #2020

I haven't compared instruction diffs, but I'm assuming we reduce the
number of instructions run on app swap as well.

BUG=none
TEST=make

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
(cherry picked from commit bed1b92)
Change-Id: I78a1a37d6d693e8399ba28f7610682ce2e9d0b26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
last-call Final review period for a pull request. risc-v RISC-V architecture
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants