From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0C6D8C43334 for ; Tue, 28 Jun 2022 13:19:45 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4LXQDb42PYz3cjM for ; Tue, 28 Jun 2022 23:19:43 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20210112 header.b=R8forfur; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=google.com (client-ip=2a00:1450:4864:20::236; helo=mail-lj1-x236.google.com; envelope-from=dvyukov@google.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20210112 header.b=R8forfur; dkim-atps=neutral Received: from mail-lj1-x236.google.com (mail-lj1-x236.google.com [IPv6:2a00:1450:4864:20::236]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4LXQCt0RXhz304r for ; Tue, 28 Jun 2022 23:19:05 +1000 (AEST) Received: by mail-lj1-x236.google.com with SMTP id q9so14896567ljp.4 for ; Tue, 28 Jun 2022 06:19:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=7CgIFPap6ypTTXSUzce/TyUpcucDj1PHP0T/IiacRoQ=; b=R8forfurDLJ8yEQgrK1Gb8Cki0g4DIuH6+lLE3aUUOOdS/aY/oXjNGR0fzVW9mLNjJ XcfLSibgmOBtdLOH/eN5bD1zWDVQq34FCmc7r1gYS6vGTTQG9EgADIrv3nOm2BaiYJvR 1W4prJNUBjLUZB5Jvrt9DFKOmCKZ+U+0oDN9cagMPv4KmjvX1HmYR7w5byLWFnfBhiYV poW6VnkixBeyNVgz2/5UVaxhnaCjkNhgB/9+oChXvfat6z6Pvp6lL1+NW5ikOzf6URfN JRluS+dz6OmwTzJZN9K49xuyyV9loFwNp4XGsGbnrHsUkR8kDLo8TWrzjaNOxdIRj2RT HJHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=7CgIFPap6ypTTXSUzce/TyUpcucDj1PHP0T/IiacRoQ=; b=XQLha5HxkTUY5OGU45e5r161YgAElCIm9o5sARpAPjXHInpIGyAORLGXBiyl6EtwUr cRiDPT71XwV00RTX9H6iE5YrZKAksqJUlOtfaxkZ0Z+bHQLOa8DpJNzlJsQ9YS3aum+l hJsso5neOECNMDsmU7ZL4K5gGXLs6YVa2W84jkiTIcQrlyn7iwPlYcaUD/PQJNwtBRr8 lFzkmacY+jFiIn5CslDEWNSYDK5hMWMybEnMu/rDKHRHIrtFi3u6ExgnoaWwtuafiGDv IdMN1NUOhL2bYeEqncdqzeZmApvmU+bYY+ILMTEEjhB8/OnJhOgoDoWU5jy9pdOELkWk LvbA== X-Gm-Message-State: AJIora//w0u2lOM07kRvYlvtggJhfm4ZGBj6QrlIvuCdKHjDKHTbp8mn y9Ys5WMOSaoHsIofYgQo35yYr28UsW1QZG3ziYUsAg== X-Google-Smtp-Source: AGRyM1toA86paItas3f13uK/yq9WZLgGB0nO/w6rvEGOTkkNC1CL8Nyv0K6R1K9zXSkuslE6c4fhWr9A82lz4OkaLP4= X-Received: by 2002:a2e:9004:0:b0:25a:6dee:4ae2 with SMTP id h4-20020a2e9004000000b0025a6dee4ae2mr9881452ljg.33.1656422341451; Tue, 28 Jun 2022 06:19:01 -0700 (PDT) MIME-Version: 1.0 References: <20220628095833.2579903-1-elver@google.com> <20220628095833.2579903-8-elver@google.com> In-Reply-To: <20220628095833.2579903-8-elver@google.com> From: Dmitry Vyukov Date: Tue, 28 Jun 2022 15:18:49 +0200 Message-ID: Subject: Re: [PATCH v2 07/13] perf/hw_breakpoint: Remove useless code related to flexible breakpoints To: Marco Elver Content-Type: text/plain; charset="UTF-8" X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , linux-sh@vger.kernel.org, Peter Zijlstra , Frederic Weisbecker , x86@kernel.org, linuxppc-dev@lists.ozlabs.org, Arnaldo Carvalho de Melo , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Alexander Shishkin , kasan-dev@googlegroups.com, Namhyung Kim , Thomas Gleixner , Jiri Olsa , Ingo Molnar Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" On Tue, 28 Jun 2022 at 11:59, Marco Elver wrote: > > 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 Reviewed-by: Dmitry Vyukov > --- > v2: > * Also remove struct bp_busy_slots, and simplify functions. > --- > 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 a124786e3ade..63e39dc836bd 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); > -- > 2.37.0.rc0.161.g10f37bed90-goog > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AB71DC433EF for ; Tue, 28 Jun 2022 13:21:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346464AbiF1NVP (ORCPT ); Tue, 28 Jun 2022 09:21:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346314AbiF1NVA (ORCPT ); Tue, 28 Jun 2022 09:21:00 -0400 Received: from mail-lj1-x233.google.com (mail-lj1-x233.google.com [IPv6:2a00:1450:4864:20::233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4E2D3585C for ; Tue, 28 Jun 2022 06:19:03 -0700 (PDT) Received: by mail-lj1-x233.google.com with SMTP id b23so14858004ljh.7 for ; Tue, 28 Jun 2022 06:19:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=7CgIFPap6ypTTXSUzce/TyUpcucDj1PHP0T/IiacRoQ=; b=R8forfurDLJ8yEQgrK1Gb8Cki0g4DIuH6+lLE3aUUOOdS/aY/oXjNGR0fzVW9mLNjJ XcfLSibgmOBtdLOH/eN5bD1zWDVQq34FCmc7r1gYS6vGTTQG9EgADIrv3nOm2BaiYJvR 1W4prJNUBjLUZB5Jvrt9DFKOmCKZ+U+0oDN9cagMPv4KmjvX1HmYR7w5byLWFnfBhiYV poW6VnkixBeyNVgz2/5UVaxhnaCjkNhgB/9+oChXvfat6z6Pvp6lL1+NW5ikOzf6URfN JRluS+dz6OmwTzJZN9K49xuyyV9loFwNp4XGsGbnrHsUkR8kDLo8TWrzjaNOxdIRj2RT HJHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=7CgIFPap6ypTTXSUzce/TyUpcucDj1PHP0T/IiacRoQ=; b=0WojTn2Ehl4yfL+Vjn1j96DBC84FguNmxltuoKd3qI6FZaKGPOR2RrAXe2YnpOT9kP D7Vj/ur4zgYJ4wmvUn22X/TcvlUhonn51EzsxiLZTLuk9R23cvuDbOzvZNd92ZxJ2mIs F8Rmxn749YK7srBGAUXQ4C2is/RDgwhxvcq5A+sBAFFz60WnWDap5/Uzlnjca2Xqgwx2 AXX0dPEDvxW4k3uOflZt6so+Bd12JSvAP1otSVhVw+j+eitd9cUjN4JzQwQocbt4mbpy IhJpJcMfjxZW5qVWAnP8QG6dwfejcTT5Oz1HOErTEYHil9+UN7jvkWpNulhiWdCVxlF2 ajrA== X-Gm-Message-State: AJIora+m7T4N6vFJMGsEVIUbLeu3H3/szu0PzagPmAO5YwxlOeUldOx9 6Yvy/dBY1pnE28sNNPkuRuhLQaE89QiRCmfxkfF9Xg== X-Google-Smtp-Source: AGRyM1toA86paItas3f13uK/yq9WZLgGB0nO/w6rvEGOTkkNC1CL8Nyv0K6R1K9zXSkuslE6c4fhWr9A82lz4OkaLP4= X-Received: by 2002:a2e:9004:0:b0:25a:6dee:4ae2 with SMTP id h4-20020a2e9004000000b0025a6dee4ae2mr9881452ljg.33.1656422341451; Tue, 28 Jun 2022 06:19:01 -0700 (PDT) MIME-Version: 1.0 References: <20220628095833.2579903-1-elver@google.com> <20220628095833.2579903-8-elver@google.com> In-Reply-To: <20220628095833.2579903-8-elver@google.com> From: Dmitry Vyukov Date: Tue, 28 Jun 2022 15:18:49 +0200 Message-ID: Subject: Re: [PATCH v2 07/13] perf/hw_breakpoint: Remove useless code related to flexible breakpoints To: Marco Elver Cc: Peter Zijlstra , Frederic Weisbecker , Ingo Molnar , Thomas Gleixner , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Michael Ellerman , linuxppc-dev@lists.ozlabs.org, linux-perf-users@vger.kernel.org, x86@kernel.org, linux-sh@vger.kernel.org, kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org On Tue, 28 Jun 2022 at 11:59, Marco Elver wrote: > > 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 Reviewed-by: Dmitry Vyukov > --- > v2: > * Also remove struct bp_busy_slots, and simplify functions. > --- > 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 a124786e3ade..63e39dc836bd 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); > -- > 2.37.0.rc0.161.g10f37bed90-goog >