Merge "init: ro.boottime.init.modules" am: 74b03a16be am: 02d2bcf0f6

Original change: https://android-review.googlesource.com/c/platform/system/core/+/1574952

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I8affbaf1398519f642bbbb20e61ef19391c450dd
This commit is contained in:
Lisa (LeeWei) Liu 2021-02-22 03:50:40 +00:00 committed by Automerger Merge Worker
commit 2f223491a4
4 changed files with 22 additions and 4 deletions

View file

@ -795,6 +795,9 @@ Init records some boot timing information in system properties.
`ro.boottime.init.selinux`
> How long in ns it took to run SELinux stage.
`ro.boottime.init.modules`
> How long in ms it took to load kernel modules.
`ro.boottime.init.cold_boot_wait`
> How long init waited for ueventd's coldboot phase to end.

View file

@ -122,7 +122,7 @@ std::string GetModuleLoadList(bool recovery, const std::string& dir_path) {
}
#define MODULE_BASE_DIR "/lib/modules"
bool LoadKernelModules(bool recovery, bool want_console) {
bool LoadKernelModules(bool recovery, bool want_console, int& modules_loaded) {
struct utsname uts;
if (uname(&uts)) {
LOG(FATAL) << "Failed to get kernel version.";
@ -164,7 +164,7 @@ bool LoadKernelModules(bool recovery, bool want_console) {
dir_path.append(module_dir);
Modprobe m({dir_path}, GetModuleLoadList(recovery, dir_path));
bool retval = m.LoadListedModules(!want_console);
int modules_loaded = m.GetModuleCount();
modules_loaded = m.GetModuleCount();
if (modules_loaded > 0) {
return retval;
}
@ -172,7 +172,7 @@ bool LoadKernelModules(bool recovery, bool want_console) {
Modprobe m({MODULE_BASE_DIR}, GetModuleLoadList(recovery, MODULE_BASE_DIR));
bool retval = m.LoadListedModules(!want_console);
int modules_loaded = m.GetModuleCount();
modules_loaded = m.GetModuleCount();
if (modules_loaded > 0) {
return retval;
}
@ -278,13 +278,23 @@ int FirstStageMain(int argc, char** argv) {
auto want_console = ALLOW_FIRST_STAGE_CONSOLE ? FirstStageConsole(cmdline) : 0;
if (!LoadKernelModules(IsRecoveryMode() && !ForceNormalBoot(cmdline), want_console)) {
boot_clock::time_point module_start_time = boot_clock::now();
int module_count = 0;
if (!LoadKernelModules(IsRecoveryMode() && !ForceNormalBoot(cmdline), want_console,
module_count)) {
if (want_console != FirstStageConsoleParam::DISABLED) {
LOG(ERROR) << "Failed to load kernel modules, starting console";
} else {
LOG(FATAL) << "Failed to load kernel modules";
}
}
if (module_count > 0) {
auto module_elapse_time = std::chrono::duration_cast<std::chrono::milliseconds>(
boot_clock::now() - module_start_time);
setenv(kEnvInitModuleDurationMs, std::to_string(module_elapse_time.count()).c_str(), 1);
LOG(INFO) << "Loaded " << module_count << " kernel modules took "
<< module_elapse_time.count() << " ms";
}
if (want_console == FirstStageConsoleParam::CONSOLE_ON_FAILURE) {
StartConsole(cmdline);

View file

@ -22,6 +22,7 @@ namespace init {
int FirstStageMain(int argc, char** argv);
static constexpr char kEnvFirstStageStartedAt[] = "FIRST_STAGE_STARTED_AT";
static constexpr char kEnvInitModuleDurationMs[] = "INIT_MODULE_DURATION_MS";
} // namespace init
} // namespace android

View file

@ -713,6 +713,10 @@ static void RecordStageBoottimes(const boot_clock::time_point& second_stage_star
SetProperty("ro.boottime.init.selinux",
std::to_string(second_stage_start_time.time_since_epoch().count() -
selinux_start_time_ns));
if (auto init_module_time_str = getenv(kEnvInitModuleDurationMs); init_module_time_str) {
SetProperty("ro.boottime.init.modules", init_module_time_str);
unsetenv(kEnvInitModuleDurationMs);
}
}
void SendLoadPersistentPropertiesMessage() {