Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964951AbbD0RHK (ORCPT ); Mon, 27 Apr 2015 13:07:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37912 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932363AbbD0REb (ORCPT ); Mon, 27 Apr 2015 13:04:31 -0400 From: Vitaly Kuznetsov To: "K. Y. Srinivasan" Cc: Haiyang Zhang , devel@linuxdriverproject.org, linux-kernel@vger.kernel.org, Dexuan Cui Subject: [PATCH v2 5/6] Drivers: hv: vmbus: distribute subchannels among all vcpus Date: Mon, 27 Apr 2015 19:04:15 +0200 Message-Id: <1430154256-26853-6-git-send-email-vkuznets@redhat.com> In-Reply-To: <1430154256-26853-1-git-send-email-vkuznets@redhat.com> References: <1430154256-26853-1-git-send-email-vkuznets@redhat.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2365 Lines: 65 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 --- drivers/hv/channel_mgmt.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c index 655c0a0..1f1417d 100644 --- a/drivers/hv/channel_mgmt.c +++ b/drivers/hv/channel_mgmt.c @@ -387,6 +387,8 @@ static void init_vp_index(struct vmbus_channel *channel, const uuid_le *type_gui int i; bool perf_chn = false; u32 max_cpus = num_online_cpus(); + struct vmbus_channel *primary = channel->primary_channel, *prev; + unsigned long flags; for (i = IDE; i < MAX_PERF_CHN; i++) { 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 channel->target_vp = 0; return; } - cur_cpu = (++next_vp % max_cpus); + + /* + * 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. + */ + if (!primary) + cur_cpu = (++next_vp % max_cpus); + else { + /* + * Let's assign the first subchannel of a channel to the + * primary->target_cpu+1 and all the subsequent channels to + * the prev->target_cpu+1. + */ + spin_lock_irqsave(&primary->lock, flags); + if (primary->num_sc == 1) + cur_cpu = (primary->target_cpu + 1) % max_cpus; + else { + prev = list_prev_entry(channel, sc_list); + cur_cpu = (prev->target_cpu + 1) % max_cpus; + } + spin_unlock_irqrestore(&primary->lock, flags); + } + channel->target_cpu = cur_cpu; channel->target_vp = hv_context.vp_index[cur_cpu]; } -- 1.9.3 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/