Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1802035pxb; Wed, 2 Feb 2022 12:51:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJxubx04fqvEJGYwlvZH+Trby6mOLaJqBP0fOi3KfsMxkfIlFQL46S6KUTuKYV9GIpqLm6o0 X-Received: by 2002:a17:902:7b95:: with SMTP id w21mr32072176pll.48.1643835069219; Wed, 02 Feb 2022 12:51:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643835069; cv=none; d=google.com; s=arc-20160816; b=DNrNuOt7FhEvoxPjQFU335fM/T/T3FrcZVJwrd+qc/r8IA657BKvzhGs1caOzIenSS c3LVvS5UTXyvvQcnL2QLdFZISrGwmWOcDPhmGCwh7qNzvPf2MvvhB5ztrdMPhYJxf1PD /tguXn5yKWR7Kio7mrZ2915aLVYbk7Ya77Arhy5v6+uXZh8PycQEwsqPozlIhW5uyAqm 0d9HzzSqZEJtmcv4xTfdjRqtMuAqMZEqMo2YGniVnaxcTpk62C8cpdvrioClfB5FEA0K 1yBTTfE6s64q179m58+H6SnkhYUT2C3j+EWGq6icEveV1uDCY8azetOkN8uuGsQZpxP3 CDlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=QU0LlTq3DNJ2aWGrY3I47oz46MhAt45cXF+2l6bSy50=; b=BWYshcH4fYEj6KnTBpUVO2K2Alz7BZFg88+WMw1saOVzbR5bPAUv6SyLmSAdBJGuck LKJ5RN2VsAoI0sgm7Gf+qxVL9l9L0NB3AFhHExjhvGHuZhrt4afogUVifmxAQNMvtq1U FZRkKIoV0PMXWQ+xv+m9+4reyxVG5M91m7CU1Kqe2aCC2U17LNAgN5vKo1fuJrpVR2Ak idZxOsX29XaznbROR2Z1AA/UN+O5uG2PhQw4i60YAlV8sbNVySkcsHea3G8KiqSHFpif Ye81uiasGeivttqRHETcJJxtOVLD1a6KWAfkBOYDbsF/1lY+8Ejcesz6XU+CnhAs0uTd lFCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=K09HJe5t; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p34si20003663pgb.807.2022.02.02.12.50.56; Wed, 02 Feb 2022 12:51:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=K09HJe5t; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238018AbiBAM1U (ORCPT + 99 others); Tue, 1 Feb 2022 07:27:20 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:54386 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229532AbiBAM1T (ORCPT ); Tue, 1 Feb 2022 07:27:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643718439; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QU0LlTq3DNJ2aWGrY3I47oz46MhAt45cXF+2l6bSy50=; b=K09HJe5tq3U9JrorDaxe1r5+KAyz/wHnGo/cLk+KMAaOCO5VuMMVhT0x97c3eHaVTNlgcN m2qYWGFy2Xx2c1KbZUJcrzbEBimYwBXM9lr4VBGBx2jKtN9nc3z6n/LsL/6gNxB7/mcmU9 8SpEPLY2x6kei2QB0Bcz4HrGKxnFdww= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-264-z5TnTUKWNuSv5aRcbPON0g-1; Tue, 01 Feb 2022 07:27:18 -0500 X-MC-Unique: z5TnTUKWNuSv5aRcbPON0g-1 Received: by mail-ej1-f72.google.com with SMTP id q21-20020a17090622d500b006bb15a59a68so4536279eja.18 for ; Tue, 01 Feb 2022 04:27:17 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=QU0LlTq3DNJ2aWGrY3I47oz46MhAt45cXF+2l6bSy50=; b=V6q34Vi8aXaOv1dPWN0ixYb01hi4Z5am5sPNnODb/BzbxbUBhyL2rCABFHvhiBTPVJ Dqx9O04oubJJxiw2U9+N8kIcZZ5jfIQyLVKikEQfemvelhJ9JUaE7f1sw7o/dzhEYD4R Ry0CIkmkFdK/tSOMdCCQ/xXuSHA+Jr7upKJflIhTVTDx74NT0qDYVVGyzPANbaUh9Log s3s0pflRDpCOh02Y1aBOOcxovnswsd8BpD9fJ47Beoez6yGiRXMsA6+Ja/GYXJVhpLXV otfY2Aqr4aKMlyvDi7h4QDubRCherejJaj3vRPh9ReaXMdF/BFi64fwy1rv8gV88h8QR U+0g== X-Gm-Message-State: AOAM533ioqz/UGmtC0OgZ0friAZuoEZoPqPdu6mjRaS40cplO0HoHp56 9MNdBCdhuHVSzcX1ROAsZsui4kCmEgHiQOz6AKFZBB7Z12TP0pfm5OiV5hN7VKyllCWibAKqhrO FU16kWagZuLOYT3RI5Ipxwd1j X-Received: by 2002:a05:6402:11c7:: with SMTP id j7mr24649136edw.139.1643718436960; Tue, 01 Feb 2022 04:27:16 -0800 (PST) X-Received: by 2002:a05:6402:11c7:: with SMTP id j7mr24649122edw.139.1643718436788; Tue, 01 Feb 2022 04:27:16 -0800 (PST) Received: from ?IPV6:2001:b07:6468:f312:c8dd:75d4:99ab:290a? ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.googlemail.com with ESMTPSA id d15sm14767385ejw.143.2022.02.01.04.27.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 01 Feb 2022 04:27:16 -0800 (PST) Message-ID: Date: Tue, 1 Feb 2022 13:27:15 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: [PATCH kvm/queue v2 2/3] perf: x86/core: Add interface to query perfmon_event_map[] directly Content-Language: en-US To: Like Xu , Jim Mattson , Peter Zijlstra Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Like Xu References: <20220117085307.93030-1-likexu@tencent.com> <20220117085307.93030-3-likexu@tencent.com> From: Paolo Bonzini In-Reply-To: <20220117085307.93030-3-likexu@tencent.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 1/17/22 09:53, Like Xu wrote: > From: Like Xu > > Currently, we have [intel|knc|p4|p6]_perfmon_event_map on the Intel > platforms and amd_[f17h]_perfmon_event_map on the AMD platforms. > > Early clumsy KVM code or other potential perf_event users may have > hard-coded these perfmon_maps (e.g., arch/x86/kvm/svm/pmu.c), so > it would not make sense to program a common hardware event based > on the generic "enum perf_hw_id" once the two tables do not match. > > Let's provide an interface for callers outside the perf subsystem to get > the counter config based on the perfmon_event_map currently in use, > and it also helps to save bytes. > > Cc: Peter Zijlstra > Signed-off-by: Like Xu > --- > arch/x86/events/core.c | 9 +++++++++ > arch/x86/include/asm/perf_event.h | 2 ++ > 2 files changed, 11 insertions(+) > > diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c > index 38b2c779146f..751048f4cc97 100644 > --- a/arch/x86/events/core.c > +++ b/arch/x86/events/core.c > @@ -693,6 +693,15 @@ void x86_pmu_disable_all(void) > } > } > > +u64 perf_get_hw_event_config(int perf_hw_id) > +{ > + if (perf_hw_id < x86_pmu.max_events) > + return x86_pmu.event_map(perf_hw_id); > + > + return 0; > +} > +EXPORT_SYMBOL_GPL(perf_get_hw_event_config); > + > struct perf_guest_switch_msr *perf_guest_get_msrs(int *nr) > { > return static_call(x86_pmu_guest_get_msrs)(nr); > diff --git a/arch/x86/include/asm/perf_event.h b/arch/x86/include/asm/perf_event.h > index 8fc1b5003713..d1e325517b74 100644 > --- a/arch/x86/include/asm/perf_event.h > +++ b/arch/x86/include/asm/perf_event.h > @@ -492,9 +492,11 @@ static inline void perf_check_microcode(void) { } > > #if defined(CONFIG_PERF_EVENTS) && defined(CONFIG_CPU_SUP_INTEL) > extern struct perf_guest_switch_msr *perf_guest_get_msrs(int *nr); > +extern u64 perf_get_hw_event_config(int perf_hw_id); > extern int x86_perf_get_lbr(struct x86_pmu_lbr *lbr); > #else > struct perf_guest_switch_msr *perf_guest_get_msrs(int *nr); > +u64 perf_get_hw_event_config(int perf_hw_id); Should this be an inline that returns 0? > static inline int x86_perf_get_lbr(struct x86_pmu_lbr *lbr) > { > return -1; Peter, please review/ack this. Paolo