From patchwork Fri Sep 15 15:00:05 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: 140492 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:a55:b0:13f:353d:d1ed with SMTP id 21csp377231rwb; Fri, 15 Sep 2023 08:03:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFfeRi5DDRJsDojCA5gjdhROYGtRS6Td9SR+laB3JJ4S2o8WV8kI1vbEymt4SLsCHiIRq1r X-Received: by 2002:a17:903:2283:b0:1b9:e81f:fb08 with SMTP id b3-20020a170903228300b001b9e81ffb08mr1774274plh.55.1694790208097; Fri, 15 Sep 2023 08:03:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694790208; cv=none; d=google.com; s=arc-20160816; b=DJihOcKRQQX+wrGz5k+a35mskTeNCmzGCGIqGF79WSy78snrMPTSN3LbKLIEjgy4oa lGmh8G7V7vW2ImH5FnlalWT3wHrpQSgcL+8cGxJm93tE+F/vcxAXe5spxaTp44cBlsHZ W5YSZws6K0gxaPbi7N1NU94IZxspGcatg/Q0K53Wdn7soB2Qk7VGRnbvUjOWR+2scoyt 0nP5yupACs/LnuzsNi6XniJ4nPb9yUk3tfGZDovFsahqpGo/pXndvb6TiMAu0rPYGYLt d8lR1T1axk4QycETSwiRwUrb68SVtLSfclQaN8cUTxMODsNLynOO2XJ0934dvIKnW+j/ Mevw== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=Wj4HGk6fLQehrd+3krea2qnnepFoyOYWYr8HVfKoMN4=; fh=D+GMbnxf3YZ6W/cs5vIO3E1zY8CFuWok3wCtlm2bqJA=; b=z77kjUbleO1Wau2hdjFTZfj0Yu6W9ZnvMBaOdr82dD/x8YyUo2kWVbhr7zW/F/MoOT A2LpfI0zrURNaKGBp8MTURZCOG/VTKZpUbD/83U/uzRWUhulNjfKTZo9SfN06UeBCgNc cc3g8H/CrkzgAhAJYn/sQWKz8FW/BeDzzqSW04Cqa8qQ84KxFbbE55lD957tk/uEG8Qx uUUmMgbAv59SJQ6kDIvwkqu/sw4V2tzDhuidgMNGBco5NlM2Zj07cf3VgrlU1z/r1bHj KljuNAyxuhQbRRxQYCIZZUUtUBX+zE7lsjessx5xrn4kowwv0aIMs4yV6hnglLODN6qf gH/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MQbpzNDY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id l11-20020a170902f68b00b001b841d54b7csi3695655plg.206.2023.09.15.08.03.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 08:03:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MQbpzNDY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 24DE4801C9E8; Fri, 15 Sep 2023 08:00:27 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235702AbjIOPAQ (ORCPT + 31 others); Fri, 15 Sep 2023 11:00:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229568AbjIOPAP (ORCPT ); Fri, 15 Sep 2023 11:00:15 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D35110D; Fri, 15 Sep 2023 08:00:10 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BC6F2C433C9; Fri, 15 Sep 2023 15:00:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1694790010; bh=FqlUd/YRLEnI9bITXzGJS4ipTYUOfDz0uPKjftQZN2Q=; h=From:To:Cc:Subject:Date:From; b=MQbpzNDYPYhuQa28l/as2SlN2tEJNV0vEbEBwQUjbqbxor8r91qBnz7702aJ5/E4b HFFTkqYaTPo7Xx0/glpwrLxZOP5KcgfAU4ey2nfRV3mFf4h68zsv4oAumyixNJoLC3 +lO1yjTukDJoA/Nbt1nlBU7Bq69eZ8R3vSq7+bCSuwvrQQ9879/2Qna2Q8A34sx6ik cX664ASLfLfr9f8RL8QlPF9Eo9JNFm+OAmuaf3V68SD35lN9wqRCBjltLu8BmF3cWf HButuETjOQWEbzgw68ws2lZa8IP21+NbmY2kDwAP/kSCF4UC1I/H/nbXnwQmEkFv0l l2pnnTIJtD/Sg== From: Daniel Bristot de Oliveira To: Daniel Bristot de Oliveira , Steven Rostedt , Masami Hiramatsu Cc: linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] tracing/timerlat: Hotplug support for the user-space interface Date: Fri, 15 Sep 2023 17:00:05 +0200 Message-Id: X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Fri, 15 Sep 2023 08:00:27 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777116337229371921 X-GMAIL-MSGID: 1777116337229371921 The osnoise/per_cpu/CPU$/timerlat_fd is create for each possible CPU, but it might create confusion if the CPU is not online. Create the file only for online CPUs, also follow hotplug by creating and deleting as CPUs come and go. Fixes: e88ed227f639 ("tracing/timerlat: Add user-space interface") Signed-off-by: Daniel Bristot de Oliveira --- kernel/trace/trace_osnoise.c | 101 ++++++++++++++++++++++++++--------- 1 file changed, 77 insertions(+), 24 deletions(-) diff --git a/kernel/trace/trace_osnoise.c b/kernel/trace/trace_osnoise.c index bd0d01d00fb9..1af01eec3e36 100644 --- a/kernel/trace/trace_osnoise.c +++ b/kernel/trace/trace_osnoise.c @@ -229,6 +229,19 @@ static inline struct osnoise_variables *this_cpu_osn_var(void) } #ifdef CONFIG_TIMERLAT_TRACER + +/* + * osnoise/per_cpu dir + */ +static struct dentry *osnoise_per_cpu_fd; + +struct osnoise_per_cpu_dir { + struct dentry *root; + struct dentry *timerlat_fd; +}; + +static DEFINE_PER_CPU(struct osnoise_per_cpu_dir, osnoise_per_cpu_dir); + /* * Runtime information for the timer mode. */ @@ -2000,6 +2013,9 @@ static int start_kthread(unsigned int cpu) char comm[24]; if (timerlat_enabled()) { + if (!test_bit(OSN_WORKLOAD, &osnoise_options)) + return 0; + snprintf(comm, 24, "timerlat/%d", cpu); main = timerlat_main; } else { @@ -2065,19 +2081,64 @@ static int start_per_cpu_kthreads(void) return retval; } +#ifdef CONFIG_TIMERLAT_TRACER +static const struct file_operations timerlat_fd_fops; +static int timerlat_add_per_cpu_interface(long cpu) +{ + struct dentry *timerlat_fd, *cpu_dir_fd; + char cpu_str[30]; /* see trace.c: tracing_init_tracefs_percpu() */ + + if (!osnoise_per_cpu_fd) + return 0; + + snprintf(cpu_str, 30, "cpu%ld", cpu); + cpu_dir_fd = tracefs_create_dir(cpu_str, osnoise_per_cpu_fd); + + if (cpu_dir_fd) { + timerlat_fd = trace_create_file("timerlat_fd", TRACE_MODE_READ, + cpu_dir_fd, NULL, &timerlat_fd_fops); + WARN_ON_ONCE(!timerlat_fd); + per_cpu_ptr(&osnoise_per_cpu_dir, cpu)->root = cpu_dir_fd; + per_cpu_ptr(&osnoise_per_cpu_dir, cpu)->timerlat_fd = timerlat_fd; + + /* Record the CPU */ + d_inode(timerlat_fd)->i_cdev = (void *)(cpu); + + return 0; + } + + return -ENOMEM; +} + +static void timerlat_rm_per_cpu_interface(long cpu) +{ + struct dentry *cpu_dir = per_cpu_ptr(&osnoise_per_cpu_dir, cpu)->root; + + if (cpu_dir) { + tracefs_remove(cpu_dir); + per_cpu_ptr(&osnoise_per_cpu_dir, cpu)->root = NULL; + per_cpu_ptr(&osnoise_per_cpu_dir, cpu)->timerlat_fd = NULL; + } +} +#else +static int timerlat_add_per_cpu_interface(long cpu) { return 0; }; +static void timerlat_rm_per_cpu_interface(long cpu) {}; +#endif + #ifdef CONFIG_HOTPLUG_CPU static void osnoise_hotplug_workfn(struct work_struct *dummy) { unsigned int cpu = smp_processor_id(); mutex_lock(&trace_types_lock); - - if (!osnoise_has_registered_instances()) - goto out_unlock_trace; - mutex_lock(&interface_lock); cpus_read_lock(); + timerlat_add_per_cpu_interface(cpu); + + if (!osnoise_has_registered_instances()) + goto out_unlock; + if (!cpumask_test_cpu(cpu, &osnoise_cpumask)) goto out_unlock; @@ -2086,7 +2147,6 @@ static void osnoise_hotplug_workfn(struct work_struct *dummy) out_unlock: cpus_read_unlock(); mutex_unlock(&interface_lock); -out_unlock_trace: mutex_unlock(&trace_types_lock); } @@ -2106,6 +2166,7 @@ static int osnoise_cpu_init(unsigned int cpu) */ static int osnoise_cpu_die(unsigned int cpu) { + timerlat_rm_per_cpu_interface(cpu); stop_kthread(cpu); return 0; } @@ -2708,10 +2769,7 @@ static int init_timerlat_stack_tracefs(struct dentry *top_dir) static int osnoise_create_cpu_timerlat_fd(struct dentry *top_dir) { - struct dentry *timerlat_fd; - struct dentry *per_cpu; - struct dentry *cpu_dir; - char cpu_str[30]; /* see trace.c: tracing_init_tracefs_percpu() */ + int retval; long cpu; /* @@ -2720,29 +2778,24 @@ static int osnoise_create_cpu_timerlat_fd(struct dentry *top_dir) * Because osnoise/timerlat have a single workload, having * multiple files like these are wast of memory. */ - per_cpu = tracefs_create_dir("per_cpu", top_dir); - if (!per_cpu) + osnoise_per_cpu_fd = tracefs_create_dir("per_cpu", top_dir); + if (!osnoise_per_cpu_fd) return -ENOMEM; - for_each_possible_cpu(cpu) { - snprintf(cpu_str, 30, "cpu%ld", cpu); - cpu_dir = tracefs_create_dir(cpu_str, per_cpu); - if (!cpu_dir) + for_each_online_cpu(cpu) { + retval = timerlat_add_per_cpu_interface(cpu); + if (retval < 0) goto out_clean; - - timerlat_fd = trace_create_file("timerlat_fd", TRACE_MODE_READ, - cpu_dir, NULL, &timerlat_fd_fops); - if (!timerlat_fd) - goto out_clean; - - /* Record the CPU */ - d_inode(timerlat_fd)->i_cdev = (void *)(cpu); } return 0; out_clean: - tracefs_remove(per_cpu); + tracefs_remove(osnoise_per_cpu_fd); + /* tracefs_remove() recursively deletes all the other files */ + osnoise_per_cpu_fd = NULL; + for_each_online_cpu(cpu) + timerlat_rm_per_cpu_interface(cpu); return -ENOMEM; }