From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ian Rogers <irogers@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Namhyung Kim <namhyung@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>,
Adrian Hunter <adrian.hunter@intel.com>,
Kan Liang <kan.liang@linux.intel.com>,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1 2/2] perf test hwmon_pmu: Fix event file location
Date: Mon, 9 Dec 2024 18:16:39 -0300 [thread overview]
Message-ID: <Z1deN2EUjwsRokn9@x1> (raw)
In-Reply-To: <20241206042306.1055913-2-irogers@google.com>
On Thu, Dec 05, 2024 at 08:23:06PM -0800, Ian Rogers wrote:
> The temp directory is made and a known fake hwmon PMU created within
> it. Prior to this fix the events were being incorrectly written to the
> temp directory rather than the fake PMU directory. This didn't impact
> the test as the directory fd matched the wrong location, but it
> doesn't mirror what a hwmon PMU would actually look like.
With these two files the 'perf test 11' for hwmon is successfully
completed on my system where I previously reported failures.
Thanks, applied,
- Arnaldo
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
> tools/perf/tests/hwmon_pmu.c | 29 ++++++++++++++++++-----------
> 1 file changed, 18 insertions(+), 11 deletions(-)
>
> diff --git a/tools/perf/tests/hwmon_pmu.c b/tools/perf/tests/hwmon_pmu.c
> index f8bcee9660d5..d2b066a2b557 100644
> --- a/tools/perf/tests/hwmon_pmu.c
> +++ b/tools/perf/tests/hwmon_pmu.c
> @@ -65,7 +65,7 @@ static struct perf_pmu *test_pmu_get(char *dir, size_t sz)
> { "temp2_label", "test hwmon event2\n", },
> { "temp2_input", "50000\n", },
> };
> - int dirfd, file;
> + int hwmon_dirfd = -1, test_dirfd = -1, file;
> struct perf_pmu *hwm = NULL;
> ssize_t len;
>
> @@ -76,19 +76,24 @@ static struct perf_pmu *test_pmu_get(char *dir, size_t sz)
> dir[0] = '\0';
> return NULL;
> }
> - dirfd = open(dir, O_DIRECTORY);
> - if (dirfd < 0) {
> + test_dirfd = open(dir, O_PATH|O_DIRECTORY);
> + if (test_dirfd < 0) {
> pr_err("Failed to open test directory \"%s\"\n", dir);
> goto err_out;
> }
>
> /* Create the test hwmon directory and give it a name. */
> - if (mkdirat(dirfd, "hwmon1234", 0755) < 0) {
> + if (mkdirat(test_dirfd, "hwmon1234", 0755) < 0) {
> pr_err("Failed to mkdir hwmon directory\n");
> goto err_out;
> }
> - file = openat(dirfd, "hwmon1234/name", O_WRONLY | O_CREAT, 0600);
> - if (!file) {
> + hwmon_dirfd = openat(test_dirfd, "hwmon1234", O_DIRECTORY);
> + if (hwmon_dirfd < 0) {
> + pr_err("Failed to open test hwmon directory \"%s/hwmon1234\"\n", dir);
> + goto err_out;
> + }
> + file = openat(hwmon_dirfd, "name", O_WRONLY | O_CREAT, 0600);
> + if (file < 0) {
> pr_err("Failed to open for writing file \"name\"\n");
> goto err_out;
> }
> @@ -104,8 +109,8 @@ static struct perf_pmu *test_pmu_get(char *dir, size_t sz)
> for (size_t i = 0; i < ARRAY_SIZE(test_items); i++) {
> const struct test_item *item = &test_items[i];
>
> - file = openat(dirfd, item->name, O_WRONLY | O_CREAT, 0600);
> - if (!file) {
> + file = openat(hwmon_dirfd, item->name, O_WRONLY | O_CREAT, 0600);
> + if (file < 0) {
> pr_err("Failed to open for writing file \"%s\"\n", item->name);
> goto err_out;
> }
> @@ -119,16 +124,18 @@ static struct perf_pmu *test_pmu_get(char *dir, size_t sz)
> }
>
> /* Make the PMU reading the files created above. */
> - hwm = perf_pmus__add_test_hwmon_pmu(dirfd, "hwmon1234", test_hwmon_name);
> + hwm = perf_pmus__add_test_hwmon_pmu(hwmon_dirfd, "hwmon1234", test_hwmon_name);
> if (!hwm)
> pr_err("Test hwmon creation failed\n");
>
> err_out:
> if (!hwm) {
> test_pmu_put(dir, hwm);
> - if (dirfd >= 0)
> - close(dirfd);
> + if (hwmon_dirfd >= 0)
> + close(hwmon_dirfd);
> }
> + if (test_dirfd >= 0)
> + close(test_dirfd);
> return hwm;
> }
>
> --
> 2.47.0.338.g60cca15819-goog
next prev parent reply other threads:[~2024-12-09 21:16 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-06 4:23 [PATCH v1 1/2] perf hwmon_pmu: Use openat rather than dup to refresh directory Ian Rogers
2024-12-06 4:23 ` [PATCH v1 2/2] perf test hwmon_pmu: Fix event file location Ian Rogers
2024-12-09 21:16 ` Arnaldo Carvalho de Melo [this message]
2024-12-09 21:47 ` Namhyung Kim
2024-12-10 13:57 ` Arnaldo Carvalho de Melo
2024-12-11 17:23 ` [PATCH v1 1/2] perf hwmon_pmu: Use openat rather than dup to refresh directory Namhyung Kim
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=Z1deN2EUjwsRokn9@x1 \
--to=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.