All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel T. Lee" <danieltimlee@gmail.com>
To: "Daniel Borkmann" <daniel@iogearbox.net>,
	"Alexei Starovoitov" <ast@kernel.org>,
	"Andrii Nakryiko" <andrii@kernel.org>, brakmo <brakmo@fb.com>,
	"Jesper Dangaard Brouer" <brouer@redhat.com>,
	"Andrii Nakryiko" <andrii.nakryiko@gmail.com>,
	"Lorenzo Bianconi" <lorenzo@kernel.org>,
	"David Ahern" <dsa@cumulusnetworks.com>,
	"Yonghong Song" <yhs@fb.com>,
	"Toke Høiland-Jørgensen" <toke@redhat.com>,
	"Ira Weiny" <ira.weiny@intel.com>, "Thomas Graf" <tgraf@suug.ch>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Martin KaFai Lau" <kafai@fb.com>,
	"John Fastabend" <john.fastabend@gmail.com>
Cc: bpf@vger.kernel.org, netdev@vger.kernel.org,
	Xdp <xdp-newbies@vger.kernel.org>
Subject: [PATCH bpf-next 1/9] selftests: bpf: move tracing helpers to trace_helper
Date: Tue, 17 Nov 2020 14:56:36 +0000	[thread overview]
Message-ID: <20201117145644.1166255-2-danieltimlee@gmail.com> (raw)
In-Reply-To: <20201117145644.1166255-1-danieltimlee@gmail.com>

Under the samples/bpf directory, similar tracing helpers are
fragmented around. To keep consistent of tracing programs, this commit
moves the helper and define locations to increase the reuse of each
helper function.

Signed-off-by: Daniel T. Lee <danieltimlee@gmail.com>

---
 samples/bpf/Makefile                        |  2 +-
 samples/bpf/hbm.c                           | 51 ++++-----------------
 tools/testing/selftests/bpf/trace_helpers.c | 33 ++++++++++++-
 tools/testing/selftests/bpf/trace_helpers.h |  3 ++
 4 files changed, 45 insertions(+), 44 deletions(-)

diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile
index aeebf5d12f32..3e83cd5ca1c2 100644
--- a/samples/bpf/Makefile
+++ b/samples/bpf/Makefile
@@ -110,7 +110,7 @@ xdp_fwd-objs := xdp_fwd_user.o
 task_fd_query-objs := bpf_load.o task_fd_query_user.o $(TRACE_HELPERS)
 xdp_sample_pkts-objs := xdp_sample_pkts_user.o $(TRACE_HELPERS)
 ibumad-objs := bpf_load.o ibumad_user.o $(TRACE_HELPERS)
-hbm-objs := bpf_load.o hbm.o $(CGROUP_HELPERS)
+hbm-objs := bpf_load.o hbm.o $(CGROUP_HELPERS) $(TRACE_HELPERS)
 
 # Tell kbuild to always build the programs
 always-y := $(tprogs-y)
diff --git a/samples/bpf/hbm.c b/samples/bpf/hbm.c
index 400e741a56eb..b9f9f771dd81 100644
--- a/samples/bpf/hbm.c
+++ b/samples/bpf/hbm.c
@@ -48,6 +48,7 @@
 
 #include "bpf_load.h"
 #include "bpf_rlimit.h"
+#include "trace_helpers.h"
 #include "cgroup_helpers.h"
 #include "hbm.h"
 #include "bpf_util.h"
@@ -65,51 +66,12 @@ bool no_cn_flag;
 bool edt_flag;
 
 static void Usage(void);
-static void read_trace_pipe2(void);
 static void do_error(char *msg, bool errno_flag);
 
-#define DEBUGFS "/sys/kernel/debug/tracing/"
-
 struct bpf_object *obj;
 int bpfprog_fd;
 int cgroup_storage_fd;
 
-static void read_trace_pipe2(void)
-{
-	int trace_fd;
-	FILE *outf;
-	char *outFname = "hbm_out.log";
-
-	trace_fd = open(DEBUGFS "trace_pipe", O_RDONLY, 0);
-	if (trace_fd < 0) {
-		printf("Error opening trace_pipe\n");
-		return;
-	}
-
-//	Future support of ingress
-//	if (!outFlag)
-//		outFname = "hbm_in.log";
-	outf = fopen(outFname, "w");
-
-	if (outf == NULL)
-		printf("Error creating %s\n", outFname);
-
-	while (1) {
-		static char buf[4097];
-		ssize_t sz;
-
-		sz = read(trace_fd, buf, sizeof(buf) - 1);
-		if (sz > 0) {
-			buf[sz] = 0;
-			puts(buf);
-			if (outf != NULL) {
-				fprintf(outf, "%s\n", buf);
-				fflush(outf);
-			}
-		}
-	}
-}
-
 static void do_error(char *msg, bool errno_flag)
 {
 	if (errno_flag)
@@ -392,8 +354,15 @@ static int run_bpf_prog(char *prog, int cg_id)
 		fclose(fout);
 	}
 
-	if (debugFlag)
-		read_trace_pipe2();
+	if (debugFlag) {
+		char *out_fname = "hbm_out.log";
+		/* Future support of ingress */
+		// if (!outFlag)
+		//	out_fname = "hbm_in.log";
+
+		read_trace_pipe2(out_fname);
+	}
+
 	return rc;
 err:
 	rc = 1;
diff --git a/tools/testing/selftests/bpf/trace_helpers.c b/tools/testing/selftests/bpf/trace_helpers.c
index 1bbd1d9830c8..b7c184e109e8 100644
--- a/tools/testing/selftests/bpf/trace_helpers.c
+++ b/tools/testing/selftests/bpf/trace_helpers.c
@@ -11,8 +11,6 @@
 #include <sys/mman.h>
 #include "trace_helpers.h"
 
