All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Yucong Sun <fallentree@fb.com>
Cc: bpf <bpf@vger.kernel.org>, Andrii Nakryiko <andrii@kernel.org>,
	Yucong Sun <sunyucong@gmail.com>
Subject: Re: [PATCH bpf-next v6 05/14] selftests/bpf: adding read_perf_max_sample_freq() helper
Date: Fri, 8 Oct 2021 15:27:08 -0700	[thread overview]
Message-ID: <CAEf4BzaWi5FQsES5C72T6FgPbEdxqAfQGTArovY_d2KS_w6-=Q@mail.gmail.com> (raw)
In-Reply-To: <20211006185619.364369-6-fallentree@fb.com>

On Wed, Oct 6, 2021 at 11:56 AM Yucong Sun <fallentree@fb.com> wrote:
>
> From: Yucong Sun <sunyucong@gmail.com>
>
> This patch moved a helper function to test_progs and make all tests
> setting sampling frequency use it to read current perf_max_sample_freq,
> this will avoid triggering EINVAL error.
>
> Signed-off-by: Yucong Sun <sunyucong@gmail.com>
> ---
>  .../selftests/bpf/prog_tests/bpf_cookie.c     |  2 +-
>  .../selftests/bpf/prog_tests/perf_branches.c  |  4 ++--
>  .../selftests/bpf/prog_tests/perf_link.c      |  2 +-
>  .../bpf/prog_tests/stacktrace_build_id_nmi.c  | 19 ++-----------------
>  tools/testing/selftests/bpf/test_progs.c      | 15 +++++++++++++++
>  tools/testing/selftests/bpf/test_progs.h      |  1 +
>  6 files changed, 22 insertions(+), 21 deletions(-)
>

We have trace_helper.c, seems like it would be better to have it
there? I haven't applied this patch yet.

[...]

