Received: by 10.223.185.116 with SMTP id b49csp8720649wrg; Fri, 2 Mar 2018 06:53:30 -0800 (PST) X-Google-Smtp-Source: AG47ELueX1GpKNq/reLrzCItxCP5/YyHE+H53nhRb2/Q0kzWccb4m2gx1h310sXHKs2o3corkeDq X-Received: by 10.98.238.2 with SMTP id e2mr5918956pfi.68.1520002410656; Fri, 02 Mar 2018 06:53:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520002410; cv=none; d=google.com; s=arc-20160816; b=MNzXwKRWbeqR1g0lnPRCUCxf4IU1E51V/HAOSZQvIt+dyce981HDIomVPmQZ6E24sP fpmtsRqvwBLlY5krm9Wzigr8g3+p57/WUWnPpqcee9zFITJJCwO+RqD9XpfBrybDl8o3 s8l5CKc5KI3xCsqar+sbyts973k0OU0NVBCMOB7jSbD7vTJPbkezciBzbsmdyb6V7Kv9 9z1q/ThOPz5AJj6sU5PjZ7oBOMsi7dsOH7Zgr/oT7IrupK3m/76MsJGPuXe7i+lHtShj P5zcvhcdVx2ETjYXCMyRjzB32y1QFNfKUwx7hR8bHMWjRmvlHYNkZOLpZo45d4xrbXr6 JP7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=60jYLMjoMMas+p1/CYLsumuP6rkM0NSzB+3CB4fhj0I=; b=f9xKGh5G6ej4aontx71hxwsZl7IUY4xp60qiOpBqbNNb1Mo/J07V0Og+3StEleZBHw oAvkXAxpsr58CQO2CxPeBGgrR4TqW9NRsetcZhgn3nM2/bRzxVktMDlzAQDq7pudm40T EBhG79WKvlNkBV6J/4gzJDlmhfvt+ZH3vDjfMd7+2xw85Vx4QaYWlun0Ih7c5PpVC0bo 2TusktEV9HwTsw8ABwZRUg/0x5eoVqvKXfX4hXcH1jKyRMxgxNk293ng9RBRxLAyEm75 tazxfO971asbyNZXz2QeiLScP+q9AwRP2zD7MgByb0X7e4bTcky6yoY244cIddPubXfM lQRQ== 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 g15si4929851pfi.330.2018.03.02.06.53.15; Fri, 02 Mar 2018 06:53:30 -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 S1426513AbeCBKmh (ORCPT + 99 others); Fri, 2 Mar 2018 05:42:37 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:52882 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1424102AbeCBKm2 (ORCPT ); Fri, 2 Mar 2018 05:42:28 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9C97C1596; Fri, 2 Mar 2018 02:42:28 -0800 (PST) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4E4543F318; Fri, 2 Mar 2018 02:42:26 -0800 (PST) Date: Fri, 2 Mar 2018 10:42:23 +0000 From: Mark Rutland To: Saravana Kannan Cc: robh@kernel.org, mathieu.poirier@linaro.org, Suzuki K Poulose , peterz@infradead.org, jonathan.cameron@huawei.com, will.deacon@arm.com, linux-kernel@vger.kernel.org, marc.zyngier@arm.com, sudeep.holla@arm.com, frowand.list@gmail.com, leo.yan@linaro.org, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH v11 8/8] perf: ARM DynamIQ Shared Unit PMU support Message-ID: <20180302104223.7tpsyhsum7nej237@lakrids.cambridge.arm.com> References: <20180102112533.13640-1-suzuki.poulose@arm.com> <20180102112533.13640-9-suzuki.poulose@arm.com> <5A90B77E.8040105@codeaurora.org> <20180225143653.peb4quk3ha5h3t5x@salmiak> <5A972A7D.9020301@codeaurora.org> <20180301114911.fundyuqxtj5klk4e@lakrids.cambridge.arm.com> <5A986425.9080007@codeaurora.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5A986425.9080007@codeaurora.org> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 01, 2018 at 12:35:49PM -0800, Saravana Kannan wrote: > On 03/01/2018 03:49 AM, Mark Rutland wrote: > > On Wed, Feb 28, 2018 at 02:17:33PM -0800, Saravana Kannan wrote: > > > On 02/25/2018 06:36 AM, Mark Rutland wrote: > > > > On Fri, Feb 23, 2018 at 04:53:18PM -0800, Saravana Kannan wrote: > > > > > On 01/02/2018 03:25 AM, Suzuki K Poulose wrote: > > > > > > +static void dsu_pmu_event_update(struct perf_event *event) > > > > > > +{ > > > > > > + struct hw_perf_event *hwc = &event->hw; > > > > > > + u64 delta, prev_count, new_count; > > > > > > + > > > > > > + do { > > > > > > + /* We may also be called from the irq handler */ > > > > > > + prev_count = local64_read(&hwc->prev_count); > > > > > > + new_count = dsu_pmu_read_counter(event); > > > > > > + } while (local64_cmpxchg(&hwc->prev_count, prev_count, new_count) != > > > > > > + prev_count); > > > > > > + delta = (new_count - prev_count) & DSU_PMU_COUNTER_MASK(hwc->idx); > > > > > > + local64_add(delta, &event->count); > > > > > > +} > > > > > > + > > > > > > +static void dsu_pmu_read(struct perf_event *event) > > > > > > +{ > > > > > > + dsu_pmu_event_update(event); > > > > > > +} > > > > > > > > > I sent out a patch that'll allow PMUs to set an event flag to avoid > > > > > unnecessary smp calls when the event can be read from any CPU. You could > > > > > just always set that if you can't have multiple DSU's running the kernel (I > > > > > don't know if the current ARM designs support having multiple DSUs in a > > > > > SoC/system) or set it if associated_cpus == cpu_present_mask. > > > > > > > > As-is, that won't be safe, given the read function calls the event_update() > > > > function, which has side-effects on hwc->prec_count and event->count. Those > > > > need to be serialized somehow. > > > > > > You have to grab the dsu_pmu->pmu_lock spin lock anyway because the system > > > registers are shared across all CPUs. > > > > I believe that lock is currently superfluous, because the perf core > > ensures operations are cpu-affine, and have interrupts disabled in most > > cases (thanks to the context lock). > > I don't think it's superfluous. You have a common "event counter" selection > register and a common "event counter value" register. You can two CPUs > racing to read two unrelated event counters and end up causing one of them > to read a bogus value from the wrong event counter. It's important to note that the DSU PMU's event_init() ensures events are affine to a single CPU, and the perf core code serializes operations on those events via the context lock. Therefore, two CPUs *won't* try to access the registers simultaneously. If events could be active on multiple CPUs simultaneously, I agree that the lock would be necessary. However, there would also be other problems to deal with in that case. If we want to allow pmu::read() from arbitrary CPUs the DSU is affine to, I agree we'd need the lock to serialize accesses to the registers and data structures. Thanks, Mark.