[PATCH i-g-t v3 3/5] lib/igt_sysfs: Update new debug mask requested by user

Pranay Samala pranay.samala at intel.com
Tue Apr 1 09:20:13 UTC 2025


These below changes will update the required debug mask passed by the
user as per the requirement. Before setting the debug mask, it stores
the original mask which will be used to restore the debug mask post
test.

To handle nested updated, update flag is being used. Using this flag the
original debug mask will be read only once to ensure while restoring it,
it should be the original value and not the previous value.

Fixes: 56b91193b825 ("lib/igt_sysfs: Implement dynamic adjustment of debug log level")
Signed-off-by: Pranay Samala <pranay.samala at intel.com>
---
 lib/igt_sysfs.c | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/lib/igt_sysfs.c b/lib/igt_sysfs.c
index e6058a1dd..0df2ab9fc 100644
--- a/lib/igt_sysfs.c
+++ b/lib/igt_sysfs.c
@@ -500,12 +500,14 @@ static void igt_drm_debug_mask_reset_exit_handler(int sig)
 
 /**
  * igt_drm_debug_mask_update:
- * @debug_level: new debug mask to set
+ * @mast_to_set: new debug mask to set
  *
  * This modifies the current drm debug mask to the new value.
  */
-void igt_drm_debug_mask_update(unsigned int new_log_level)
+void igt_drm_debug_mask_update(unsigned int mask_to_set)
 {
+	unsigned int new_debug_mask;
+	static bool debug_mask_read_once = true;
 	char buf[20];
 	int dir;
 
@@ -513,14 +515,20 @@ void igt_drm_debug_mask_update(unsigned int new_log_level)
 	if (dir < 0)
 		return;
 
-	original_debug_mask = igt_drm_debug_mask_get(dir);
-	if (original_debug_mask < 0) {
-		close(dir);
-		return;
+	/* The below flag is used to read the original debug mask only once */
+	if (debug_mask_read_once) {
+		debug_mask_read_once = false;
+		original_debug_mask = igt_drm_debug_mask_get(dir);
+		if (original_debug_mask < 0) {
+			close(dir);
+			return;
+		}
 	}
 
-	igt_debug("Setting DRM debug mask to %d\n", new_log_level);
-	snprintf(buf, sizeof(buf), "%d", new_log_level);
+	new_debug_mask = mask_to_set;
+
+	igt_debug("Setting DRM debug mask to %d\n", new_debug_mask);
+	snprintf(buf, sizeof(buf), "%d", new_debug_mask);
 	igt_assert(igt_sysfs_set(dir, "debug", buf));
 
 	close(dir);
@@ -530,6 +538,7 @@ void igt_drm_debug_mask_update(unsigned int new_log_level)
 	 * if we call this api multiple times
 	 */
 	igt_install_exit_handler(igt_drm_debug_level_reset_exit_handler);
+
 }
 
 /**
-- 
2.34.1



More information about the igt-dev mailing list