mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-31 02:51:26 +00:00
On VM-based builders, the nvmem unittest was sometimes missing the 10-second deadline, likely being stuck in slow I/Os. Try to move the persistent storage files used for flash 'emulation' on host from the build directory to a RAM-backed filesystem in /dev/shm in order to mitigate this bottleneck. Store the new backing files in a path like: /dev/shm/EC_persist__mnt_host_source_src_platform_ec_build_host_nvmem_nvmem.exe_flash in order to keep the properties of the old system: subsequent runs of the same build will use the same persistent storage but 2 different trees won't mix up. Signed-off-by: Vincent Palatin <vpalatin@chromium.org> BRANCH=none BUG=chromium:715011 TEST=make runtests TEST=run the following command with and without this change: 'for i in 0 1 2 3 4 5 6 7 8 9 ; do time make run-nvmem ; done' and see the average test time around 500 ms without the change and around 320 ms with it on an idle and beefy workstation. Change-Id: Ic2ff6511b81869171efc484ca805f8c0d6008595 Reviewed-on: https://chromium-review.googlesource.com/893380 Commit-Ready: Vincent Palatin <vpalatin@chromium.org> Tested-by: Vincent Palatin <vpalatin@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
65 lines
1.3 KiB
C
65 lines
1.3 KiB
C
/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
/* Persistence module for emulator */
|
|
|
|
#include <linux/limits.h>
|
|
#include <unistd.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
static void get_storage_path(char *out)
|
|
{
|
|
char buf[PATH_MAX];
|
|
int sz;
|
|
char *current;
|
|
|
|
sz = readlink("/proc/self/exe", buf, PATH_MAX - 1);
|
|
buf[sz] = '\0';
|
|
|
|
/* replace / by underscores in the path to get the shared memory name */
|
|
current = strchr(buf, '/');
|
|
while (current) {
|
|
*current = '_';
|
|
current = strchr(current, '/');
|
|
}
|
|
|
|
snprintf(out, PATH_MAX - 1, "/dev/shm/EC_persist_%s", buf);
|
|
out[PATH_MAX - 1] = '\0';
|
|
}
|
|
|
|
FILE *get_persistent_storage(const char *tag, const char *mode)
|
|
{
|
|
char buf[PATH_MAX];
|
|
char path[PATH_MAX];
|
|
|
|
/*
|
|
* The persistent storage with tag 'foo' for test 'bar' would
|
|
* be named 'bar_persist_foo'
|
|
*/
|
|
get_storage_path(buf);
|
|
snprintf(path, PATH_MAX - 1, "%s_%s", buf, tag);
|
|
path[PATH_MAX - 1] = '\0';
|
|
|
|
return fopen(path, mode);
|
|
}
|
|
|
|
void release_persistent_storage(FILE *ps)
|
|
{
|
|
fclose(ps);
|
|
}
|
|
|
|
void remove_persistent_storage(const char *tag)
|
|
{
|
|
char buf[PATH_MAX];
|
|
char path[PATH_MAX];
|
|
|
|
get_storage_path(buf);
|
|
snprintf(path, PATH_MAX - 1, "%s_%s", buf, tag);
|
|
path[PATH_MAX - 1] = '\0';
|
|
|
|
unlink(path);
|
|
}
|