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 A3D77428BF; Mon, 3 Apr 2023 17:26:40 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 77CAB40ED7; Mon, 3 Apr 2023 17:26:40 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id E1B2C40A7E for ; Mon, 3 Apr 2023 17:26:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680535598; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LvFWBlcDOuBnQ7FNkTntenG7tkgF0fyWos3zlOizcHM=; b=VMTNmMlqLNC2XPk7sS3NusEubpqwRgTIaHD15NbEVUQcW3GBJz8N2oFv7KYJ145vJTxeea mm5K0NsiiIfTZGfAd229spF1ORQ6LAoJe32PjT5hM64ZEbqpoKqx+usTBaYsJdPRQblYDr Z7BsljpyxmnkerH2lUPGbqT8z6aAbVo= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-269-5auTwAA0MKelr32shq5nsw-1; Mon, 03 Apr 2023 11:26:35 -0400 X-MC-Unique: 5auTwAA0MKelr32shq5nsw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1172E1C04191; Mon, 3 Apr 2023 15:26:35 +0000 (UTC) Received: from [10.39.208.17] (unknown [10.39.208.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 28272140EBF4; Mon, 3 Apr 2023 15:26:33 +0000 (UTC) Message-ID: Date: Mon, 3 Apr 2023 17:26:32 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 To: Eelco Chaudron Cc: Gowrishankar Muthukrishnan , chenbo.xia@intel.com, dev@dpdk.org References: <167992139724.45323.17979512439014217881.stgit@ebuild.local> <4FB0405A-41E0-4CE2-B8B1-0974CD398956@redhat.com> <3a70ad5c-9b8c-a990-c184-c1e6d29c13ad@redhat.com> <7669CF0F-2581-4178-A6B7-77AA09AD5E62@redhat.com> From: Maxime Coquelin Subject: Re: [EXT] [PATCH] vhost: add device op to offload the interrupt kick In-Reply-To: <7669CF0F-2581-4178-A6B7-77AA09AD5E62@redhat.com> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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 Hi Eelco, On 4/3/23 16:51, Eelco Chaudron wrote: > > > On 27 Mar 2023, at 18:35, Maxime Coquelin wrote: > >> On 3/27/23 18:04, Eelco Chaudron wrote: >>> >>> >>> On 27 Mar 2023, at 17:16, Gowrishankar Muthukrishnan wrote: >>> >>>> Hi Eelco, >>>> >>>>> +void >>>>> +rte_vhost_notify_guest(int vid, uint16_t queue_id) { >>>>> + struct virtio_net *dev = get_device(vid); >>>>> + struct vhost_virtqueue *vq; >>>>> + >>>>> + if (!dev || queue_id >= VHOST_MAX_VRING) >>>>> + return; >>>>> + >>>>> + vq = dev->virtqueue[queue_id]; >>>>> + if (!vq) >>>>> + return; >>>>> + >>>>> + rte_spinlock_lock(&vq->access_lock); >>>>> + >>>> >>>> Is spin lock needed here before system call ? >>> >>> I assumed access_lock is protecting all the following fields in this structure, so I need the lock to read the vq->callfd, however, I can/should move the eventfd_write outside of the lock. >> >> The FD might be closed between the check and the call to eventfd_write >> though, but I agree this is not optimal to call the eventfd_write under >> the spinlock in your case, as you will block the pmd thread if it tries >> to enqueue/dequeue packets on this queue, defeating the purpose of this >> patch. >> >> Maybe the solution is to change to read-write locks for the access_lock >> spinlock. The datapath (rte_vhost_enqueue_burst/rte_vhost_dequeue_burst) >> and this API would use the read version, meaning they won't lock each >> other, and the control path (lib/vhost/vhost_user.c) will use the write >> version. >> >> Does that make sense? > > Hi Maxime, I prepped a patch, but not the read/write part yet, https://github.com/chaudron/dpdk/commit/d51c93b4ff08b43daed33e3c0fee193a6d039c25#. > > I was thinking that even a read/write lock does not work (or maybe we need a combination of taking the read and write lock). As we need to update statistics, which need protection. > For example here you see the split (with just two locks, but the sys call could be called in the read lock): > > https://github.com/chaudron/dpdk/blob/d51c93b4ff08b43daed33e3c0fee193a6d039c25/lib/vhost/vhost.c#L1493 > > The best would be to not have a lock when calling the system call, but that does not seem safe. I do not see a clear solution, guess also as I have some trouble understanding the lock rules around vq’s. The lock is indeed required. Maybe we can use read-lock, and use atomic operations for counters that could be accessed by several threads? > > Do you have some more insights to share? I can ping you offline and discuss this. Sure, I'll be happy to discuss more about this. Thanks, Maxime > Cheers, > > Eelco > >>> >>>>> + if (vq->callfd >= 0) >>>>> + eventfd_write(vq->callfd, (eventfd_t)1); >>>>> + >>>>> + rte_spinlock_unlock(&vq->access_lock); >>>>> +} >>>>> + >>>> >>>> Thanks. >>> >