Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp5429255ybp; Mon, 14 Oct 2019 22:35:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqyc1uoqzB/liHKOc+Ky7OBdxLVpuO/paz4NGmUQTXsiKOtStcfHYwZue5Lhbng4XEWNFnbM X-Received: by 2002:aa7:d316:: with SMTP id p22mr31864711edq.77.1571117703024; Mon, 14 Oct 2019 22:35:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571117703; cv=none; d=google.com; s=arc-20160816; b=Fd9jVJmMxG3XcH5cuWoZX28FzIqhEcA2Sxh/lDSzPPPuwi+gD3Qlsipx7+tJZ51xPG XMQ5Nq8ET+PSUCGeSxNg2ldSAJ4QXkk6m8puydHiEGFH12Wl70idzH7U5ca4Ti1Fsz1X YTxv4qXVw8rp3sI67thGsFzEyrsdRYkxVjzK4s8KWWTBOC+FXI1oHwo6wz7WH7QbqWF7 s8kvZT5Sahcy/kB8P2egEV+0eySwvyicL8h8GPorzmAybCmbifR1x3GwSxofjYjhfKfv 44IcHi3ec+AA6UmOw5s/hLcNRXsAjLXABFuBiGwAbydLluRSvwueEkWI4jAdWJI2Zi3f 3q7g== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:organization:from:references:cc:to:subject; bh=hbJ7rmmnYC2oK/J1vAK8EjyQ97V+kGuxBK3ZW8iq4T8=; b=tazitOPwaFotKBvVvIA1+Y2MQPWJaVdgWFtCr37scJq2owZOhv88Y/uy8OzMQac3po j7eE6ZaeKmjWz2/MxY+9blSTZLj7c/V6CErmrxtvmcW+axiWdLFMh+gDbj4ROKGLxSBp BPPgUpvVkzjVGKboRohdd5VxeTx/llpnKeVWgKyr6chCJsMcOVqrnrYISKS9zuCAr3W4 WyKW+EEV5H6WlZl1ISKZMIdl7HAZT5jGMCX+cMBTukc7qmjIG4xKOU9fUA4hVls7nRyK Yn4oLPSd4a5GaUCupSraUSnuwDmBrhHWsacXx5bpVC7yxNjjpplaX41nFOJ546HFy+sJ F2KA== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v18si5067739ejd.115.2019.10.14.22.34.28; Mon, 14 Oct 2019 22:35:03 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727498AbfJOBrr (ORCPT + 99 others); Mon, 14 Oct 2019 21:47:47 -0400 Received: from mga11.intel.com ([192.55.52.93]:57388 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726476AbfJOBrq (ORCPT ); Mon, 14 Oct 2019 21:47:46 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Oct 2019 18:47:46 -0700 X-IronPort-AV: E=Sophos;i="5.67,297,1566889200"; d="scan'208";a="189204875" Received: from likexu-mobl1.ccr.corp.intel.com (HELO [10.239.196.183]) ([10.239.196.183]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/AES256-SHA; 14 Oct 2019 18:47:43 -0700 Subject: Re: [PATCH v2 2/4] perf/core: Provide a kernel-internal interface to pause perf_event To: Peter Zijlstra Cc: Paolo Bonzini , kvm@vger.kernel.org, Jim Mattson , rkrcmar@redhat.com, sean.j.christopherson@intel.com, vkuznets@redhat.com, Ingo Molnar , Arnaldo Carvalho de Melo , ak@linux.intel.com, wei.w.wang@intel.com, kan.liang@intel.com, like.xu@intel.com, ehankland@google.com, arbel.moshe@oracle.com, linux-kernel@vger.kernel.org References: <20191013091533.12971-1-like.xu@linux.intel.com> <20191013091533.12971-3-like.xu@linux.intel.com> <20191014115158.GC2328@hirez.programming.kicks-ass.net> From: Like Xu Organization: Intel OTC Message-ID: <1aa1fa7e-6d06-3ab0-f9f9-9e90c9c0921c@linux.intel.com> Date: Tue, 15 Oct 2019 09:47:41 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <20191014115158.GC2328@hirez.programming.kicks-ass.net> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2019/10/14 19:51, Peter Zijlstra wrote: > On Sun, Oct 13, 2019 at 05:15:31PM +0800, Like Xu wrote: >> Exporting perf_event_pause() as an external accessor for kernel users (such >> as KVM) who may do both disable perf_event and read count with just one >> time to hold perf_event_ctx_lock. Also the value could be reset optionally. > >> +u64 perf_event_pause(struct perf_event *event, bool reset) >> +{ >> + struct perf_event_context *ctx; >> + u64 count, enabled, running; >> + >> + ctx = perf_event_ctx_lock(event); > >> + _perf_event_disable(event); >> + count = __perf_event_read_value(event, &enabled, &running); >> + if (reset) >> + local64_set(&event->count, 0); > > This local64_set() already assumes there are no child events, so maybe > write the thing like: > > WARN_ON_ONCE(event->attr.inherit); > _perf_event_disable(event); > count = local64_read(&event->count); > local64_set(&event->count, 0); > Thanks. It looks good to me and I will apply this. > >> + perf_event_ctx_unlock(event, ctx); >> + >> + return count; >> +} >> +EXPORT_SYMBOL_GPL(perf_event_pause); >