Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp1639573pxv; Fri, 16 Jul 2021 14:08:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxdLS4UgTv0cJ9JrCD7BGg3Q+zcYNIL9Cqr1CRSgELiGeFdATM7nyEetEYSHOI7o516/C9H X-Received: by 2002:a5e:c803:: with SMTP id y3mr8106355iol.107.1626469700431; Fri, 16 Jul 2021 14:08:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626469700; cv=none; d=google.com; s=arc-20160816; b=qM9RiiHPlRGl91yFa43Ki7M5eVcQbMcRkcxWNd9rvxbH3zJazXNPz0/z+iClJUn8GM hJTmUIeT0o/XEUfYg+dEhfqWweO5DBYVxuIZp94E7bX/uZxhq1Silzir6JRE1fYiXxVI PW/dg9UQdtARx50XI/p2xFyz9t2Az7C4NLJdUE3fVb/5HaPqM1IcCil0+aOzl/rCgmI8 NVK1F3D04Ynn21IC1P7WSX15uKtILTLXtQHCcUVvLp3M5KuiEMrvsCXr8fs9e1Ivf7Ko qRisXKSi5DIXBjS1sIlCXDLW/wOfocptpCKVfnfJUjEjN2gBGMJ4lILEDqcINcq4jrQz 4iWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=+KcxcljLGJIVJWS815GhZ8vwrKBLUZUCoehT4sKIick=; b=San5ieRg+xdveJjXBljaSdpE6t/XoeyrDqE0WsT1SQgQ1KUG7mCxRquzmS74F9FZM8 LqOVFOLVn9k7cap3uxuQOSg0YlNeXdxBipCWadOY0hsfJ9nxdtpFYLJuNOe2rAQvrFMU ZyiCCN4PB1TJPJaeaPIVWnDZ4eI8dG+fPQHTCp7ICPXVI5m9InveEXEV0t1yE9QbDrbk hIzGw7Gm7UHBQEsPcL1Uo9JdYnL+ZMQhc4CqGULYxyjH64wQ3F4eYc4wpDMiSZB8BKlM gg1gHKDiajVI7uUB/7Mbnln0Cx9yEEIzwVUCzjiOvUK3l7Ku8F4FqyF6U7wboSM7y6D/ +BWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=QnfCOaF+; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e127si11775996iof.13.2021.07.16.14.08.08; Fri, 16 Jul 2021 14:08:20 -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=@google.com header.s=20161025 header.b=QnfCOaF+; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235006AbhGPVKT (ORCPT + 99 others); Fri, 16 Jul 2021 17:10:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234967AbhGPVKQ (ORCPT ); Fri, 16 Jul 2021 17:10:16 -0400 Received: from mail-ot1-x336.google.com (mail-ot1-x336.google.com [IPv6:2607:f8b0:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E0ABC061760 for ; Fri, 16 Jul 2021 14:07:20 -0700 (PDT) Received: by mail-ot1-x336.google.com with SMTP id i12-20020a05683033ecb02903346fa0f74dso11219334otu.10 for ; Fri, 16 Jul 2021 14:07:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=+KcxcljLGJIVJWS815GhZ8vwrKBLUZUCoehT4sKIick=; b=QnfCOaF+t/airvvWleBWMXi4bMAV8F8C07l/T21uynV4up468L9W/0CdIOvo/1Ioa+ 3Nq3QpfIdmG2aHxBU8+fchqhDTbq+QALYfwICHMMLDq2xDVmXKwD2p5A/zt1kpKgmcLR 3Rv9fl+CacqOqDy2bfRXC48IE+KHTvF2Fj0pDj4L+e0wif8olOH6OiHxTXNaS8IWhovm srV6dFZmOAYSg23tqf7uOHyQWF/y5bZHWcW5dAlsRVqGgeI9zQQ+hdvMnRzy0XFHm7Yi 6uxumbS1rmq6jAdLTjZNdyULanX8BhvaeBdyZAj9dvJmJ+rB2bclMcsrAM+PV93H3FT1 /Ekg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=+KcxcljLGJIVJWS815GhZ8vwrKBLUZUCoehT4sKIick=; b=nJ/nyW9DOuM/jKXz5rQLRjg/wXHscvebY+MMzVLTSDeqoyQabSdAUhMgYHOdvjcGt0 D0k+cw9FpaYfWFHBELUzn2umtJ3aMANd6FGhjlGGmMLOTqIkU/YNGrPbgWqw6NNpyTp+ CaR6PTnKihL5INMwNCAXuSosJqOzsfQFMMQVOGSq0boN/sZLqg+mFzQfyHFwHKtHTydH EyTl9Cw7x+3SlsHzKNmInchFrrKLRb8cf2FUsKtwhmK7MblAUnCMumqc144tS/JYFTBy HEfLi2jQ4h778D+S64/+y1yRLlRPoIHqGJR3+zhPmgNAxBnh9zL6K5PrbFT0O4UQVOu7 cRNQ== X-Gm-Message-State: AOAM5324nAPaSw+K1g93JttGUaPGtzUaYFjEnS4An+rygIIQqMTv3yDR iryL3RtcbQyYT/GGmVMtyQ8OANihZp/eZJy5io1BGg== X-Received: by 2002:a9d:550e:: with SMTP id l14mr9890451oth.241.1626469639196; Fri, 16 Jul 2021 14:07:19 -0700 (PDT) MIME-Version: 1.0 References: <20210716085325.10300-1-lingshan.zhu@intel.com> In-Reply-To: From: Jim Mattson Date: Fri, 16 Jul 2021 14:07:08 -0700 Message-ID: Subject: Re: [PATCH V8 00/18] KVM: x86/pmu: Add *basic* support to enable guest PEBS via DS To: "Liang, Kan" Cc: Zhu Lingshan , 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 16, 2021 at 12:00 PM Liang, Kan wrote: > > > > 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/ It's the other way around. AFAIK, there is no architectural way to specify that only counters 2 and 3 are available, so we have to give the guest counters 0 and 1. > For the current proposal, both guest and host can see all 4 GP counters. > The counters are shared. I don't understand how that can work. If the host programs two counters, how can you give the guest four counters? > 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 we reserve counters 0 and 1 for the guest, this is not a problem (assuming we tell the guest it only has two counters). If we don't statically partition the counters, I don't see how you can ensure that the guest behaves as architected. For example, what do you do when the guest programs four counters and the host programs two? > 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. And if you don't have enough resources?