From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751394AbbLUKzp (ORCPT ); Mon, 21 Dec 2015 05:55:45 -0500 Received: from eu-smtp-delivery-143.mimecast.com ([207.82.80.143]:41002 "EHLO eu-smtp-delivery-143.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751076AbbLUKzn convert rfc822-to-8bit (ORCPT ); Mon, 21 Dec 2015 05:55:43 -0500 Date: Mon, 21 Dec 2015 10:55:29 +0000 From: "Suzuki K. Poulose" To: Peter Zijlstra CC: , , , , 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+UAdppo3ubseZC6xY7jUH1XgVtJEbL9mH6OEGIsoOYChEGI61gMgViw3ohuz9EAR53KVOVB8c4tWxGXJ71lDhADykDbbIue7WQ3uOLeDDQFyUpVXHtTJqJa05oZuxHFdH9pL+fdBBm3uYsm6l6LynCXNQKsp5bFIIPraptiTiB1Zmj9bo4OH7XLUkc79CbSRhJfB6N1CE7TokEbvWUeDfhaqDhR72pEPQEU/nFCDoMySGLHJHRdSAUxtT8AP3t6NJTOVpKawDFLg==;25:/Nm19LmAQvCSZHdNkAyLV6vqJ0NGdAj2w1qfdxezAIc7YAWEbsnN0+XLDSUxGhDYPvo6biaq4/emGEDXHKKibyeFDgGbuLrFaHfHocnsY0M413SoqrQ7jkLNoRAkG22xJ3Dmwn6kguT7WwzMNk9lzZ8+RDhfnX8AK0JBDBCNlGCLF4237h1eLeBUoAuwIsuDt+Dnacx8E6a6O5GLDdcWS+cI7m24Z5d2iqrWjKhRb8fNejTFmbu9Bd3LWJzktJwtYpah6i5M3Xqt1JYGyzNcEw== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(8251501001);SRVR:AM4PR08MB0882; X-Microsoft-Exchange-Diagnostics: 1;AM4PR08MB0882;20:tODpUm1cBt/4KdK2+AqeNUVyy6rdYJpgrMSZR4z2s200unke/SadEuw1ob6bhnsosqsdU4u84W2WRK3eWi8Uj3QAWP/UiAyk9Yagzi/k+y1K6XwFiOqatSYd3uBDD8p5t3YfRu7H6r+uVLQ75GCZq5gxTQMQOd57HLuBD3dMs7G7+f+pNrwNPgU1fCglFTHI6FRRGBOS1zTtoJQyDcgK90u2EX/sAONQaCVST9J0/OfgTHLLdiVSok4D3lQVlM3n;4:IDMWS//DTqtH+UZZBkkA4LbnaBTkXRkK7l6fYj5xm8j/jdndtu8dK0hSk3gZB80h1mpyhq1QnBNdTU1Yyf8nwMgKBQK9N78JRKB5m9si5JR8Ag9By9bWY4UqG/rcJYModeK12BfUe5rMftMoKlJKVoCLg/0g/aAbn63lH3UBWKiiC1fHDNCcA9RirdPcBCXnW1wSBX6cN3Yew/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-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: 8BIT Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(-) 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); -- 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.