> @@ -48,6 +31,8 @@ void test_stacktrace_build_id_nmi(void)
>         if (CHECK(err, "skel_load", "skeleton load failed: %d\n", err))
>                 goto cleanup;
>
> +       attr.sample_freq = read_perf_max_sample_freq();
> +
>         pmu_fd = syscall(__NR_perf_event_open, &attr, -1 /* pid */,
>                          0 /* cpu 0 */, -1 /* group id */,
>                          0 /* flags */);
> diff --git a/tools/testing/selftests/bpf/test_progs.c b/tools/testing/selftests/bpf/test_progs.c
> index 2ac922f8aa2c..66825313414b 100644
> --- a/tools/testing/selftests/bpf/test_progs.c
> +++ b/tools/testing/selftests/bpf/test_progs.c
> @@ -1500,3 +1500,18 @@ int main(int argc, char **argv)
>
>         return env.fail_cnt ? EXIT_FAILURE : EXIT_SUCCESS;
>  }
> +
> +__u64 read_perf_max_sample_freq(void)
> +{
> +       __u64 sample_freq = 1000; /* fallback to 1000 on error */

previous default was 5000, message below still claims 5000, what's the
reason for changing it?



> +       FILE *f;
> +       __u32 duration = 0;
> +
> +       f = fopen("/proc/sys/kernel/perf_event_max_sample_rate", "r");
> +       if (f == NULL)
> +               return sample_freq;
> +       CHECK(fscanf(f, "%llu", &sample_freq) != 1, "Get max sample rate",
> +             "return default value: 5000,err %d\n", -errno);
> +       fclose(f);
> +       return sample_freq;
> +}
> diff --git a/tools/testing/selftests/bpf/test_progs.h b/tools/testing/selftests/bpf/test_progs.h
> index b239dc9fcef0..d5ca0d36cc96 100644
> --- a/tools/testing/selftests/bpf/test_progs.h
> +++ b/tools/testing/selftests/bpf/test_progs.h
> @@ -327,6 +327,7 @@ int extract_build_id(char *build_id, size_t size);
>  int kern_sync_rcu(void);
>  int trigger_module_test_read(int read_sz);
>  int trigger_module_test_write(int write_sz);
> +__u64 read_perf_max_sample_freq(void);
>
>  #ifdef __x86_64__
>  #define SYS_NANOSLEEP_KPROBE_NAME "__x64_sys_nanosleep"
> --
> 2.30.2
>

  reply	other threads:[~2021-10-08 22:27 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-06 18:56 [PATCH bpf-next v6 00/14] selftests/bpf: Add parallelism to test_progs Yucong Sun
2021-10-06 18:56 ` [PATCH bpf-next v6 01/14] " Yucong Sun
2021-10-08 22:26   ` Andrii Nakryiko
2021-10-06 18:56 ` [PATCH bpf-next v6 02/14] selftests/bpf: Allow some tests to be executed in sequence Yucong Sun
2021-10-08 22:26   ` Andrii Nakryiko
2021-10-08 23:06     ` sunyucong
2021-10-09  3:17       ` Andrii Nakryiko
2021-10-06 18:56 ` [PATCH bpf-next v6 03/14] selftests/bpf: disable perf rate limiting when running tests Yucong Sun
2021-10-08 22:26   ` Andrii Nakryiko
2021-10-06 18:56 ` [PATCH bpf-next v6 04/14] selftests/bpf: add per worker cgroup suffix Yucong Sun
2021-10-06 18:56 ` [PATCH bpf-next v6 05/14] selftests/bpf: adding read_perf_max_sample_freq() helper Yucong Sun
2021-10-08 22:27   ` Andrii Nakryiko [this message]
2021-10-08 22:49     ` sunyucong
2022-03-08 20:22       ` sunyucong
2021-10-06 18:56 ` [PATCH bpf-next v6 06/14] selftests/bpf: fix race condition in enable_stats Yucong Sun
2021-10-06 18:56 ` [PATCH bpf-next v6 07/14] selftests/bpf: make cgroup_v1v2 use its own port Yucong Sun
2021-10-06 18:56 ` [PATCH bpf-next v6 08/14] selftests/bpf: adding a namespace reset for tc_redirect Yucong Sun
2021-10-08 22:27   ` Andrii Nakryiko
2021-10-08 23:07     ` sunyucong
2021-10-06 18:56 ` [PATCH bpf-next v6 09/14] selftests/bpf: Make uprobe tests use different attach functions Yucong Sun
2021-10-08 22:27   ` Andrii Nakryiko
2021-10-08 22:46     ` sunyucong
2021-10-09  3:13       ` Andrii Nakryiko
2021-10-06 18:56 ` [PATCH bpf-next v6 10/14] selftests/bpf: adding pid filtering for atomics test Yucong Sun
2021-10-06 18:56 ` [PATCH bpf-next v6 11/14] selftests/bpf: adding random delay for send_signal test Yucong Sun
2021-10-08 22:27   ` Andrii Nakryiko
2021-10-06 18:56 ` [PATCH bpf-next v6 12/14] selftests/bpf: Fix pid check in fexit_sleep test Yucong Sun
2021-10-06 18:56 ` [PATCH bpf-next v6 13/14] selftests/bpf: increase loop count for perf_branches Yucong Sun
2021-10-08 22:27   ` Andrii Nakryiko
2021-10-08 22:57     ` sunyucong
2021-10-06 18:56 ` [PATCH bpf-next v6 14/14] selfetest/bpf: make some tests serial Yucong Sun
2021-10-08 22:27   ` Andrii Nakryiko
2021-10-08 22:55     ` sunyucong
2021-10-09  3:14       ` Andrii Nakryiko
2021-10-08 22:26 ` [PATCH bpf-next v6 00/14] selftests/bpf: Add parallelism to test_progs Andrii Nakryiko
2021-10-08 22:42   ` Andrii Nakryiko
2021-10-08 23:37     ` Steven Rostedt
2021-10-09  3:20       ` Andrii Nakryiko
2021-10-09  3:28         ` Steven Rostedt

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='CAEf4BzaWi5FQsES5C72T6FgPbEdxqAfQGTArovY_d2KS_w6-=Q@mail.gmail.com' \
    --to=andrii.nakryiko@gmail.com \
    --cc=andrii@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=fallentree@fb.com \
    --cc=sunyucong@gmail.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 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.