Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp803683img; Mon, 18 Mar 2019 14:45:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqxShJocEUrRp7v/JXrWtOkDJPyHMVcCs4F5UuMSD4hFLmFK6rxDb5tf2ZWhO/0hM1eStoyq X-Received: by 2002:a17:902:3f83:: with SMTP id a3mr21287961pld.6.1552945515552; Mon, 18 Mar 2019 14:45:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552945515; cv=none; d=google.com; s=arc-20160816; b=iKrWyxOV2tL9SPjF1EmvFNcwSW8QOWjETU7+NufQemwe8STmlzxnZNfRlcqcuBOqN1 Rr95/ynzunuKkfHLMcw379L972K66VnPVGXTytzwpKmNFaolMMj8EzcvdOJjrafnsUhf rYgcHc0UeOWijq9wbE0qsvn2c3EgjBiJyVUn0gqPQWoBfqXRxtdAkpDU/Ajk+om+9rTn Td6tmwIjnF0ts8C2kU+5RpF1a7DFxlwii2zRJyk38QDof4azvtjTqVDrzaua+3MnOFts 9r7U/evDOBqnxgKr9ql0+f33OKpajVng++SAFfuUtS3aNBrmAnWAo5DTDtzrPYO3GBxr hn4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=o8Vuc4TPTiMYWGJpuPBKE/mvvWEkPqNawGYhFYQrHyI=; b=NulRZDTMV+hXv8uX5WN2s6dYXKSvhjJt8spQFf+7sKrcuVd/l6WjMSd5q4oAhDluLb 4T2RKLjf133qyAu1zr4JqJJ3drx7xpwU1N0WVV9VsZ8kO0/lgC9jvlkn/K8SsPp5Ib/y Ir5OCF2XRvu6i9Y55LEoQZxaz2xqSjC6qrpJjDtG5F2toorS5MxlysS3i5W5kuw+UhFy V09s/Kr0caH8nN6SAkZfJdzBhFBbaXhK+JjcOwUdl+OZYCvZXTfDsq3w768TxoadenVf c0/KKbecfuhnVSr6/SsA3pYb/uHi/PM/nalKtZrssxQv9u2z+r3R3uBMk9iI43IPSoov Gxog== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id 42si10982445pld.383.2019.03.18.14.45.00; Mon, 18 Mar 2019 14:45:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1727593AbfCRVoS (ORCPT + 99 others); Mon, 18 Mar 2019 17:44:18 -0400 Received: from mga04.intel.com ([192.55.52.120]:57595 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727516AbfCRVoR (ORCPT ); Mon, 18 Mar 2019 17:44:17 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Mar 2019 14:44:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,495,1544515200"; d="scan'208";a="308301786" Received: from otc-icl-cdi187.jf.intel.com ([10.54.55.103]) by orsmga005.jf.intel.com with ESMTP; 18 Mar 2019 14:44:16 -0700 From: kan.liang@linux.intel.com To: peterz@infradead.org, acme@kernel.org, mingo@redhat.com, linux-kernel@vger.kernel.org Cc: tglx@linutronix.de, jolsa@kernel.org, eranian@google.com, alexander.shishkin@linux.intel.com, ak@linux.intel.com, Kan Liang Subject: [PATCH 05/22] perf/x86: Support constraint ranges Date: Mon, 18 Mar 2019 14:41:27 -0700 Message-Id: <20190318214144.4639-6-kan.liang@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190318214144.4639-1-kan.liang@linux.intel.com> References: <20190318214144.4639-1-kan.liang@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andi Kleen Icelake extended the general counters to 8, even when SMT is enabled. However only a (large) subset of the events can be used on all 8 counters. The events that can or cannot be used on all counters are organized in ranges. We need a lot of scheduler constraints to handle all this. To avoid blowing up the tables add event code ranges to the constraint tables, and a new inline function to match them. The changes costs ~2k text size according to 0day report. Signed-off-by: Andi Kleen Signed-off-by: Kan Liang --- arch/x86/events/intel/core.c | 2 +- arch/x86/events/intel/ds.c | 2 +- arch/x86/events/perf_event.h | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c index a964b9832b0c..8486ab87f8f8 100644 --- a/arch/x86/events/intel/core.c +++ b/arch/x86/events/intel/core.c @@ -2655,7 +2655,7 @@ x86_get_event_constraints(struct cpu_hw_events *cpuc, int idx, if (x86_pmu.event_constraints) { for_each_event_constraint(c, x86_pmu.event_constraints) { - if ((event->hw.config & c->cmask) == c->code) { + if (constraint_match(c, event->hw.config)) { event->hw.flags |= c->flags; return c; } diff --git a/arch/x86/events/intel/ds.c b/arch/x86/events/intel/ds.c index 974284c5ed6c..30370fb93e21 100644 --- a/arch/x86/events/intel/ds.c +++ b/arch/x86/events/intel/ds.c @@ -858,7 +858,7 @@ struct event_constraint *intel_pebs_constraints(struct perf_event *event) if (x86_pmu.pebs_constraints) { for_each_event_constraint(c, x86_pmu.pebs_constraints) { - if ((event->hw.config & c->cmask) == c->code) { + if (constraint_match(c, event->hw.config)) { event->hw.flags |= c->flags; return c; } diff --git a/arch/x86/events/perf_event.h b/arch/x86/events/perf_event.h index 27c7945b5174..863d27f4c352 100644 --- a/arch/x86/events/perf_event.h +++ b/arch/x86/events/perf_event.h @@ -54,6 +54,7 @@ struct event_constraint { int weight; int overlap; int flags; + u64 range_end; }; /* * struct hw_perf_event.flags flags @@ -71,6 +72,12 @@ struct event_constraint { #define PERF_X86_EVENT_AUTO_RELOAD 0x0400 /* use PEBS auto-reload */ #define PERF_X86_EVENT_LARGE_PEBS 0x0800 /* use large PEBS */ +static inline bool constraint_match(struct event_constraint *c, u64 ecode) +{ + ecode &= c->cmask; + return ecode == c->code || + (c->range_end && ecode >= c->code && ecode <= c->range_end); +} struct amd_nb { int nb_id; /* NorthBridge id */ @@ -267,9 +274,22 @@ struct cpu_hw_events { .flags = f, \ } +#define __EVENT_CONSTRAINT_RANGE(c, e, n, m, w, o, f) { \ + { .idxmsk64 = (n) }, \ + .code = (c), \ + .range_end = (e), \ + .cmask = (m), \ + .weight = (w), \ + .overlap = (o), \ + .flags = f, \ +} + #define EVENT_CONSTRAINT(c, n, m) \ __EVENT_CONSTRAINT(c, n, m, HWEIGHT(n), 0, 0) +#define EVENT_CONSTRAINT_RANGE(c, e, n, m) \ + __EVENT_CONSTRAINT_RANGE(c, e, n, m, HWEIGHT(n), 0, 0) + #define INTEL_EXCLEVT_CONSTRAINT(c, n) \ __EVENT_CONSTRAINT(c, n, ARCH_PERFMON_EVENTSEL_EVENT, HWEIGHT(n),\ 0, PERF_X86_EVENT_EXCL) @@ -304,6 +324,12 @@ struct cpu_hw_events { #define INTEL_EVENT_CONSTRAINT(c, n) \ EVENT_CONSTRAINT(c, n, ARCH_PERFMON_EVENTSEL_EVENT) +/* + * Constraint on a range of Event codes + */ +#define INTEL_EVENT_CONSTRAINT_RANGE(c, e, n) \ + EVENT_CONSTRAINT_RANGE(c, e, n, ARCH_PERFMON_EVENTSEL_EVENT) + /* * Constraint on the Event code + UMask + fixed-mask * @@ -351,6 +377,9 @@ struct cpu_hw_events { #define INTEL_FLAGS_EVENT_CONSTRAINT(c, n) \ EVENT_CONSTRAINT(c, n, INTEL_ARCH_EVENT_MASK|X86_ALL_EVENT_FLAGS) +#define INTEL_FLAGS_EVENT_CONSTRAINT_RANGE(c, e, n) \ + EVENT_CONSTRAINT_RANGE(c, e, n, INTEL_ARCH_EVENT_MASK|X86_ALL_EVENT_FLAGS) + /* Check only flags, but allow all event/umask */ #define INTEL_ALL_EVENT_CONSTRAINT(code, n) \ EVENT_CONSTRAINT(code, n, X86_ALL_EVENT_FLAGS) @@ -367,6 +396,11 @@ struct cpu_hw_events { ARCH_PERFMON_EVENTSEL_EVENT|X86_ALL_EVENT_FLAGS, \ HWEIGHT(n), 0, PERF_X86_EVENT_PEBS_LD_HSW) +#define INTEL_FLAGS_EVENT_CONSTRAINT_DATALA_LD_RANGE(code, end, n) \ + __EVENT_CONSTRAINT_RANGE(code, end, n, \ + ARCH_PERFMON_EVENTSEL_EVENT|X86_ALL_EVENT_FLAGS, \ + HWEIGHT(n), 0, PERF_X86_EVENT_PEBS_LD_HSW) + #define INTEL_FLAGS_EVENT_CONSTRAINT_DATALA_XLD(code, n) \ __EVENT_CONSTRAINT(code, n, \ ARCH_PERFMON_EVENTSEL_EVENT|X86_ALL_EVENT_FLAGS, \ -- 2.17.1