Skip to content

Commit

Permalink
RH7: scsi: netvsc: Use the vmbus function to calculate ring buffer pe…
Browse files Browse the repository at this point in the history
…rcentage (corrected for 7.0|7.x)
  • Loading branch information
seansp-zz committed Aug 7, 2018
1 parent 4905be0 commit 5533542
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 3 deletions.
4 changes: 4 additions & 0 deletions hv-rhel7.x/hv/hyperv_net.h
Expand Up @@ -194,6 +194,10 @@ struct net_device_context;

extern u32 netvsc_ring_bytes;

#if (RHEL_RELEASE_CODE == RHEL_RELEASE_VERSION(7,0))
extern u32 netvsc_ring_reciprocal;
#endif

struct netvsc_device *netvsc_device_add(struct hv_device *device,
const struct netvsc_device_info *info);
int netvsc_alloc_recv_comp_ring(struct netvsc_device *net_device, u32 q_idx);
Expand Down
19 changes: 18 additions & 1 deletion hv-rhel7.x/hv/include/linux/hyperv.h
Expand Up @@ -36,6 +36,9 @@
#include <linux/device.h>
#include <linux/mod_devicetable.h>
#include <linux/interrupt.h>
#if (RHEL_RELEASE_CODE > RHEL_RELEASE_VERSION(7, 0))
#include <linux/reciprocal_div.h>
#endif

#define MAX_PAGE_BUFFER_COUNT 32
#define MAX_MULTIPAGE_BUFFER_COUNT 32 /* 128K */
Expand Down Expand Up @@ -121,6 +124,9 @@ struct hv_ring_buffer {
struct hv_ring_buffer_info {
struct hv_ring_buffer *ring_buffer;
u32 ring_size; /* Include the shared header */
#if (RHEL_RELEASE_CODE > RHEL_RELEASE_VERSION(7,0))
struct reciprocal_value ring_size_div10_reciprocal;
#endif
spinlock_t ring_lock;

u32 ring_datasize; /* < ring_size */
Expand Down Expand Up @@ -155,7 +161,18 @@ static inline u32 hv_get_bytes_to_write(const struct hv_ring_buffer_info *rbi)
return write;
}

/*
#if (RHEL_RELEASE_CODE > RHEL_RELEASE_VERSION(7, 0))
static inline u32 hv_get_avail_to_write_percent(const struct hv_ring_buffer_info *rbi)
{
u32 avail_write = hv_get_bytes_to_write(rbi);

return reciprocal_divide(
(avail_write << 3) + (avail_write << 1),
rbi->ring_size_div10_reciprocal);
}
#endif

/*
* VMBUS version is 32 bit entity broken up into
* two 16 bit quantities: major_number. minor_number.
*
Expand Down
34 changes: 32 additions & 2 deletions hv-rhel7.x/hv/netvsc.c
Expand Up @@ -35,6 +35,12 @@
#include "hyperv_net.h"
#include "netvsc_trace.h"

#if (RHEL_RELEASE_CODE == RHEL_RELEASE_VERSION(7,0))
#include <linux/reciprocal_div.h>
#else
#include <linux/hyperv.h>
#endif

/*
* Switch the data path from the synthetic interface to the VF
* interface.
Expand Down Expand Up @@ -631,6 +637,18 @@ void netvsc_device_remove(struct hv_device *device)
#define RING_AVAIL_PERCENT_HIWATER 20
#define RING_AVAIL_PERCENT_LOWATER 10

#if (RHEL_RELEASE_CODE == RHEL_RELEASE_VERSION(7, 0))
/*
* Get the percentage of available bytes to write in the ring.
* The return value is in range from 0 to 100.
*/
static u32 hv_ringbuf_avail_percent(const struct hv_ring_buffer_info *ring_info)
{
u32 avail_write = hv_get_bytes_to_write(ring_info);
return reciprocal_divide(avail_write * 100, netvsc_ring_reciprocal);
}
#endif

static inline void netvsc_free_send_slot(struct netvsc_device *net_device,
u32 index)
{
Expand Down Expand Up @@ -687,8 +705,16 @@ static void netvsc_send_tx_complete(struct netvsc_device *net_device,
struct netdev_queue *txq = netdev_get_tx_queue(ndev, q_idx);

if (netif_tx_queue_stopped(txq) &&
(hv_get_avail_to_write_percent(&channel->outbound) >
RING_AVAIL_PERCENT_HIWATER || queue_sends < 1)) {
#if (RHEL_RELEASE_CODE == RHEL_RELEASE_VERSION(7, 0))
(hv_ringbuf_avail_percent(&channel->outbound) > RING_AVAIL_PERCENT_HIWATER ||
queue_sends < 1))
{
#else
(hv_get_avail_to_write_percent(&channel->outbound) >
RING_AVAIL_PERCENT_HIWATER ||
queue_sends < 1))
{
#endif
netif_tx_wake_queue(txq);
ndev_ctx->eth_stats.wake_queue++;
}
Expand Down Expand Up @@ -804,7 +830,11 @@ static inline int netvsc_send_pkt(
struct netdev_queue *txq = netdev_get_tx_queue(ndev, packet->q_idx);
u64 req_id;
int ret;
#if (RHEL_RELEASE_CODE == RHEL_RELEASE_VERSION(7, 0))
u32 ring_avail = hv_ringbuf_avail_percent(&out_channel->outbound);
#else
u32 ring_avail = hv_get_avail_to_write_percent(&out_channel->outbound);
#endif

nvmsg.hdr.msg_type = NVSP_MSG1_TYPE_SEND_RNDIS_PKT;
if (skb)
Expand Down
11 changes: 11 additions & 0 deletions hv-rhel7.x/hv/netvsc_drv.c
Expand Up @@ -46,6 +46,10 @@

#include "hyperv_net.h"

#if (RHEL_RELEASE_CODE == RHEL_RELEASE_VERSION(7, 0))
#include <linux/reciprocal_div.h>
#endif

#define RING_SIZE_MIN 64
#define RETRY_US_LO 5000
#define RETRY_US_HI 10000
Expand All @@ -59,6 +63,10 @@ module_param(ring_size, uint, 0444);
MODULE_PARM_DESC(ring_size, "Ring buffer size (# of pages)");
unsigned int netvsc_ring_bytes;

#if (RHEL_RELEASE_CODE == RHEL_RELEASE_VERSION(7, 0))
u32 netvsc_ring_reciprocal;
#endif

static const u32 default_msg = NETIF_MSG_DRV | NETIF_MSG_PROBE |
NETIF_MSG_LINK | NETIF_MSG_IFUP |
NETIF_MSG_IFDOWN | NETIF_MSG_RX_ERR |
Expand Down Expand Up @@ -2222,6 +2230,9 @@ static int __init netvsc_drv_init(void)
ring_size);
}
netvsc_ring_bytes = ring_size * PAGE_SIZE;
#if (RHEL_RELEASE_CODE == RHEL_RELEASE_VERSION(7, 0))
netvsc_ring_reciprocal = reciprocal_value(netvsc_ring_bytes);
#endif

ret = vmbus_driver_register(&netvsc_drv);
if (ret)
Expand Down

0 comments on commit 5533542

Please sign in to comment.