Received: by 10.213.65.68 with SMTP id h4csp3467243imn; Tue, 3 Apr 2018 05:35:01 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+SqDiHomNR670wLLmo3320GWloPFGi4Fc6hmbkCk6Xd9YA/7oovpLsU5pc/2nSeFzd+a1o X-Received: by 10.99.125.75 with SMTP id m11mr8946615pgn.391.1522758901782; Tue, 03 Apr 2018 05:35:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522758901; cv=none; d=google.com; s=arc-20160816; b=DGynTsEGkMni9y7O4QM8uhI40Rzb1ow070xEbfUNXaetNFJsoOKoSvO2z9k8v6mFUx fA+UlzUhpkP+ze/zm1PhQGfR39M3I0e+/W+BaCVGpvV4qeLkCbBPAp0ptcWS2ZmwY6Av AIt7xF2hffWUt2t4RBJuOZmrga4+qjF5fe+TqoOI/i7yLlM/kYAA8AIWOWJ7lqXxs+3e ykDsyXSThOhbjUyPrlPhwsSMkkUIGeoNpdX834WgY+HX89+5uEyX63i+cA24GjtdEVFh lLr45RO4AFF15gwgY0leK9MvBGvXTKHgG0BJcwkgMYHHl50gvhAZt9TeyUlH/9iLpN/W niQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=0mDsFxlyowh2ykTJURh/4QCEU3ANSLo903y+6gdY1bI=; b=V+4o0ARj6415n9Way9swMqz8XEv8+KNB/2TOWUhsy85Ev1U6gqC3RAHOgbCY3TgLzr RlbFqkiaNuVm4o42KTOtRr00YWiDWBUFdaLLcLseiTbmCfJaAzp6sgzk8F5NT//hBXLr AFYQ+fyYCXlsQygfnfQDmYbsG+RKreAnYIiOYh8ghi46HX8iaOcDq+MEFXgynlUYYHbz s7xSSG86ImtkpNUmkgYnh4f9KZb2Dbgt5h3i3IPY0NvVUEL1yzAn3I842fjmWqZ38ICj FBc9/vnGcEw+unrOy2jrDD1Y4/e5exyJJD626GMyhXNieT7hQRjRPsOlPoL5fOrY34o0 vbAA== 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 a86si2050652pfc.207.2018.04.03.05.34.48; Tue, 03 Apr 2018 05:35:01 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932191AbeDCMdF (ORCPT + 99 others); Tue, 3 Apr 2018 08:33:05 -0400 Received: from 9pmail.ess.barracuda.com ([64.235.154.211]:50369 "EHLO 9pmail.ess.barracuda.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932081AbeDCMdD (ORCPT ); Tue, 3 Apr 2018 08:33:03 -0400 Received: from MIPSMAIL01.mipstec.com (mailrelay.mips.com [12.201.5.28]) by mx1411.ess.rzc.cudaops.com (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NO); Tue, 03 Apr 2018 12:32:41 +0000 Received: from mredfearn-linux.mipstec.com (192.168.155.41) by MIPSMAIL01.mipstec.com (10.20.43.31) with Microsoft SMTP Server (TLS) id 14.3.361.1; Tue, 3 Apr 2018 05:32:26 -0700 From: Matt Redfearn To: James Hogan , Ralf Baechle CC: , Matt Redfearn , Namhyung Kim , "Maciej W. Rozycki" , Peter Zijlstra , , "Paul Burton" , Ingo Molnar , Jiri Olsa , Alexander Shishkin , Arnaldo Carvalho de Melo Subject: [PATCH 1/5] MIPS: perf: More robustly probe for the presence of per-tc counters Date: Tue, 3 Apr 2018 13:31:27 +0100 Message-ID: <1522758691-17003-2-git-send-email-matt.redfearn@mips.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1522758691-17003-1-git-send-email-matt.redfearn@mips.com> References: <1522758691-17003-1-git-send-email-matt.redfearn@mips.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [192.168.155.41] X-BESS-ID: 1522758734-452059-13817-58425-11 X-BESS-VER: 2018.4.1-r1803302241 X-BESS-Apparent-Source-IP: 12.201.5.28 X-BESS-Outbound-Spam-Score: 0.00 X-BESS-Outbound-Spam-Report: Code version 3.2, rules version 3.2.2.191653 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------- 0.00 BSF_BESS_OUTBOUND META: BESS Outbound X-BESS-Outbound-Spam-Status: SCORE=0.00 using account:ESS59374 scores of KILL_LEVEL=7.0 tests=BSF_BESS_OUTBOUND X-BESS-BRTS-Status: 1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Processors implementing the MIPS MT ASE may have performance counters implemented per core or per TC. Processors implemented by MIPS and the BMIPS5000 signify presence per TC through a bit in the implementation specific Config7 register. Currently the code which probes for their presence blindly reads a magic number corresponding to this bit, despite it potentially having a different meaning in the CPU implementation. Fix this by introducing probe_mipsmt_pertccounters() to probe for their presence. This detects the ases implemented in the CPU, and reads any implementation specific bit flagging their presence. In the case of MIPS and BMIPS5000 implementations, this bit is Config7.PTC. A definition of this bit is added in mipsregs.h for both MIPS Technologies implementations and BMIPS5000. Signed-off-by: Matt Redfearn --- The test of Config7.PTC was previously enabled when CONFIG_BMIPS5000 was enabled, whereas now it is based on Broadcom PRID. If this bit is not present / defined for all Broadcom implementations, please could someone present a correct alternative means to detect it? --- arch/mips/include/asm/mipsregs.h | 10 ++++++++++ arch/mips/kernel/perf_event_mipsxx.c | 32 +++++++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/arch/mips/include/asm/mipsregs.h b/arch/mips/include/asm/mipsregs.h index 858752dac337..4f61e16f43c3 100644 --- a/arch/mips/include/asm/mipsregs.h +++ b/arch/mips/include/asm/mipsregs.h @@ -684,6 +684,16 @@ #define MIPS_CONF7_IAR (_ULCAST_(1) << 10) #define MIPS_CONF7_AR (_ULCAST_(1) << 16) +/* Config7 Bits specific to MIPS Technologies. */ + +/* Performance counters implemented Per TC */ +#define MTI_CONF7_PTC (_ULCAST_(1) << 19) + +/* Config7 Bits specific to BMIPS5000. */ + +/* Performance counters implemented Per TC */ +#define BRCM_CONF7_PTC (_ULCAST_(1) << 19) + /* WatchLo* register definitions */ #define MIPS_WATCHLO_IRW (_ULCAST_(0x7) << 0) diff --git a/arch/mips/kernel/perf_event_mipsxx.c b/arch/mips/kernel/perf_event_mipsxx.c index 6668f67a61c3..3308b35d6680 100644 --- a/arch/mips/kernel/perf_event_mipsxx.c +++ b/arch/mips/kernel/perf_event_mipsxx.c @@ -1708,6 +1708,36 @@ static const struct mips_perf_event *xlp_pmu_map_raw_event(u64 config) return &raw_event; } +#ifdef CONFIG_MIPS_PERF_SHARED_TC_COUNTERS +/* + * The MIPS MT ASE specifies that performance counters may be implemented + * per core or per TC. If implemented per TC then all Linux CPUs have their + * own unique counters. If implemented per core, then VPEs in the core must + * treat the counters as a shared resource. + * Probe for the presence of per-TC counters + */ +static int probe_mipsmt_pertccounters(void) +{ + struct cpuinfo_mips *c = ¤t_cpu_data; + + /* Non-MT cores by definition cannot implement per-TC counters */ + if (!cpu_has_mipsmt) + return 0; + + switch (c->processor_id & PRID_COMP_MASK) { + case PRID_COMP_MIPS: + /* MTI implementations use CONFIG7.PTC to signify presence */ + return read_c0_config7() & MTI_CONF7_PTC; + case PRID_COMP_BROADCOM: + /* BMIPS5000 uses CONFIG7.PTC to signify presence */ + return read_c0_config7() & BRCM_CONF7_PTC; + default: + break; + } + return 0; +} +#endif /* CONFIG_MIPS_PERF_SHARED_TC_COUNTERS */ + static int __init init_hw_perf_events(void) { @@ -1723,7 +1753,7 @@ init_hw_perf_events(void) } #ifdef CONFIG_MIPS_PERF_SHARED_TC_COUNTERS - cpu_has_mipsmt_pertccounters = read_c0_config7() & (1<<19); + cpu_has_mipsmt_pertccounters = probe_mipsmt_pertccounters(); if (!cpu_has_mipsmt_pertccounters) counters = counters_total_to_per_cpu(counters); #endif -- 2.7.4