From patchwork Tue Feb 9 22:53:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Suthikulpanit, Suravee" X-Patchwork-Id: 61601 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp2316802lbl; Tue, 9 Feb 2016 14:55:03 -0800 (PST) X-Received: by 10.66.141.229 with SMTP id rr5mr54561407pab.123.1455058501889; Tue, 09 Feb 2016 14:55:01 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id rm12si346819pab.225.2016.02.09.14.55.01; Tue, 09 Feb 2016 14:55:01 -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 S965044AbcBIWyo (ORCPT + 30 others); Tue, 9 Feb 2016 17:54:44 -0500 Received: from mail-bn1bon0071.outbound.protection.outlook.com ([157.56.111.71]:43645 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S965002AbcBIWyk (ORCPT ); Tue, 9 Feb 2016 17:54:40 -0500 Authentication-Results: 8bytes.org; dkim=none (message not signed) header.d=none; 8bytes.org; dmarc=none action=none header.from=amd.com; Received: from localhost.localdomain (58.10.104.205) by BLUPR12MB0434.namprd12.prod.outlook.com (10.162.92.14) with Microsoft SMTP Server (TLS) id 15.1.403.16; Tue, 9 Feb 2016 22:54:34 +0000 From: Suravee Suthikulpanit To: , , , , CC: , , , Suravee Suthikulpanit Subject: [PATCH V3 4/5] perf/amd/iommu: Introduce get_iommu_bnk_cnt_evt_idx Date: Tue, 9 Feb 2016 16:53:54 -0600 Message-ID: <1455058435-8716-5-git-send-email-Suravee.Suthikulpanit@amd.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1455058435-8716-1-git-send-email-Suravee.Suthikulpanit@amd.com> References: <1455058435-8716-1-git-send-email-Suravee.Suthikulpanit@amd.com> MIME-Version: 1.0 X-Originating-IP: [58.10.104.205] X-ClientProxiedBy: SG2PR03CA0004.apcprd03.prod.outlook.com (25.160.233.14) To BLUPR12MB0434.namprd12.prod.outlook.com (25.162.92.14) X-MS-Office365-Filtering-Correlation-Id: b2a4a45e-8f9e-410f-2f5b-08d331a3fca9 X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0434; 2:i56xRqCeLmY5ivgCki21bMgC7kz4Sp2J6L+akdAunbFiiTIMxwR2OHl0NFnn9HaJuUiVmAUN/Erj5t5B6FxBgfuPWMfZnMcNW6vQtpxsDj0EaCdD7NdolP+6qRmGWMYOy22McVaDwZTZxlCdN9Db9IHFmt+Fho0Bhyu0vQhpF3occr0M2VWwqHUcMcEuU1wE; 3:A+rGH1C+QJolwKFlaWO8VzxTIxnRwIDEnoQjrlV5xFQyu4MFBimMsBRedzhd61xJohMLHTbgFvr3G5J8SN02NaqRNBfFxiJJcFa8BHPi7aRW/EerU3RnohnccDXnQd1U; 25:mzR4VEWur0xVXC2UzjppDoGpFT1/56VwNu9ylOAbWFMLtlMp3fJ2M4aojgA+yFOcjrtSyjcySvrctUm8U0xDA6VPEzsl01eMoSEiU83jaZbCciFp2e62v1oYuBz1ydoCrr6DGwDQV3cKbjzvHZp+jOlrLSfjkqJCz35YO5W+iJf4L8uOM00E5qifgSyXFxCbSKFhmbD+W3iTmmnu2q5atJIRIYYnxGFi2a537rH+oEsYn++GYnkA/CDCI3Ni7m8xlN2IRY9RWtsIN63uf+nm2x7xaljpdRdE5JlhYdJ3SJn+QsNrtqYcwXSmjULlLMgb X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BLUPR12MB0434; X-Micro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0; PCL:0; RULEID:(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046); SRVR:BLUPR12MB0434; BCL:0; PCL:0; RULEID:; SRVR:BLUPR12MB0434; X-Forefront-PRVS: 08476BC6EF X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(6069001)(19580405001)(19580395003)(48376002)(122386002)(36756003)(77096005)(5001960100002)(5003940100001)(92566002)(86362001)(50986999)(42186005)(76176999)(2906002)(87976001)(40100003)(5008740100001)(189998001)(4326007)(5004730100002)(50466002)(47776003)(66066001)(229853001)(50226001)(5001770100001)(3846002)(6116002)(1096002)(2950100001)(2201001)(586003); DIR:OUT; SFP:1101; SCL:1; SRVR:BLUPR12MB0434; H:localhost.localdomain; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0434; 23:LaJILwMKx31eE+iJG79iCuEi4kLfv+3HRLBVb8RNYophOGgCuQaHqasAXk3NxyRf7Uvw9PmJBIJbfuJNI/6f3FSrAlDjsf3fwAss1L2fDJiBaKLGW55R+dEpGQn23vyKWLCbkrNANebFgVA8EdRDzcevO3ykdDLR5V8h0fLknaAJXQngHdG1U/bmpxB+zzyIuQZptsJktjbXMcJJhZmqVPVetdzFwpayjjSwkGWRxbLoqTcHPgykXP9Kphaz10mE9xyWv20amya2GWADtLbTDYqlwdr0VPfLwC26VAj45jcU250kZKIunpMs197EwYU8OQEEOg49m7OexGjZhITdzVJea/w126N7uO4Jom0Zyy6wk+P5k/m4fx4VO6I612eIEjlRPA0tKeSIiJkRHGGLQewbH4agfTRk1PSulix7ZZDBMLTDwqPQkz2XPq8hDdUYhPjAlV94Xtuo5vy8jyDcAkGDm7O0Jb40nXZC+dR1JC8ZQu4rPBWiocSv1MpLCRI2XinZBLmDZ2AQ2p+50Owxs3//xEhcdAnE8l2G1Jpl9aGXsIE1If0LxdM5mdQaPE6kqs/6B3VgsVFEtm+apATHFsousYKCqwEJzOVU43xxMz4fRVQoFZJalom2w2HcdWR37NkNm9z717Vmw0mPvatshqkLtzG0HV6VQFbutVtuRJ8BpPxDWrZHE50Ek0zjUk2ILMyvW0D1uq4b73D78+/FbM2DUJC8PChHJxjlff71vLfM0xWq7/0yKVloNrxaQyNebWoSmtyDmETB3qtmMs1vt43G2ipZh5AdSomfjMYUCU6yxZDPxHjyz4o2oI47sJVPLs7OtYimOFrBrE7mPVxHDflAOY7ZcBUKSfvRYgIwc8MDVkgyMb19KIeii4EHX4Oey4UgmaDR7qzpzmFYG4pbxyJyUOCP6fEji/4ldDz7pIiED1yW9B/Ymogx7clYVDA+ X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0434; 5:w36l5DXrBdpmhx3ZJC5NQ97+d1eaDtAmUYOswJRhG39OYPArbRpRnGHeaeaCy2VNFsKTUMmFyMMSsYakpsAolx5mMeYFkQ5qLh654YKH+3QHMUFgxYTfzbk874z6yx+Tz9zWBvBVQTd6iMXvk/kCqQ==; 24:Ta6LDnZbcBDspzLFOlERN2QFbeK+NcRx1cwpb/70sznYrFu8qNNS9ZgH9vWaV4s7mzPnlR9nF9EvOI96+EnH/6OPSWagvpMORu6F5xHpY9I=; 20:4CCdeaGis8jGbwmETgH7JPEbZG0RmZn4BPsT7XAHg1Xva09M9UTHBW6+34B88Yh0Q7qqceWsSTqyzkFRRkIXokFlnxwj9KSZeGAGs+z4chWvIx2liGi+M7ZkAxQG6QGEllT7r/+0lE7O2XZWLt/JZJ7grekJFCGg4HJY7B4xRF78dcPT31/KN+oiQn/02cqscl1ICv3ap2BZEk8IMRA9g0qGwlhfvtIOMz6FyGyN+wx2txPhB/kFILrxWtvjJbL/ X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Feb 2016 22:54:34.5247 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR12MB0434 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Introduce a helper function to calculate bit-index for assigning performance counter assignment. Signed-off-by: Suravee Suthikulpanit --- arch/x86/kernel/cpu/perf_event_amd_iommu.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) -- 2.5.0 diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c index 2d59e20..791bbcf 100644 --- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c +++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c @@ -145,18 +145,28 @@ static struct attribute_group amd_iommu_cpumask_group = { /*---------------------------------------------*/ +static inline +int get_iommu_bnk_cnt_evt_idx(struct perf_amd_iommu *perf_iommu, + int iommu_index, int bank_index, + int cntr_index) +{ + int cntrs_per_iommu = perf_iommu->max_banks * perf_iommu->max_counters; + int index = (perf_iommu->max_counters * bank_index) + cntr_index; + + return (cntrs_per_iommu * iommu_index) + index; +} + static int get_next_avail_iommu_bnk_cntr(struct perf_amd_iommu *perf_iommu) { unsigned long flags; int shift, bank, cntr, retval; - int max_banks = perf_iommu->max_banks; - int max_cntrs = perf_iommu->max_counters; raw_spin_lock_irqsave(&perf_iommu->lock, flags); - for (bank = 0, shift = 0; bank < max_banks; bank++) { - for (cntr = 0; cntr < max_cntrs; cntr++) { - shift = bank + (bank*3) + cntr; + for (bank = 0, shift = 0; bank < perf_iommu->max_banks; bank++) { + for (cntr = 0; cntr < perf_iommu->max_counters; cntr++) { + shift = get_iommu_bnk_cnt_evt_idx(perf_iommu, + 0, bank, cntr); if (perf_iommu->cntr_assign_mask & (1ULL<