stand/lua: Defer kernel/module loading until boot or menu escape

Loading the kernel and modules can be really slow. Loading before the menu
draws and every time one changes kernel/boot environment is even more
painful.

Defer loading until we either boot, auto-boot, or escape to loader prompt.
We still need to deal with configuration changes as the boot environment
changes, but this is generally much quicker.

This commit strips all ELF loading out of config.load/config.reload so that
these are purely for configuration. config.loadelf has been created to deal
with kernel/module loads. Unloading logic has been ripped out, as we won't
need to deal with it in the menu anymore.

Discussed in part with:	allanjude
This commit is contained in:
Kyle Evans 2018-02-19 14:21:56 +00:00
parent 15bf717a93
commit fa4a2394a7
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=329576
3 changed files with 33 additions and 29 deletions

View file

@ -345,6 +345,9 @@ function config.loadkernel(other_kernel)
end
end
function config.selectkernel(kernel)
config.kernel_selected = kernel;
end
function config.load(file)
if (not file) then
@ -367,9 +370,32 @@ function config.load(file)
-- Cache the provided module_path at load time for later use
config.module_path = loader.getenv("module_path");
end
-- Reload configuration
function config.reload(file)
-- XXX TODO: We should be doing something more here to clear out env
-- changes that rode in with the last configuration load
modules = {};
config.load(file);
end
function config.loadelf()
local kernel = config.kernel_loaded or config.kernel_selected;
local loaded = false;
print("Loading kernel...");
config.loadkernel(config.kernel_loaded);
loaded = config.loadkernel(kernel);
if (not loaded) then
loaded = config.loadkernel();
end
if (not loaded) then
-- Ultimately failed to load kernel
print("Failed to load any kernel");
return;
end
print("Loading configured modules...");
if (not config.loadmod(modules)) then
@ -377,30 +403,5 @@ function config.load(file)
end
end
function config.reload(kernel)
local kernel_loaded = false;
-- unload all modules
print("Unloading modules...");
loader.perform("unload");
if (kernel ~= nil) then
print("Trying to load '" .. kernel .. "'")
kernel_loaded = config.loadkernel(kernel);
if (kernel_loaded) then
print("Kernel '" .. kernel .. "' loaded!");
end
end
-- failed to load kernel or it is nil
-- then load default
if (not kernel_loaded) then
print("Loading default kernel...");
config.loadkernel();
end
-- load modules
config.loadmod(modules);
end
return config

View file

@ -26,6 +26,8 @@
-- $FreeBSD$
--
local config = require('config');
local core = {};
-- Commonly appearing constants
@ -180,10 +182,12 @@ function core.setDefaults()
end
function core.autoboot()
config.loadelf();
loader.perform("autoboot");
end
function core.boot()
config.loadelf();
loader.perform("boot");
end

View file

@ -220,9 +220,7 @@ menu.welcome = {
" of " .. #all_choices .. ")";
end,
func = function(idx, choice, all_choices)
if (#all_choices > 1) then
config.reload(choice);
end
config.selectkernel(choice);
end,
alias = {"k", "K"}
},
@ -332,6 +330,7 @@ function menu.run(m)
if (m == menu.welcome) then
screen.defcursor();
print("Exiting menu!");
config.loadelf();
return false;
end