Received: by 10.213.65.68 with SMTP id h4csp1015428imn; Wed, 14 Mar 2018 07:11:07 -0700 (PDT) X-Google-Smtp-Source: AG47ELvVru5SNx8vyli69uzY037JtHZpPDRVO7OZP1yq2MrPhHzXjbLpCAvNjFuI+8oPoZRD7dor X-Received: by 10.98.50.130 with SMTP id y124mr4424859pfy.147.1521036666985; Wed, 14 Mar 2018 07:11:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521036666; cv=none; d=google.com; s=arc-20160816; b=kpCGkuFz+oW4pWo7+K/DCGv/1AvMrcyCMvXdcEXPUgrhgMZgma88lN7puDmeNSyOx3 cKp8S4zwzEx/EuvKKeqoaFDxjJ3c/MyE3Zm6fZgzh525YZ47Dj8e63GZGZuGS8tP1leY 6FvNIg2P51yeU3JZ+2cbs3zde/LV7ah0J6KGTMilqAXDB0Cy+2/ESD88NGS3FEKInnbP LoWQKrP+BVbyC1WScEGlMDz/g4e6njMky0egy+XEWLEBRFvDPxJWzBZH+Rb3bNMyATxR ivUsw+agmHT79Bqn3GaM/kll6cJDVVCzaONJEtstxqssgKkOVo/ydBL6FgOF+baV0Sbw Jblg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dmarc-filter:arc-authentication-results; bh=6a85RVUenE7kz+30DFisSy/yVmP8rAHCWel4nvW40Ww=; b=qn14Xh1exjKmkNX+UQKMCR9AGXBmHDsuBw4iGRxJPvvaNMRmAlyNEJClQGi1O3pYjH 6mrovLBANNJw7jLWH4j0Zo8Idx4EejvTh9lDSY6M7AeLbmCQ3ZM2b1BIkBOgecCJ4Mss lV/Z6J4tyAk9bwBPU1fakUGyNZR9VSznUN5BzB/4QHcD0JDT8jWXMR58WFtxAD0PlFB/ xbPeyT4xuncctWn9HzDVdd/Fh81TU6KspreEQ4QXx4FnFxURHLrRcc/MEIuya1RIW29b oQLjGz6vsXj68/nrl9EE4gMHOxdKzrDGLdqZ2XNs5iey2R9EWlduUf4R0YEXD4cWyL7p fQMw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m37-v6si2072490pla.346.2018.03.14.07.10.51; Wed, 14 Mar 2018 07:11:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751711AbeCNOJR (ORCPT + 99 others); Wed, 14 Mar 2018 10:09:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:53082 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751366AbeCNOJQ (ORCPT ); Wed, 14 Mar 2018 10:09:16 -0400 Received: from devbox (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 80752214D7; Wed, 14 Mar 2018 14:09:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 80752214D7 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=mhiramat@kernel.org Date: Wed, 14 Mar 2018 23:09:09 +0900 From: Masami Hiramatsu To: Ravi Bangoria Cc: oleg@redhat.com, peterz@infradead.org, srikar@linux.vnet.ibm.com, acme@kernel.org, ananth@linux.vnet.ibm.com, akpm@linux-foundation.org, alexander.shishkin@linux.intel.com, alexis.berlemont@gmail.com, corbet@lwn.net, dan.j.williams@intel.com, gregkh@linuxfoundation.org, huawei.libin@huawei.com, hughd@google.com, jack@suse.cz, jglisse@redhat.com, jolsa@redhat.com, kan.liang@intel.com, kirill.shutemov@linux.intel.com, kjlx@templeofstupid.com, kstewart@linuxfoundation.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mhocko@suse.com, milian.wolff@kdab.com, mingo@redhat.com, namhyung@kernel.org, naveen.n.rao@linux.vnet.ibm.com, pc@us.ibm.com, pombredanne@nexb.com, rostedt@goodmis.org, tglx@linutronix.de, tmricht@linux.vnet.ibm.com, willy@infradead.org, yao.jin@linux.intel.com, fengguang.wu@intel.com Subject: Re: [PATCH 7/8] perf probe: Support SDT markers having reference counter (semaphore) Message-Id: <20180314230909.52963a161210294ea2fc0420@kernel.org> In-Reply-To: <20180313125603.19819-8-ravi.bangoria@linux.vnet.ibm.com> References: <20180313125603.19819-1-ravi.bangoria@linux.vnet.ibm.com> <20180313125603.19819-8-ravi.bangoria@linux.vnet.ibm.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Ravi, This code logic looks good. I just have several small comments for style. On Tue, 13 Mar 2018 18:26:02 +0530 Ravi Bangoria wrote: > diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c > index e1dbc98..2cbe68a 100644 > --- a/tools/perf/util/probe-event.c > +++ b/tools/perf/util/probe-event.c > @@ -1832,6 +1832,12 @@ int parse_probe_trace_command(const char *cmd, struct probe_trace_event *tev) > tp->offset = strtoul(fmt2_str, NULL, 10); > } > > + if (tev->uprobes) { > + fmt2_str = strchr(p, '('); > + if (fmt2_str) > + tp->ref_ctr_offset = strtoul(fmt2_str + 1, NULL, 0); > + } > + > tev->nargs = argc - 2; > tev->args = zalloc(sizeof(struct probe_trace_arg) * tev->nargs); > if (tev->args == NULL) { > @@ -2054,15 +2060,22 @@ char *synthesize_probe_trace_command(struct probe_trace_event *tev) > } > > /* Use the tp->address for uprobes */ > - if (tev->uprobes) > - err = strbuf_addf(&buf, "%s:0x%lx", tp->module, tp->address); > - else if (!strncmp(tp->symbol, "0x", 2)) > + if (tev->uprobes) { > + if (tp->ref_ctr_offset) > + err = strbuf_addf(&buf, "%s:0x%lx(0x%lx)", tp->module, > + tp->address, tp->ref_ctr_offset); > + else > + err = strbuf_addf(&buf, "%s:0x%lx", tp->module, > + tp->address); > + } else if (!strncmp(tp->symbol, "0x", 2)) { > /* Absolute address. See try_to_find_absolute_address() */ > err = strbuf_addf(&buf, "%s%s0x%lx", tp->module ?: "", > tp->module ? ":" : "", tp->address); > - else > + } else { > err = strbuf_addf(&buf, "%s%s%s+%lu", tp->module ?: "", > tp->module ? ":" : "", tp->symbol, tp->offset); > + } What the purpose of this {}? > + > if (err) > goto error; > > diff --git a/tools/perf/util/probe-event.h b/tools/perf/util/probe-event.h > index 45b14f0..15a98c3 100644 > --- a/tools/perf/util/probe-event.h > +++ b/tools/perf/util/probe-event.h > @@ -27,6 +27,7 @@ struct probe_trace_point { > char *symbol; /* Base symbol */ > char *module; /* Module name */ > unsigned long offset; /* Offset from symbol */ > + unsigned long ref_ctr_offset; /* SDT reference counter offset */ > unsigned long address; /* Actual address of the trace point */ > bool retprobe; /* Return probe flag */ > }; > diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c > index 4ae1123..08ba3a6 100644 > --- a/tools/perf/util/probe-file.c > +++ b/tools/perf/util/probe-file.c > @@ -701,6 +701,12 @@ static unsigned long long sdt_note__get_addr(struct sdt_note *note) > : (unsigned long long)note->addr.a64[0]; > } > > +static unsigned long long sdt_note__get_ref_ctr_offset(struct sdt_note *note) > +{ > + return note->bit32 ? (unsigned long long)note->addr.a32[2] > + : (unsigned long long)note->addr.a64[2]; > +} Could you please introduce an enum for specifying the index by name? e.g. enum { SDT_NOTE_IDX_ADDR = 0, SDT_NOTE_IDX_REFCTR = 2, }; > + > static const char * const type_to_suffix[] = { > ":s64", "", "", "", ":s32", "", ":s16", ":s8", > "", ":u8", ":u16", "", ":u32", "", "", "", ":u64" > @@ -776,14 +782,24 @@ static char *synthesize_sdt_probe_command(struct sdt_note *note, > { > struct strbuf buf; > char *ret = NULL, **args; > - int i, args_count; > + int i, args_count, err; > + unsigned long long ref_ctr_offset; > > if (strbuf_init(&buf, 32) < 0) > return NULL; > > - if (strbuf_addf(&buf, "p:%s/%s %s:0x%llx", > + ref_ctr_offset = sdt_note__get_ref_ctr_offset(note); > + > + if (ref_ctr_offset) > + err = strbuf_addf(&buf, "p:%s/%s %s:0x%llx(0x%llx)", > sdtgrp, note->name, pathname, > - sdt_note__get_addr(note)) < 0) > + sdt_note__get_addr(note), ref_ctr_offset); > + else > + err = strbuf_addf(&buf, "p:%s/%s %s:0x%llx", > + sdtgrp, note->name, pathname, > + sdt_note__get_addr(note)); This can be minimized (and avoid repeating) by using 2 strbuf_addf()s, like err = strbuf_addf(&buf, "p:%s/%s %s:0x%llx", sdtgrp, note->name, pathname, sdt_note__get_addr(note)); if (ref_ctr_offset && !err < 0) err = strbuf_addf("(0x%llx)", ref_ctr_offset); > + > + if (err < 0) > goto error; > > if (!note->args) > diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c > index 2de7705..76c7b54 100644 > --- a/tools/perf/util/symbol-elf.c > +++ b/tools/perf/util/symbol-elf.c > @@ -1928,6 +1928,16 @@ static int populate_sdt_note(Elf **elf, const char *data, size_t len, > } > } > > + /* Adjust reference counter offset */ > + if (elf_section_by_name(*elf, &ehdr, &shdr, SDT_PROBES_SCN, NULL)) { > + if (shdr.sh_offset) { > + if (tmp->bit32) > + tmp->addr.a32[2] -= (shdr.sh_addr - shdr.sh_offset); > + else > + tmp->addr.a64[2] -= (shdr.sh_addr - shdr.sh_offset); Here we should use enum above too. Thank you, > + } > + } > + > list_add_tail(&tmp->note_list, sdt_notes); > return 0; > > diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h > index 70c16741..ad0c4f2 100644 > --- a/tools/perf/util/symbol.h > +++ b/tools/perf/util/symbol.h > @@ -384,6 +384,7 @@ struct sdt_note { > int cleanup_sdt_note_list(struct list_head *sdt_notes); > int sdt_notes__get_count(struct list_head *start); > > +#define SDT_PROBES_SCN ".probes" > #define SDT_BASE_SCN ".stapsdt.base" > #define SDT_NOTE_SCN ".note.stapsdt" > #define SDT_NOTE_TYPE 3 > -- > 1.8.3.1 > -- Masami Hiramatsu