Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp1910456ybf; Sun, 1 Mar 2020 21:25:54 -0800 (PST) X-Google-Smtp-Source: APXvYqy9CYKslxSLAmA0DLw4XIWLu3LoGK/b7JD1zL9fveoCzgXV4wJOJiXws9r6qHAptFbR+Bk4 X-Received: by 2002:a9d:4c8c:: with SMTP id m12mr12340975otf.312.1583126754413; Sun, 01 Mar 2020 21:25:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583126754; cv=none; d=google.com; s=arc-20160816; b=H2QqwE+RFb3OosxRMo7HdDUfddiKT/8/ERFXLeoNi4xDWwFRZpZowyShhbaKf2pbP5 kYKBWgUFVG33JUkYFG4qKEx+dWHfpcEGALuqZZtiHBud2dXPF+GHSPE9oK5Yy+hQ4eA8 9Vg1+qqnrwSEDNb4xyUVUd28LgP7Jg7xpDuawhCE1k75ECoyaXVaeHi5sI6+EzfcuT8N 5vZHlBfsLD/GljbLeEqaDBKXwZjn4dePu+c2ZdexriO6Jn7WqzIMiGoWVAbTFM6COE+a a9fo7fZ1DXitZNQ3pZWNBWCoX5qzQpDRAA8W4cwbAsN/vKTn6FbsYw/H8MOxGtZowfE+ 5tUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:content-transfer-encoding :mime-version:references:in-reply-to:date:subject:cc:to:from; bh=w2+HeJgP8fBGZVx53Z1Kj4JfkyuT/W5GsftpkXcGrXA=; b=SXKttY/kEYf9V0z5a0Qhc4uHkkeX5v4NiyZTP/Aj4vsiWb8e5NrUUQ8huAk5eLzGzK LT3rpQIcwkjwkqdrCJSJWLYVLRlvz7au9coAIIHF6T2+KxNwyLBbTglM5hnWoJFMmRVU zvQnHptNUKm+YqhfEIfUKF7o8gbG5v61nOH79H9M9lncuxiifkA7U8GtxYORDvyqpEbi TJobtXFseNf1YlxiwzEl7IvUx57zUhJq3DdTxGIFF2DDN5dwWFKvNGC+SSgikYlyNJIK VQN14vJkbUnxmcYyXO4VWbZ77JdW0YHnOeDJgj1coAu2g7Y6guc8Iy5r6rI8bqJq5Zc8 gq7Q== 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 a3si6097948otk.234.2020.03.01.21.25.43; Sun, 01 Mar 2020 21:25:54 -0800 (PST) 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 S1727123AbgCBFZE (ORCPT + 99 others); Mon, 2 Mar 2020 00:25:04 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:18314 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726980AbgCBFZD (ORCPT ); Mon, 2 Mar 2020 00:25:03 -0500 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0225Og0l039490 for ; Mon, 2 Mar 2020 00:25:02 -0500 Received: from e06smtp05.uk.ibm.com (e06smtp05.uk.ibm.com [195.75.94.101]) by mx0b-001b2d01.pphosted.com with ESMTP id 2yfhs35yj0-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 02 Mar 2020 00:25:02 -0500 Received: from localhost by e06smtp05.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 2 Mar 2020 05:25:00 -0000 Received: from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198) by e06smtp05.uk.ibm.com (192.168.101.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Mon, 2 Mar 2020 05:24:54 -0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 0225OrdN48693362 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 2 Mar 2020 05:24:53 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F11525204F; Mon, 2 Mar 2020 05:24:52 +0000 (GMT) Received: from bangoria.in.ibm.com (unknown [9.124.31.175]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id BD2A952050; Mon, 2 Mar 2020 05:24:49 +0000 (GMT) From: Ravi Bangoria To: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Cc: eranian@google.com, peterz@infradead.org, mpe@ellerman.id.au, paulus@samba.org, mingo@redhat.com, acme@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org, adrian.hunter@intel.com, ak@linux.intel.com, kan.liang@linux.intel.com, alexey.budankov@linux.intel.com, yao.jin@linux.intel.com, robert.richter@amd.com, kim.phillips@amd.com, maddy@linux.ibm.com, ravi.bangoria@linux.ibm.com Subject: [RFC 10/11] perf annotate: Preparation for hazard Date: Mon, 2 Mar 2020 10:53:54 +0530 X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200302052355.36365-1-ravi.bangoria@linux.ibm.com> References: <20200302052355.36365-1-ravi.bangoria@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 x-cbid: 20030205-0020-0000-0000-000003AF5D2C X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 20030205-0021-0000-0000-000022078669 Message-Id: <20200302052355.36365-11-ravi.bangoria@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.572 definitions=2020-03-02_01:2020-02-28,2020-03-02 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 lowpriorityscore=0 mlxlogscore=999 malwarescore=0 impostorscore=0 suspectscore=0 clxscore=1015 bulkscore=0 adultscore=0 mlxscore=0 priorityscore=1501 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2003020039 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Introduce 'struct hazard_hist' that will contain hazard specific information for annotate. Add Array of list of 'struct hazard_hist' into 'struct annotated_source' where array length = symbol size and each member of list contain hazard info from associated perf sample. This information is prepared while parsing samples in perf report. Also, this is just a preparation step for annotate and followup patch does actual annotate ui changes. Signed-off-by: Ravi Bangoria --- tools/perf/builtin-report.c | 1 + tools/perf/util/annotate.c | 75 +++++++++++++++++++++++++++++++++++++ tools/perf/util/annotate.h | 14 +++++++ tools/perf/util/hist.c | 13 +++++++ tools/perf/util/hist.h | 4 ++ tools/perf/util/machine.c | 6 +++ tools/perf/util/machine.h | 3 ++ 7 files changed, 116 insertions(+) diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index a47542a12da1..ff950ff8dd51 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -301,6 +301,7 @@ static int process_sample_event(struct perf_tool *tool, hist__account_cycles(sample->branch_stack, &al, sample, rep->nonany_branch_mode, &rep->total_cycles); + hist__capture_haz_info(&al, sample, evsel); } ret = hist_entry_iter__add(&iter, &al, rep->max_stack, rep); diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 8aef60a6ffea..766934b0f36d 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -36,6 +36,7 @@ #include "string2.h" #include "util/event.h" #include "arch/common.h" +#include "hazard.h" #include #include #include @@ -800,6 +801,21 @@ static int symbol__alloc_hist_cycles(struct symbol *sym) return 0; } +static int symbol__alloc_hist_hazard(struct symbol *sym) +{ + struct annotation *notes = symbol__annotation(sym); + const size_t size = symbol__size(sym); + size_t i; + + notes->src->haz_hist = calloc(size, sizeof(struct hazard_hist)); + if (notes->src->haz_hist == NULL) + return -1; + + for (i = 0; i < size; i++) + INIT_LIST_HEAD(¬es->src->haz_hist[i].list); + return 0; +} + void symbol__annotate_zero_histograms(struct symbol *sym) { struct annotation *notes = symbol__annotation(sym); @@ -920,6 +936,25 @@ static struct cyc_hist *symbol__cycles_hist(struct symbol *sym) return notes->src->cycles_hist; } +static struct hazard_hist *symbol__hazard_hist(struct symbol *sym) +{ + struct annotation *notes = symbol__annotation(sym); + + if (notes->src == NULL) { + notes->src = annotated_source__new(); + if (notes->src == NULL) + return NULL; + goto alloc_haz_hist; + } + + if (!notes->src->haz_hist) { +alloc_haz_hist: + symbol__alloc_hist_hazard(sym); + } + + return notes->src->haz_hist; +} + struct annotated_source *symbol__hists(struct symbol *sym, int nr_hists) { struct annotation *notes = symbol__annotation(sym); @@ -1014,6 +1049,46 @@ int addr_map_symbol__account_cycles(struct addr_map_symbol *ams, return err; } +int symbol__capture_haz_info(struct addr_map_symbol *ams, + struct perf_sample *sample, + struct evsel *evsel) +{ + struct hazard_hist *hh, *tmp; + u64 offset; + const char *arch = perf_env__arch(perf_evsel__env(evsel)); + + if (ams->ms.sym == NULL) + return 0; + + hh = symbol__hazard_hist(ams->ms.sym); + if (!hh) + return -ENOMEM; + + if (ams->al_addr < ams->ms.sym->start || ams->al_addr >= ams->ms.sym->end) + return -ERANGE; + + offset = ams->al_addr - ams->ms.sym->start; + + tmp = zalloc(sizeof(*tmp)); + if (!tmp) + return -ENOMEM; + + tmp->icache = perf_haz__icache_str(sample->pipeline_haz->icache, arch); + tmp->haz_stage = perf_haz__hstage_str(sample->pipeline_haz->hazard_stage, + arch); + tmp->haz_reason = perf_haz__hreason_str(sample->pipeline_haz->hazard_stage, + sample->pipeline_haz->hazard_reason, + arch); + tmp->stall_stage = perf_haz__sstage_str(sample->pipeline_haz->stall_stage, + arch); + tmp->stall_reason = perf_haz__sreason_str(sample->pipeline_haz->stall_stage, + sample->pipeline_haz->stall_reason, + arch); + + list_add(&tmp->list, &hh[offset].list); + return 0; +} + static unsigned annotation__count_insn(struct annotation *notes, u64 start, u64 end) { unsigned n_insn = 0; diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index 89839713d242..a3803f89b8fc 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h @@ -249,6 +249,15 @@ struct cyc_hist { u16 reset; }; +struct hazard_hist { + struct list_head list; + const char *icache; + const char *haz_stage; + const char *haz_reason; + const char *stall_stage; + const char *stall_reason; +}; + /** struct annotated_source - symbols with hits have this attached as in sannotation * * @histograms: Array of addr hit histograms per event being monitored @@ -271,6 +280,7 @@ struct annotated_source { int nr_histograms; size_t sizeof_sym_hist; struct cyc_hist *cycles_hist; + struct hazard_hist *haz_hist; /* Array of list. Array length = symbol size */ struct sym_hist *histograms; }; @@ -343,6 +353,10 @@ int addr_map_symbol__account_cycles(struct addr_map_symbol *ams, struct addr_map_symbol *start, unsigned cycles); +int symbol__capture_haz_info(struct addr_map_symbol *ams, + struct perf_sample *sample, + struct evsel *evsel); + int hist_entry__inc_addr_samples(struct hist_entry *he, struct perf_sample *sample, struct evsel *evsel, u64 addr); diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index d690d08b0f64..3cbfebb80f68 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c @@ -2702,6 +2702,19 @@ void hist__account_cycles(struct branch_stack *bs, struct addr_location *al, } } +void hist__capture_haz_info(struct addr_location *al, + struct perf_sample *sample, + struct evsel *evsel) +{ + struct addr_map_symbol ams; + + if (!sample->pipeline_haz) + return; + + sample__resolve_haz(al, &ams, sample); + symbol__capture_haz_info(&ams, sample, evsel); +} + size_t perf_evlist__fprintf_nr_events(struct evlist *evlist, FILE *fp) { struct evsel *pos; diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h index 063d65985a11..086c1dfde21f 100644 --- a/tools/perf/util/hist.h +++ b/tools/perf/util/hist.h @@ -554,6 +554,10 @@ void hist__account_cycles(struct branch_stack *bs, struct addr_location *al, struct perf_sample *sample, bool nonany_branch_mode, u64 *total_cycles); +void hist__capture_haz_info(struct addr_location *al, + struct perf_sample *sample, + struct evsel *evsel); + struct option; int parse_filter_percentage(const struct option *opt, const char *arg, int unset); int perf_hist_config(const char *var, const char *value); diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index fb5c2cd44d30..e575488a1390 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -2094,6 +2094,12 @@ struct branch_info *sample__resolve_bstack(struct perf_sample *sample, return bi; } +void sample__resolve_haz(struct addr_location *al, struct addr_map_symbol *ams, + struct perf_sample *sample) +{ + ip__resolve_ams(al->thread, ams, sample->ip); +} + static void save_iterations(struct iterations *iter, struct branch_entry *be, int nr) { diff --git a/tools/perf/util/machine.h b/tools/perf/util/machine.h index be0a930eca89..e9a298b5430c 100644 --- a/tools/perf/util/machine.h +++ b/tools/perf/util/machine.h @@ -173,6 +173,9 @@ struct branch_info *sample__resolve_bstack(struct perf_sample *sample, struct mem_info *sample__resolve_mem(struct perf_sample *sample, struct addr_location *al); +void sample__resolve_haz(struct addr_location *al, struct addr_map_symbol *ams, + struct perf_sample *sample); + struct callchain_cursor; int thread__resolve_callchain(struct thread *thread, -- 2.21.1