DPDK patches and discussions
 help / color / mirror / Atom feed
From: David Marchand <david.marchand@redhat.com>
To: Maxime Coquelin <maxime.coquelin@redhat.com>
Cc: dev <dev@dpdk.org>, "Xia, Chenbo" <chenbo.xia@intel.com>,
	 Adrian Moreno Zapata <amorenoz@redhat.com>,
	Olivier Matz <olivier.matz@6wind.com>,
	bnemeth@redhat.com
Subject: Re: [dpdk-dev] [PATCH v2 3/3] vhost: optimize vhost virtqueue struct
Date: Tue, 16 Mar 2021 14:38:58 +0100	[thread overview]
Message-ID: <CAJFAV8ymm_XKqdaJaXutByBfWUmmS6haZNzpWkcDiOi7XPqp4g@mail.gmail.com> (raw)
In-Reply-To: <20210316124153.503928-4-maxime.coquelin@redhat.com>

On Tue, Mar 16, 2021 at 1:42 PM Maxime Coquelin
<maxime.coquelin@redhat.com> wrote:
>
> This patch moves vhost_virtuqueue struct fields in order

virtqueue
You might want to add something in your local dictionary :-p.


> to both optimize packing and move hot fields on the first
> cachelines.
>
> Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
> ---
>  lib/librte_vhost/vhost.h | 52 +++++++++++++++++++++-------------------
>  1 file changed, 27 insertions(+), 25 deletions(-)
>
> diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h
> index 3a71dfeed9..ae45b05dd1 100644
> --- a/lib/librte_vhost/vhost.h
> +++ b/lib/librte_vhost/vhost.h
> @@ -133,7 +133,7 @@ struct vhost_virtqueue {
>                 struct vring_used       *used;
>                 struct vring_packed_desc_event *device_event;
>         };
> -       uint32_t                size;
> +       uint16_t                size;

There is one site in the code that could be problematic:

vhost_user_set_vring_num()
...
vq->size = msg->payload.state.num;
...
if (vq->size > 32768) {

payload.state.num is an unsigned int, so we'd better check its value
as an unsigned int, before storing to vq->size.


>
>         uint16_t                last_avail_idx;
>         uint16_t                last_used_idx;
> @@ -143,29 +143,12 @@ struct vhost_virtqueue {
>  #define VIRTIO_INVALID_EVENTFD         (-1)
>  #define VIRTIO_UNINITIALIZED_EVENTFD   (-2)
>
> -       int                     enabled;
> -       int                     access_ok;
> -       int                     ready;
> -       int                     notif_enable;
> -#define VIRTIO_UNINITIALIZED_NOTIF     (-1)
> +       bool                    enabled;
> +       bool                    access_ok;
> +       bool                    ready;

Changing those types is fine, but it is a bit odd to still see
boolean_var = 0 or boolean_var = 1 in the rest of the code.


>
>         rte_spinlock_t          access_lock;
>
> -       /* Used to notify the guest (trigger interrupt) */
> -       int                     callfd;
> -       /* Currently unused as polling mode is enabled */
> -       int                     kickfd;
> -
> -       /* Physical address of used ring, for logging */
> -       uint64_t                log_guest_addr;
> -
> -       /* inflight share memory info */
> -       union {
> -               struct rte_vhost_inflight_info_split *inflight_split;
> -               struct rte_vhost_inflight_info_packed *inflight_packed;
> -       };
> -       struct rte_vhost_resubmit_info *resubmit_inflight;
> -       uint64_t                global_counter;
>
>         union {
>                 struct vring_used_elem  *shadow_used_split;
> @@ -176,22 +159,36 @@ struct vhost_virtqueue {
>         uint16_t                shadow_aligned_idx;
>         /* Record packed ring first dequeue desc index */
>         uint16_t                shadow_last_used_idx;
> -       struct vhost_vring_addr ring_addrs;
>
> -       struct batch_copy_elem  *batch_copy_elems;
>         uint16_t                batch_copy_nb_elems;
> +       struct batch_copy_elem  *batch_copy_elems;
>         bool                    used_wrap_counter;
>         bool                    avail_wrap_counter;
>
> -       struct log_cache_entry *log_cache;
> +       /* Physical address of used ring, for logging */
>         uint16_t log_cache_nb_elem;

Indent is broken / not consistent, probably because you cut/pasted lines.


> +       uint64_t                log_guest_addr;
> +       struct log_cache_entry *log_cache;
>
>         rte_rwlock_t    iotlb_lock;
>         rte_rwlock_t    iotlb_pending_lock;
>         struct rte_mempool *iotlb_pool;
>         TAILQ_HEAD(, vhost_iotlb_entry) iotlb_list;
> -       int                             iotlb_cache_nr;
>         TAILQ_HEAD(, vhost_iotlb_entry) iotlb_pending_list;
> +       int                             iotlb_cache_nr;
> +
> +       /* Used to notify the guest (trigger interrupt) */
> +       int                     callfd;
> +       /* Currently unused as polling mode is enabled */
> +       int                     kickfd;
> +
> +       /* inflight share memory info */
> +       union {
> +               struct rte_vhost_inflight_info_split *inflight_split;
> +               struct rte_vhost_inflight_info_packed *inflight_packed;
> +       };
> +       struct rte_vhost_resubmit_info *resubmit_inflight;
> +       uint64_t                global_counter;
>
>         /* operation callbacks for async dma */
>         struct rte_vhost_async_channel_ops      async_ops;
> @@ -212,6 +209,11 @@ struct vhost_virtqueue {
>         bool            async_inorder;
>         bool            async_registered;
>         uint16_t        async_threshold;
> +
> +       int                     notif_enable;
> +#define VIRTIO_UNINITIALIZED_NOTIF     (-1)
> +
> +       struct vhost_vring_addr ring_addrs;
>  } __rte_cache_aligned;
>
>  /* Virtio device status as per Virtio specification */
> --
> 2.29.2
>



-- 
David Marchand


  reply	other threads:[~2021-03-16 13:39 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-16 12:41 [dpdk-dev] [PATCH v2 0/3] vhost: make virtqueue cache-friendly Maxime Coquelin
2021-03-16 12:41 ` [dpdk-dev] [PATCH v2 1/3] vhost: remove unused Vhost virtqueue field Maxime Coquelin
2021-03-16 12:41 ` [dpdk-dev] [PATCH v2 2/3] vhost: move dirty logging cache out of the virtqueue Maxime Coquelin
2021-03-16 13:13   ` David Marchand
2021-03-17 10:20     ` Maxime Coquelin
2021-03-16 12:41 ` [dpdk-dev] [PATCH v2 3/3] vhost: optimize vhost virtqueue struct Maxime Coquelin
2021-03-16 13:38   ` David Marchand [this message]
2021-03-17 10:26     ` Maxime Coquelin

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=CAJFAV8ymm_XKqdaJaXutByBfWUmmS6haZNzpWkcDiOi7XPqp4g@mail.gmail.com \
    --to=david.marchand@redhat.com \
    --cc=amorenoz@redhat.com \
    --cc=bnemeth@redhat.com \
    --cc=chenbo.xia@intel.com \
    --cc=dev@dpdk.org \
    --cc=maxime.coquelin@redhat.com \
    --cc=olivier.matz@6wind.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;
as well as URLs for NNTP newsgroup(s).