Skip to content

Add basic memory allocation outside Python runtime#1057

Merged
dhalbert merged 6 commits into
adafruit:masterfrom
tannewt:flexible_heap
Aug 2, 2018
Merged

Add basic memory allocation outside Python runtime#1057
dhalbert merged 6 commits into
adafruit:masterfrom
tannewt:flexible_heap

Conversation

@tannewt
Copy link
Copy Markdown
Member

@tannewt tannewt commented Jul 25, 2018

This allows for the heap to fill all space but the stack. It also allows us to designate space for memory outside the runtime for things such as USB descriptors, flash cache and main filename.

Fixes #754

@notro
Copy link
Copy Markdown

notro commented Jul 25, 2018

The mode on some of the files are changed from 0644 to 0755, which I suppose is unintentional.

tannewt and others added 3 commits July 31, 2018 05:18
This allows for the heap to fill all space but the stack. It also
allows us to designate space for memory outside the runtime for
things such as USB descriptors, flash cache and main filename.

Fixes micropython#754
@tannewt
Copy link
Copy Markdown
Member Author

tannewt commented Jul 31, 2018

Ok this should be good to go after travis gives the ok. Please take another look.

Copy link
Copy Markdown
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

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

Excellent idea! Some questions and comments.

found = allocation == &allocations[index];
if (found) {
break;
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Supposer the allocation is not found. Wouldn't that be a fatal error of some kind?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes but I couldn't decide how to convey it since the Python VM isn't running. Maybe an assert?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Maybe we should have a general "terrible thing happened -- blink the status LED?" loop? Or do we need the LED set up to do that?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We could use your "blink variable number of times" code and have some ifdef's for the values. This could be a todo. Right now you could just while { } like we do for some other errors, and mark it as a TODO.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

TODO added. Sounds like we'd want to kick into safe mode.

return allocate_memory((high_address - low_address) * 4, false);
}

supervisor_allocation* allocate_memory(uint32_t length, bool high) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could you add some a comment here about what the high bool means? it looks likethis is for blocks that are addressed downward, is that right?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Added it to the .h at the top level. (Will push soon.)

}
supervisor_allocation* alloc = &allocations[index];
if (high) {
high_address -= length / 4;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If the requested length is not a multiple of 4, then I think you'll allocate a region that's length % 4 bytes too short. So maybe check that length % 4 == 0.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done

Comment thread ports/nrf/supervisor/memory.c Outdated

#define CIRCUITPY_SUPERVISOR_ALLOC_COUNT 8

static supervisor_allocation allocations[CIRCUITPY_SUPERVISOR_ALLOC_COUNT];
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This nrf/supervisor/memory.c looks pretty identical to the atmel-samd version. Can you share code? Hoist this into the common supervisor/ dir? add #if's for arch-specific if needed?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Shared. I'm not sure if ESP will fit but we can change it when the time comes.

Comment thread supervisor/shared/stack.c
}

inline void stack_init(void) {
allocate_stack();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Do these have to be inline or are you suggesting? If it's required, then we need to do the volatile asm(""); trick.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Nope. I must have been experimenting.

Copy link
Copy Markdown
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

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

Thanks for this!

@dhalbert dhalbert merged commit dfa2581 into adafruit:master Aug 2, 2018
@arturo182 arturo182 mentioned this pull request Sep 8, 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.

3 participants