Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

bradjc
Copy link
Contributor

@bradjc bradjc commented Feb 12, 2021

Pull Request Overview

This pull request removes SuccessWithValue for 2.0. Other than IPC, nothing was using SuccessWithValue anymore.

Testing Strategy

travis

TODO or Help Wanted

Need the IPC updates first.

Documentation Updated

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

Formatting

  • Ran make prepush.

@bradjc bradjc added blocked Waiting on something, like a different PR or a dependency. tock-2.0 Issues and PRs related to Tock version 2.0. labels Feb 12, 2021
@bradjc bradjc mentioned this pull request Feb 12, 2021
23 tasks
@ppannuto ppannuto force-pushed the 2.0-no-successwithvalue branch from 645d2a4 to 5c3de11 Compare February 12, 2021 22:06
Copy link
Contributor

@hudson-ayers hudson-ayers left a comment

Choose a reason for hiding this comment

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

Looks good modulo the IPC change, of course

@@ -42,7 +40,6 @@ pub enum ReturnCode {
impl From<ReturnCode> for isize {
fn from(original: ReturnCode) -> isize {
match original {
ReturnCode::SuccessWithValue { value } => value as isize,
Copy link
Contributor

Choose a reason for hiding this comment

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

HURRAY!

@bradjc bradjc force-pushed the 2.0-no-successwithvalue branch from 5c3de11 to 2edf62d Compare February 17, 2021 19:56
@bradjc bradjc removed the blocked Waiting on something, like a different PR or a dependency. label Feb 17, 2021
@bradjc
Copy link
Contributor Author

bradjc commented Feb 17, 2021

Ok new plan...we leave SuccessWithValue but vow to never use it.

But seriously, this change seems to increase the imix kernel size by 4512 bytes.

Before:

make
   Compiling kernel v0.1.0 (/Users/bradjc/git/tock/kernel)
   Compiling cortexm v0.1.0 (/Users/bradjc/git/tock/arch/cortex-m)
   Compiling capsules v0.1.0 (/Users/bradjc/git/tock/capsules)
   Compiling cortexm4 v0.1.0 (/Users/bradjc/git/tock/arch/cortex-m4)
   Compiling sam4l v0.1.0 (/Users/bradjc/git/tock/chips/sam4l)
   Compiling components v0.1.0 (/Users/bradjc/git/tock/boards/components)
   Compiling imix v0.1.0 (/Users/bradjc/git/tock/boards/imix)
    Finished release [optimized + debuginfo] target(s) in 41.70s
   text	   data	    bss	    dec	    hex	filename
 188373	     64	  32704	 221141	  35fd5	/Users/bradjc/git/tock/target/thumbv7em-none-eabi/release/imix
dd516105645d93567b70c598c75fe2e2cb3d4de9b83817aa4f4b49bdbd88746e	/Users/bradjc/git/tock/target/thumbv7em-none-eabi/release/imix.bin

after

make
   Compiling imix v0.1.0 (/Users/bradjc/git/tock/boards/imix)
    Finished release [optimized + debuginfo] target(s) in 18.77s
   text	   data	    bss	    dec	    hex	filename
 192885	     64	  32704	 225653	  37175	/Users/bradjc/git/tock/target/thumbv7em-none-eabi/release/imix
3ba74f8fd1b72bdbb0c9dddf57609caf2ce8834b561b12eda0aebd07c589f592	/Users/bradjc/git/tock/target/thumbv7em-none-eabi/release/imix.bin

@bradjc
Copy link
Contributor Author

bradjc commented Feb 17, 2021

Just adding the SuccessWithValue enum value back "fixes" the issue and reduces the size relative to the 2.0 branch:

make
   Compiling kernel v0.1.0 (/Users/bradjc/git/tock/kernel)
   Compiling cortexm v0.1.0 (/Users/bradjc/git/tock/arch/cortex-m)
   Compiling capsules v0.1.0 (/Users/bradjc/git/tock/capsules)
   Compiling cortexm4 v0.1.0 (/Users/bradjc/git/tock/arch/cortex-m4)
   Compiling sam4l v0.1.0 (/Users/bradjc/git/tock/chips/sam4l)
   Compiling components v0.1.0 (/Users/bradjc/git/tock/boards/components)
   Compiling imix v0.1.0 (/Users/bradjc/git/tock/boards/imix)
    Finished release [optimized + debuginfo] target(s) in 34.42s
   text	   data	    bss	    dec	    hex	filename
 188309	     64	  32704	 221077	  35f95	/Users/bradjc/git/tock/target/thumbv7em-none-eabi/release/imix
3e6578da0741e58e8f0b802d445558df4c1394f8f898dd064ea0d39bde04f7ae	/Users/bradjc/git/tock/target/thumbv7em-none-eabi/release/imix.bin

@phil-levis
Copy link
Contributor

I will look into this. I'll try to improve the print tool to see what's happening.

@hudson-ayers hudson-ayers force-pushed the 2.0-no-successwithvalue branch from 2edf62d to a89173c Compare February 18, 2021 20:46
@hudson-ayers
Copy link
Contributor

Rebased ontop of 2.0-dev now that I merged master in

@hudson-ayers
Copy link
Contributor

After the rebase, this PR adds just under 2kB of code, but Imix now fits.

@hudson-ayers
Copy link
Contributor

hudson-ayers commented Feb 18, 2021

Some tidbits from my investigating the size changes:

  • Increase seems spread across many functions
  • Marking all returnCode functions inline(never) → small improvement
  • Marking inline(always) → little worse
  • mem::size_of(Returncode now): 1 byte. Before it was 8 bytes!
pub enum ReturnCode {
    SuccessWithValue { value },
    SUCCESS

Total Imix size: 184996 bytes

pub enum ReturnCode {
    SUCCESS,

Total Imix size: 186980

#[repr(isize)]
pub enum ReturnCode {
    SUCCESS,

Total Imix size: 184485

#[repr(rust)]
pub enum ReturnCode {
    SUCCESS,
// ...
#[repr(rust)] // previously was #[repr(usize)]
pub enum ErrorCode {
    SUCCESS,

Total Imix size: 185541

Hypothesis: Making ReturnCode 1 byte instead of 4 decreases stack memory use, however doing so also increases code size, because now kernel has to sign extend values when moving ReturnCodes in/out of a word-size register at the userspace boundary.

Looking at the difference in stack frame sizes, most functions are unchanged. the biggest changes are:

  • UDP::Driver::command() stack frame 480 bytes --> 536 bytes
  • IPC::Driver::command() stack frame 232 bytes --> 280 bytes
  • nrfSerializiation::Driver::command() stack frame 136 bytes --> 216 bytes

@alevy
Copy link
Member

alevy commented Feb 19, 2021

Following some side discussion, @hudson-ayers's theory seems to hold water and his proposal to just force ReturnCode to usize/isize seems strictly positive---there is no semantic difference within the kernel and it ends up resulting in an overall improvement in code space for this PR.

A note: I'm very skeptical that we get any actual memory savings from the ReturnCode being smaller than a word since likely the compiler is using a word for it on the stack anyway in most cases.

Copy link
Member

@ppannuto ppannuto left a comment

Choose a reason for hiding this comment

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

bors r+

@alevy
Copy link
Member

alevy commented Feb 19, 2021

bors r+

@bors
Copy link
Contributor

bors bot commented Feb 19, 2021

Already running a review

@bors
Copy link
Contributor

bors bot commented Feb 19, 2021

@bors bors bot merged commit cf21e7f into tock-2.0-dev Feb 19, 2021
@bors bors bot deleted the 2.0-no-successwithvalue branch February 19, 2021 17:35
@phil-levis
Copy link
Contributor

A note: I'm very skeptical that we get any actual memory savings from the ReturnCode being smaller than a word since likely the compiler is using a word for it on the stack anyway in most cases.

This seems to be a case where you can trade off RAM for flash; given we are much more cramped for flash, a possible few extra bytes of RAM here or there are well worth it.

lschuermann pushed a commit to lschuermann/tock that referenced this pull request Mar 22, 2021
2430: 2.0: Remove SuccessWithValue r=ppannuto a=bradjc

### Pull Request Overview

This pull request removes `SuccessWithValue` for 2.0. Other than IPC, nothing was using SuccessWithValue anymore.

### Testing Strategy

travis

### TODO or Help Wanted

Need the IPC updates first.

### Documentation Updated

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

### Formatting

- [x] Ran `make prepush`.

2443: 2.0: lps25hb r=alevy a=bradjc

### Pull Request Overview

Update the last capsule to 2.0.

### Testing Strategy

travis.

### TODO or Help Wanted

n/a

### Documentation Updated

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

### Formatting

- [x] Ran `make prepush`.

Co-authored-by: Brad Campbell <[email protected]>
Co-authored-by: Hudson Ayers <[email protected]>
lschuermann pushed a commit to lschuermann/tock that referenced this pull request Mar 22, 2021
2430: 2.0: Remove SuccessWithValue r=ppannuto a=bradjc

### Pull Request Overview

This pull request removes `SuccessWithValue` for 2.0. Other than IPC, nothing was using SuccessWithValue anymore.

### Testing Strategy

travis

### TODO or Help Wanted

Need the IPC updates first.

### Documentation Updated

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

### Formatting

- [x] Ran `make prepush`.

2443: 2.0: lps25hb r=alevy a=bradjc

### Pull Request Overview

Update the last capsule to 2.0.

### Testing Strategy

travis.

### TODO or Help Wanted

n/a

### Documentation Updated

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

### Formatting

- [x] Ran `make prepush`.

Co-authored-by: Brad Campbell <[email protected]>
Co-authored-by: Hudson Ayers <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kernel tock-2.0 Issues and PRs related to Tock version 2.0.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants