From patchwork Mon Dec 21 10:55:29 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 7894771 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 3A0499F349 for ; Mon, 21 Dec 2015 10:58:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3AFD02037E for ; Mon, 21 Dec 2015 10:58:01 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 368C42037C for ; Mon, 21 Dec 2015 10:58:00 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aAy8Q-0002mE-6V; Mon, 21 Dec 2015 10:56:10 +0000 Received: from eu-smtp-delivery-143.mimecast.com ([207.82.80.143]) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aAy8M-0002el-0B for linux-arm-kernel@lists.infradead.org; Mon, 21 Dec 2015 10:56:07 +0000 Received: from emea01-am1-obe.outbound.protection.outlook.com (mail-am1lrp0016.outbound.protection.outlook.com [213.199.154.16]) (Using TLS) by eu-smtp-1.mimecast.com with ESMTP id uk-mta-34-Ucb_Ls0MTXeL4ld8FpaC7Q-1; Mon, 21 Dec 2015 10:55:41 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector1-arm-com; h=From:To:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=xFUmlCpd2SHU9i4vymFaoiVrn5hWW5PI3zb0qdGl4FU=; b=euhCwLBaxxlk4x1h6oL1325KpOXqw14iSZULaNl1XgNZhOuMWvUhIcX884SXpOsYtkIscE/0cGzyACxLTfw4MxaK4ImZ5vRq2xDIDW1mP7kfkS47Xa+h55DQ+K0ZuJYlrYGz//BruV/IjBgal8eWt7C0CY/TnyKHXBopmyVjvRs= Received: from HE1PR08CA0009.eurprd08.prod.outlook.com (10.161.112.19) by AM4PR08MB0882.eurprd08.prod.outlook.com (10.164.83.28) with Microsoft SMTP Server (TLS) id 15.1.361.13; Mon, 21 Dec 2015 10:55:39 +0000 Received: from AM1FFO11FD024.protection.gbl (2a01:111:f400:7e00::160) by HE1PR08CA0009.outlook.office365.com (2a01:111:e400:5097::19) with Microsoft SMTP Server (TLS) id 15.1.361.13 via Frontend Transport; Mon, 21 Dec 2015 10:55:39 +0000 Received: from nebula.arm.com (217.140.96.140) by AM1FFO11FD024.mail.protection.outlook.com (10.174.64.213) with Microsoft SMTP Server (TLS) id 15.1.355.15 via Frontend Transport; Mon, 21 Dec 2015 10:55:37 +0000 Received: from e106634-lin.cambridge.arm.com (10.1.2.79) by mail.arm.com (10.1.106.66) with Microsoft SMTP Server id 14.3.266.1; Mon, 21 Dec 2015 10:55:29 +0000 Date: Mon, 21 Dec 2015 10:55:29 +0000 From: "Suzuki K. Poulose" To: Peter Zijlstra Subject: Re: [PATCH v4 05/12] arm-cci: PMU: Add support for transactions Message-ID: <20151221105528.GA19617@e106634-lin.cambridge.arm.com> References: <1450374559-23315-1-git-send-email-suzuki.poulose@arm.com> <1450374559-23315-6-git-send-email-suzuki.poulose@arm.com> <20151217184255.GI6344@twins.programming.kicks-ass.net> <5673DFC7.6060406@arm.com> <20151218104234.GN6344@twins.programming.kicks-ass.net> <5673E6C9.7040304@arm.com> <20151218114751.GP6344@twins.programming.kicks-ass.net> MIME-Version: 1.0 In-Reply-To: <20151218114751.GP6344@twins.programming.kicks-ass.net> User-Agent: Mutt/1.5.21 (2010-09-15) X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1; AM1FFO11FD024; 1:C8MOylso4U+AN2d/Te9uKu9XPBKlBJNXEYd08upUfUGW4PqSsVq13ekywiOfXKbbpVop1gCnPQRsBo28egbikBlvwj/z8ms89Wz5GZYz1NMkbxVH4cTDrHtDcihqpplZ5e6z49MdeE2q18u5yhyX9KU+yPggWfBZpg4JmutG2VBUwhCM5497Mxn9Bk254ccEfL5sxZfJjXlpiHFRl946zAWEz+vD1H7frhFLOH032/qlo2OxqzBTh5EiQyodPBMLqd799RZiEvL5WZSuTy10lNLrZacx3d3m2Kg68LfE9NmqxL4Q9t0DDPZqiIFnvgEVIRFJLYv59C4heQdIbBCifcBxDLOkIb6G60IU/1RWSDmNCnknzYaYSRmPC5mNB/PDsZfLD+gJYYvabbVOBKgl7A== X-Forefront-Antispam-Report: CIP:217.140.96.140; CTRY:GB; IPV:CAL; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(2980300002)(438002)(189002)(24454002)(199003)(40434004)(83506001)(76176999)(47776003)(86362001)(5008740100001)(50986999)(19580395003)(26826002)(93886004)(54356999)(87936001)(97756001)(5003600100002)(46406003)(189998001)(1076002)(77096005)(5890100001)(33656002)(1220700001)(11100500001)(110136002)(2950100001)(586003)(1096002)(104016004)(50466002)(19580405001)(92566002)(6806005)(106466001)(4001350100001)(23726003); DIR:OUT; SFP:1101; SCL:1; SRVR:AM4PR08MB0882; H:nebula.arm.com; FPR:; SPF:Pass; PTR:fw-tnat.cambridge.arm.com; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; AM4PR08MB0882; 2:8SKBVRZFTmbmaiYl4BhUrjJNUk6p0dawpEh1meyxafwJ/yxGP+bn433scQJoW7+kbOcS2oshsJpYL8fGIW+kDro6Vgd8JNP5hq6MG91ZaMds6nx6PFHcdaHEZ2tm9wqVskRIfbGd3iaaKqs56J3Rmg==; 3:Tmqb7ZfCFy+UAdppo3ubseZC6xY7jUH1XgVtJE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XnW1wSBX6cN3Yew/Z0W1ZRYzkAhbE1Q6OvLt455jGiJQ9HD03U0ihH/Ao3Se8o1MN/OIfHeYWJ/JZ/a02YJ1M0iTVQUqHnBQdITBC/460mToC82Ng079NSHbfHaTy4m4a81YrryzKkuaR9Xika1i6UprdfQH03Lw1J11axA6pufa6Qk36jawHUa7KnIymawLs//0fiLIrBpAFjIXGoEGhYE1LtmafRvMTET2fbcHv4P/tGOihOJ61IDqM4caVaLVzU X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(180628864354917); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(520078)(5005006)(8121501046)(3002001)(10201501046); SRVR:AM4PR08MB0882; BCL:0; PCL:0; RULEID:; SRVR:AM4PR08MB0882; X-Forefront-PRVS: 079756C6B9 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; AM4PR08MB0882; 23:sGxvwwOuweLcDbftsW5+yZpX/p/4NcJykkWbmjl8T?= =?us-ascii?Q?oflyursSWdc0wfgfeRGwngk+KJNeF5XJtV2OqmS1IZqrbbhbO9ldokbMFiFP?= =?us-ascii?Q?XdhxgjPRy3xXmeKKpFwYCLp6jaywMl0nR+maI+YxnjABAspftpOJIzWQwHd5?= =?us-ascii?Q?y6qjA1qu0KzUPt2yb9KgAIQoIrIso6FiYwP4MJ8jMMSS1imUhpLVsj3ene8C?= =?us-ascii?Q?IbPQ2hVCUhmPrXbAzGxa+dkF6/T+ucyE2iGklhm1JxqIEB9BypKqpYflK7ZA?= =?us-ascii?Q?qJ5trdAxoYyHSUZae3VSHS6ZzUfKeC7T9G8nvDqrMS830Tne6rFLjpvhG8X5?= =?us-ascii?Q?KFveYlQzBhFrT5Fx1yjiZWr5uzO+NOTP7oDpsLnTWUnomxnsKbWhtD1LxRKU?= =?us-ascii?Q?NUwjwdlA4xPMwh9plyemKGGMv0/l2MzCkqFgFLrKug/Ap+Dx2herYgOGJ+zb?= =?us-ascii?Q?xdjzXwdYpGLM6xae0U9tImroitG+2F31XomG4bjK65LicIM7d7ArjguNFqku?= =?us-ascii?Q?RG10WliIJdOxOK0FJ6snRw/w7kx2NuFas/sRrNlDsFRw4Vn3Cojohmukxbmd?= =?us-ascii?Q?o9lLjidK1lFblp4oLgluG/innJ2RM9FxJTALNM3Bd9pOvEI5qpMD8KssbaMU?= =?us-ascii?Q?szCCVU5+nb7FU0LbeW0ZHYFP4X4xF6PkjDIRTkY9yQ+DqE6BMHV8776pAO49?= =?us-ascii?Q?BG/SUX4lI9uoYopX7HSNdFgaF9rWi3vcpouNSIe6mea65udAaCfWj976k39C?= =?us-ascii?Q?n+duC02O+/WI/GTbBKSbbqKlejsuFm6rFReT5czrubWMomZNCIT9qjzOHLzu?= =?us-ascii?Q?b3iT59xixtDJ8IsCKBIfElK2AqgamI6WWP49sakEkpLOhw2GImqgYxnv2JV5?= =?us-ascii?Q?fw9U6+9sX5yWGSUmddmvBiEMh0mW5IKzSnU8AavwvTalKOmvp1AkUrY6lzlG?= =?us-ascii?Q?r0UAlr85FQOHPODvCzCVr3rn+QjUoXuJpF42SY4P0nle8e8zBhB930DNnvcl?= =?us-ascii?Q?XXQVVNlb++6s2D+2nxcbD6Npsc3tYTxlkAHTzVP4RxjTWX2QI+ND0Qy9z7+z?= =?us-ascii?Q?2EfDR4yGbk5VJfIZQH+pasfbsMT?= X-Microsoft-Exchange-Diagnostics: 1; AM4PR08MB0882; 5:CBkrhgDbv+PMNDcVaL+kdoVUduwNzhui+MyXjSmB+8/RuJ4PxA8kr2Tl4U2MHi7ICld57YCBBT5vj9e515Oq6eMTFSQbW2UOiEeboqTsAuQtjzqUu7Hjf0ufoK2IgzrCStgpD6LoWZyCWLjx+b99Xg==; 24:6CeUPOxbS6pJXHgICsf34Azn6VS9ACdbIR2c1y3/nLNdNStonbTkfLcsy8Zj0R5qdShMq/fVDD1FKZC8ZFSZnf7xucxQNZfUW2D9rfI0flo=; 20:2qgIyOnkKtXGl6g8XQh0ggcuXBiOj/uPu6lZkPjOo1vCTYeZ4lTSlFVssgWt2esF1sxk4rSQcxs+hHsondVawQZJRQ7Nh5CClm0m4GpceDiKVHrIgCr0Ukn2x4La1O8YbHF8QXf9PebB2vEjBCI+dwPueyGIN7D11rriEQblgus= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Dec 2015 10:55:37.7185 (UTC) X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[217.140.96.140]; Helo=[nebula.arm.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR08MB0882 X-MC-Unique: Ucb_Ls0MTXeL4ld8FpaC7Q-1 Content-Disposition: inline X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151221_025606_362639_9B92AC50 X-CRM114-Status: GOOD ( 21.19 ) X-Spam-Score: -4.1 (----) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, punit.agrawal@arm.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, arm@kernel.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED,RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Fri, Dec 18, 2015 at 12:47:51PM +0100, Peter Zijlstra wrote: > On Fri, Dec 18, 2015 at 10:58:17AM +0000, Suzuki K. Poulose wrote: > > > We have a global Enable/Disable for CCI PMU and thats what we use > > currently. To be able to reprogram the counters with the event period > > (we program the counter with a specific count in pmu::start() and at > > overflow irq handler, not to be confused with the sampling period, which > > is not supported), we need to be sure that the counter value has been updated. > > > > May be we could check the event->hw->state to see if we need to reprogram it. > > Right, have a look at arch/x86/kernel/cpu/perf_event.c:x86_pmu_enable() > Thanks for that hint. Here is what I cam up with. We don't reschedule the events, all we need to do is group the writes to the counters. Hence we could as well add a flag for those events which need programming and perform the write in pmu::pmu_enable(). ----8>----- arm-cci PMU: Delay counter writes to pmu_enable Delay setting the event periods for enabled events to pmu::pmu_enable(). We mark the event.hw->state PERF_HES_ARCH for the events that we know have their counts recorded and have been started. Since we reprogram the counters every time before count, we can set the counters for all the event counters which are !STOPPED && ARCH. Grouping the writes to counters can ammortise the cost of the operation on PMUs where it is expensive (e.g, CCI-500). Cc: Mark Rutland Cc: Punit Agrawal Cc: peterz@infradead.org Signed-off-by: Suzuki K. Poulose --- drivers/bus/arm-cci.c | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. diff --git a/drivers/bus/arm-cci.c b/drivers/bus/arm-cci.c index 0189f3a..c768ee4 100644 --- a/drivers/bus/arm-cci.c +++ b/drivers/bus/arm-cci.c @@ -916,6 +916,40 @@ static void hw_perf_event_destroy(struct perf_event *event) } } +/* + * Program the CCI PMU counters which have PERF_HES_ARCH set + * with the event period and mark them ready before we enable + * PMU. + */ +void cci_pmu_update_counters(struct cci_pmu *cci_pmu) +{ + int i; + unsigned long mask[BITS_TO_LONGS(cci_pmu->num_cntrs)]; + + memset(mask, 0, BITS_TO_LONGS(cci_pmu->num_cntrs) * sizeof(unsigned long)); + + for_each_set_bit(i, cci_pmu->hw_events.used_mask, cci_pmu->num_cntrs) { + struct hw_perf_event *hwe; + + if (!cci_pmu->hw_events.events[i]) { + WARN_ON(1); + continue; + } + + hwe = &cci_pmu->hw_events.events[i]->hw; + /* Leave the events which are not counting */ + if (hwe->state & PERF_HES_STOPPED) + continue; + if (hwe->state & PERF_HES_ARCH) { + set_bit(i, mask); + hwe->state &= ~PERF_HES_ARCH; + local64_set(&hwe->prev_count, CCI_CNTR_PERIOD); + } + } + + pmu_write_counters(cci_pmu, mask, CCI_CNTR_PERIOD); +} + static void cci_pmu_enable(struct pmu *pmu) { struct cci_pmu *cci_pmu = to_cci_pmu(pmu); @@ -927,6 +961,7 @@ static void cci_pmu_enable(struct pmu *pmu) return; raw_spin_lock_irqsave(&hw_events->pmu_lock, flags); + cci_pmu_update_counters(cci_pmu); __cci_pmu_enable(); raw_spin_unlock_irqrestore(&hw_events->pmu_lock, flags); @@ -980,8 +1015,11 @@ static void cci_pmu_start(struct perf_event *event, int pmu_flags) /* Configure the counter unless you are counting a fixed event */ if (!pmu_fixed_hw_idx(cci_pmu, idx)) pmu_set_event(cci_pmu, idx, hwc->config_base); - - pmu_event_set_period(event); + /* + * Mark this counter, so that we can program the + * counter with the event_period. see cci_pmu_enable() + */ + hwc->state = PERF_HES_ARCH; pmu_enable_counter(cci_pmu, idx); raw_spin_unlock_irqrestore(&hw_events->pmu_lock, flags);