Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
trx-ecpri
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
trx-ecpri
Commits
370ef0bc
Commit
370ef0bc
authored
Dec 17, 2024
by
Joanne Hugé
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wip
parent
4e72db49
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
1014 additions
and
0 deletions
+1014
-0
ring_buffer.c
ring_buffer.c
+165
-0
trx_ecpri.c
trx_ecpri.c
+849
-0
No files found.
ring_buffer.c
0 → 100644
View file @
370ef0bc
//#define TEST
#ifdef TEST
#include <arpa/inet.h>
#include <assert.h>
#include <errno.h>
#include <error.h>
#include <fcntl.h>
#include <getopt.h>
#include <immintrin.h>
#include <inttypes.h>
#include <limits.h>
#include <linux/if_packet.h>
#include <math.h>
#include <netdb.h>
#include <netinet/ether.h>
#include <netinet/in.h>
#include <net/if.h>
#include <pthread.h>
#include <sched.h>
#include <semaphore.h>
#include <signal.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <time.h>
#include <unistd.h>
#endif
typedef
struct
{
volatile
char
*
buffer
;
volatile
size_t
*
block_buffer
;
char
name
[
64
];
size_t
len
;
size_t
block_buf_len
;
size_t
min_block_size
;
volatile
int
write_index
;
volatile
int
read_index
;
volatile
int
block_write_index
;
volatile
int
block_read_index
;
}
ring_buffer_t
;
static
void
init_rbuf
(
ring_buffer_t
*
rbuf
,
char
*
name
,
size_t
len
,
size_t
min_block_size
)
{
//log_debug("TRX_ECPRI", "Allocating %s with %d bytes\n", _name, len);
rbuf
->
len
=
len
;
rbuf
->
block_buf_len
=
len
/
min_block_size
;
rbuf
->
buffer
=
(
char
*
)
malloc
(
len
);
rbuf
->
block_buffer
=
(
size_t
*
)
malloc
(
rbuf
->
block_buf_len
*
sizeof
(
size_t
));
rbuf
->
min_block_size
=
min_block_size
;
rbuf
->
write_index
=
0
;
rbuf
->
read_index
=
0
;
rbuf
->
block_write_index
=
0
;
rbuf
->
block_read_index
=
0
;
strcpy
(
rbuf
->
name
,
name
);
}
static
int
rbuf_read_amount
(
ring_buffer_t
*
rbuf
)
{
return
(
rbuf
->
write_index
+
rbuf
->
len
-
rbuf
->
read_index
)
%
rbuf
->
len
;
}
static
int
rbuf_write_amount
(
ring_buffer_t
*
rbuf
)
{
// Don't write everything to avoid write index catching up to read index
// That we way we don't have to use locks
return
((
rbuf
->
read_index
+
rbuf
->
len
-
rbuf
->
write_index
-
1
)
%
rbuf
->
len
);
}
static
volatile
char
*
rbuf_write
(
ring_buffer_t
*
rbuf
)
{
return
rbuf
->
buffer
+
rbuf
->
write_index
;
}
static
void
rbuf_increment_write
(
ring_buffer_t
*
rbuf
,
size_t
size
)
{
rbuf
->
write_index
=
(
rbuf
->
write_index
+
size
)
%
rbuf
->
len
;
rbuf
->
block_buffer
[
rbuf
->
block_write_index
]
=
size
;
rbuf
->
block_write_index
=
(
rbuf
->
block_write_index
+
1
)
%
rbuf
->
block_buf_len
;
}
static
volatile
char
*
rbuf_read
(
ring_buffer_t
*
rbuf
,
size_t
*
size
)
{
volatile
char
*
data
=
rbuf
->
buffer
+
rbuf
->
read_index
;
*
size
=
rbuf
->
block_buffer
[
rbuf
->
block_read_index
];
rbuf
->
read_index
=
(
rbuf
->
read_index
+
*
size
)
%
rbuf
->
len
;
rbuf
->
block_read_index
=
(
rbuf
->
block_read_index
+
1
)
%
rbuf
->
block_buf_len
;
return
data
;
}
#ifdef TEST
static
ring_buffer_t
test_rbuf
;
int
main
(
int
argc
,
char
**
argv
)
{
char
volatile
*
data
;
size_t
size
;
int
i
,
j
;
init_rbuf
(
&
test_rbuf
,
"TEST"
,
64
,
4
);
for
(
j
=
0
;
j
<
10
;
j
++
)
{
data
=
rbuf_write
(
&
test_rbuf
);
strcpy
(
data
,
"hello"
);
rbuf_increment_write
(
&
test_rbuf
,
6
);
data
=
rbuf_write
(
&
test_rbuf
);
strcpy
(
data
,
"world"
);
rbuf_increment_write
(
&
test_rbuf
,
6
);
data
=
rbuf_read
(
&
test_rbuf
,
&
size
);
for
(
i
=
0
;
i
<
size
;
i
++
)
{
printf
(
"%c"
,
data
[
i
]);
}
printf
(
"
\n
"
);
data
=
rbuf_read
(
&
test_rbuf
,
&
size
);
for
(
i
=
0
;
i
<
size
;
i
++
)
{
printf
(
"%c"
,
data
[
i
]);
}
printf
(
"
\n
"
);
}
return
0
;
}
#endif
#ifdef ARCHIVE
static
void
rbuf_update_write_index
(
ring_buffer_t
*
rbuf
)
{
rbuf
->
write_index
=
(
rbuf
->
write_index
+
1
)
%
rbuf
->
buf_len
;
}
static
void
rbuf_update_read_index
(
ring_buffer_t
*
rbuf
)
{
rbuf
->
read_index
=
(
rbuf
->
read_index
+
1
)
%
rbuf
->
buf_len
;
}
static
int
rbuf_read_amount
(
ring_buffer_t
*
rbuf
)
{
return
(
rbuf
->
write_index
+
rbuf
->
buf_len
-
rbuf
->
read_index
)
%
rbuf
->
buf_len
;
}
static
int
rbuf_write_amount
(
ring_buffer_t
*
rbuf
)
{
// Don't write everything to avoid write index catching up to read index
// That we way we don't have to use locks
return
((
rbuf
->
read_index
+
rbuf
->
buf_len
-
rbuf
->
write_index
-
1
)
%
rbuf
->
buf_len
);
}
static
int
rbuf_contiguous_copy
(
ring_buffer_t
*
rbuf1
,
ring_buffer_t
*
rbuf2
,
int
n
)
{
int
ret
=
n
;
if
(
rbuf1
)
{
n
=
rbuf1
->
buf_len
-
rbuf1
->
read_index
;
ret
=
n
<
ret
?
n
:
ret
;
}
if
(
rbuf2
)
n
=
rbuf2
->
buf_len
-
rbuf2
->
write_index
;
return
n
<
ret
?
n
:
ret
;
}
#define RBUF_READ0(rbuf, type) (((type *) rbuf.buffer) + (rbuf.read_index * rbuf.len))
#define RBUF_WRITE0(rbuf, type) (((type *) rbuf.buffer) + (rbuf.write_index * rbuf.len))
#define RBUF_READ(rbuf, i, type) (((type *) rbuf.buffer) + (((rbuf.read_index + i) % rbuf.buf_len) * rbuf.len))
#define RBUF_WRITE(rbuf, i, type) (((type *) rbuf.buffer) + (((rbuf.write_index + i) % rbuf.buf_len) * rbuf.len))
#define RBUF_INIT(rbuf, _name, _buf_len, _len, type) do\
{\
log_debug("TRX_ECPRI", "Allocating %s with %d bytes\n", _name, (_buf_len * _len * sizeof(type)));\
rbuf.buffer = (type *) malloc(_buf_len * _len * sizeof(type));\
strcpy(rbuf.name, _name);\
rbuf.buf_len = _buf_len;\
rbuf.len = _len;\
rbuf.write_index = 0;\
rbuf.read_index = 0;\
} while(0)
#endif
trx_ecpri.c
0 → 100644
View file @
370ef0bc
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment