Skip to contentSkip to conversation

lib/igt_sysfs: add asserting helpers for read/write operations

PATCH Superseded Lukasz Laguna 1 participant 1 message Jul 11, 2023 Library code

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 lib/igt_sysfs: add asserting helpers for read/write operations

Prefix names of existing, non-asserting helpers with "__":

- igt_sysfs_get_u32 -> __igt_sysfs_get_u32
- igt_sysfs_set_u32 -> __igt_sysfs_set_u32
- igt_sysfs_get_u64 -> __igt_sysfs_get_u64
- igt_sysfs_set_u64 -> __igt_sysfs_set_u64
- igt_sysfs_get_boolean -> __igt_sysfs_get_boolean
- igt_sysfs_set_boolean -> __igt_sysfs_set_boolean

Replace all calls to don't introduce any functional changes in the existing code.

Additionally, reimplement non-asserting get helpers to return boolean result of the read operation and store the read value via pointer passed as function parameter. In previous implementation, it wasn't possible to distinguish if returned zero was a read value or failure on a read attempt.

On the occasion, fix a typo in modified debug message.

---
 lib/i915/gem_submission.c      |   4 +-
 lib/igt_aux.c                  |   3 +-
 lib/igt_pm.c                   |   2 +-
 lib/igt_sysfs.c                | 220 +++++++++++++++++++++++++--------
 lib/igt_sysfs.h                |  12 +-
 tests/i915/i915_pm_dc.c        |   6 +-
 tests/i915/i915_pm_freq_mult.c |  42 ++++---
 tests/i915/i915_pm_rps.c       |  32 ++---
 tests/i915/i915_power.c        |   9 +-
 tests/i915/perf_pmu.c          |  45 ++++---
 tests/kms_prime.c              |   2 +-
 tests/nouveau_crc.c            |   7 +-
 12 files changed, 260 insertions(+), 124 deletions(-)
lib/i915/gem_submission.c +3 -1
index adf5eb394..7d1c3970f 100644
@@ -65,12 +65,14 @@ unsigned gem_submission_method(int fd)
 	const int gen = intel_gen(intel_get_drm_devid(fd));
 	unsigned method = GEM_SUBMISSION_RINGBUF;
 	int dir;
+	uint32_t value = 0;
 
 	dir = igt_params_open(fd);
 	if (dir < 0)
 		return 0;
 
-	if (igt_sysfs_get_u32(dir, "enable_guc") & 1) {
+	__igt_sysfs_get_u32(dir, "enable_guc", &value);
+	if (value & 1) {
 		method = GEM_SUBMISSION_GUC;
 	} else if (gen >= 8) {
 		method = GEM_SUBMISSION_EXECLISTS;
lib/igt_aux.c +1 -2
index fd5103043..6a72eb5e5 100644
@@ -953,8 +953,7 @@ static void igt_aux_enable_pm_suspend_dbg(int power_dir)
 	if (sysfs_fd > 0) {
 		__console_suspend_saved_state = igt_sysfs_get_boolean(sysfs_fd, "console_suspend");
 
-		if (!igt_sysfs_set_boolean(sysfs_fd, "console_suspend", CONSOLE_SUSPEND_DISABLE))
-			igt_warn("Unable to disable console suspend\n");
+		igt_sysfs_set_boolean(sysfs_fd, "console_suspend", CONSOLE_SUSPEND_DISABLE);
 
 	} else {
 		igt_warn("Unable to open printk parameters Err:%d\n", errno);
lib/igt_pm.c +1 -1
index 18c84bf3a..ba591f0f8 100644
@@ -1415,5 +1415,5 @@ void igt_pm_ignore_slpc_efficient_freq(int i915, int gtfd, bool val)
 		return;
 
 	igt_require(igt_sysfs_has_attr(gtfd, "slpc_ignore_eff_freq"));
-	igt_assert(igt_sysfs_set_u32(gtfd, "slpc_ignore_eff_freq", val));
+	igt_sysfs_set_u32(gtfd, "slpc_ignore_eff_freq", val);
 }
lib/igt_sysfs.c +167 -53

325 lines not on this page · raw message

lib/igt_sysfs.h +9 -3
index d507fde8b..0087c03b7 100644
@@ -119,14 +119,20 @@ int igt_sysfs_vprintf(int dir, const char *attr, const char *fmt, va_list ap)
 int igt_sysfs_printf(int dir, const char *attr, const char *fmt, ...)
 	__attribute__((format(printf,3,4)));
 
+bool __igt_sysfs_get_u32(int dir, const char *attr, uint32_t *value);
 uint32_t igt_sysfs_get_u32(int dir, const char *attr);
-bool igt_sysfs_set_u32(int dir, const char *attr, uint32_t value);
+bool __igt_sysfs_set_u32(int dir, const char *attr, uint32_t value);
+void igt_sysfs_set_u32(int dir, const char *attr, uint32_t value);
 
+bool __igt_sysfs_get_u64(int dir, const char *attr, uint64_t *value);
 uint64_t igt_sysfs_get_u64(int dir, const char *attr);
-bool igt_sysfs_set_u64(int dir, const char *attr, uint64_t value);
+bool __igt_sysfs_set_u64(int dir, const char *attr, uint64_t value);
+void igt_sysfs_set_u64(int dir, const char *attr, uint64_t value);
 
+bool __igt_sysfs_get_boolean(int dir, const char *attr, bool *value);
 bool igt_sysfs_get_boolean(int dir, const char *attr);
-bool igt_sysfs_set_boolean(int dir, const char *attr, bool value);
+bool __igt_sysfs_set_boolean(int dir, const char *attr, bool value);
+void igt_sysfs_set_boolean(int dir, const char *attr, bool value);
 
 void bind_fbcon(bool enable);
 void kick_snd_hda_intel(void);
tests/i915/i915_pm_dc.c +3 -3
index 5069ddcc3..90fe847fc 100644
@@ -533,8 +533,8 @@ static void setup_dc9_dpms(data_t *data, int dc_target)
 	int prev_dc = 0, prev_rpm, sysfs_fd;
 
 	igt_require((sysfs_fd = open(KMS_HELPER, O_RDONLY)) >= 0);
-	kms_poll_saved_state = igt_sysfs_get_boolean(sysfs_fd, "poll");
-	igt_sysfs_set_boolean(sysfs_fd, "poll", KMS_POLL_DISABLE);
+	__igt_sysfs_get_boolean(sysfs_fd, "poll", &kms_poll_saved_state);
+	__igt_sysfs_set_boolean(sysfs_fd, "poll", KMS_POLL_DISABLE);
 	close(sysfs_fd);
 	if (DC9_RESETS_DC_COUNTERS(data->devid)) {
 		prev_dc = read_dc_counter(data->debugfs_fd, dc_target);
@@ -629,7 +629,7 @@ static void kms_poll_state_restore(int sig)
 
 	sysfs_fd = open(KMS_HELPER, O_RDONLY);
 	if (sysfs_fd >= 0) {
-		igt_sysfs_set_boolean(sysfs_fd, "poll", kms_poll_saved_state);
+		__igt_sysfs_set_boolean(sysfs_fd, "poll", kms_poll_saved_state);
 		close(sysfs_fd);
 	}
 }
tests/i915/i915_pm_freq_mult.c +23 -19

94 lines not on this page · raw message

tests/i915/i915_pm_rps.c +16 -16
index 7044fcd81..d9d43e568 100644
@@ -720,7 +720,7 @@ static void fence_order(int i915)
 		.buffer_count = ARRAY_SIZE(obj),
 	};
 	uint64_t wr, rw;
-	int min, max;
+	uint32_t min = 0, max = 0;
 	double freq;
 	int sysfs;
 
@@ -742,14 +742,14 @@ static void fence_order(int i915)
 	 */
 
 	sysfs = igt_sysfs_open(i915);
-	min = igt_sysfs_get_u32(sysfs, "gt_RPn_freq_mhz");
-	max = igt_sysfs_get_u32(sysfs, "gt_RP0_freq_mhz");
+	__igt_sysfs_get_u32(sysfs, "gt_RPn_freq_mhz", &min);
+	__igt_sysfs_get_u32(sysfs, "gt_RP0_freq_mhz", &max);
 	igt_require(max > min);
 
 	/* Only allow ourselves to upclock via waitboosting */
-	igt_sysfs_printf(sysfs, "gt_min_freq_mhz", "%d", min);
-	igt_sysfs_printf(sysfs, "gt_max_freq_mhz", "%d", min);
-	igt_sysfs_printf(sysfs, "gt_boost_freq_mhz", "%d", max);
+	igt_sysfs_printf(sysfs, "gt_min_freq_mhz", "%u", min);
+	igt_sysfs_printf(sysfs, "gt_max_freq_mhz", "%u", min);
+	igt_sysfs_printf(sysfs, "gt_boost_freq_mhz", "%u", max);
 
 	/* Warm up to bind the vma */
 	__fence_order(i915, &obj[0], &execbuf, 0, 0, &freq);
@@ -763,8 +763,8 @@ static void fence_order(int i915)
 	gem_close(i915, obj[0].handle);
 	gem_close(i915, obj[1].handle);
 
-	igt_sysfs_printf(sysfs, "gt_min_freq_mhz", "%d", min);
-	igt_sysfs_printf(sysfs, "gt_max_freq_mhz", "%d", max);
+	igt_sysfs_printf(sysfs, "gt_min_freq_mhz", "%u", min);
+	igt_sysfs_printf(sysfs, "gt_max_freq_mhz", "%u", max);
 
 	close(sysfs);
 
@@ -830,7 +830,7 @@ static void engine_order(int i915)
 	uint64_t forward, backward, both;
 	unsigned int num_engines;
 	const intel_ctx_t *ctx;
-	int min, max;
+	uint32_t min = 0, max = 0;
 	double freq;
 	int sysfs;
 
@@ -862,14 +862,14 @@ static void engine_order(int i915)
 	execbuf.rsvd1 = ctx->id;
 
 	sysfs = igt_sysfs_open(i915);
-	min = igt_sysfs_get_u32(sysfs, "gt_RPn_freq_mhz");
-	max = igt_sysfs_get_u32(sysfs, "gt_RP0_freq_mhz");
+	__igt_sysfs_get_u32(sysfs, "gt_RPn_freq_mhz", &min);
+	__igt_sysfs_get_u32(sysfs, "gt_RP0_freq_mhz", &max);
 	igt_require(max > min);
 
 	/* Only allow ourselves to upclock via waitboosting */
-	igt_sysfs_printf(sysfs, "gt_min_freq_mhz", "%d", min);
-	igt_sysfs_printf(sysfs, "gt_max_freq_mhz", "%d", min);
-	igt_sysfs_printf(sysfs, "gt_boost_freq_mhz", "%d", max);
+	igt_sysfs_printf(sysfs, "gt_min_freq_mhz", "%u", min);
+	igt_sysfs_printf(sysfs, "gt_max_freq_mhz", "%u", min);
+	igt_sysfs_printf(sysfs, "gt_boost_freq_mhz", "%u", max);
 
 	/* Warm up to bind the vma */
 	gem_execbuf(i915, &execbuf);
@@ -893,8 +893,8 @@ static void engine_order(int i915)
 	gem_close(i915, obj[1].handle);
 	intel_ctx_destroy(i915, ctx);
 
-	igt_sysfs_printf(sysfs, "gt_min_freq_mhz", "%d", min);
-	igt_sysfs_printf(sysfs, "gt_max_freq_mhz", "%d", max);
+	igt_sysfs_printf(sysfs, "gt_min_freq_mhz", "%u", min);
+	igt_sysfs_printf(sysfs, "gt_max_freq_mhz", "%u", max);
 
 	close(sysfs);
 
tests/i915/i915_power.c +5 -4
index ed7bef495..ee00cbcd8 100644
@@ -38,7 +38,8 @@ static void sanity(int i915)
 	double idle, busy;
 	igt_spin_t *spin;
 	uint64_t ahnd;
-	int dir, gt, req, act;
+	int dir, gt;
+	uint32_t req = 0, act = 0;
 
 #define DURATION_SEC 2
 
@@ -58,9 +59,9 @@ static void sanity(int i915)
 	igt_spin_busywait_until_started(spin);
 	busy = measure_power(&pwr, DURATION_SEC);
 	i915_for_each_gt(i915, dir, gt) {
-		req = igt_sysfs_get_u32(dir, "rps_cur_freq_mhz");
-		act = igt_sysfs_get_u32(dir, "rps_act_freq_mhz");
-		igt_info("gt %d: req MHz: %d, act MHz: %d\n", gt, req, act);
+		__igt_sysfs_get_u32(dir, "rps_cur_freq_mhz", &req);
+		__igt_sysfs_get_u32(dir, "rps_act_freq_mhz", &act);
+		igt_info("gt %d: req MHz: %u, act MHz: %u\n", gt, req, act);
 	}
 	igt_free_spins(i915);
 	put_ahnd(ahnd);
tests/i915/perf_pmu.c +26 -19

77 lines not on this page · raw message

tests/kms_prime.c +1 -1
index 52f587961..dedbf6233 100644
@@ -341,7 +341,7 @@ static void kms_poll_state_restore(void)
 	int sysfs_fd;
 
 	igt_assert((sysfs_fd = open(KMS_HELPER, O_RDONLY)) >= 0);
-	igt_sysfs_set_boolean(sysfs_fd, "poll", kms_poll_saved_state);
+	__igt_sysfs_set_boolean(sysfs_fd, "poll", kms_poll_saved_state);
 	close(sysfs_fd);
 
 }
tests/nouveau_crc.c +5 -2
index d5aa0e650..c94972318 100644
@@ -264,15 +264,18 @@ static void test_ctx_flip_threshold_reset_after_capture(data_t *data)
 {
 	igt_pipe_crc_t *pipe_crc;
 	const int fd = data->drm_fd;
+	uint32_t value = 0;
 
 	pipe_crc = igt_pipe_crc_new(fd, data->pipe, IGT_PIPE_CRC_SOURCE_AUTO);
 
 	set_crc_flip_threshold(data, 5);
 	igt_pipe_crc_start(pipe_crc);
-	igt_assert_eq(igt_sysfs_get_u32(data->nv_crc_dir, "flip_threshold"), 5);
+	__igt_sysfs_get_u32(data->nv_crc_dir, "flip_threshold", &value);
+	igt_assert_eq(value, 5);
 	igt_pipe_crc_stop(pipe_crc);
 
-	igt_assert_neq(igt_sysfs_get_u32(data->nv_crc_dir, "flip_threshold"), 5);
+	__igt_sysfs_get_u32(data->nv_crc_dir, "flip_threshold", &value);
+	igt_assert_neq(value, 5);
 	igt_pipe_crc_free(pipe_crc);
 }
 
Signature · 1 line
2.40.0