mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Daniel Bristot de Oliveira <bristot@kernel.org>
To: Tao Zhou <tao.zhou@linux.dev>
Cc: Steven Rostedt <rostedt@goodmis.org>,
	linux-trace-devel@vger.kernel.org, linux-kernel@vger.kernel.org,
	John Kacur <jkacur@redhat.com>, Daniel Wagner <dwagner@suse.de>
Subject: Re: [PATCH v2] rtla: Remove procps-ng dependency
Date: Fri, 6 May 2022 17:39:58 +0200	[thread overview]
Message-ID: <1ebd6c1d-4409-df70-165c-6f181764a617@kernel.org> (raw)
In-Reply-To: <YnU5gtSFW8Wl54iv@geo.homenetwork>

On 5/6/22 17:06, Tao Zhou wrote:
> On Fri, Apr 29, 2022 at 03:01:48PM +0200,
> Daniel Bristot de Oliveira wrote:
> 
>> Daniel Wagner reported to me that readproc.h got deprecated. Also,
>> while the procps-ng library was available on Fedora, it was not available
>> on RHEL, which is a piece of evidence that it was not that used.
>>
>> rtla uses procps-ng only to find the PID of the tracers' workload.
>>
>> I used the procps-ng library to avoid reinventing the wheel. But in this
>> case, reinventing the wheel took me less time than the time we already
>> took trying to work around problems.
>>
>> Implement a function that reads /proc/ entries, checking if:
>> 	- the entry is a directory
>> 	- the directory name is composed only of digits (PID)
>> 	- the directory contains the comm file
>> 	- the comm file contains a comm that matches the tracers'
>> 	  workload prefix.
>> 	- then return true; otherwise, return false.
>>
>> And use it instead of procps-ng.
>>
>> Changes from V1:
>>   - Use a single buffer for comm and comm_path
>>   - Cause an error in case of a too long command prefix
>>   - Do a close_dir()
>>   - Improve log messages
>>
>> Cc: John Kacur <jkacur@redhat.com>
>> Cc: Steven Rostedt <rostedt@goodmis.org>
>> Fixes: b1696371d865 ("rtla: Helper functions for rtla")
>> Reported-by: Daniel Wagner <dwagner@suse.de>
>> Signed-off-by: Daniel Bristot de Oliveira <bristot@kernel.org>


[...]

>> +
>>  /*
>> - * set_comm_sched_attr - set sched params to threads starting with char *comm
>> + * procfs_is_workload_pid - check if a procfs entry contains a comm_prefix* comm
>> + *
>> + * Check if the procfs entry is a directory of a process, and then check if the
>> + * process has a comm with the prefix set in char *comm_prefix. As the
>> + * current users of this function only check for kernel threads, there is no
>> + * need to check for the threads for the process.
>>   *
>> - * This function uses procps to list the currently running threads and then
>> - * set the sched_attr *attr to the threads that start with char *comm. It is
>> + * Return: True if the proc_entry contains a comm file with comm_prefix*.
>> + * Otherwise returns false.
>> + */
>> +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;
> 
> Need a blank..
> char *t_name;


right

>> +
>> +	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;
> 
> 
> Confused.
> 
> For example:
> comm_prefix is "osnoise/", buffer is "osnoise\n"(as said by comment below),
> strlen_prefix is 8. The return value of strncmp() is 1 and not set sched attr.

it should not set "osnoise" thread priority... so it is correct.

> Or use "osnoise" as the comm_prefix. Or am I miss something here.

I am looking for "osnoise/$CPU" threads, not "osnoise" threads. Run rtla osnoise
with log messages (-D) you will see it finding the expected threads.

>> +	/* 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 procps to list the currently running threads and then set the
> 
> s/procps/procfs/

right

Thanks
-- Daniel
> 
> Thanks,
> Tao

      reply	other threads:[~2022-05-06 15:40 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-29 13:01 Daniel Bristot de Oliveira
2022-05-05 16:16 ` John Kacur
2022-05-05 16:21   ` Daniel Bristot de Oliveira
2022-05-06 15:06 ` Tao Zhou
2022-05-06 15:39   ` 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=1ebd6c1d-4409-df70-165c-6f181764a617@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

all inboxes | Powered by JetHome®