Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp2255020rdb; Tue, 3 Oct 2023 15:36:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFFhxo79YY/Kmdj5mAwXwxdULw9HJXX+095MqNtkFxb6QgRmkfhKwQ+YpaddvbjaG3lbdiY X-Received: by 2002:a05:6a20:748e:b0:15e:bf2b:e6c8 with SMTP id p14-20020a056a20748e00b0015ebf2be6c8mr778742pzd.2.1696372617975; Tue, 03 Oct 2023 15:36:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696372617; cv=none; d=google.com; s=arc-20160816; b=d8c4PlinmGahHA9odjjsdKqm71qt1HXOd4FmZ3RSDn4KV0zh8lK+5UsVd17CYTSeX9 b3YGxj07hLjkNNkWNv+eEfQYweZ8ZGeuvsMc3I96oMLxicPMPQHt9BVONVFVpxIX1QQJ Rgz5GPhEGwgNYU7+n0vP/xJnDADFYB+F+bPoceAl2VitWOaRxUUzkx1iUiu+IEd2UPf+ B6mtElKmfYg+Gmq3MkN6EqYtoC0I1v9peiyh38iHbQperZGf/RDbt5LSGij45BXsULJ1 +CX6JnowsQPQEMtONinNXC24IwWKrnvjVN6euitymPZxegpd6OTpbblrg6TUUY1fvMni XyNQ== 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 :dkim-signature; bh=EG7kDtdkJVrJR5n87G+tHxj9vqVqM2ibNV7n3CHBcaM=; fh=bwgLixT0ggMWir7FFWxU5cBy+S9EITMJVBEGWbkg6oE=; b=Eq7NYMJhJ6vjtDZDGEBxt4o13UkjA56NGjrJxhx3VjVbnRQLzSafRltVi+bxH2uS0o pNOcMjV+7cIClZXg5pioprc5BdLWaW2uPUZSpG1YJTsHPIpY7lFxkZuhDpumvR3jK0PV 4nfVHTYtlB84Auzrs0aRIx3LGAaebBCxYpmISu/6GgFM4bRT8kxofnhXEmpuX/itVhGy 7J/yXZGBJLcbNbli4DdAP3VySFjy94YKG8WTi/KYcRJo4E6YHpsY1OcD6Fup3T99trY/ pAeCpucXIFnFEBgyDvznMfouH4M9lXuMGPj67iWqjsCdPtfX2nR3qMba5KQ42ymUZucU rBmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=1Lx9A2j4; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id a24-20020a63cd58000000b005859dcf3c4dsi2468961pgj.92.2023.10.03.15.36.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 15:36:57 -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; dkim=pass header.i=@google.com header.s=20230601 header.b=1Lx9A2j4; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 6EC418048D89; Tue, 3 Oct 2023 15:36:55 -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 S230035AbjJCWgh (ORCPT + 99 others); Tue, 3 Oct 2023 18:36:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229802AbjJCWgg (ORCPT ); Tue, 3 Oct 2023 18:36:36 -0400 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73ABDAF for ; Tue, 3 Oct 2023 15:36:32 -0700 (PDT) Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-50348c54439so1037e87.1 for ; Tue, 03 Oct 2023 15:36:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696372591; x=1696977391; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=EG7kDtdkJVrJR5n87G+tHxj9vqVqM2ibNV7n3CHBcaM=; b=1Lx9A2j4pHQYDICxtXgVq5dUcE3TV44XTOQLdSgauFrBc8ngQOnAAXneU0i61/akv4 qjaThIbGJZxT/PHcclWs3toMOAW5yi1DPXNAgK4uDnCgLKQ+jKMwOu1yfIKShOTAodtM GbHhRjtimkt/CBlcST9V9pj9bOetTNHiFN00RIKbLyyQpRBVUDLGHCP4VM9C2M1rc6Wv kbFP2BQFn+oiQG+WwVfoOfBxPccw1dfpG726AujbZmWpVRyAStaXfbN50akZSsN9MoQa LkuS1CQ3v2aq0KRPtva0psATj2wbuCuIYk1nvVpu+rynygSIr3T9aq3SlYCSAK6Fz5Sv XeDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696372591; x=1696977391; 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=EG7kDtdkJVrJR5n87G+tHxj9vqVqM2ibNV7n3CHBcaM=; b=jDyLlUycriHYXDXb9lz2Or1OWxaRaKeWRjOfHP+fD1X1ugCr7dNOSs1NdtL2rtdKjE eFGFoHBs1EfcMyOa7Bvm+yDvBJJ81xphh8WxcfZx/r+NqMptlJRFH2f3q2mIcIjsfmb6 m8YjrP4+lhgeOgxQ94zlDqHuL4lOd1Os86L9czikz1g62LiPP01lrxadKVnHqvLiZv6B VVfdOleMbe4mIh/wIN2n+hCz9UdvACJ0E+XhTSORklSI3uhZ/gRtQcn05WGmdxgXoOSe vNqsey1edPif0LhTgK3evlBM99oo2q4HqeltBUlXBpMwu+gwdFSIatLAVB+i0CJoPbS0 vczw== X-Gm-Message-State: AOJu0Yz1BsL+JmwwGFVqxhInW5Q8LDNRlQTYGskhx7Ep5p1KEL9GE5QG 2WXtswoOi9N5BshVZLrLr6/xLRCxiD8NodYQkf9vAw== X-Received: by 2002:ac2:4e6f:0:b0:505:715f:d36b with SMTP id y15-20020ac24e6f000000b00505715fd36bmr7786lfs.5.1696372590536; Tue, 03 Oct 2023 15:36:30 -0700 (PDT) MIME-Version: 1.0 References: <20230916040915.1075620-1-irogers@google.com> In-Reply-To: From: Ian Rogers Date: Tue, 3 Oct 2023 15:36:19 -0700 Message-ID: Subject: Re: [PATCH v1] perf evlist: Avoid frequency mode for the dummy event To: Namhyung Kim Cc: Mingwei Zhang , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Adrian Hunter , Kan Liang , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Yang Jihong , Stephane Eranian Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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]); Tue, 03 Oct 2023 15:36:55 -0700 (PDT) On Tue, Oct 3, 2023 at 1:08=E2=80=AFPM Namhyung Kim w= rote: > > Hello, > > On Wed, Sep 20, 2023 at 10:05=E2=80=AFPM Mingwei Zhang wrote: > > > > On Mon, Sep 18, 2023 at 3:43=E2=80=AFPM Ian Rogers = wrote: > > > > > > On Sat, Sep 16, 2023 at 5:46=E2=80=AFPM Mingwei Zhang wrote: > > > > Thank you very much for the change. I have one quick question about > > > > the PMU unthrottling logic. When I am looking into the function > > > > perf_adjust_freq_unthr_context(), I see the loop with PMU stop and > > > > start in each iteration. Is there a good way to avoid this PMU rese= t > > > > operation while quickly figuring out the event in frequency mode? > > > > > > Agreed. I think before the pmu_disable could be avoided for this cond= ition: > > > ``` > > > if (event->hw.interrupts !=3D MAX_INTERRUPTS && > > > (!event->attr.freq || !event->attr.sample_freq)) > > > continue; > > > ``` > > > Fixing up the event stop/start looks harder. > > > > > > > Right, I think putting the check early before pmu_disable() is already > > a great optimization. The only concern I initially had was whether > > event->hw.interrupts can be accessed before we disable the pmu. But > > after checking this field in other locations, I don't see any problem > > at all. > > The event->hw.interrupts would be increased in the NMI handler > so there is a race between the check and the NMI. That's why > I think it checks that after disabling the PMU. > > But I think we can skip non-sampling events for sure. Then it > would be better to set attr.sample_period =3D 0 rather than attr.freq. > > if (!is_sampling_event(event)) > continue; > > perf_pmu_disable(event->pmu); > ... > > Thanks, > Namhyung With the PMU disabled, isn't there still a risk of an interrupt still being in flight? In other words the disable doesn't prevent a race and we'll catch this on the next timer call to perf_adjust_freq_unthr_context. I think we can also improve the code by just disabling a PMU once, we can take advantage of the perf_event_pmu_context and disable that PMU, iterate its events and then re-enable the PMU - i.e. no need for an enable and disable per event. I'll put a patch together. Thanks, Ian