From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by gabe.freedesktop.org (Postfix) with ESMTPS id BA1E010E46E for ; Mon, 9 Jan 2023 19:30:10 +0000 (UTC) From: Jonathan Cavitt To: igt-dev@lists.freedesktop.org Date: Mon, 9 Jan 2023 11:25:36 -0800 Message-Id: <20230109192536.3395428-1-jonathan.cavitt@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [igt-dev] [PATCH i-g-t] lib/igt_kmod: Allow some leeway in igt_kmod_unload_r List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jonathan.cavitt@intel.com Errors-To: igt-dev-bounces@lists.freedesktop.org Sender: "igt-dev" List-ID: kmod_module_remove_module occasionally returns EAGAIN for mei_gsc in the setup of some gem_lmem_swapping subtests. Just because EAGAIN is returned doesn't mean the module is lost and unable to be unloaded. Try again some number of times (currently 10) before giving up. Retries will occur for -EBUSY and -EAGAIN, as these imply the system is waiting for the target module can simply be waited for. All other errors exit immediately, but as the context for each error informs their relative severity, no warnings will be issued. References: VLK-30287, VLK-39629 Signed-off-by: Jonathan Cavitt CC: Stuart Summers CC: Sandeep Kumar Parupalli CC: Chris Wilson Reviewed-by: Chris Wilson --- lib/igt_kmod.c | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/lib/igt_kmod.c b/lib/igt_kmod.c index 17090110c..c840f9a17 100644 --- a/lib/igt_kmod.c +++ b/lib/igt_kmod.c @@ -253,8 +253,11 @@ out: static int igt_kmod_unload_r(struct kmod_module *kmod, unsigned int flags) { +#define MAX_TRIES 20 +#define SLEEP_DURATION 500000 struct kmod_list *holders, *pos; - int err = 0; + int err, tries; + const char *mod_name = kmod_module_get_name(kmod); holders = kmod_module_get_holders(kmod); kmod_list_foreach(pos, holders) { @@ -269,7 +272,6 @@ static int igt_kmod_unload_r(struct kmod_module *kmod, unsigned int flags) return err; if (igt_kmod_is_loading(kmod)) { - const char *mod_name = kmod_module_get_name(kmod); igt_debug("%s still initializing\n", mod_name); err = igt_wait(!igt_kmod_is_loading(kmod), 10000, 100); if (err < 0) { @@ -279,7 +281,40 @@ static int igt_kmod_unload_r(struct kmod_module *kmod, unsigned int flags) } } - return kmod_module_remove_module(kmod, flags); + for (tries = 0; tries < MAX_TRIES; tries++) { + bool loop = false; + + err = kmod_module_remove_module(kmod, flags); + + /* Only loop in the following cases */ + switch (err) { + case -EBUSY: + case -EAGAIN: + /* Waiting for module to be available */ + loop = true; + break; + default: + break; + } + if (!loop) + break; + + igt_debug("Module %s failed to unload with err: %d on attempt: %i\n", + mod_name, err, tries + 1); + + usleep(SLEEP_DURATION); + } + + if (err == -ENOENT) + igt_debug("Module %s could not be found. Skipping.\n", mod_name); + else if (err) + igt_info("Module %s failed to unload with err: %d after ~%.1fms\n", + mod_name, err, SLEEP_DURATION*tries/1000.); + else if (tries) + igt_info("Module %s unload took ~%.1fms over %i attempts\n", + mod_name, SLEEP_DURATION*tries/1000., tries + 1); + + return err; } /** -- 2.25.1