Commit dd600f3f authored by Jonathan Jenkins's avatar Jonathan Jenkins

Overhaul of resource LP to support 'blocking'

parent 490048d7
......@@ -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,
......
......@@ -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;
};
......
This diff is collapsed.
......@@ -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
......
......@@ -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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment