Netdev List
 help / color / mirror / Atom feed
From: Daniel Borkmann <daniel@iogearbox.net>
To: Jakub Kicinski <jakub.kicinski@netronome.com>,
	alexei.starovoitov@gmail.com
Cc: oss-drivers@netronome.com, netdev@vger.kernel.org
Subject: Re: [PATCH bpf-next 09/10] tools: bpftool: add simple perf event output reader
Date: Fri, 4 May 2018 23:53:34 +0200	[thread overview]
Message-ID: <274be74e-979a-2fe4-6fe6-60733fc0077a@iogearbox.net> (raw)
In-Reply-To: <20180504013717.29317-10-jakub.kicinski@netronome.com>

On 05/04/2018 03:37 AM, Jakub Kicinski wrote:
> Users of BPF sooner or later discover perf_event_output() helpers
> and BPF_MAP_TYPE_PERF_EVENT_ARRAY.  Dumping this array type is
> not possible, however, we can add simple reading of perf events.
> Create a new event_pipe subcommand for maps, this sub command
> will only work with BPF_MAP_TYPE_PERF_EVENT_ARRAY maps.
> 
> Parts of the code from samples/bpf/trace_output_user.c.
> 
> Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
> Reviewed-by: Quentin Monnet <quentin.monnet@netronome.com>
[...]

One remark below:

[...]
> +static void
> +print_bpf_output(struct event_ring_info *ring, struct perf_event_sample *e)
> +{
> +	struct {
> +		struct perf_event_header header;
> +		__u64 id;
> +		__u64 lost;
> +	} *lost = (void *)e;
> +	struct timespec ts;
> +
> +	if (clock_gettime(CLOCK_MONOTONIC, &ts)) {
> +		perror("Can't read clock for timestamp");
> +		return;
> +	}
Instead of the timestamp above, probably better to pick it up via
PERF_SAMPLE_TIME which needs to be added to sample_type so it also
ends up in the RB. Given below you poll with 200 and you don't set
a wakeup event for perf RB (it's probably fine not to here, but it
can be done based on watermark or events), the clock_gettime() will
be off compared to when it was actually put into the RB.

> +	if (json_output) {
> +		jsonw_start_object(json_wtr);
> +		jsonw_name(json_wtr, "timestamp");
> +		jsonw_uint(json_wtr, ts.tv_sec * 1000000000ull + ts.tv_nsec);
> +		jsonw_name(json_wtr, "type");
> +		jsonw_uint(json_wtr, e->header.type);
> +		jsonw_name(json_wtr, "cpu");
> +		jsonw_uint(json_wtr, ring->cpu);
> +		jsonw_name(json_wtr, "index");
> +		jsonw_uint(json_wtr, ring->key);
> +		if (e->header.type == PERF_RECORD_SAMPLE) {
> +			jsonw_name(json_wtr, "data");
> +			print_data_json(e->data, e->size);
> +		} else if (e->header.type == PERF_RECORD_LOST) {
> +			jsonw_name(json_wtr, "lost");
> +			jsonw_start_object(json_wtr);
> +			jsonw_name(json_wtr, "id");
> +			jsonw_uint(json_wtr, lost->id);
> +			jsonw_name(json_wtr, "count");
> +			jsonw_uint(json_wtr, lost->lost);
> +			jsonw_end_object(json_wtr);
> +		}
> +		jsonw_end_object(json_wtr);
> +	} else {
> +		if (e->header.type == PERF_RECORD_SAMPLE) {
> +			printf("== @%ld.%ld CPU: %d index: %d =====\n",
> +			       (long)ts.tv_sec, ts.tv_nsec,
> +			       ring->cpu, ring->key);
> +			fprint_hex(stdout, e->data, e->size, " ");
> +			printf("\n");
> +		} else if (e->header.type == PERF_RECORD_LOST) {
> +			printf("lost %lld events\n", lost->lost);
> +		} else {
> +			printf("unknown event type=%d size=%d\n",
> +			       e->header.type, e->header.size);
> +		}

  parent reply	other threads:[~2018-05-04 21:53 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-04  1:37 [PATCH bpf-next 00/10] bpf: support offload of bpf_event_output() Jakub Kicinski
2018-05-04  1:37 ` [PATCH bpf-next 01/10] bpf: offload: allow offloaded programs to use perf event arrays Jakub Kicinski
2018-05-04  1:37 ` [PATCH bpf-next 02/10] nfp: bpf: record offload neutral maps in the driver Jakub Kicinski
2018-05-04  1:37 ` [PATCH bpf-next 03/10] bpf: export bpf_event_output() Jakub Kicinski
2018-05-04  1:37 ` [PATCH bpf-next 04/10] bpf: replace map pointer loads before calling into offloads Jakub Kicinski
2018-05-04  1:37 ` [PATCH bpf-next 05/10] nfp: bpf: perf event output helpers support Jakub Kicinski
2018-05-04  1:37 ` [PATCH bpf-next 06/10] nfp: bpf: rewrite map pointers with NFP TIDs Jakub Kicinski
2018-05-04  1:37 ` [PATCH bpf-next 07/10] tools: bpftool: fold hex keyword in command help Jakub Kicinski
2018-05-04  1:37 ` [PATCH bpf-next 08/10] tools: bpftool: move get_possible_cpus() to common code Jakub Kicinski
2018-05-04  1:37 ` [PATCH bpf-next 09/10] tools: bpftool: add simple perf event output reader Jakub Kicinski
2018-05-04 21:25   ` Alexei Starovoitov
2018-05-04 22:28     ` Jakub Kicinski
2018-05-04 21:53   ` Daniel Borkmann [this message]
2018-05-04  1:37 ` [PATCH bpf-next 10/10] bpf: fix references to free_bpf_prog_info() in comments Jakub Kicinski
2018-05-04 21:46 ` [PATCH bpf-next 00/10] bpf: support offload of bpf_event_output() Daniel Borkmann

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=274be74e-979a-2fe4-6fe6-60733fc0077a@iogearbox.net \
    --to=daniel@iogearbox.net \
    --cc=alexei.starovoitov@gmail.com \
    --cc=jakub.kicinski@netronome.com \
    --cc=netdev@vger.kernel.org \
    --cc=oss-drivers@netronome.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox