From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 55C2FA054F; Tue, 16 Mar 2021 14:39:18 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 726D624295C; Tue, 16 Mar 2021 14:39:13 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mails.dpdk.org (Postfix) with ESMTP id 298D04003D for ; Tue, 16 Mar 2021 14:39:12 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615901951; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=PjvMFibgg4wytU/s/vueG7036BBwsNUT1n0qdcpLkZY=; b=QZQ+gazA+giURq3HKPp3I9h78oagrktIWzDU66oLCThyCxyfjJD7UCewHvPQffSjll0KhU P4GYQ0cfxwm6FCzLRPcOsoRBsU2rXFnS+GhxgwOsGShfsOslF/oQ+KSC5hwyjZ+k4lo8G3 fvCsbZyTweAKbAIAqRH8BwGrnMr7oWo= Received: from mail-vk1-f200.google.com (mail-vk1-f200.google.com [209.85.221.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-590-hSSvjJ2iN7GQIqp8_6VAqw-1; Tue, 16 Mar 2021 09:39:10 -0400 X-MC-Unique: hSSvjJ2iN7GQIqp8_6VAqw-1 Received: by mail-vk1-f200.google.com with SMTP id r63so9979104vkg.6 for ; Tue, 16 Mar 2021 06:39:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=PjvMFibgg4wytU/s/vueG7036BBwsNUT1n0qdcpLkZY=; b=BJhBcdJtrvwTdKZ0u/5wM5fGFiBUZiPVb+wNfQZLE4XZX2tWG3NkFT9V5cZvf6h/4J 0dymyox/KyTlOEBkdTAwk7HuLtOy9Y5AyKEbx0oRrG40D8sO7rvn++8/ysRVWDsAIkcA TMNriHQiG9ejtTjLaDSsRxY4MsgrR3buGrWblZ/Gd/VBjBc6c6iZwoCwlZn/uhk7isMG dnK43NEWgx6ysahYjibLmqK8NdSLNGokaqWpVqkHDZYRHCs7QLiM06+x8A4zKAJ2Zodo 1fvPQ0FPtnlV4ePelfG+b/tjCNP2iE9NZWGxzcwKBejPyafuzycK50waAgyG18tQJyrJ yXLQ== X-Gm-Message-State: AOAM533JEyT0PfRRtmeEj8H3rDNn2MlIEY3XfhdG24WG3M7vKd9SUTr/ 4HGIQ6Pz+BvaF7cXfxSbHNRgvl6gNku2BCP4lGVKivtIlY0OeeahvV4YUML7Cd4SiemwFpzAWZT as3aHEQPogLyg9mzZIYM= X-Received: by 2002:a9f:3591:: with SMTP id t17mr7803861uad.41.1615901949521; Tue, 16 Mar 2021 06:39:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwtvFdwP6NpBEpr8fFSjgi7B9f8COogwhcyWqR237k67fip3c5a5k1x44jfnsqz0BXbfmr0SkYJ4oxMXo2Mq9Y= X-Received: by 2002:a9f:3591:: with SMTP id t17mr7803847uad.41.1615901949262; Tue, 16 Mar 2021 06:39:09 -0700 (PDT) MIME-Version: 1.0 References: <20210316124153.503928-1-maxime.coquelin@redhat.com> <20210316124153.503928-4-maxime.coquelin@redhat.com> In-Reply-To: <20210316124153.503928-4-maxime.coquelin@redhat.com> From: David Marchand Date: Tue, 16 Mar 2021 14:38:58 +0100 Message-ID: To: Maxime Coquelin Cc: dev , "Xia, Chenbo" , Adrian Moreno Zapata , Olivier Matz , bnemeth@redhat.com Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dmarchan@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Subject: Re: [dpdk-dev] [PATCH v2 3/3] vhost: optimize vhost virtqueue struct X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On Tue, Mar 16, 2021 at 1:42 PM Maxime Coquelin 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 > --- > 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