From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DDDB6C88CB2 for ; Mon, 12 Jun 2023 15:27:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235831AbjFLP1l (ORCPT ); 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 Precedence: bulk List-ID: X-Mailing-List: linux-perf-users@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.