From patchwork Sun Mar 19 16:46:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 71831 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp798408wrt; Sun, 19 Mar 2023 10:07:13 -0700 (PDT) X-Google-Smtp-Source: AK7set/V7FCFfxLNNwkCIDYKNGDSRxPoKGWAeAvMSy7Hbb1xRWfveNCRAiJeReKy3GVWKd/zZkJF X-Received: by 2002:a17:90b:4b84:b0:23d:3c7b:8684 with SMTP id lr4-20020a17090b4b8400b0023d3c7b8684mr15787884pjb.41.1679245632880; Sun, 19 Mar 2023 10:07:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679245632; cv=none; d=google.com; s=arc-20160816; b=xZVxHETfPFAI2/EeV8pAxSs/0e2vcgHT7jXUglxQS4/gu4Czff5Yan5a/+8aQngGWm t3y/wdcR1sYQYhCY0fzr5fVpPyxCzSFl/c2Bdb7+swZFcicJDVGW/rrt62hMTRyd8eVr iQMMHN67IZ7/VCvjBiDGizBb+LpZ8iFwmBM7aMRmzlNb1oDg1IsXuqhZym7C3yaxLRAK dPXhf+cawcno6K/SnHj6ub8+CNYwXtccIRFa+e/tHA0DrHbKnf+nhw1iD8MKqVGKEFgT txYmu/JgHLKsxI3s06OpsGQG+FF+i8Mk0ypTLDzHDYgjkKmSNTKHdmrjrAQxREWzqbVa JARA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:subject:cc:to:from:date :user-agent:message-id; bh=0YzHqA94vjhNzihzJD7myf9eoBv4ktw9lHc5Vq86DwI=; b=vMwPxKNunJkazwwRom5xxEDkt/Uh7ygE+nJEOhxyrJJ6VoIcjOfBXxjvTl8BRX+VEg Sg0Y2y5mRCgJnXOclRF+U4teKRpVLe0lJXINsG8JH6dIXKVYNL2AV5pfaNUWVJDdtu/E YNkhtah4bFVlxlz/PYoETsABE13OyEm76PX/ASU8dZEO/TSnP5wBMf21hSu3fFRUw56A 7rXCnhXR1D3slTYy7B9llOpjkfjZHEPwPI65KLk3LgeENGwbfyyw1ypPtnXXuEw4CHup OcTFZNxi7ggEBzS42ZFt4JhKuWyjzAdqPb7mvrruNZkPMyFvENzEkcAoXONA1yUoOhpz FGAA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v69-20020a638948000000b0050bfb509da6si8522884pgd.631.2023.03.19.10.06.57; Sun, 19 Mar 2023 10:07:12 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229736AbjCSQsP (ORCPT + 99 others); Sun, 19 Mar 2023 12:48:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231126AbjCSQrx (ORCPT ); Sun, 19 Mar 2023 12:47:53 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64E2D1E9D1 for ; Sun, 19 Mar 2023 09:47:52 -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 88D8661135 for ; Sun, 19 Mar 2023 16:47:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 62740C43444; Sun, 19 Mar 2023 16:47:50 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.96) (envelope-from ) id 1pdwCD-000Jae-1e; Sun, 19 Mar 2023 12:47:49 -0400 Message-ID: <20230319164749.324599670@goodmis.org> User-Agent: quilt/0.66 Date: Sun, 19 Mar 2023 12:46:51 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Andrew Morton , Costa Shulyupin , Daniel Bristot de Oliveira Subject: [for-linus][PATCH 8/8] tracing/hwlat: Replace sched_setaffinity with set_cpus_allowed_ptr References: <20230319164643.513018619@goodmis.org> MIME-Version: 1.0 X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS 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?1760816668559285915?= X-GMAIL-MSGID: =?utf-8?q?1760816668559285915?= From: Costa Shulyupin There is a problem with the behavior of hwlat in a container, resulting in incorrect output. A warning message is generated: "cpumask changed while in round-robin mode, switching to mode none", and the tracing_cpumask is ignored. This issue arises because the kernel thread, hwlatd, is not a part of the container, and the function sched_setaffinity is unable to locate it using its PID. Additionally, the task_struct of hwlatd is already known. Ultimately, the function set_cpus_allowed_ptr achieves the same outcome as sched_setaffinity, but employs task_struct instead of PID. Test case: # cd /sys/kernel/tracing # echo 0 > tracing_on # echo round-robin > hwlat_detector/mode # echo hwlat > current_tracer # unshare --fork --pid bash -c 'echo 1 > tracing_on' # dmesg -c Actual behavior: [573502.809060] hwlat_detector: cpumask changed while in round-robin mode, switching to mode none Link: https://lore.kernel.org/linux-trace-kernel/20230316144535.1004952-1-costa.shul@redhat.com Cc: Masami Hiramatsu Fixes: 0330f7aa8ee63 ("tracing: Have hwlat trace migrate across tracing_cpumask CPUs") Signed-off-by: Costa Shulyupin Acked-by: Daniel Bristot de Oliveira Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_hwlat.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/trace/trace_hwlat.c b/kernel/trace/trace_hwlat.c index c4945f8adc11..2f37a6e68aa9 100644 --- a/kernel/trace/trace_hwlat.c +++ b/kernel/trace/trace_hwlat.c @@ -339,7 +339,7 @@ static void move_to_next_cpu(void) cpumask_clear(current_mask); cpumask_set_cpu(next_cpu, current_mask); - sched_setaffinity(0, current_mask); + set_cpus_allowed_ptr(current, current_mask); return; change_mode: @@ -446,7 +446,7 @@ static int start_single_kthread(struct trace_array *tr) } - sched_setaffinity(kthread->pid, current_mask); + set_cpus_allowed_ptr(kthread, current_mask); kdata->kthread = kthread; wake_up_process(kthread);