diff options
author | K. Y. Srinivasan <kys@microsoft.com> | 2016-04-03 02:59:46 +0200 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2016-04-30 23:00:19 +0200 |
commit | a6341f000024cdf1ec14dc26743a409a17378db5 (patch) | |
tree | b2929b9009b5e9dedd2e943c8ef4b7bd8113296e /include | |
parent | Drivers: hv: vmbus: Fix signaling logic in hv_need_to_signal_on_read() (diff) | |
download | linux-a6341f000024cdf1ec14dc26743a409a17378db5.tar.xz linux-a6341f000024cdf1ec14dc26743a409a17378db5.zip |
Drivers: hv: vmbus: Introduce functions for estimating room in the ring buffer
Introduce separate functions for estimating how much can be read from
and written to the ring buffer.
Signed-off-by: K. Y. Srinivasan <kys@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'include')
-rw-r--r-- | include/linux/hyperv.h | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h index aa0fadce9308..66226ceade37 100644 --- a/include/linux/hyperv.h +++ b/include/linux/hyperv.h @@ -151,6 +151,33 @@ hv_get_ringbuffer_availbytes(struct hv_ring_buffer_info *rbi, *read = dsize - *write; } +static inline u32 hv_get_bytes_to_read(struct hv_ring_buffer_info *rbi) +{ + u32 read_loc, write_loc, dsize, read; + + dsize = rbi->ring_datasize; + read_loc = rbi->ring_buffer->read_index; + write_loc = READ_ONCE(rbi->ring_buffer->write_index); + + read = write_loc >= read_loc ? (write_loc - read_loc) : + (dsize - read_loc) + write_loc; + + return read; +} + +static inline u32 hv_get_bytes_to_write(struct hv_ring_buffer_info *rbi) +{ + u32 read_loc, write_loc, dsize, write; + + dsize = rbi->ring_datasize; + read_loc = READ_ONCE(rbi->ring_buffer->read_index); + write_loc = rbi->ring_buffer->write_index; + + write = write_loc >= read_loc ? dsize - (write_loc - read_loc) : + read_loc - write_loc; + return write; +} + /* * VMBUS version is 32 bit entity broken up into * two 16 bit quantities: major_number. minor_number. |