Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 11 Oct 2016 09:02:55 +0000 (UTC)
From:      Sepherosa Ziehau <sephe@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r307033 - in stable/10/sys/dev/hyperv: include vmbus
Message-ID:  <201610110902.u9B92tkh045901@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: sephe
Date: Tue Oct 11 09:02:55 2016
New Revision: 307033
URL: https://svnweb.freebsd.org/changeset/base/307033

Log:
  MFC 302873,302874
  
  302873
      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.
  
      Sponsored by:   Microsoft OSTC
      Differential Revision:  https://reviews.freebsd.org/D7141
  
  302874
      hyperv/vmbus: Field rename
  
      Sponsored by:   Microsoft OSTC
      Differential Revision:  https://reviews.freebsd.org/D7146

Modified:
  stable/10/sys/dev/hyperv/include/hyperv.h
  stable/10/sys/dev/hyperv/vmbus/hv_channel.c
  stable/10/sys/dev/hyperv/vmbus/vmbus.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/dev/hyperv/include/hyperv.h
==============================================================================
--- stable/10/sys/dev/hyperv/include/hyperv.h	Tue Oct 11 08:52:27 2016	(r307032)
+++ stable/10/sys/dev/hyperv/include/hyperv.h	Tue Oct 11 09:02:55 2016	(r307033)
@@ -242,7 +242,7 @@ typedef struct {
 	uint32_t		ring_data_size;	/* ring_size */
 } hv_vmbus_ring_buffer_info;
 
