From: Juha-Pekka Heikkila <juhapekka.heikkila@gmail.com>
To: igt-dev@lists.freedesktop.org
Cc: Jani Nikula <jani.nikula@intel.com>
Subject: [igt-dev] [PATCH i-g-t 3/7] lib/params: overhaul param saving
Date: Tue, 28 Apr 2020 23:22:51 +0300 [thread overview]
Message-ID: <20200428202255.31309-4-juhapekka.heikkila@gmail.com> (raw)
In-Reply-To: <20200428202255.31309-1-juhapekka.heikkila@gmail.com>
From: Jani Nikula <jani.nikula@intel.com>
More generic, use existing functions.
Signed-off-by: Jani Nikula <jani.nikula@intel.com>
Signed-off-by: Juha-Pekka Heikkila <juhapekka.heikkila@gmail.com>
---
lib/igt_params.c | 101 +++++++++++++++++++----------------------------
1 file changed, 41 insertions(+), 60 deletions(-)
diff --git a/lib/igt_params.c b/lib/igt_params.c
index f220e73b..b5ac1266 100644
--- a/lib/igt_params.c
+++ b/lib/igt_params.c
@@ -34,92 +34,74 @@
#include "igt_params.h"
#include "igt_sysfs.h"
-#define MODULE_PARAM_DIR "/sys/module/i915/parameters/"
-#define PARAM_NAME_MAX_SZ 32
-#define PARAM_VALUE_MAX_SZ 16
-#define PARAM_FILE_PATH_MAX_SZ (strlen(MODULE_PARAM_DIR) + PARAM_NAME_MAX_SZ)
-
struct module_param_data {
- char name[PARAM_NAME_MAX_SZ];
- char original_value[PARAM_VALUE_MAX_SZ];
+ char *path;
+ char *name;
+ char *original_value;
struct module_param_data *next;
};
struct module_param_data *module_params = NULL;
-static void igt_module_param_exit_handler(int sig)
+static void igt_params_exit_handler(int sig)
{
- const size_t dir_len = strlen(MODULE_PARAM_DIR);
- char file_path[PARAM_FILE_PATH_MAX_SZ];
struct module_param_data *data;
- int fd;
-
- /* We don't need to assert string sizes on this function since they were
- * already checked before being stored on the lists. Besides,
- * igt_assert() is not AS-Safe. */
- strcpy(file_path, MODULE_PARAM_DIR);
+ int dir;
for (data = module_params; data != NULL; data = data->next) {
- strcpy(file_path + dir_len, data->name);
-
- fd = open(file_path, O_RDWR);
- if (fd >= 0) {
- int size = strlen (data->original_value);
-
- if (size != write(fd, data->original_value, size)) {
- const char msg[] = "WARNING: Module parameters "
- "may not have been reset to their "
- "original values\n";
- assert(write(STDERR_FILENO, msg, sizeof(msg))
- == sizeof(msg));
- }
-
- close(fd);
+ dir = open(data->path, O_RDONLY);
+
+ if (!igt_sysfs_set(dir, data->name, data->original_value)) {
+ const char msg[] = "WARNING: Module parameters "
+ "may not have been reset to their "
+ "original values\n";
+ assert(write(STDERR_FILENO, msg, sizeof(msg))
+ == sizeof(msg));
}
+
+ close(dir);
}
/* free() is not AS-Safe, so we can't call it here. */
}
/**
- * igt_save_module_param:
- * @name: name of the i915.ko module parameter
- * @file_path: full sysfs file path for the parameter
+ * igt_params_save:
+ * @dir: file handle for path
+ * @path: full path to the sysfs directory
+ * @name: name of the sysfs attribute
*
- * Reads the current value of an i915.ko module parameter, saves it on an array,
- * then installs an exit handler to restore it when the program exits.
+ * Reads the current value of a sysfs attribute, saves it on an array, then
+ * installs an exit handler to restore it when the program exits.
*
* It is safe to call this function multiple times for the same parameter.
*
* Notice that this function is called by igt_set_module_param(), so that one -
* or one of its wrappers - is the only function the test programs need to call.
*/
-static void igt_save_module_param(const char *name, const char *file_path)
+static void igt_params_save(int dir, const char *path, const char *name)
{
struct module_param_data *data;
- size_t n;
- int fd;
/* Check if this parameter is already saved. */
for (data = module_params; data != NULL; data = data->next)
- if (strncmp(data->name, name, PARAM_NAME_MAX_SZ) == 0)
+ if (strcmp(data->path, path) == 0 &&
+ strcmp(data->name, name) == 0)
return;
if (!module_params)
- igt_install_exit_handler(igt_module_param_exit_handler);
+ igt_install_exit_handler(igt_params_exit_handler);
data = calloc(1, sizeof (*data));
igt_assert(data);
- strncpy(data->name, name, PARAM_NAME_MAX_SZ - 1);
-
- fd = open(file_path, O_RDONLY);
- igt_assert(fd >= 0);
+ data->path = strdup(path);
+ igt_assert(data->path);
- n = read(fd, data->original_value, PARAM_VALUE_MAX_SZ);
- igt_assert_f(n > 0 && n < PARAM_VALUE_MAX_SZ,
- "Need to increase PARAM_VALUE_MAX_SZ\n");
+ data->name = strdup(name);
+ igt_assert(data->name);
- igt_assert(close(fd) == 0);
+ data->original_value = igt_sysfs_get(dir, name);
+ igt_assert(data->original_value);
data->next = module_params;
module_params = data;
@@ -205,22 +187,21 @@ bool igt_params_set(int device, const char *parameter, const char *fmt, ...)
*/
void igt_set_module_param(const char *name, const char *val)
{
- char file_path[PARAM_FILE_PATH_MAX_SZ];
- size_t len = strlen(val);
- int fd;
+ const char *path = "/sys/module/i915/parameters";
+ int dir;
- igt_assert_f(strlen(name) < PARAM_NAME_MAX_SZ,
- "Need to increase PARAM_NAME_MAX_SZ\n");
- strcpy(file_path, MODULE_PARAM_DIR);
- strcpy(file_path + strlen(MODULE_PARAM_DIR), name);
+ dir = open(path, O_RDONLY);
+ igt_assert(dir >= 0);
- igt_save_module_param(name, file_path);
+ igt_params_save(dir, path, name);
- fd = open(file_path, O_RDWR);
- igt_assert(write(fd, val, len) == len);
- igt_assert(close(fd) == 0);
+ igt_assert(igt_sysfs_set(dir, name, val));
+
+ igt_assert(close(dir) == 0);
}
+#define PARAM_VALUE_MAX_SZ 16
+
/**
* igt_set_module_param_int:
* @name: i915.ko parameter name
--
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-04-28 20:23 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
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 1/7] lib/params: add igt_params.c for module parameter access Juha-Pekka Heikkila
2020-04-28 20:22 ` [igt-dev] [PATCH i-g-t 2/7] lib/params: start renaming functions igt_params_* Juha-Pekka Heikkila
2020-05-05 14:04 ` Arkadiusz Hiler
2020-05-05 18:43 ` Juha-Pekka Heikkila
2020-04-28 20:22 ` Juha-Pekka Heikkila [this message]
2020-05-05 7:05 ` [igt-dev] [PATCH i-g-t 3/7] lib/params: overhaul param saving Petri Latvala
2020-04-28 20:22 ` [igt-dev] [PATCH i-g-t 4/7] lib/params: add igt_params_open() which will return path Juha-Pekka Heikkila
2020-05-05 7:07 ` Petri Latvala
2020-05-05 18:44 ` 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
2020-04-28 20:22 ` [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-05 7:20 ` Petri Latvala
2020-05-05 14:22 ` Arkadiusz Hiler
2020-05-06 7:34 ` Petri Latvala
2020-04-28 20:22 ` [igt-dev] [PATCH i-g-t 7/7] tests/gem_eio: switch to using igt_params_set() Juha-Pekka Heikkila
2020-05-05 7:41 ` Petri Latvala
2020-04-28 21:16 ` [igt-dev] ✓ Fi.CI.BAT: success for Use device dependant module parameters (rev5) Patchwork
2020-04-29 1:42 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork
-- strict thread matches above, loose matches on Subject: below --
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 3/7] lib/params: overhaul param saving Juha-Pekka Heikkila
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=20200428202255.31309-4-juhapekka.heikkila@gmail.com \
--to=juhapekka.heikkila@gmail.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=jani.nikula@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