Author: sephe
Date: Fri Jul 15 05:59:27 2016
New Revision: 302873
URL: https://svnweb.freebsd.org/changeset/base/302873

Log:
  hyperv/vmbus: Set vcpuid to 0, if MSR_HV_VP_INDEX does not exist.
  
  Mainly for compatibility.  While I'm here, rename cpuid related
  fields in hv_vmbus_channel.
  
  MFC after:    1 week
  Sponsored by: Microsoft OSTC
  Differential Revision:        https://reviews.freebsd.org/D7141

Modified:
  head/sys/dev/hyperv/include/hyperv.h
  head/sys/dev/hyperv/vmbus/hv_channel.c
  head/sys/dev/hyperv/vmbus/vmbus.c

Modified: head/sys/dev/hyperv/include/hyperv.h
==============================================================================
--- head/sys/dev/hyperv/include/hyperv.h        Fri Jul 15 05:51:58 2016        
(r302872)
+++ head/sys/dev/hyperv/include/hyperv.h        Fri Jul 15 05:59:27 2016        
(r302873)
@@ -274,16 +274,13 @@ typedef struct hv_vmbus_channel {
        struct hyperv_mon_param         *ch_monprm;
        struct hyperv_dma               ch_monprm_dma;
 
+       int                             ch_cpuid;       /* owner cpu */
        /*
-        * From Win8, this field specifies the target virtual process
-        * on which to deliver the interrupt from the host to guest.
-        * Before Win8, all channel interrupts would only be
-        * delivered on cpu 0. Setting this value to 0 would preserve
-        * the earlier behavior.
+        * Virtual cpuid for ch_cpuid; it is used to communicate cpuid
+        * related information w/ Hyper-V.  If MSR_HV_VP_INDEX does not
+        * exist, ch_vcpuid will always be 0 for compatibility.
         */
-       uint32_t                        target_vcpu;
-       /* The corresponding CPUID in the guest */
-       uint32_t                        target_cpu;
+       uint32_t                        ch_vcpuid;
 
        /*
         * If this is a primary channel, ch_subchan* fields

Modified: head/sys/dev/hyperv/vmbus/hv_channel.c
==============================================================================
--- head/sys/dev/hyperv/vmbus/hv_channel.c      Fri Jul 15 05:51:58 2016        
(r302872)
+++ head/sys/dev/hyperv/vmbus/hv_channel.c      Fri Jul 15 05:59:27 2016        
(r302873)
@@ -157,7 +157,7 @@ vmbus_channel_sysctl_create(hv_vmbus_cha
                    &channel->ch_id, 0, "channel id");
        }
        SYSCTL_ADD_UINT(ctx, SYSCTL_CHILDREN(devch_id_sysctl), OID_AUTO,
-           "cpu", CTLFLAG_RD, &channel->target_cpu, 0, "owner CPU id");
+           "cpu", CTLFLAG_RD, &channel->ch_cpuid, 0, "owner CPU id");
        SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(devch_id_sysctl), OID_AUTO,
            "monitor_allocated", CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MPSAFE,
            channel, 0, vmbus_channel_sysctl_monalloc, "I",
@@ -226,7 +226,7 @@ hv_vmbus_channel_open(
        vmbus_chan_update_evtflagcnt(sc, new_channel);
 
        new_channel->rxq = VMBUS_PCPU_GET(new_channel->vmbus_sc, event_tq,
-           new_channel->target_cpu);
+           new_channel->ch_cpuid);
        if (new_channel->ch_flags & VMBUS_CHAN_FLAG_BATCHREAD) {
                TASK_INIT(&new_channel->channel_task, 0,
                    vmbus_chan_task, new_channel);
@@ -290,7 +290,7 @@ hv_vmbus_channel_open(
        req->chm_chanid = new_channel->ch_id;
        req->chm_openid = new_channel->ch_id;
        req->chm_gpadl = new_channel->ch_bufring_gpadl;
-       req->chm_vcpuid = new_channel->target_vcpu;
+       req->chm_vcpuid = new_channel->ch_vcpuid;
        req->chm_rxbr_pgofs = send_ring_buffer_size >> PAGE_SHIFT;
        if (user_data_len)
                memcpy(req->chm_udata, user_data, user_data_len);
@@ -1005,7 +1005,7 @@ vmbus_chan_update_evtflagcnt(struct vmbu
        int flag_cnt;
 
        flag_cnt = (chan->ch_id / VMBUS_EVTFLAG_LEN) + 1;
-       flag_cnt_ptr = VMBUS_PCPU_PTR(sc, event_flags_cnt, chan->target_cpu);
+       flag_cnt_ptr = VMBUS_PCPU_PTR(sc, event_flags_cnt, chan->ch_cpuid);
 
        for (;;) {
                int old_flag_cnt;
@@ -1017,8 +1017,7 @@ vmbus_chan_update_evtflagcnt(struct vmbu
                        if (bootverbose) {
                                device_printf(sc->vmbus_dev,
                                    "channel%u update cpu%d flag_cnt to %d\n",
-                                   chan->ch_id,
-                                   chan->target_cpu, flag_cnt);
+                                   chan->ch_id, chan->ch_cpuid, flag_cnt);
                        }
                        break;
                }
@@ -1162,13 +1161,12 @@ vmbus_channel_cpu_set(struct hv_vmbus_ch
                cpu = 0;
        }
 
-       chan->target_cpu = cpu;
-       chan->target_vcpu = VMBUS_PCPU_GET(chan->vmbus_sc, vcpuid, cpu);
+       chan->ch_cpuid = cpu;
+       chan->ch_vcpuid = VMBUS_PCPU_GET(chan->vmbus_sc, vcpuid, cpu);
 
        if (bootverbose) {
                printf("vmbus_chan%u: assigned to cpu%u [vcpu%u]\n",
-                   chan->ch_id,
-                   chan->target_cpu, chan->target_vcpu);
+                   chan->ch_id, chan->ch_cpuid, chan->ch_vcpuid);
        }
 }
 
@@ -1401,17 +1399,17 @@ vmbus_select_outgoing_channel(struct hv_
                        continue;
                }
 
-               if (new_channel->target_vcpu == cur_vcpu){
+               if (new_channel->ch_vcpuid == cur_vcpu){
                        return new_channel;
                }
 
-               old_cpu_distance = ((outgoing_channel->target_vcpu > cur_vcpu) ?
-                   (outgoing_channel->target_vcpu - cur_vcpu) :
-                   (cur_vcpu - outgoing_channel->target_vcpu));
-
-               new_cpu_distance = ((new_channel->target_vcpu > cur_vcpu) ?
-                   (new_channel->target_vcpu - cur_vcpu) :
-                   (cur_vcpu - new_channel->target_vcpu));
+               old_cpu_distance = ((outgoing_channel->ch_vcpuid > cur_vcpu) ?
+                   (outgoing_channel->ch_vcpuid - cur_vcpu) :
+                   (cur_vcpu - outgoing_channel->ch_vcpuid));
+
+               new_cpu_distance = ((new_channel->ch_vcpuid > cur_vcpu) ?
+                   (new_channel->ch_vcpuid - cur_vcpu) :
+                   (cur_vcpu - new_channel->ch_vcpuid));
 
                if (old_cpu_distance < new_cpu_distance) {
                        continue;

Modified: head/sys/dev/hyperv/vmbus/vmbus.c
==============================================================================
--- head/sys/dev/hyperv/vmbus/vmbus.c   Fri Jul 15 05:51:58 2016        
(r302872)
+++ head/sys/dev/hyperv/vmbus/vmbus.c   Fri Jul 15 05:59:27 2016        
(r302873)
@@ -726,19 +726,11 @@ vmbus_synic_setup(void *xsc)
        uint32_t sint;
 
        if (hyperv_features & CPUID_HV_MSR_VP_INDEX) {
-               /*
-                * Save virtual processor id.
-                */
+               /* Save virtual processor id. */
                VMBUS_PCPU_GET(sc, vcpuid, cpu) = rdmsr(MSR_HV_VP_INDEX);
        } else {
-               /*
-                * XXX
-                * Virtual processoor id is only used by a pretty broken
-                * channel selection code from storvsc.  It's nothing
-                * critical even if CPUID_HV_MSR_VP_INDEX is not set; keep
-                * moving on.
-                */
-               VMBUS_PCPU_GET(sc, vcpuid, cpu) = cpu;
+               /* Set virtual processor id to 0 for compatibility. */
+               VMBUS_PCPU_GET(sc, vcpuid, cpu) = 0;
        }
 
        /*
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to