From: "Michał Winiarski" <michal.winiarski@intel.com>
To: igt-dev@lists.freedesktop.org
Subject: [igt-dev] [CI 2/8] tests/perf: Simplify generic read/write, use sysfs helpers
Date: Thu, 14 Mar 2019 13:50:44 +0100 [thread overview]
Message-ID: <20190314125050.14911-2-michal.winiarski@intel.com> (raw)
In-Reply-To: <20190314125050.14911-1-michal.winiarski@intel.com>
Doing this lets us avoid drm_get_card, which we plan to remove
eventually.
Signed-off-by: Michał Winiarski <michal.winiarski@intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
---
tests/perf.c | 82 +++++++++++++++++++---------------------------------
1 file changed, 30 insertions(+), 52 deletions(-)
diff --git a/tests/perf.c b/tests/perf.c
index 220c52ef..ecbadfcd 100644
--- a/tests/perf.c
+++ b/tests/perf.c
@@ -185,7 +185,6 @@ static int sysfs = -1;
static int pm_fd = -1;
static int stream_fd = -1;
static uint32_t devid;
-static int card = -1;
static int n_eus;
static uint64_t test_metric_set_id = UINT64_MAX;
@@ -259,63 +258,47 @@ lookup_format(int i915_perf_fmt_id)
return i915_perf_fmt_id;
}
-static bool
-try_read_u64_file(const char *file, uint64_t *val)
-{
- char buf[32];
- int fd, n;
-
- fd = open(file, O_RDONLY);
- if (fd < 0)
- return false;
-
- while ((n = read(fd, buf, sizeof(buf) - 1)) < 0 && errno == EINTR)
- ;
- igt_assert(n >= 0);
-
- close(fd);
-
- buf[n] = '\0';
- *val = strtoull(buf, NULL, 0);
-
- return true;
-}
-
static uint64_t
-read_u64_file(const char *file)
+read_u64_file(const char *path)
{
+ FILE *f;
uint64_t val;
- igt_assert_eq(try_read_u64_file(file, &val), true);
+ f = fopen(path, "r");
+ igt_assert(f);
+
+ igt_assert_eq(fscanf(f, "%"PRIu64, &val), 1);
+
+ fclose(f);
return val;
}
static void
-write_u64_file(const char *file, uint64_t val)
+write_u64_file(const char *path, uint64_t val)
{
- char buf[32];
- int fd, len, ret;
+ FILE *f;
- fd = open(file, O_WRONLY);
- igt_assert(fd >= 0);
+ f = fopen(path, "r");
+ igt_assert(f);
- len = snprintf(buf, sizeof(buf), "%"PRIu64, val);
- igt_assert(len > 0);
+ igt_assert(fprintf(f, "%"PRIu64, val) > 0);
- while ((ret = write(fd, buf, len)) < 0 && errno == EINTR)
- ;
- igt_assert_eq(ret, len);
+ fclose(f);
+}
- close(fd);
+static bool
+try_sysfs_read_u64(const char *path, uint64_t *val)
+{
+ return igt_sysfs_scanf(sysfs, path, "%"PRIu64, val) == 1;
}
static unsigned long
-sysfs_read(const char *file)
+sysfs_read(const char *path)
{
unsigned long value;
- igt_assert(igt_sysfs_scanf(sysfs, file, "%lu", &value) == 1);
+ igt_assert(igt_sysfs_scanf(sysfs, path, "%lu", &value) == 1);
return value;
}
@@ -876,7 +859,6 @@ init_sys_info(void)
const char *test_set_uuid = NULL;
char buf[256];
- igt_assert_neq(card, -1);
igt_assert_neq(devid, 0);
timestamp_frequency = get_cs_timestamp_frequency();
@@ -979,12 +961,9 @@ init_sys_info(void)
oa_exp_1_millisec = max_oa_exponent_for_period_lte(1000000);
- snprintf(buf, sizeof(buf),
- "/sys/class/drm/card%d/metrics/%s/id",
- card,
- test_set_uuid);
+ snprintf(buf, sizeof(buf), "metrics/%s/id", test_set_uuid);
- return try_read_u64_file(buf, &test_metric_set_id);
+ return try_sysfs_read_u64(buf, &test_metric_set_id);
}
static int
@@ -3739,10 +3718,10 @@ test_invalid_remove_userspace_config(void)
igt_require(has_i915_perf_userspace_config(drm_fd));
- snprintf(path, sizeof(path), "/sys/class/drm/card%d/metrics/%s/id", card, uuid);
+ snprintf(path, sizeof(path), "metrics/%s/id", uuid);
/* Destroy previous configuration if present */
- if (try_read_u64_file(path, &config_id))
+ if (try_sysfs_read_u64(path, &config_id))
i915_perf_remove_config(drm_fd, config_id);
memset(&config, 0, sizeof(config));
@@ -3799,10 +3778,10 @@ test_create_destroy_userspace_config(void)
igt_require(has_i915_perf_userspace_config(drm_fd));
- snprintf(path, sizeof(path), "/sys/class/drm/card%d/metrics/%s/id", card, uuid);
+ snprintf(path, sizeof(path), "metrics/%s/id", uuid);
/* Destroy previous configuration if present */
- if (try_read_u64_file(path, &config_id))
+ if (try_sysfs_read_u64(path, &config_id))
i915_perf_remove_config(drm_fd, config_id);
memset(&config, 0, sizeof(config));
@@ -3881,9 +3860,9 @@ test_whitelisted_registers_userspace_config(void)
igt_require(has_i915_perf_userspace_config(drm_fd));
- snprintf(path, sizeof(path), "/sys/class/drm/card%d/metrics/%s/id", card, uuid);
+ snprintf(path, sizeof(path), "metrics/%s/id", uuid);
- if (try_read_u64_file(path, &config_id))
+ if (try_sysfs_read_u64(path, &config_id))
i915_perf_remove_config(drm_fd, config_id);
memset(&config, 0, sizeof(config));
@@ -4034,7 +4013,6 @@ test_i915_ref_count(void)
drm_fd = __drm_open_driver(DRIVER_INTEL);
devid = intel_get_drm_devid(drm_fd);
- card = drm_get_card();
/* Note: these global variables are only initialized after calling
* init_sys_info()...
@@ -4111,7 +4089,7 @@ igt_main
igt_require_gem(drm_fd);
devid = intel_get_drm_devid(drm_fd);
- sysfs = igt_sysfs_open(drm_fd, &card);
+ sysfs = igt_sysfs_open(drm_fd, NULL);
igt_require(init_sys_info());
--
2.20.1
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev
next prev parent reply other threads:[~2019-03-14 12:51 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-14 12:50 [igt-dev] [CI 1/8] tests/gem_exec_blt: Drop benchmark mode, use igt_sysfs Michał Winiarski
2019-03-14 12:50 ` Michał Winiarski [this message]
2019-03-18 10:49 ` [igt-dev] [CI 2/8] tests/perf: Simplify generic read/write, use sysfs helpers Chris Wilson
2019-03-18 10:52 ` Chris Wilson
2019-03-14 12:50 ` [igt-dev] [CI 3/8] tests/i915_pm_rps: Use " Michał Winiarski
2019-03-14 12:50 ` [igt-dev] [CI 4/8] lib/igt_device: Introduce igt_device_get_card_index Michał Winiarski
2019-03-14 12:50 ` [igt-dev] [CI 5/8] lib: Kill drm_get_card() Michał Winiarski
2019-03-14 12:50 ` [igt-dev] [CI 6/8] lib/igt_sysfs: Remove idx from sysfs_open Michał Winiarski
2019-03-14 12:50 ` [igt-dev] [CI 7/8] lib/igt_sysfs: Simplify obtaining sysfs path Michał Winiarski
2019-03-14 12:50 ` [igt-dev] [CI 8/8] lib/igt_device: Move intel_get_pci_device under igt_device Michał Winiarski
2019-03-14 13:31 ` [igt-dev] ✗ Fi.CI.BAT: failure for series starting with [CI,1/8] tests/gem_exec_blt: Drop benchmark mode, use igt_sysfs Patchwork
2019-03-14 13:39 ` Patchwork
2019-03-18 8:55 ` [igt-dev] ✓ Fi.CI.BAT: success for series starting with [CI,1/8] tests/gem_exec_blt: Drop benchmark mode, use igt_sysfs (rev3) Patchwork
2019-03-18 10:41 ` [igt-dev] ✗ Fi.CI.IGT: failure " Patchwork
-- strict thread matches above, loose matches on Subject: below --
2019-03-19 10:15 [igt-dev] [CI 1/8] tests/gem_exec_blt: Drop benchmark mode, use igt_sysfs Michał Winiarski
2019-03-19 10:15 ` [igt-dev] [CI 2/8] tests/perf: Simplify generic read/write, use sysfs helpers Michał Winiarski
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=20190314125050.14911-2-michal.winiarski@intel.com \
--to=michal.winiarski@intel.com \
--cc=igt-dev@lists.freedesktop.org \
/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