Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp4445355ybp; Mon, 14 Oct 2019 04:54:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqyng3yWauB5G5dBZKo4+nlPc3O7oxwy/IK52/vVYePwxO5E6PxyFAot+Q4NJmD3gu3/TKEU X-Received: by 2002:a17:906:2d49:: with SMTP id e9mr27966246eji.240.1571054094724; Mon, 14 Oct 2019 04:54:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571054094; cv=none; d=google.com; s=arc-20160816; b=icD3NyL34LpU06+WtWvu9s2qiTy8p2uRjOZIy6Zl65YkqiUDFg9VVcjVgCGhgA7scv ngPjmq4UlbFi9MK1xhWcMm8dogG43qAVJIq5fh3JM8nURPqZs7VZZ6uPRuvWf8YMvfkY tgMCuTv7xbsXuHWDwO3jByL0t5I955hR4srAl+krwPfw6PwZbOq0duBbWSCfv9Zz42q+ dBTRJO3Y49gYzGEYodRPLG++Lazk/H+bHKX3LJ7Jv6Tq15y5/JB1VH6ytR5fhpXTk3w3 wkKJXtFvWoEpxw3J+SR2BJmOxi3WFrqNb10pXh/tdFCjFF0++K9UlDcDnjDOGf31v9Ro O9oQ== 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:dkim-signature; bh=7VSr7BYb7+J2hDKY+7JG0niopCL5cvNnFzSou8GfhQQ=; b=Kv3oblzU+OOcGxFI1nm5wx9ejGD7GJV8NrP6CW6GuzhxVJw1ntOnP3g0BQwfRPK7A9 ODamF9c6bmYhLtocrvlThJZMTeAmY+I5UokMsoVrlFSum2MGGWVoCO8pbERjlj/w6NC9 nv87SyJ7ao2Lw7aKhfJEdiKLtD5LjgWI3KsWgdL0o9htW5DUsV8oMwvluzn3RW6XIlNw 9rUMiRiBWNMDnUUBDPntKBMVDfiRQ+2HbezVnsaY1AGwnJSCs8U/deQ5bAfxicxuyHun P2KEK+kvugg4hziNMJsWTfA9CzoHexKLAJk3QZvStCsdaN6LAy2eGDa2qvOLK+yyy3P3 +H7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=EeyYP8Ij; 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 l8si10893723ejc.432.2019.10.14.04.54.31; Mon, 14 Oct 2019 04:54:54 -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=fail header.i=@infradead.org header.s=merlin.20170209 header.b=EeyYP8Ij; 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 S1731400AbfJNLwS (ORCPT + 99 others); Mon, 14 Oct 2019 07:52:18 -0400 Received: from merlin.infradead.org ([205.233.59.134]:56142 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730369AbfJNLwR (ORCPT ); Mon, 14 Oct 2019 07:52:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=7VSr7BYb7+J2hDKY+7JG0niopCL5cvNnFzSou8GfhQQ=; b=EeyYP8IjsvAkXMNXfavRV9I8j eafH208u2y1jq2NjgLUZq5lnznDQ+L+tetsdLZaAoBq2s9Uj/0LNnVnpxP3qMsyMEtP2Br7VfD+KR Nx+zVESmeSsJGQg1BONDaXirf+hy8Yzjm3t8BeeRVunGQm73RedlC/q+8+P34GNdIPjlyp8qVqnWN EuCg7OU8EfI26+PHoR2LJkOLIxtbLMFgMYdlWwi04JLwxGfFF4TeKfGRl+9tz7u/xkgKdDgwK2/ZZ 0fOd6ManRE7v12zs7/E1Pc0WeYMWvU4RhM2MnzmQvYt/gsGM2GuLvTIfUEZkNTjRaR3rrHev1IL71 EVQggPzgw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1iJytO-0007iT-61; Mon, 14 Oct 2019 11:52:02 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 0883D300F3F; Mon, 14 Oct 2019 13:51:04 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id E411E200843F1; Mon, 14 Oct 2019 13:51:58 +0200 (CEST) Date: Mon, 14 Oct 2019 13:51:58 +0200 From: Peter Zijlstra To: Like Xu 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 Subject: Re: [PATCH v2 2/4] perf/core: Provide a kernel-internal interface to pause perf_event Message-ID: <20191014115158.GC2328@hirez.programming.kicks-ass.net> References: <20191013091533.12971-1-like.xu@linux.intel.com> <20191013091533.12971-3-like.xu@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191013091533.12971-3-like.xu@linux.intel.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); > + perf_event_ctx_unlock(event, ctx); > + > + return count; > +} > +EXPORT_SYMBOL_GPL(perf_event_pause);