From patchwork Tue May 23 17:44:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Bristot de Oliveira X-Patchwork-Id: 98117 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2315059vqo; Tue, 23 May 2023 10:47:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4C1uiBulsZIAZz1nJMGmRHrnJmxWTYY7H38cmtUXwwE9Ldt+q7VnZnOOQ5NAWLZ9P+ftvc X-Received: by 2002:a05:6a20:7f8a:b0:f4:d4a8:9c82 with SMTP id d10-20020a056a207f8a00b000f4d4a89c82mr15272227pzj.47.1684864025662; Tue, 23 May 2023 10:47:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684864025; cv=none; d=google.com; s=arc-20160816; b=qIT/BSC2NSTaW9PH5SGebsBYuq4ifB7ucMVvuv6bbz0w5fVnYIdAgTHfAz6U+WDm5i Q4ARNiV0qa7Sd4IGMEBFRo4RdI624724PVpRF7RwUszgiZgSzougz6DYzVblIPe7IJ/0 Hj5SuWBPemZYxCRgFrAUVEs/eDZbcdoAjHFbdc6m3C4maw93/IpVU7QfQGQrDYlYwb/g D3MpUfsYU+/umD+xYbRAK2EsGN/tq6+VbMbGP63Iir6QJoa4jtpnV+XdUkV3rT3sbswF DWpbH2D5Ej0PZZZN1vDldvXQ2WPMYQjxNnrTRmUb7/ZdmM3N8jX1JXk6jgmHzZeyiINU 0/XQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=oHHRXHnCsGs1ap582/zikDRpSxQ93BkdqJxSpq/5rJg=; b=r6NFtzj1NJucFtcPjtUkE0mvn/R9yXTDD43X37AHG0WoWr1HvA4KN4df6HDXShmj+t yAaj4ePdvjl833N5Ve6lRraIocxad6/OVvMvGyl12N3k2Wy3UhCr1f/Sn59xnVY2XnFu F1EgCF59dQJk22cYMQEm5jIaNRsVcFDGknD8M1zkmcrOzH673CydH72aTq9JvBG0AkQw jXs+5oLfWObJ2l41ihPq+KkROkQg5e203kYLTf7WYb+l1ukRegHCj/hBFfKmYxpcHhHy tidzpi5Kxt1278/J7R3tW0FBvrpvp8PXX69+YRaoCATSIO5RFp+oPsC7b3678zfIkNe0 0zHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=O1VD3oHb; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m24-20020a638c18000000b0053481a225desi6664982pgd.340.2023.05.23.10.46.52; Tue, 23 May 2023 10:47:05 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=O1VD3oHb; 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 S238277AbjEWRpI (ORCPT + 99 others); Tue, 23 May 2023 13:45:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238320AbjEWRox (ORCPT ); Tue, 23 May 2023 13:44:53 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A1D197; Tue, 23 May 2023 10:44:51 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 04D7863571; Tue, 23 May 2023 17:44:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2AD2BC4339B; Tue, 23 May 2023 17:44:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1684863890; bh=I75jhz8De3NPiqlgBoHOa8UPruFRWJnxpiQkId7IjnI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O1VD3oHb0/IyMuEtPFzUOvEHiNtzhZCp4mtbHGOPcoDllUpUyDSwVQrCvaX1O2fvh n9qYHbMEDqgjF1VIce51yXjvQjFpJ28aTzca2PfTkUsPmheSGlUcBTqrBCD1tc0fcA znlHzknbtm56gM1A6vRRqkLHP9Axs8R11NcJfQvLMh/NNeZfsEB5qlm/yb33q9KvKu 3bF48i3XqteEgEB7kxw3Hlnja0jtg8hDBifRkcdfieuqp1jLNqajcGq1otF+dxsoR7 0MwpCT8xvw7sPghtUGty3qoWDpxQNERrWN6wUy4IfNacqWuuGr0PItH2gZX9QHslS6 bJ74iwmDYxBsQ== From: Daniel Bristot de Oliveira To: linux-kernel@vger.kernel.org, linux-trace-devel@vger.kernel.org, Steven Rostedt Cc: linux-doc@vger.kernel.org, Juri Lelli , William White , Daniel Bristot de Oliveira , Masami Hiramatsu , Jonathan Corbet Subject: [PATCH V2 4/9] rtla: Automatically move rtla to a house-keeping cpu Date: Tue, 23 May 2023 19:44:26 +0200 Message-Id: <2a9c16fedbef08d483f92c5af08a9b637d396056.1684863094.git.bristot@kernel.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766707980897366195?= X-GMAIL-MSGID: =?utf-8?q?1766707980897366195?= When the user sets -c try to move rtla out of the , even without an -H option. This is useful to avoid having rtla interfering with the workload. This works by removing from rtla's current affinity. If rtla fails to move itself away it is not that of a problem as this is an automatic measure. Cc: Steven Rostedt Cc: Daniel Bristot de Oliveira Cc: Masami Hiramatsu Cc: Jonathan Corbet Signed-off-by: Daniel Bristot de Oliveira --- tools/tracing/rtla/src/osnoise_hist.c | 9 +++++ tools/tracing/rtla/src/osnoise_top.c | 9 +++++ tools/tracing/rtla/src/timerlat_hist.c | 9 +++++ tools/tracing/rtla/src/timerlat_top.c | 9 +++++ tools/tracing/rtla/src/utils.c | 50 ++++++++++++++++++++++++++ tools/tracing/rtla/src/utils.h | 1 + 6 files changed, 87 insertions(+) diff --git a/tools/tracing/rtla/src/osnoise_hist.c b/tools/tracing/rtla/src/osnoise_hist.c index b616a72d5c0a..dfbcb5ca7ecb 100644 --- a/tools/tracing/rtla/src/osnoise_hist.c +++ b/tools/tracing/rtla/src/osnoise_hist.c @@ -753,6 +753,15 @@ osnoise_hist_apply_config(struct osnoise_tool *tool, struct osnoise_hist_params err_msg("Failed to set rtla to the house keeping CPUs\n"); goto out_err; } + } else if (params->cpus) { + /* + * Even if the user do not set a house-keeping CPU, try to + * move rtla to a CPU set different to the one where the user + * set the workload to run. + * + * No need to check results as this is an automatic attempt. + */ + auto_house_keeping(¶ms->monitored_cpus); } return 0; diff --git a/tools/tracing/rtla/src/osnoise_top.c b/tools/tracing/rtla/src/osnoise_top.c index 0e2f3b216d34..0833537bb2eb 100644 --- a/tools/tracing/rtla/src/osnoise_top.c +++ b/tools/tracing/rtla/src/osnoise_top.c @@ -582,6 +582,15 @@ osnoise_top_apply_config(struct osnoise_tool *tool, struct osnoise_top_params *p err_msg("Failed to set rtla to the house keeping CPUs\n"); goto out_err; } + } else if (params->cpus) { + /* + * Even if the user do not set a house-keeping CPU, try to + * move rtla to a CPU set different to the one where the user + * set the workload to run. + * + * No need to check results as this is an automatic attempt. + */ + auto_house_keeping(¶ms->monitored_cpus); } return 0; diff --git a/tools/tracing/rtla/src/timerlat_hist.c b/tools/tracing/rtla/src/timerlat_hist.c index 00287e96f22e..1675d54cae81 100644 --- a/tools/tracing/rtla/src/timerlat_hist.c +++ b/tools/tracing/rtla/src/timerlat_hist.c @@ -776,6 +776,15 @@ timerlat_hist_apply_config(struct osnoise_tool *tool, struct timerlat_hist_param err_msg("Failed to set rtla to the house keeping CPUs\n"); goto out_err; } + } else if (params->cpus) { + /* + * Even if the user do not set a house-keeping CPU, try to + * move rtla to a CPU set different to the one where the user + * set the workload to run. + * + * No need to check results as this is an automatic attempt. + */ + auto_house_keeping(¶ms->monitored_cpus); } return 0; diff --git a/tools/tracing/rtla/src/timerlat_top.c b/tools/tracing/rtla/src/timerlat_top.c index 920f2f6ef842..f0c6d9735e2a 100644 --- a/tools/tracing/rtla/src/timerlat_top.c +++ b/tools/tracing/rtla/src/timerlat_top.c @@ -619,6 +619,15 @@ timerlat_top_apply_config(struct osnoise_tool *top, struct timerlat_top_params * err_msg("Failed to set rtla to the house keeping CPUs\n"); goto out_err; } + } else if (params->cpus) { + /* + * Even if the user do not set a house-keeping CPU, try to + * move rtla to a CPU set different to the one where the user + * set the workload to run. + * + * No need to check results as this is an automatic attempt. + */ + auto_house_keeping(¶ms->monitored_cpus); } return 0; diff --git a/tools/tracing/rtla/src/utils.c b/tools/tracing/rtla/src/utils.c index 8f9ad8f01e0f..3e25f0277fb9 100644 --- a/tools/tracing/rtla/src/utils.c +++ b/tools/tracing/rtla/src/utils.c @@ -709,3 +709,53 @@ int set_comm_cgroup(const char *comm_prefix, const char *cgroup) close(cg_fd); return 0; } + +/** + * auto_house_keeping - Automatically move rtla out of measurement threads + * + * Try to move rtla away from the tracer, if possible. + * + * Returns 1 on success, 0 otherwise. + */ +int auto_house_keeping(cpu_set_t *monitored_cpus) +{ + cpu_set_t rtla_cpus, house_keeping_cpus; + int retval; + + /* first get the CPUs in which rtla can actually run. */ + retval = sched_getaffinity(getpid(), sizeof(rtla_cpus), &rtla_cpus); + if (retval == -1) { + debug_msg("Could not get rtla affinity, rtla might run with the threads!\n"); + return 0; + } + + /* then check if the existing setup is already good. */ + CPU_AND(&house_keeping_cpus, &rtla_cpus, monitored_cpus); + if (!CPU_COUNT(&house_keeping_cpus)) { + debug_msg("rtla and the monitored CPUs do not share CPUs."); + debug_msg("Skipping auto house-keeping\n"); + return 1; + } + + /* remove the intersection */ + CPU_XOR(&house_keeping_cpus, &rtla_cpus, monitored_cpus); + + /* get only those that rtla can run */ + CPU_AND(&house_keeping_cpus, &house_keeping_cpus, &rtla_cpus); + + /* is there any cpu left? */ + if (!CPU_COUNT(&house_keeping_cpus)) { + debug_msg("Could not find any CPU for auto house-keeping\n"); + return 0; + } + + retval = sched_setaffinity(getpid(), sizeof(house_keeping_cpus), &house_keeping_cpus); + if (retval == -1) { + debug_msg("Could not set affinity for auto house-keeping\n"); + return 0; + } + + debug_msg("rtla automatically moved to an auto house-keeping cpu set\n"); + + return 1; +} diff --git a/tools/tracing/rtla/src/utils.h b/tools/tracing/rtla/src/utils.h index 9ab2f0d7bc1c..dec59163cfbc 100644 --- a/tools/tracing/rtla/src/utils.h +++ b/tools/tracing/rtla/src/utils.h @@ -60,6 +60,7 @@ int parse_cpu_set(char *cpu_list, cpu_set_t *set); int set_comm_sched_attr(const char *comm_prefix, struct sched_attr *attr); int set_comm_cgroup(const char *comm_prefix, const char *cgroup); int set_cpu_dma_latency(int32_t latency); +int auto_house_keeping(cpu_set_t *monitored_cpus); #define ns_to_usf(x) (((double)x/1000)) #define ns_to_per(total, part) ((part * 100) / (double)total)