[PATCH 1/2] vmbus: add per-channel sysfs info

2017-09-21 Thread kys
From: Stephen Hemminger 

This extends existing vmbus related sysfs structure to provide per-channel
state information. This is useful when diagnosing issues with multiple
queues in networking and storage.

The existing sysfs only displayed information about the primary
channel. The one place it reported multiple channels was the
channel_vp_mapping file which violated the sysfs convention
of one value per file.

Signed-off-by: Stephen Hemminger 
Signed-off-by: K. Y. Srinivasan 
---
 Documentation/ABI/stable/sysfs-bus-vmbus |  56 ++
 drivers/hv/channel_mgmt.c|  10 +-
 drivers/hv/hyperv_vmbus.h|   2 +
 drivers/hv/vmbus_drv.c   | 185 +--
 include/linux/hyperv.h   |   6 +
 5 files changed, 246 insertions(+), 13 deletions(-)

diff --git a/Documentation/ABI/stable/sysfs-bus-vmbus 
b/Documentation/ABI/stable/sysfs-bus-vmbus
index 5d0125f7bcaf..0ebd8a1537a0 100644
--- a/Documentation/ABI/stable/sysfs-bus-vmbus
+++ b/Documentation/ABI/stable/sysfs-bus-vmbus
@@ -41,3 +41,59 @@ KernelVersion:   4.5
 Contact:   K. Y. Srinivasan 
 Description:   The 16 bit vendor ID of the device
 Users: tools/hv/lsvmbus and user level RDMA libraries
+
+What:  /sys/bus/vmbus/devices/vmbus_*/channels/relid/cpu
+Date:  September. 2017
+KernelVersion: 4.14
+Contact:   Stephen Hemminger 
+Description:   VCPU (sub)channel is affinitized to
+Users: tools/hv/lsvmbus and other debuggig tools
+
+What:  /sys/bus/vmbus/devices/vmbus_*/channels/relid/cpu
+Date:  September. 2017
+KernelVersion: 4.14
+Contact:   Stephen Hemminger 
+Description:   VCPU (sub)channel is affinitized to
+Users: tools/hv/lsvmbus and other debuggig tools
+
+What:  /sys/bus/vmbus/devices/vmbus_*/channels/relid/in_mask
+Date:  September. 2017
+KernelVersion: 4.14
+Contact:   Stephen Hemminger 
+Description:   Inbound channel signaling state
+Users: Debuggig tools
+
+What:  /sys/bus/vmbus/devices/vmbus_*/channels/relid/latency
+Date:  September. 2017
+KernelVersion: 4.14
+Contact:   Stephen Hemminger 
+Description:   Channel signaling latency
+Users: Debuggig tools
+
+What:  /sys/bus/vmbus/devices/vmbus_*/channels/relid/out_mask
+Date:  September. 2017
+KernelVersion: 4.14
+Contact:   Stephen Hemminger 
+Description:   Outbound channel signaling state
+Users: Debuggig tools
+
+What:  /sys/bus/vmbus/devices/vmbus_*/channels/relid/pending
+Date:  September. 2017
+KernelVersion: 4.14
+Contact:   Stephen Hemminger 
+Description:   Channel interrupt pending state
+Users: Debuggig tools
+
+What:  /sys/bus/vmbus/devices/vmbus_*/channels/relid/read_avail
+Date:  September. 2017
+KernelVersion: 4.14
+Contact:   Stephen Hemminger 
+Description:   Bytes availabble to read
+Users: Debuggig tools
+
+What:  /sys/bus/vmbus/devices/vmbus_*/channels/relid/write_avail
+Date:  September. 2017
+KernelVersion: 4.14
+Contact:   Stephen Hemminger 
+Description:   Bytes availabble to write
+Users: Debuggig tools
diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c
index 624d815745e4..747887038992 100644
--- a/drivers/hv/channel_mgmt.c
+++ b/drivers/hv/channel_mgmt.c
@@ -350,7 +350,7 @@ static void free_channel(struct vmbus_channel *channel)
 {
tasklet_kill(>callback_event);
 
-   kfree_rcu(channel, rcu);
+   kobject_put(>kobj);
 }
 
 static void percpu_channel_enq(void *arg)
@@ -513,6 +513,14 @@ static void vmbus_process_offer(struct vmbus_channel 
*newchannel)
newchannel->state = CHANNEL_OPEN_STATE;
 
if (!fnew) {
+   struct hv_device *dev
+   = newchannel->primary_channel->device_obj;
+
+   if (vmbus_add_channel_kobj(dev, newchannel)) {
+   atomic_dec(_connection.offer_in_progress);
+   goto err_free_chan;
+   }
+
if (channel->sc_creation_callback != NULL)
channel->sc_creation_callback(newchannel);
return;
diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
index 1b6a5e0dfa75..bfa2d0af4e1d 100644
--- a/drivers/hv/hyperv_vmbus.h
+++ b/drivers/hv/hyperv_vmbus.h
@@ -384,6 +384,8 @@ struct hv_device *vmbus_device_create(const uuid_le *type,
 
 int vmbus_device_register(struct hv_device *child_device_obj);
 void vmbus_device_unregister(struct hv_device *device_obj);
+int vmbus_add_channel_kobj(struct hv_device *device_obj,
+  struct vmbus_channel *channel);

[PATCH 1/2] vmbus: add per-channel sysfs info

2017-09-21 Thread kys
From: Stephen Hemminger 

This extends existing vmbus related sysfs structure to provide per-channel
state information. This is useful when diagnosing issues with multiple
queues in networking and storage.

The existing sysfs only displayed information about the primary
channel. The one place it reported multiple channels was the
channel_vp_mapping file which violated the sysfs convention
of one value per file.

Signed-off-by: Stephen Hemminger 
Signed-off-by: K. Y. Srinivasan 
---
 Documentation/ABI/stable/sysfs-bus-vmbus |  56 ++
 drivers/hv/channel_mgmt.c|  10 +-
 drivers/hv/hyperv_vmbus.h|   2 +
 drivers/hv/vmbus_drv.c   | 185 +--
 include/linux/hyperv.h   |   6 +
 5 files changed, 246 insertions(+), 13 deletions(-)

diff --git a/Documentation/ABI/stable/sysfs-bus-vmbus 
b/Documentation/ABI/stable/sysfs-bus-vmbus
index 5d0125f7bcaf..0ebd8a1537a0 100644
--- a/Documentation/ABI/stable/sysfs-bus-vmbus
+++ b/Documentation/ABI/stable/sysfs-bus-vmbus
@@ -41,3 +41,59 @@ KernelVersion:   4.5
 Contact:   K. Y. Srinivasan 
 Description:   The 16 bit vendor ID of the device
 Users: tools/hv/lsvmbus and user level RDMA libraries
+
+What:  /sys/bus/vmbus/devices/vmbus_*/channels/relid/cpu
+Date:  September. 2017
+KernelVersion: 4.14
+Contact:   Stephen Hemminger 
+Description:   VCPU (sub)channel is affinitized to
+Users: tools/hv/lsvmbus and other debuggig tools
+
+What:  /sys/bus/vmbus/devices/vmbus_*/channels/relid/cpu
+Date:  September. 2017
+KernelVersion: 4.14
+Contact:   Stephen Hemminger 
+Description:   VCPU (sub)channel is affinitized to
+Users: tools/hv/lsvmbus and other debuggig tools
+
+What:  /sys/bus/vmbus/devices/vmbus_*/channels/relid/in_mask
+Date:  September. 2017
+KernelVersion: 4.14
+Contact:   Stephen Hemminger 
+Description:   Inbound channel signaling state
+Users: Debuggig tools
+
+What:  /sys/bus/vmbus/devices/vmbus_*/channels/relid/latency
+Date:  September. 2017
+KernelVersion: 4.14
+Contact:   Stephen Hemminger 
+Description:   Channel signaling latency
+Users: Debuggig tools
+
+What:  /sys/bus/vmbus/devices/vmbus_*/channels/relid/out_mask
+Date:  September. 2017
+KernelVersion: 4.14
+Contact:   Stephen Hemminger 
+Description:   Outbound channel signaling state
+Users: Debuggig tools
+
+What:  /sys/bus/vmbus/devices/vmbus_*/channels/relid/pending
+Date:  September. 2017
+KernelVersion: 4.14
+Contact:   Stephen Hemminger 
+Description:   Channel interrupt pending state
+Users: Debuggig tools
+
+What:  /sys/bus/vmbus/devices/vmbus_*/channels/relid/read_avail
+Date:  September. 2017
+KernelVersion: 4.14
+Contact:   Stephen Hemminger 
+Description:   Bytes availabble to read
+Users: Debuggig tools
+
+What:  /sys/bus/vmbus/devices/vmbus_*/channels/relid/write_avail
+Date:  September. 2017
+KernelVersion: 4.14
+Contact:   Stephen Hemminger 
+Description:   Bytes availabble to write
+Users: Debuggig tools
diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c
index 624d815745e4..747887038992 100644
--- a/drivers/hv/channel_mgmt.c
+++ b/drivers/hv/channel_mgmt.c
@@ -350,7 +350,7 @@ static void free_channel(struct vmbus_channel *channel)
 {
tasklet_kill(>callback_event);
 
-   kfree_rcu(channel, rcu);
+   kobject_put(>kobj);
 }
 
 static void percpu_channel_enq(void *arg)
@@ -513,6 +513,14 @@ static void vmbus_process_offer(struct vmbus_channel 
*newchannel)
newchannel->state = CHANNEL_OPEN_STATE;
 
if (!fnew) {
+   struct hv_device *dev
+   = newchannel->primary_channel->device_obj;
+
+   if (vmbus_add_channel_kobj(dev, newchannel)) {
+   atomic_dec(_connection.offer_in_progress);
+   goto err_free_chan;
+   }
+
if (channel->sc_creation_callback != NULL)
channel->sc_creation_callback(newchannel);
return;
diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
index 1b6a5e0dfa75..bfa2d0af4e1d 100644
--- a/drivers/hv/hyperv_vmbus.h
+++ b/drivers/hv/hyperv_vmbus.h
@@ -384,6 +384,8 @@ struct hv_device *vmbus_device_create(const uuid_le *type,
 
 int vmbus_device_register(struct hv_device *child_device_obj);
 void vmbus_device_unregister(struct hv_device *device_obj);
+int vmbus_add_channel_kobj(struct hv_device *device_obj,
+  struct vmbus_channel *channel);
 
 struct vmbus_channel *relid2channel(u32 relid);
 
diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index 43160a2eafe0..c126d3937414 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -107,28 +107,30 @@ static void print_alias_name(struct hv_device