Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp5978687iob; Tue, 10 May 2022 07:51:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwpZn5amobzeGXzkeOTY5UkO07eTS+mZgcTwD6OfHrYEsWykGwBlV/mVB/+pxudGXD7KPLy X-Received: by 2002:a17:906:1ec3:b0:6cf:d118:59e2 with SMTP id m3-20020a1709061ec300b006cfd11859e2mr20380235ejj.767.1652194306374; Tue, 10 May 2022 07:51:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652194306; cv=none; d=google.com; s=arc-20160816; b=mSd47TvGDMuct7NOS8HjywN6xTEai8q9NggD7WzfiAJ0EvP6z5W6eCvS+jAOQOz7Bi p57GLbV8ZwqwJkAQTraNXY0bn48CdvU9YJnOkJ1mS+eGyr5X+0r9XJR04EF88ZKUHGgR cZdIReImvbUWayXBXcpJfSe6j3F/wCnZCN7cUz2hpe77QO1P1qhJg7Wu1eGEsRm3Y+CD GXDMPI/RbaUUi6YNxF0PNnaR8PIVCSAEjO0MlD1tLCyDIkY4BSMyslF7KjvAqayeLZTX /UOQbwdV3YRno6BzC+LZhURNYRAvEEo54FJ6ZZOuyrwkzNnawnTqiFsR0094BcfEK9nX rn5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :dkim-signature; bh=MBjlQI2uyibVlu7+Ejq7Z4/K5FS1DpSVUvjHPHaboy4=; b=mgvhRfa6pzhAvBVRNSH6APNCPnO1gdbyA0Kne/WXbuBLmZDWjDD9pl1/PI5RxEId5z vEMIsnXZ6JTWKXkOeLISXbuBPl7+BCQO73U9J87BVaiQNvIK6qMH4UZPF7UIg/ucuZhC FRyAtF/tptSGFHIMp6lKOuO2rOjTka7Velw0zE+lOkBKhbSSCPhF4u8iB7c/Yn/mP8EA s0GQbAk6IWb4c1WL1YxGnDrUnN2ZQANvWSZPPp4+Wf/1QJy9360oAe/NP10RkdU4g07N 5aEzYe+t/llSyUtC2Csp/D2Vd5e92kdaiQsEvHyGwApmU3gTDo+/02uprfmYLv0PjJZa pgHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=Ex7tvOdM; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; 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=suse.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gn30-20020a1709070d1e00b006f476161a18si18370265ejc.744.2022.05.10.07.51.22; Tue, 10 May 2022 07:51:46 -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=@suse.de header.s=susede2_rsa header.b=Ex7tvOdM; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; 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=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241004AbiEJLei (ORCPT + 99 others); Tue, 10 May 2022 07:34:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233550AbiEJLec (ORCPT ); Tue, 10 May 2022 07:34:32 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D545324EA08; Tue, 10 May 2022 04:30:34 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 921C61F8B4; Tue, 10 May 2022 11:30:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1652182233; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=MBjlQI2uyibVlu7+Ejq7Z4/K5FS1DpSVUvjHPHaboy4=; b=Ex7tvOdMwC9HCxyktFuFnlGrHLjZ6vCkmEwN8xHkuNT59UdjniLk0s8XPUYPw2fEwohYhm DJyQhr5kfvEPDdW25tT5/mcCa02KeFf+1Lrq6ieRGWA3HGexK+pbbDk/PrPSNcnIK+VkwF XsxlcV0DVrTq35vWPRuY/jNHEqlkvCE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1652182233; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=MBjlQI2uyibVlu7+Ejq7Z4/K5FS1DpSVUvjHPHaboy4=; b=wPe4gt5+vEYMpulFqg+80Bd2RNGxgVr2pSTrhDPX1imYT2oAyEUjMK6YnPjmmQLmSXhYoL gNs3gzmxIVqJcXCA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 82FAD13AA5; Tue, 10 May 2022 11:30:33 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 9fz5H9lMemLTawAAMHmgww (envelope-from ); Tue, 10 May 2022 11:30:33 +0000 Date: Tue, 10 May 2022 13:30:33 +0200 From: Daniel Wagner To: Daniel Bristot de Oliveira Cc: Steven Rostedt , linux-trace-devel@vger.kernel.org, linux-kernel@vger.kernel.org, John Kacur , Tao Zhou Subject: Re: [PATCH V3] rtla: Remove procps-ng dependency Message-ID: <20220510113033.auxhunymxbhioi4z@carbon.lan> References: <553032a74ccdb1e6ae4dda543b7c4430ce8fae1a.1652176288.git.bristot@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <553032a74ccdb1e6ae4dda543b7c4430ce8fae1a.1652176288.git.bristot@kernel.org> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 On Tue, May 10, 2022 at 11:57:04AM +0200, Daniel Bristot de Oliveira wrote: > +static int procfs_is_workload_pid(const char *comm_prefix, struct dirent *proc_entry) > +{ > + char buffer[MAX_PATH]; > + int comm_fd, retval; > + char *t_name; > + > + if (proc_entry->d_type != DT_DIR) > + return 0; > + > + if (*proc_entry->d_name == '.') > + return 0; > + > + /* check if the string is a pid */ > + for (t_name = proc_entry->d_name; t_name; t_name++) { > + if (!isdigit(*t_name)) > + break; > + } > + > + if (*t_name != '\0') > + return 0; > + > + snprintf(buffer, MAX_PATH, "/proc/%s/comm", proc_entry->d_name); > + comm_fd = open(buffer, O_RDONLY); > + if (comm_fd < 0) > + return 0; > + > + memset(buffer, 0, MAX_PATH); > + retval = read(comm_fd, buffer, MAX_PATH); > + > + close(comm_fd); > + > + if (retval <= 0) > + return 0; > + > + retval = strncmp(comm_prefix, buffer, strlen(comm_prefix)); > + if (retval) > + return 0; > + > + /* comm already have \n */ > + debug_msg("Found workload pid:%s comm:%s", proc_entry->d_name, buffer); > + > + return 1; > +} > + > +/* > + * set_comm_sched_attr - set sched params to threads starting with char *comm_prefix > + * > + * This function uses /procfs to list the currently running threads and then set the > + * sched_attr *attr to the threads that start with char *comm_prefix. It is > * mainly used to set the priority to the kernel threads created by the > * tracers. > */ > -int set_comm_sched_attr(const char *comm, struct sched_attr *attr) > +int set_comm_sched_attr(const char *comm_prefix, struct sched_attr *attr) > { > - int flags = PROC_FILLCOM | PROC_FILLSTAT; > - PROCTAB *ptp; > - proc_t task; > + struct dirent *proc_entry; > + DIR *procfs; > int retval; > > - ptp = openproc(flags); > - if (!ptp) { > - err_msg("error openproc()\n"); > - return -ENOENT; > + if (strlen(comm_prefix) >= MAX_PATH) { > + err_msg("Command prefix is too long: %d < strlen(%s)\n", > + MAX_PATH, comm_prefix); > + exit(EINVAL); > } > > - memset(&task, 0, sizeof(task)); > + procfs = opendir("/proc"); Maybe you want to check if procfs is a valid handle before using it. > + > + while ((proc_entry = readdir(procfs))) { > > - while (readproc(ptp, &task)) { > - retval = strncmp(comm, task.cmd, strlen(comm)); > - if (retval) > + retval = procfs_is_workload_pid(comm_prefix, proc_entry); > + if (!retval) > continue; > - retval = __set_sched_attr(task.tid, attr); > - if (retval) > + > + /* procfs_is_workload_pid confirmed it is a pid */ > + retval = __set_sched_attr(atoi(proc_entry->d_name), attr); > + if (retval) { > + err_msg("Error setting sched attributes for pid:%s\n", proc_entry->d_name); > goto out_err; > - } > + } > > - closeproc(ptp); > + debug_msg("Set sched attributes for pid:%s\n", proc_entry->d_name); > + } > return 0; > > out_err: > - closeproc(ptp); > + closedir(procfs); > return 1; > } > > diff --git a/tools/tracing/rtla/src/utils.h b/tools/tracing/rtla/src/utils.h > index fa08e374870a..5571afd3b549 100644 > --- a/tools/tracing/rtla/src/utils.h > +++ b/tools/tracing/rtla/src/utils.h > @@ -6,6 +6,7 @@ > * '18446744073709551615\0' > */ > #define BUFF_U64_STR_SIZE 24 > +#define MAX_PATH 1024 linux/limits.h defined MAX_PATH as well, though as 4096. Maybe use that definition? If you want to make it dynamic you could use fpathconf(fd, _PC_PATH_MAX) but one could argue that is over engineering :) Thanks for the fix. Anyway just nitpicking. Reviewed-by: Daniel Wagner