sock: create spdk_sock_prep_reqs function.
The purpose is to reduce the duplicated functions in posix and uring implmentation. Signed-off-by: Ziye Yang <ziye.yang@intel.com> Change-Id: Ia0568b2490d362e7e78fa59b3ca88a60313ba0bd Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/5284 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Community-CI: Mellanox Build Bot Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
This commit is contained in:
parent
0e99c68d61
commit
c38a1bc002
@ -41,6 +41,7 @@
|
|||||||
#include "spdk/stdinc.h"
|
#include "spdk/stdinc.h"
|
||||||
#include "spdk/sock.h"
|
#include "spdk/sock.h"
|
||||||
#include "spdk/queue.h"
|
#include "spdk/queue.h"
|
||||||
|
#include "spdk/likely.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@ -51,6 +52,7 @@ extern "C" {
|
|||||||
#define MIN_SOCK_PIPE_SIZE 1024
|
#define MIN_SOCK_PIPE_SIZE 1024
|
||||||
#define MIN_SO_RCVBUF_SIZE (2 * 1024 * 1024)
|
#define MIN_SO_RCVBUF_SIZE (2 * 1024 * 1024)
|
||||||
#define MIN_SO_SNDBUF_SIZE (2 * 1024 * 1024)
|
#define MIN_SO_SNDBUF_SIZE (2 * 1024 * 1024)
|
||||||
|
#define IOV_BATCH_SIZE 64
|
||||||
|
|
||||||
struct spdk_sock {
|
struct spdk_sock {
|
||||||
struct spdk_net_impl *net_impl;
|
struct spdk_net_impl *net_impl;
|
||||||
@ -221,6 +223,60 @@ spdk_sock_abort_requests(struct spdk_sock *sock)
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline int
|
||||||
|
spdk_sock_prep_reqs(struct spdk_sock *_sock, struct iovec *iovs, int index,
|
||||||
|
struct spdk_sock_request **last_req)
|
||||||
|
{
|
||||||
|
int iovcnt, i;
|
||||||
|
struct spdk_sock_request *req;
|
||||||
|
unsigned int offset;
|
||||||
|
|
||||||
|
/* Gather an iov */
|
||||||
|
iovcnt = index;
|
||||||
|
if (spdk_unlikely(iovcnt >= IOV_BATCH_SIZE)) {
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (last_req != NULL && *last_req != NULL) {
|
||||||
|
req = TAILQ_NEXT(*last_req, internal.link);
|
||||||
|
} else {
|
||||||
|
req = TAILQ_FIRST(&_sock->queued_reqs);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (req) {
|
||||||
|
offset = req->internal.offset;
|
||||||
|
|
||||||
|
for (i = 0; i < req->iovcnt; i++) {
|
||||||
|
/* Consume any offset first */
|
||||||
|
if (offset >= SPDK_SOCK_REQUEST_IOV(req, i)->iov_len) {
|
||||||
|
offset -= SPDK_SOCK_REQUEST_IOV(req, i)->iov_len;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
iovs[iovcnt].iov_base = SPDK_SOCK_REQUEST_IOV(req, i)->iov_base + offset;
|
||||||
|
iovs[iovcnt].iov_len = SPDK_SOCK_REQUEST_IOV(req, i)->iov_len - offset;
|
||||||
|
iovcnt++;
|
||||||
|
|
||||||
|
offset = 0;
|
||||||
|
|
||||||
|
if (iovcnt >= IOV_BATCH_SIZE) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (iovcnt >= IOV_BATCH_SIZE) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (last_req != NULL) {
|
||||||
|
*last_req = req;
|
||||||
|
}
|
||||||
|
req = TAILQ_NEXT(req, internal.link);
|
||||||
|
}
|
||||||
|
|
||||||
|
end:
|
||||||
|
return iovcnt;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -44,12 +44,10 @@
|
|||||||
#include "spdk/pipe.h"
|
#include "spdk/pipe.h"
|
||||||
#include "spdk/sock.h"
|
#include "spdk/sock.h"
|
||||||
#include "spdk/util.h"
|
#include "spdk/util.h"
|
||||||
#include "spdk/likely.h"
|
|
||||||
#include "spdk_internal/sock.h"
|
#include "spdk_internal/sock.h"
|
||||||
|
|
||||||
#define MAX_TMPBUF 1024
|
#define MAX_TMPBUF 1024
|
||||||
#define PORTNUMLEN 32
|
#define PORTNUMLEN 32
|
||||||
#define IOV_BATCH_SIZE 64
|
|
||||||
|
|
||||||
#if defined(SO_ZEROCOPY) && defined(MSG_ZEROCOPY)
|
#if defined(SO_ZEROCOPY) && defined(MSG_ZEROCOPY)
|
||||||
#define SPDK_ZEROCOPY
|
#define SPDK_ZEROCOPY
|
||||||
@ -750,36 +748,7 @@ _sock_flush(struct spdk_sock *sock)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Gather an iov */
|
iovcnt = spdk_sock_prep_reqs(sock, iovs, 0, NULL);
|
||||||
iovcnt = 0;
|
|
||||||
req = TAILQ_FIRST(&sock->queued_reqs);
|
|
||||||
while (req) {
|
|
||||||
offset = req->internal.offset;
|
|
||||||
|
|
||||||
for (i = 0; i < req->iovcnt; i++) {
|
|
||||||
/* Consume any offset first */
|
|
||||||
if (offset >= SPDK_SOCK_REQUEST_IOV(req, i)->iov_len) {
|
|
||||||
offset -= SPDK_SOCK_REQUEST_IOV(req, i)->iov_len;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
iovs[iovcnt].iov_base = SPDK_SOCK_REQUEST_IOV(req, i)->iov_base + offset;
|
|
||||||
iovs[iovcnt].iov_len = SPDK_SOCK_REQUEST_IOV(req, i)->iov_len - offset;
|
|
||||||
iovcnt++;
|
|
||||||
|
|
||||||
offset = 0;
|
|
||||||
|
|
||||||
if (iovcnt >= IOV_BATCH_SIZE) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (iovcnt >= IOV_BATCH_SIZE) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
req = TAILQ_NEXT(req, internal.link);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (iovcnt == 0) {
|
if (iovcnt == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -38,7 +38,6 @@
|
|||||||
#include <liburing.h>
|
#include <liburing.h>
|
||||||
|
|
||||||
#include "spdk/barrier.h"
|
#include "spdk/barrier.h"
|
||||||
#include "spdk/likely.h"
|
|
||||||
#include "spdk/log.h"
|
#include "spdk/log.h"
|
||||||
#include "spdk/pipe.h"
|
#include "spdk/pipe.h"
|
||||||
#include "spdk/sock.h"
|
#include "spdk/sock.h"
|
||||||
@ -51,7 +50,6 @@
|
|||||||
#define MAX_TMPBUF 1024
|
#define MAX_TMPBUF 1024
|
||||||
#define PORTNUMLEN 32
|
#define PORTNUMLEN 32
|
||||||
#define SPDK_SOCK_GROUP_QUEUE_DEPTH 4096
|
#define SPDK_SOCK_GROUP_QUEUE_DEPTH 4096
|
||||||
#define IOV_BATCH_SIZE 64
|
|
||||||
|
|
||||||
enum spdk_sock_task_type {
|
enum spdk_sock_task_type {
|
||||||
SPDK_SOCK_TASK_POLLIN = 0,
|
SPDK_SOCK_TASK_POLLIN = 0,
|
||||||
@ -720,60 +718,6 @@ uring_sock_writev(struct spdk_sock *_sock, struct iovec *iov, int iovcnt)
|
|||||||
return writev(sock->fd, iov, iovcnt);
|
return writev(sock->fd, iov, iovcnt);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
sock_prep_reqs(struct spdk_sock *_sock, struct iovec *iovs, int index,
|
|
||||||
struct spdk_sock_request **last_req)
|
|
||||||
{
|
|
||||||
int iovcnt, i;
|
|
||||||
struct spdk_sock_request *req;
|
|
||||||
unsigned int offset;
|
|
||||||
|
|
||||||
/* Gather an iov */
|
|
||||||
iovcnt = index;
|
|
||||||
if (spdk_unlikely(iovcnt >= IOV_BATCH_SIZE)) {
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (last_req != NULL && *last_req != NULL) {
|
|
||||||
req = TAILQ_NEXT(*last_req, internal.link);
|
|
||||||
} else {
|
|
||||||
req = TAILQ_FIRST(&_sock->queued_reqs);
|
|
||||||
}
|
|
||||||
|
|
||||||
while (req) {
|
|
||||||
offset = req->internal.offset;
|
|
||||||
|
|
||||||
for (i = 0; i < req->iovcnt; i++) {
|
|
||||||
/* Consume any offset first */
|
|
||||||
if (offset >= SPDK_SOCK_REQUEST_IOV(req, i)->iov_len) {
|
|
||||||
offset -= SPDK_SOCK_REQUEST_IOV(req, i)->iov_len;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
iovs[iovcnt].iov_base = SPDK_SOCK_REQUEST_IOV(req, i)->iov_base + offset;
|
|
||||||
iovs[iovcnt].iov_len = SPDK_SOCK_REQUEST_IOV(req, i)->iov_len - offset;
|
|
||||||
iovcnt++;
|
|
||||||
|
|
||||||
offset = 0;
|
|
||||||
|
|
||||||
if (iovcnt >= IOV_BATCH_SIZE) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (iovcnt >= IOV_BATCH_SIZE) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (last_req != NULL) {
|
|
||||||
*last_req = req;
|
|
||||||
}
|
|
||||||
req = TAILQ_NEXT(req, internal.link);
|
|
||||||
}
|
|
||||||
|
|
||||||
end:
|
|
||||||
return iovcnt;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
sock_complete_reqs(struct spdk_sock *_sock, ssize_t rc)
|
sock_complete_reqs(struct spdk_sock *_sock, ssize_t rc)
|
||||||
{
|
{
|
||||||
@ -838,7 +782,7 @@ _sock_flush(struct spdk_sock *_sock)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
iovcnt = sock_prep_reqs(&sock->base, task->iovs, task->iov_cnt, &task->last_req);
|
iovcnt = spdk_sock_prep_reqs(&sock->base, task->iovs, task->iov_cnt, &task->last_req);
|
||||||
if (!iovcnt) {
|
if (!iovcnt) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1010,7 +954,7 @@ _sock_flush_client(struct spdk_sock *_sock)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Gather an iov */
|
/* Gather an iov */
|
||||||
iovcnt = sock_prep_reqs(_sock, iovs, 0, NULL);
|
iovcnt = spdk_sock_prep_reqs(_sock, iovs, 0, NULL);
|
||||||
if (iovcnt == 0) {
|
if (iovcnt == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -203,7 +203,7 @@ flush_server(void)
|
|||||||
* that is fully completed. */
|
* that is fully completed. */
|
||||||
spdk_sock_request_queue(sock, req1);
|
spdk_sock_request_queue(sock, req1);
|
||||||
cb_arg1 = false;
|
cb_arg1 = false;
|
||||||
rc = sock_prep_reqs(sock, usock.write_task.iovs, 0, NULL);
|
rc = spdk_sock_prep_reqs(sock, usock.write_task.iovs, 0, NULL);
|
||||||
CU_ASSERT(rc == 2);
|
CU_ASSERT(rc == 2);
|
||||||
sock_complete_reqs(sock, 128);
|
sock_complete_reqs(sock, 128);
|
||||||
CU_ASSERT(cb_arg1 == true);
|
CU_ASSERT(cb_arg1 == true);
|
||||||
@ -214,7 +214,7 @@ flush_server(void)
|
|||||||
spdk_sock_request_queue(sock, req2);
|
spdk_sock_request_queue(sock, req2);
|
||||||
cb_arg1 = false;
|
cb_arg1 = false;
|
||||||
cb_arg2 = false;
|
cb_arg2 = false;
|
||||||
rc = sock_prep_reqs(sock, usock.write_task.iovs, 0, NULL);
|
rc = spdk_sock_prep_reqs(sock, usock.write_task.iovs, 0, NULL);
|
||||||
CU_ASSERT(rc == 4);
|
CU_ASSERT(rc == 4);
|
||||||
sock_complete_reqs(sock, 192);
|
sock_complete_reqs(sock, 192);
|
||||||
CU_ASSERT(cb_arg1 == true);
|
CU_ASSERT(cb_arg1 == true);
|
||||||
@ -225,7 +225,7 @@ flush_server(void)
|
|||||||
/* One request that is partially sent. */
|
/* One request that is partially sent. */
|
||||||
spdk_sock_request_queue(sock, req1);
|
spdk_sock_request_queue(sock, req1);
|
||||||
cb_arg1 = false;
|
cb_arg1 = false;
|
||||||
rc = sock_prep_reqs(sock, usock.write_task.iovs, 0, NULL);
|
rc = spdk_sock_prep_reqs(sock, usock.write_task.iovs, 0, NULL);
|
||||||
CU_ASSERT(rc == 2);
|
CU_ASSERT(rc == 2);
|
||||||
sock_complete_reqs(sock, 92);
|
sock_complete_reqs(sock, 92);
|
||||||
CU_ASSERT(rc == 2);
|
CU_ASSERT(rc == 2);
|
||||||
|
Loading…
Reference in New Issue
Block a user