All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] selftests/bpf: skip get_branch_snapshot in vm
@ 2021-10-06 20:31 Song Liu
  2021-10-06 20:38 ` Song Liu
  2021-10-06 21:35 ` Andrii Nakryiko
  0 siblings, 2 replies; 4+ messages in thread
From: Song Liu @ 2021-10-06 20:31 UTC (permalink / raw)
  To: bpf, netdev; +Cc: ast, daniel, andrii, kernel-team, Song Liu

VMs running on latest kernel support LBR. However, bpf_get_branch_snapshot
couldn't stop the LBR before too many entries are flushed. Skip the test
for VMs before we find a proper fix for VMs.

Read the "flags" line from /proc/cpuinfo, if it contains "hypervisor",
skip test get_branch_snapshot.

Fixes: 025bd7c753aa (selftests/bpf: Add test for bpf_get_branch_snapshot)
Signed-off-by: Song Liu <songliubraving@fb.com>
---
 .../bpf/prog_tests/get_branch_snapshot.c      | 32 +++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/tools/testing/selftests/bpf/prog_tests/get_branch_snapshot.c b/tools/testing/selftests/bpf/prog_tests/get_branch_snapshot.c
index 67e86f8d86775..bf9d47a859449 100644
--- a/tools/testing/selftests/bpf/prog_tests/get_branch_snapshot.c
+++ b/tools/testing/selftests/bpf/prog_tests/get_branch_snapshot.c
@@ -6,6 +6,30 @@
 static int *pfd_array;
 static int cpu_cnt;
 
