Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1675820pxj; Wed, 19 May 2021 11:12:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzo2scQGS4/kg3V4W5BdDxi7esHB9FPfdz10lX6GLf80La7HOL4+dzVJBjXawzNyhcTToFR X-Received: by 2002:a17:906:a48:: with SMTP id x8mr417691ejf.127.1621447950386; Wed, 19 May 2021 11:12:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621447950; cv=none; d=google.com; s=arc-20160816; b=sGqG635Py4KT8wkrwfU1QJMBgtTBgFV0kroSVBQqHjMnfHfAz2Kp1Y8WmFcHHFWXwV +sYRLud3Jp6z4ac7Czp343NLdTrMVGPcjtvG+r+CCUTNXhbm8QhAoWQmqDYPYHE8dhk7 k3S+G9DohYwVE4gRz0JBffjP2K4w3tNJv1ICcAs/WXMZ4cq/MUac6sEQ83Ohc0DIJ5li RbXVH//bXD9LK3xLnGFrZo7J6CiOrInKhAfzLdNsndLrvhNMDp4eiUxiPFYgjZEQIVQf tZaE23wP88DRaBCKIc9to6uPGgAfDx4+Ai+UhaU1QeY69aaX+CZ1IxVfLlsGbK646PiG DE9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=yuqCWcIqul/1lj3NsVLBchoLnyRiKeIyOOoNOlV42Hs=; b=w6oc2fIBmcMgeWdKKt8u3yxkmzLhdVM/osI/ISsVcG+D3WnnXFN+hy4RMDTCXFeq7v 4GRGijRNEt3KIF6rnqCc5W38WsyeYkoBxrNbPD8N0hM4MGYGCvwIeRYBVMyqQZTaVUsp yQM2FOkapKjaMFljYlO5oUIAkoh5YjU7bUQKVo2LyuvTLB8VonsrJS6zvciknsYg/ifh SHGvtf1bd14MrcFtw7PyDyFDUJQVqVuplN4V8VnTjHJJOFfnFy2g3/XjHu/TDv3vusvv CZyicadsfKilyk34/f8NT+oobPSnyHvmfBNK+XA2p3CKJ2TwDIE/Jdb5lu8dikwBSlmg XT/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=bQH0fgbq; 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 n8si347062eje.94.2021.05.19.11.12.06; Wed, 19 May 2021 11:12:30 -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=pass header.i=@infradead.org header.s=desiato.20200630 header.b=bQH0fgbq; 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 S1349686AbhERNhw (ORCPT + 99 others); Tue, 18 May 2021 09:37:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349681AbhERNhu (ORCPT ); Tue, 18 May 2021 09:37:50 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC325C061573; Tue, 18 May 2021 06:36:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; 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=yuqCWcIqul/1lj3NsVLBchoLnyRiKeIyOOoNOlV42Hs=; b=bQH0fgbqI9bCAw2E4kTrPyruHo Sdf8ZX08AyYdMekNB+R0Nlp/yhM9U2IuZ1SDaLoKzA+t8GbV4IItx2DuRb/HyEx0EjjcZlhTs7aTK zJ62HS1rYEuYpzendAp6+dMkOmjKGZC6vtjQQfXoMwm8aYb5jNRMzQc+kHQRm1UkHlngPyvZHdwWD cWPKa0Sra1qGZcFNAVklSi5LJRvds+V9ky6yJG9sCQMI44Goue5p1x2U0vU9xaXXUXFJmz6JUPjTL Pvu89thupqInO5dfCrWu2pd6APq8YAJz4+2KtOHzF5DhLD2NzfOjwgh0q6DTWI8FMtB6JKKhEyX5c aP8R+ndQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1liztH-000tHR-N2; Tue, 18 May 2021 13:36:07 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 54DFC30022C; Tue, 18 May 2021 15:36:06 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 3DB893011B374; Tue, 18 May 2021 15:36:06 +0200 (CEST) Date: Tue, 18 May 2021 15:36:06 +0200 From: Peter Zijlstra To: "Xu, Like" Cc: Paolo Bonzini , Borislav Petkov , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , weijiang.yang@intel.com, Kan Liang , ak@linux.intel.com, wei.w.wang@intel.com, eranian@google.com, liuxiangdong5@huawei.com, linux-kernel@vger.kernel.org, x86@kernel.org, kvm@vger.kernel.org, Like Xu Subject: Re: [PATCH v6 07/16] KVM: x86/pmu: Reprogram PEBS event to emulate guest PEBS counter Message-ID: References: <20210511024214.280733-1-like.xu@linux.intel.com> <20210511024214.280733-8-like.xu@linux.intel.com> <2d874bce-2823-13b4-0714-3de5b7c475f0@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <2d874bce-2823-13b4-0714-3de5b7c475f0@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 18, 2021 at 09:28:52PM +0800, Xu, Like wrote: > > How would pebs && !intr be possible? > > I don't think it's possible. And yet you keep that 'intr||pebs' weirdness :/ > > Also; wouldn't this be more legible > > when written like: > > > > perf_overflow_handler_t ovf = kvm_perf_overflow; > > > > ... > > > > if (intr) > > ovf = kvm_perf_overflow_intr; > > > > ... > > > > event = perf_event_create_kernel_counter(&attr, -1, current, ovf, pmc); > > > > Please yell if you don't like this: > > diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c > index 711294babb97..a607f5a1b9cd 100644 > --- a/arch/x86/kvm/pmu.c > +++ b/arch/x86/kvm/pmu.c > @@ -122,6 +122,8 @@ static void pmc_reprogram_counter(struct kvm_pmc *pmc, > u32 type, > ??????????????? .config = config, > ??????? }; > ??????? bool pebs = test_bit(pmc->idx, (unsigned long *)&pmu->pebs_enable); > +?????? perf_overflow_handler_t ovf = (intr || pebs) ? > +?????????????? kvm_perf_overflow_intr : kvm_perf_overflow; This, that's exactly the kind of code I wanted to get rid of. ?: has it's place I suppose, but you're creating dense ugly code for no reason. perf_overflow_handle_t ovf = kvm_perf_overflow; if (intr) ovf = kvm_perf_overflow_intr; Is so much easier to read. And if you really worry about that pebs thing; you can add: WARN_ON_ONCE(pebs && !intr);