All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Jiri Olsa <jolsa@kernel.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
	Naveen N Rao <naveen@kernel.org>,
	"David S. Miller" <davem@davemloft.net>,
	Josh Poimboeuf <jpoimboe@kernel.org>,
	Jason Baron <jbaron@akamai.com>,
	Alice Ryhl <aliceryhl@google.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Ard Biesheuvel <ardb@kernel.org>,
	Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
	Alan Maguire <almagui@kernel.org>,
	x86@kernel.org, linux-trace-kernel@vger.kernel.org,
	linux-kernel@vger.kernel.org, bpf@vger.kernel.org
Subject: Re: [PATCH 01/13] static_call: Index code text reservation lookups
Date: Thu, 12 Nov 2026 10:07:34 +0100	[thread overview]
Message-ID: <20261112090734.GH2668804@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20261109194916.1089703-2-jolsa@kernel.org>

On Mon, Nov 09, 2026 at 08:49:04PM +0100, Jiri Olsa wrote:
> --- a/kernel/static_call_inline.c
> +++ b/kernel/static_call_inline.c
> @@ -15,6 +15,18 @@ extern struct static_call_site __start_static_call_sites[],
>  extern struct static_call_tramp_key __start_static_call_tramp_key[],
>  				    __stop_static_call_tramp_key[];
>  
> +struct static_call_site_index {
> +	struct static_call_site *base;
> +	unsigned int nr;
> +	u32 entries[];
> +};
> +
> +/*
> + * Index static call sites by code address for text reservation lookups.
> + * The site table itself is sorted by static-call-key address.
> + */
> +static struct static_call_site_index *static_call_site_index;
> +
>  int static_call_initialized;
>  
>  /*
> @@ -41,7 +53,7 @@ static void static_call_unlock(void)
>  	mutex_unlock(&static_call_mutex);
>  }
>  
> -static inline void *static_call_addr(struct static_call_site *site)
> +static inline void *static_call_addr(const struct static_call_site *site)
>  {
>  	return (void *)((long)site->addr + (long)&site->addr);
>  }
> @@ -301,6 +313,79 @@ static int addr_conflict(struct static_call_site *site, void *start, void *end)
>  	return 0;
>  }
>  
> +static int static_call_site_index_cmp(const void *a, const void *b, const void *priv)
> +{
> +	const struct static_call_site *base = priv;
> +	unsigned int ia = *(u32 *)a;
> +	unsigned int ib = *(u32 *)b;
> +	unsigned long ca = (unsigned long)static_call_addr(base + ia);
> +	unsigned long cb = (unsigned long)static_call_addr(base + ib);
> +
> +	return cmp_int(ca, cb);
> +}
> +
> +static struct static_call_site_index *
> +static_call_site_index_alloc(struct static_call_site *start,
> +			     struct static_call_site *stop)
> +{
> +	struct static_call_site_index *index;
> +	unsigned int nr = stop - start;
> +	unsigned int i;
> +
> +	if (!nr)
> +		return NULL;
> +
> +	index = kvmalloc_flex(*index, entries, nr, GFP_KERNEL);
> +	if (!index)
> +		return NULL;
> +
> +	index->nr = nr;
> +	index->base = start;
> +	for (i = 0; i < nr; i++)
> +		index->entries[i] = i;
> +
> +	sort_r(index->entries, nr, sizeof(index->entries[0]),
> +	       static_call_site_index_cmp, NULL, start);
> +
> +	return index;
> +}
> +
> +static int
> +static_call_site_index_text_reserved(struct static_call_site_index *index,
> +				     void *start, void *end, bool init)
> +{
> +	unsigned int low = 0, high = index->nr, i;
> +
> +	/* Find the first site after @start. */
> +	while (low < high) {
> +		unsigned int mid = low + (high - low) / 2;
> +		void *addr = static_call_addr(index->base + index->entries[mid]);
> +
> +		if (addr <= start)
> +			low = mid + 1;
> +		else
> +			high = mid;
> +	}
> +
> +	/* The preceding site may overlap @start. */
> +	if (low)
> +		low--;
> +
> +	for (i = low; i < index->nr; i++) {
> +		struct static_call_site *site = index->base + index->entries[i];
> +		void *addr = static_call_addr(site);
> +
> +		/* Later sites cannot overlap once this address is past @end. */
> +		if (addr > end)
> +			break;
> +		if ((init || !static_call_is_init(site)) &&
> +		    addr_conflict(site, start, end))
> +			return 1;
> +	}
> +
> +	return 0;
> +}