-typedef void (*hv_vmbus_pfn_channel_callback)(void *context);
+typedef void	(*vmbus_chan_callback_t)(void *);
 
 typedef struct hv_vmbus_channel {
 	device_t			ch_dev;
@@ -266,24 +266,21 @@ typedef struct hv_vmbus_channel {
 	 */
 	hv_vmbus_ring_buffer_info	inbound;
 
-	struct taskqueue *		rxq;
-	struct task			channel_task;
-	hv_vmbus_pfn_channel_callback	on_channel_callback;
-	void*				channel_callback_context;
+	struct taskqueue		*ch_tq;
+	struct task			ch_task;
+	vmbus_chan_callback_t		ch_cb;
+	void				*ch_cbarg;
 
 	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 interupt 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.
-	 */
-	uint32_t			target_vcpu;
-	/* The corresponding CPUID in the guest */
-	uint32_t			target_cpu;
+	 * 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			ch_vcpuid;
 
 	/*
 	 * If this is a primary channel, ch_subchan* fields
@@ -365,9 +362,8 @@ int		hv_vmbus_channel_open(
 				uint32_t		recv_ring_buffer_size,
 				void*			user_data,
 				uint32_t		user_data_len,
-				hv_vmbus_pfn_channel_callback
-							pfn_on_channel_callback,
-				void*			context);
+				vmbus_chan_callback_t	cb,
+				void			*cbarg);
 
 void		hv_vmbus_channel_close(hv_vmbus_channel *channel);
 

Modified: stable/10/sys/dev/hyperv/vmbus/hv_channel.c
==============================================================================
--- stable/10/sys/dev/hyperv/vmbus/hv_channel.c	Tue Oct 11 08:52:27 2016	(r307032)
+++ stable/10/sys/dev/hyperv/vmbus/hv_channel.c	Tue Oct 11 09:02:55 2016	(r307033)
@@ -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",
@@ -193,8 +193,8 @@ hv_vmbus_channel_open(
 	uint32_t			recv_ring_buffer_size,
 	void*				user_data,
 	uint32_t			user_data_len,
-	hv_vmbus_pfn_channel_callback	pfn_on_channel_callback,
-	void* 				context)
+	vmbus_chan_callback_t		cb,
+	void				*cbarg)
 {
 	struct vmbus_softc *sc = new_channel->vmbus_sc;
 	const struct vmbus_chanmsg_chopen_resp *resp;
@@ -220,19 +220,19 @@ hv_vmbus_channel_open(
 	    VMBUS_CHAN_ST_OPENED_SHIFT))
 		panic("double-open chan%u", new_channel->ch_id);
 
-	new_channel->on_channel_callback = pfn_on_channel_callback;
-	new_channel->channel_callback_context = context;
+	new_channel->ch_cb = cb;
+	new_channel->ch_cbarg = cbarg;
 
 	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_tq = VMBUS_PCPU_GET(new_channel->vmbus_sc, event_tq,
+	    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);
+		TASK_INIT(&new_channel->ch_task, 0, vmbus_chan_task,
+		    new_channel);
 	} else {
-		TASK_INIT(&new_channel->channel_task, 0,
-		    vmbus_chan_task_nobatch, new_channel);
+		TASK_INIT(&new_channel->ch_task, 0, vmbus_chan_task_nobatch,
+		    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);
@@ -521,7 +521,7 @@ hv_vmbus_channel_close_internal(hv_vmbus
 	struct vmbus_softc *sc = channel->vmbus_sc;
 	struct vmbus_msghc *mh;
 	struct vmbus_chanmsg_chclose *req;
-	struct taskqueue *rxq = channel->rxq;
+	struct taskqueue *tq = channel->ch_tq;
 	int error;
 
 	/* TODO: stringent check */
@@ -530,11 +530,11 @@ hv_vmbus_channel_close_internal(hv_vmbus
 	sysctl_ctx_free(&channel->ch_sysctl_ctx);
 
 	/*
-	 * set rxq to NULL to avoid more requests be scheduled
+	 * Set ch_tq to NULL to avoid more requests be scheduled
 	 */
-	channel->rxq = NULL;
-	taskqueue_drain(rxq, &channel->channel_task);
-	channel->on_channel_callback = NULL;
+	channel->ch_tq = NULL;
+	taskqueue_drain(tq, &channel->ch_task);
+	channel->ch_cb = NULL;
 
 	/**
 	 * Send a closing message
@@ -895,11 +895,8 @@ static void
 vmbus_chan_task(void *xchan, int pending __unused)
 {
 	struct hv_vmbus_channel *chan = xchan;
-	void (*callback)(void *);
-	void *arg;
-
-	arg = chan->channel_callback_context;
-	callback = chan->on_channel_callback;
+	vmbus_chan_callback_t cb = chan->ch_cb;
+	void *cbarg = chan->ch_cbarg;
 
 	/*
 	 * Optimize host to guest signaling by ensuring:
@@ -916,7 +913,7 @@ vmbus_chan_task(void *xchan, int pending
 	for (;;) {
 		uint32_t left;
 
-		callback(arg);
+		cb(cbarg);
 
 		left = hv_ring_buffer_read_end(&chan->inbound);
 		if (left == 0) {
@@ -932,7 +929,7 @@ vmbus_chan_task_nobatch(void *xchan, int
 {
 	struct hv_vmbus_channel *chan = xchan;
 
-	chan->on_channel_callback(chan->channel_callback_context);
+	chan->ch_cb(chan->ch_cbarg);
 }
 
 static __inline void
@@ -961,12 +958,12 @@ vmbus_event_flags_proc(struct vmbus_soft
 			channel = sc->vmbus_chmap[chid_base + chid_ofs];
 
 			/* if channel is closed or closing */
-			if (channel == NULL || channel->rxq == NULL)
+			if (channel == NULL || channel->ch_tq == NULL)
 				continue;
 
 			if (channel->ch_flags & VMBUS_CHAN_FLAG_BATCHREAD)
 				hv_ring_buffer_read_begin(&channel->inbound);
-			taskqueue_enqueue(channel->rxq, &channel->channel_task);
+			taskqueue_enqueue(channel->ch_tq, &channel->ch_task);
 		}
 	}
 }
@@ -1005,7 +1002,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 +1014,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 +1158,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 +1396,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: stable/10/sys/dev/hyperv/vmbus/vmbus.c
==============================================================================
--- stable/10/sys/dev/hyperv/vmbus/vmbus.c	Tue Oct 11 08:52:27 2016	(r307032)
+++ stable/10/sys/dev/hyperv/vmbus/vmbus.c	Tue Oct 11 09:02:55 2016	(r307033)
@@ -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;
 	}
 
 	/*



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201610110902.u9B92tkh045901>