+static bool is_hypervisor(void)
+{
+	char *line = NULL;
+	bool ret = false;
+	size_t len;
+	FILE *fp;
+
+	fp = fopen("/proc/cpuinfo", "r");
+	if (!fp)
+		return false;
+
+	while (getline(&line, &len, fp) != -1) {
+		if (strstr(line, "flags") == line) {
+			if (strstr(line, "hypervisor") != NULL)
+				ret = true;
+			break;
+		}
+	}
+
+	free(line);
+	fclose(fp);
+	return ret;
+}
+
 static int create_perf_events(void)
 {
 	struct perf_event_attr attr = {0};
@@ -54,6 +78,14 @@ void test_get_branch_snapshot(void)
 	struct get_branch_snapshot *skel = NULL;
 	int err;
 
+	if (is_hypervisor()) {
+		/* As of today, LBR in hypervisor cannot be stopped before
+		 * too many entries are flushed. Skip the test for now in
+		 * hypervisor until we optimize the LBR in hypervisor.
+		 */
+		test__skip();
+		return;
+	}
 	if (create_perf_events()) {
 		test__skip();  /* system doesn't support LBR */
 		goto cleanup;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] selftests/bpf: skip get_branch_snapshot in vm
  2021-10-06 20:31 [PATCH] selftests/bpf: skip get_branch_snapshot in vm Song Liu
@ 2021-10-06 20:38 ` Song Liu
  2021-10-06 21:35 ` Andrii Nakryiko
  1 sibling, 0 replies; 4+ messages in thread
From: Song Liu @ 2021-10-06 20:38 UTC (permalink / raw)
  To: Song Liu
  Cc: bpf, Networking, Alexei Starovoitov, Daniel Borkmann,
	Andrii Nakryiko, Kernel Team

On Wed, Oct 6, 2021 at 1:32 PM Song Liu <songliubraving@fb.com> wrote:
>
> VMs running on latest kernel support LBR. However, bpf_get_branch_snapshot
> couldn't stop the LBR before too many entries are flushed. Skip the test
> for VMs before we find a proper fix for VMs.
>
> Read the "flags" line from /proc/cpuinfo, if it contains "hypervisor",
> skip test get_branch_snapshot.

Forgot to use --subject-prefix. This applies to bpf-next.

Thanks,
Song

>
> Fixes: 025bd7c753aa (selftests/bpf: Add test for bpf_get_branch_snapshot)
> Signed-off-by: Song Liu <songliubraving@fb.com>
> ---
>  .../bpf/prog_tests/get_branch_snapshot.c      | 32 +++++++++++++++++++
>  1 file changed, 32 insertions(+)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/get_branch_snapshot.c b/tools/testing/selftests/bpf/prog_tests/get_branch_snapshot.c
> index 67e86f8d86775..bf9d47a859449 100644
> --- a/tools/testing/selftests/bpf/prog_tests/get_branch_snapshot.c
> +++ b/tools/testing/selftests/bpf/prog_tests/get_branch_snapshot.c
> @@ -6,6 +6,30 @@
>  static int *pfd_array;
>  static int cpu_cnt;
>
> +static bool is_hypervisor(void)
> +{
> +       char *line = NULL;
> +       bool ret = false;
> +       size_t len;
> +       FILE *fp;
> +
> +       fp = fopen("/proc/cpuinfo", "r");
> +       if (!fp)
> +               return false;
> +
> +       while (getline(&line, &len, fp) != -1) {
> +               if (strstr(line, "flags") == line) {
> +                       if (strstr(line, "hypervisor") != NULL)
> +                               ret = true;
> +                       break;
> +               }
> +       }
> +
> +       free(line);
> +       fclose(fp);
> +       return ret;
> +}
> +
>  static int create_perf_events(void)
>  {
>         struct perf_event_attr attr = {0};
> @@ -54,6 +78,14 @@ void test_get_branch_snapshot(void)
>         struct get_branch_snapshot *skel = NULL;
>         int err;
>
> +       if (is_hypervisor()) {
> +               /* As of today, LBR in hypervisor cannot be stopped before
> +                * too many entries are flushed. Skip the test for now in
> +                * hypervisor until we optimize the LBR in hypervisor.
> +                */
> +               test__skip();
> +               return;
> +       }
>         if (create_perf_events()) {
>                 test__skip();  /* system doesn't support LBR */
>                 goto cleanup;
> --
> 2.30.2
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] selftests/bpf: skip get_branch_snapshot in vm
  2021-10-06 20:31 [PATCH] selftests/bpf: skip get_branch_snapshot in vm Song Liu
  2021-10-06 20:38 ` Song Liu
@ 2021-10-06 21:35 ` Andrii Nakryiko
  2021-10-07  0:35   ` Song Liu
  1 sibling, 1 reply; 4+ messages in thread
From: Andrii Nakryiko @ 2021-10-06 21:35 UTC (permalink / raw)
  To: Song Liu
  Cc: bpf, Networking, Alexei Starovoitov, Daniel Borkmann,
	Andrii Nakryiko, Kernel Team

On Wed, Oct 6, 2021 at 1:31 PM Song Liu <songliubraving@fb.com> wrote:
>
> VMs running on latest kernel support LBR. However, bpf_get_branch_snapshot
> couldn't stop the LBR before too many entries are flushed. Skip the test
> for VMs before we find a proper fix for VMs.
>
> Read the "flags" line from /proc/cpuinfo, if it contains "hypervisor",
> skip test get_branch_snapshot.
>
> Fixes: 025bd7c753aa (selftests/bpf: Add test for bpf_get_branch_snapshot)

missing quotes?

> Signed-off-by: Song Liu <songliubraving@fb.com>
> ---
>  .../bpf/prog_tests/get_branch_snapshot.c      | 32 +++++++++++++++++++
>  1 file changed, 32 insertions(+)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/get_branch_snapshot.c b/tools/testing/selftests/bpf/prog_tests/get_branch_snapshot.c
> index 67e86f8d86775..bf9d47a859449 100644
> --- a/tools/testing/selftests/bpf/prog_tests/get_branch_snapshot.c
> +++ b/tools/testing/selftests/bpf/prog_tests/get_branch_snapshot.c
> @@ -6,6 +6,30 @@
>  static int *pfd_array;
>  static int cpu_cnt;
>
> +static bool is_hypervisor(void)
> +{
> +       char *line = NULL;
> +       bool ret = false;
> +       size_t len;
> +       FILE *fp;
> +
> +       fp = fopen("/proc/cpuinfo", "r");
> +       if (!fp)
> +               return false;
> +
> +       while (getline(&line, &len, fp) != -1) {
> +               if (strstr(line, "flags") == line) {

strncmp() would be more explicit. That's what you are trying to do
(prefix match), right?

> +                       if (strstr(line, "hypervisor") != NULL)
> +                               ret = true;
> +                       break;
> +               }
> +       }
> +
> +       free(line);
> +       fclose(fp);
> +       return ret;
> +}
> +
>  static int create_perf_events(void)
>  {
>         struct perf_event_attr attr = {0};
> @@ -54,6 +78,14 @@ void test_get_branch_snapshot(void)
>         struct get_branch_snapshot *skel = NULL;
>         int err;
>
> +       if (is_hypervisor()) {
> +               /* As of today, LBR in hypervisor cannot be stopped before
> +                * too many entries are flushed. Skip the test for now in
> +                * hypervisor until we optimize the LBR in hypervisor.
> +                */
> +               test__skip();
> +               return;
> +       }
>         if (create_perf_events()) {
>                 test__skip();  /* system doesn't support LBR */
>                 goto cleanup;
> --
> 2.30.2
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] selftests/bpf: skip get_branch_snapshot in vm
  2021-10-06 21:35 ` Andrii Nakryiko
@ 2021-10-07  0:35   ` Song Liu
  0 siblings, 0 replies; 4+ messages in thread
From: Song Liu @ 2021-10-07  0:35 UTC (permalink / raw)
  To: Andrii Nakryiko
  Cc: Song Liu, bpf, Networking, Alexei Starovoitov, Daniel Borkmann,
	Andrii Nakryiko, Kernel Team

On Wed, Oct 6, 2021 at 2:36 PM Andrii Nakryiko
<andrii.nakryiko@gmail.com> wrote:
>
> On Wed, Oct 6, 2021 at 1:31 PM Song Liu <songliubraving@fb.com> wrote:
> >
> > VMs running on latest kernel support LBR. However, bpf_get_branch_snapshot
> > couldn't stop the LBR before too many entries are flushed. Skip the test
> > for VMs before we find a proper fix for VMs.
> >
> > Read the "flags" line from /proc/cpuinfo, if it contains "hypervisor",
> > skip test get_branch_snapshot.
> >
> > Fixes: 025bd7c753aa (selftests/bpf: Add test for bpf_get_branch_snapshot)
>
> missing quotes?

Aha, I copied this line from e31eec77e4ab90dcec7d2da93415f839098dc287. Will fix.

>
> > Signed-off-by: Song Liu <songliubraving@fb.com>
> > ---
> >  .../bpf/prog_tests/get_branch_snapshot.c      | 32 +++++++++++++++++++
> >  1 file changed, 32 insertions(+)
> >
> > diff --git a/tools/testing/selftests/bpf/prog_tests/get_branch_snapshot.c b/tools/testing/selftests/bpf/prog_tests/get_branch_snapshot.c
> > index 67e86f8d86775..bf9d47a859449 100644
> > --- a/tools/testing/selftests/bpf/prog_tests/get_branch_snapshot.c
> > +++ b/tools/testing/selftests/bpf/prog_tests/get_branch_snapshot.c
> > @@ -6,6 +6,30 @@
> >  static int *pfd_array;
> >  static int cpu_cnt;
> >
> > +static bool is_hypervisor(void)
> > +{
> > +       char *line = NULL;
> > +       bool ret = false;
> > +       size_t len;
> > +       FILE *fp;
> > +
> > +       fp = fopen("/proc/cpuinfo", "r");
> > +       if (!fp)
> > +               return false;
> > +
> > +       while (getline(&line, &len, fp) != -1) {
> > +               if (strstr(line, "flags") == line) {
>
> strncmp() would be more explicit. That's what you are trying to do
> (prefix match), right?

right... let me fix it in v2.

>
> > +                       if (strstr(line, "hypervisor") != NULL)
> > +                               ret = true;
> > +                       break;
> > +               }
> > +       }
> > +
> > +       free(line);
> > +       fclose(fp);
> > +       return ret;
> > +}
> > +
> >  static int create_perf_events(void)
> >  {
> >         struct perf_event_attr attr = {0};
> > @@ -54,6 +78,14 @@ void test_get_branch_snapshot(void)
> >         struct get_branch_snapshot *skel = NULL;
> >         int err;
> >
> > +       if (is_hypervisor()) {
> > +               /* As of today, LBR in hypervisor cannot be stopped before
> > +                * too many entries are flushed. Skip the test for now in
> > +                * hypervisor until we optimize the LBR in hypervisor.
> > +                */
> > +               test__skip();
> > +               return;
> > +       }
> >         if (create_perf_events()) {
> >                 test__skip();  /* system doesn't support LBR */
> >                 goto cleanup;
> > --
> > 2.30.2
> >

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-10-07  0:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-06 20:31 [PATCH] selftests/bpf: skip get_branch_snapshot in vm Song Liu
2021-10-06 20:38 ` Song Liu
2021-10-06 21:35 ` Andrii Nakryiko
2021-10-07  0:35   ` Song Liu

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.