linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Bristot de Oliveira <bristot@kernel.org>
To: Daniel Wagner <dwagner@suse.de>
Cc: Steven Rostedt <rostedt@goodmis.org>,
	linux-trace-devel@vger.kernel.org, linux-kernel@vger.kernel.org,
	John Kacur <jkacur@redhat.com>, Tao Zhou <tao.zhou@linux.dev>
Subject: Re: [PATCH V3] rtla: Remove procps-ng dependency
Date: Tue, 10 May 2022 14:20:20 +0200	[thread overview]
Message-ID: <6bd4ced4-88b9-89ce-9674-6678784a2f47@kernel.org> (raw)
In-Reply-To: <20220510113033.auxhunymxbhioi4z@carbon.lan>

On 5/10/22 13:30, Daniel Wagner wrote:
> On Tue, May 10, 2022 at 11:57:04AM +0200, Daniel Bristot de Oliveira wrote:

>> -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.

Yes I want!

>> +
>> +	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.

Fedora did not find it by default... let's just define our own here.

> Reviewed-by: Daniel Wagner <dwagner@suse.de>
Thanks!
-- Daniel


      reply	other threads:[~2022-05-10 12:20 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-10  9:57 [PATCH V3] rtla: Remove procps-ng dependency Daniel Bristot de Oliveira
2022-05-10 11:30 ` Daniel Wagner
2022-05-10 12:20   ` Daniel Bristot de Oliveira [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6bd4ced4-88b9-89ce-9674-6678784a2f47@kernel.org \
    --to=bristot@kernel.org \
    --cc=dwagner@suse.de \
    --cc=jkacur@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=tao.zhou@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).