From 08026555313db5c2dad33dc9bf3eed7ccb2adb46 Mon Sep 17 00:00:00 2001 From: Brian Norris Date: Tue, 27 Feb 2024 13:01:23 -0800 Subject: [PATCH] linux_mtd: Provide no-op delay implementation Flashrom has several magic programmer_delay() calls scattered throughout its codebase (see cli_classic.s/main() and flashrom.c/flashrom_image_write(), at least). These delays are superfluous for the linux_mtd programmer, because it's an opaque programmer in which all protocol details are handled by the kernel driver. Stub out the delay function, so we don't waste up to 1.1 seconds of needless delay time, depending on the operation and CLI vs libflashrom usage. BUG=b:325539928 TEST=`elogtool add 0xa7` on a linux_mtd system (such as a Mediatek Chromebook): Time improvement - reduces from ~1.5s wall clock to about 0.4s CPU usage: -90%, as most of the CPU cycles (before this change) are spent in needless magic-delay busy loops Change-Id: I3ac69d3fd7cfc689c5b32c130d044516ed846c29 Signed-off-by: Brian Norris Reviewed-on: https://review.coreboot.org/c/flashrom/+/80771 Tested-by: build bot (Jenkins) Reviewed-by: Anastasia Klimchuk --- linux_mtd.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/linux_mtd.c b/linux_mtd.c index 495db9a74..eea0cf225 100644 --- a/linux_mtd.c +++ b/linux_mtd.c @@ -429,6 +429,14 @@ static enum flashrom_wp_result linux_mtd_wp_get_available_ranges(struct flashrom return FLASHROM_WP_ERR_RANGE_LIST_UNAVAILABLE; } +static void linux_mtd_nop_delay(const struct flashctx *flash, unsigned int usecs) +{ + /* + * Ignore delay requests. The Linux MTD framework brokers all flash + * protocol, including timing, resets, etc. + */ +} + static const struct opaque_master linux_mtd_opaque_master = { /* max_data_{read,write} don't have any effect for this programmer */ .max_data_read = MAX_DATA_UNSPECIFIED, @@ -441,6 +449,7 @@ static const struct opaque_master linux_mtd_opaque_master = { .wp_read_cfg = linux_mtd_wp_read_cfg, .wp_write_cfg = linux_mtd_wp_write_cfg, .wp_get_ranges = linux_mtd_wp_get_available_ranges, + .delay = linux_mtd_nop_delay, }; /* Returns 0 if setup is successful, non-zero to indicate error */