-#define DEBUGFS "/sys/kernel/debug/tracing/"
-
 #define MAX_SYMS 300000
 static struct ksym syms[MAX_SYMS];
 static int sym_cnt;
@@ -136,3 +134,34 @@ void read_trace_pipe(void)
 		}
 	}
 }
+
+void read_trace_pipe2(char *filename)
+{
+	int trace_fd;
+	FILE *outf;
+
+	trace_fd = open(DEBUGFS "trace_pipe", O_RDONLY, 0);
+	if (trace_fd < 0) {
+		printf("Error opening trace_pipe\n");
+		return;
+	}
+
+	outf = fopen(filename, "w");
+	if (!outf)
+		printf("Error creating %s\n", filename);
+
+	while (1) {
+		static char buf[4096];
+		ssize_t sz;
+
+		sz = read(trace_fd, buf, sizeof(buf) - 1);
+		if (sz > 0) {
+			buf[sz] = 0;
+			puts(buf);
+			if (outf) {
+				fprintf(outf, "%s\n", buf);
+				fflush(outf);
+			}
+		}
+	}
+}
diff --git a/tools/testing/selftests/bpf/trace_helpers.h b/tools/testing/selftests/bpf/trace_helpers.h
index f62fdef9e589..68c23bf55897 100644
--- a/tools/testing/selftests/bpf/trace_helpers.h
+++ b/tools/testing/selftests/bpf/trace_helpers.h
@@ -2,6 +2,8 @@
 #ifndef __TRACE_HELPER_H
 #define __TRACE_HELPER_H
 
+#define DEBUGFS "/sys/kernel/debug/tracing/"
+
 #include <bpf/libbpf.h>
 
 struct ksym {
@@ -17,5 +19,6 @@ long ksym_get_addr(const char *name);
 int kallsyms_find(const char *sym, unsigned long long *addr);
 
 void read_trace_pipe(void);
+void read_trace_pipe2(char *filename);
 
 #endif
-- 
2.25.1


  reply	other threads:[~2020-11-17 14:57 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-17 14:56 [PATCH bpf-next 0/9] bpf: remove bpf_load loader completely Daniel T. Lee
2020-11-17 14:56 ` Daniel T. Lee [this message]
2020-11-18  1:19   ` [PATCH bpf-next 1/9] selftests: bpf: move tracing helpers to trace_helper Martin KaFai Lau
2020-11-18  2:44     ` Daniel T. Lee
2020-11-18  1:58   ` Andrii Nakryiko
2020-11-18  2:54     ` Daniel T. Lee
2020-11-18  3:04       ` Andrii Nakryiko
2020-11-17 14:56 ` [PATCH bpf-next 2/9] samples: bpf: refactor hbm program with libbpf Daniel T. Lee
2020-11-18  2:10   ` Martin KaFai Lau
2020-11-18  9:31     ` Daniel T. Lee
2020-11-17 14:56 ` [PATCH bpf-next 3/9] samples: bpf: refactor test_cgrp2_sock2 " Daniel T. Lee
2020-11-18  3:02   ` Andrii Nakryiko
2020-11-18  3:21     ` Daniel T. Lee
2020-11-18  5:58   ` Martin KaFai Lau
2020-11-18  9:03     ` Daniel T. Lee
2020-11-17 14:56 ` [PATCH bpf-next 4/9] samples: bpf: refactor task_fd_query " Daniel T. Lee
2020-11-18  2:58   ` Andrii Nakryiko
2020-11-18  3:19     ` Daniel T. Lee
2020-11-18  6:15   ` Martin KaFai Lau
2020-11-17 14:56 ` [PATCH bpf-next 5/9] samples: bpf: refactor ibumad " Daniel T. Lee
2020-11-18  2:52   ` Andrii Nakryiko
2020-11-18  3:05     ` Daniel T. Lee
2020-11-18  3:10       ` Andrii Nakryiko
2020-11-18  5:04         ` Daniel T. Lee
2020-11-17 14:56 ` [PATCH bpf-next 6/9] samples: bpf: refactor test_overhead " Daniel T. Lee
2020-11-18  2:45   ` Andrii Nakryiko
2020-11-17 14:56 ` [PATCH bpf-next 7/9] samples: bpf: fix lwt_len_hist reusing previous BPF map Daniel T. Lee
2020-11-17 14:56 ` [PATCH bpf-next 8/9] samples: bpf: remove unused trace_helper and bpf_load from Makefile Daniel T. Lee
2020-11-17 14:56 ` [PATCH bpf-next 9/9] samples: bpf: remove bpf_load loader completely Daniel T. Lee
2020-11-17 16:12   ` Jesper Dangaard Brouer
2020-11-18  2:48   ` Andrii Nakryiko
2020-11-18  2:57     ` Daniel T. Lee

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=20201117145644.1166255-2-danieltimlee@gmail.com \
    --to=danieltimlee@gmail.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=brakmo@fb.com \
    --cc=brouer@redhat.com \
    --cc=daniel@iogearbox.net \
    --cc=dsa@cumulusnetworks.com \
    --cc=ira.weiny@intel.com \
    --cc=john.fastabend@gmail.com \
    --cc=kafai@fb.com \
    --cc=kuba@kernel.org \
    --cc=lorenzo@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=tgraf@suug.ch \
    --cc=toke@redhat.com \
    --cc=xdp-newbies@vger.kernel.org \
    --cc=yhs@fb.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.