From fed2aba021783d12720a1dfd7aebe10f0c0f1de7 Mon Sep 17 00:00:00 2001 From: Michael Blizek Date: Fri, 1 Jan 2010 16:43:39 +0100 Subject: [PATCH] new buffering logic part 1 --- net/cor/common.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ net/cor/cor.h | 31 ++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) diff --git a/net/cor/common.c b/net/cor/common.c index a17f28cc4ea..c528cda9261 100644 --- a/net/cor/common.c +++ b/net/cor/common.c @@ -286,6 +286,63 @@ found: #define PAGESIZE (1 << PAGE_SHIFT) +/* +static void data_nextreadchunk(struct data_buf *data) +{ + struct list_head *next = data->lastread->buf_list.next; + + data->last_read_offset = 0; + + if (next == &(data->items)) + data->lastread = 0; + else + data->lastread = container_of(next, struct data_buf_item, + buf_list); +} + +void data_pull(struct data_buf *data, char *dst, int len) { + BUG_ON(data->read_remaining < len); + + while(len > 0) { + int cpy = len; + + char *srcbuf = 0; + int srcbuflen = 0; + + char *srcbufcpystart = 0; + int srcbufcpylen = 0; + + BUG_ON(data->lastread == 0); + + if (data->lastread->type == TYPE_BUF) { + srcbuf = data->lastread->data.buf.buf; + srcbuflen = data->lastread->data.buf.datalen; + } else if (data->lastread->type == TYPE_SKB) { + srcbuf = data->lastread->data.skb->data; + srcbuflen = data->lastread->data.skb->len; + } else { + BUG(); + } + + srcbufcpystart = srcbuf + data->last_read_offset; + srcbufcpylen = srcbuflen - data->last_read_offset; + + if (cpy > srcbufcpylen) + cpy = srcbufcpylen; + + memcpy(dst, srcbufcpystart, cpy); + + dst += cpy; + len -= cpy; + + data->read_remaining -= cpy; + data->last_read_offset += cpy; + + if (cpy == srcbufcpylen) + data_nextreadchunk(data); + } +} */ + static int ringbuffer_init(struct ringbuffer *buf) { int i; diff --git a/net/cor/cor.h b/net/cor/cor.h index 2f3eb9d6b49..1ca4269bf32 100644 --- a/net/cor/cor.h +++ b/net/cor/cor.h @@ -303,6 +303,37 @@ struct cor_sched_data{ struct sk_buff_head requeue_queue; }; +struct data_buf_item{ + struct list_head buf_list; + + union { + struct { + char *buf; + __u32 datalen; + + }buf; + + struct sk_buff *skb; + }data; + + __u8 type; +}; + +struct data_buf{ + struct mutex lock; + struct list_head items; + struct data_buf_item *lastread; + __u64 first_offset; + __u64 read_offset; + + __u32 totalsize; + __u32 read_remaining; + + __u32 last_read_offset; + + __u32 last_buflen; +}; + /* these are the non sent, non resized packets */ struct resize_buf{ spinlock_t lock; -- 2.11.4.GIT