Skip to content

Commit 78c65f0

Browse files
Saurabh Sengarliuw
authored andcommitted
Drivers: hv: vmbus: Optimize vmbus_on_event
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. Signed-off-by: Saurabh Sengar <ssengar@linux.microsoft.com> Reviewed-by: Michael Kelley <mikelley@microsoft.com> Link: https://lore.kernel.org/r/1658741848-4210-1-git-send-email-ssengar@linux.microsoft.com Signed-off-by: Wei Liu <wei.liu@kernel.org>
1 parent 521a547 commit 78c65f0

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

drivers/hv/connection.c

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -431,34 +431,29 @@ struct vmbus_channel *relid2channel(u32 relid)
431431
void vmbus_on_event(unsigned long data)
432432
{
433433
struct vmbus_channel *channel = (void *) data;
434-
unsigned long time_limit = jiffies + 2;
434+
void (*callback_fn)(void *context);
435435

436436
trace_vmbus_on_event(channel);
437437

438438
hv_debug_delay_test(channel, INTERRUPT_DELAY);
439-
do {
440-
void (*callback_fn)(void *);
441439

442-
/* A channel once created is persistent even when
443-
* there is no driver handling the device. An
444-
* unloading driver sets the onchannel_callback to NULL.
445-
*/
446-
callback_fn = READ_ONCE(channel->onchannel_callback);
447-
if (unlikely(callback_fn == NULL))
448-
return;
449-
450-
(*callback_fn)(channel->channel_callback_context);
440+
/* A channel once created is persistent even when
441+
* there is no driver handling the device. An
442+
* unloading driver sets the onchannel_callback to NULL.
443+
*/
444+
callback_fn = READ_ONCE(channel->onchannel_callback);
445+
if (unlikely(!callback_fn))
446+
return;
451447

452-
if (channel->callback_mode != HV_CALL_BATCHED)
453-
return;
448+
(*callback_fn)(channel->channel_callback_context);
454449

455-
if (likely(hv_end_read(&channel->inbound) == 0))
456-
return;
450+
if (channel->callback_mode != HV_CALL_BATCHED)
451+
return;
457452

458-
hv_begin_read(&channel->inbound);
459-
} while (likely(time_before(jiffies, time_limit)));
453+
if (likely(hv_end_read(&channel->inbound) == 0))
454+
return;
460455

461-
/* The time limit (2 jiffies) has been reached */
456+
hv_begin_read(&channel->inbound);
462457
tasklet_schedule(&channel->callback_event);
463458
}
464459

drivers/scsi/storvsc_drv.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@
6060
#define VMSTOR_PROTO_VERSION_WIN8_1 VMSTOR_PROTO_VERSION(6, 0)
6161
#define VMSTOR_PROTO_VERSION_WIN10 VMSTOR_PROTO_VERSION(6, 2)
6262

63+
/* channel callback timeout in ms */
64+
#define CALLBACK_TIMEOUT 2
65+
6366
/* Packet structure describing virtual storage requests. */
6467
enum vstor_packet_operation {
6568
VSTOR_OPERATION_COMPLETE_IO = 1,
@@ -1204,6 +1207,7 @@ static void storvsc_on_channel_callback(void *context)
12041207
struct hv_device *device;
12051208
struct storvsc_device *stor_device;
12061209
struct Scsi_Host *shost;
1210+
unsigned long time_limit = jiffies + msecs_to_jiffies(CALLBACK_TIMEOUT);
12071211

12081212
if (channel->primary_channel != NULL)
12091213
device = channel->primary_channel->device_obj;
@@ -1224,6 +1228,11 @@ static void storvsc_on_channel_callback(void *context)
12241228
u32 minlen = rqst_id ? sizeof(struct vstor_packet) :
12251229
sizeof(enum vstor_packet_operation);
12261230

1231+
if (unlikely(time_after(jiffies, time_limit))) {
1232+
hv_pkt_iter_close(channel);
1233+
return;
1234+
}
1235+
12271236
if (pktlen < minlen) {
12281237
dev_err(&device->device,
12291238
"Invalid pkt: id=%llu, len=%u, minlen=%u\n",

0 commit comments

Comments
 (0)