Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp156435imn; Tue, 2 Aug 2022 21:54:04 -0700 (PDT) X-Google-Smtp-Source: AA6agR6+2PgvvvZHoIDKQwmtIvVAtJFG+YD29MrqgZGFwMCm6xft0tYIPBxgUmR9HVtu2GKgIa8D X-Received: by 2002:a17:907:72ce:b0:730:606b:6fdb with SMTP id du14-20020a17090772ce00b00730606b6fdbmr12824200ejc.407.1659502443907; Tue, 02 Aug 2022 21:54:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659502443; cv=none; d=google.com; s=arc-20160816; b=G2jm1vXum0n/rq6qbF1DFl1YncS9jfivFIgMACB7FzqasdQl7L1TgzIR7TfRV5Tc+Y wOocUdOGMjwFskythy2r37nlo0213MJe83xd38EPhHZq9yb5NGOzjjt/pQdKsbjpZXSk 5dPnxZQQ46dFYsATa+XBb40B7CowwRM602fQUszAs2aaM/j3JzDXzL4lYUTGE9xWR1a/ JolBwinWn1PV3dVturn/uVeFzXnefhJ6zruf2WfZzyFE3oTjJYS3OX8EA9wPH8kwKEZD tm7W29i/UqNNMh2xRuR3xBMLGxU/BCtxML9yHXucNOhWg+WH/PQdnnrwR7q57bOGu6RY TkRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature:dkim-filter; bh=aGFADYTmhfG3G/nJc1EU3o6+heuDU6xMfrYwIst6ego=; b=mn+hei6Ye2efKELpCo+/dTvQD+kA2lbZa1gatMCZWV348ObK61R48Eqq2DYAMh6zjc 16LQYLnrNlcebdks01sQXugN2AO8zgmHGsBVwiZut21RvQSPhAx1ucgZbldFSrVbcobn iITKjJunj9LNpZl4R6u1TIhOfrGnYMAMadkkNOCuZSVRO8zdL8cs3vMYn9PZogeimPfy XZnfdcdHJLOnX7WMrWwaqB0VFgyAZcdp6P/M/wwE8lQxtE1oJSEKPDeUhjboKXdUjvYc TBL+7Veju7J3GmTBxqyc1ESX77uZroiUfNkcTc0lvqt4oYegQ20tW6flAePW7MUC+4f2 VNhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=gOeW3fl4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qb27-20020a1709077e9b00b00730a3906ecfsi2259579ejc.110.2022.08.02.21.53.38; Tue, 02 Aug 2022 21:54:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=gOeW3fl4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234801AbiHCEhO (ORCPT + 99 others); Wed, 3 Aug 2022 00:37:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229457AbiHCEhL (ORCPT ); Wed, 3 Aug 2022 00:37:11 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 53A395467B; Tue, 2 Aug 2022 21:37:10 -0700 (PDT) Received: by linux.microsoft.com (Postfix, from userid 1127) id 0565520FFC0C; Tue, 2 Aug 2022 21:37:10 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 0565520FFC0C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1659501430; bh=aGFADYTmhfG3G/nJc1EU3o6+heuDU6xMfrYwIst6ego=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=gOeW3fl49V+aGkpBFee5/bhUVVHJSX4+034spdXmC4DqX6J1l6qFfEdd1f2q98zvR Yr76dKo8cooAPN6qlCidReDpiQcmoqPLBXuJzZU+84ePQb9tGYdZnUoIyaE5Pn/tQy he/DTnIOzmApIFQwgJFeqAwmS3AJPlF15f5ZpAnk= Date: Tue, 2 Aug 2022 21:37:09 -0700 From: Saurabh Singh Sengar To: Praveen Kumar Cc: kys@microsoft.com, haiyangz@microsoft.com, sthemmin@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, jejb@linux.ibm.com, martin.petersen@oracle.com, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org Subject: Re: [PATCH] Drivers: hv: vmbus: Optimize vmbus_on_event Message-ID: <20220803043709.GA26795@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> References: <1658741848-4210-1-git-send-email-ssengar@linux.microsoft.com> <33983fa2-c9a8-1ac1-2f75-8360a077cfc2@linux.microsoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <33983fa2-c9a8-1ac1-2f75-8360a077cfc2@linux.microsoft.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Spam-Status: No, score=-19.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Thanks for your review, please find my comment inline. On Tue, Aug 02, 2022 at 01:44:23PM +0530, Praveen Kumar wrote: > On 25-07-2022 15:07, Saurabh Sengar wrote: > > In the vmbus_on_event loop, 2 jiffies timer will not serve the purpose if > > callback_fn takes longer. For effective use move this check inside of > > callback functions where needed. Out of all the VMbus drivers using > > vmbus_on_event, only storvsc has a high packet volume, thus add this limit > > only in storvsc callback for now. > > There is no apparent benefit of loop itself because this tasklet will be > > scheduled anyway again if there are packets left in ring buffer. This > > patch removes this unnecessary loop as well. > > > > In my understanding the loop was for optimizing the host to guest signaling for batched channels. > And the loop ensures that we process all the posted messages from the host before returning from the respective callbacks. > > Am I missing something here. Out of all the drivers using vmbus_on_event, only storvsc have high packet volume. The callback for storvsc is storvsc_on_channel_callback function which anyway has loop to check if there are any completion packets left. After this change when we move timeout inside storvsc callback, there is a possibility it comes back from callback leaving packets in ring buffer, for such cases the tasklet will be rescheduled. This function handles single ring buffer per call there is no batching. - Saurabh > > > Signed-off-by: Saurabh Sengar > > --- > > drivers/hv/connection.c | 33 ++++++++++++++------------------- > > drivers/scsi/storvsc_drv.c | 9 +++++++++ > > 2 files changed, 23 insertions(+), 19 deletions(-) > > > > diff --git a/drivers/hv/connection.c b/drivers/hv/connection.c > > index eca7afd..9dc27e5 100644 > > --- a/drivers/hv/connection.c > > +++ b/drivers/hv/connection.c > > @@ -431,34 +431,29 @@ struct vmbus_channel *relid2channel(u32 relid) > > void vmbus_on_event(unsigned long data) > > { > > struct vmbus_channel *channel = (void *) data; > > - unsigned long time_limit = jiffies + 2; > > + void (*callback_fn)(void *context); > > > > trace_vmbus_on_event(channel); > > > > hv_debug_delay_test(channel, INTERRUPT_DELAY); > > - do { > > - void (*callback_fn)(void *); > > > > - /* A channel once created is persistent even when > > - * there is no driver handling the device. An > > - * unloading driver sets the onchannel_callback to NULL. > > - */ > > - callback_fn = READ_ONCE(channel->onchannel_callback); > > - if (unlikely(callback_fn == NULL)) > > - return; > > - > > - (*callback_fn)(channel->channel_callback_context); > > + /* A channel once created is persistent even when > > + * there is no driver handling the device. An > > + * unloading driver sets the onchannel_callback to NULL. > > + */ > > + callback_fn = READ_ONCE(channel->onchannel_callback); > > + if (unlikely(!callback_fn)) > > + return; > > > > - if (channel->callback_mode != HV_CALL_BATCHED) > > - return; > > + (*callback_fn)(channel->channel_callback_context); > > > > - if (likely(hv_end_read(&channel->inbound) == 0)) > > - return; > > + if (channel->callback_mode != HV_CALL_BATCHED) > > + return; > > > > - hv_begin_read(&channel->inbound); > > - } while (likely(time_before(jiffies, time_limit))); > > + if (likely(hv_end_read(&channel->inbound) == 0)) > > + return; > > > > - /* The time limit (2 jiffies) has been reached */ > > + hv_begin_read(&channel->inbound); > > tasklet_schedule(&channel->callback_event); > > } > > > > diff --git a/drivers/scsi/storvsc_drv.c b/drivers/scsi/storvsc_drv.c > > index fe000da..c457e6b 100644 > > --- a/drivers/scsi/storvsc_drv.c > > +++ b/drivers/scsi/storvsc_drv.c > > @@ -60,6 +60,9 @@ > > #define VMSTOR_PROTO_VERSION_WIN8_1 VMSTOR_PROTO_VERSION(6, 0) > > #define VMSTOR_PROTO_VERSION_WIN10 VMSTOR_PROTO_VERSION(6, 2) > > > > +/* channel callback timeout in ms */ > > +#define CALLBACK_TIMEOUT 2 > > + > > /* Packet structure describing virtual storage requests. */ > > enum vstor_packet_operation { > > VSTOR_OPERATION_COMPLETE_IO = 1, > > @@ -1204,6 +1207,7 @@ static void storvsc_on_channel_callback(void *context) > > struct hv_device *device; > > struct storvsc_device *stor_device; > > struct Scsi_Host *shost; > > + unsigned long time_limit = jiffies + msecs_to_jiffies(CALLBACK_TIMEOUT); > > > > if (channel->primary_channel != NULL) > > device = channel->primary_channel->device_obj; > > @@ -1224,6 +1228,11 @@ static void storvsc_on_channel_callback(void *context) > > u32 minlen = rqst_id ? sizeof(struct vstor_packet) : > > sizeof(enum vstor_packet_operation); > > > > + if (unlikely(time_after(jiffies, time_limit))) { > > + hv_pkt_iter_close(channel); > > + return; > > + } > > + > > if (pktlen < minlen) { > > dev_err(&device->device, > > "Invalid pkt: id=%llu, len=%u, minlen=%u\n", > > Regards, > > ~Praveen.