Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp507535img; Wed, 20 Mar 2019 05:24:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqx3jCKW1l7SlEzxtH2iCayjlVNBt6RU1/UwQR8XLD202dX45exkZZSdSBKgXWjY6KoSxGeq X-Received: by 2002:a17:902:87:: with SMTP id a7mr7853961pla.295.1553084693465; Wed, 20 Mar 2019 05:24:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553084693; cv=none; d=google.com; s=arc-20160816; b=Wg6mm8S85HgYY6+eu9+eS+fPTq4kEKy4c7uzZcftHlSvo3c3krolCJyal1qMARoGvx inZp13kMTFQfw1EQMkykfn8UzNUB5g1v0mwO/VWaEwL/jks+Wr1VomAL7Aq5L4ILcXhY HDCAeT5wMg6RLeO//UkcpNldMw0QF67BRyHrilqQbrsCWyrg7avvq6Q8Ai4layWF2yGv diYoJJFwKEc80DO25dZ3cBeGRZW7Qs6tnNYMONPKRH6WZ3JubwC4ATO+M7A9YPVPDAo2 EtVtdNJryHaIpzLYVfdPiW1Ry0oKM0O4wtVH+SFXtzTVlqh0PV+3xeyASNEMQqBX3jEp SzPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=W82fy8KoUHr4dndbn9kYy5T4gB/YgZQsmivULDCU6eA=; b=prYejYdndBllqp20E6H2q6ygRGxjo0Okymte5am7z6RJo6rr1Fmho8p0fYS5BwjPrA tpc5QXNiXWfPIajD2A2L/HXbpA5dlfbxgOYtZSuQAQcj83vZ8J4goMi6j8HJeXfMu+R6 aFUcDRmUp4aM6flhvz5Xqi/vNybdNq889PFs8jR7JxrLyCgZGaYNezDhXqBXIZgvd4KJ J8xLNviPB8TiA2BNg5pFuLvI4M4UIplTzge2MZ24ItZx/eCe0gKUqq/AYLshZ4QTYQY1 vt2AlR6I26V1F2U1xkDUNTUQB82e8+bEDr6330lDTyuEG4lAZcBJwABWigb7d0MHiL8Q SS9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=Oh+U9TzX; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l7si1569339pgq.72.2019.03.20.05.24.36; Wed, 20 Mar 2019 05:24:53 -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; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=Oh+U9TzX; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727622AbfCTMXx (ORCPT + 99 others); Wed, 20 Mar 2019 08:23:53 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:52812 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726366AbfCTMXw (ORCPT ); Wed, 20 Mar 2019 08:23:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=W82fy8KoUHr4dndbn9kYy5T4gB/YgZQsmivULDCU6eA=; b=Oh+U9TzXXCMXMCD0s14YCM7Cj QhOXcDtqcjL90I74mEO+sWHBLUFPozFwWKK8WfYLOFXkGJlj290MgmjIJ7qKxFvjpQxP3x6l0Kgs7 /YWH9qo81zT83lQmqMlWOf0tctRwLkhxKLfEpoR6yijr47mDUtDZj0V2uZyPkHsTUj1gVNWRJqrFJ TmpzzHXBfyjOBfkYivCNn8rUhMI9NJnZCIpQQHOp4iTB72ZRc4x1sp0sVMoxU4TBo42t9rHLX/0IP cgu7FKtYWxv00aGrOVAH5NNSGdSwwd002c/7oS+9K3n0lDDtx7pw7g/qsrrlciFrB0rEk6G2KVWxy pI8XSHG5w==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1h6aG3-0005pY-Ni; Wed, 20 Mar 2019 12:23:47 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 144D423EA30BA; Wed, 20 Mar 2019 13:23:46 +0100 (CET) Date: Wed, 20 Mar 2019 13:23:46 +0100 From: Peter Zijlstra To: Stephane Eranian Cc: Ingo Molnar , Jiri Olsa , LKML , tonyj@suse.com, nelson.dsouza@intel.com Subject: Re: [RFC][PATCH 4/8] perf/x86: Remove PERF_X86_EVENT_COMMITTED Message-ID: <20190320122346.GE6058@hirez.programming.kicks-ass.net> References: <20190314130113.919278615@infradead.org> <20190314130705.750219024@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Subject: perf/x86: Remove PERF_X86_EVENT_COMMITTED From: Peter Zijlstra Date: Thu Mar 14 12:58:52 CET 2019 The flag PERF_X86_EVENT_COMMITTED is used to find uncommitted events for which to call put_event_constraint() when scheduling fails. These are the newly added events to the list, and must form, per definition, the tail of cpuc->event_list[]. By computing the list index of the last successfull schedule, then iteration can start there and the flag is redundant. There are only 3 callers of x86_schedule_events(), notably: - x86_pmu_add() - x86_pmu_commit_txn() - validate_group() For x86_pmu_add(), cpuc->n_events isn't updated until after schedule_events() succeeds, therefore cpuc->n_events points to the desired index. For x86_pmu_commit_txn(), cpuc->n_events is updated, but we can trivially compute the desired value with cpuc->n_txn -- the number of events added in this transaction. For validate_group(), we can make the rule for x86_pmu_add() work by simply setting cpuc->n_events to 0 before calling schedule_events(). Reviewed-by: Stephane Eranian Signed-off-by: Peter Zijlstra (Intel) --- arch/x86/events/core.c | 28 +++++++++++++--------------- arch/x86/events/perf_event.h | 19 +++++++++---------- 2 files changed, 22 insertions(+), 25 deletions(-) --- a/arch/x86/events/core.c +++ b/arch/x86/events/core.c @@ -925,19 +925,23 @@ int x86_schedule_events(struct cpu_hw_ev if (!unsched && assign) { for (i = 0; i < n; i++) { e = cpuc->event_list[i]; - e->hw.flags |= PERF_X86_EVENT_COMMITTED; if (x86_pmu.commit_scheduling) x86_pmu.commit_scheduling(cpuc, i, assign[i]); } } else { - for (i = 0; i < n; i++) { + /* + * In a transaction cpuc->n_events is already updated, but we + * can use cpuc->n_txn know how many new events there are. + * + * Outside of a transaction, cpuc->n_events is not yet updated, + * and indicates how many events how many events are scheduled. + */ + i = cpuc->n_events; + if (cpuc->txn_flags & PERF_PMU_TXN_ADD) + i -= cpuc->n_txn; + + for (; i < n; i++) { e = cpuc->event_list[i]; - /* - * do not put_constraint() on comitted events, - * because they are good to go - */ - if ((e->hw.flags & PERF_X86_EVENT_COMMITTED)) - continue; /* * release events that failed scheduling @@ -1372,11 +1376,6 @@ static void x86_pmu_del(struct perf_even int i; /* - * event is descheduled - */ - event->hw.flags &= ~PERF_X86_EVENT_COMMITTED; - - /* * If we're called during a txn, we only need to undo x86_pmu.add. * The events never got scheduled and ->cancel_txn will truncate * the event_list. @@ -2079,8 +2078,7 @@ static int validate_group(struct perf_ev if (n < 0) goto out; - fake_cpuc->n_events = n; - + fake_cpuc->n_events = 0; ret = x86_pmu.schedule_events(fake_cpuc, n, NULL); out: --- a/arch/x86/events/perf_event.h +++ b/arch/x86/events/perf_event.h @@ -55,22 +55,21 @@ struct event_constraint { int overlap; int flags; }; + /* * struct hw_perf_event.flags flags */ #define PERF_X86_EVENT_PEBS_LDLAT 0x0001 /* ld+ldlat data address sampling */ #define PERF_X86_EVENT_PEBS_ST 0x0002 /* st data address sampling */ #define PERF_X86_EVENT_PEBS_ST_HSW 0x0004 /* haswell style datala, store */ -#define PERF_X86_EVENT_COMMITTED 0x0008 /* event passed commit_txn */ -#define PERF_X86_EVENT_PEBS_LD_HSW 0x0010 /* haswell style datala, load */ -#define PERF_X86_EVENT_PEBS_NA_HSW 0x0020 /* haswell style datala, unknown */ -#define PERF_X86_EVENT_EXCL 0x0040 /* HT exclusivity on counter */ -#define PERF_X86_EVENT_DYNAMIC 0x0080 /* dynamic alloc'd constraint */ -#define PERF_X86_EVENT_RDPMC_ALLOWED 0x0100 /* grant rdpmc permission */ -#define PERF_X86_EVENT_EXCL_ACCT 0x0200 /* accounted EXCL event */ -#define PERF_X86_EVENT_AUTO_RELOAD 0x0400 /* use PEBS auto-reload */ -#define PERF_X86_EVENT_LARGE_PEBS 0x0800 /* use large PEBS */ - +#define PERF_X86_EVENT_PEBS_LD_HSW 0x0008 /* haswell style datala, load */ +#define PERF_X86_EVENT_PEBS_NA_HSW 0x0010 /* haswell style datala, unknown */ +#define PERF_X86_EVENT_EXCL 0x0020 /* HT exclusivity on counter */ +#define PERF_X86_EVENT_DYNAMIC 0x0040 /* dynamic alloc'd constraint */ +#define PERF_X86_EVENT_RDPMC_ALLOWED 0x0080 /* grant rdpmc permission */ +#define PERF_X86_EVENT_EXCL_ACCT 0x0100 /* accounted EXCL event */ +#define PERF_X86_EVENT_AUTO_RELOAD 0x0200 /* use PEBS auto-reload */ +#define PERF_X86_EVENT_LARGE_PEBS 0x0400 /* use large PEBS */ struct amd_nb { int nb_id; /* NorthBridge id */