Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp2264100rdb; Tue, 3 Oct 2023 16:02:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE34br/RfbsCImXbwt3PIvZLi3g7WXMxUyQ8XdWZUFt/2ahiRc8c+f0OmXRTxO0Kj31FsE4 X-Received: by 2002:a05:6e02:1c08:b0:34d:e998:fb4f with SMTP id l8-20020a056e021c0800b0034de998fb4fmr983657ilh.10.1696374162485; Tue, 03 Oct 2023 16:02:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696374162; cv=none; d=google.com; s=arc-20160816; b=E7zwJvxGRGtZRokGnCCyg94t4+t/wA83NhrmXWWBpY0wwJT8GjKrlerzFQZQgXVtwO 5lmV4TjFEbJEJyFwz4oE2xB7JBeiOOvNrp5IDS11QdJ3TpevZ4hypeivSR0uYramtgGx 4Z1g2mGH6XzRNOSV+qkQ1Yi63LdOQfZ9VnRBkjSIL/rSiSbnQZIclqtxvZEFJU6Bxf21 w5kEIYsjaCXRZq4onv28QD+h8qoY2nGtFWC4ci3P27JKd1TQbRg8YQ2ju8+CC3GSZzX9 aui6GCk3TFif7RcRS5MCN9BSqUIA/kLIB8M5j0tB9MB+NrmGFMCDBHr+Ja+4yPJ5ap6B YWTw== 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=ZM22tBJ2nZaGweH4N5lXsdrErHNT1gYwL5tFe+R39kM=; fh=q669Xh6e/iyt+qSnnlb/nJ3bw/Q/nAzz62QhTktQbpo=; b=gTY46HJn7mK1RTknOEtdEJhPfOMosfhlO1janAoaK7R0QA/DySEpUjb7RePEnkZ13N Qqla9CLi0sSINJEcGzUuu+G/OCYutYIOflvVQKCDP5HTOAbbIC9BT0X+fZzuP6VYBBgt ZKjqdTH//NB++HGLRlA2h9P+WB+BEh7J+XiE//sBIJN+uiEBZ8HAahps5MRso+OfvZvX BSBu8cRZcosSscOIEiEwc1kdzCZ/E5k4OGsVzAgCPLvldVkxmMwmqw0MOtf4wnZdbeWb zX+bMIHQf/BoU9qrSH/qdI12w2mlDdtJRhOtGyfuO4U80TlAVD2hDHvjnoSVa6t+zFSu P/jg== 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: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 w190-20020a6382c7000000b00573fbbb7803si2316417pgd.613.2023.10.03.16.02.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:02:42 -0700 (PDT) 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; 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 BB8B680CC14B; Tue, 3 Oct 2023 16:02:37 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232357AbjJCXCe convert rfc822-to-8bit (ORCPT + 99 others); Tue, 3 Oct 2023 19:02:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232328AbjJCXCd (ORCPT ); Tue, 3 Oct 2023 19:02:33 -0400 Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 277EDCC; Tue, 3 Oct 2023 16:02:29 -0700 (PDT) Received: by mail-pg1-f180.google.com with SMTP id 41be03b00d2f7-517ab9a4a13so1027696a12.1; Tue, 03 Oct 2023 16:02:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696374148; x=1696978948; 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=Bc75ZLj27HqA99qp9BegB2tmAdW+msTPeqxif7xbAds=; b=c3iTPSvpAIuxsy5yNxtHdeeDfrqN4j2fN9yJYyNj0UZxdwCdaEOZ/KTTQJY53ZBenb VPi3lP+1MzPnL6hv6FralCteLDvZ2etoyBYP01gROD3XyOfK2ODccFKq8FmChy/h+n07 AGHl8BjTf/d2Eh5bHZ+t/RaOIijqi6cTUG9AHsStGEz5lXgusXYhc3i61THXCaHN6dCH u78CQ7zJ1tb8XXRq1zbbV1tfS/izc4xu9BZeq1UVQp2Zlv/ot3EfiFUqmudk5ksUe7gV RH5gajfam9H2lbh54Oram2mHhQd/bOU5HW+1H3/vgd0WLWNZ7IM5DgdOgWqGtG+VKH3i /1/g== X-Gm-Message-State: AOJu0Yy28/Ry0D/WHMXcWv9J0Q19cHeEJcFhO7Vc/f6xXS8H89SwpuTT 2KstOuYiXujs78aDqCgT4f6+6vdYYTBbeaEQ7I8= X-Received: by 2002:a17:90a:c293:b0:268:18e:9dfa with SMTP id f19-20020a17090ac29300b00268018e9dfamr731538pjt.5.1696374148336; Tue, 03 Oct 2023 16:02:28 -0700 (PDT) MIME-Version: 1.0 References: <20230916040915.1075620-1-irogers@google.com> In-Reply-To: From: Namhyung Kim Date: Tue, 3 Oct 2023 16:02:16 -0700 Message-ID: Subject: Re: [PATCH v1] perf evlist: Avoid frequency mode for the dummy event To: Ian Rogers 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: 8BIT X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS 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, 03 Oct 2023 16:02:37 -0700 (PDT) On Tue, Oct 3, 2023 at 3:36 PM Ian Rogers wrote: > > On Tue, Oct 3, 2023 at 1:08 PM Namhyung Kim wrote: > > > > Hello, > > > > On Wed, Sep 20, 2023 at 10:05 PM Mingwei Zhang wrote: > > > > > > On Mon, Sep 18, 2023 at 3:43 PM Ian Rogers wrote: > > > > > > > > On Sat, Sep 16, 2023 at 5:46 PM 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 reset > > > > > operation while quickly figuring out the event in frequency mode? > > > > > > > > Agreed. I think before the pmu_disable could be avoided for this condition: > > > > ``` > > > > if (event->hw.interrupts != 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 = 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, I was thinking about that too. It's also a side effect of the context rewrite. Maybe we could iterate pmu_ctx's active lists and skip pmus with PERF_PMU_CAP_NO_INTERRUPT and individual non-sampling events. Thanks, Namhyung