mirror of
https://git.proxmox.com/git/fwupd
synced 2025-08-04 03:36:57 +00:00
trivial: Add FuProgress to fu_context_load_hwinfo()
TIL: fu_bios_settings_setup() takes over 50ms (10%!) at startup.
This commit is contained in:
parent
4d4c56fa75
commit
6e34a90a12
@ -8,6 +8,7 @@
|
||||
|
||||
#include "fu-context.h"
|
||||
#include "fu-hwids.h"
|
||||
#include "fu-progress.h"
|
||||
#include "fu-quirks.h"
|
||||
#include "fu-volume.h"
|
||||
|
||||
@ -26,7 +27,10 @@ fu_context_new(void);
|
||||
gboolean
|
||||
fu_context_reload_bios_settings(FuContext *self, GError **error);
|
||||
gboolean
|
||||
fu_context_load_hwinfo(FuContext *self, FuContextHwidFlags flags, GError **error);
|
||||
fu_context_load_hwinfo(FuContext *self,
|
||||
FuProgress *progress,
|
||||
FuContextHwidFlags flags,
|
||||
GError **error);
|
||||
gboolean
|
||||
fu_context_load_quirks(FuContext *self, FuQuirksLoadFlags flags, GError **error);
|
||||
void
|
||||
|
@ -772,6 +772,7 @@ typedef gboolean (*FuContextHwidsSetupFunc)(FuContext *self, FuHwids *hwids, GEr
|
||||
/**
|
||||
* fu_context_load_hwinfo:
|
||||
* @self: a #FuContext
|
||||
* @progress: a #FuProgress
|
||||
* @flags: a #FuContextHwidFlags, e.g. %FU_CONTEXT_HWID_FLAG_LOAD_SMBIOS
|
||||
* @error: (nullable): optional return location for an error
|
||||
*
|
||||
@ -782,7 +783,10 @@ typedef gboolean (*FuContextHwidsSetupFunc)(FuContext *self, FuHwids *hwids, GEr
|
||||
* Since: 1.8.10
|
||||
**/
|
||||
gboolean
|
||||
fu_context_load_hwinfo(FuContext *self, FuContextHwidFlags flags, GError **error)
|
||||
fu_context_load_hwinfo(FuContext *self,
|
||||
FuProgress *progress,
|
||||
FuContextHwidFlags flags,
|
||||
GError **error)
|
||||
{
|
||||
FuContextPrivate *priv = GET_PRIVATE(self);
|
||||
GPtrArray *guids;
|
||||
@ -802,6 +806,13 @@ fu_context_load_hwinfo(FuContext *self, FuContextHwidFlags flags, GError **error
|
||||
g_return_val_if_fail(FU_IS_CONTEXT(self), FALSE);
|
||||
g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
|
||||
|
||||
/* progress */
|
||||
fu_progress_set_id(progress, G_STRLOC);
|
||||
fu_progress_add_step(progress, FWUPD_STATUS_LOADING, 1, "hwids-setup-funcs");
|
||||
fu_progress_add_step(progress, FWUPD_STATUS_LOADING, 1, "hwids-setup");
|
||||
fu_progress_add_step(progress, FWUPD_STATUS_LOADING, 3, "set-flags");
|
||||
fu_progress_add_step(progress, FWUPD_STATUS_LOADING, 95, "reload-bios-settings");
|
||||
|
||||
/* run all the HWID setup funcs */
|
||||
for (guint i = 0; hwids_setup_map[i].name != NULL; i++) {
|
||||
if ((flags & hwids_setup_map[i].flag) > 0) {
|
||||
@ -815,8 +826,11 @@ fu_context_load_hwinfo(FuContext *self, FuContextHwidFlags flags, GError **error
|
||||
}
|
||||
}
|
||||
priv->loaded_hwinfo = TRUE;
|
||||
fu_progress_step_done(progress);
|
||||
|
||||
if (!fu_hwids_setup(priv->hwids, &error_hwids))
|
||||
g_warning("Failed to load HWIDs: %s", error_hwids->message);
|
||||
fu_progress_step_done(progress);
|
||||
|
||||
/* set the hwid flags */
|
||||
guids = fu_context_get_hwid_guids(self);
|
||||
@ -832,10 +846,12 @@ fu_context_load_hwinfo(FuContext *self, FuContextHwidFlags flags, GError **error
|
||||
g_hash_table_add(priv->hwid_flags, g_strdup(values[j]));
|
||||
}
|
||||
}
|
||||
fu_progress_step_done(progress);
|
||||
|
||||
fu_context_add_udev_subsystem(self, "firmware-attributes");
|
||||
if (!fu_context_reload_bios_settings(self, &error_bios_settings))
|
||||
g_debug("%s", error_bios_settings->message);
|
||||
fu_progress_step_done(progress);
|
||||
|
||||
/* always */
|
||||
return TRUE;
|
||||
|
@ -435,10 +435,11 @@ static void
|
||||
fu_context_hwids_dmi_func(void)
|
||||
{
|
||||
g_autoptr(FuContext) ctx = fu_context_new();
|
||||
g_autoptr(FuProgress) progress = fu_progress_new(G_STRLOC);
|
||||
g_autoptr(GError) error = NULL;
|
||||
gboolean ret;
|
||||
|
||||
ret = fu_context_load_hwinfo(ctx, FU_CONTEXT_HWID_FLAG_LOAD_DMI, &error);
|
||||
ret = fu_context_load_hwinfo(ctx, progress, FU_CONTEXT_HWID_FLAG_LOAD_DMI, &error);
|
||||
g_assert_no_error(error);
|
||||
g_assert_true(ret);
|
||||
if (g_getenv("FWUPD_VERBOSE") != NULL) {
|
||||
@ -559,6 +560,7 @@ fu_hwids_func(void)
|
||||
{
|
||||
g_autofree gchar *testdatadir = NULL;
|
||||
g_autoptr(FuContext) context = NULL;
|
||||
g_autoptr(FuProgress) progress = fu_progress_new(G_STRLOC);
|
||||
g_autoptr(GError) error = NULL;
|
||||
gboolean ret;
|
||||
|
||||
@ -593,7 +595,7 @@ fu_hwids_func(void)
|
||||
(void)g_setenv("FWUPD_SYSFSFWDIR", testdatadir, TRUE);
|
||||
|
||||
context = fu_context_new();
|
||||
ret = fu_context_load_hwinfo(context, FU_CONTEXT_HWID_FLAG_LOAD_SMBIOS, &error);
|
||||
ret = fu_context_load_hwinfo(context, progress, FU_CONTEXT_HWID_FLAG_LOAD_SMBIOS, &error);
|
||||
g_assert_no_error(error);
|
||||
g_assert_true(ret);
|
||||
|
||||
|
@ -46,7 +46,7 @@ fu_test_self_init(FuTest *self, GError **error_global)
|
||||
&error);
|
||||
g_assert_no_error(error);
|
||||
g_assert_true(ret);
|
||||
ret = fu_context_load_hwinfo(ctx, FU_CONTEXT_HWID_FLAG_LOAD_CONFIG, &error);
|
||||
ret = fu_context_load_hwinfo(ctx, progress, FU_CONTEXT_HWID_FLAG_LOAD_CONFIG, &error);
|
||||
g_assert_no_error(error);
|
||||
g_assert_true(ret);
|
||||
ret = fu_context_reload_bios_settings(ctx, &error);
|
||||
|
@ -32,7 +32,7 @@ fu_test_mtd_device_func(void)
|
||||
ret = fu_context_load_quirks(ctx, FU_QUIRKS_LOAD_FLAG_NO_CACHE, &error);
|
||||
g_assert_no_error(error);
|
||||
g_assert_true(ret);
|
||||
ret = fu_context_load_hwinfo(ctx, FU_CONTEXT_HWID_FLAG_LOAD_SMBIOS, &error);
|
||||
ret = fu_context_load_hwinfo(ctx, progress, FU_CONTEXT_HWID_FLAG_LOAD_SMBIOS, &error);
|
||||
g_assert_no_error(error);
|
||||
g_assert_true(ret);
|
||||
|
||||
|
@ -29,6 +29,7 @@ _test_add_fake_devices_from_dir(FuPlugin *plugin, const gchar *path)
|
||||
const gchar *basename;
|
||||
gboolean ret;
|
||||
g_autoptr(FuContext) ctx = fu_context_new();
|
||||
g_autoptr(FuProgress) progress = fu_progress_new(G_STRLOC);
|
||||
g_autoptr(GError) error = NULL;
|
||||
g_autoptr(GDir) dir = g_dir_open(path, 0, &error);
|
||||
g_assert_no_error(error);
|
||||
@ -37,13 +38,13 @@ _test_add_fake_devices_from_dir(FuPlugin *plugin, const gchar *path)
|
||||
ret = fu_context_load_quirks(ctx, FU_QUIRKS_LOAD_FLAG_NO_CACHE, &error);
|
||||
g_assert_no_error(error);
|
||||
g_assert_true(ret);
|
||||
ret = fu_context_load_hwinfo(ctx, FU_CONTEXT_HWID_FLAG_NONE, &error);
|
||||
ret = fu_context_load_hwinfo(ctx, progress, FU_CONTEXT_HWID_FLAG_NONE, &error);
|
||||
g_assert_no_error(error);
|
||||
g_assert_true(ret);
|
||||
|
||||
while ((basename = g_dir_read_name(dir)) != NULL) {
|
||||
g_autofree gchar *fn = g_build_filename(path, basename, NULL);
|
||||
g_autoptr(FuProgress) progress = fu_progress_new(G_STRLOC);
|
||||
g_autoptr(FuProgress) progress_local = fu_progress_new(G_STRLOC);
|
||||
g_autoptr(FuUdevDevice) dev = NULL;
|
||||
if (!g_str_has_prefix(basename, "drm_dp_aux"))
|
||||
continue;
|
||||
@ -60,8 +61,10 @@ _test_add_fake_devices_from_dir(FuPlugin *plugin, const gchar *path)
|
||||
fn,
|
||||
NULL);
|
||||
g_debug("creating drm_dp_aux_dev object backed by %s", fn);
|
||||
ret =
|
||||
fu_plugin_runner_backend_device_added(plugin, FU_DEVICE(dev), progress, &error);
|
||||
ret = fu_plugin_runner_backend_device_added(plugin,
|
||||
FU_DEVICE(dev),
|
||||
progress_local,
|
||||
&error);
|
||||
g_assert_no_error(error);
|
||||
g_assert_true(ret);
|
||||
}
|
||||
@ -84,7 +87,7 @@ fu_plugin_synaptics_mst_none_func(void)
|
||||
ret = fu_context_load_quirks(ctx, FU_QUIRKS_LOAD_FLAG_NO_CACHE, &error);
|
||||
g_assert_no_error(error);
|
||||
g_assert_true(ret);
|
||||
ret = fu_context_load_hwinfo(ctx, FU_CONTEXT_HWID_FLAG_NONE, &error);
|
||||
ret = fu_context_load_hwinfo(ctx, progress, FU_CONTEXT_HWID_FLAG_NONE, &error);
|
||||
g_assert_no_error(error);
|
||||
g_assert_true(ret);
|
||||
|
||||
@ -127,7 +130,7 @@ fu_plugin_synaptics_mst_tb16_func(void)
|
||||
ret = fu_context_load_quirks(ctx, FU_QUIRKS_LOAD_FLAG_NO_CACHE, &error);
|
||||
g_assert_no_error(error);
|
||||
g_assert_true(ret);
|
||||
ret = fu_context_load_hwinfo(ctx, FU_CONTEXT_HWID_FLAG_NONE, &error);
|
||||
ret = fu_context_load_hwinfo(ctx, progress, FU_CONTEXT_HWID_FLAG_NONE, &error);
|
||||
g_assert_no_error(error);
|
||||
g_assert_true(ret);
|
||||
|
||||
|
@ -336,7 +336,10 @@ main(int argc, char *argv[])
|
||||
g_autoptr(GError) error_local = NULL;
|
||||
|
||||
/* load SMBIOS */
|
||||
if (!fu_context_load_hwinfo(ctx, FU_CONTEXT_HWID_FLAG_LOAD_ALL, &error_local)) {
|
||||
if (!fu_context_load_hwinfo(ctx,
|
||||
progress,
|
||||
FU_CONTEXT_HWID_FLAG_LOAD_ALL,
|
||||
&error_local)) {
|
||||
g_printerr("failed: %s\n", error_local->message);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
@ -459,15 +462,20 @@ main(int argc, char *argv[])
|
||||
/* progress */
|
||||
fu_progress_set_id(progress, G_STRLOC);
|
||||
fu_progress_add_flag(progress, FU_PROGRESS_FLAG_NO_PROFILE);
|
||||
fu_progress_add_step(progress, FWUPD_STATUS_LOADING, 1, "hwinfo");
|
||||
fu_progress_add_step(progress, FWUPD_STATUS_DEVICE_BUSY, 1, "prepare");
|
||||
fu_progress_add_step(progress, FWUPD_STATUS_DEVICE_WRITE, 98, NULL);
|
||||
fu_progress_add_step(progress, FWUPD_STATUS_DEVICE_BUSY, 1, "cleanup");
|
||||
|
||||
/* load SMBIOS */
|
||||
if (!fu_context_load_hwinfo(ctx, FU_CONTEXT_HWID_FLAG_LOAD_ALL, &error_local)) {
|
||||
if (!fu_context_load_hwinfo(ctx,
|
||||
fu_progress_get_child(progress),
|
||||
FU_CONTEXT_HWID_FLAG_LOAD_ALL,
|
||||
&error_local)) {
|
||||
g_printerr("failed: %s\n", error_local->message);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
fu_progress_step_done(progress);
|
||||
|
||||
/* type is specified, otherwise use default */
|
||||
if (type != NULL) {
|
||||
|
@ -8036,7 +8036,10 @@ fu_engine_load(FuEngine *self, FuEngineLoadFlags flags, FuProgress *progress, GE
|
||||
|
||||
/* load SMBIOS and the hwids */
|
||||
if (flags & FU_ENGINE_LOAD_FLAG_HWINFO) {
|
||||
if (!fu_context_load_hwinfo(self->ctx, FU_CONTEXT_HWID_FLAG_LOAD_ALL, error))
|
||||
if (!fu_context_load_hwinfo(self->ctx,
|
||||
fu_progress_get_child(progress),
|
||||
FU_CONTEXT_HWID_FLAG_LOAD_ALL,
|
||||
error))
|
||||
return FALSE;
|
||||
self->has_hwinfo = TRUE;
|
||||
}
|
||||
|
@ -1988,7 +1988,7 @@ fu_util_export_hwids(FuUtilPrivate *priv, gchar **values, GError **error)
|
||||
}
|
||||
|
||||
/* setup default hwids */
|
||||
if (!fu_context_load_hwinfo(ctx, FU_CONTEXT_HWID_FLAG_LOAD_ALL, error))
|
||||
if (!fu_context_load_hwinfo(ctx, priv->progress, FU_CONTEXT_HWID_FLAG_LOAD_ALL, error))
|
||||
return FALSE;
|
||||
|
||||
/* save all keys */
|
||||
@ -2022,7 +2022,7 @@ fu_util_hwids(FuUtilPrivate *priv, gchar **values, GError **error)
|
||||
fu_hwids_add_value(hwids, hwid_key, tmp);
|
||||
}
|
||||
}
|
||||
if (!fu_context_load_hwinfo(ctx, FU_CONTEXT_HWID_FLAG_LOAD_ALL, error))
|
||||
if (!fu_context_load_hwinfo(ctx, priv->progress, FU_CONTEXT_HWID_FLAG_LOAD_ALL, error))
|
||||
return FALSE;
|
||||
|
||||
/* show debug output */
|
||||
|
Loading…
Reference in New Issue
Block a user