Skip to content

Commit 3457d7d

Browse files
committed
issue: 1792164 Add PBUF_ZEROCOPY type of allocated pbuf
Extend pbuf allocation functions with new parameter as pbuf_type to by pass requested type of memory to socket. Socket layer needs this information to manage different types of mem_buf_desc_t elements. Signed-off-by: Igor Ivanov <[email protected]>
1 parent 74de061 commit 3457d7d

File tree

7 files changed

+21
-15
lines changed

7 files changed

+21
-15
lines changed

src/vma/lwip/pbuf.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ typedef enum {
5757
PBUF_RAM, /* pbuf data is stored in RAM */
5858
PBUF_ROM, /* pbuf data is stored in ROM */
5959
PBUF_REF, /* pbuf comes from the pbuf pool */
60-
PBUF_POOL /* pbuf payload refers to RAM */
60+
PBUF_POOL, /* pbuf payload refers to RAM */
61+
PBUF_ZEROCOPY /* pbuf data used directly from user */
6162
} pbuf_type;
6263

6364

src/vma/lwip/tcp.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,10 +1084,10 @@ tcp_tx_pbuf_alloc(struct tcp_pcb * pcb, u16_t length, pbuf_type type)
10841084
{
10851085
struct pbuf * p;
10861086

1087-
if (!pcb->pbuf_alloc) {
1087+
if (!pcb->pbuf_alloc || pcb->pbuf_alloc->type != type) {
10881088

10891089
// pbuf_alloc is not valid, we should allocate a new pbuf.
1090-
p = external_tcp_tx_pbuf_alloc(pcb);
1090+
p = external_tcp_tx_pbuf_alloc(pcb, type);
10911091
if (!p) return NULL;
10921092

10931093
p->next = NULL;
@@ -1129,7 +1129,7 @@ tcp_tx_pbuf_free(struct tcp_pcb * pcb, struct pbuf * p)
11291129
while (p) {
11301130
p_next = p->next;
11311131
p->next = NULL;
1132-
if (p->type == PBUF_RAM) {
1132+
if (p->type == PBUF_RAM || p->type == PBUF_ZEROCOPY) {
11331133
external_tcp_tx_pbuf_free(pcb, p);
11341134
} else {
11351135
pbuf_free(p);

src/vma/lwip/tcp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ void register_sys_readv(sys_readv_fn fn);
6666
#endif
6767

6868
#if LWIP_3RD_PARTY_BUFS
69-
typedef struct pbuf * (*tcp_tx_pbuf_alloc_fn)(void* p_conn);
69+
typedef struct pbuf * (*tcp_tx_pbuf_alloc_fn)(void* p_conn, pbuf_type type);
7070

7171
void register_tcp_tx_pbuf_alloc(tcp_tx_pbuf_alloc_fn fn);
7272

src/vma/lwip/tcp_in.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ tcp_shrink_segment(struct tcp_pcb *pcb, struct tcp_seg *seg, u32_t ackno)
820820
seg->p->next = cur_p;
821821
p->next = NULL;
822822

823-
if (p->type == PBUF_RAM) {
823+
if (p->type == PBUF_RAM || p->type == PBUF_ZEROCOPY) {
824824
external_tcp_tx_pbuf_free(pcb, p);
825825
} else {
826826
pbuf_free(p);
@@ -844,7 +844,7 @@ tcp_shrink_segment(struct tcp_pcb *pcb, struct tcp_seg *seg, u32_t ackno)
844844
seg->p->next = cur_p;
845845
p->next = NULL;
846846

847-
if (p->type == PBUF_RAM) {
847+
if (p->type == PBUF_RAM || p->type == PBUF_ZEROCOPY) {
848848
external_tcp_tx_pbuf_free(pcb, p);
849849
} else {
850850
pbuf_free(p);

src/vma/lwip/tcp_out.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ tcp_create_segment(struct tcp_pcb *pcb, struct pbuf *p, u8_t flags, u32_t seqno,
286286
*/
287287
static struct pbuf *
288288
tcp_pbuf_prealloc(u16_t length, u16_t max_length,
289-
u16_t *oversize, struct tcp_pcb *pcb, u8_t tcp_write_flag_more,
289+
u16_t *oversize, struct tcp_pcb *pcb, pbuf_type type, u8_t tcp_write_flag_more,
290290
u8_t first_seg)
291291
{
292292
struct pbuf *p;
@@ -310,7 +310,7 @@ tcp_pbuf_prealloc(u16_t length, u16_t max_length,
310310
alloc = LWIP_MIN(max_length, LWIP_MEM_ALIGN_SIZE(length + pcb->tcp_oversize_val));
311311
}
312312
}
313-
p = tcp_tx_pbuf_alloc(pcb, alloc, PBUF_RAM);
313+
p = tcp_tx_pbuf_alloc(pcb, alloc, type);
314314
if (p == NULL) {
315315
return NULL;
316316
}
@@ -440,6 +440,7 @@ tcp_write(struct tcp_pcb *pcb, const void *arg, u32_t len, u8_t apiflags)
440440
struct iovec piov[piov_max_size];
441441
int piov_cur_index = 0;
442442
int piov_cur_len = 0;
443+
pbuf_type type = PBUF_RAM;
443444

444445
int byte_queued = pcb->snd_nxt - pcb->lastack;
445446
if ( len < pcb->mss && !(apiflags & TCP_WRITE_DUMMY))
@@ -567,7 +568,7 @@ tcp_write(struct tcp_pcb *pcb, const void *arg, u32_t len, u8_t apiflags)
567568
* can use PBUF_RAW here since the data appears in the middle of
568569
* a segment. A header will never be prepended. */
569570
/* Data is copied */
570-
if ((concat_p = tcp_pbuf_prealloc(seglen, space, &oversize, pcb, TCP_WRITE_FLAG_MORE, 1)) == NULL) {
571+
if ((concat_p = tcp_pbuf_prealloc(seglen, space, &oversize, pcb, type, TCP_WRITE_FLAG_MORE, 1)) == NULL) {
571572
LWIP_DEBUGF(TCP_OUTPUT_DEBUG | 2,
572573
("tcp_write : could not allocate memory for pbuf copy size %"U16_F"\n",
573574
seglen));
@@ -606,7 +607,7 @@ tcp_write(struct tcp_pcb *pcb, const void *arg, u32_t len, u8_t apiflags)
606607

607608
/* If copy is set, memory should be allocated and data copied
608609
* into pbuf */
609-
if ((p = tcp_pbuf_prealloc(seglen + optlen, max_len, &oversize, pcb, TCP_WRITE_FLAG_MORE, queue == NULL)) == NULL) {
610+
if ((p = tcp_pbuf_prealloc(seglen + optlen, max_len, &oversize, pcb, type, TCP_WRITE_FLAG_MORE, queue == NULL)) == NULL) {
610611
LWIP_DEBUGF(TCP_OUTPUT_DEBUG | 2, ("tcp_write : could not allocate memory for pbuf copy size %"U16_F"\n", seglen));
611612
goto memerr;
612613
}
@@ -1058,6 +1059,7 @@ tcp_split_one_segment(struct tcp_pcb *pcb, struct tcp_seg *seg, u32_t lentosend,
10581059
struct pbuf *cur_p = NULL;
10591060
u16_t max_length = 0;
10601061
u16_t oversize = 0;
1062+
pbuf_type type = PBUF_RAM;
10611063

10621064
cur_seg = seg;
10631065
max_length = cur_seg->p->len;
@@ -1066,7 +1068,7 @@ tcp_split_one_segment(struct tcp_pcb *pcb, struct tcp_seg *seg, u32_t lentosend,
10661068
u32_t lentoqueue = cur_seg->len - lentosend;
10671069

10681070
/* Allocate memory for p_buf and fill in fields. */
1069-
if (NULL == (cur_p = tcp_pbuf_prealloc(lentoqueue + optlen, max_length, &oversize, pcb, 0, 0))) {
1071+
if (NULL == (cur_p = tcp_pbuf_prealloc(lentoqueue + optlen, max_length, &oversize, pcb, type, 0, 0))) {
10701072
LWIP_DEBUGF(TCP_OUTPUT_DEBUG | 2, ("tcp_split_one_segment: could not allocate memory for pbuf copy size %"U16_F"\n", (lentoqueue + optlen)));
10711073
goto out;
10721074
}
@@ -1264,6 +1266,7 @@ tcp_split_segment(struct tcp_pcb *pcb, struct tcp_seg *seg, u32_t wnd)
12641266
u16_t oversize = 0;
12651267
u8_t optlen = 0, optflags = 0;
12661268
u16_t mss_local = 0;
1269+
pbuf_type type = PBUF_RAM;
12671270

12681271
LWIP_ASSERT("tcp_split_segment: sanity check", (seg && seg->p));
12691272

@@ -1294,7 +1297,7 @@ tcp_split_segment(struct tcp_pcb *pcb, struct tcp_seg *seg, u32_t wnd)
12941297
if (seg->p->len > ((TCP_HLEN + optlen) + lentosend)) {/* First buffer is too big, split it */
12951298
u32_t lentoqueue = seg->p->len - (TCP_HLEN + optlen) - lentosend;
12961299

1297-
if (NULL == (p = tcp_pbuf_prealloc(lentoqueue + optlen, mss_local, &oversize, pcb, 0, 0))) {
1300+
if (NULL == (p = tcp_pbuf_prealloc(lentoqueue + optlen, mss_local, &oversize, pcb, type, 0, 0))) {
12981301
LWIP_DEBUGF(TCP_OUTPUT_DEBUG | 2, ("tcp_split_segment: could not allocate memory for pbuf copy size %"U16_F"\n", (lentoqueue + optlen)));
12991302
return;
13001303
}

src/vma/sock/sockinfo_tcp.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4534,11 +4534,13 @@ int sockinfo_tcp::free_buffs(uint16_t len)
45344534
return 0;
45354535
}
45364536

4537-
struct pbuf * sockinfo_tcp::tcp_tx_pbuf_alloc(void* p_conn)
4537+
struct pbuf * sockinfo_tcp::tcp_tx_pbuf_alloc(void* p_conn, pbuf_type type)
45384538
{
45394539
sockinfo_tcp *p_si_tcp = (sockinfo_tcp *)(((struct tcp_pcb*)p_conn)->my_container);
45404540
dst_entry_tcp *p_dst = (dst_entry_tcp *)(p_si_tcp->m_p_connected_dst_entry);
45414541
mem_buf_desc_t* p_desc = NULL;
4542+
4543+
NOT_IN_USE(type);
45424544
if (likely(p_dst)) {
45434545
p_desc = p_dst->get_buffer();
45444546
}

src/vma/sock/sockinfo_tcp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ class sockinfo_tcp : public sockinfo, public timer_handler
180180
virtual void update_header_field(data_updater *updater);
181181
virtual bool rx_input_cb(mem_buf_desc_t* p_rx_pkt_mem_buf_desc_info, void* pv_fd_ready_array);
182182

183-
static struct pbuf * tcp_tx_pbuf_alloc(void* p_conn);
183+
static struct pbuf * tcp_tx_pbuf_alloc(void* p_conn, pbuf_type type);
184184
static void tcp_tx_pbuf_free(void* p_conn, struct pbuf *p_buff);
185185
static struct tcp_seg * tcp_seg_alloc(void* p_conn);
186186
static void tcp_seg_free(void* p_conn, struct tcp_seg * seg);

0 commit comments

Comments
 (0)