Staging: hv: Introduce a function to wait to drain outgoing I/O
Rather than busy loop waiting to drain I/O, introduce a function that does not burn CPU cycles waiting. Signed-off-by: K. Y. Srinivasan <kys@microsoft.com> Signed-off-by: Haiyang Zhang <haiyangz@microsoft.com> Signed-off-by: Abhishek Kane <v-abkane@microsoft.com> Signed-off-by: Hank Janssen <hjanssen@microsoft.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
This commit is contained in:
parent
43c51f7dd1
commit
604df37dc3
2 changed files with 17 additions and 1 deletions
|
@ -47,6 +47,7 @@ static inline struct storvsc_device *alloc_stor_device(struct hv_device *device)
|
||||||
/* (ie get_stor_device() and must_get_stor_device()) to proceed. */
|
/* (ie get_stor_device() and must_get_stor_device()) to proceed. */
|
||||||
atomic_cmpxchg(&stor_device->ref_count, 0, 2);
|
atomic_cmpxchg(&stor_device->ref_count, 0, 2);
|
||||||
|
|
||||||
|
init_waitqueue_head(&stor_device->waiting_to_drain);
|
||||||
stor_device->device = device;
|
stor_device->device = device;
|
||||||
device->ext = stor_device;
|
device->ext = stor_device;
|
||||||
|
|
||||||
|
@ -332,7 +333,10 @@ static void stor_vsc_on_io_completion(struct hv_device *device,
|
||||||
|
|
||||||
request->on_io_completion(request);
|
request->on_io_completion(request);
|
||||||
|
|
||||||
atomic_dec(&stor_device->num_outstanding_req);
|
if (atomic_dec_and_test(&stor_device->num_outstanding_req) &&
|
||||||
|
stor_device->drain_notify)
|
||||||
|
wake_up(&stor_device->waiting_to_drain);
|
||||||
|
|
||||||
|
|
||||||
put_stor_device(device);
|
put_stor_device(device);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#define _STORVSC_API_H_
|
#define _STORVSC_API_H_
|
||||||
|
|
||||||
#include <linux/kernel.h>
|
#include <linux/kernel.h>
|
||||||
|
#include <linux/wait.h>
|
||||||
#include "vstorage.h"
|
#include "vstorage.h"
|
||||||
#include "vmbus_api.h"
|
#include "vmbus_api.h"
|
||||||
#include "vmbus.h"
|
#include "vmbus.h"
|
||||||
|
@ -108,8 +109,11 @@ struct storvsc_device {
|
||||||
/* 0 indicates the device is being destroyed */
|
/* 0 indicates the device is being destroyed */
|
||||||
atomic_t ref_count;
|
atomic_t ref_count;
|
||||||
|
|
||||||
|
bool drain_notify;
|
||||||
atomic_t num_outstanding_req;
|
atomic_t num_outstanding_req;
|
||||||
|
|
||||||
|
wait_queue_head_t waiting_to_drain;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Each unique Port/Path/Target represents 1 channel ie scsi
|
* Each unique Port/Path/Target represents 1 channel ie scsi
|
||||||
* controller. In reality, the pathid, targetid is always 0
|
* controller. In reality, the pathid, targetid is always 0
|
||||||
|
@ -161,6 +165,14 @@ struct storvsc_driver *drv_to_stordrv(struct device_driver *d)
|
||||||
return hvdr_to_stordr(hvdrv);
|
return hvdr_to_stordr(hvdrv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void storvsc_wait_to_drain(struct storvsc_device *dev)
|
||||||
|
{
|
||||||
|
dev->drain_notify = true;
|
||||||
|
wait_event(dev->waiting_to_drain,
|
||||||
|
atomic_read(&dev->num_outstanding_req) == 0);
|
||||||
|
dev->drain_notify = false;
|
||||||
|
}
|
||||||
|
|
||||||
/* Interface */
|
/* Interface */
|
||||||
|
|
||||||
int storvsc_dev_add(struct hv_device *device,
|
int storvsc_dev_add(struct hv_device *device,
|
||||||
|
|
Loading…
Add table
Reference in a new issue