Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp5036798ybi; Mon, 3 Jun 2019 23:38:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqyLzJtDxerfxC08kQRM6bUPVNkqo3b2UoiTTyW1EPgqBiMK+6b0ghutQo5oV5TEcSkM1q5c X-Received: by 2002:a17:902:a70a:: with SMTP id w10mr33129197plq.250.1559630337834; Mon, 03 Jun 2019 23:38:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559630337; cv=none; d=google.com; s=arc-20160816; b=f/bHdzljagjjF1xw+5mDBh6xUmoaHAITBhJe2gWcFm58I5g5htn0Mqh38EYQcJ6SiH 00d0004l/zoCOivSB6AdofAi+O08bunktH52VJ/UInYxDLmnm8vHRvXqb7Eo168XqZDi 5Lq08Jj+QK+mbknWVPVPylk8mKMLFYK3+u53yA1JqrYbdK8BSL73PXch9IYDa06BAO4y DomSb7FKFjtD/PyrZwDzJsinDZV7cWKdZUk2oq3cAgouDcrn7QnGc2BAOOuior2hH8JN qApzh3RllYznDFxx6mlsItEVo420epEXsscuU8sKI2DLl9eIlJEMNNe+6cTbn4qzcd/W cn9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=dF4ISIvuCNFZ/Oqj2PF6M4C4tejG07fBxKhA0A7xlPM=; b=JqMDX/HxGwJs/Nr2VRJGVSOZtB0Pwgi15u9sN74Va6vLzsPKU+39Bz2989My62Cmvw 43Y4TH1O5ZER2XwySLAUSBetmctwHn8pLCnNFdYFxn35XyIlJF7d+2/YFfQsVktLNvWT 3z2gVi0/HfK/FJvqAwVip+Uk0dC9pAlgH+A64+VDu6MLZ5W1I2oyDgno/FyTFbTt4M41 TyxpCPv3kkvgPoDhDcClfwaPrkAr9/YpiPM7NN3Jd39/Q9gJ26+/V78Stm9F2W1I5swh CkOkiUQfI581KmpwFpC1ufC/qOBn+5iHFZxonhRkz4Ie9tN9gbTrKw9EklhGoyrZDDOo LODg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Fi7wRIBQ; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j4si8122342pgf.369.2019.06.03.23.38.41; Mon, 03 Jun 2019 23:38:57 -0700 (PDT) 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=@kernel.org header.s=default header.b=Fi7wRIBQ; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726797AbfFDGhA (ORCPT + 99 others); Tue, 4 Jun 2019 02:37:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:58486 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726554AbfFDGhA (ORCPT ); Tue, 4 Jun 2019 02:37:00 -0400 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B977C24CDC; Tue, 4 Jun 2019 06:36:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559630219; bh=dwqyY5JxBtGqhxd/56EiAMH8oEK1rne586EbXZFul8k=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=Fi7wRIBQMzbZwdXZCUmExlszkUUzTC3AtjeunLFRzvOYgvREE2vHuRQfPix4f6dNl R5znMCwJvjJEvn+0U4DD8Oo9tGGZ0sgsGVITSi586uM+kT/ea8qeTh73dqbmMqsCv1 qVypskIrliuA1EO48FSx0eZaeM17fc/iRxMNQIpM= Received: by mail-wr1-f43.google.com with SMTP id p11so9647187wre.7; Mon, 03 Jun 2019 23:36:58 -0700 (PDT) X-Gm-Message-State: APjAAAUHZr1bLatYMzZ7o8WGV+LVD6j3q+BFci6Au3J+FzhczsDyQbu5 DCPxIgQJoyD5XHLXsJV+yVUUOue1dO78VxeWNX8= X-Received: by 2002:adf:eb42:: with SMTP id u2mr18271932wrn.80.1559630217365; Mon, 03 Jun 2019 23:36:57 -0700 (PDT) MIME-Version: 1.0 References: <3a6a5379b4f692773d82ff5ad18a7b22ceaf5a80.1559614824.git.han_mao@c-sky.com> In-Reply-To: <3a6a5379b4f692773d82ff5ad18a7b22ceaf5a80.1559614824.git.han_mao@c-sky.com> From: Guo Ren Date: Tue, 4 Jun 2019 14:36:45 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH V4 6/6] csky: Fix perf record in kernel/user space To: Mao Han Cc: linux-kernel@vger.kernel.org, linux-csky@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Just move attr.exclude_user after switch, like this: OK? diff --git a/arch/csky/kernel/perf_event.c b/arch/csky/kernel/perf_event.c index 376c972..3470cfa 100644 --- a/arch/csky/kernel/perf_event.c +++ b/arch/csky/kernel/perf_event.c @@ -844,15 +844,6 @@ static int csky_pmu_event_init(struct perf_event *event) struct hw_perf_event *hwc = &event->hw; int ret; - if (event->attr.exclude_user) - csky_pmu.hpcr = BIT(2); - else if (event->attr.exclude_kernel) - csky_pmu.hpcr = BIT(3); - else - csky_pmu.hpcr = BIT(2) | BIT(3); - - csky_pmu.hpcr |= BIT(1) | BIT(0); - switch (event->attr.type) { case PERF_TYPE_HARDWARE: if (event->attr.config >= PERF_COUNT_HW_MAX) @@ -861,21 +852,31 @@ static int csky_pmu_event_init(struct perf_event *event) if (ret == HW_OP_UNSUPPORTED) return -ENOENT; hwc->idx = ret; - return 0; + break; case PERF_TYPE_HW_CACHE: ret = csky_pmu_cache_event(event->attr.config); if (ret == CACHE_OP_UNSUPPORTED) return -ENOENT; hwc->idx = ret; - return 0; + break; case PERF_TYPE_RAW: if (hw_raw_read_mapping[event->attr.config] == NULL) return -ENOENT; hwc->idx = event->attr.config; - return 0; + break; default: return -ENOENT; } + + if (event->attr.exclude_user) + csky_pmu.hpcr = BIT(2); + else if (event->attr.exclude_kernel) + csky_pmu.hpcr = BIT(3); + else + csky_pmu.hpcr = BIT(2) | BIT(3); + + csky_pmu.hpcr |= BIT(1) | BIT(0); + } On Tue, Jun 4, 2019 at 10:25 AM Mao Han wrote: > > csky_pmu_event_init is called several times during the perf record > initialzation. After configure the event counter in either kernel > space or user space, csky_pmu_event_init is called twice with no > attr specified. Configuration will be overwritten with sampling in > both kernel space and user space. --all-kernel/--all-user is > useless without this patch applied. > > Signed-off-by: Mao Han > Cc: Guo Ren > Cc: linux-csky@vger.kernel.org > --- > arch/csky/kernel/perf_event.c | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/arch/csky/kernel/perf_event.c b/arch/csky/kernel/perf_event.c > index dc84dc7..e3308ab 100644 > --- a/arch/csky/kernel/perf_event.c > +++ b/arch/csky/kernel/perf_event.c > @@ -983,6 +983,12 @@ static int csky_pmu_event_init(struct perf_event *event) > struct hw_perf_event *hwc = &event->hw; > int ret; > > + if (event->attr.type != PERF_TYPE_HARDWARE && > + event->attr.type != PERF_TYPE_HW_CACHE && > + event->attr.type != PERF_TYPE_RAW) { > + return -ENOENT; > + } > + > if (event->attr.exclude_user) > csky_pmu.hpcr = BIT(2); > else if (event->attr.exclude_kernel) > -- > 2.7.4 >