[igt-dev] [PATCH i-g-t] tools/intel_guc_logger: Update to use new relay mechanism

Robert M. Fosha robert.m.fosha at intel.com
Mon Sep 30 20:58:50 UTC 2019


Update the GuC logger tool to use new GuC relay logging mechanism and
correct logging verbosity levels. Verbosity level is written and stored
in i915_guc_log_level file instead of the GuC logging control file.
Opening the control file creates the relay log file. Writing a '1' to the
control file starts logging, and writing a '0' to the control file flushes
the log.

Cc: Matthew Brost <matthew.brost at intel.com>
Cc: Daniele Ceraolo Spurio <daniele.ceraolospurio at intel.com>
Signed-off-by: Robert M. Fosha <robert.m.fosha at intel.com>
---
 tools/intel_guc_logger.c | 76 ++++++++++++++++++++++++----------------
 1 file changed, 45 insertions(+), 31 deletions(-)

diff --git a/tools/intel_guc_logger.c b/tools/intel_guc_logger.c
index 5f1de8db..c74824ae 100644
--- a/tools/intel_guc_logger.c
+++ b/tools/intel_guc_logger.c
@@ -56,53 +56,61 @@
  */
 #define NUM_SUBBUFS 100
 
-#define RELAY_FILE_NAME  "guc_log"
+#define RELAY_FILE_NAME  "guc_log0"
 #define DEFAULT_OUTPUT_FILE_NAME  "guc_log_dump.dat"
-#define CONTROL_FILE_NAME "i915_guc_log_control"
+#define LOG_LEVEL_FILE_NAME "i915_guc_log_level"
+#define CONTROL_FILE_NAME "i915_guc_log_relay"
 
 char *read_buffer;
 char *out_filename;
 int poll_timeout = 2; /* by default 2ms timeout */
 pthread_mutex_t mutex;
 pthread_t flush_thread;
-int verbosity_level = 3; /* by default capture logs at max verbosity */
+int verbosity_level = 5; /* by default capture logs at max verbosity */
 uint32_t produced, consumed;
 uint64_t total_bytes_written;
 int num_buffers = NUM_SUBBUFS;
-int relay_fd, outfile_fd = -1;
+int log_level_fd, control_fd, relay_fd, outfile_fd = -1;
 uint32_t test_duration, max_filesize;
 pthread_cond_t underflow_cond, overflow_cond;
 bool stop_logging, discard_oldlogs, capturing_stopped;
 
-static void guc_log_control(bool enable, uint32_t log_level)
+static void set_log_verbosity(void)
 {
-	int control_fd;
-	char data[19];
-	uint64_t val;
+	char data[2];
 	int ret;
 
-	igt_assert_lte(log_level, 3);
+	log_level_fd = igt_debugfs_open(-1, LOG_LEVEL_FILE_NAME, O_WRONLY);
+	igt_assert_f(control_fd >= 0,
+		     "couldn't open the guc log level file\n");
 
-	control_fd = igt_debugfs_open(-1, CONTROL_FILE_NAME, O_WRONLY);
-	igt_assert_f(control_fd >= 0, "couldn't open the guc log control file\n");
+	ret = snprintf(data, sizeof(data), "%d", verbosity_level);
+	ret = write(log_level_fd, data, ret);
+	igt_assert_f(ret > 0,
+		     "couldn't write to the log level file\n");
 
-	/*
-	 * i915 expects GuC log level to be specified as:
-	 * 0: disabled
-	 * 1: enabled (verbosity level 0 = min)
-	 * 2: enabled (verbosity level 1)
-	 * 3: enabled (verbosity level 2)
-	 * 4: enabled (verbosity level 3 = max)
-	 */
-	val = enable ? log_level + 1 : 0;
+	close(log_level_fd);
+}
+
+static void guc_log_control(bool enable)
+{
+	const char control_val[] = "1";
+	int ret;
 
-	ret = snprintf(data, sizeof(data), "0x%" PRIx64, val);
-	igt_assert(ret > 2 && ret < sizeof(data));
+	if (enable) {
+		set_log_verbosity();
 
-	ret = write(control_fd, data, ret);
-	igt_assert_f(ret > 0, "couldn't write to the log control file\n");
+		control_fd = igt_debugfs_open(-1, CONTROL_FILE_NAME, O_WRONLY);
+		igt_assert_f(control_fd >= 0,
+			     "couldn't open the guc log control file\n");
 
-	close(control_fd);
+		/* Write '1' to control file to start logging. */
+		ret = write(control_fd, control_val, 1);
+		igt_assert_f(ret > 0,
+			     "couldn't write to the log control file\n");
+	} else {
+		close(control_fd);
+	}
 }
 
 static void int_sig_handler(int sig)
@@ -115,8 +123,13 @@ static void int_sig_handler(int sig)
 static void pull_leftover_data(void)
 {
 	unsigned int bytes_read = 0;
+	const char control_val[] = "0";
 	int ret;
 
+	/* Write '0' to control file to flush relay log. */
+	ret = write(control_fd, control_val, 1);
+	igt_assert_f(ret >= 0, "couldn't write to the log control file\n");
+
 	do {
 		/* Read the logs from relay buffer */
 		ret = read(relay_fd, read_buffer, SUBBUF_SIZE);
@@ -321,7 +334,7 @@ static void init_main_thread(void)
 	/* Enable the logging, it may not have been enabled from boot and so
 	 * the relay file also wouldn't have been created.
 	 */
-	guc_log_control(true, verbosity_level);
+	guc_log_control(true);
 
 	open_relay_file();
 	open_output_file();
@@ -334,7 +347,7 @@ static int parse_options(int opt, int opt_index, void *data)
 	switch(opt) {
 	case 'v':
 		verbosity_level = atoi(optarg);
-		igt_assert_f(verbosity_level >= 0 && verbosity_level <= 3, "invalid input for -v option\n");
+		igt_assert_f(verbosity_level >= 1 && verbosity_level <= 5, "invalid input for -v option\n");
 		igt_debug("verbosity level to be used is %d\n", verbosity_level);
 		break;
 	case 'o':
@@ -386,7 +399,7 @@ static void process_command_line(int argc, char **argv)
 	};
 
 	const char *help =
-		"  -v --verbosity=level   verbosity level of GuC logging (0-3)\n"
+		"  -v --verbosity=level   verbosity level of GuC logging (1-5)\n"
 		"  -o --outputfile=name   name of the output file, including the location, where logs will be stored\n"
 		"  -b --buffers=num       number of buffers to be maintained on logger side for storing logs\n"
 		"  -t --testduration=sec  max duration in seconds for which the logger should run\n"
@@ -452,9 +465,6 @@ int main(int argc, char **argv)
 		pull_data();
 	} while (!stop_logging);
 
-	/* Pause logging on the GuC side */
-	guc_log_control(false, 0);
-
 	/* Signal flusher thread to make an exit */
 	capturing_stopped = 1;
 	pthread_cond_signal(&underflow_cond);
@@ -463,8 +473,12 @@ int main(int argc, char **argv)
 	pull_leftover_data();
 	igt_info("total bytes written %" PRIu64 "\n", total_bytes_written);
 
+	/* Stop logging on the GuC side */
+	guc_log_control(false);
+
 	free(read_buffer);
 	close(relay_fd);
 	close(outfile_fd);
+
 	igt_exit();
 }
-- 
2.21.0.5.gaeb582a983



More information about the igt-dev mailing list