From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
To: Andrii Nakryiko <andrii@kernel.org>
Cc: linux-trace-kernel@vger.kernel.org, rostedt@goodmis.org,
peterz@infradead.org, oleg@redhat.com, bpf@vger.kernel.org,
linux-kernel@vger.kernel.org, jolsa@kernel.org
Subject: Re: [PATCH v2] uprobes: make trace_uprobe->nhit counter a per-CPU one
Date: Tue, 13 Aug 2024 22:30:14 +0900 [thread overview]
Message-ID: <20240813223014.1a5093ede1a5046aaedea34a@kernel.org> (raw)
In-Reply-To: <20240809192357.4061484-1-andrii@kernel.org>
On Fri, 9 Aug 2024 12:23:57 -0700
Andrii Nakryiko <andrii@kernel.org> wrote:
> trace_uprobe->nhit counter is not incremented atomically, so its value
> is questionable in when uprobe is hit on multiple CPUs simultaneously.
>
> Also, doing this shared counter increment across many CPUs causes heavy
> cache line bouncing, limiting uprobe/uretprobe performance scaling with
> number of CPUs.
>
> Solve both problems by making this a per-CPU counter.
>
This looks good to me. I would like to pick this to linux-trace/probes/for-next.
> @@ -62,7 +63,7 @@ struct trace_uprobe {
> struct uprobe *uprobe;
BTW, what is this change? I couldn't cleanly apply this to the v6.11-rc3.
Which tree would you working on? (I missed something?)
Thanks,
> unsigned long offset;
> unsigned long ref_ctr_offset;
> - unsigned long nhit;
> + unsigned long __percpu *nhits;
> struct trace_probe tp;
> };
>
> @@ -337,6 +338,12 @@ alloc_trace_uprobe(const char *group, const char *event, int nargs, bool is_ret)
> if (!tu)
> return ERR_PTR(-ENOMEM);
>
> + tu->nhits = alloc_percpu(unsigned long);
> + if (!tu->nhits) {
> + ret = -ENOMEM;
> + goto error;
> + }
> +
> ret = trace_probe_init(&tu->tp, event, group, true, nargs);
> if (ret < 0)
> goto error;
> @@ -349,6 +356,7 @@ alloc_trace_uprobe(const char *group, const char *event, int nargs, bool is_ret)
> return tu;
>
> error:
> + free_percpu(tu->nhits);
> kfree(tu);
>
> return ERR_PTR(ret);
> @@ -362,6 +370,7 @@ static void free_trace_uprobe(struct trace_uprobe *tu)
> path_put(&tu->path);
> trace_probe_cleanup(&tu->tp);
> kfree(tu->filename);
> + free_percpu(tu->nhits);
> kfree(tu);
> }
>
> @@ -815,13 +824,21 @@ static int probes_profile_seq_show(struct seq_file *m, void *v)
> {
> struct dyn_event *ev = v;
> struct trace_uprobe *tu;
> + unsigned long nhits;
> + int cpu;
>
> if (!is_trace_uprobe(ev))
> return 0;
>
> tu = to_trace_uprobe(ev);
> +
> + nhits = 0;
> + for_each_possible_cpu(cpu) {
> + nhits += READ_ONCE(*per_cpu_ptr(tu->nhits, cpu));
> + }
> +
> seq_printf(m, " %s %-44s %15lu\n", tu->filename,
> - trace_probe_name(&tu->tp), tu->nhit);
> + trace_probe_name(&tu->tp), nhits);
> return 0;
> }
>
> @@ -1507,7 +1524,8 @@ static int uprobe_dispatcher(struct uprobe_consumer *con, struct pt_regs *regs)
> int ret = 0;
>
> tu = container_of(con, struct trace_uprobe, consumer);
> - tu->nhit++;
> +
> + this_cpu_inc(*tu->nhits);
>
> udd.tu = tu;
> udd.bp_addr = instruction_pointer(regs);
> --
> 2.43.5
>
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
next prev parent reply other threads:[~2024-08-13 13:30 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-09 19:23 [PATCH v2] uprobes: make trace_uprobe->nhit counter a per-CPU one Andrii Nakryiko
2024-08-13 13:30 ` Masami Hiramatsu [this message]
2024-08-13 15:41 ` Oleg Nesterov
2024-08-25 10:15 ` Masami Hiramatsu
2024-08-26 16:17 ` Andrii Nakryiko
2024-08-13 14:50 ` Oleg Nesterov
2024-08-13 17:05 ` Andrii Nakryiko
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=20240813223014.1a5093ede1a5046aaedea34a@kernel.org \
--to=mhiramat@kernel.org \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=oleg@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.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.