From owner-svn-src-head@freebsd.org Wed Mar 2 01:40:49 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 14197AC072E; Wed, 2 Mar 2016 01:40:49 +0000 (UTC) (envelope-from sephe@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id DEBC912DD; Wed, 2 Mar 2016 01:40:48 +0000 (UTC) (envelope-from sephe@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u221elJI003070; Wed, 2 Mar 2016 01:40:47 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u221els4003069; Wed, 2 Mar 2016 01:40:47 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201603020140.u221els4003069@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Wed, 2 Mar 2016 01:40:47 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r296291 - head/sys/dev/hyperv/vmbus X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Mar 2016 01:40:49 -0000 Author: sephe Date: Wed Mar 2 01:40:47 2016 New Revision: 296291 URL: https://svnweb.freebsd.org/changeset/base/296291 Log: hyperv/chan: Factor out the vcpu setting And use it for cpu0 assignment; it does not sound right to assume that cpu0 maps to vcpu0. And this factored out function will be exposed to drivers, if driver specific CPU binding is needed, e.g. hn(4). Move default cpu select after saving channel offer message. This makes sure that all useful information of the channel has been setup. MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D5504 Modified: head/sys/dev/hyperv/vmbus/hv_channel_mgmt.c Modified: head/sys/dev/hyperv/vmbus/hv_channel_mgmt.c ============================================================================== --- head/sys/dev/hyperv/vmbus/hv_channel_mgmt.c Wed Mar 2 01:33:30 2016 (r296290) +++ head/sys/dev/hyperv/vmbus/hv_channel_mgmt.c Wed Mar 2 01:40:47 2016 (r296291) @@ -274,6 +274,21 @@ vmbus_channel_process_offer(hv_vmbus_cha } } +static void +vmbus_channel_cpu_set(struct hv_vmbus_channel *chan, int cpu) +{ + KASSERT(cpu >= 0 && cpu < mp_ncpus, ("invalid cpu %d", cpu)); + + chan->target_cpu = cpu; + chan->target_vcpu = hv_vmbus_g_context.hv_vcpu_index[cpu]; + + if (bootverbose) { + printf("vmbus_chan%u: assigned to cpu%u [vcpu%u]\n", + chan->offer_msg.child_rel_id, + chan->target_cpu, chan->target_vcpu); + } +} + /** * Array of device guids that are performance critical. We try to distribute * the interrupt load for these devices across all online cpus. @@ -306,11 +321,12 @@ static uint32_t next_vcpu; * distributed across all available CPUs. */ static void -vmbus_channel_select_cpu(hv_vmbus_channel *channel, hv_guid *guid) +vmbus_channel_select_defcpu(struct hv_vmbus_channel *channel) { uint32_t current_cpu; int i; boolean_t is_perf_channel = FALSE; + const hv_guid *guid = &channel->offer_msg.offer.interface_type; for (i = PERF_CHN_NIC; i < MAX_PERF_CHN; i++) { if (memcmp(guid->data, high_perf_devices[i].data, @@ -323,21 +339,13 @@ vmbus_channel_select_cpu(hv_vmbus_channe if ((hv_vmbus_protocal_version == HV_VMBUS_VERSION_WS2008) || (hv_vmbus_protocal_version == HV_VMBUS_VERSION_WIN7) || (!is_perf_channel)) { - /* Host's view of guest cpu */ - channel->target_vcpu = 0; - /* Guest's own view of cpu */ - channel->target_cpu = 0; + /* Stick to cpu0 */ + vmbus_channel_cpu_set(channel, 0); return; } /* mp_ncpus should have the number cpus currently online */ current_cpu = (++next_vcpu % mp_ncpus); - channel->target_cpu = current_cpu; - channel->target_vcpu = - hv_vmbus_g_context.hv_vcpu_index[current_cpu]; - if (bootverbose) - printf("VMBUS: Total online cpus %d, assign perf channel %d " - "to vcpu %d, cpu %d\n", mp_ncpus, i, channel->target_vcpu, - current_cpu); + vmbus_channel_cpu_set(channel, current_cpu); } /** @@ -408,17 +416,14 @@ vmbus_channel_on_offer_internal(void* co offer->connection_id; } - /* - * Bind the channel to a chosen cpu. - */ - vmbus_channel_select_cpu(new_channel, - &offer->offer.interface_type); - memcpy(&new_channel->offer_msg, offer, sizeof(hv_vmbus_channel_offer_channel)); new_channel->monitor_group = (uint8_t) offer->monitor_id / 32; new_channel->monitor_bit = (uint8_t) offer->monitor_id % 32; + /* Select default cpu for this channel. */ + vmbus_channel_select_defcpu(new_channel); + vmbus_channel_process_offer(new_channel); free(offer, M_DEVBUF);