Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp2620160ybi; Thu, 18 Jul 2019 11:18:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqxzBIa90kp0dpMDJ1wNSIfNN4hVIshHdVT2xs965C628nN43VYUvWoAX+T3/JMPto5TfkIo X-Received: by 2002:a17:902:1003:: with SMTP id b3mr52338074pla.172.1563473929716; Thu, 18 Jul 2019 11:18:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563473929; cv=none; d=google.com; s=arc-20160816; b=k9FISpiXW1Z420O6BX1lGq3QPut3sgPwwD/BClt7N4PNKcTnU8f19aH4ghxbTjabZJ eMOzo+MV0jvydhOAfRaMAnxaeKXy0hjpJ9hj2RRXbv9oinHozQ/dqBuRSAs6dcp/Ekpi GBl2J5Kwvb83YJAueLY7LNljpaOBTuSRzUJDqhKjjeqS3bhZ/R2RK0HHNtGRrsPK3DCS 3QVi/FvKuUEP7snngSLnk5BkBcDLGtsaOqKClqisjn40AYlxmFq/jyFKzkiDfi3kbwdr g9oO2kwc7l9dPYyAkny4TflHNMP/1VgNPK3zLA1uhxq64h0S5oxqgdgYbD6nJfbqLYPu 1niA== 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=9Dj+l/9yPIj9elRY2k2SRmpB8V6g3qPRujBW5eRvse8=; b=OjcHkqSuMPhjjzo+fGhbplcRgNwZGb1WKSdR2L9Yvr83Rkk2GT6c+AbpOn5O+J/JWf WdVkLriX+nD30KP9s6FReAatX7SK+/5GsnfORDcNXkzHl/YnsrkFQhvl9/WeYuwPpBqi iaLow00GNo0cxLiXWiagdJ1y+XggIcDAJI7adUSW2WjbRJXUEZFg97qpAPPXMJ0nLL0w GO+lw91iStCFjoJRG5ZR+fsdmEcwNHEGNx31RQilIy+rdPon14bRUgk/SEL/cMdNo2Gr NXmuXBcojvJ8dzeERh6yIO+X9tLanKdPEeiqNEWR3k0u4aeZislG4g7IbAAzJFaIYqyH mDng== 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 68si754389plc.269.2019.07.18.11.18.34; Thu, 18 Jul 2019 11:18:49 -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 S2390951AbfGRSSI (ORCPT + 99 others); Thu, 18 Jul 2019 14:18:08 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:19442 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728183AbfGRSSH (ORCPT ); Thu, 18 Jul 2019 14:18:07 -0400 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x6II3EMg043185 for ; Thu, 18 Jul 2019 14:18:05 -0400 Received: from e06smtp03.uk.ibm.com (e06smtp03.uk.ibm.com [195.75.94.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 2ttw9s1p0v-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 18 Jul 2019 14:18:05 -0400 Received: from localhost by e06smtp03.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 18 Jul 2019 19:18:03 +0100 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp03.uk.ibm.com (192.168.101.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Thu, 18 Jul 2019 19:18:00 +0100 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x6IIHxBm56295462 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 18 Jul 2019 18:17:59 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6ED894C04E; Thu, 18 Jul 2019 18:17:59 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 216784C046; Thu, 18 Jul 2019 18:17:57 +0000 (GMT) Received: from localhost.localdomain.com (unknown [9.199.42.37]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 18 Jul 2019 18:17:56 +0000 (GMT) From: Anju T Sudhakar To: mpe@ellerman.id.au, acme@kernel.org, jolsa@redhat.com Cc: namhyung@kernel.org, peterz@infradead.org, alexander.shishkin@linux.intel.com, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, maddy@linux.vnet.ibm.com, anju@linux.vnet.ibm.com, ravi.bangoria@linux.ibm.com Subject: [PATCH v2 2/3] tools/perf: Add arch neutral function to choose event for perf kvm record Date: Thu, 18 Jul 2019 23:47:48 +0530 X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190718181749.30612-1-anju@linux.vnet.ibm.com> References: <20190718181749.30612-1-anju@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 x-cbid: 19071818-0012-0000-0000-000003342229 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19071818-0013-0000-0000-0000216DA54D Message-Id: <20190718181749.30612-2-anju@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-07-18_09:,, 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=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1907180187 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 'perf kvm record' uses 'cycles'(if the user did not specify any event) as the default event to profile the guest. This will not provide any proper samples from the guest incase of powerpc architecture, since in powerpc the PMUs are controlled by the guest rather than the host. Patch adds a function to pick an arch specific event for 'perf kvm record', instead of selecting 'cycles' as a default event for all architectures. For powerpc this function checks for any user specified event, and if there isn't any it returns invalid instead of proceeding with 'cycles' event. Signed-off-by: Anju T Sudhakar --- Changes from v1->v2 * Cross-build issue for aarch64, reported by Ravi is fixed. --- tools/perf/arch/powerpc/util/kvm-stat.c | 37 +++++++++++++++++++++++++ tools/perf/builtin-kvm.c | 12 +++++++- tools/perf/util/kvm-stat.h | 1 + 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/tools/perf/arch/powerpc/util/kvm-stat.c b/tools/perf/arch/powerpc/util/kvm-stat.c index f9db341c47b6..c55e7405940e 100644 --- a/tools/perf/arch/powerpc/util/kvm-stat.c +++ b/tools/perf/arch/powerpc/util/kvm-stat.c @@ -8,6 +8,7 @@ #include "book3s_hv_exits.h" #include "book3s_hcalls.h" +#include #define NR_TPS 4 @@ -172,3 +173,39 @@ int cpu_isa_init(struct perf_kvm_stat *kvm, const char *cpuid __maybe_unused) return ret; } + +/* + * Incase of powerpc architecture, pmu registers are programmable + * by guest kernel. So monitoring guest via host may not provide + * valid samples. It is better to fail the "perf kvm record" + * with default "cycles" event to monitor guest in powerpc. + * + * Function to parse the arguments and return appropriate values. + */ +int kvm_add_default_arch_event(int *argc, const char **argv) +{ + const char **tmp; + bool event = false; + int i, j = *argc; + + const struct option event_options[] = { + OPT_BOOLEAN('e', "event", &event, NULL), + OPT_END() + }; + + tmp = calloc(j + 1, sizeof(char *)); + if (!tmp) + return -EINVAL; + + for (i = 0; i < j; i++) + tmp[i] = argv[i]; + + parse_options(j, tmp, event_options, NULL, PARSE_OPT_KEEP_UNKNOWN); + if (!event) { + free(tmp); + return -EINVAL; + } + + free(tmp); + return 0; +} diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 5d2b34d290a3..d03750da051b 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -1510,11 +1510,21 @@ static int kvm_cmd_stat(const char *file_name, int argc, const char **argv) } #endif /* HAVE_KVM_STAT_SUPPORT */ +int __weak kvm_add_default_arch_event(int *argc __maybe_unused, + const char **argv __maybe_unused) +{ + return 0; +} + static int __cmd_record(const char *file_name, int argc, const char **argv) { - int rec_argc, i = 0, j; + int rec_argc, i = 0, j, ret; const char **rec_argv; + ret = kvm_add_default_arch_event(&argc, argv); + if (ret) + return -EINVAL; + rec_argc = argc + 2; rec_argv = calloc(rec_argc + 1, sizeof(char *)); rec_argv[i++] = strdup("record"); diff --git a/tools/perf/util/kvm-stat.h b/tools/perf/util/kvm-stat.h index b3b2670e1a2b..81a5bf4fbc71 100644 --- a/tools/perf/util/kvm-stat.h +++ b/tools/perf/util/kvm-stat.h @@ -148,4 +148,5 @@ extern const char *kvm_entry_trace; extern const char *kvm_exit_trace; #endif /* HAVE_KVM_STAT_SUPPORT */ +extern int kvm_add_default_arch_event(int *argc, const char **argv); #endif /* __PERF_KVM_STAT_H */ -- 2.20.1