Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Pranay Samala <pranay.samala@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: karthik.b.s@intel.com, kunal1.joshi@intel.com,
	bhanuprakash.modem@intel.com, sameer.lattannavar@intel.com,
	pranay.samala@intel.com
Subject: [PATCH i-g-t v2 1/2] lib/igt_sysfs: Implement dynamic adjustment of debug log level
Date: Wed, 10 Jul 2024 14:13:57 +0530	[thread overview]
Message-ID: <20240710084358.744278-2-pranay.samala@intel.com> (raw)
In-Reply-To: <20240710084358.744278-1-pranay.samala@intel.com>

Adjust debug log levels dynamically to prevent machine
disk overflow during excessive test debug logs.

Introduce function to modify log levels as needed,
with an exit handler restoring default settings post-test.

v2:
- Using proper function name to represent its
  functionality (Bhanu)
- Added Documentation for each functions (Bhanu)
- Removed the magic number and instead reading the
  default value first (Bhanu)
- Using recommended apis for better handling (Bhanu)

Signed-off-by: Pranay Samala <pranay.samala@intel.com>
---
 lib/igt_sysfs.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++
 lib/igt_sysfs.h |  4 +++
 2 files changed, 79 insertions(+)

diff --git a/lib/igt_sysfs.c b/lib/igt_sysfs.c
index ffeec1ca2..a3e833798 100644
--- a/lib/igt_sysfs.c
+++ b/lib/igt_sysfs.c
@@ -49,6 +49,8 @@
 #include "igt_io.h"
 #include "intel_chipset.h"
 
+#define PATH "/sys/module/drm/parameters/debug"
+
 /**
  * SECTION:igt_sysfs
  * @short_description: Support code for sysfs features
@@ -412,6 +414,79 @@ int igt_sysfs_get_num_gt(int device)
 	return num_gts;
 }
 
+static int log_level = -1;
+
+/**
+ * igt_debug_level_init:
+ *
+ * This reads the current debug log level of the machine on
+ * which the test is currently executing.
+ *
+ * Returns:
+ * The current log level, or -errno on error.
+ */
+
+int igt_debug_level_init(void)
+{
+	char buf[20];
+	int dir = open(PATH, O_WRONLY);
+
+	if (dir < 0)
+		return -errno;
+
+	igt_assert(igt_sysfs_read(dir, PATH, buf, sizeof(buf) - 1) > 0);
+	log_level = atoi(buf);
+	close(dir);
+	return log_level;
+}
+
+/**
+ * igt_drm_debug_level_reset:
+ *
+ * This modifies the current debug log level of the machine
+ * to the default value post-test.
+ *
+ */
+
+void igt_drm_debug_level_reset(void)
+{
+	char buf[20];
+	int debug_dir = open(PATH, O_WRONLY);
+
+	if (debug_dir < 0)
+		return;
+
+	snprintf(buf, sizeof(buf), "%d", log_level);
+	igt_debug("Resetting Debug value\n");
+	igt_assert_eq(igt_sysfs_write(debug_dir, PATH, buf, strlen(buf)), strlen(buf));
+}
+
+static void igt_debug_exit_handler(int sig)
+{
+	igt_drm_debug_level_reset();
+}
+
+void igt_drm_debug_level_decrement(unsigned int step)
+{
+	char buf[220];
+	int debug_dir = open(PATH, O_WRONLY);
+	int new_log_level;
+
+	if (debug_dir < 0)
+		return;
+
+	if (log_level == -1)
+		return;
+
+	new_log_level = log_level - step;
+	igt_debug("Setting Debug value to %d\n", new_log_level);
+	snprintf(buf, sizeof(buf), "%d", new_log_level);
+	igt_assert_eq(igt_sysfs_write(debug_dir, PATH, buf, strlen(buf)), strlen(buf));
+
+	close(debug_dir);
+	igt_install_exit_handler(igt_debug_exit_handler);
+}
+
 /**
  * igt_sysfs_write:
  * @dir: sysfs directory
diff --git a/lib/igt_sysfs.h b/lib/igt_sysfs.h
index 6c604d939..2c4e34714 100644
--- a/lib/igt_sysfs.h
+++ b/lib/igt_sysfs.h
@@ -138,6 +138,10 @@ void igt_sysfs_set_boolean(int dir, const char *attr, bool value);
 void bind_fbcon(bool enable);
 void fbcon_blink_enable(bool enable);
 
+void igt_drm_debug_level_decrement(unsigned int step);
+void igt_drm_debug_level_reset(void);
+int igt_debug_level_init(void);
+
 /**
  * igt_sysfs_rw_attr:
  * @dir: file descriptor for parent directory
-- 
2.34.1


  reply	other threads:[~2024-07-10  8:47 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-10  8:43 [PATCH i-g-t v2 0/2] Runtime alteration of debuglog level Pranay Samala
2024-07-10  8:43 ` Pranay Samala [this message]
2024-07-10  8:43 ` [PATCH i-g-t v2 2/2] tests/kms_atomic_transition: Reducing debug loglevel dynamically Pranay Samala
2024-07-10 12:38 ` ✓ CI.xeBAT: success for Runtime alteration of debuglog level (rev2) Patchwork
2024-07-10 12:46 ` ✓ Fi.CI.BAT: " Patchwork
2024-07-10 13:34 ` ✗ CI.xeFULL: failure " Patchwork
2024-07-11  8:02 ` ✗ Fi.CI.IGT: " Patchwork

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=20240710084358.744278-2-pranay.samala@intel.com \
    --to=pranay.samala@intel.com \
    --cc=bhanuprakash.modem@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=karthik.b.s@intel.com \
    --cc=kunal1.joshi@intel.com \
    --cc=sameer.lattannavar@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