Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp787892rwd; Mon, 12 Jun 2023 23:46:34 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4Os3EWNA0r/QVoVoCkEyywaK7D1dboPHblKp3WDn+wAF2boKs3DU1+4eBAdCH69v1eMM3b X-Received: by 2002:a17:90a:8b92:b0:253:3e9d:f925 with SMTP id z18-20020a17090a8b9200b002533e9df925mr10328706pjn.31.1686638794086; Mon, 12 Jun 2023 23:46:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686638794; cv=none; d=google.com; s=arc-20160816; b=MGI4R+Q1Vxtni79y3K0u5Kfg3i7+zUt1YzUGge71SevANviUdq7nTscJU+5RN9LBUh zJV8DxrsuNjZP8u9tNXYjKjLOM7GnScSxbbKgvK+w6uXU86YbW62I8yCqQFaTk2EyODM HUntymm4kSK7X5Div/18mMqOC/0M2FlaZnPIedxkY1510PX2Za4Xgo7vxFfZVYFgsdWB CsTRyWatyuhoGvDYpz6Rkgvx/8/m7r+bfaP2vBpE/uUSZmgMw+5tpN5VeCtqfdd/ZKiq 47B9R6WaVCWE6nQtSIPpcjCrwWSBgbqfvNKk5DoCbSJGhhy6pcTWfH51X1FOtv4qZoKa DYmw== 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=z1jmYlCM2ZcIh3gFn2TOwRpsplsyddT5uewR7EeefkA=; b=dolJHLL7IqjVVG/Hvid7hDPNQq+7azM106ZqvrS9KUADme0Ee+7tQcuHqt/0cp2N2+ uQhlHfF5jPlwwCLzOTDiyC5q3eKL0NKgxrXH7cMSTFDls234CEGpv898OxZk6ebr7pT4 Ap+DAkjFNva7cuxfPISm9M4kqcb8yVEqAj0bMiCD0URacCH40b72r7Nyxc79LMOnU2Ea 8dYb1wCbV0fTnw/EfAMgmWB7cAis9H9mLTQdGF0eKD0+h0f7t+w9+wKwxI4hQh9NdPxl 1miX5oSpneju4ieMTU3Z3HQy76GevMmgNsfSN/V2p96ZhPYwlGNMj4TozYBP/DSmbH3p NF9w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id oj10-20020a17090b4d8a00b002536c5eb7cfsi10157577pjb.58.2023.06.12.23.46.22; Mon, 12 Jun 2023 23:46:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239724AbjFMFuU convert rfc822-to-8bit (ORCPT + 99 others); Tue, 13 Jun 2023 01:50:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234044AbjFMFuS (ORCPT ); Tue, 13 Jun 2023 01:50:18 -0400 Received: from mail-vk1-f172.google.com (mail-vk1-f172.google.com [209.85.221.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A394193; Mon, 12 Jun 2023 22:50:17 -0700 (PDT) Received: by mail-vk1-f172.google.com with SMTP id 71dfb90a1353d-4635c158e2aso1435245e0c.3; Mon, 12 Jun 2023 22:50:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686635416; x=1689227416; 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=nsx620+1M90qrU4V38kYMgmC7IznSroVoq6oc0YB+sE=; b=k8Z6HE2+obOa/WFEGowyR11EINKva/INij0RxavUqPvfa6IdPSum07+Bzd41mf7Wbq DBJoWfiwM2+GctnEoKVcEbPFfmRZDpT5wqJVddZ/V5quLRT2xY9Y+Xv1EI7n6D2qYVH7 q7zLrDBDvTZwVocD4xWV/TLq1QNu+l79AwZCAI3V3GUoGJQXZucXg/ZyUWXxb+eJSOyp 1837Bu+sr9OMqAp3jKKrMJZNZlzYwFvfQ6sK7DuxieJ+Ie3Og7zDW0av4VySgafZh2d9 MGR1Os1CisMeIp0K/t0T+9VuocN1ikS4IqHAaaEi2uwv3T1+wkgO2Z7tS1paTekRm5l6 yzQg== X-Gm-Message-State: AC+VfDxFed4KIg6Ilyq1ULSHdLj9A0/tHS0+rDXBCJH2GXAOauUehdwW IhtPkAPc/NrdMyPc3MR8CiXIVOiJa/wwlozT2Dw= X-Received: by 2002:a1f:c192:0:b0:45e:890e:f3cc with SMTP id r140-20020a1fc192000000b0045e890ef3ccmr4237944vkf.4.1686635416471; Mon, 12 Jun 2023 22:50:16 -0700 (PDT) MIME-Version: 1.0 References: <159de73b-fdd6-6df8-4f77-73c628fe641f@huawei.com> In-Reply-To: From: Namhyung Kim Date: Mon, 12 Jun 2023 22:50:05 -0700 Message-ID: Subject: Re: [RFC] Adding support for setting the affinity of the recording process To: Yang Jihong Cc: James Clark , Peter Zijlstra , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , linux-perf-users , linux-kernel , Ingo Molnar Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello, On Mon, Jun 12, 2023 at 7:28 PM Yang Jihong wrote: > > Hello, > > On 2023/6/12 23:27, James Clark wrote: > > > > > > On 12/06/2023 11:26, Yang Jihong wrote: > >> Hello everyone, > >> > >> Currently, perf-record supports profiling an existing process, thread, > >> or a specified command. > >> > >> Sometimes we may need to set CPU affinity of the target process before > >> recording: > >> > >> # taskset -pc > >> # perf record -p -- sleep 10 > >> > >> or: > >> > >> # perf record -- `taskset -c COMMAND` > >> > >> I'm thinking about getting perf to support setting the affinity of the > >> recording process, for example: > >> > >> 1. set the CPU affinity of the process to , process > >> to , and record: > >> > >> # perf record -p /:/ -- sleep 10 > >> > > > > I'm not sure if this is necessary. You can already do this with taskset > > when you launch the processes or for existing ones. > > Yes, that's what we're doing now, and I'm thinking about whether perf > can support this "taskset" feature. I agree with James that it looks out of scope of perf tools. You can always use `taskset` for external processes. > > > > >> and > >> > >> 2. set CPU affinity of the COMMAND and record: > >> > >> # perf record --taskset-command COMMAND > >> > >> In doing so, perf, as an observer, actually changes some of the > >> properties of the target process, which may be contrary to the purpose > >> of perf tool. > >> > >> > >> Will we consider accepting this approach? > >> > > > > For #2 I do this sometimes, but I prefix the perf command with taskset > > because otherwise there is a small time between when taskset does its > > thing and launching the child process that it runs in the wrong place. > > > > Then one issue with the above method is that perf itself gets pinned to > > those CPUs as well. I suppose that could influence your application but > > I've never had an issue with it. > > > > If you really can't live with perf also being pinned to those CPUs I > > would say it makes sense to add options for #2. Otherwise I would just > > run everything under taskset and no changes are needed. > > If "perf" process and the target process are pinned to the same CPU, > and the CPU usage of the target process is high, the perf data > collection may be affected. Therefore, in this case, we may need to pin > the target process and "perf" to different CPUs. > > > > > I think you would still need to have perf itself pinned to the CPUs just > > before it does the fork and exec, and then after that it can undo its > > pinning. Otherwise you'd still get that small time running on the wrong > > cores. > > > > Thanks for your advice, or we can support setting different affinities > for the "perf" process and the target process. When it comes to controlling `perf`, you can use --threads= option which supports fairly complex control for parallelism and affinity. Thanks, Namhyung