-
Notifications
You must be signed in to change notification settings - Fork 2k
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
drivers/mtd_flashpage: improve _write_page #20173
drivers/mtd_flashpage: improve _write_page #20173
Conversation
@@ -114,9 +114,13 @@ static int _write_page(mtd_dev_t *dev, const void *buf, uint32_t page, uint32_t | |||
__attribute__ ((aligned (FLASHPAGE_WRITE_BLOCK_ALIGNMENT))); | |||
|
|||
offset = addr % FLASHPAGE_WRITE_BLOCK_ALIGNMENT; | |||
size = MIN(size, FLASHPAGE_WRITE_BLOCK_ALIGNMENT - offset); | |||
size = MIN(size, FLASHPAGE_WRITE_BLOCK_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 not
size = MIN(size, FLASHPAGE_WRITE_BLOCK_SIZE); | |
size = MIN(size, FLASHPAGE_WRITE_BLOCK_SIZE - offset); |
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 tried that it was wrong in some cases. I don´t remember in which cases. I will post an example later.
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 enabled the DEBUG()
and tried an application with FLashDB. From the output it seems to be the same 🤔. I don´t know why I wrote it like this back then.
|
||
DEBUG("flashpage: write %"PRIu32" unaligned bytes\n", size); | ||
if (offset + size > FLASHPAGE_WRITE_BLOCK_SIZE) { | ||
size = ((offset + size) & ~(FLASHPAGE_WRITE_BLOCK_SIZE - 1)) - offset; |
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.
Can you add a comment how you arrived at this formula?
a5be0a1
to
37c39d0
Compare
Contribution description
Some time ago I noticed that the mtd_flashpage driver was not writing the size of a full block (
FLASHPAGE_WRITE_BLOCK_SIZE
) when it could be, on unaligned access.It was only writing
FLASHPAGE_WRITE_BLOCK_ALIGNMENT
.So this PR is just a tiny performance improvement.
Testing procedure
That case even happens in the test
tests/drivers/mtd_flashpage
.And with his change it still passes on
same54-xpro
.Issues/PRs references