Linux Trace Kernel
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Vincent Donnefort <vdonnefort@google.com>
Cc: mhiramat@kernel.org, linux-kernel@vger.kernel.org,
	linux-trace-kernel@vger.kernel.org, kernel-team@android.com
Subject: Re: [PATCH v9 1/2] ring-buffer: Introducing ring-buffer mapping functions
Date: Thu, 21 Dec 2023 12:58:13 -0500	[thread overview]
Message-ID: <20231221125813.673293a2@gandalf.local.home> (raw)
In-Reply-To: <20231221173523.3015715-2-vdonnefort@google.com>

On Thu, 21 Dec 2023 17:35:22 +0000
Vincent Donnefort <vdonnefort@google.com> wrote:

> @@ -5999,6 +6078,307 @@ int ring_buffer_subbuf_order_set(struct trace_buffer *buffer, int order)
>  }
>  EXPORT_SYMBOL_GPL(ring_buffer_subbuf_order_set);
>  

The kernel developers have agreed to allow loop variables to be declared in
loops. This will simplify these macros:



> +#define subbuf_page(off, start) \
> +	virt_to_page((void *)(start + (off << PAGE_SHIFT)))
> +
> +#define foreach_subbuf_page(off, sub_order, start, page)	\
> +	for (off = 0, page = subbuf_page(0, start);		\
> +	     off < (1 << sub_order);				\
> +	     off++, page = subbuf_page(off, start))

#define foreach_subbuf_page(sub_order, start, page)		\
	for (int __off = 0, page = subbuf_page(0, (start));	\
	     __off < (1 << (sub_order));			\
	     __off++, page = subbuf_page(__off, (start)))

And parameters as r-values should always be wrapped in parenthesis.

> +
> +static inline void subbuf_map_prepare(unsigned long subbuf_start, int order)
> +{
> +	struct page *page;
> +	int subbuf_off;

Then you can remove the "subbuf_off".

> +
> +	/*
> +	 * When allocating order > 0 pages, only the first struct page has a
> +	 * refcount > 1. Increasing the refcount here ensures none of the struct
> +	 * page composing the sub-buffer is freeed when the mapping is closed.

Nice catch by the way ;-)

-- Steve

> +	 */
> +	foreach_subbuf_page(subbuf_off, order, subbuf_start, page)
> +		page_ref_inc(page);
> +}
> +
> +static inline void subbuf_unmap(unsigned long subbuf_start, int order)
> +{
> +	struct page *page;
> +	int subbuf_off;
> +
> +	foreach_subbuf_page(subbuf_off, order, subbuf_start, page) {
> +		page_ref_dec(page);
> +		page->mapping = NULL;
> +	}
> +}
> +

  parent reply	other threads:[~2023-12-21 17:57 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-21 17:35 [PATCH v9 0/2] Introducing trace buffer mapping by user-space Vincent Donnefort
2023-12-21 17:35 ` [PATCH v9 1/2] ring-buffer: Introducing ring-buffer mapping functions Vincent Donnefort
2023-12-21 17:51   ` Steven Rostedt
2023-12-21 17:58   ` Steven Rostedt [this message]
2024-01-04 18:28     ` Steven Rostedt
2023-12-21 17:35 ` [PATCH v9 2/2] tracing: Allow user-space mapping of the ring-buffer Vincent Donnefort

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=20231221125813.673293a2@gandalf.local.home \
    --to=rostedt@goodmis.org \
    --cc=kernel-team@android.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=vdonnefort@google.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