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 D5FC5428BF; Mon, 3 Apr 2023 16:51:55 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B271A410D1; Mon, 3 Apr 2023 16:51:55 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 9DF6D40A7E for ; Mon, 3 Apr 2023 16:51:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680533514; 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=7qetm43TfVyxw3dTGSlwXl1X4nFvxnYibs+PjO1m2ms=; b=Gq4LKSPXAyasRw8sP3h7NV8sapOGOWyPmmXdIW746Wi+nbyhcQD5McSquxMOyV7O8S1o0V sTuh+Az98e1ZTVs49hx2M4J12LcaI7rNBXgHUPkEqCEd8YGQSyJ1DEycizx5Zji72xkzB4 ev78cQoyjAVO6sM7MPhZI/LFPC05Q9c= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-472-qeX3ut54OVyXvtwxhCuGJQ-1; Mon, 03 Apr 2023 10:51:52 -0400 X-MC-Unique: qeX3ut54OVyXvtwxhCuGJQ-1 Received: by mail-ed1-f69.google.com with SMTP id ev6-20020a056402540600b004bc2358ac04so42112708edb.21 for ; Mon, 03 Apr 2023 07:51:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680533511; x=1683125511; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lBjPG/JB7UUM9nVKfOuDlZJTYIgArqZJhaHwh13G9I0=; b=TxVtt7pIPvDSaT9ljR7sKJ5+XqrQe5bjySiPXDHzSKjhhfvyN6YW4ZMdSZAvrDb/+7 DIua+eTEPM0nW4VExUTQNGRas4bnk4JXiRNlSxT54/RN435OKRwjlRTVxOPgFpZCxeI8 4+s8UH2HhFittIME4RyTqCUplP852H16nJMJxPKINRPoLuzA4H1NP913mVO4mDALP0U8 IRaIvGzuX0r95JLWDMA/5EzSlM3cf3ZCcwbxLsiULI5DoUeNMZ19823ktuPodub6XSXT 61ERg4JJzJYkKfoi3UokAeitJj3ar6bdAiRmAD+DF8AB/cwEr6BKUQAPVwcNaXoVOZlr pRSQ== X-Gm-Message-State: AAQBX9dL9TwsGHy5P0W4iNYjIT9IXjzPZGBzKi6m6nvQFn5YKdBUnbf2 G3eP6MmIhZYTAt9LfbkyinAS2FgIqSgPc1+b6osh6QKhcNi68Gl1R9mKv8kk/tzQAZxCPKUJLom 8co4= X-Received: by 2002:a17:906:4e92:b0:946:b942:ad6f with SMTP id v18-20020a1709064e9200b00946b942ad6fmr13583281eju.8.1680533511700; Mon, 03 Apr 2023 07:51:51 -0700 (PDT) X-Google-Smtp-Source: AKy350YObv3FSfAZwYIPvaB88M9K9AdlI5yv7aWE9d7FNe+7Rk04TxmR75scXdqa7qSwsbkyitmXYg== X-Received: by 2002:a17:906:4e92:b0:946:b942:ad6f with SMTP id v18-20020a1709064e9200b00946b942ad6fmr13583269eju.8.1680533511383; Mon, 03 Apr 2023 07:51:51 -0700 (PDT) Received: from [10.39.192.135] (5920ab7b.static.cust.trined.nl. [89.32.171.123]) by smtp.gmail.com with ESMTPSA id i17-20020a170906851100b0094775894e50sm4704365ejx.170.2023.04.03.07.51.50 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Apr 2023 07:51:50 -0700 (PDT) From: Eelco Chaudron To: Maxime Coquelin Cc: Gowrishankar Muthukrishnan , chenbo.xia@intel.com, dev@dpdk.org Subject: Re: [EXT] [PATCH] vhost: add device op to offload the interrupt kick Date: Mon, 03 Apr 2023 16:51:47 +0200 X-Mailer: MailMate (1.14r5964) Message-ID: <7669CF0F-2581-4178-A6B7-77AA09AD5E62@redhat.com> In-Reply-To: <3a70ad5c-9b8c-a990-c184-c1e6d29c13ad@redhat.com> References: <167992139724.45323.17979512439014217881.stgit@ebuild.local> <4FB0405A-41E0-4CE2-B8B1-0974CD398956@redhat.com> <3a70ad5c-9b8c-a990-c184-c1e6d29c13ad@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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 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) { >>>> +=09struct virtio_net *dev =3D get_device(vid); >>>> +=09struct vhost_virtqueue *vq; >>>> + >>>> +=09if (!dev || queue_id >=3D VHOST_MAX_VRING) >>>> +=09=09return; >>>> + >>>> +=09vq =3D dev->virtqueue[queue_id]; >>>> +=09if (!vq) >>>> +=09=09return; >>>> + >>>> +=09rte_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 str= ucture, so I need the lock to read the vq->callfd, however, I can/should mo= ve 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://gith= ub.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 stat= istics, which need protection. For example here you see the split (with just two locks, but the sys call c= ould be called in the read lock): https://github.com/chaudron/dpdk/blob/d51c93b4ff08b43daed33e3c0fee193a6d039= c25/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 so= me trouble understanding the lock rules around vq=E2=80=99s. Do you have some more insights to share? I can ping you offline and discuss= this. Cheers, Eelco >> >>>> +=09if (vq->callfd >=3D 0) >>>> +=09=09eventfd_write(vq->callfd, (eventfd_t)1); >>>> + >>>> +=09rte_spinlock_unlock(&vq->access_lock); >>>> +} >>>> + >>> >>> Thanks. >>