DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Morten Brørup" <mb@smartsharesystems.com>
To: "Tyler Retzlaff" <roretzla@linux.microsoft.com>, <dev@dpdk.org>
Cc: "Bruce Richardson" <bruce.richardson@intel.com>,
	"Stephen Hemminger" <stephen@networkplumber.org>,
	"Thomas Monjalon" <thomas@monjalon.net>
Subject: RE: [PATCH 4/4] dispatcher: use alloca instead of vla multi dimensional
Date: Sat, 6 Apr 2024 17:49:11 +0200	[thread overview]
Message-ID: <98CBD80474FA8B44BF855DF32C47DC35E9F374@smartserver.smartshare.dk> (raw)
In-Reply-To: <1712250913-1977-5-git-send-email-roretzla@linux.microsoft.com>

> From: Tyler Retzlaff [mailto:roretzla@linux.microsoft.com]
> Sent: Thursday, 4 April 2024 19.15
> 
> RFC sample illustrating conversion of multi-dimensional VLA to use
> alloca().
> 
> Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
> ---
>  lib/dispatcher/rte_dispatcher.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/lib/dispatcher/rte_dispatcher.c
> b/lib/dispatcher/rte_dispatcher.c
> index 7934917..f154c26 100644
> --- a/lib/dispatcher/rte_dispatcher.c
> +++ b/lib/dispatcher/rte_dispatcher.c
> @@ -119,7 +119,7 @@ struct rte_dispatcher {
>  	struct rte_event *events, uint16_t num_events)
>  {
>  	int i;
> -	struct rte_event bursts[EVD_MAX_HANDLERS][num_events];
> +	struct rte_event *bursts = alloca(sizeof(struct rte_event) *
> EVD_MAX_HANDLERS * num_events);

This is an interesting example, because keeping the allocated memory tight probably has better cache performance than a max sized multi dimensional array, such as bursts[EVD_MAX_HANDLERS][RTE_MAX_EVENT_BURST_SIZE].

And multiplication on modern CPUs are not much slower than left shifting, as they were on CPUs ages ago.

So this suggested solution for multi dimensional arrays seems preferable.

>  	uint16_t burst_lens[EVD_MAX_HANDLERS] = { 0 };
>  	uint16_t drop_count = 0;
>  	uint16_t dispatch_count;
> @@ -136,7 +136,7 @@ struct rte_dispatcher {
>  			continue;
>  		}
> 
> -		bursts[handler_idx][burst_lens[handler_idx]] = *event;
> +		bursts[handler_idx * num_events + burst_lens[handler_idx]]
> = *event;
>  		burst_lens[handler_idx]++;
>  	}
> 
> @@ -152,7 +152,7 @@ struct rte_dispatcher {
>  			continue;
> 
>  		handler->process_fun(dispatcher->event_dev_id, port-
> >port_id,
> -				     bursts[i], len, handler->process_data);
> +				     &bursts[i * num_events], len, handler-
> >process_data);
> 
>  		dispatched += len;
> 
> --
> 1.8.3.1


  reply	other threads:[~2024-04-06 15:49 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-07 19:32 RFC acceptable handling of VLAs across toolchains Tyler Retzlaff
2023-11-08  2:31 ` Stephen Hemminger
2023-11-08  3:25   ` Tyler Retzlaff
2023-11-08  8:19     ` Morten Brørup
2023-11-08 16:51 ` Stephen Hemminger
2023-11-08 17:48   ` Morten Brørup
2023-11-09 10:25     ` RFC: default burst sizes in rte_config Morten Brørup
2023-11-09 20:26   ` RFC acceptable handling of VLAs across toolchains Tyler Retzlaff
2024-03-21  0:12     ` Tyler Retzlaff
2024-04-04 17:15 ` [PATCH 0/4] RFC samples converting VLA to alloca Tyler Retzlaff
2024-04-04 17:15   ` [PATCH 1/4] latencystats: use alloca instead of vla trivial Tyler Retzlaff
2024-04-06 15:28     ` Morten Brørup
2024-04-07  9:36       ` Mattias Rönnblom
2024-04-07 17:00         ` Stephen Hemminger
2024-04-04 17:15   ` [PATCH 2/4] hash: " Tyler Retzlaff
2024-04-06 16:01     ` Morten Brørup
2024-04-04 17:15   ` [PATCH 3/4] vhost: use alloca instead of vla sizeof Tyler Retzlaff
2024-04-06 22:30     ` Morten Brørup
2024-04-04 17:15   ` [PATCH 4/4] dispatcher: use alloca instead of vla multi dimensional Tyler Retzlaff
2024-04-06 15:49     ` Morten Brørup [this message]
2024-04-07  9:31   ` [PATCH 0/4] RFC samples converting VLA to alloca Mattias Rönnblom
2024-04-07 11:07     ` Morten Brørup
2024-04-07 17:03       ` Stephen Hemminger
2024-04-08 15:27         ` Tyler Retzlaff
2024-04-08 15:53           ` Morten Brørup
2024-04-09  8:28             ` Konstantin Ananyev
2024-04-09 15:08               ` Tyler Retzlaff
2024-04-10  9:58                 ` Konstantin Ananyev
2024-04-10 17:03                   ` Tyler Retzlaff
2024-04-10  7:32             ` Mattias Rönnblom
2024-04-10  7:52               ` Morten Brørup
2024-04-10 17:04               ` Tyler Retzlaff
2024-04-10  7:27           ` Mattias Rönnblom
2024-04-10 17:10             ` Tyler Retzlaff

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=98CBD80474FA8B44BF855DF32C47DC35E9F374@smartserver.smartshare.dk \
    --to=mb@smartsharesystems.com \
    --cc=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    --cc=roretzla@linux.microsoft.com \
    --cc=stephen@networkplumber.org \
    --cc=thomas@monjalon.net \
    /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;
as well as URLs for NNTP newsgroup(s).