Received: by 10.213.65.68 with SMTP id h4csp331469imn; Tue, 13 Mar 2018 05:57:11 -0700 (PDT) X-Google-Smtp-Source: AG47ELtQ+l8xBOWAxI+2O4TkaomyT+3jXUh2xCfctpzyxWoSFt+4jc4nYeIxuu0e/772RD9e4gTG X-Received: by 10.98.231.26 with SMTP id s26mr529154pfh.210.1520945831756; Tue, 13 Mar 2018 05:57:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520945831; cv=none; d=google.com; s=arc-20160816; b=P3e0kL6JIEigLAvoxQBpJMi4B/jx7HcWEvGnwfgXsfm0t5PQQiZGGM8AplHlFER8z/ cQ8PZHRIu5qlweMMBaIqONG6qIAvgDSpbjyhQu2wJ1qQYD4YrxSfPD0Oc29x5SPtXNwS n5PB8BDXi6m0RVmBVYGP6ZD0MGxuH9RL6QgLRXnKUok0nGOdHcJjXz8Hjy2IUYSjc8ia PavwqQb+6m8IeMe7OajXzKjFfO1rElt6c7MlodTT4ISpUgGw7MmB/pi9wDgu8JFWSgp5 Q0CtGHPx4ep7QuncdAwdXwkpjyemI/DGUCAo32Ug2G65nEWlSW/ADPP8Ko4qHWO2+Ha5 kYGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:references:in-reply-to:date :subject:cc:to:from:arc-authentication-results; bh=qpbJBXI1HDBlINj5lpvL2THZB0yP4nBX8rLFMAK5Y4A=; b=ag7ZwpibaUeE0aMB/SQrVIySZUd5ZkTCIccIiO9NaWRqtwPBWUfhNdlv+WEtzFJFLm ZHO3jdl3dCtN2dkSCjtHpvrO3a+q5pBBuDGbIh4Py/jXWqAei3wnvESHZvYHXhdkYNZx 6dEYVJTQqqgvnfCME9OD4KQxeuQU2Vnm9hJ1kap+imbTa+PzqN9b4sMrmr9Y8i6ezpdp byJ1dTaWb8q1hrXzQZy+CqWBG05wtWprG+OvF9oPkyeiNqF/ZoomUxmg93bKyxb+03Go 1lz28tVIWyFG2PqoVRkhqm7oca4vRdSpKUk4WiteQc+dp0fK2IYCOGUOnEHm7iB/pZIP pXxQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u9si79259pgp.670.2018.03.13.05.56.57; Tue, 13 Mar 2018 05:57:11 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752700AbeCMMzn (ORCPT + 99 others); Tue, 13 Mar 2018 08:55:43 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:50376 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752277AbeCMMzk (ORCPT ); Tue, 13 Mar 2018 08:55:40 -0400 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w2DCsoIL012874 for ; Tue, 13 Mar 2018 08:55:40 -0400 Received: from e06smtp10.uk.ibm.com (e06smtp10.uk.ibm.com [195.75.94.106]) by mx0a-001b2d01.pphosted.com with ESMTP id 2gpc41gkan-1 (version=TLSv1.2 cipher=AES256-SHA256 bits=256 verify=NOT) for ; Tue, 13 Mar 2018 08:55:40 -0400 Received: from localhost by e06smtp10.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 13 Mar 2018 12:55:36 -0000 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp10.uk.ibm.com (192.168.101.140) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 13 Mar 2018 12:55:27 -0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w2DCtRab66650204; Tue, 13 Mar 2018 12:55:27 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8B0B911C04C; Tue, 13 Mar 2018 12:48:06 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B324E11C050; Tue, 13 Mar 2018 12:47:54 +0000 (GMT) Received: from bangoria.in.ibm.com (unknown [9.124.221.140]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 13 Mar 2018 12:47:54 +0000 (GMT) From: Ravi Bangoria To: mhiramat@kernel.org, oleg@redhat.com, peterz@infradead.org, srikar@linux.vnet.ibm.com Cc: 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, Ravi Bangoria Subject: [PATCH 7/8] perf probe: Support SDT markers having reference counter (semaphore) Date: Tue, 13 Mar 2018 18:26:02 +0530 X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180313125603.19819-1-ravi.bangoria@linux.vnet.ibm.com> References: <20180313125603.19819-1-ravi.bangoria@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18031312-0040-0000-0000-0000041F00A3 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18031312-0041-0000-0000-000026222B87 Message-Id: <20180313125603.19819-8-ravi.bangoria@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2018-03-13_06:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1803130154 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org With this, perf buildid-cache will save SDT markers with reference counter in probe cache. Perf probe will be able to probe markers having reference counter. Ex, # readelf -n /tmp/tick | grep -A1 loop2 Name: loop2 ... Semaphore: 0x0000000010020036 # ./perf buildid-cache --add /tmp/tick # ./perf probe sdt_tick:loop2 # ./perf stat -e sdt_tick:loop2 /tmp/tick hi: 0 hi: 1 hi: 2 ^C Performance counter stats for '/tmp/tick': 3 sdt_tick:loop2 2.561851452 seconds time elapsed Signed-off-by: Ravi Bangoria --- tools/perf/util/probe-event.c | 21 +++++++++++++++++---- tools/perf/util/probe-event.h | 1 + tools/perf/util/probe-file.c | 22 +++++++++++++++++++--- tools/perf/util/symbol-elf.c | 10 ++++++++++ tools/perf/util/symbol.h | 1 + 5 files changed, 48 insertions(+), 7 deletions(-) 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); + } + 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]; +} + 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)); + + 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); + } + } + 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