Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp415522ybz; Fri, 17 Apr 2020 03:34:06 -0700 (PDT) X-Google-Smtp-Source: APiQypKgZZAPOQuSLF8pwKQO1nqeIms9WdtvQSdOCzyAbTX4jjYdXekDWRNblSp60wLaCV7FeOH9 X-Received: by 2002:a50:8716:: with SMTP id i22mr2222887edb.248.1587119646376; Fri, 17 Apr 2020 03:34:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587119646; cv=none; d=google.com; s=arc-20160816; b=KDL22IghqxJt/YSVSaNQMmGGQwh6Ju5rND08JvXEgAkCTpn+j67K0LXsiqT3q9mdh8 V8qkouqiSxf9oUe98k3VLopN/3qyzUicJ7v+UzAWT9AtvGPfNCzdmVlMFGX6WcrM8mNf VQW9cbg8wUZ1kMR2LWGQcHwDD82lBLsyPMTSS6W6hHtPHGfOkaRzj73WFIMfAwivccpl As4/co5yGZrdZMF10px+tNe2073F3IxEAkCsxcrypIxNWuNiEhSkN7yBGsDFdTzASy3w U2m5XaY/flcaW03GmbOwDprnZhyTEl/rGVvZwGmJmNqN45UQVdtOVNptJG+ldxw73u5Y 6B7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=5T+iJux5AD2LbQoaV8j0BcNwC32G2ubqGpp3NLw7K2U=; b=fkEE2zULKb41c52g7FRIeFH14fQMxKEMdvXPB27cXODcPpUJ7jHhElgkSxGsy1XuJ2 4SfoKLAA93lhERdoFuveNHE+oJbsVHI6pHctqLIoto6bfrvjuv/DCTEyLeGI4/L3nSwI JQxedk8wmIzWEzhItPq26dRJavHK6EUQngyBE5I8dkYbtViq9q5g8p+uhutUwbDvcMub 9z03tBfSqEAKEG+lViwYlHUzDwt2u0f1ZHBcagAN4PmHDD6skKKWsr87kwESCBQPcNwp WfVQtEJZAIWboOytvINzv4saNEeZFzy/aWddN1M/gu80c6prQxNpAO/EGObGBTLAzsaQ bDuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=OJJIIwuj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v23si11320593ejo.321.2020.04.17.03.33.43; Fri, 17 Apr 2020 03:34:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=OJJIIwuj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729218AbgDQKas (ORCPT + 99 others); Fri, 17 Apr 2020 06:30:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1728830AbgDQKar (ORCPT ); Fri, 17 Apr 2020 06:30:47 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8DA77C061A0C; Fri, 17 Apr 2020 03:30:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Transfer-Encoding :Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description; bh=5T+iJux5AD2LbQoaV8j0BcNwC32G2ubqGpp3NLw7K2U=; b=OJJIIwujh1arTkzUU+hPFfANoY NiFEfLxyk7MLGkT08KL5BncSK7vyJY5V1xcSdc9lu4nmdLJWsOOjLtcHiAFMxitLUHUhiDjpxfur5 re+nSC6fHG0QGIQepP+ceQyfoA498aJNGGkDr8wP1kTpcdo48Dbs7e5ih92O3nndERPXsTZSpJ9J5 eGj1sgLq1Zy0x0/y/NQh7uct6dhQwwEu+QZ88iicydfw2e/NkA1C05v7rJHyuUD+IfeLPpFKwD4WA Jc2eMY70zCMsMSJgshZNIsYf8F/uwbsy+9V7UIrA79dxto2GrGLCaxDqW56X6o2O4Y0O0qZg4kN5G KvHh6R6Q==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jPOGL-0007BH-EK; Fri, 17 Apr 2020 10:30:21 +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 1EEC53006E0; Fri, 17 Apr 2020 12:30:17 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 075632B0DE450; Fri, 17 Apr 2020 12:30:17 +0200 (CEST) Date: Fri, 17 Apr 2020 12:30:16 +0200 From: Peter Zijlstra To: "Xu, Like" Cc: Like Xu , Paolo Bonzini , kvm@vger.kernel.org, Andi Kleen , Jim Mattson , Wanpeng Li , Sean Christopherson , Joerg Roedel , Liran Alon , Thomas Gleixner , Ingo Molnar , Arnaldo Carvalho de Melo , Liang Kan , Wei Wang , linux-kernel@vger.kernel.org, Ingo Molnar Subject: Re: [PATCH v9 03/10] perf/x86: Add constraint to create guest LBR event without hw counter Message-ID: <20200417103016.GV20730@hirez.programming.kicks-ass.net> References: <20200313021616.112322-1-like.xu@linux.intel.com> <20200313021616.112322-4-like.xu@linux.intel.com> <20200409163717.GD20713@hirez.programming.kicks-ass.net> <0b89963d-33d8-3b0f-fc56-eff3ccce648d@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <0b89963d-33d8-3b0f-fc56-eff3ccce648d@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Apr 10, 2020 at 11:03:33AM +0800, Xu, Like wrote: > On 2020/4/10 0:37, Peter Zijlstra wrote: > > That should sort the branches in order of: gp,fixed,bts,vlbr > > Note the current order is: bts, pebs, fixed, gp. Yeah, and that means that gp (which is I think the most common case) is the most expensive. > Sure, let me try to refactor it in this way. Thanks! > > > +static inline bool is_guest_event(struct perf_event *event) > > > +{ > > > + if (event->attr.exclude_host && is_kernel_event(event)) > > > + return true; > > > + return false; > > > +} > > I don't like this one, what if another in-kernel users generates an > > event with exclude_host set ? > Thanks for the clear attitude. > > How about: > - remove the is_guest_event() to avoid potential misuse; > - move all checks into is_guest_lbr_event() and make it dedicated: > > static inline bool is_guest_lbr_event(struct perf_event *event) > { >     if (is_kernel_event(event) && >         event->attr.exclude_host && needs_branch_stack(event)) >         return true; >     return false; > } > > In this case, it's safe to generate an event with exclude_host set > and also use LBR to count guest or nothing for other in-kernel users > because the intel_guest_lbr_event_constraints() makes LBR exclusive. > > For this generic usage, I may rename: > - is_guest_lbr_event() to is_lbr_no_counter_event(); > - intel_guest_lbr_event_constraints() to > intel_lbr_no_counter_event_constraints(); > > Is this acceptable to you? I suppose so, please put a comment on top of that function though, so we don't forget. > > > @@ -181,9 +181,19 @@ struct x86_pmu_capability { > > > #define GLOBAL_STATUS_UNC_OVF BIT_ULL(61) > > > #define GLOBAL_STATUS_ASIF BIT_ULL(60) > > > #define GLOBAL_STATUS_COUNTERS_FROZEN BIT_ULL(59) > > > -#define GLOBAL_STATUS_LBRS_FROZEN BIT_ULL(58) > > > +#define GLOBAL_STATUS_LBRS_FROZEN_BIT 58 > > > +#define GLOBAL_STATUS_LBRS_FROZEN BIT_ULL(GLOBAL_STATUS_LBRS_FROZEN_BIT) > > > #define GLOBAL_STATUS_TRACE_TOPAPMI BIT_ULL(55) > > > +/* > > > + * We model guest LBR event tracing as another fixed-mode PMC like BTS. > > > + * > > > + * We choose bit 58 (LBRS_FROZEN_BIT) which is used to indicate that the LBR > > > + * stack is frozen on a hardware PMI request in the PERF_GLOBAL_STATUS msr, > > > + * and the 59th PMC counter (if any) is not supposed to use it as well. > > Is this saying that STATUS.58 should never be set? I don't really > > understand the language. > My fault, and let me make it more clearly: > > We choose bit 58 because it's used to indicate LBR stack frozen state > not like other overflow conditions in the PERF_GLOBAL_STATUS msr, > and it will not be used for any actual fixed events. That's only with v4, also we unconditionally mask that bit in handle_pmi_common(), so it'll never be set in the overflow handling. That's all fine, I suppose, all you want is means of programming the LBR registers, we don't actually do anything with then in the host context. Please write a more elaborate comment here.