Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp3823241imc; Thu, 14 Mar 2019 06:12:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqx0zuOXWo2n+WDBY2XQJe7b0XMsmREpq49Xom4ujaWeWSaRFXdKY+wJIND4U6csV3jo6Cnw X-Received: by 2002:aa7:83cb:: with SMTP id j11mr36613906pfn.117.1552569174294; Thu, 14 Mar 2019 06:12:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552569174; cv=none; d=google.com; s=arc-20160816; b=QmUdR9/2CwAKT2Q6QiaRehE9ULEbSTNR+tjSyQOJQHW5sgbo3ou+ELkw0n3gCHsKL7 rh/ycvSUf/fNZOxE8DFsOcH0oMo4zS/vpczMMcO6ut69HA9TuSnasjxLrgDLssk28y0l jMwwfv7a6hpceJhlRgD20VrrePaLISw24HkgY1qfF0RrBy0++viCrscBcK3VeQvHkv0j 5RU5htIgWUebUaf02YjoOFfwVW5qjuaM00pkcMf/AfWP6u1HokB0NrVaWbMJ+L+WVTXa E/usxUShRS/hTY8/LO8rhakjOEfJDtQSgD2p8kqBc50qGjhQtGhaYwSQtX3GCUgzeLJl l+1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:subject:cc:to :from:date:user-agent:message-id:dkim-signature; bh=UYG49NhyVu7cNtNRCL20P1Z39GZ6lT/pWSkNg1mi8D4=; b=TofAfnfOaVl1KTBTYIDW9Uq7W3ZD/piZpllxHn3rik/9vK9WnN/B0QvkKRAst0eB1R RA7sKIbPWy50/+BqGPiHrO10SlCNtvfCjIobODTKd1lmYZgSQlBlDxZXiiu5fw+bg5tf NoQ3ITOqZjRCl6fiiMA1+ML990LAngc1dqAEvHe7P0NHFb8n+5WtryO6qyujHDl6mJvN lhqyDQKCKdKVThES156o74+lkdAzaTPKSRG2wFxd76fMXPAjOBGulRoSAQBR37jt43Zz /xgZUWDgx0gDwQJfowsN2y3KyZ9vMnZbjHLAl4ABcYc1Vi3gM3GLVVJYeUfrguDP7mUM lLgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=Kvmziy7z; 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 h5si12478006pgv.48.2019.03.14.06.12.39; Thu, 14 Mar 2019 06:12:54 -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=merlin.20170209 header.b=Kvmziy7z; 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 S1727574AbfCNNLu (ORCPT + 99 others); Thu, 14 Mar 2019 09:11:50 -0400 Received: from merlin.infradead.org ([205.233.59.134]:59866 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727497AbfCNNLn (ORCPT ); Thu, 14 Mar 2019 09:11:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-Id:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=UYG49NhyVu7cNtNRCL20P1Z39GZ6lT/pWSkNg1mi8D4=; b=Kvmziy7zhGNL8F91u4nj8sobuf kf5QEQvma4Pb8+umK5xp/TY3iVqo3MtDY7xXv3UQ0USSMjIcEYvomvSW67zrgosSuU75/0TQeVu7e ONiV10iqmQVUlKLRxTxV4qnSYkucSWjuPLqF8C8i8iFI1eUY2WWIRPQB6+l8lT6AeYOeBYJM9Gjbn jYPIvBOMOoA7w8nF77hMdf/Zv0VNxNaZhWbxwGvlYuGSIKtAS0wNIEi+sAhGWhkciNQ4BR+wdazGQ PDPN7Ts2fmGbN1sran/sNtvXXCIA1wRyQWw1Hlzx2ZZ2HB+75YIHDtPxAg5NOneVXfboklBb5PcUE qjqGPdSA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1h4Q8w-0005RX-6R; Thu, 14 Mar 2019 13:11:30 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id 5A57D203C774E; Thu, 14 Mar 2019 14:11:27 +0100 (CET) Message-Id: <20190314130705.852659665@infradead.org> User-Agent: quilt/0.65 Date: Thu, 14 Mar 2019 14:01:18 +0100 From: Peter Zijlstra To: mingo@kernel.org, eranian@google.com, jolsa@redhat.com Cc: linux-kernel@vger.kernel.org, tonyj@suse.com, nelson.dsouza@intel.com, peterz@infradead.org Subject: [RFC][PATCH 5/8] perf/x86/intel: Optimize intel_get_excl_constraints() References: <20190314130113.919278615@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Avoid the POPCNT by noting we can decrement the weight for each cleared bit. Signed-off-by: Peter Zijlstra (Intel) --- arch/x86/events/intel/core.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) --- a/arch/x86/events/intel/core.c +++ b/arch/x86/events/intel/core.c @@ -2838,7 +2838,7 @@ intel_get_excl_constraints(struct cpu_hw struct intel_excl_cntrs *excl_cntrs = cpuc->excl_cntrs; struct intel_excl_states *xlo; int tid = cpuc->excl_thread_id; - int is_excl, i; + int is_excl, i, w; /* * validating a group does not require @@ -2894,36 +2894,40 @@ intel_get_excl_constraints(struct cpu_hw * SHARED : sibling counter measuring non-exclusive event * UNUSED : sibling counter unused */ + w = c->weight; for_each_set_bit(i, c->idxmsk, X86_PMC_IDX_MAX) { /* * exclusive event in sibling counter * our corresponding counter cannot be used * regardless of our event */ - if (xlo->state[i] == INTEL_EXCL_EXCLUSIVE) + if (xlo->state[i] == INTEL_EXCL_EXCLUSIVE) { __clear_bit(i, c->idxmsk); + w--; + continue; + } /* * if measuring an exclusive event, sibling * measuring non-exclusive, then counter cannot * be used */ - if (is_excl && xlo->state[i] == INTEL_EXCL_SHARED) + if (is_excl && xlo->state[i] == INTEL_EXCL_SHARED) { __clear_bit(i, c->idxmsk); + w--; + continue; + } } /* - * recompute actual bit weight for scheduling algorithm - */ - c->weight = hweight64(c->idxmsk64); - - /* * if we return an empty mask, then switch * back to static empty constraint to avoid * the cost of freeing later on */ - if (c->weight == 0) + if (!w) c = &emptyconstraint; + c->weight = w; + return c; }