Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
codes
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
38
Issues
38
List
Boards
Labels
Milestones
Merge Requests
8
Merge Requests
8
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
codes
codes
Commits
dd600f3f
Commit
dd600f3f
authored
Apr 29, 2014
by
Jonathan Jenkins
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Overhaul of resource LP to support 'blocking'
parent
490048d7
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
313 additions
and
174 deletions
+313
-174
codes/resource-lp.h
codes/resource-lp.h
+3
-0
codes/resource.h
codes/resource.h
+10
-13
src/util/resource-lp.c
src/util/resource-lp.c
+274
-128
src/util/resource.c
src/util/resource.c
+24
-31
tests/resource-test.c
tests/resource-test.c
+2
-2
No files found.
codes/resource-lp.h
View file @
dd600f3f
...
...
@@ -35,6 +35,7 @@ void resource_lp_configure();
void
resource_lp_get
(
msg_header
*
header
,
uint64_t
req
,
int
block_on_unavail
,
int
msg_size
,
int
msg_header_offset
,
int
msg_callback_offset
,
...
...
@@ -44,6 +45,7 @@ void resource_lp_free(uint64_t req, tw_lp *sender);
void
resource_lp_reserve
(
msg_header
*
header
,
uint64_t
req
,
int
block_on_unavail
,
int
msg_size
,
int
msg_header_offset
,
int
msg_callback_offset
,
...
...
@@ -52,6 +54,7 @@ void resource_lp_get_reserved(
msg_header
*
header
,
uint64_t
req
,
resource_token_t
tok
,
int
block_on_unavail
,
int
msg_size
,
int
msg_header_offset
,
int
msg_callback_offset
,
...
...
codes/resource.h
View file @
dd600f3f
...
...
@@ -16,18 +16,21 @@
#include <stdint.h>
typedef
struct
resource_s
resource
;
typedef
unsigned
int
resource_token_t
;
/* initialize with avail capacity, all unreserved */
void
resource_init
(
uint64_t
avail
,
resource
*
r
);
/* Acquire req units of the resource from the general pool.
* Returns 0 on success, 1 on failure (not enough available). */
int
resource_get
(
uint64_t
req
,
resource
*
r
);
/* Acquire req units of the resource.
* Returns 0 on success, 1 on failure (not enough available), 2 on invalid
* token. */
int
resource_get
(
uint64_t
req
,
resource_token_t
tok
,
resource
*
r
);
/* Release req units of the resource from the general pool. */
void
resource_free
(
uint64_t
req
,
resource
*
r
);
/* Release req units of the resource.
* Returns 0 on success, 2 on invalid token */
int
resource_free
(
uint64_t
req
,
resource_token_t
tok
,
resource
*
r
);
/* Reservation functions, same return value as get.
* These functions expect exactly one caller per LP group as
...
...
@@ -35,16 +38,10 @@ void resource_free(uint64_t req, resource *r);
* TODO: "un-reserving" not yet supported */
int
resource_reserve
(
uint64_t
req
,
resource_token_t
*
tok
,
resource
*
r
);
/* Acquire req units of the resource from a reserved pool */
int
reserved_get
(
uint64_t
req
,
resource_token_t
tok
,
resource
*
r
);
/* Release req units of the resource from the general pool. */
void
reserved_free
(
uint64_t
req
,
resource_token_t
tok
,
resource
*
r
);
#define MAX_RESERVE 8
struct
resource_s
{
uint64_t
avail
;
uint64_t
reserved_avail
[
MAX_RESERVE
];
/* index 0 is the general pool, 1... are the reserved pools */
uint64_t
avail
[
MAX_RESERVE
+
1
];
unsigned
int
num_tokens
;
};
...
...
src/util/resource-lp.c
View file @
dd600f3f
This diff is collapsed.
Click to expand it.
src/util/resource.c
View file @
dd600f3f
...
...
@@ -9,25 +9,36 @@
/* initialize with avail capacity, all unreserved */
void
resource_init
(
uint64_t
avail
,
resource
*
r
){
r
->
avail
=
avail
;
r
->
avail
[
0
]
=
avail
;
r
->
num_tokens
=
0
;
}
/* Acquire req units of the resource from the general pool.
* Returns 0 on success, 1 on failure (not enough available). */
int
resource_get
(
uint64_t
req
,
resource
*
r
){
if
(
req
>
r
->
avail
){
/* Acquire req units of the resource.
* Returns 0 on success, 1 on failure (not enough available), 2 on invalid
* token. */
int
resource_get
(
uint64_t
req
,
resource_token_t
tok
,
resource
*
r
){
if
(
tok
>
r
->
num_tokens
){
return
2
;
}
else
if
(
req
>
r
->
avail
[
tok
]){
return
1
;
}
else
{
r
->
avail
-=
req
;
r
->
avail
[
tok
]
-=
req
;
return
0
;
}
}
/* Release req units of the resource from the general pool. */
void
resource_free
(
uint64_t
req
,
resource
*
r
){
r
->
avail
+=
req
;
/* Release req units of the resource.
* Returns 0 on success, 2 on invalid token */
int
resource_free
(
uint64_t
req
,
resource_token_t
tok
,
resource
*
r
){
if
(
tok
>
r
->
num_tokens
){
return
2
;
}
else
{
r
->
avail
[
tok
]
+=
req
;
return
0
;
}
}
/* Reservation functions, same return value as get.
...
...
@@ -35,35 +46,17 @@ void resource_free(uint64_t req, resource *r){
* defined by the codes configuration
* TODO: "un-reserving" not yet supported */
int
resource_reserve
(
uint64_t
req
,
resource_token_t
*
tok
,
resource
*
r
){
if
(
req
>
r
->
avail
){
return
1
;
}
else
{
*
tok
=
r
->
num_tokens
++
;
r
->
reserved_avail
[
*
tok
]
=
req
;
r
->
avail
-=
req
;
return
0
;
}
}
/* Acquire req units of the resource from a reserved pool */
int
reserved_get
(
uint64_t
req
,
resource_token_t
tok
,
resource
*
r
){
assert
(
tok
<
r
->
num_tokens
);
if
(
req
>
r
->
reserved_avail
[
tok
]){
if
(
req
>
r
->
avail
[
0
]){
return
1
;
}
else
{
r
->
reserved_avail
[
tok
]
-=
req
;
/* reserved tokens start from 1 */
*
tok
=
++
(
r
->
num_tokens
);
r
->
avail
[
*
tok
]
=
req
;
return
0
;
}
}
/* Release req units of the resource from the general pool. */
void
reserved_free
(
uint64_t
req
,
resource_token_t
tok
,
resource
*
r
){
assert
(
tok
<
r
->
num_tokens
);
r
->
reserved_avail
[
tok
]
+=
req
;
}
/*
* Local variables:
* c-indent-level: 4
...
...
tests/resource-test.c
View file @
dd600f3f
...
...
@@ -51,7 +51,7 @@ static void s_event(s_state *ns, tw_bf *bf, s_msg *m, tw_lp *lp){
case
S_KICKOFF
:
;
msg_header
h
;
msg_set_header
(
s_magic
,
S_ALLOC_ACK
,
lp
->
gid
,
&
h
);
resource_lp_get
(
&
h
,
bsize
,
sizeof
(
s_msg
),
resource_lp_get
(
&
h
,
bsize
,
0
,
sizeof
(
s_msg
),
offsetof
(
s_msg
,
h
),
offsetof
(
s_msg
,
c
),
lp
);
break
;
case
S_ALLOC_ACK
:
...
...
@@ -61,7 +61,7 @@ static void s_event(s_state *ns, tw_bf *bf, s_msg *m, tw_lp *lp){
ns
->
mem_max
=
max
(
ns
->
mem
,
ns
->
mem_max
);
msg_header
h
;
msg_set_header
(
s_magic
,
S_ALLOC_ACK
,
lp
->
gid
,
&
h
);
resource_lp_get
(
&
h
,
bsize
,
sizeof
(
s_msg
),
resource_lp_get
(
&
h
,
bsize
,
0
,
sizeof
(
s_msg
),
offsetof
(
s_msg
,
h
),
offsetof
(
s_msg
,
c
),
lp
);
break
;
}
...
...
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