Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp1559916pxv; Fri, 16 Jul 2021 12:02:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJweZucd8jy3g9Q9N+rX4Zmxa8BWmoGst+QaP+Phb5oYj6PfAEs6RT2jbVqbIvWYAygyOypU X-Received: by 2002:a05:600c:2189:: with SMTP id e9mr17735359wme.35.1626462158437; Fri, 16 Jul 2021 12:02:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626462158; cv=none; d=google.com; s=arc-20160816; b=mSeJXUuaDI6D8Em6TmfPPBq6+kv5j6V2Ou8gW6JZ+8I1HdkPUgLQ/TPLvmofs/Kh3d CKC3+1NKPMjDJCUM7j9F1KFTTzxLsYPaQSBjhvGf3CqfTvSx/c7fCrHyGBR77LKQxn1G R8YIDJouzhtdvXyBEtEJRjYIBD6KaNFvTBcKyq7hux7ENQd9BcaB/TA6ua+eJspq/BLC i47KNVPNmlCjLzFCVRnyCkN84NUMnuM27cp2klf9lAwvZrfAPCv4y0fGYex2SMh8LdNE FOHsqrYQA9b8csUqNRCkI8pv16UE3vyRjGjC9H3OAyfOkh7TG+JyeUtt9Y/YbKBnKAHA YaHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=ycp5dQgAbIAJQL95OLm0zEIRhqkm31dJdaHviz7JbGM=; b=uo7V5X3db0WTlv1RLBj+OpPI0PWfIXJrITKVUe+R8436ZXCGSuAN86YSKT4rMeOkb1 qFhJzT4qXFGETc48SrfN2U98lr5IQsPi8picTqpEGtbOEizj1BGPTs08W/zKrD/tX/iB bza0VhHKaAd5WcVh4VkRlVbVTmJUnqXkcjNIksQ5Eye2Ugjhi0UacOJfPaf+FayDT2xT mU/NDywJO1X0gkANY7PuWy7EGIl6/n8kP/3x7n5AiYEHD+Mb2I2MejZjfBUvKqvgbMXV ysaLy2eLG6qQJ/6hzL/yt9ONROItmdbmiP0d8qQpXWvLqvXLc7hzVLOephsZUyG1HyNp pJUA== 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 x21si11711522ejj.704.2021.07.16.12.02.11; Fri, 16 Jul 2021 12:02:38 -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 S232362AbhGPTDe (ORCPT + 99 others); Fri, 16 Jul 2021 15:03:34 -0400 Received: from mga12.intel.com ([192.55.52.136]:3997 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232048AbhGPTDd (ORCPT ); Fri, 16 Jul 2021 15:03:33 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10047"; a="190455776" X-IronPort-AV: E=Sophos;i="5.84,245,1620716400"; d="scan'208";a="190455776" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jul 2021 12:00:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.84,245,1620716400"; d="scan'208";a="497124607" Received: from linux.intel.com ([10.54.29.200]) by FMSMGA003.fm.intel.com with ESMTP; 16 Jul 2021 12:00:36 -0700 Received: from [10.209.0.112] (kliang2-MOBL.ccr.corp.intel.com [10.209.0.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by linux.intel.com (Postfix) with ESMTPS id EFC7858073D; Fri, 16 Jul 2021 12:00:33 -0700 (PDT) Subject: Re: [PATCH V8 00/18] KVM: x86/pmu: Add *basic* support to enable guest PEBS via DS To: Jim Mattson , Zhu Lingshan Cc: peterz@infradead.org, pbonzini@redhat.com, bp@alien8.de, seanjc@google.com, vkuznets@redhat.com, wanpengli@tencent.com, joro@8bytes.org, 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.linux@gmail.com, boris.ostrvsky@oracle.com References: <20210716085325.10300-1-lingshan.zhu@intel.com> From: "Liang, Kan" Message-ID: Date: Fri, 16 Jul 2021 15:00:32 -0400 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 7/16/2021 1:02 PM, Jim Mattson wrote: > On Fri, Jul 16, 2021 at 1:54 AM Zhu Lingshan wrote: >> >> The guest Precise Event Based Sampling (PEBS) feature can provide an >> architectural state of the instruction executed after the guest instruction >> that exactly caused the event. It needs new hardware facility only available >> on Intel Ice Lake Server platforms. This patch set enables the basic PEBS >> feature for KVM guests on ICX. >> >> We can use PEBS feature on the Linux guest like native: >> >> # echo 0 > /proc/sys/kernel/watchdog (on the host) >> # perf record -e instructions:ppp ./br_instr a >> # perf record -c 100000 -e instructions:pp ./br_instr a >> >> To emulate guest PEBS facility for the above perf usages, >> we need to implement 2 code paths: >> >> 1) Fast path >> >> This is when the host assigned physical PMC has an identical index as the >> virtual PMC (e.g. using physical PMC0 to emulate virtual PMC0). >> This path is used in most common use cases. >> >> 2) Slow path >> >> This is when the host assigned physical PMC has a different index from the >> virtual PMC (e.g. using physical PMC1 to emulate virtual PMC0) In this case, >> KVM needs to rewrite the PEBS records to change the applicable counter indexes >> to the virtual PMC indexes, which would otherwise contain the physical counter >> index written by PEBS facility, and switch the counter reset values to the >> offset corresponding to the physical counter indexes in the DS data structure. >> >> The previous version [0] enables both fast path and slow path, which seems >> a bit more complex as the first step. In this patchset, we want to start with >> the fast path to get the basic guest PEBS enabled while keeping the slow path >> disabled. More focused discussion on the slow path [1] is planned to be put to >> another patchset in the next step. >> >> Compared to later versions in subsequent steps, the functionality to support >> host-guest PEBS both enabled and the functionality to emulate guest PEBS when >> the counter is cross-mapped are missing in this patch set >> (neither of these are typical scenarios). > > I'm not sure exactly what scenarios you're ruling out here. In our > environment, we always have to be able to support host-level > profiling, whether or not the guest is using the PMU (for PEBS or > anything else). Hence, for our *basic* vPMU offering, we only expose > two general purpose counters to the guest, so that we can keep two > general purpose counters for the host. In this scenario, I would > expect cross-mapped counters to be common. Are we going to be able to > use this implementation? > Let's say we have 4 GP counters in HW. Do you mean that the host owns 2 GP counters (counter 0 & 1) and the guest own the other 2 GP counters (counter 2 & 3) in your envirinment? We did a similar implementation in V1, but the proposal has been denied. https://lore.kernel.org/kvm/20200306135317.GD12561@hirez.programming.kicks-ass.net/ For the current proposal, both guest and host can see all 4 GP counters. The counters are shared. The guest cannot know the availability of the counters. It may requires a counter (e.g., counter 0) which may has been used by the host. Host may provides another counter (e.g., counter 1) to the guest. This is the case described in the slow path. For this case, we have to modify the guest PEBS record. Because the counter index in the PEBS record is 1, while the guest perf driver expects 0. If counter 0 is available, guests can use counter 0. That's the fast path. I think the fast path should be more common even both host and guest are profiling. Because except for some specific events, we may move the host event to the counters which are not required by guest if we have enough resources. Thanks, Kan