freedreno: sanitize device names for config name usage

Names used in libconfig's configuration files only allow alphanumerics,
underscores, dashes and asterisks. Freedreno device names, used as names
in fdperf.cfg, can also contain other characters, currently spaces and
plus characters. Not accounting for those makes it impossible to store
fdperf configuration across separate runs.

Once the Freedreno device name is retrieved, it's now sanitized for use
in fdperf.cfg. Unsupported characters are converted to underscores.

Signed-off-by: Zan Dobersek <zdobersek@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/31577>
This commit is contained in:
Zan Dobersek 2024-10-07 15:20:10 +02:00 committed by Marge Bot
parent d741a6766e
commit 61ad069a21

View file

@ -5,6 +5,7 @@
*/
#include <assert.h>
#include <ctype.h>
#include <curses.h>
#include <err.h>
#include <inttypes.h>
@ -828,6 +829,20 @@ setup_counter_groups(const struct fd_perfcntr_group *groups)
static config_t cfg;
static config_setting_t *setting;
static void
config_sanitize_device_name(char *name)
{
/* libconfig names allow alphanumeric characters, dashes, underscores and
* asterisks. Anything else in the device name (most commonly spaces and
* plus characters) should be converted to underscores.
*/
for (char *s = name; *s; ++s) {
if (isalnum(*s) || *s == '-' || *s == '_' || *s == '*')
continue;
*s = '_';
}
}
static void
config_save(void)
{
@ -866,6 +881,7 @@ config_restore(void)
/* per device settings: */
char device_name[64];
snprintf(device_name, sizeof(device_name), "%s", fd_dev_name(dev.dev_id));
config_sanitize_device_name(device_name);
setting = config_setting_get_member(root, device_name);
if (!setting)
setting = config_setting_add(root, device_name, CONFIG_TYPE_GROUP);