Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp922219imm; Wed, 6 Jun 2018 07:54:17 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLKuVpD80c2H8tvVEGAp0IwOdTqTyzWTVqFcpO0n+4vpYyKOMMn7irepbY7k9mXEGhgyGOK X-Received: by 2002:a17:902:2924:: with SMTP id g33-v6mr3620308plb.26.1528296857831; Wed, 06 Jun 2018 07:54:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528296857; cv=none; d=google.com; s=arc-20160816; b=jkV1gHi9MzDHLqoHA6vCFYzIqgGFF1cDu5vWrZmjSvqWbs8YwDu7e61pnlDJAdxAWU LslyUTN0hqr9R8OqF39Rj+weZ0KLOCJCcIzGME2YioYifQ0sef4pE+XCHzF19gkXa8QK dH2UCsDt+6PkAb8WSmOkQKnO1mgVyPYUSTKkrNtHU6Nc/GMLGPnRDvfYcC2xBPjThx08 flssHfFIuMsKBs/ExEWmhRsidsz+cVz6B3rglQDag9OLZMYUfaOI6MN1m6n+8vuE2k7/ OcGdogL4VHRjqQgSzBvR58XsCpgbqI18oK8tiwzzSJ+RMyHaGe7hLSYWmGc0rgKvsvgh dmWw== 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:message-id :content-language:in-reply-to:mime-version:user-agent:date:from :references:cc:to:subject:arc-authentication-results; bh=MdD5UD2koZU+lHZusiEDLurPgVNf5YLO2TdaREdRHOA=; b=caS8mFC4Dyav8C/PG9e86y3lEvOP1l/MsjSWC1x8tiJ7wdWI/cSWemrGtx2+EYeXZB bn7uYlZOK/NfVVktx2dS0Ka45mpF8/4+BbMuDM8Tn1wGzVx+6f/wNHbRYW+NuUNpUNIf D+AnYkSPLZxNQQ7hGHa8qdQ1YT69jh3NDPnZ3Mnyhevinydl+WagA532Z+8by9WyNm6t +oqtX8/s2FwHD+xB2Yj1JqmytaJ/lU21ix9v0JCZppZxNwXrDpWiRV0pGDrlOjoc2t27 Ji3lW3ELMZR05IaLV+d2iSFJXCKVOkLpM6nalFJHAgzTriFnBiGpLsQhHQqHwT+/OIrM 4nNg== 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 y1-v6si28676056pgv.36.2018.06.06.07.54.03; Wed, 06 Jun 2018 07:54:17 -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 S1752097AbeFFOxa (ORCPT + 99 others); Wed, 6 Jun 2018 10:53:30 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:49146 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751957AbeFFOx3 (ORCPT ); Wed, 6 Jun 2018 10:53:29 -0400 Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w56EnIjQ037003 for ; Wed, 6 Jun 2018 10:53:28 -0400 Received: from e16.ny.us.ibm.com (e16.ny.us.ibm.com [129.33.205.206]) by mx0b-001b2d01.pphosted.com with ESMTP id 2jegywtp90-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 06 Jun 2018 10:53:27 -0400 Received: from localhost by e16.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 6 Jun 2018 10:53:27 -0400 Received: from b01cxnp23033.gho.pok.ibm.com (9.57.198.28) by e16.ny.us.ibm.com (146.89.104.203) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 6 Jun 2018 10:53:24 -0400 Received: from b01ledav002.gho.pok.ibm.com (b01ledav002.gho.pok.ibm.com [9.57.199.107]) by b01cxnp23033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w56ErNwl15925746 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 6 Jun 2018 14:53:23 GMT Received: from b01ledav002.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C4BE0124054; Wed, 6 Jun 2018 11:54:49 -0400 (EDT) Received: from b01ledav002.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5D085124053; Wed, 6 Jun 2018 11:54:48 -0400 (EDT) Received: from oc3272150783.ibm.com (unknown [9.41.174.154]) by b01ledav002.gho.pok.ibm.com (Postfix) with ESMTPS; Wed, 6 Jun 2018 11:54:48 -0400 (EDT) Subject: Re: [PATCH 42/46] perf script powerpc: Python script for hypervisor call statistics To: Arnaldo Carvalho de Melo , Ravi Bangoria Cc: Ingo Molnar , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Alexander Shishkin , Jiri Olsa , Michael Ellerman , Namhyung Kim , "Naveen N . Rao" , Arnaldo Carvalho de Melo References: <20180605175030.32549-1-acme@kernel.org> <20180605175030.32549-43-acme@kernel.org> From: Paul Clarke Date: Wed, 6 Jun 2018 09:53:21 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <20180605175030.32549-43-acme@kernel.org> Content-Language: en-US X-TM-AS-GCONF: 00 x-cbid: 18060614-0072-0000-0000-000003694007 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00009139; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000265; SDB=6.01043027; UDB=6.00534142; IPR=6.00822157; MB=3.00021491; MTD=3.00000008; XFM=3.00000015; UTC=2018-06-06 14:53:26 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18060614-0073-0000-0000-00004844209A Message-Id: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-06-06_06:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1805220000 definitions=main-1806060170 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 06/05/2018 12:50 PM, Arnaldo Carvalho de Melo wrote: > From: Ravi Bangoria > > Add python script to show hypervisor call statistics. Ex, > > # perf record -a -e "{powerpc:hcall_entry,powerpc:hcall_exit}" > # perf script -s scripts/python/powerpc-hcalls.py > hcall count min(ns) max(ns) avg(ns) > -------------------------------------------------------------------- > H_RANDOM 82 838 1164 904 > H_PUT_TCE 47 1078 5928 2003 > H_EOI 266 1336 3546 1654 > H_ENTER 28 1646 4038 1952 > H_PUT_TCE_INDIRECT 230 2166 18168 6109 > H_IPI 238 1072 3232 1688 > H_SEND_LOGICAL_LAN 42 5488 21366 7694 > H_STUFF_TCE 294 986 6210 3591 > H_XIRR 266 2286 6990 3783 > H_PROTECT 10 2196 3556 2555 > H_VIO_SIGNAL 294 1028 2784 1311 > H_ADD_LOGICAL_LAN_BUFFER 53 1978 3450 2600 > H_SEND_CRQ 77 1762 7240 2447 This translation from HCALL code to mnemonic is more generally useful. Is there a good way to make the "hcall_table_lookup" function more generally available, like "syscall_name" in scripts/python/Perf-Trace-Util/lib/Perf/Trace/Util.py ? It's even simpler than the syscall ID-to-name mapping, because the HCALL codes are constant, unlike syscall IDs which vary between arches. > diff --git a/tools/perf/scripts/python/powerpc-hcalls.py b/tools/perf/scripts/python/powerpc-hcalls.py > new file mode 100644 > index 000000000000..00e0e7476e55 > --- /dev/null > +++ b/tools/perf/scripts/python/powerpc-hcalls.py > @@ -0,0 +1,200 @@ > +# SPDX-License-Identifier: GPL-2.0+ > +# > +# Copyright (C) 2018 Ravi Bangoria, IBM Corporation > +# > +# Hypervisor call statisics > + > +import os > +import sys > + > +sys.path.append(os.environ['PERF_EXEC_PATH'] + \ > + '/scripts/python/Perf-Trace-Util/lib/Perf/Trace') > + > +from perf_trace_context import * > +from Core import * > +from Util import * > + > +# output: { > +# opcode: { > +# 'min': minimum time nsec > +# 'max': maximum time nsec > +# 'time': average time nsec > +# 'cnt': counter > +# } ... > +# } > +output = {} > + > +# d_enter: { > +# cpu: { > +# opcode: nsec > +# } ... > +# } > +d_enter = {} > + > +hcall_table = { > + 4: 'H_REMOVE', > + 8: 'H_ENTER', > + 12: 'H_READ', > + 16: 'H_CLEAR_MOD', > + 20: 'H_CLEAR_REF', > + 24: 'H_PROTECT', > + 28: 'H_GET_TCE', > + 32: 'H_PUT_TCE', > + 36: 'H_SET_SPRG0', > + 40: 'H_SET_DABR', > + 44: 'H_PAGE_INIT', > + 48: 'H_SET_ASR', > + 52: 'H_ASR_ON', > + 56: 'H_ASR_OFF', > + 60: 'H_LOGICAL_CI_LOAD', > + 64: 'H_LOGICAL_CI_STORE', > + 68: 'H_LOGICAL_CACHE_LOAD', > + 72: 'H_LOGICAL_CACHE_STORE', > + 76: 'H_LOGICAL_ICBI', > + 80: 'H_LOGICAL_DCBF', > + 84: 'H_GET_TERM_CHAR', > + 88: 'H_PUT_TERM_CHAR', > + 92: 'H_REAL_TO_LOGICAL', > + 96: 'H_HYPERVISOR_DATA', > + 100: 'H_EOI', > + 104: 'H_CPPR', > + 108: 'H_IPI', > + 112: 'H_IPOLL', > + 116: 'H_XIRR', > + 120: 'H_MIGRATE_DMA', > + 124: 'H_PERFMON', > + 220: 'H_REGISTER_VPA', > + 224: 'H_CEDE', > + 228: 'H_CONFER', > + 232: 'H_PROD', > + 236: 'H_GET_PPP', > + 240: 'H_SET_PPP', > + 244: 'H_PURR', > + 248: 'H_PIC', > + 252: 'H_REG_CRQ', > + 256: 'H_FREE_CRQ', > + 260: 'H_VIO_SIGNAL', > + 264: 'H_SEND_CRQ', > + 272: 'H_COPY_RDMA', > + 276: 'H_REGISTER_LOGICAL_LAN', > + 280: 'H_FREE_LOGICAL_LAN', > + 284: 'H_ADD_LOGICAL_LAN_BUFFER', > + 288: 'H_SEND_LOGICAL_LAN', > + 292: 'H_BULK_REMOVE', > + 304: 'H_MULTICAST_CTRL', > + 308: 'H_SET_XDABR', > + 312: 'H_STUFF_TCE', > + 316: 'H_PUT_TCE_INDIRECT', > + 332: 'H_CHANGE_LOGICAL_LAN_MAC', > + 336: 'H_VTERM_PARTNER_INFO', > + 340: 'H_REGISTER_VTERM', > + 344: 'H_FREE_VTERM', > + 348: 'H_RESET_EVENTS', > + 352: 'H_ALLOC_RESOURCE', > + 356: 'H_FREE_RESOURCE', > + 360: 'H_MODIFY_QP', > + 364: 'H_QUERY_QP', > + 368: 'H_REREGISTER_PMR', > + 372: 'H_REGISTER_SMR', > + 376: 'H_QUERY_MR', > + 380: 'H_QUERY_MW', > + 384: 'H_QUERY_HCA', > + 388: 'H_QUERY_PORT', > + 392: 'H_MODIFY_PORT', > + 396: 'H_DEFINE_AQP1', > + 400: 'H_GET_TRACE_BUFFER', > + 404: 'H_DEFINE_AQP0', > + 408: 'H_RESIZE_MR', > + 412: 'H_ATTACH_MCQP', > + 416: 'H_DETACH_MCQP', > + 420: 'H_CREATE_RPT', > + 424: 'H_REMOVE_RPT', > + 428: 'H_REGISTER_RPAGES', > + 432: 'H_DISABLE_AND_GETC', > + 436: 'H_ERROR_DATA', > + 440: 'H_GET_HCA_INFO', > + 444: 'H_GET_PERF_COUNT', > + 448: 'H_MANAGE_TRACE', > + 468: 'H_FREE_LOGICAL_LAN_BUFFER', > + 472: 'H_POLL_PENDING', > + 484: 'H_QUERY_INT_STATE', > + 580: 'H_ILLAN_ATTRIBUTES', > + 592: 'H_MODIFY_HEA_QP', > + 596: 'H_QUERY_HEA_QP', > + 600: 'H_QUERY_HEA', > + 604: 'H_QUERY_HEA_PORT', > + 608: 'H_MODIFY_HEA_PORT', > + 612: 'H_REG_BCMC', > + 616: 'H_DEREG_BCMC', > + 620: 'H_REGISTER_HEA_RPAGES', > + 624: 'H_DISABLE_AND_GET_HEA', > + 628: 'H_GET_HEA_INFO', > + 632: 'H_ALLOC_HEA_RESOURCE', > + 644: 'H_ADD_CONN', > + 648: 'H_DEL_CONN', > + 664: 'H_JOIN', > + 676: 'H_VASI_STATE', > + 688: 'H_ENABLE_CRQ', > + 696: 'H_GET_EM_PARMS', > + 720: 'H_SET_MPP', > + 724: 'H_GET_MPP', > + 748: 'H_HOME_NODE_ASSOCIATIVITY', > + 756: 'H_BEST_ENERGY', > + 764: 'H_XIRR_X', > + 768: 'H_RANDOM', > + 772: 'H_COP', > + 788: 'H_GET_MPP_X', > + 796: 'H_SET_MODE', > + 61440: 'H_RTAS', > +} > + > +def hcall_table_lookup(opcode): > + if (hcall_table.has_key(opcode)): > + return hcall_table[opcode] > + else: > + return opcode > + > +print_ptrn = '%-28s%10s%10s%10s%10s' > + > +def trace_end(): > + print print_ptrn % ('hcall', 'count', 'min(ns)', 'max(ns)', 'avg(ns)') > + print '-' * 68 > + for opcode in output: > + h_name = hcall_table_lookup(opcode) > + time = output[opcode]['time'] > + cnt = output[opcode]['cnt'] > + min_t = output[opcode]['min'] > + max_t = output[opcode]['max'] > + > + print print_ptrn % (h_name, cnt, min_t, max_t, time/cnt) > + > +def powerpc__hcall_exit(name, context, cpu, sec, nsec, pid, comm, callchain, > + opcode, retval): > + if (d_enter.has_key(cpu) and d_enter[cpu].has_key(opcode)): > + diff = nsecs(sec, nsec) - d_enter[cpu][opcode] > + > + if (output.has_key(opcode)): > + output[opcode]['time'] += diff > + output[opcode]['cnt'] += 1 > + if (output[opcode]['min'] > diff): > + output[opcode]['min'] = diff > + if (output[opcode]['max'] < diff): > + output[opcode]['max'] = diff > + else: > + output[opcode] = { > + 'time': diff, > + 'cnt': 1, > + 'min': diff, > + 'max': diff, > + } > + > + del d_enter[cpu][opcode] > +# else: > +# print "Can't find matching hcall_enter event. Ignoring sample" > + > +def powerpc__hcall_entry(event_name, context, cpu, sec, nsec, pid, comm, > + callchain, opcode): > + if (d_enter.has_key(cpu)): > + d_enter[cpu][opcode] = nsecs(sec, nsec) > + else: > + d_enter[cpu] = {opcode: nsecs(sec, nsec)} > PC