Received: by 2002:a05:7412:40d:b0:e2:908c:2ebd with SMTP id 13csp502496rdf; Tue, 21 Nov 2023 08:18:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IFd4xk0U+ghOlkJLV2YKLA4DLkhqYliSh/QImKl8AF48VnsDGPhL4zR78jnbaGq3spNRt/J X-Received: by 2002:a05:6808:1783:b0:3b2:e27e:ac9d with SMTP id bg3-20020a056808178300b003b2e27eac9dmr13646921oib.50.1700583486683; Tue, 21 Nov 2023 08:18:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700583486; cv=none; d=google.com; s=arc-20160816; b=bkcfFxWbusIZWrJtEAI9h4Y+S9mCeVNQMef8RtMfACsFSN+IzOq1zypf4tIeS0r+r6 DqAS7Xw7dBk/E86hzrMAusla5L30mJrcCh9u0sA7H60PMx/odA562d4n3Em3p8E9PTQq RKwkosAcm6yeXvDYytFCmqosNPc/QaSRGJpfObIifFjLG8k3ACLKb3crAFz6UW7Ow74I RUY0dBHgnPycKyTBIGijVEp0uXBL8YDFLlOCWF/tXsxiCae8ArYv8gaEic/hy/S8D4q2 XzDja3VH58AQevJvvqPnvSIaSDbpAF48wKK8yjVxaYBWBJL/g3ftpNYZnFtZh9e6/J2C nzHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=hTtmuF/PIBDSTXGREUcwyrGCwtAupGD76jBaYP8LBJU=; fh=IPk8TAKCt3+SMZa+xKx+VhLUV46crqtVEfdba4xzsx0=; b=sodxGMju00JJ6vcOn56P8k0jMDWsl3qRsCSmb3liUXMqMj2R4C4mhjcyyuFGahg9q3 qT5s2TlBjeGujNoY6Pd2mXLZNoAvliSLrkukfuYzp6MtoEAdWkA0EtDsoZh3I3LNYcBc TBdS1HtvUARf0BNwf9V1KWt6u+V2q/QW1rJMXTZNG9MlMPtzmg8A7u+fn9qmPCGXQzHV EcFkr9Tf0DYSv/fVxIHPxkniWa0ilDnJXz6GqK2BF9qDINgLWlEOv2EC1e+qM4i/wUgO OCGY3dEUu862YopNONbeqVYFXgeafcYbSpZnNi6hWc1Jopbt4kdoeeC+rLSB4Aux45DC Glhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=eq0EG04J; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id j4-20020a63cf04000000b005bdf59618e3si11112484pgg.497.2023.11.21.08.18.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 08:18:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=eq0EG04J; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 3699A8026DBB; Tue, 21 Nov 2023 08:18:04 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231439AbjKUQRy (ORCPT + 99 others); Tue, 21 Nov 2023 11:17:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230307AbjKUQRw (ORCPT ); Tue, 21 Nov 2023 11:17:52 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5EC3192 for ; Tue, 21 Nov 2023 08:17:48 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 380C5C433C8; Tue, 21 Nov 2023 16:17:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700583468; bh=7cSOHL2IJoGFmC5GmmnLkiU+EjKX6ahpFKVxkXiUgDc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=eq0EG04J1DXAqs3vJIZolU3NEyJeIwWevtTYBz0vO9D8e+gpCDdFKNLg3ZQaXt1dr SUFtUIqUTHZZTvoNwnAQxhZ3OD154gKT5HOL2+WX+CY+0vS02Fax6pvI3xhTUBGLyH Vj7FQ0pLr4NFqUI3iEZANxlliV/pCkMEFWMTWB06xpl9LYw1pxN65HTpuaLtjcfT/g 6IN4DkHuduC10RllAeKNp6uOrKjgrITWq3hcDxVfMQkwU9oympZZtm1EclJMgk+fHB q2xUUmPD/FUH8eOOV3MZ7OioLmdFA7AoRg8HJDqeqDjLwagkiXPCOFeDgQFZ8G5wIS AVP9zbvflfT7w== Date: Tue, 21 Nov 2023 16:17:42 +0000 From: Will Deacon To: Yury Norov Cc: linux-kernel@vger.kernel.org, Mark Rutland , linux-arm-kernel@lists.infradead.org, Jan Kara , Mirsad Todorovac , Matthew Wilcox , Rasmus Villemoes , Andy Shevchenko , Maxim Kuvyrkov , Alexey Klimov Subject: Re: [PATCH 07/34] perf/arm: optimize opencoded atomic find_bit() API Message-ID: <20231121161742.GA2151@willie-the-truck> References: <20231118155105.25678-1-yury.norov@gmail.com> <20231118155105.25678-8-yury.norov@gmail.com> <20231121155344.GB1938@willie-the-truck> 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) X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Tue, 21 Nov 2023 08:18:04 -0800 (PST) On Tue, Nov 21, 2023 at 08:16:13AM -0800, Yury Norov wrote: > On Tue, Nov 21, 2023 at 03:53:44PM +0000, Will Deacon wrote: > > On Sat, Nov 18, 2023 at 07:50:38AM -0800, Yury Norov wrote: > > > Switch subsystem to use atomic find_bit() or atomic iterators as > > > appropriate. > > > > > > Signed-off-by: Yury Norov > > > --- > > > drivers/perf/arm-cci.c | 23 +++++------------------ > > > drivers/perf/arm-ccn.c | 10 ++-------- > > > drivers/perf/arm_dmc620_pmu.c | 9 ++------- > > > drivers/perf/arm_pmuv3.c | 8 ++------ > > > 4 files changed, 11 insertions(+), 39 deletions(-) > > > > > > diff --git a/drivers/perf/arm-cci.c b/drivers/perf/arm-cci.c > > > index 61de861eaf91..70fbf9d09d37 100644 > > > --- a/drivers/perf/arm-cci.c > > > +++ b/drivers/perf/arm-cci.c > > > @@ -320,12 +320,8 @@ static int cci400_get_event_idx(struct cci_pmu *cci_pmu, > > > return CCI400_PMU_CYCLE_CNTR_IDX; > > > } > > > > > > - for (idx = CCI400_PMU_CNTR0_IDX; idx <= CCI_PMU_CNTR_LAST(cci_pmu); ++idx) > > > - if (!test_and_set_bit(idx, hw->used_mask)) > > > - return idx; > > > - > > > - /* No counters available */ > > > - return -EAGAIN; > > > + idx = find_and_set_bit(hw->used_mask, CCI_PMU_CNTR_LAST(cci_pmu) + 1); > > > > CCI400_PMU_CNTR0_IDX is defined as 1, so isn't this wrong? > > You're right. Will fix in v2 > > > [...] > > > > > diff --git a/drivers/perf/arm_dmc620_pmu.c b/drivers/perf/arm_dmc620_pmu.c > > > index 30cea6859574..e41c84dabc3e 100644 > > > --- a/drivers/perf/arm_dmc620_pmu.c > > > +++ b/drivers/perf/arm_dmc620_pmu.c > > > @@ -303,13 +303,8 @@ static int dmc620_get_event_idx(struct perf_event *event) > > > end_idx = DMC620_PMU_MAX_COUNTERS; > > > } > > > > > > - for (idx = start_idx; idx < end_idx; ++idx) { > > > - if (!test_and_set_bit(idx, dmc620_pmu->used_mask)) > > > - return idx; > > > - } > > > - > > > - /* The counters are all in use. */ > > > - return -EAGAIN; > > > + idx = find_and_set_next_bit(dmc620_pmu->used_mask, end_idx, start_idx); > > > > It might just be me, but I'd find this a tonne easier to read if you swapped > > the last two arguments around so that the offset came before the limit in > > the new function. > > I personally agree, but we already have find_next_*_bit(addr, nbits, offset) > functions, and having atomic versions of the same with different order > of arguments will make it even more messy... Urgh, and there's loads of them too :( Will