Looking at this in a little more detail; I'm confused. 

You're literally adding an index, so that you can find the
static_call_size, while all you really need is static_call_addr().

That is, you could have just created an array of relocated site->addr
and sorted that, that would safe you a ton of indirection all around.

That is:

	index->entries[i] = (long)static_call_addr(start + i) - (long)&index->entries[i];

That will make your lookup take at least half the amount of loads.


Also, you really should support modules, there is no point being fast
until you load a module.

  parent reply	other threads:[~2026-11-12  9:07 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-09 19:49 [PATCH 00/13] kprobes: Reduce registration and optimization lookup costs Jiri Olsa
2026-11-09 19:49 ` [PATCH 01/13] static_call: Index code text reservation lookups Jiri Olsa
2026-11-12  8:27   ` Peter Zijlstra
2026-11-12 18:33     ` Jiri Olsa
2026-11-12  8:34   ` Peter Zijlstra
2026-11-12 18:33     ` Jiri Olsa
2026-11-12  9:07   ` Peter Zijlstra [this message]
2026-11-12 10:11     ` Peter Zijlstra
2026-11-12 18:33       ` Jiri Olsa
2026-11-09 19:49 ` [PATCH 02/13] jump_label: Index " Jiri Olsa
2026-11-12  8:33   ` Peter Zijlstra
2026-11-12 18:33     ` Jiri Olsa
2026-11-09 19:49 ` [PATCH 03/13] jump_label/x86: Avoid decoding instructions for jump entry size Jiri Olsa
2026-11-12  8:39   ` Peter Zijlstra
2026-11-12 18:33     ` Jiri Olsa
2026-11-09 19:55 ` [PATCH 04/13] kprobes: Maintain an rbtree of registered probes Jiri Olsa
2026-11-10  8:12   ` Masami Hiramatsu (Google)
2026-11-10 10:37     ` Jiri Olsa
2026-11-10 15:38       ` Masami Hiramatsu (Google)
2026-11-11 10:49         ` Jiri Olsa
2026-11-10 23:45   ` sashiko-bot
2026-11-12  8:50   ` Peter Zijlstra
2026-11-09 19:56 ` [PATCH 05/13] kprobes: Add an iterator for address ranges Jiri Olsa
2026-11-09 19:56 ` [PATCH 06/13] kprobes: Add an address iterator for probe lookup Jiri Olsa
2026-11-09 19:56 ` [PATCH 07/13] kprobes: Use kprobe iterator in get_optimized_kprobe Jiri Olsa
2026-11-09 19:57 ` [PATCH 08/13] x86/kprobes: Use kprobe iterator in __recover_optprobed_insn Jiri Olsa
2026-11-09 19:57 ` [PATCH 09/13] x86/kprobes: Use kprobe iterator in arch_check_optimized_kprobe Jiri Olsa
2026-11-11  0:17   ` sashiko-bot
2026-11-09 19:57 ` [PATCH 10/13] x86/kprobes: Use kprobe address iterator in can_optimize Jiri Olsa
2026-11-09 19:57 ` [PATCH 11/13] x86/kprobes: Use kprobe address iterator in can_probe Jiri Olsa
2026-11-09 19:58 ` [PATCH 12/13] x86/kprobes: Use kprobe address iterator in in copy_optimized_instructions Jiri Olsa
2026-11-09 19:58 ` [PATCH 13/13] samples/kprobes: Add batch probe example Jiri Olsa
2026-11-11  0:49   ` sashiko-bot
2026-11-11  2:20   ` kernel test robot

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=20261112090734.GH2668804@noisy.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=aliceryhl@google.com \
    --cc=almagui@kernel.org \
    --cc=ardb@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=davem@davemloft.net \
    --cc=jbaron@akamai.com \
    --cc=jolsa@kernel.org \
    --cc=jpoimboe@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=mingo@redhat.com \
    --cc=naveen@kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=tglx@kernel.org \
    --cc=x86@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.