Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp843784rdf; Fri, 3 Nov 2023 18:15:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHEGNS/H9UPUYsxDms5XcxXgUhw2fPPIx1A3WXGSr6NqYCXYuWCFn3hL1ALPk9ooo5NaAFN X-Received: by 2002:a05:6a20:9187:b0:17a:f0e0:ed07 with SMTP id v7-20020a056a20918700b0017af0e0ed07mr27969117pzd.15.1699060510020; Fri, 03 Nov 2023 18:15:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1699060510; cv=none; d=google.com; s=arc-20160816; b=mdo+Y0EtKsQQAct6nAkvpMQw3y5tqR8URSma0++lcsiHXNtC3ywl+EdVbP/cVR7i5b JmMfeUpTCDzVzKISyY7q8F6Oyrfp2zbyS+3MHZIiDISpy9AvlOk80ayfKAmDPBFFM00o UbfDdQWru/5PYRnEHn0XWNSM9ziocGqPJ9lCFSUZvfZDQlP1MC6IBDKpMclH3/CFnPSG pC8dWFfcNPqHEBHW3t9fS7gKK8JLuSLuD7l7RZGfIZ4sJhlmtv38+y4QgHs0AT03f3mn 7HpWC7C2ISNVa+HjRZ+rbz+Klg4wCXilmlIyqD4uwJHUMfSRHWd9Gc5L3TKagrMvK7wO AZKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=7WVniVQ1kUcA8k566lIh3+geujoKOq2gAZMKfx2LqEs=; fh=L3MtDd4ISad/HgQmVZIkOhBnis0KoQzTdbWBNYLIjF0=; b=eTbW65S5jTcuP3UqRQCWvDX5wKtUtZ2avIsYy9hah8GQXqx55w4KMi058oyEQo+94a RFowmvSnMjR+jyOelql0wA2Pm/QywSnOOd1H5BV2HuC8uWzQ7H375ZFqHmo3/shc3qgc 8NdmtcjvhPlrb5lgFSnKAh+FwqNywuDgaU6pqaeL/QaA5FiOIy1bTL0qMxkWAteTvoru 37ARTXvdvy7dH8aaa+85l5713Kc2PPqQBZvwS0hrm2GqeVv3ywbVY3EUYatC0F/s+6JU kpVBWJcGVEGVix1aSk3pN592VDajK7p4z5QdPAZ0GouRlKgIRmza9Q/wpiazHAEEhGsw jsGg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id bw22-20020a056a02049600b005702257f32esi2884226pgb.185.2023.11.03.18.15.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 18:15:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (Postfix) with ESMTP id 765E0826FAA5; Fri, 3 Nov 2023 18:15:02 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231191AbjKDBOs convert rfc822-to-8bit (ORCPT + 99 others); Fri, 3 Nov 2023 21:14:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229557AbjKDBOq (ORCPT ); Fri, 3 Nov 2023 21:14:46 -0400 Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82EF4D54 for ; Fri, 3 Nov 2023 18:14:44 -0700 (PDT) Received: by mail-pj1-f50.google.com with SMTP id 98e67ed59e1d1-2802e5ae23bso2529700a91.2 for ; Fri, 03 Nov 2023 18:14:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699060484; x=1699665284; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iQTY7jB2XuDR5VNadrU1LVQTS48IqrRjbSad0fqLF/A=; b=tAXn6DBXtvt+6a+61JRQQbWXHXjAuUo++vG0JwGdent4+DLa1IDNKGl1lGywft5dx0 Xos3FXuDSIgDVk591DgBZNFh/NcGVfVKrmM3y/VY51Grg9ODfWZ2S7+7WtM6Ylq0KD2/ 3ukBOEnvnaBnmxkHlq2D23Jn7Upr/rnGIxIRzqxp+SMFUmLsOHzXKpaTurhKwaG3hh3O t1Hk+DfcEv2jKdOGokMKivfMRRwSlvr9vCL6O57Tg0fYxY2U4BmRE+aShIl1IXMfochZ qQPkYudlOlLKgEQcBSbwFi4FIo7aCAl7a4Z7VAiAzng7GaPnTOCfoSA/MIOZVV32zMS0 KOww== X-Gm-Message-State: AOJu0YxPdpX5wjdi/SACWoVhiTD/C5Zw8YLJ+SWc8slnDmqTOaBjJ9BC kI/Nfue2M1AAMfORmb0pjQvFRz+N7CwdaZlWhLk= X-Received: by 2002:a17:90b:4004:b0:280:94e8:99f4 with SMTP id ie4-20020a17090b400400b0028094e899f4mr13095321pjb.46.1699060483860; Fri, 03 Nov 2023 18:14:43 -0700 (PDT) MIME-Version: 1.0 References: <20231102150919.719936610@infradead.org> <20231102152018.986157891@infradead.org> In-Reply-To: <20231102152018.986157891@infradead.org> From: Namhyung Kim Date: Fri, 3 Nov 2023 18:14:32 -0700 Message-ID: Subject: Re: [PATCH 11/13] perf: Simplify perf_adjust_freq_unthr_context() To: Peter Zijlstra Cc: mingo@kernel.org, linux-kernel@vger.kernel.org, acme@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.0 required=5.0 tests=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 groat.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 (groat.vger.email [0.0.0.0]); Fri, 03 Nov 2023 18:15:02 -0700 (PDT) On Thu, Nov 2, 2023 at 8:32 AM Peter Zijlstra wrote: > > > Signed-off-by: Peter Zijlstra (Intel) > --- > kernel/events/core.c | 51 +++++++++++++++++++++++---------------------------- > 1 file changed, 23 insertions(+), 28 deletions(-) > > --- a/kernel/events/core.c > +++ b/kernel/events/core.c > @@ -4090,7 +4090,7 @@ perf_adjust_freq_unthr_context(struct pe > if (!(ctx->nr_freq || unthrottle)) > return; > > - raw_spin_lock(&ctx->lock); > + guard(raw_spinlock)(&ctx->lock); > > list_for_each_entry_rcu(event, &ctx->event_list, event_entry) { > if (event->state != PERF_EVENT_STATE_ACTIVE) > @@ -4100,7 +4100,7 @@ perf_adjust_freq_unthr_context(struct pe > if (!event_filter_match(event)) > continue; > > - perf_pmu_disable(event->pmu); > + guard(perf_pmu_disable)(event->pmu); > > hwc = &event->hw; > > @@ -4110,34 +4110,29 @@ perf_adjust_freq_unthr_context(struct pe > event->pmu->start(event, 0); > } > > - if (!event->attr.freq || !event->attr.sample_freq) > - goto next; > + if (event->attr.freq && event->attr.sample_freq) { Any reason for this change? I think we can just change the 'goto next' to 'continue', no? Also I think this code needs changes to optimize the access. A similar reason for the cgroup switch, it accesses all the pmu/events in the context even before checking the sampling frequency. This is bad for uncore PMUs (and KVM too). But this is a different issue.. Thanks, Namhyung > + /* > + * stop the event and update event->count > + */ > + event->pmu->stop(event, PERF_EF_UPDATE); > + > + now = local64_read(&event->count); > + delta = now - hwc->freq_count_stamp; > + hwc->freq_count_stamp = now; > + > + /* > + * restart the event > + * reload only if value has changed > + * we have stopped the event so tell that > + * to perf_adjust_period() to avoid stopping it > + * twice. > + */ > + if (delta > 0) > + perf_adjust_period(event, period, delta, false); > > - /* > - * stop the event and update event->count > - */ > - event->pmu->stop(event, PERF_EF_UPDATE); > - > - now = local64_read(&event->count); > - delta = now - hwc->freq_count_stamp; > - hwc->freq_count_stamp = now; > - > - /* > - * restart the event > - * reload only if value has changed > - * we have stopped the event so tell that > - * to perf_adjust_period() to avoid stopping it > - * twice. > - */ > - if (delta > 0) > - perf_adjust_period(event, period, delta, false); > - > - event->pmu->start(event, delta > 0 ? PERF_EF_RELOAD : 0); > - next: > - perf_pmu_enable(event->pmu); > + event->pmu->start(event, delta > 0 ? PERF_EF_RELOAD : 0); > + } > } > - > - raw_spin_unlock(&ctx->lock); > } > > /* > >