public inbox for igt-dev@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Jonathan Cavitt <jonathan.cavitt@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: chris.p.wilson@linux.intel.com, jonathan.cavitt@intel.com,
	sandeep.kumar.parupalli@intel.com
Subject: [igt-dev] [PATCH i-g-t] lib/igt_kmod: Allow some leeway in igt_kmod_unload_r
Date: Wed, 18 Jan 2023 12:03:44 -0800	[thread overview]
Message-ID: <20230118200344.795326-1-jonathan.cavitt@intel.com> (raw)

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 20) 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.

Signed-off-by: Jonathan Cavitt <jonathan.cavitt@intel.com>
CC: Stuart Summers <stuart.summers@intel.com>
CC: Sandeep Kumar Parupalli <sandeep.kumar.parupalli@intel.com>
CC: Chris Wilson <chris.p.wilson@linux.intel.com>
Reviewed-by: Chris Wilson <chris.p.wilson@linux.intel.com>
---
 lib/igt_kmod.c | 37 ++++++++++++++++++++++++++++++++++---
 1 file changed, 34 insertions(+), 3 deletions(-)

diff --git a/lib/igt_kmod.c b/lib/igt_kmod.c
index 17090110c..75f1a1035 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,36 @@ 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++) {
+		err = kmod_module_remove_module(kmod, flags);
+
+		/* Only loop in the following cases */
+		if (err != -EBUSY && err != -EAGAIN)
+			break;
+
+		igt_debug("Module %s failed to unload with err: %d on attempt: %i\n",
+			  mod_name, err, tries + 1);
+
+		if (tries < MAX_TRIES - 1)
+			usleep(SLEEP_DURATION);
+	}
+
+	if (err == -ENOENT)
+		igt_debug("Module %s could not be found or does not exist. err: %d\n",
+			  mod_name, err);
+	else if (err == -ENOTSUP)
+		igt_debug("Module %s cannot be unloaded. err: %d\n",
+			  mod_name, err);
+	else if (err)
+		igt_debug("Module %s failed to unload with err: %d after ~%.1fms\n",
+			  mod_name, err, SLEEP_DURATION*tries/1000.);
+	else if (tries)
+		igt_debug("Module %s unload took ~%.1fms over %i attempts\n",
+			  mod_name, SLEEP_DURATION*tries/1000., tries + 1);
+	else
+		igt_debug("Module %s unloaded immediately\n", mod_name);
+
+	return err;
 }
 
 /**
-- 
2.25.1

             reply	other threads:[~2023-01-18 20:08 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-18 20:03 Jonathan Cavitt [this message]
2023-01-18 21:04 ` [igt-dev] ✓ Fi.CI.BAT: success for lib/igt_kmod: Allow some leeway in igt_kmod_unload_r (rev4) Patchwork
2023-01-19 18:53 ` [igt-dev] ✗ Fi.CI.IGT: failure " Patchwork
2023-01-23 13:56   ` Kamil Konieczny
2023-01-24  3:33     ` Yedireswarapu, SaiX Nandan
2023-01-24  2:18 ` [igt-dev] ✓ Fi.CI.IGT: success " Patchwork
  -- strict thread matches above, loose matches on Subject: below --
2023-01-18 16:06 [igt-dev] [PATCH i-g-t] lib/igt_kmod: Allow some leeway in igt_kmod_unload_r Jonathan Cavitt
2023-01-18 19:32 ` Kamil Konieczny
2023-01-18 19:56   ` Cavitt, Jonathan
2023-01-17 18:03 Jonathan Cavitt
2023-01-18 13:10 ` Kamil Konieczny
2023-01-09 19:25 Jonathan Cavitt
2023-01-09 19:33 ` Cavitt, Jonathan
2023-01-17 16:06 ` Kamil Konieczny
2023-01-17 17:56   ` Cavitt, Jonathan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230118200344.795326-1-jonathan.cavitt@intel.com \
    --to=jonathan.cavitt@intel.com \
    --cc=chris.p.wilson@linux.intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=sandeep.kumar.parupalli@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox