Received: by 2002:ab2:6c55:0:b0:1fd:c486:4f03 with SMTP id v21csp16260lqp; Tue, 11 Jun 2024 12:57:03 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXNlVy0Jt4js3zoJnwTLG9IQkRILN/BNmfZuxyyRAqYrXD9PuaWoDIdNu7KGii0OZtZ2LkOZJ9+Cxj4UjFtnivDUa24v4yvoUP9waTfTQ== X-Google-Smtp-Source: AGHT+IEFKi5WjBtEhbcDfsGk7zBUo+TLjQ4p0sYKziibWqz1Dw4jVeqtfGJSjkVK57rxRFR5mR47 X-Received: by 2002:a17:902:e84a:b0:1f7:37f:728d with SMTP id d9443c01a7336-1f7037f75d2mr94875795ad.10.1718135822790; Tue, 11 Jun 2024 12:57:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718135822; cv=pass; d=google.com; s=arc-20160816; b=qJ4iIW3mOH1LxRIxXwrV28K4w++JzkpN0PvN64wVTpJNROIArSHo0reR2JiCtAnL49 QmUJR+gfIbDxM0FmRcP+m1JV42KrwKSrWygQThs/NDp4z+H50xV6rha9nK/Sikp5mAfC UYrlGZyt75iHNwFnFUvIslZtuJXpDZmY2QX7syRqODZWbVI0g+uKDuvyr1nbHycU5f8J 0bOhdLPVnT/EtiRfYtS1RdBjkp0It/dL+zsRBf6QjbEg1vXAd20V337c/kB4A8zRCGLH Nz++XaPYFIkoRX9eX26x9UrYeKXolxZhbLo8zWmt3lsG98gl0hZ77GNIYj+ty80OKhnp wvAA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=B3v/pXSYAvC49GnBoSXGaAkiqLpqIK06JhdUetKq2w0=; fh=JGtRCR3dKrXV8esVJCk+oAhHY00UnmybnBogj9A//Ew=; b=lALzEmXI22qfIyvJNyfQyX9PdVggsA630FfSyIsr9a/heWbxAfc89Ez836Psa/IRqP CrimeTFWkm/4g2S6ls+1nmmMxARtGAkeTObubEd3eee2TmrbU3Fi3ZGQCxtq1iI8nhCa +45OzV6mR+hAVOIECqnpFYoQAx+s7NW+3b6QPheB9SCA/px9huRIJjNHHzVwE/LMaYPe RJk0OZ3lEGmdvy8N/mKqQZ95iLMbRG1Mtau+t1fsOFl51df4VOtHoJL5bPa547azGe2N pf76jRwrhXf5TgysoOg9KZiyrw8zoBKM+J2oVO9Y+PR8P1keKE04y9XN+mc2iaDI48om w2rw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Ho9qZ2nR; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-210272-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-210272-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d9443c01a7336-1f6ef25e4c4si64037415ad.266.2024.06.11.12.57.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 12:57:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-210272-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Ho9qZ2nR; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-210272-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-210272-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id D516B288260 for ; Tue, 11 Jun 2024 16:51:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 524007441E; Tue, 11 Jun 2024 16:50:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Ho9qZ2nR" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E352C55880; Tue, 11 Jun 2024 16:49:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.7 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718124601; cv=none; b=TCWiW7J/hqDW7Uzbc8vFNC9L/+fUbX1qWgUzXziIE8pDfVoE1ldq90RRkd18smkx5IFvKBOxEFe6FX7LgAT7oeUKIBWWqnUD4bnpcrDbwWxkdgw7UwrPb9j6ceQc6ilTupJ8oPu4eyIlAhVcDVMdT70Zozg/LF3RTRoBCLFZlLY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718124601; c=relaxed/simple; bh=k75EWiLGbT8v5X6AJvmrIwUxotvioqipvuQ9n/eL580=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=RKM541ahtRKEkfrUPpL+hbbQRQIlKD3vkw78Y3SttehPQuyYVz2PZiA3GtZrie3vJ3JVfgBRyg7lYoUwB8f+nZ4cel2WY6czD5raUVejEzQmQy+H1k3qk9X8ADYivIjSxxJMjfEITMZXT4p5UaHOvKcURcjRFMCRugCG72q4sR4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Ho9qZ2nR; arc=none smtp.client-ip=192.198.163.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1718124600; x=1749660600; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=k75EWiLGbT8v5X6AJvmrIwUxotvioqipvuQ9n/eL580=; b=Ho9qZ2nRU7Y6On8MG9u4TrGQG3vZyD3HgDKuE0BtIaSWolkkeT6CVzKT w3fyYsQcYyU2ulC++3Lh656CIV8Uu4wXiMH9aSanyZSfjOEetoc1+pd3D 7FvG9cmHh5MCzT2GwddbInK0FykeLn3gFIdYltGryEtyZPi3VV6ElHIPQ eztCGjwFhQ10ue82ZcOO0ZzhTs7yJEumlYODGy4RgNrarA3oeDyCWN3ng vdmnsVcO9kh9PQPcq5qzYT1aeNq6tLPBJpAig7e2y3lNU4fMOeJiU1oWm dylCRdKPSRq4YncBHugiyDKtCrhWyi4U5lh13ZJ458N2EVLwRplbC9oqE A==; X-CSE-ConnectionGUID: coijBmh+RE2Qw3Z8VI0VmQ== X-CSE-MsgGUID: mnRNCBiSTP2rLQfVl4ieXg== X-IronPort-AV: E=McAfee;i="6600,9927,11100"; a="40249667" X-IronPort-AV: E=Sophos;i="6.08,230,1712646000"; d="scan'208";a="40249667" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jun 2024 09:49:59 -0700 X-CSE-ConnectionGUID: prw5tJPDTMChoJPIe/LuxQ== X-CSE-MsgGUID: g3xvhN0eTX6960PvsJSbsw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,230,1712646000"; d="scan'208";a="40103312" Received: from jacob-builder.jf.intel.com ([10.54.39.125]) by orviesa008.jf.intel.com with ESMTP; 11 Jun 2024 09:49:58 -0700 From: Jacob Pan To: X86 Kernel , LKML , Thomas Gleixner , Dave Hansen , "H. Peter Anvin" , "Ingo Molnar" , "Borislav Petkov" , linux-perf-users@vger.kernel.org, Peter Zijlstra Cc: Andi Kleen , "Xin Li" , Jacob Pan , Zeng Guang Subject: [PATCH v2 5/6] perf/x86: Enable NMI source reporting for perfmon Date: Tue, 11 Jun 2024 09:54:56 -0700 Message-Id: <20240611165457.156364-6-jacob.jun.pan@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240611165457.156364-1-jacob.jun.pan@linux.intel.com> References: <20240611165457.156364-1-jacob.jun.pan@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Program the designated NMI source vector into the performance monitoring interrupt (PMI) of the local vector table. PMI handler will be directly invoked when its NMI is generated. This avoids the latency of calling all NMI handlers blindly. Co-developed-by: Zeng Guang Signed-off-by: Jacob Pan --- v2: Fix a compile error apic_perfmon_ctr is undefined in i386 config --- arch/x86/events/core.c | 8 ++++++-- arch/x86/events/intel/core.c | 6 +++--- arch/x86/include/asm/apic.h | 1 + 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c index 1ef2201e48ac..db8c30881f5c 100644 --- a/arch/x86/events/core.c +++ b/arch/x86/events/core.c @@ -46,6 +46,7 @@ struct x86_pmu x86_pmu __read_mostly; static struct pmu pmu; +u32 apic_perfmon_ctr = APIC_DM_NMI; DEFINE_PER_CPU(struct cpu_hw_events, cpu_hw_events) = { .enabled = 1, @@ -1680,7 +1681,7 @@ int x86_pmu_handle_irq(struct pt_regs *regs) * This generic handler doesn't seem to have any issues where the * unmasking occurs so it was left at the top. */ - apic_write(APIC_LVTPC, APIC_DM_NMI); + apic_write(APIC_LVTPC, apic_perfmon_ctr); for (idx = 0; idx < x86_pmu.num_counters; idx++) { if (!test_bit(idx, cpuc->active_mask)) @@ -1723,7 +1724,10 @@ void perf_events_lapic_init(void) /* * Always use NMI for PMU */ - apic_write(APIC_LVTPC, APIC_DM_NMI); + if (cpu_feature_enabled(X86_FEATURE_NMI_SOURCE)) + apic_perfmon_ctr |= NMI_SOURCE_VEC_PMI; + + apic_write(APIC_LVTPC, apic_perfmon_ctr); } static int diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c index 38c1b1f1deaa..b4a70457c678 100644 --- a/arch/x86/events/intel/core.c +++ b/arch/x86/events/intel/core.c @@ -3093,7 +3093,7 @@ static int intel_pmu_handle_irq(struct pt_regs *regs) * NMI handler. */ if (!late_ack && !mid_ack) - apic_write(APIC_LVTPC, APIC_DM_NMI); + apic_write(APIC_LVTPC, apic_perfmon_ctr); intel_bts_disable_local(); cpuc->enabled = 0; __intel_pmu_disable_all(true); @@ -3130,7 +3130,7 @@ static int intel_pmu_handle_irq(struct pt_regs *regs) done: if (mid_ack) - apic_write(APIC_LVTPC, APIC_DM_NMI); + apic_write(APIC_LVTPC, apic_perfmon_ctr); /* Only restore PMU state when it's active. See x86_pmu_disable(). */ cpuc->enabled = pmu_enabled; if (pmu_enabled) @@ -3143,7 +3143,7 @@ static int intel_pmu_handle_irq(struct pt_regs *regs) * Haswell CPUs. */ if (late_ack) - apic_write(APIC_LVTPC, APIC_DM_NMI); + apic_write(APIC_LVTPC, apic_perfmon_ctr); return handled; } diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h index 9327eb00e96d..bcf8d17240c8 100644 --- a/arch/x86/include/asm/apic.h +++ b/arch/x86/include/asm/apic.h @@ -49,6 +49,7 @@ static inline void x86_32_probe_apic(void) { } #endif extern u32 cpuid_to_apicid[]; +extern u32 apic_perfmon_ctr; #define CPU_ACPIID_INVALID U32_MAX -- 2.25.1