Linux DTrace development list
 help / color / mirror / Atom feed
From: Nick Alcock <nix@esperi.org.uk>
To: Kris Van Hees <kris.van.hees@oracle.com>
Cc: dtrace@lists.linux.dev, dtrace-devel@oss.oracle.com
Subject: Re: [PATCH 09/20] libdtrace: streamline kernel symbol parsing and module lookup
Date: Tue, 24 Nov 2026 15:39:36 +0000	[thread overview]
Message-ID: <87ik1mgrwn.fsf@esperi.org.uk> (raw)
In-Reply-To: <au9Jamtz3PtdAnnr@kvh-deb-bpf>

On 7 Nov 2026, Kris Van Hees uttered the following:

> On Fri, Nov 06, 2026 at 12:56:47PM +0000, Nick Alcock wrote:
>> On 30 Oct 2026, Kris Van Hees told this:
>> 
>> Is it really worth replacing sscanf(), which though it's a bit clunky is
>> at least used by other people, with even more hand-rolled parsing code?
>> The hex parser isn't too bad, but this:
>> 
>> > +static int
>> > +dt_modsym_parse(const char *line, int kind, dt_kallsym_t *sym)
>> > +{
>> > +	const char *end;
>> > +	uint64_t value;
>> > +	size_t len;
>> > +
>> > +	if (dt_modsym_hex(&line, &value) != 0)
>> > +		return -1;
>> > +	sym->addr = value;
>> > +	sym->size = 1;
>> > +	if (kind == DT_MODSYM_KALLMODSYMS) {
>> > +		if (dt_modsym_hex(&line, &value) != 0 || value > SIZE_MAX)
>> > +			return -1;
>> > +		sym->size = value;
>> > +	}
>> > +	while (isspace((unsigned char)*line))
>> > +		line++;
>> > +	if (*line == '\0')
>> > +		return -1;
>> > +	sym->type = *line++;
>> > +	if (!isspace((unsigned char)*line))
>> > +		return -1;
>> > +	while (isspace((unsigned char)*line))
>> > +		line++;
>> > +	len = strcspn(line, " \t\r\n");
>> > +	if (len == 0 || len >= sizeof(sym->name))
>> > +		return -1;
>> > +	memcpy(sym->name, line, len);
>> > +	sym->name[len] = '\0';
>> > +	line += len;
>> > +	while (isspace((unsigned char)*line))
>> > +		line++;
>> > +	if (*line == '\0') {
>> > +		strcpy(sym->mod, "vmlinux");
>> > +		return 0;
>> > +	}
>> > +	if (*line++ != '[' || (end = strchr(line, ']')) == NULL)
>> > +		return -1;
>> > +	len = end - line;
>> > +	if (len == 0 || len >= sizeof(sym->mod))
>> > +		return -1;
>> > +	memcpy(sym->mod, line, len);
>> > +	sym->mod[len] = '\0';
>> > +	return 1;		/* Explicit module name(s). */
>> > +}
>> 
>> ... strikes me as exactly the sort of thing you should never ever do as
>> root.
>>
>> Is sscanf() really noticable in profiles? (I guess it might be: we are
>> calling it hundreds of thousands of times, after all...)
>
> Yes - benchmarking the change showed on average a 5x speedup compared to
> the sscanf() version, which is quite significant during dtrace startup.

Good grief!

Reviewed-by: Nick Alcock <nix@esperi.org.uk>

-- 
NULL && (void)

      reply	other threads:[~2026-11-24 15:39 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-30 19:36 [PATCH 09/20] libdtrace: streamline kernel symbol parsing and module lookup Kris Van Hees
2026-11-06 12:56 ` Nick Alcock
2026-11-07 15:53   ` Kris Van Hees
2026-11-24 15:39     ` Nick Alcock [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=87ik1mgrwn.fsf@esperi.org.uk \
    --to=nix@esperi.org.uk \
    --cc=dtrace-devel@oss.oracle.com \
    --cc=dtrace@lists.linux.dev \
    --cc=kris.van.hees@oracle.com \
    /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