Skip to content

Commit ce59fec

Browse files
vittyvkgregkh
authored andcommitted
Drivers: hv: vmbus: distribute subchannels among all vcpus
Primary channels are distributed evenly across all vcpus we have. When the host asks us to create subchannels it usually makes us num_cpus-1 offers and we are supposed to distribute the work evenly among the channel itself and all its subchannels. Make sure they are all assigned to different vcpus. Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com> Signed-off-by: K. Y. Srinivasan <kys@microsoft.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent f38e7dd commit ce59fec

1 file changed

Lines changed: 28 additions & 1 deletion

File tree

‎drivers/hv/channel_mgmt.c‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,8 @@ static void init_vp_index(struct vmbus_channel *channel, const uuid_le *type_gui
387387
int i;
388388
bool perf_chn = false;
389389
u32 max_cpus = num_online_cpus();
390+
struct vmbus_channel *primary = channel->primary_channel, *prev;
391+
unsigned long flags;
390392

391393
for (i = IDE; i < MAX_PERF_CHN; i++) {
392394
if (!memcmp(type_guid->b, hp_devs[i].guid,
@@ -407,7 +409,32 @@ static void init_vp_index(struct vmbus_channel *channel, const uuid_le *type_gui
407409
channel->target_vp = 0;
408410
return;
409411
}
410-
cur_cpu = (++next_vp % max_cpus);
412+
413+
/*
414+
* Primary channels are distributed evenly across all vcpus we have.
415+
* When the host asks us to create subchannels it usually makes us
416+
* num_cpus-1 offers and we are supposed to distribute the work evenly
417+
* among the channel itself and all its subchannels. Make sure they are
418+
* all assigned to different vcpus.
419+
*/
420+
if (!primary)
421+
cur_cpu = (++next_vp % max_cpus);
422+
else {
423+
/*
424+
* Let's assign the first subchannel of a channel to the
425+
* primary->target_cpu+1 and all the subsequent channels to
426+
* the prev->target_cpu+1.
427+
*/
428+
spin_lock_irqsave(&primary->lock, flags);
429+
if (primary->num_sc == 1)
430+
cur_cpu = (primary->target_cpu + 1) % max_cpus;
431+
else {
432+
prev = list_prev_entry(channel, sc_list);
433+
cur_cpu = (prev->target_cpu + 1) % max_cpus;
434+
}
435+
spin_unlock_irqrestore(&primary->lock, flags);
436+
}
437+
411438
channel->target_cpu = cur_cpu;
412439
channel->target_vp = hv_context.vp_index[cur_cpu];
413440
}

0 commit comments

Comments
 (0)