Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ycai
simbricks
Commits
2b10d7cb
Commit
2b10d7cb
authored
Mar 25, 2021
by
Antoine Kaufmann
Browse files
dist/net_rdma: add spinlock for buffer allocator
parent
eaa624d8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
0 deletions
+11
-0
dist/rdma.c
dist/rdma.c
+11
-0
No files found.
dist/rdma.c
View file @
2b10d7cb
...
@@ -25,6 +25,7 @@
...
@@ -25,6 +25,7 @@
#include "dist/net_rdma.h"
#include "dist/net_rdma.h"
#include <fcntl.h>
#include <fcntl.h>
#include <pthread.h>
#include <rdma/rdma_cma.h>
#include <rdma/rdma_cma.h>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
...
@@ -70,19 +71,24 @@ static struct ibv_mr *mr_msgs;
...
@@ -70,19 +71,24 @@ static struct ibv_mr *mr_msgs;
static
struct
ibv_qp_init_attr
qp_attr
=
{
};
static
struct
ibv_qp_init_attr
qp_attr
=
{
};
static
struct
NetRdmaMsg
msgs
[
MSG_RXBUFS
+
MSG_TXBUFS
];
static
struct
NetRdmaMsg
msgs
[
MSG_RXBUFS
+
MSG_TXBUFS
];
pthread_spinlock_t
freelist_spin
;
static
struct
NetRdmaMsg
*
msgs_free
=
NULL
;
static
struct
NetRdmaMsg
*
msgs_free
=
NULL
;
static
struct
NetRdmaMsg
*
RdmaMsgAlloc
()
{
static
struct
NetRdmaMsg
*
RdmaMsgAlloc
()
{
pthread_spin_lock
(
&
freelist_spin
);
struct
NetRdmaMsg
*
msg
=
msgs_free
;
struct
NetRdmaMsg
*
msg
=
msgs_free
;
if
(
msg
!=
NULL
)
{
if
(
msg
!=
NULL
)
{
msgs_free
=
msg
->
next_free
;
msgs_free
=
msg
->
next_free
;
}
}
pthread_spin_unlock
(
&
freelist_spin
);
return
msg
;
return
msg
;
}
}
static
void
RdmaMsgFree
(
struct
NetRdmaMsg
*
msg
)
{
static
void
RdmaMsgFree
(
struct
NetRdmaMsg
*
msg
)
{
pthread_spin_lock
(
&
freelist_spin
);
msg
->
next_free
=
msgs_free
;
msg
->
next_free
=
msgs_free
;
msgs_free
=
msg
;
msgs_free
=
msg
;
pthread_spin_unlock
(
&
freelist_spin
);
}
}
static
int
RdmMsgRxEnqueue
(
struct
NetRdmaMsg
*
msg
)
{
static
int
RdmMsgRxEnqueue
(
struct
NetRdmaMsg
*
msg
)
{
...
@@ -170,6 +176,11 @@ static int RdmaMsgRx(struct NetRdmaMsg *msg) {
...
@@ -170,6 +176,11 @@ static int RdmaMsgRx(struct NetRdmaMsg *msg) {
}
}
static
int
RdmaCommonInit
()
{
static
int
RdmaCommonInit
()
{
if
(
pthread_spin_init
(
&
freelist_spin
,
PTHREAD_PROCESS_PRIVATE
))
{
perror
(
"RdmaCommonInit: pthread_spin_init failed"
);
return
1
;
}
if
(
!
(
pd
=
ibv_alloc_pd
(
cm_id
->
verbs
)))
{
if
(
!
(
pd
=
ibv_alloc_pd
(
cm_id
->
verbs
)))
{
perror
(
"RdmaCommonInit: ibv_alloc_pd failed"
);
perror
(
"RdmaCommonInit: ibv_alloc_pd failed"
);
return
1
;
return
1
;
...
...
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