lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Mon, 30 Mar 2015 16:40:55 -0300
From:	Arnaldo Carvalho de Melo <acme@...nel.org>
To:	David Ahern <dsahern@...il.com>
Cc:	linux-kernel@...r.kernel.org, Don Zickus <dzickus@...hat.com>,
	Joe Mario <jmario@...hat.com>, Jiri Olsa <jolsa@...hat.com>,
	Ingo Molnar <mingo@...nel.org>,
	Peter Zijlstra <peterz@...radead.org>
Subject: Re: [PATCH v2 2/2] perf tool: Fix ppid for synthesized fork events

Em Mon, Mar 30, 2015 at 12:20:42PM -0600, David Ahern escreveu:

Some nits below:
 
>  tools/perf/util/event.c | 92 ++++++++++++++++++++++++++++++-------------------
>  1 file changed, 57 insertions(+), 35 deletions(-)
> 
> diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
<SNIP>
> @@ -81,6 +84,7 @@ static pid_t perf_event__get_comm_tgid(pid_t pid, char *comm, size_t len)
>  
>  	name = strstr(bf, "Name:");
>  	tgids = strstr(bf, "Tgid:");
> +	ppids = strstr(bf, "PPid:");

can't we make this:

	ppids = strstr(tgids, "PPid:");

To speed it up a teeny little bit? 8-)
  
>  	if (name) {
>  		name += 5;  /* strlen("Name:") */
> @@ -109,32 +113,51 @@ static pid_t perf_event__get_comm_tgid(pid_t pid, char *comm, size_t len)
>  		if (nl)
>  			*nl = '\0';
>  
> -		tgid = atoi(tgids);
> +		*tgid = atoi(tgids);
>  
>  	} else
>  		pr_debug("Tgid: string not found for pid %d\n", pid);
>  
> -	return tgid;
> +	if (ppids) {
> +		ppids += 5;  /* strlen("PPid:") */
> +
> +		while (*ppids && isspace(*ppids))
> +			++ppids;

The above could be simplified to:

		while (isspace(*ppids))
			++ppids;

$ cat isspace.c 
#include <ctype.h>
#include <stdio.h>
int main(void) { return printf("isspace('\\0')=%d\n", isspace('\0')); }
$ ./isspace 
isspace('\0')=0
$ 

> +		nl = strchr(ppids, '\n');
> +		if (nl)
> +			 *nl = '\0';

We also don't need to find and zero this '\n', as:

$ cat atoi.c 
#include <string.h>
#include <stdio.h>
int main(void) { return printf("atoi(\"1234\\n\")=%d\n",
atoi("1234\n")); }
$ ./atoi 
atoi("1234\n")=1234
$

<SNIP>

> +	if (machine__is_host(machine)) {
> +		if (perf_event__get_comm_ids(pid, event->comm.comm,
> +					     sizeof(event->comm.comm),
> +					     tgid, ppid) != 0) {
> +			return -1;
> +		}
> +	} else
> +		*tgid = machine->pid;

Somebody, I think PeterZ and also Ingo, routinely asks for having {} on
the else part of an if that has {}, please do so.

- Arnaldo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