From: Juha-Pekka Heikkila <juhapekka.heikkila@gmail.com>
To: igt-dev@lists.freedesktop.org
Cc: Jani Nikula <jani.nikula@intel.com>,
Petri Latvala <petri.latvala@intel.com>
Subject: [igt-dev] [PATCH i-g-t 5/7] igt/params: add generic saving module parameter set
Date: Thu, 7 May 2020 22:09:42 +0300 [thread overview]
Message-ID: <20200507190944.19520-6-juhapekka.heikkila@gmail.com> (raw)
In-Reply-To: <20200507190944.19520-1-juhapekka.heikkila@gmail.com>
From: Jani Nikula <jani.nikula@intel.com>
Add functionality to save original value to be restored by exit
handler and setting new value.
Signed-off-by: Jani Nikula <jani.nikula@intel.com>
Signed-off-by: Juha-Pekka Heikkila <juhapekka.heikkila@gmail.com>
Reviewed-by: Petri Latvala <petri.latvala@intel.com>
---
lib/igt_params.c | 62 +++++++++++++++++++++++++++++++++++++++++-------
lib/igt_params.h | 3 +++
2 files changed, 56 insertions(+), 9 deletions(-)
diff --git a/lib/igt_params.c b/lib/igt_params.c
index fe4b1df3..bc1f6af7 100644
--- a/lib/igt_params.c
+++ b/lib/igt_params.c
@@ -153,6 +153,29 @@ int igt_params_open(int device)
return __igt_params_open(device, NULL);
}
+__attribute__((format(printf, 3, 0)))
+static bool __igt_params_set(int device, const char *parameter,
+ const char *fmt, va_list ap, bool save)
+{
+ char *path = NULL;
+ int dir;
+ int ret;
+
+ dir = __igt_params_open(device, save ? &path : NULL);
+ if (dir < 0)
+ return false;
+
+ if (save)
+ igt_params_save(dir, path, parameter);
+
+ ret = igt_sysfs_vprintf(dir, parameter, fmt, ap);
+
+ close(dir);
+ free(path);
+
+ return ret > 0;
+}
+
/**
* igt_params_set:
* @device: fd of the device
@@ -164,20 +187,41 @@ int igt_params_open(int device)
bool igt_params_set(int device, const char *parameter, const char *fmt, ...)
{
va_list ap;
- int dir;
- int ret;
-
- dir = igt_params_open(device);
- if (dir < 0)
- return false;
+ bool ret;
va_start(ap, fmt);
- ret = igt_sysfs_vprintf(dir, parameter, fmt, ap);
+ ret = __igt_params_set(device, parameter, fmt, ap, false);
va_end(ap);
- close(dir);
+ return ret;
+}
- return ret > 0;
+/**
+ * igt_params_save_and_set:
+ * @device: fd of the device or -1 to default.
+ * @parameter: the name of the parameter to set
+ * @fmt: printf-esque format string
+ *
+ * Save original value to be restored by exit handler. Parameter is first
+ * searched at debugfs/dri/N/<device>_params and if not found will look for
+ * parameter at /sys/module/<device>/parameters.
+ *
+ * Giving -1 here for default device will search for matching device from
+ * debugfs/dri/N where N go from 0 to 63. First device found from debugfs
+ * which exist also at /sys/module/<device> will be 'default'.
+ *
+ * Returns true on success
+ */
+bool igt_params_save_and_set(int device, const char *parameter, const char *fmt, ...)
+{
+ va_list ap;
+ bool ret;
+
+ va_start(ap, fmt);
+ ret = __igt_params_set(device, parameter, fmt, ap, true);
+ va_end(ap);
+
+ return ret;
}
/**
diff --git a/lib/igt_params.h b/lib/igt_params.h
index 52eed77f..ed17f34a 100644
--- a/lib/igt_params.h
+++ b/lib/igt_params.h
@@ -31,6 +31,9 @@ int igt_params_open(int device);
__attribute__((format(printf, 3, 4)))
bool igt_params_set(int device, const char *parameter, const char *fmt, ...);
+__attribute__((format(printf, 3, 4)))
+bool igt_params_save_and_set(int device, const char *parameter, const char *fmt, ...);
+
void igt_set_module_param(const char *name, const char *val);
void igt_set_module_param_int(const char *name, int val);
--
2.26.0
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev
next prev parent reply other threads:[~2020-05-07 19:10 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-07 19:09 [igt-dev] [PATCH i-g-t 0/7] Use device dependant module parameters Juha-Pekka Heikkila
2020-05-07 19:09 ` [igt-dev] [PATCH i-g-t 1/7] lib/params: add igt_params.c for module parameter access Juha-Pekka Heikkila
2020-05-07 19:09 ` [igt-dev] [PATCH i-g-t 2/7] lib/params: start renaming functions igt_params_* Juha-Pekka Heikkila
2020-05-07 19:09 ` [igt-dev] [PATCH i-g-t 3/7] lib/params: overhaul param saving Juha-Pekka Heikkila
2020-05-07 19:09 ` [igt-dev] [PATCH i-g-t 4/7] lib/params: add igt_params_open() which will return path Juha-Pekka Heikkila
2020-05-08 11:07 ` Jani Nikula
2020-05-07 19:09 ` Juha-Pekka Heikkila [this message]
2020-05-07 19:09 ` [igt-dev] [PATCH i-g-t 6/7] igt/params: use igt_params_set_save for igt_set_module_param* Juha-Pekka Heikkila
2020-05-07 19:09 ` [igt-dev] [PATCH i-g-t 7/7] tests/gem_eio: switch to using igt_params_set() Juha-Pekka Heikkila
2020-05-07 21:10 ` [igt-dev] ✗ Fi.CI.BAT: failure for Use device dependant module parameters (rev6) Patchwork
2020-05-08 4:14 ` [igt-dev] ✗ Fi.CI.BAT: failure for Use device dependant module parameters (rev7) Patchwork
2020-05-08 5:00 ` [igt-dev] ✗ Fi.CI.BAT: failure for Use device dependant module parameters (rev8) Patchwork
2020-05-08 7:09 ` [igt-dev] ✓ Fi.CI.BAT: success for Use device dependant module parameters (rev9) Patchwork
2020-05-08 10:05 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork
-- strict thread matches above, loose matches on Subject: below --
2020-04-28 20:22 [igt-dev] [PATCH i-g-t 0/7] Use device dependant module parameters Juha-Pekka Heikkila
2020-04-28 20:22 ` [igt-dev] [PATCH i-g-t 5/7] igt/params: add generic saving module parameter set Juha-Pekka Heikkila
2020-05-05 7:16 ` Petri Latvala
2020-05-05 18:44 ` Juha-Pekka Heikkila
2020-05-05 14:09 ` Arkadiusz Hiler
2020-05-05 18:46 ` Juha-Pekka Heikkila
2020-05-05 20:00 ` Juha-Pekka Heikkila
2020-05-06 9:05 ` Arkadiusz Hiler
2020-05-06 9:54 ` Juha-Pekka Heikkila
2020-05-06 10:09 ` Petri Latvala
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=20200507190944.19520-6-juhapekka.heikkila@gmail.com \
--to=juhapekka.heikkila@gmail.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=jani.nikula@intel.com \
--cc=petri.latvala@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