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

spi_nor Erase operation selection is excessively conservative #60904

Closed
Crzyrndm opened this issue Jul 28, 2023 · 2 comments · Fixed by #60943
Closed

spi_nor Erase operation selection is excessively conservative #60904

Crzyrndm opened this issue Jul 28, 2023 · 2 comments · Fixed by #60943
Assignees
Labels
area: SPI SPI bus bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug

Comments

@Crzyrndm
Copy link
Contributor

Crzyrndm commented Jul 28, 2023

Summary: SPI_NOR driver is selecting a smaller erase operation in in many situations it doesn't need to

SPI NOR FLASH devices often have multiple erase sizes. 4k, 32k and 64k are very typical.
When spi_nor_erase (link) is invoked part of the loop attempts to pick the largest erase operation for the current address and remaining size (link)

I was erasing parts of a 512MiB NOR device today and observed extremely slow erase speeds. I found that many of the erase operation where using only the 4kiB erase even when the address/remainder was suitable for a much larger operation.

I extracted the main parts of the op selector in order to confirm my suspicions. This can be seen here

erasing 0x40000 bytes starting at 0x4000
loc: 0x4000, remaining: 0x40000, chosen: 0x1000
loc: 0x5000, remaining: 0x3F000, chosen: 0x1000
loc: 0x6000, remaining: 0x3E000, chosen: 0x1000
loc: 0x7000, remaining: 0x3D000, chosen: 0x1000
loc: 0x8000, remaining: 0x3C000, chosen: 0x1000 // should have been a 32k erase
loc: 0x9000, remaining: 0x3B000, chosen: 0x1000
loc: 0xA000, remaining: 0x3A000, chosen: 0x1000
loc: 0xB000, remaining: 0x39000, chosen: 0x1000
loc: 0xC000, remaining: 0x38000, chosen: 0x1000
loc: 0xD000, remaining: 0x37000, chosen: 0x1000
loc: 0xE000, remaining: 0x36000, chosen: 0x1000
loc: 0xF000, remaining: 0x35000, chosen: 0x1000
loc: 0x10000, remaining: 0x34000, chosen: 0x1000 // should have been a 64k erase
loc: 0x11000, remaining: 0x33000, chosen: 0x1000
...

What I would expect to see is that 4k erases are used until 32k is reached, a 32k erase to get to 64k then 64k erases until the last 16 kB. What actually happens is that only 4k erases are used.

The problem is this line. For a larger erase op to be chosen, the final end address must be aligned with that op size. In my example above, the end is only 16kB aligned so this never occurs

The correct check would be size >= (1 << etp->exp) (updated example. Change is to line 30). This results in the desired/expected output with the largest applicable erase op being used at each step

erasing 0x40000 bytes starting at 0x4000
loc: 0x4000, remaining: 0x40000, chosen: 0x1000
loc: 0x5000, remaining: 0x3F000, chosen: 0x1000
loc: 0x6000, remaining: 0x3E000, chosen: 0x1000
loc: 0x7000, remaining: 0x3D000, chosen: 0x1000
loc: 0x8000, remaining: 0x3C000, chosen: 0x8000 // 32k
loc: 0x10000, remaining: 0x34000, chosen: 0x10000 // 64k
loc: 0x20000, remaining: 0x24000, chosen: 0x10000
loc: 0x30000, remaining: 0x14000, chosen: 0x10000
loc: 0x40000, remaining: 0x4000, chosen: 0x1000 // back to 4k
loc: 0x41000, remaining: 0x3000, chosen: 0x1000
loc: 0x42000, remaining: 0x2000, chosen: 0x1000
loc: 0x43000, remaining: 0x1000, chosen: 0x1000
@Crzyrndm Crzyrndm added the bug The issue is a bug, or the PR is fixing a bug label Jul 28, 2023
@Laczen
Copy link
Collaborator

Laczen commented Jul 28, 2023

@Crzyrndm, the check should indeed be that the (remaining) size is larger or equal to the erase size. Could you provide a PR ?

Crzyrndm added a commit to Crzyrndm/zephyr that referenced this issue Jul 28, 2023
The spi_nor erase op selection was based on the alignment of the end of
the region to be erased. This prevented larger erase operations being
selected in many cases

See zephyrproject-rtos#60904

Signed-off-by: Joshua Crawford <joshua.crawford@levno.com>
@Crzyrndm
Copy link
Contributor Author

@Crzyrndm, the check should indeed be that the (remaining) size is larger or equal to the erase size. Could you provide a PR ?

