Edward O'Callaghan has uploaded this change for review.

View Change

linux_mtd.c: Optimise linux_mtd_wp_read_cfg() ioctl() calls

The linux_mtd_wp_read_cfg() function makes excessive
ioctl() calls as it sweeps on a per-eraseblock basis.
Instead employ a bisection algorithm to optimise the
number of user to kernel interactions to a minimum.

Change-Id: I7ae3816598b74f0db7ac7d564391e69cfb8b1f79
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
Co-Authored-by: Damien Zammit <damien@zamaudio.com>
---
M linux_mtd.c
1 file changed, 5 insertions(+), 2 deletions(-)

git pull ssh://review.coreboot.org:29418/flashrom refs/changes/76/75476/1
diff --git a/linux_mtd.c b/linux_mtd.c
index 495db9a..bc07dfa 100644
--- a/linux_mtd.c
+++ b/linux_mtd.c
@@ -323,7 +323,8 @@
cfg->range.len = 0;

/* Check protection status of each block */
- for (size_t u = 0; u < data->total_size; u += data->erasesize) {
+ uint32_t erase_boundary = total_size/2;
+ for (size_t u = 0; u < data->total_size; u += erase_boundary) {
struct erase_info_user erase_info = {
.start = u,
.length = data->erasesize,
@@ -339,13 +340,15 @@
} else if (ret == 1) {
/* Block is protected. */

- if (end_found) {
+ if (end_found && (erase_boundary < data->erasesize)) {
/*
* We already found the end of another
* protection range, so this is the start of a
* new one.
*/
return FLASHROM_WP_ERR_OTHER;
+ } else { /* hole to bisect */
+ erase_boundary = max(erase_boundary/2, data->erasesize);
}
if (!start_found) {
cfg->range.start = erase_info.start;

To view, visit change 75476. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I7ae3816598b74f0db7ac7d564391e69cfb8b1f79
Gerrit-Change-Number: 75476
Gerrit-PatchSet: 1
Gerrit-Owner: Edward O'Callaghan <quasisec@chromium.org>
Gerrit-MessageType: newchange