Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp608391rwd; Mon, 12 Jun 2023 19:52:20 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6TQqVNUnaQ24NaH2hWrjklVtwcZAjHXHRl4+vliIoA6WCOY2DSp2T9WAiiG3JWev0dygAY X-Received: by 2002:a17:906:da85:b0:96a:4ea0:a1e7 with SMTP id xh5-20020a170906da8500b0096a4ea0a1e7mr12111241ejb.50.1686624740269; Mon, 12 Jun 2023 19:52:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686624740; cv=none; d=google.com; s=arc-20160816; b=Kzkiq0rFEKi5zxWqJTs9bgEP3bCUW1ZzH8qFh+TG+EGUZ3x9ZBV4Lcse3cAMQRXDDP Gr8waRsf9sdtwG1efvl9HPaIq8hoMdDDJ5Unxu3eTpkGHoY9Gk+DP20GuEhCwi3M+6Fe TvZINog0ybyvWNB0DJQolJsT4hw+/r5ol0/UbXN4+YwiVVK9qHXiMTM7IYNOGpA3VPq1 BjeZy1X2HmLPHV3CYiGr2tDmMkngG+g2nulfSA1mAxdqIokeLy8iMBC7q1GtpQ73E55I bXoHZQyOjvt2mDClksUU7EfhA5ZuK6CvimUN8hjFsN2CXZAXVK/PA19r1PLfxtYRV8Ol /TaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=hdw3/XFonRscw+z0J3FlBcxdTanb/wu2v4Tx9RG6BCc=; b=0JITFpVGzIPqwNDEqBrAEL5XcimU3ZdTGAYTdZj+Wf7apVCPwwhhb1nXxjvPOJnnib 3e1quIRNmkPWiPMbpeoFRy3X3zjPilSlCJhwBzNspwDkBAhKzJRtuymeTNfUlocH7O1v tBRykv500lN3Hbhp0SJOYh+3wPUf3DxxESTzT0zOngMUzL+a6Cj6h7fB+BQ4fjROQD32 JuMGXZO2iX5wV1mYTeuSVPWyn9ZWzQi/38inKfM2xyCODQdR2Zz/4iXgjbtpy62NoXw3 pmztnFTGrjiBp0aWay5tvyzWsHfA7LAcrHgWIo9d39oR7e8HmfvPnFUI85ffV4FwjpPX ygug== 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v24-20020a170906339800b009787062562esi5767261eja.585.2023.06.12.19.51.55; Mon, 12 Jun 2023 19:52:20 -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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239018AbjFMC2d (ORCPT + 99 others); Mon, 12 Jun 2023 22:28:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239035AbjFMC20 (ORCPT ); Mon, 12 Jun 2023 22:28:26 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15C55199E; Mon, 12 Jun 2023 19:28:17 -0700 (PDT) Received: from kwepemm600003.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4QgC7p48VDzLq8m; Tue, 13 Jun 2023 10:25:10 +0800 (CST) Received: from [10.67.111.205] (10.67.111.205) by kwepemm600003.china.huawei.com (7.193.23.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Tue, 13 Jun 2023 10:28:14 +0800 Subject: Re: [RFC] Adding support for setting the affinity of the recording process To: James Clark , Peter Zijlstra , Arnaldo Carvalho de Melo CC: Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , linux-perf-users , linux-kernel , Ingo Molnar References: <159de73b-fdd6-6df8-4f77-73c628fe641f@huawei.com> From: Yang Jihong Message-ID: Date: Tue, 13 Jun 2023 10:28:14 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Originating-IP: [10.67.111.205] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemm600003.china.huawei.com (7.193.23.202) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS,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 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. > >> 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. Thanks, Yang.