Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp443615rwe; Thu, 1 Sep 2022 02:05:39 -0700 (PDT) X-Google-Smtp-Source: AA6agR4K+sbnn+8puNuaXrhPg34Qx+AB2IVU0lsOVGoQ4/wNoMDj2y+DDd4SdVxezxUtdg1XHX/6 X-Received: by 2002:a17:90a:4fe3:b0:1fd:b6f7:f5e3 with SMTP id q90-20020a17090a4fe300b001fdb6f7f5e3mr7604324pjh.169.1662023138999; Thu, 01 Sep 2022 02:05:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662023138; cv=none; d=google.com; s=arc-20160816; b=V94JkSEA2XrSV/hQ/AslxJX3jJ+I6Uj5ZHsHAUBxC0jw/VyvXaAF3hwa8UgDJXdSfl VfB7N2DmOG+iRrfq4DvuRVhdsVpXrzlZ+QojC04HhImu9uc1Vy6KQ6FE/PURg/oIacCi CZkV9v/bzS13uvoR+6nPiG12EYUjmqsv4Wqg9yxqFrThqWBcXvzRy5G5cif5UqpYBs1h nblh58tNkta+Qf1RhvgQwIeufBcUmmnH++0YMI4DVlH/YInVU8nSpFUM0Fyh6Ik4nHWY 41nPyEbeuOKLVWIHe4p46tZodRRT5qkVgWg5oBIZudXfhifGD7wjYx0Nwq9VYEShsiDV GP+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=1UFSJOyVKjNHHGUv9Qm+HPhrOiBuH5OGF6uz/mfXBcE=; b=lJ70Zf/aAP9rujZ5IAI01MqEGNszAjHUMT7nhwBvBCWIV3r9Gy7PDvKpzRCBhCRIC4 YnAjHMwZ5r4xBQJfSVg9mFBNtt0iTWRHzhdXN+bS3r8QWO4ynXtaPcATwnFTOTnE9udx yR3uWUh8n45M9eDrDlvZMq/VV+jdfABE91mZYkr4EeWKhnR/3829NQfCy2cicTBDIv41 RTAl1ETVG3tTfIGpJxxZbJQElecs9y0HG30NLSlsP+JVVcuTArafo/sCc4Gc8TM4tTZL Y+LNXa8qdo+YFlnSKH6CCa8OR7AWhD2aMxADAxN+pv+9pp9gdOILecbnjoD1YqmLURnH n4AQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=LOoO2+nT; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i7-20020a639d07000000b0042b1451d39asi7538366pgd.37.2022.09.01.02.05.20; Thu, 01 Sep 2022 02:05:38 -0700 (PDT) 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=@linutronix.de header.s=2020 header.b=LOoO2+nT; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234082AbiIAINU (ORCPT + 99 others); Thu, 1 Sep 2022 04:13:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233875AbiIAIMu (ORCPT ); Thu, 1 Sep 2022 04:12:50 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8FAF012BF63; Thu, 1 Sep 2022 01:12:48 -0700 (PDT) Date: Thu, 01 Sep 2022 08:12:45 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1662019967; h=from:from:sender:sender:reply-to: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=1UFSJOyVKjNHHGUv9Qm+HPhrOiBuH5OGF6uz/mfXBcE=; b=LOoO2+nTpQGNWMNlhr/7SLoOd7hXD2zS2Tg7Webd0k6wF7qZLf2V5LIX6g3JVN0iA998nK 73vito8fbEJQckGnnwlRM7+kd1m9+zbjMjbn4flfmRJkWU9wexRqP8PDdXxmZ3dWisjNfA s14t3BOfmVABOmJc6vhVibXzvpZUnXsRqaw2iMLkUHCbA472EikZi7bL7ClpU5uuz04lx8 ZIFQAfkuQDMXAUZsoDaezXWGz9fQ+/x4j3oIlyy/pZmIFZJGzxYBYN5yqaxYYMDBp1NfcE 5plIbaBYV9VY7VMzOLI78VwGsXyii2W6L8WtQRPRL5AwEL7ACY9BtEBiwMcyjw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1662019967; h=from:from:sender:sender:reply-to: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=1UFSJOyVKjNHHGUv9Qm+HPhrOiBuH5OGF6uz/mfXBcE=; b=DzQ1tUfEnwt+wALGeFzLfsyyZ0LV6d9IN+WJ6ptL4eMqej5B2f1iWDsIZsLWa0eHxcmjRN oPVTMa3AmXN79LDA== From: "tip-bot2 for Marco Elver" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: perf/core] perf/hw_breakpoint: Remove useless code related to flexible breakpoints Cc: Marco Elver , "Peter Zijlstra (Intel)" , Dmitry Vyukov , Ian Rogers , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20220829124719.675715-9-elver@google.com> References: <20220829124719.675715-9-elver@google.com> MIME-Version: 1.0 Message-ID: <166201996577.401.1852531279033258686.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the perf/core branch of tip: Commit-ID: 24198ad373ad1e30b638aa147142dc21ab5757e7 Gitweb: https://git.kernel.org/tip/24198ad373ad1e30b638aa147142dc21ab5757e7 Author: Marco Elver AuthorDate: Mon, 29 Aug 2022 14:47:13 +02:00 Committer: Peter Zijlstra CommitterDate: Tue, 30 Aug 2022 10:56:22 +02:00 perf/hw_breakpoint: Remove useless code related to flexible breakpoints Flexible breakpoints have never been implemented, with bp_cpuinfo::flexible always being 0. Unfortunately, they still occupy 4 bytes in each bp_cpuinfo and bp_busy_slots, as well as computing the max flexible count in fetch_bp_busy_slots(). This again causes suboptimal code generation, when we always know that `!!slots.flexible` will be 0. Just get rid of the flexible "placeholder" and remove all real code related to it. Make a note in the comment related to the constraints algorithm but don't remove them from the algorithm, so that if in future flexible breakpoints need supporting, it should be trivial to revive them (along with reverting this change). Signed-off-by: Marco Elver Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Dmitry Vyukov Acked-by: Ian Rogers Link: https://lore.kernel.org/r/20220829124719.675715-9-elver@google.com --- kernel/events/hw_breakpoint.c | 57 ++++++++++------------------------ 1 file changed, 17 insertions(+), 40 deletions(-) diff --git a/kernel/events/hw_breakpoint.c b/kernel/events/hw_breakpoint.c index 9c9bf17..8b40fca 100644 --- a/kernel/events/hw_breakpoint.c +++ b/kernel/events/hw_breakpoint.c @@ -45,8 +45,6 @@ struct bp_cpuinfo { #else unsigned int *tsk_pinned; #endif - /* Number of non-pinned cpu/task breakpoints in a cpu */ - unsigned int flexible; /* XXX: placeholder, see fetch_this_slot() */ }; static DEFINE_PER_CPU(struct bp_cpuinfo, bp_cpuinfo[TYPE_MAX]); @@ -67,12 +65,6 @@ static const struct rhashtable_params task_bps_ht_params = { static bool constraints_initialized __ro_after_init; -/* Gather the number of total pinned and un-pinned bp in a cpuset */ -struct bp_busy_slots { - unsigned int pinned; - unsigned int flexible; -}; - /* Serialize accesses to the above constraints */ static DEFINE_MUTEX(nr_bp_mutex); @@ -190,14 +182,14 @@ static const struct cpumask *cpumask_of_bp(struct perf_event *bp) } /* - * Report the number of pinned/un-pinned breakpoints we have in - * a given cpu (cpu > -1) or in all of them (cpu = -1). + * Returns the max pinned breakpoint slots in a given + * CPU (cpu > -1) or across all of them (cpu = -1). */ -static void -fetch_bp_busy_slots(struct bp_busy_slots *slots, struct perf_event *bp, - enum bp_type_idx type) +static int +max_bp_pinned_slots(struct perf_event *bp, enum bp_type_idx type) { const struct cpumask *cpumask = cpumask_of_bp(bp); + int pinned_slots = 0; int cpu; for_each_cpu(cpu, cpumask) { @@ -210,24 +202,10 @@ fetch_bp_busy_slots(struct bp_busy_slots *slots, struct perf_event *bp, else nr += task_bp_pinned(cpu, bp, type); - if (nr > slots->pinned) - slots->pinned = nr; - - nr = info->flexible; - if (nr > slots->flexible) - slots->flexible = nr; + pinned_slots = max(nr, pinned_slots); } -} -/* - * For now, continue to consider flexible as pinned, until we can - * ensure no flexible event can ever be scheduled before a pinned event - * in a same cpu. - */ -static void -fetch_this_slot(struct bp_busy_slots *slots, int weight) -{ - slots->pinned += weight; + return pinned_slots; } /* @@ -298,7 +276,12 @@ __weak void arch_unregister_hw_breakpoint(struct perf_event *bp) } /* - * Constraints to check before allowing this new breakpoint counter: + * Constraints to check before allowing this new breakpoint counter. + * + * Note: Flexible breakpoints are currently unimplemented, but outlined in the + * below algorithm for completeness. The implementation treats flexible as + * pinned due to no guarantee that we currently always schedule flexible events + * before a pinned event in a same CPU. * * == Non-pinned counter == (Considered as pinned for now) * @@ -340,8 +323,8 @@ __weak void arch_unregister_hw_breakpoint(struct perf_event *bp) */ static int __reserve_bp_slot(struct perf_event *bp, u64 bp_type) { - struct bp_busy_slots slots = {0}; enum bp_type_idx type; + int max_pinned_slots; int weight; int ret; @@ -357,15 +340,9 @@ static int __reserve_bp_slot(struct perf_event *bp, u64 bp_type) type = find_slot_idx(bp_type); weight = hw_breakpoint_weight(bp); - fetch_bp_busy_slots(&slots, bp, type); - /* - * Simulate the addition of this breakpoint to the constraints - * and see the result. - */ - fetch_this_slot(&slots, weight); - - /* Flexible counters need to keep at least one slot */ - if (slots.pinned + (!!slots.flexible) > hw_breakpoint_slots_cached(type)) + /* Check if this new breakpoint can be satisfied across all CPUs. */ + max_pinned_slots = max_bp_pinned_slots(bp, type) + weight; + if (max_pinned_slots > hw_breakpoint_slots_cached(type)) return -ENOSPC; ret = arch_reserve_bp_slot(bp);