Received: by 10.223.164.202 with SMTP id h10csp1892826wrb; Mon, 27 Nov 2017 08:51:43 -0800 (PST) X-Google-Smtp-Source: AGs4zMZ34Wggo+7ITXL8Rp3xo3jwB5nkAGWBWZWyVL6VImPm5mRd1GnrMJx7MQUiXb8wOdtipB1r X-Received: by 10.84.244.193 with SMTP id f1mr39961007plt.32.1511801503801; Mon, 27 Nov 2017 08:51:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511801503; cv=none; d=google.com; s=arc-20160816; b=ZJ0Wtkjv7QleFo4RjDdouminLT26vytUaZyTBxT8FbXXD56yzurTewFApvrVlXeAUa JrNprJAAg1jUZeyjQCRALXGyDl1UiR0SJr/xRQvnCICpiWAqzK7KY8fPd7TPK1z1JfNM JWK1l6+IJEDbe1Pinid/vpgE4LOO/q59MpkZKaNer84uCH+VXWuRKBTlBhIviH0H6AGC MG4gvBm6DbCSm9Mc3oA+XKCjbiI3w8po/NkVf2LSQQoDAjcVk0NEhgdrLWBZm5jPxdiw U7F1kcByh/h3MrBo0SnZj2kNWgPDXnR005Wc7oXJ5d0dBW3RnsYNxOTFWlusb7O4+mRc jBjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :dlp-reaction:dlp-version:dlp-product:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:arc-authentication-results; bh=O8tsimM5K1R2tpPhYRkrTscafyYY1+Tozgz64Dm+0N4=; b=GVTLybSCAbp+PTqRLX5MtYSjaFq+SH1JU2OuLOzVzQfuLmOX+SLF/7wYcNdFGWF+5n qJo/6fYRAi58reSaXdAha69ox7ZZkrkIQeVkKNuKj8N0JhNpvAXCIjk14s8lplFfMgry NebtP/M3pUtD89K2axWxW7Vii7DEhQQn3bfkmbgXI7oDvNlbBvhpyiwH724r9KhSHKBX EzGAWXNZKeyJEc0hRTYJePtTUEa+MWsqiQTkUGnXeyP2acJHNFXcaLwCuIy/ldbA2GVR Xyx8P+PAP5jP16U4G0u17on6aDvPMxlqIYIssBLgBqhCVqnjUWu5antumH+cHwRGbYOi nPmw== 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 n65si10996821pfg.62.2017.11.27.08.51.32; Mon, 27 Nov 2017 08:51:43 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753544AbdK0Qum convert rfc822-to-8bit (ORCPT + 78 others); Mon, 27 Nov 2017 11:50:42 -0500 Received: from mga14.intel.com ([192.55.52.115]:3121 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753105AbdK0Quk (ORCPT ); Mon, 27 Nov 2017 11:50:40 -0500 Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Nov 2017 08:50:40 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,465,1505804400"; d="scan'208";a="153712950" Received: from fmsmsx108.amr.corp.intel.com ([10.18.124.206]) by orsmga004.jf.intel.com with ESMTP; 27 Nov 2017 08:50:39 -0800 Received: from fmsmsx154.amr.corp.intel.com (10.18.116.70) by FMSMSX108.amr.corp.intel.com (10.18.124.206) with Microsoft SMTP Server (TLS) id 14.3.319.2; Mon, 27 Nov 2017 08:50:30 -0800 Received: from shsmsx104.ccr.corp.intel.com (10.239.4.70) by FMSMSX154.amr.corp.intel.com (10.18.116.70) with Microsoft SMTP Server (TLS) id 14.3.319.2; Mon, 27 Nov 2017 08:50:30 -0800 Received: from shsmsx103.ccr.corp.intel.com ([169.254.4.213]) by SHSMSX104.ccr.corp.intel.com ([169.254.5.152]) with mapi id 14.03.0319.002; Tue, 28 Nov 2017 00:50:28 +0800 From: "Liang, Kan" To: "acme@kernel.org" , "peterz@infradead.org" , "mingo@redhat.com" , "linux-kernel@vger.kernel.org" CC: "jolsa@kernel.org" , "eranian@google.com" , "ak@linux.intel.com" , "Williams, Dan J" Subject: RE: [PATCH V2] perf script: add script to profile and resolve physical mem type Thread-Topic: [PATCH V2] perf script: add script to profile and resolve physical mem type Thread-Index: AQHTTd4TIJZdwMdEMU6VrilGLG4DTqMoo56g Date: Mon, 27 Nov 2017 16:50:28 +0000 Message-ID: <37D7C6CF3E00A74B8858931C1DB2F077537EB76B@SHSMSX103.ccr.corp.intel.com> References: <1508969363-351481-1-git-send-email-kan.liang@intel.com> In-Reply-To: <1508969363-351481-1-git-send-email-kan.liang@intel.com> Accept-Language: zh-CN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiZjQ5ZDllNGMtNjQzZi00YjRhLThmNTAtMWYyZTY0Mjc3NzM0IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX0lDIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE2LjUuOS4zIiwiVHJ1c3RlZExhYmVsSGFzaCI6ImloeUkxSDhBY3R3YUNiT21WVGsxMkpvZVNaaDZrYjRlNHZMdnEyRDMrS2s9In0= x-ctpclassification: CTP_IC dlp-product: dlpe-windows dlp-version: 11.0.0.116 dlp-reaction: no-action x-originating-ip: [10.239.127.40] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi all, Any comments for the patch? Thanks, Kan > > From: Kan Liang > > There could be different types of memory in the system. E.g normal > System Memory, Persistent Memory. To understand how the workload maps > to > those memories, it's important to know the I/O statistics of them. > Perf can collect physical addresses, but those are raw data. > It still needs extra work to resolve the physical addresses. > Provide a script to facilitate the physical addresses resolving and > I/O statistics. > > Profile with MEM_INST_RETIRED.ALL_LOADS or > MEM_UOPS_RETIRED.ALL_LOADS > event if any of them is available. > Look up the /proc/iomem and resolve the physical address. > Provide memory type summary. > > Here is an example output. > #perf script report mem-phys-addr > Event: mem_inst_retired.all_loads:P > Memory type count percentage > ---------------------------------------- ----------- ----------- > System RAM 74 53.2% > Persistent Memory 55 39.6% > N/A 10 7.2% > > Signed-off-by: Kan Liang > --- > > Changes since V1: > - Do not mix DLA and Load Latency. Do not compare the loads and stores. > Only profile the loads. > - Use event name to replace the RAW event > > tools/perf/scripts/python/bin/mem-phys-addr-record | 19 +++++ > tools/perf/scripts/python/bin/mem-phys-addr-report | 3 + > tools/perf/scripts/python/mem-phys-addr.py | 97 > ++++++++++++++++++++++ > .../util/scripting-engines/trace-event-python.c | 2 + > 4 files changed, 121 insertions(+) > create mode 100644 tools/perf/scripts/python/bin/mem-phys-addr-record > create mode 100644 tools/perf/scripts/python/bin/mem-phys-addr-report > create mode 100644 tools/perf/scripts/python/mem-phys-addr.py > > diff --git a/tools/perf/scripts/python/bin/mem-phys-addr-record > b/tools/perf/scripts/python/bin/mem-phys-addr-record > new file mode 100644 > index 0000000..5a87512 > --- /dev/null > +++ b/tools/perf/scripts/python/bin/mem-phys-addr-record > @@ -0,0 +1,19 @@ > +#!/bin/bash > + > +# > +# Profiling physical memory by all retired load instructions/uops event > +# MEM_INST_RETIRED.ALL_LOADS or MEM_UOPS_RETIRED.ALL_LOADS > +# > + > +load=`perf list | grep mem_inst_retired.all_loads` > +if [ -z "$load" ]; then > + load=`perf list | grep mem_uops_retired.all_loads` > +fi > +if [ -z "$load" ]; then > + echo "There is no event to count all retired load instructions/uops." > + exit 1 > +fi > + > +arg=$(echo $load | tr -d ' ') > +arg="$arg:P" > +perf record --phys-data -e $arg $@ > diff --git a/tools/perf/scripts/python/bin/mem-phys-addr-report > b/tools/perf/scripts/python/bin/mem-phys-addr-report > new file mode 100644 > index 0000000..3f2b847 > --- /dev/null > +++ b/tools/perf/scripts/python/bin/mem-phys-addr-report > @@ -0,0 +1,3 @@ > +#!/bin/bash > +# description: resolve physical address samples > +perf script $@ -s "$PERF_EXEC_PATH"/scripts/python/mem-phys-addr.py > diff --git a/tools/perf/scripts/python/mem-phys-addr.py > b/tools/perf/scripts/python/mem-phys-addr.py > new file mode 100644 > index 0000000..1d1f757 > --- /dev/null > +++ b/tools/perf/scripts/python/mem-phys-addr.py > @@ -0,0 +1,97 @@ > +# mem-phys-addr.py: Resolve physical address samples > +# Copyright (c) 2017, Intel Corporation. > +# > +# This program is free software; you can redistribute it and/or modify it > +# under the terms and conditions of the GNU General Public License, > +# version 2, as published by the Free Software Foundation. > +# > +# This program is distributed in the hope it will be useful, but WITHOUT > +# ANY WARRANTY; without even the implied warranty of > MERCHANTABILITY or > +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License > for > +# more details. > + > +from __future__ import division > +import os > +import sys > +import struct > +import re > +import bisect > +import collections > + > +sys.path.append(os.environ['PERF_EXEC_PATH'] + \ > + '/scripts/python/Perf-Trace-Util/lib/Perf/Trace') > + > +system_ram = [] > +pmem = [] > +f = None > +load_mem_type_cnt = collections.Counter() > +event_name = None > + > +def parse_iomem(): > + global f > + f = open('/proc/iomem', 'r') > + for i, j in enumerate(f): > + m = re.split('-|:',j,2) > + if m[2].strip() == 'System RAM': > + system_ram.append(long(m[0], 16)) > + system_ram.append(long(m[1], 16)) > + if m[2].strip() == 'Persistent Memory': > + pmem.append(long(m[0], 16)) > + pmem.append(long(m[1], 16)) > + > +def print_memory_type(): > + print "Event: %s" % (event_name) > + print "%-40s %10s %10s\n" % ("Memory type", "count", > "percentage"), > + print "%-40s %10s %10s\n" % ("----------------------------------------", \ > + "-----------", "-----------"), > + total = sum(load_mem_type_cnt.values()) > + for mem_type, count in sorted(load_mem_type_cnt.most_common(), > \ > + key = lambda(k, v): (v, k), reverse = > True): > + print "%-40s %10d %10.1f%%\n" % (mem_type, count, 100 * > count / total), > + > +def trace_begin(): > + parse_iomem() > + > +def trace_end(): > + print_memory_type() > + f.close() > + > +def is_system_ram(phys_addr): > + #/proc/iomem is sorted > + position = bisect.bisect(system_ram, phys_addr) > + if position % 2 == 0: > + return False > + return True > + > +def is_persistent_mem(phys_addr): > + position = bisect.bisect(pmem, phys_addr) > + if position % 2 == 0: > + return False > + return True > + > +def find_memory_type(phys_addr): > + if phys_addr == 0: > + return "N/A" > + if is_system_ram(phys_addr): > + return "System RAM" > + > + if is_persistent_mem(phys_addr): > + return "Persistent Memory" > + > + #slow path, search all > + f.seek(0, 0) > + for j in f: > + m = re.split('-|:',j,2) > + if long(m[0], 16) <= phys_addr <= long(m[1], 16): > + return m[2] > + return "N/A" > + > +def process_event(param_dict): > + name = param_dict["ev_name"] > + sample = param_dict["sample"] > + phys_addr = sample["phys_addr"] > + > + global event_name > + if event_name == None: > + event_name = name > + load_mem_type_cnt[find_memory_type(phys_addr)] += 1 > diff --git a/tools/perf/util/scripting-engines/trace-event-python.c > b/tools/perf/util/scripting-engines/trace-event-python.c > index c7187f0..8cd6317 100644 > --- a/tools/perf/util/scripting-engines/trace-event-python.c > +++ b/tools/perf/util/scripting-engines/trace-event-python.c > @@ -500,6 +500,8 @@ static PyObject *get_perf_sample_dict(struct > perf_sample *sample, > PyLong_FromUnsignedLongLong(sample->time)); > pydict_set_item_string_decref(dict_sample, "period", > PyLong_FromUnsignedLongLong(sample->period)); > + pydict_set_item_string_decref(dict_sample, "phys_addr", > + PyLong_FromUnsignedLongLong(sample- > >phys_addr)); > set_sample_read_in_dict(dict_sample, sample, evsel); > pydict_set_item_string_decref(dict, "sample", dict_sample); > > -- > 2.7.4 From 1583328445262710762@xxx Mon Nov 06 14:47:52 +0000 2017 X-GM-THRID: 1582269168036921833 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread