public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Leo Yan <leo.yan@linaro.org>
To: Arnaldo Carvalho de Melo <arnaldo.melo@gmail.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@redhat.com>, Namhyung Kim <namhyung@kernel.org>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Martin KaFai Lau <kafai@fb.com>, Song Liu <songliubraving@fb.com>,
	Yonghong Song <yhs@fb.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Mathieu Poirier <mathieu.poirier@linaro.org>,
	Mike Leach <mike.leach@linaro.org>,
	Suzuki K Poulose <suzuki.poulose@arm.com>,
	linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
	bpf@vger.kernel.org
Subject: Re: [PATCH v2 3/4] perf augmented_raw_syscalls: Support arm64 raw syscalls
Date: Sat, 15 Jun 2019 13:52:49 +0800	[thread overview]
Message-ID: <20190615055249.GA3742@leoy-ThinkPad-X240s> (raw)
In-Reply-To: <20190613181514.GC1402@kernel.org>

On Thu, Jun 13, 2019 at 03:15:14PM -0300, Arnaldo Carvalho de Melo wrote:

[...]

> > > > diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
> > > > index 1a2a605cf068..eb70a4b71755 100644
> > > > --- a/tools/perf/builtin-trace.c
> > > > +++ b/tools/perf/builtin-trace.c
> > > > @@ -1529,6 +1529,7 @@ static int trace__read_syscall_info(struct trace *trace, int id)
> > > >  static int trace__validate_ev_qualifier(struct trace *trace)
> > > >  {
> > > >  	int err = 0, i;
> > > > +	bool printed_invalid_prefix = false;
> > > >  	size_t nr_allocated;
> > > >  	struct str_node *pos;
> > > >  
> > > > @@ -1555,14 +1556,15 @@ static int trace__validate_ev_qualifier(struct trace *trace)
> > > >  			if (id >= 0)
> > > >  				goto matches;
> > > >  
> > > > -			if (err == 0) {
> > > > -				fputs("Error:\tInvalid syscall ", trace->output);
> > > > -				err = -EINVAL;
> > > > +			if (!printed_invalid_prefix) {
> > > > +				pr_debug("Skipping unknown syscalls: ");
> > > > +				printed_invalid_prefix = true;
> > > >  			} else {
> > > > -				fputs(", ", trace->output);
> > > > +				pr_debug(", ");
> > > >  			}
> > > >  
> > > > -			fputs(sc, trace->output);
> > > > +			pr_debug("%s", sc);
> > > > +			continue;
> > > 
> > > Here adds 'continue' so that we want to let ev_qualifier_ids.entries
> > > to only store valid system call ids.  But this is not sufficient,
> > > because we have initialized ev_qualifier_ids.nr at the beginning of
> > > the function:
> > > 
> > >   trace->ev_qualifier_ids.nr = strlist__nr_entries(trace->ev_qualifier);
> > > This sentence will set ids number to the string table's length; but
> > > actually some strings are not really supported; this leads to some
> > > items in trace->ev_qualifier_ids.entries[] will be not initialized
> > > properly.
> > > 
> > > If we want to get neat entries and entry number, I suggest at the
> > > beginning of the function we use variable 'nr_allocated' to store
> > > string table length and use it to allocate entries:
> > > 
> > >   nr_allocated = strlist__nr_entries(trace->ev_qualifier);
> > >   trace->ev_qualifier_ids.entries = malloc(nr_allocated *
> > >                                            sizeof(trace->ev_qualifier_ids.entries[0]));
> > > 
> > > If we find any matched string, then increment the nr field under
> > > 'matches' tag:
> > > 
> > > matches:
> > >                 trace->ev_qualifier_ids.nr++;
> > >                 trace->ev_qualifier_ids.entries[i++] = id;
> > > 
> > > This can ensure the entries[0..nr-1] has valid id and we can use
> > > ev_qualifier_ids.nr to maintain the valid system call numbers.
> > 
> > yeah, you're right, I'll address these issues in a followup patch,
> > tomorrow.
> 
> This is equivalent and I think the smallest patch, I'll add one on top
> doing what you suggested about nr_allocated getting the
> strlist__nr_entries() and also will rename i to nr_used to contrast with
> nr_allocated, and then at the end set ev_qualifier_ids.nr to nr_used.

Thanks for this patch, I tested below changes and 'perf trace' works
well.  You could add my test tag:

Tested-by: Leo Yan <leo.yan@linaro.org>

> - Arnaldo
> 
> diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
> index eb70a4b71755..bd1f00e7a2eb 100644
> --- a/tools/perf/builtin-trace.c
> +++ b/tools/perf/builtin-trace.c
> @@ -1528,9 +1528,9 @@ static int trace__read_syscall_info(struct trace *trace, int id)
>  
>  static int trace__validate_ev_qualifier(struct trace *trace)
>  {
> -	int err = 0, i;
> +	int err = 0;
>  	bool printed_invalid_prefix = false;
> -	size_t nr_allocated;
> +	size_t nr_allocated, i;
>  	struct str_node *pos;
>  
>  	trace->ev_qualifier_ids.nr = strlist__nr_entries(trace->ev_qualifier);
> @@ -1575,7 +1575,7 @@ static int trace__validate_ev_qualifier(struct trace *trace)
>  			id = syscalltbl__strglobmatch_next(trace->sctbl, sc, &match_next);
>  			if (id < 0)
>  				break;
> -			if (nr_allocated == trace->ev_qualifier_ids.nr) {
> +			if (nr_allocated == i) {
>  				void *entries;
>  
>  				nr_allocated += 8;
> @@ -1588,11 +1588,11 @@ static int trace__validate_ev_qualifier(struct trace *trace)
>  				}
>  				trace->ev_qualifier_ids.entries = entries;
>  			}
> -			trace->ev_qualifier_ids.nr++;
>  			trace->ev_qualifier_ids.entries[i++] = id;
>  		}
>  	}
>  
> +	trace->ev_qualifier_ids.nr = i;
>  out:
>  	if (printed_invalid_prefix)
>  		pr_debug("\n");

  reply	other threads:[~2019-06-15  5:53 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-06  9:48 [PATCH v2 0/4] perf augmented_raw_syscalls: Support for arm64 Leo Yan
2019-06-06  9:48 ` [PATCH v2 1/4] perf trace: Exit when build eBPF program failure Leo Yan
2019-06-06 13:30   ` Arnaldo Carvalho de Melo
2019-06-06 13:34     ` Arnaldo Carvalho de Melo
2019-06-10  7:38       ` Leo Yan
2019-06-06 13:56     ` Leo Yan
2019-06-06  9:48 ` [PATCH v2 2/4] perf augmented_raw_syscalls: Remove duplicate macros Leo Yan
2019-06-06  9:48 ` [PATCH v2 3/4] perf augmented_raw_syscalls: Support arm64 raw syscalls Leo Yan
2019-06-06 13:38   ` Arnaldo Carvalho de Melo
2019-06-06 13:46     ` Arnaldo Carvalho de Melo
2019-06-06 14:05       ` Arnaldo Carvalho de Melo
2019-06-06 14:12     ` Leo Yan
2019-06-06 14:44       ` Arnaldo Carvalho de Melo
2019-06-07  9:58         ` Leo Yan
2019-06-09 13:18           ` Leo Yan
2019-06-10 18:47             ` Arnaldo Carvalho de Melo
2019-06-11  4:18               ` Leo Yan
2019-06-12  2:49                 ` Arnaldo Carvalho de Melo
2019-06-13 18:15                   ` Arnaldo Carvalho de Melo
2019-06-15  5:52                     ` Leo Yan [this message]
2019-06-06  9:48 ` [PATCH v2 4/4] perf augmented_raw_syscalls: Document clang configuration Leo Yan
2019-06-06 14:08   ` Arnaldo Carvalho de Melo
2019-06-06 14:35     ` Leo Yan
2019-06-06 18:29       ` Arnaldo Carvalho de Melo
2019-06-07 14:38         ` Leo Yan
2019-06-07 18:33           ` Arnaldo Carvalho de Melo

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=20190615055249.GA3742@leoy-ThinkPad-X240s \
    --to=leo.yan@linaro.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=arnaldo.melo@gmail.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=jolsa@redhat.com \
    --cc=kafai@fb.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.poirier@linaro.org \
    --cc=mike.leach@linaro.org \
    --cc=namhyung@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=songliubraving@fb.com \
    --cc=suzuki.poulose@arm.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox