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.133.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 C378C30EF62 for ; Wed, 26 Nov 2025 06:41:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764139281; cv=none; b=H3/E2M+Qng3SJdXl6X2zitClVLlmGYEW3WSbBV2/WyvsTEWRIsu2ldhRDEO/bv2qUp9AiK3+dmEpuh/zteN/OGiGZMJbGnIHN4qAv2h3Hkx+jQWimDXZlPDRbRdF2A4IY3bwkWSRU4icufQeMGuXlW+3JoTn99FIedzzpgpLCkA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764139281; c=relaxed/simple; bh=QGAnoy4Dpq+iZUpFV+/GD9HeagIzEqq8RFCNZfqkZDk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=q/hT63/75dMX+O97Zb9ch+77upwRaq+/0Yz8Zk4MmKkMsiXsmGAwfNlZSRfr8UbVJSRyHhurSbCOmJ156VoVO5k7fDxki6Kk1Ldc/sQFzR2+R0sX77opYwbnJjEs549WmuacU+0sG5TpproDwx9VIJLwzBTnZCC/1IMJ2q5QQac= 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=VG04zcCh; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=mIRs/abo; arc=none smtp.client-ip=170.10.133.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="VG04zcCh"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="mIRs/abo" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1764139278; 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=2gwbwF5MFgvvyjCvPMrgDXnD+XmnUmUshXklxp3cjS8=; b=VG04zcChr3ZyEginJp68jsnGm5WAW2jn8e+AFKW4JIQlb3QZVCXkijDHn5MaIwdLYFbiXJ 1UWCVOTavHxV+N59KI9xsJGb5pI/in4AYFUVsaAcCaCCzUn8HiQIR+JedPK5Quhbqd/8Ww oHfHAh1A9yMZR0DbVMe7TgYKaKjGjdg= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-116-M-quNM3nNr6YVtv066jWhQ-1; Wed, 26 Nov 2025 01:41:16 -0500 X-MC-Unique: M-quNM3nNr6YVtv066jWhQ-1 X-Mimecast-MFC-AGG-ID: M-quNM3nNr6YVtv066jWhQ_1764139276 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-477b8a667bcso63317215e9.2 for ; Tue, 25 Nov 2025 22:41:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1764139275; x=1764744075; 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=2gwbwF5MFgvvyjCvPMrgDXnD+XmnUmUshXklxp3cjS8=; b=mIRs/aboTeN5nYRFd5LJHGmAv6ykfTRvudIstprujRftAISPrMxzpXwC68yzGNYC0F iwQ46f/hRdFwiIyuZn8E3TEqxA7RQlQoXTcgjfPS6MPZh7mdw4mTGIe/HmSW1Z/Y2E7B unwZAANJRhANOe1v76N7u2sckjr+SMHV1PB57eYW9XEy+dhZbluu3bBp5HVvZcBONUbW 4eMOjmqVcKUrZqXNYc/zOvQCVQFM6vgToc1GajuvqH2PzbywhOtyXM7LBoGw2UBifeXp TnTPYg0B4Poa+1bmOtg8xDturwecvov2R8idtr4Cewtmb3o0q9OTQqHtyv+e3sigEwzV DG5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764139275; x=1764744075; 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=2gwbwF5MFgvvyjCvPMrgDXnD+XmnUmUshXklxp3cjS8=; b=L7j6ipzI0zRy2u1l0juyiOec8vLsXKKpBMph1snqXXMqlGKxbRjs/nywNd/i8An1fs SGC5yi5KaDtZgXLpxrgQfAgpBeS/BFUbQtcDaRvmPgfG16qW/tH+J9pTlU7Nb0m06Ul1 6FlQcNYVJYNr0Wlrbj2F/tCkUYy6jv+gnNyYIKXpNulGqwB1K0SScWWk+nqPISEDYQla 8QpmIl5X+nGBQnBx8FGaGjB6AmM7nnhsIJFsqsX8dDRU74V+nJzRX9mP97t/RDbu1fve fTIWCWTsBdziGWPk7WBtIkLZHYLIq7LeoUesUxporoglSOFDD3DYqyOmbyAm1j07qyAW WT8Q== X-Forwarded-Encrypted: i=1; AJvYcCW1FqliK8Ia2JoECxrCb6P16vDPo1ofTswt3A1ykRHiUtlkV4OXRpy4VIAYjMEkGCuc67FwvlE=@vger.kernel.org X-Gm-Message-State: AOJu0Yw3lQTd5qDC/4jVDGKlDEOhUhqzJyckM4ldzL5nGgWQMWCWt2Hm sNwn9sginVaVgAJnMZcKZ++HSNoEcMRH30S7vEmNKg7mSEfZWw5iHP3WmD5TbOJZIY0BLVJVeeW aOgI8bBfzS6g/F3HE6c6sCHIYchVo8DWi+bM4F2rGSGuucnmyhVpobNF0uQ== X-Gm-Gg: ASbGnctrhLZnCNBeg9mRyEYWYg0E+4apqIyqTmEZqeeh2gK/+DNB6AM3ovuL01fJaKH ibc99lvOjl+MxgTSu7ceLhs5lbg3z43LQjjMlG6KBmJlXYzM1zbnwVD9KzrjUZXzhrXr6nnaxN5 BSpHEQzIje+kuDPng7d/Gy/eNITuUm03PXX+d1+/O9Yfi+AcanvaMy8mcIv8TxAuvY/r9J2K82a QJjaoNZN6LdRDMBaM+87yKzvjrGHV5ngvPUpM4Pgrw4tCvHufpFVCEpTKeqe8FJw42E9JN1iX5Q hgkD/clzLEAL5M35NNLcVKaWMAqSN3Kjs9lVBM0/tunn4ZcIRa4Aa3De3pxCb7XPU9pceakp6oz 2qK6J4oQfG16DzzFz8F5xp/IL2UiZ2A== X-Received: by 2002:a05:600c:474d:b0:477:7c7d:d9b2 with SMTP id 5b1f17b1804b1-47904b290bcmr52060355e9.32.1764139275455; Tue, 25 Nov 2025 22:41:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IEDoRireQsP5/XG7ok5T657RYeSY0MQ0WBAZuQRYdeqW40JoE8OKq+SygU0m3K5smDQLLeFzw== X-Received: by 2002:a05:600c:474d:b0:477:7c7d:d9b2 with SMTP id 5b1f17b1804b1-47904b290bcmr52060165e9.32.1764139275010; Tue, 25 Nov 2025 22:41:15 -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-4790adddb4bsm25619865e9.7.2025.11.25.22.41.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Nov 2025 22:41:14 -0800 (PST) Date: Wed, 26 Nov 2025 01:41:12 -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: <20251126012918-mutt-send-email-mst@kernel.org> References: <20251125180034.1167847-1-jon@nutanix.com> Precedence: bulk X-Mailing-List: netdev@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 > --- > 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); Looks like this can easily send more interrupts than originally? How can this be good? >From the description, I would expect the changes to just add another call to peek_head_len after the existing vhost_net_signal_used. What am I missing? > -- > 2.43.0