PR has been opened. I think I got all the neccesary conventions covered but feel free to just fix it if more needs doing

Crzyrndm added a commit to Crzyrndm/zephyr that referenced this issue Jul 29, 2023
The spi_nor erase op selection was based on the alignment of the end of
the region to be erased. This prevented larger erase operations being
selected in many cases

Closes zephyrproject-rtos#60904

Signed-off-by: Joshua Crawford <joshua.crawford@levno.com>
@jhedberg jhedberg added priority: low Low impact/importance bug area: SPI SPI bus labels Aug 1, 2023
Crzyrndm added a commit to Crzyrndm/zephyr that referenced this issue Aug 1, 2023
The spi_nor erase op selection was based on the alignment of the end of
the region to be erased. This prevented larger erase operations being
selected in many cases

Closes zephyrproject-rtos#60904

Signed-off-by: Joshua Crawford <joshua.crawford@levno.com>
carlescufi pushed a commit that referenced this issue Aug 4, 2023
The spi_nor erase op selection was based on the alignment of the end of
the region to be erased. This prevented larger erase operations being
selected in many cases

Closes #60904

Signed-off-by: Joshua Crawford <joshua.crawford@levno.com>
zephyrbot pushed a commit that referenced this issue Aug 4, 2023
The spi_nor erase op selection was based on the alignment of the end of
the region to be erased. This prevented larger erase operations being
selected in many cases

Closes #60904

Signed-off-by: Joshua Crawford <joshua.crawford@levno.com>
(cherry picked from commit ea2dd9f)
zephyrbot pushed a commit that referenced this issue Aug 4, 2023
The spi_nor erase op selection was based on the alignment of the end of
the region to be erased. This prevented larger erase operations being
selected in many cases

Closes #60904

Signed-off-by: Joshua Crawford <joshua.crawford@levno.com>
(cherry picked from commit ea2dd9f)
zephyrbot pushed a commit that referenced this issue Aug 4, 2023
The spi_nor erase op selection was based on the alignment of the end of
the region to be erased. This prevented larger erase operations being
selected in many cases

Closes #60904

Signed-off-by: Joshua Crawford <joshua.crawford@levno.com>
(cherry picked from commit ea2dd9f)
zephyrbot pushed a commit that referenced this issue Aug 4, 2023
The spi_nor erase op selection was based on the alignment of the end of
the region to be erased. This prevented larger erase operations being
selected in many cases

Closes #60904

Signed-off-by: Joshua Crawford <joshua.crawford@levno.com>
(cherry picked from commit ea2dd9f)
kunoh pushed a commit to kunoh/zephyr that referenced this issue Aug 7, 2023
The spi_nor erase op selection was based on the alignment of the end of
the region to be erased. This prevented larger erase operations being
selected in many cases

Closes zephyrproject-rtos#60904

Signed-off-by: Joshua Crawford <joshua.crawford@levno.com>
umarnisar92 pushed a commit to nisarumar/zephyr that referenced this issue Aug 15, 2023
The spi_nor erase op selection was based on the alignment of the end of
the region to be erased. This prevented larger erase operations being
selected in many cases

Closes zephyrproject-rtos#60904

Signed-off-by: Joshua Crawford <joshua.crawford@levno.com>
meshium pushed a commit to meshium/zephyr that referenced this issue Aug 16, 2023
The spi_nor erase op selection was based on the alignment of the end of
the region to be erased. This prevented larger erase operations being
selected in many cases

Closes zephyrproject-rtos#60904

Signed-off-by: Joshua Crawford <joshua.crawford@levno.com>
jgl-meta pushed a commit that referenced this issue Aug 22, 2023
The spi_nor erase op selection was based on the alignment of the end of
the region to be erased. This prevented larger erase operations being
selected in many cases

Closes #60904

Signed-off-by: Joshua Crawford <joshua.crawford@levno.com>
(cherry picked from commit ea2dd9f)
fabiobaltieri pushed a commit that referenced this issue Sep 5, 2023
The spi_nor erase op selection was based on the alignment of the end of
the region to be erased. This prevented larger erase operations being
selected in many cases

Closes #60904

Signed-off-by: Joshua Crawford <joshua.crawford@levno.com>
(cherry picked from commit ea2dd9f)
cfriedt pushed a commit that referenced this issue Nov 17, 2023
The spi_nor erase op selection was based on the alignment of the end of
the region to be erased. This prevented larger erase operations being
selected in many cases

Closes #60904

Signed-off-by: Joshua Crawford <joshua.crawford@levno.com>
(cherry picked from commit ea2dd9f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: SPI SPI bus bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants