Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp5740131rwd; Mon, 12 Jun 2023 09:02:18 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7tJOw6gT6fnLsqi6TfxVBvoJq/ueZvgydKFyfW2hQTzK8v5Jl4TeiGONs1qdE3S2uVVNvy X-Received: by 2002:a05:6a20:e48f:b0:119:c5a2:b32b with SMTP id ni15-20020a056a20e48f00b00119c5a2b32bmr7202366pzb.47.1686585738202; Mon, 12 Jun 2023 09:02:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686585738; cv=none; d=google.com; s=arc-20160816; b=ZyvtEscF5WGgW+4btfXGD1RYL9mbXrgr8LgK6f9WjB8wl9Zr6EGExeOD287Xa0djjI WI5/cVa+2B7rNyN1n3tatdEYpAHmys5Llo0wIGcjK3TP2n1ML0YF8TA5iNQhaOpW2sk0 mQa1Zp4tUZR98oeQ6qTLTFR6sF9lgVEr20lZQY1z69KbetxEuzVWXP2W0GXGmfEeIqGn ZrE6NXlFSYkqVXPBD+d3LIMaL4KV60WflYSr/2P8rh30KHvgGM2uQzctlDFYAa3JxgBI DBHzo39NAEWj0Pnc8OHXGsejgrdOZqXKz/NEi2a/xBcccjnJ2PLsxaJ7aQNZdY9zMif9 ja3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:cc:from :references:to:content-language:subject:user-agent:mime-version:date :message-id; bh=Lin+tiZWs4RHxC9KkGcR1ma5x8aZH8ky6TI05IKjxQs=; b=aSFfaIX5+KkFjraMU1pCjxB7y/nSuKF5X6DQF35a/KOQUXvUBPgc5XST6FCPfQlD6B xOgtdZ5QZGeOWjgdZ8xIrW1xin3wIpnR8tslp0fl4XV36ZG6ZzffVDglZEUT9b8gU5VP KDrsNdu4qoKUn+OJ6wvZIA/J8ySRaVBlsX98g+Mkl5eQbSPNE++k4WKsw6Rdd/AdOFN9 HNXydHxnYcJmhs9+1cie8n3YbIkWkN+BIsPCtdsrxPSeDnmzrrpmfu7cHXarK/7JzT+w QdwfB0jM/LKVdAr6dJ8FEqsPTNNmErjLj2ACMkFf5mVN8ttE7B7I8i0hbEEvtAW6GGez OkfQ== 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l191-20020a6391c8000000b0053087bce16esi7088100pge.830.2023.06.12.09.01.38; Mon, 12 Jun 2023 09:02:18 -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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234490AbjFLP1l (ORCPT + 99 others); Mon, 12 Jun 2023 11:27:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233303AbjFLP1k (ORCPT ); Mon, 12 Jun 2023 11:27:40 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0F36EE7B; Mon, 12 Jun 2023 08:27:22 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id BBEA61FB; Mon, 12 Jun 2023 08:28:06 -0700 (PDT) Received: from [192.168.1.3] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 9DF2D3F5A1; Mon, 12 Jun 2023 08:27:19 -0700 (PDT) Message-ID: Date: Mon, 12 Jun 2023 16:27:07 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.0 Subject: Re: [RFC] Adding support for setting the affinity of the recording process Content-Language: en-US To: Yang Jihong , Peter Zijlstra , Arnaldo Carvalho de Melo References: <159de73b-fdd6-6df8-4f77-73c628fe641f@huawei.com> From: James Clark Cc: Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , linux-perf-users , linux-kernel , Ingo Molnar In-Reply-To: <159de73b-fdd6-6df8-4f77-73c628fe641f@huawei.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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 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. > 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. 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. James > Thanks, > Yang.