Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp265799pxb; Fri, 29 Oct 2021 09:26:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw5JvHvPou5wYll1lD7s6BhcsMb5kwb1hr69p1xh5Fg6G1iegS7TzS/2S36pBfJK02CrMP6 X-Received: by 2002:a05:6402:14cc:: with SMTP id f12mr16253734edx.242.1635524785890; Fri, 29 Oct 2021 09:26:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635524785; cv=none; d=google.com; s=arc-20160816; b=gkOsZpzJY711DxH6Rfr+13PL0T9hnx6G7Iy71evDvLoz4QVARadf23ul5wsgh+2+kT sk3DQdgm5uNYLub4eT929UePyYPVQnFLZC2HG7G6aIfdQ0yaPEjvGKoIUrZioflyKCYF e50CrGjtVYEzXYZ+7GvJfV47Ykoo2P6fYgb/TuxqDvDgXScBVNNqjZW2alew7wmhpCr5 CXe00BfkUyZu2c1GoLARegr9DtpUGBUaiSrcHMqZvBZwCQt2ZXE1bw0ZbZmnvoEJMi11 6mCehhh5mmcmqNeFgDoPpoThEbtRu3rfRoNek0LJK+erM0z3Jw8PF8BSzNS9YFHSJNql 5m8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=p/VSsELt3+2zuzX0/zpcJ0pZUU5jh9psuWIwJXMlNjw=; b=FhiFObH4rUsak7CfBv6JT8POvVeN+U05V/MW1I6aQ55D+RnK0XdShbGPNvBjSR+9+/ ptxjlbpwQXEgES7/JK4TvDyl5XVFN6G+MMyt6fMs/mUWKIrsan8CeDXmsrCRLo3Ss8tL Rww3Zio6NHGXu/LYJZvotXP7kKof8cd36xBNg2E0wxRu7uXMRtciwQXMnM6jDFPkzYqA aQL+ULN3m5aaEUQ1fI8nv0yzXKUPhZigZEPW9o3piIcrqVvkbuXIDCwNE+e50Ad65saw ySXkT1U8PiKrzsqp5ZDYQBAzhrpGijPFoFEXBEXY1gTn0wVcn19insjgxsl4Bv6G7XOv 55/w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 26si8986481ejl.744.2021.10.29.09.26.00; Fri, 29 Oct 2021 09:26:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S229957AbhJ2Q0l (ORCPT + 99 others); Fri, 29 Oct 2021 12:26:41 -0400 Received: from gateway20.websitewelcome.com ([192.185.68.24]:13663 "EHLO gateway20.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229893AbhJ2Q0k (ORCPT ); Fri, 29 Oct 2021 12:26:40 -0400 X-Greylist: delayed 1177 seconds by postgrey-1.27 at vger.kernel.org; Fri, 29 Oct 2021 12:26:40 EDT Received: from cm13.websitewelcome.com (cm13.websitewelcome.com [100.42.49.6]) by gateway20.websitewelcome.com (Postfix) with ESMTP id 5DBCF400DC12D for ; Fri, 29 Oct 2021 11:03:38 -0500 (CDT) Received: from gator4132.hostgator.com ([192.185.4.144]) by cmsmtp with SMTP id gULym0urcG0jLgULym5J43; Fri, 29 Oct 2021 11:03:38 -0500 X-Authority-Reason: nr=8 Received: from host-79-27-6-113.retail.telecomitalia.it ([79.27.6.113]:40438 helo=[10.0.0.44]) by gator4132.hostgator.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1mgULx-001Sy2-2u; Fri, 29 Oct 2021 11:03:37 -0500 Message-ID: <8ba373fa-2649-db63-546d-d300b9205947@kernel.org> Date: Fri, 29 Oct 2021 18:03:30 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.2.0 Subject: Re: [PATCH V6 09/20] rtla: Add osnoise tool Content-Language: en-US To: Tao Zhou Cc: Steven Rostedt , Ingo Molnar , Tom Zanussi , Masami Hiramatsu , Juri Lelli , Clark Williams , John Kacur , Peter Zijlstra , Thomas Gleixner , Sebastian Andrzej Siewior , linux-rt-users@vger.kernel.org, linux-trace-devel@vger.kernel.org, linux-kernel@vger.kernel.org References: From: Daniel Bristot de Oliveira In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4132.hostgator.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - kernel.org X-BWhitelist: no X-Source-IP: 79.27.6.113 X-Source-L: No X-Exim-ID: 1mgULx-001Sy2-2u X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: host-79-27-6-113.retail.telecomitalia.it ([10.0.0.44]) [79.27.6.113]:40438 X-Source-Auth: kernel@bristot.me X-Email-Count: 1 X-Source-Cap: YnJpc3RvdG1lO2JyaXN0b3RtZTtnYXRvcjQxMzIuaG9zdGdhdG9yLmNvbQ== X-Local-Domain: no Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/27/21 18:30, Tao Zhou wrote: > On Wed, Oct 27, 2021 at 12:06:20AM +0200, Daniel Bristot de Oliveira wrote: > >> +/* >> + * osnoise_set_cpus - configure osnoise to run on *cpus >> + * >> + * "osnoise/cpus" file is used to set the cpus in which osnoise/timerlat >> + * will run. This function opens this file, saves the current value, >> + * and set the cpus passed as argument. >> + */ >> +int osnoise_set_cpus(struct osnoise_context *context, char *cpus) >> +{ >> + char *osnoise_cpus = tracefs_get_tracing_file("osnoise/cpus"); >> + char curr_cpus[1024]; >> + int retval; >> + >> + context->cpus_fd = open(osnoise_cpus, O_RDWR); >> + if (!context->cpus_fd) >> + goto out_err; > The above check should be "context->cpus_fd < 0". Revisited all open/read/write! >> + retval = read(context->cpus_fd, &curr_cpus, sizeof(curr_cpus)); >> + if (!retval) >> + goto out_close; >> + context->orig_cpus = strdup(curr_cpus); >> + if (!context->orig_cpus) >> + goto out_err; > Need to close ->cpus_fd; > > if (!context->orig_cpus) > goto out_close; > >> + retval = write(context->cpus_fd, cpus, strlen(cpus) + 1); >> + if (!retval) >> + goto out_err; > Same as above. Use "goto out_close" instead. yep! fixed in the next version. >> + tracefs_put_tracing_file(osnoise_cpus); >> + >> + return 0; >> + >> +out_close: >> + close(context->cpus_fd); >> + context->cpus_fd = -1; >> +out_err: >> + tracefs_put_tracing_file(osnoise_cpus); >> + return 1; >> +} >> + >> +/* >> + * osnoise_restore_cpus - restore the original "osnoise/cpus" >> + * >> + * osnoise_set_cpus() saves the original data for the "osnoise/cpus" >> + * file. This function restore the original config it was previously >> + * modified. >> + */ >> +void osnoise_restore_cpus(struct osnoise_context *context) >> +{ >> + int retval; >> + >> + if (!context->orig_cpus) >> + return; >> + >> + retval = write(context->cpus_fd, context->orig_cpus, strlen(context->orig_cpus)); > __osnoise_write_runtime() check "context->cpus_fd == -1". > Is it possible here we need to check "context->cpus_fd == -1". > So, yeah, this was inconsistent. In some parts I checked the fd, on other I checked if the original value was load, so the file was opened. In the next version I am checking if the original value was loaded, and then using it to define if the fd is open. Thanks for your review Tao! -- Daniel