Received: by 10.223.164.202 with SMTP id h10csp3864449wrb; Mon, 20 Nov 2017 06:17:27 -0800 (PST) X-Google-Smtp-Source: AGs4zMbfzHFfdd7pwowPYRKttxaekBFFE0caMtzRDgnKuhP71765fm1nPV9/JbPmkkuAXiXqbUEQ X-Received: by 10.84.252.4 with SMTP id x4mr13443423pll.99.1511187447580; Mon, 20 Nov 2017 06:17:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511187447; cv=none; d=google.com; s=arc-20160816; b=IYhuOpLEtvu0nI1t91MTYTUjnoMKji4dcdgYzC2DnEhZi4J0DACRW/i+cDZwXXjXfY Ac06ROJRQB8upxVzRLE8q4w59JK+G5Ds2RCf2iXut3AMjVKB3biQfPVuI8nRgbyzJnfp VF24uyrM1dCn0pHHdpffmCJ5xAp/oZGTHhoWuhsAlLfw5toa8gmQOqoon1GIUBpFDsC8 LKbMkruRQs/OaUGBxt3kX4KiH2E5oZIj/4gzam/DVWCDjV2i8DEkLZLhjfW4ywjvBYAT uvD3E7qYwIH8/8L+WP+jISTOb73Ae4o0PVpkL3ONz3GXKSS95B27YT8umhWEdVLz2x+Z LNww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject:dkim-signature:arc-authentication-results; bh=ZXWRKKSFZScDOY9OveJxPx6fXPr5egk3+bFdIzJ8vLg=; b=fsuhzxWCS8OOFnuXPipvgV4G5KMDkCaVRuIADzOqoa3gpyFeaqRTbpiEFgWFOFK/n5 GhXPhg9AMGLaEBZ5N/7HxHxJZmHT/zy9yFmvs9S2ihJ4q3FBV2egrrm+JhI8YBAZRkJV 2guB5uo8PuroAfQ4vMK2/i/3Y62796VpD0blVnWl1JBbXYaL50NeClt6yK6t0uVEORfC WH+yiWI/0tiLFejvJxjw6cvd6Xc9uyliAM8yS2omf/pZSV0WBL8zC/BEiKP/ljPyuGT3 s/ujrMHGbtU0AuRxNTc+3dXMOiLoUmChxBg62S2cdTqJOZBqPKYD3yjwMDl71I3Z3hL5 A5jA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=paT7ajzY; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g3si7969161pgc.280.2017.11.20.06.17.17; Mon, 20 Nov 2017 06:17:27 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=paT7ajzY; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751681AbdKTOQI (ORCPT + 66 others); Mon, 20 Nov 2017 09:16:08 -0500 Received: from mail-pf0-f194.google.com ([209.85.192.194]:36614 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751173AbdKTOQG (ORCPT ); Mon, 20 Nov 2017 09:16:06 -0500 Received: by mail-pf0-f194.google.com with SMTP id i15so7394746pfa.3 for ; Mon, 20 Nov 2017 06:16:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=ZXWRKKSFZScDOY9OveJxPx6fXPr5egk3+bFdIzJ8vLg=; b=paT7ajzYLm3n2RuTDgoHcGjErzJUOVK7geN4oC3hXglIxMMvaQf9gZu7okXB+XMUnw 59G1wGaNR/s8w/wM7ZG3j6A+gLd9iX/G23aVm05AX4v/EXkiROpqQgwbH3ykfJSR3+So +uz2ZLA6pO20315hmUVyO6Qm3bsyFPHCQlXPu7802THoNoCQJdofwhSJUlqW7Q/CAtER sw4TF+vo3CAx5X6KO9+qeOFvCr7u79eGofKbQ02L0O4agSuEhOsAVsa8s2X05hc9iK7C MetfLZS6T38lmIAmuMmd/hsWga0S1xrL5tDLD6RV6MBnCVCYsYu8xOGuafWvmeG7BeXZ vXmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=ZXWRKKSFZScDOY9OveJxPx6fXPr5egk3+bFdIzJ8vLg=; b=twStwt15LVFJro/Wj0Mgti//LTXc9Lb/4hU55iBW4VHYr2Ssde84S7FrYQNfIx9v0V Eyi1SvQesYklHpWAD5JGMxGblR5EP0G2/oaML8V9jFJeSjDxl5np9BEBKk+sKmOjRPwG x39BPl++lglVFXtVRx35B0vIDQC4+knxXJotGht71b5JuJiQdp3JNlXm89VAixMBTRWf SZ7uW62W7ENpI/2PpJp5U3X2AqdPbl1qqNoDqs3D0hKfqXrmqL7oLpSaE1UyT96SZj+v e3HkXYM0F6FQAAW1+qoVVY3wqE7dQBrqLSP3h+r8RKKJ5Sd57dXO6Xrt/aMMfWSeRF5/ 1RMA== X-Gm-Message-State: AJaThX5Fet7qD7FGT4W/YkC4acHA7E2WYjKFyzCJNx7FCO2DA7nk6muZ UftDnfCWJ+W5OltE6VtojTk= X-Received: by 10.99.8.5 with SMTP id 5mr13724950pgi.28.1511187365875; Mon, 20 Nov 2017 06:16:05 -0800 (PST) Received: from [0.0.0.0] (67.209.179.165.16clouds.com. [67.209.179.165]) by smtp.gmail.com with ESMTPSA id y5sm20792379pfk.3.2017.11.20.06.16.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Nov 2017 06:16:05 -0800 (PST) Subject: Re: [PATCH] drivers/perf: arm_pmu: save/restore cpu cycle counter in cpu_pm_pmu_notify To: Mark Rutland Cc: Will Deacon , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Lorenzo Pieralisi , Jia He References: <1510813648-45090-1-git-send-email-hejianet@gmail.com> <20171120123240.ohcdgv2nnoyrc7ov@lakrids.cambridge.arm.com> <20171120140451.ztr2i24v2vspu364@lakrids.cambridge.arm.com> From: Jia He Message-ID: Date: Mon, 20 Nov 2017 22:15:58 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <20171120140451.ztr2i24v2vspu364@lakrids.cambridge.arm.com> Content-Type: text/plain; charset=gbk; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Thanks, got it Cheers, Jia On 11/20/2017 10:04 PM, Mark Rutland Wrote: > On Mon, Nov 20, 2017 at 09:50:15PM +0800, Jia He wrote: >> On 11/20/2017 8:32 PM, Mark Rutland Wrote: >>> On Thu, Nov 16, 2017 at 06:27:28AM +0000, Jia He wrote: >>>> Sometimes userspace need a high resolution cycle counter by reading >>>> pmccntr_el0. >>>> >>>> In commit da4e4f18afe0 ("drivers/perf: arm_pmu: implement CPU_PM >>>> notifier"), it resets all the counters even when the pmcr_el0.E and >>>> pmcntenset_el0.C are both 1 . That is incorrect. >>> I appreciate that you may wish to make use of the cycle counter from >>> userspace, but this is the intended behaviour kernel-side. Direct >>> userspace counter acceess is not supported. >> Sorry for my previous description. Not only user space, but also any >> pmccntr_el0 reading >> in kernel space is 0 except perf infrastructure. > The only user of PMCCNTR in the kernel is the perf infrastructure. > > If you want to perform in-kernel counts, please use > perf_event_create_kernel_counter() and related functions. > >>> In power states where context is lost, any perf events are >>> saved/restored by cpu_pm_pmu_setup(). So we certainly shouldn't be >>> modifying the counter registers in any other PM code. >>> >>> We *could* expose counters to userspace on homogeneous systems, so long >>> as users stuck to the usual perf data page interface. However, this >>> comes with a number of subtle problems, and no-one's done the work to >>> enable this. >>> >>> Even then, perf may modify counters at any point in time, and >>> monotonicity (and/or presence) of counters is not guaranteed. >> Yes, the cycle counter register pmccntr_el0 will be impacted by perf >> usage.But do you think pmccntr_el0 is intented for perf only? > We only intend for the in-kernel perf infrastructure to access > pmccntr_el0; nothing else should touch it. > >> Currently, many user space/kernel space programs will use pmccntr_el0 >> as a timestamp( just likethe rdtsc() on X86). > This is not supported, and will return completely unusable numbers if > it were. This will be randomly reset/modified, CPUs aren't in lock-step, > so this isn't monotonic, etc. > > If you want a timestamp, the architecture provides an counter that is > monotonic and uniform across all CPUs. We expose that to userspace via > the VDSO (e.g. clock_gettime with CLOCK_MONOTONIC_RAW) and it can be > read in-kernel through the usual clocksource APIs. > > PMCCNTR is *not* usable in this manner. > >> After commit da4e4f18afe0, all the cycle counter readingis 0 because >> of CPU PM enter/exit state changes in armv8pmu_reset. > Previously, had a CPU been reset, the counter would hold an UNKNOWN > value (i.e. it would be reset to junk), and may or may not have been > accessible depending on what CNTKCTL reset to. > > So if you tried to read PMCCNTR in userspace, and happened to have been > granted access, the values would have been bogus and unusable. > > Commit da4e4f18afe0 fixed things and made the behaviour consistent, as > intended. > > Thanks, > Mark. > From 1584594243471062717@xxx Mon Nov 20 14:07:11 +0000 2017 X-GM-THRID: 1584209216349987268 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread