summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVadim Bendebury <vbendeb@chromium.org>2014-11-07 17:25:09 -0800
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-11-10 20:43:05 +0000
commit38201fe1f7c0144578b0d67572a0f2db22b8d0b7 (patch)
tree80102e5741f6eaf5df1815352697b4b826a73e9a
parentfe21172cc315b6249e78ee8bc17d1470e8b6b02b (diff)
downloadvboot-38201fe1f7c0144578b0d67572a0f2db22b8d0b7.tar.gz
crossystem: cache vbnv contents to avoid lengthy reads
Storing nvram in SPI Flash becomes more and more popular. Retrieving it takes quite a while due to various flashrom issues. While flashrom still needs to be improved to minimize its running time, a good speed up can be achieved by caching the nvram contents in crossystem. The cache is invalidated each time nvram is written (this could be optimized by updating the local copy, but probably is not worth the extra effort). BRANCH=storm BUG=chrome-os-partner:33592 TEST=crossystem runs much faster now: localhost var # time /var/tmp/crossystem . . . real 0m1.669s user 0m0.790s sys 0m0.170s localhost var # Change-Id: Ie4a483efc189257ff58c92bdc39871b917c89727 Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/228655 Reviewed-by: Randall Spangler <rspangler@chromium.org> Reviewed-by: David Hendricks <dhendrix@chromium.org>
-rw-r--r--host/lib/crossystem.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/host/lib/crossystem.c b/host/lib/crossystem.c
index b28fd877..43dcc2a4 100644
--- a/host/lib/crossystem.c
+++ b/host/lib/crossystem.c
@@ -80,20 +80,24 @@ int FwidStartsWith(const char *start) {
return 0 == strncmp(fwid, start, strlen(start));
}
+static int vnc_read;
int VbGetNvStorage(VbNvParam param) {
- VbNvContext vnc;
uint32_t value;
int retval;
+ static VbNvContext cached_vnc;
/* TODO: locking around NV access */
+ if (!vnc_read) {
+ if (0 != VbReadNvStorage(&cached_vnc))
+ return -1;
+ vnc_read = 1;
+ }
- if (0 != VbReadNvStorage(&vnc))
+ if (0 != VbNvSetup(&cached_vnc))
return -1;
- if (0 != VbNvSetup(&vnc))
- return -1;
- retval = VbNvGet(&vnc, param, &value);
- if (0 != VbNvTeardown(&vnc))
+ retval = VbNvGet(&cached_vnc, param, &value);
+ if (0 != VbNvTeardown(&cached_vnc))
return -1;
if (0 != retval)
return -1;
@@ -123,6 +127,7 @@ int VbSetNvStorage(VbNvParam param, int value) {
goto VbSetNvCleanup;
if (vnc.raw_changed) {
+ vnc_read = 0;
if (0 != VbWriteNvStorage(&vnc))
goto VbSetNvCleanup;
}