Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1677553pxj; Wed, 19 May 2021 11:14:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxLBhtcGfFzpPjvFr6oEOeySBaszq3H0TqL5XgqmRPXbgGUtu2TNm6vmzrzWsaZY/vVLQmo X-Received: by 2002:a05:6402:1914:: with SMTP id e20mr378681edz.70.1621448088350; Wed, 19 May 2021 11:14:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621448088; cv=none; d=google.com; s=arc-20160816; b=QP9xnryoYdI6x5shKZquPGom6EIjpvf/rO3B1RQGH5e2cIylp2MUdP0XdycKcrBCoH +Zz1FZla5Bm+RNsteNDRdgBsLWOga4MAuzbV7updVfmW093Bfd4GdEwINHBDIaY8VFMN FXhH6pCMNQDILdemSdeOsl13DfGeuOZnpOd6QuS3laroADonN8CanuWXgNaRZR4kTNx7 ljAWtUf08M/OR2u9EL4NK0fpB/tSGIW4jei1eulZSN0PpY4IsJW8tpXs3RG0EM3X9Yck 2EoDn/LUnY+qX5lTWhSOrXNc6dT+FWpZwktGdxtIozh3J3uKm4fC9qt/sej4b9zAG/Wp XQOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:ironport-sdr:ironport-sdr; bh=bwVxclCcRygzww4Giw4dAcrNPAhD+E7P+18cqT1+F58=; b=Oz04Leopa+R2WAOS7EiVRaeqz0lvQG+0tTebkN0FdXhxWQF8X6AFi3sg8LYDpbO1Oj W1JxTYcwaAPgPj+6x2vDITzxn7PjKzDEzXylEiJYSHziCSoBrAfRI4dICTXS4HNS+WTB O0ecqUZA0JCBfXmeEZFYPaadOt7CUqD2oybZ+rMH0LGVLM0CbUNVLsKInkN4FdZTvwxG amZQFJzVCVMYuLmV4tVCyVO8Or+wZKeCGXBmsnyhRfN6UG/hiGTgd+5XwbTwxEp60zq8 UZBTvpA/tgJqEs1cr38JnQptg5GHy7cB+wWXRrRNn4Eo9r2QUCvxVHOzoyArn2v+tcke t1ag== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id fl21si340293ejc.601.2021.05.19.11.14.24; Wed, 19 May 2021 11:14:48 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349769AbhEROHX (ORCPT + 99 others); Tue, 18 May 2021 10:07:23 -0400 Received: from mga14.intel.com ([192.55.52.115]:40327 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244785AbhEROHW (ORCPT ); Tue, 18 May 2021 10:07:22 -0400 IronPort-SDR: mvIvGkY4EEkezmry0/mCOpQuXV/sOyXe8+pbjk92ACcuoLEK0O0mZ33Jlozy8Wy2POcAh7oUFw nmHmIEkOs32Q== X-IronPort-AV: E=McAfee;i="6200,9189,9987"; a="200413209" X-IronPort-AV: E=Sophos;i="5.82,310,1613462400"; d="scan'208";a="200413209" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 May 2021 07:06:04 -0700 IronPort-SDR: jC8sz1bNPimczh67OzWbwHkgHhSoGhxg1bBGuokQrEIPj/pXy9uCtGfPMd3vFO3xrxh9YSCeJE 1HmNRlU2Nmrg== X-IronPort-AV: E=Sophos;i="5.82,310,1613462400"; d="scan'208";a="472969079" Received: from likexu-mobl1.ccr.corp.intel.com (HELO [10.255.30.127]) ([10.255.30.127]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 May 2021 07:06:00 -0700 Subject: Re: [PATCH v6 07/16] KVM: x86/pmu: Reprogram PEBS event to emulate guest PEBS counter To: Peter Zijlstra 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 References: <20210511024214.280733-1-like.xu@linux.intel.com> <20210511024214.280733-8-like.xu@linux.intel.com> <2d874bce-2823-13b4-0714-3de5b7c475f0@intel.com> From: "Xu, Like" Message-ID: <6f4061ef-1a3e-b21c-2dd1-051bb93c846f@intel.com> Date: Tue, 18 May 2021 22:05:56 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.10.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021/5/18 21:36, Peter Zijlstra wrote: > 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); > Thanks!  Glad you could review my code. As a new generation, we do appreciate your patient guidance on your taste in code.