From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9A45C2F1FE9 for ; Tue, 25 Nov 2025 23:50:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764114632; cv=none; b=r9SqsCBt4dcjWARXIwoGw8C0fNrPlVmYWqn88xh6cue4/L5G35APa9H/0GOtLeMFsJMq95cYq71wHVbk3sk3V8XIsj/5EMSepI2mY4bK+j5nXGkNj9sMIZ4Lb2RYyGiAOJqL++h0Qsj9r4HNIK5YukwfJs8RdWqpOOSiYlyreRc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764114632; c=relaxed/simple; bh=VR/QlSFYXfB2XAkyEqk2La815NaXCesg1lVuqP0+cyE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=J1etkWY9WD4OYWi0HeIdtlZZrlawI1mtxnST4/s/PI6sEsxhlogYN80cqk+0+ui+U+MRtd/x3nuxYQrvqQ6SfG+VG/edmB1dYqhx2QTcSBeRqXPMB5OIaelJ4TyxIFYd6EjXXVR7kldbFx1DisGY3A5HREiCT9y7b7MWgVz6VNQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=c6L6X1Qw; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=AKy3ZVkK; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="c6L6X1Qw"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="AKy3ZVkK" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1764114629; 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=rIwS7E0jdpZel3anL6UezeiFSzMWSTuk00aa6Qzm+5s=; b=c6L6X1QwyIRy5gYOul937dnv9Dgg7KmZ3xFGLBa77WUKtZfTuVfZkSQF/RLoY4Vb006DyS 2xCM1hSEB5HlrrpUpALEDSO5ND7BA/WlxkvWjHYqO24w332HvHGPCiRb9nfzVjzoAZOMwB AH0mC131W4vOP8iKQXHRaQG0AIUxfqg= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-607-ttBCx5nJNwaW9vN3ZqIuBw-1; Tue, 25 Nov 2025 18:50:25 -0500 X-MC-Unique: ttBCx5nJNwaW9vN3ZqIuBw-1 X-Mimecast-MFC-AGG-ID: ttBCx5nJNwaW9vN3ZqIuBw_1764114624 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-477212937eeso37522415e9.2 for ; Tue, 25 Nov 2025 15:50:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1764114624; x=1764719424; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=rIwS7E0jdpZel3anL6UezeiFSzMWSTuk00aa6Qzm+5s=; b=AKy3ZVkKL1lF1IVsOpuUpB0EsE1qPUgLKNQJyujF7MBqRno9gF64A/IPOmoqELpIDS GU5U2EHwMmk25vGrwPAnmLDGEkCpp5PlbmHbR4pj3Z68FQf1qByvjY8oZxYSdcTigDKu 4CWmsF67v+s9q5gzNkxbc5Ys/AOjSjYsc9RfZdJufT8BFGuFM8uLxJ+SHazvBhxhoLa7 CFmDK8k42IMAe6jlCETQtb6MZ1KMjGfMvQsgAZT25D7e5p92sJ9Q1xlmSoUlcjT2id8/ garHq+bqIcu9IIlTj1EEVYQYFOU1I6aVEs+t8/22e+euL9QJH4Ivf4U7CpichSuYR3pe CkxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764114624; x=1764719424; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rIwS7E0jdpZel3anL6UezeiFSzMWSTuk00aa6Qzm+5s=; b=w1gY+MX8y5WxG4BRnr1zhN4LKeyDbp9/oPeFbKAORH7xaPtBqnAaaDZTARQt/E3QeI Y2whttq5JO9XO5vipkY7Rcksk27D4nfTd4pa+Mei33b9Sap1HVVXDd6NgY5nPxOEJwQ4 6rxVq+lmqk+t/AtqGS5PHpAjphIYvfBm+c2TQhcWx9CzoFblCqR4vkXbcMLgMOfW7sO8 yHrNtGw9owUDZ7xKCfNGAoBBCh6MNL0tz64wEzuS9RbOeDQtlfYw5Ecb/P3PtpGHNm6/ n2ZhaZX4qKk+zrLv/N+i30f6iRU+5Kjr3sttGbMmBGPbvfSNY6A23O6qk++7m/wapbdc qpbg== X-Forwarded-Encrypted: i=1; AJvYcCWGZMu4vWpRiQCpnxZB1gNbQ4Fd5JWLkSNvqcrie3b1wZC1qZJR4fmi8u95YBAotSAlh7ds2y4Z1OgkwN0=@vger.kernel.org X-Gm-Message-State: AOJu0YzYJbZAb074VIy06wdGk2Ig8rBcqml5fRnXCLQ5Ta2idIzIkgsw wlc/l/J9HgT+rS7IyiCm8V72t+TpMfa+vSHMbDKXW3k8EF0//W+xcez2uTgH2nXaITj0r18xuy+ V4V3Me961txbyiJfJLsS7+6pNiJFwQT7SmSbF5b4a5QrmA/DnSeQVCo2FtrjBcdmSfg== X-Gm-Gg: ASbGncv0jl8BXhx0EtNEnjpD7QX25V+aN1OzYHlRmCtrvyPN6x1G8WNE/Aw0DF0B7yE rKCfTYo/9UWQ8A+floBiGp8Kl1tWsresRDb2d+CetaNZhf/+GjP9WE4Z9outFlX++rsR/Rbd9ri XVX+Qxc72zTtOdungktGjtMnQ9ZcPUe608/7jC9codRhA9OcNl9hkMHzgmyIJA2Du+WttCaSZV+ Jp07SZgOAc9DCYaFjUjGMEK67EsPCvuJ/v5iR6mAjGxsLCkx+ev2liFAkQP1ZYTzsNVDN/PxUoc +YzwwYLrBb7js+YmKu+h+r5EoVBCVa4IQgP7EtEoGxuaagUQLqYYN5kgk5/DCQ+wu2ZDtP64ZxK TtGf3fcu9E0AStwpo1P+KUccy+Pjeyg== X-Received: by 2002:a05:600c:1c25:b0:46e:4586:57e4 with SMTP id 5b1f17b1804b1-477c114ed70mr261113175e9.24.1764114624358; Tue, 25 Nov 2025 15:50:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IFnq4RJlt9m2aS6c4TGKhjJ1S2uVgEkT/HKNHftYudQTJJrbCWeUDlCnlsQl791oaHujLBMkw== X-Received: by 2002:a05:600c:1c25:b0:46e:4586:57e4 with SMTP id 5b1f17b1804b1-477c114ed70mr261112975e9.24.1764114623865; Tue, 25 Nov 2025 15:50:23 -0800 (PST) Received: from redhat.com (IGLD-80-230-39-63.inter.net.il. [80.230.39.63]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-479052def4bsm26279025e9.13.2025.11.25.15.50.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Nov 2025 15:50:23 -0800 (PST) Date: Tue, 25 Nov 2025 18:50:20 -0500 From: "Michael S. Tsirkin" To: Jon Kohler Cc: Jason Wang , Eugenio =?iso-8859-1?Q?P=E9rez?= , kvm@vger.kernel.org, virtualization@lists.linux.dev, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH net-next] vhost/net: check peek_head_len after signal to guest to avoid delays Message-ID: <20251125184936-mutt-send-email-mst@kernel.org> References: <20251125180034.1167847-1-jon@nutanix.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20251125180034.1167847-1-jon@nutanix.com> On Tue, Nov 25, 2025 at 11:00:33AM -0700, Jon Kohler wrote: > In non-busypoll handle_rx paths, if peek_head_len returns 0, the RX > loop breaks, the RX wait queue is re-enabled, and vhost_net_signal_used > is called to flush done_idx and notify the guest if needed. > > However, signaling the guest can take non-trivial time. During this > window, additional RX payloads may arrive on rx_ring without further > kicks. These new payloads will sit unprocessed until another kick > arrives, increasing latency. In high-rate UDP RX workloads, this was > observed to occur over 20k times per second. > > To minimize this window and improve opportunities to process packets > promptly, immediately call peek_head_len after signaling. If new packets > are found, treat it as a busy poll interrupt and requeue handle_rx, > improving fairness to TX handlers and other pending CPU work. This also > helps suppress unnecessary thread wakeups, reducing waker CPU demand. > > Signed-off-by: Jon Kohler Given this is supposed to be a performance improvement, pls include info on the effect this has on performance. Thanks! > --- > drivers/vhost/net.c | 21 +++++++++++++++++++++ > 1 file changed, 21 insertions(+) > > diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c > index 35ded4330431..04cb5f1dc6e4 100644 > --- a/drivers/vhost/net.c > +++ b/drivers/vhost/net.c > @@ -1015,6 +1015,27 @@ static int vhost_net_rx_peek_head_len(struct vhost_net *net, struct sock *sk, > struct vhost_virtqueue *tvq = &tnvq->vq; > int len = peek_head_len(rnvq, sk); > > + if (!len && rnvq->done_idx) { > + /* When idle, flush signal first, which can take some > + * time for ring management and guest notification. > + * Afterwards, check one last time for work, as the ring > + * may have received new work during the notification > + * window. > + */ > + vhost_net_signal_used(rnvq, *count); > + *count = 0; > + if (peek_head_len(rnvq, sk)) { > + /* More work came in during the notification > + * window. To be fair to the TX handler and other > + * potentially pending work items, pretend like > + * this was a busy poll interruption so that > + * the RX handler will be rescheduled and try > + * again. > + */ > + *busyloop_intr = true; > + } > + } > + > if (!len && rvq->busyloop_timeout) { > /* Flush batched heads first */ > vhost_net_signal_used(rnvq, *count); > -- > 2.43.0