Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp925960rdg; Wed, 11 Oct 2023 09:10:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG5XTWCaURsSBBVJfLsVre2pZV9EQXDflfkpH7h4yTwKnAMvW807gki6d1uYcQuPOyOC5pn X-Received: by 2002:a05:6358:7208:b0:141:3fd:2441 with SMTP id h8-20020a056358720800b0014103fd2441mr24416864rwa.30.1697040616507; Wed, 11 Oct 2023 09:10:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697040616; cv=none; d=google.com; s=arc-20160816; b=tl0u70upN7wW7pN4qApXX+k8NpAokoOUZIOmeFadg29gmJQTbL3dYFWl8CYCPNB0FO ePOgGS21KX4peBJFUlbAEw9eKuR3CGpHyqjSO5f2fOG4xucsaAO91avJI3n5WswYJM0a QMTm9rg2deJiMjI3gIsroXLab9RigfQWxfFKi0jD5bLJHQDcKNbnSi/1nMzKiZ1GnBlY PqwPDBbyoT6lExc3jj8r6jVuiGZ0hxvOttBlV/X8Yz1WVMeVczR6ezR4esLl8e8/JTz9 YxBNfNJg9wntkRTUBaBa4AlcwXaDSbVTZDImn3vpl0ZKIKoctNKKGCOdXnm/U/4OjTsS cANg== 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=1thydHnwi5P6XCd03Jpq8liioyzmnerMnhR2au+cNG4=; fh=2puutePm3w16nhyYEtlTqX0VrO8qErl2ti6ibhwagxA=; b=0pTlga2fNIVDi5PxqUdm547i3uo7N3CZcJbAijyxBp+jDSrS0wEcj4LZMRATfraXkO 6iLcYoXk1UFBit9XYmhwgTKsi/5+vzGd898UwFiDhmQhmHpgqzL+uktA5cQRuVd/GeLB oUdrRSrpJpY99jUAhNV7xnnVmAnLdycKbMDVr9Nvfjv2jwcBBRhDbVGpDBIslpl29x3u cqTZhlphGV/KmeXCTZfdHwumJK1PmCpp3ByvUHT2lMqWDpNTVCDq/jUIZtkj07nDle8p +C0Ot4CjYh1oHu/Iwow/XtCXiY3vgWA0QW+no6AOqd5n0dKYe2VW7QemqAgzg0JadllX 8ZQw== 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 a21-20020a630b55000000b005578c6a7672si101876pgl.90.2023.10.11.09.10.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 09:10:16 -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 245BF8255485; Wed, 11 Oct 2023 09:10:14 -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 S232467AbjJKQKG convert rfc822-to-8bit (ORCPT + 99 others); Wed, 11 Oct 2023 12:10:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229853AbjJKQKF (ORCPT ); Wed, 11 Oct 2023 12:10:05 -0400 Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 395529D; Wed, 11 Oct 2023 09:10:04 -0700 (PDT) Received: by mail-pg1-f170.google.com with SMTP id 41be03b00d2f7-58907163519so5286778a12.1; Wed, 11 Oct 2023 09:10:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697040603; x=1697645403; 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=cZ+VIPsKS+z6FGqu1gSOMc5oXv3t+KffR0mpRHqGu2k=; b=Qnt7cxb2+eM6qJMUL016LqFSXptG2Bhc10IkBoSkIvA0rBgbQeju1cWpAjAOmjrDIC IpkapYAM3PsCniNBB2Bj/b4JJZfU68AxrgdlzHBSDmCIo1QReWXjr3oIhUqWcfhUo3Q/ xk8IwzB3adxgtfWLjb+p64S8DW0VnSPbUDk/vWV9va/ZL02QL9SiKGIhhskmUt1INn9H Zs84ctjkeucnb82tt7FKaNM/ZLb5hdevIpIxMWhXhfp+cwPK8fLCaRXKUjzcjc28pCxT coZJczebIVxz7My3c1byKN2QYYeciOG862///+FQN0vOJdb0xD7caXHSlzVIoL1NaRSc blhA== X-Gm-Message-State: AOJu0Yxwxb9BeyQWRiDNYbEWd32jpJxv8lPb2RQ2VPqsFhXkuEtzN8yi 4OZYSoiNVhxXSAlb3AXrrGNta7abSGFGlAJo9Ds= X-Received: by 2002:a17:90b:ecc:b0:27d:a59:ebae with SMTP id gz12-20020a17090b0ecc00b0027d0a59ebaemr1571538pjb.46.1697040603539; Wed, 11 Oct 2023 09:10:03 -0700 (PDT) MIME-Version: 1.0 References: <20230916040915.1075620-1-irogers@google.com> In-Reply-To: From: Namhyung Kim Date: Wed, 11 Oct 2023 09:09:51 -0700 Message-ID: Subject: Re: [PATCH v1] perf evlist: Avoid frequency mode for the dummy event To: Ian Rogers , Mingwei Zhang Cc: Jim Mattson , 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=2.6 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no 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]); Wed, 11 Oct 2023 09:10:14 -0700 (PDT) X-Spam-Level: ** Hi Ian, On Tue, Oct 3, 2023 at 4:20 PM Mingwei Zhang wrote: > > 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, > > Ian > > +Jim Mattson > > I initially thought this idea was just an alternative, or a more > professional fix in the perf subsystem. I was wrong... > > This would be way better than just skipping frequency events in the > loop. Since if we just skip by event, we may still suffer from huge > overhead if the event list contains many sampling events in frequency > mode. Unfortunately, that is the general case when we do perf record > -e 'eventlist' (IIUC all events in eventlist are in frequency mode if > we don't specify period=). So the problem actually remains whenever we > do perf sampling unless we use something like Intel vtune. > > On the other hand, since all of the events are presumably CPU core > events, with the fix we pay only once for the PMU reset per hrtimer > regardless of how many events are in frequency mode. > > Looking forward to the patch! Please keep us posted if possible. Any updates? Thanks, Namhyung