Commit ac0d0f3c authored by Jonathan Jenkins's avatar Jonathan Jenkins
Browse files

convert resource lp implementation to use codes-callback/map-ctx

parent a5c4512a
...@@ -52,6 +52,23 @@ struct codes_cb_params { ...@@ -52,6 +52,23 @@ struct codes_cb_params {
(_cb_info_ptr)->cb_ret_offset = offsetof(_event_type, _cb_ret_field); \ (_cb_info_ptr)->cb_ret_offset = offsetof(_event_type, _cb_ret_field); \
} while (0) } while (0)
#define CB_HO(_cb_params_ptr) ((_cb_params_ptr)->info.header_offset)
#define CB_TO(_cb_params_ptr) ((_cb_params_ptr)->info.tag_offset)
#define CB_RO(_cb_params_ptr) ((_cb_params_ptr)->info.cb_ret_offset)
/* Declare return variables at the right byte offsets from a codes_cb_params.
* Additionally, set the header and tag vars */
#define GET_INIT_CB_PTRS(_cb_params_ptr, _data_ptr, _sender_gid_val, _header_nm, _tag_nm, _rtn_name, _rtn_type) \
msg_header * _header_nm = \
(msg_header*)((char*)(_data_ptr) + CB_HO(_cb_params_ptr)); \
int * _tag_nm = \
(int*)((char*)(_data_ptr) + CB_TO(_cb_params_ptr));\
_rtn_type * _rtn_name = \
(_rtn_type*)((char*)(_data_ptr) + CB_RO(_cb_params_ptr)); \
msg_set_header((_cb_params_ptr)->h.magic, (_cb_params_ptr)->h.event_type, \
_sender_gid_val, _header_nm); \
*_tag_nm = (_cb_params_ptr)->tag
#define SANITY_CHECK_CB(_cb_info_ptr, _ret_type) \ #define SANITY_CHECK_CB(_cb_info_ptr, _ret_type) \
do { \ do { \
int _total_size = sizeof(_ret_type) + sizeof(int) + sizeof(msg_header);\ int _total_size = sizeof(_ret_type) + sizeof(int) + sizeof(msg_header);\
......
...@@ -11,11 +11,14 @@ ...@@ -11,11 +11,14 @@
#ifndef RESOURCE_LP_H #ifndef RESOURCE_LP_H
#define RESOURCE_LP_H #define RESOURCE_LP_H
#include "ross.h" #include <ross.h>
#include "codes/lp-msg.h"
#include "codes/resource.h"
#include <stdint.h> #include <stdint.h>
#include "lp-msg.h"
#include "resource.h"
#include "codes-callback.h"
#include "codes-mapping-context.h"
#define RESOURCE_MAX_CALLBACK_PAYLOAD 64 #define RESOURCE_MAX_CALLBACK_PAYLOAD 64
#define RESOURCE_LP_NM "resource" #define RESOURCE_LP_NM "resource"
...@@ -24,7 +27,7 @@ typedef struct { ...@@ -24,7 +27,7 @@ typedef struct {
int ret; int ret;
/* in the case of a reserve, need to return the token */ /* in the case of a reserve, need to return the token */
resource_token_t tok; resource_token_t tok;
} resource_callback; } resource_return;
/* registers the resource LP with CODES/ROSS */ /* registers the resource LP with CODES/ROSS */
...@@ -42,57 +45,43 @@ void resource_lp_configure(); ...@@ -42,57 +45,43 @@ void resource_lp_configure();
* *
* block_on_unavail - flag whether to wait to message the requester if * block_on_unavail - flag whether to wait to message the requester if
* request cannot be satisfied * request cannot be satisfied
* msg_size - size of the requester event structure * tag, h - set in the return client event, using the offsets in cb
* msg_header_offset - offset in the requester event to place the resource's
* msg_header
* msg_callback_offset - offset in the requester event struct to place the
* resource-provided resource_callback data
* msg_callback_misc_size - size of requester-provided callback data
* msg_callback_misc_offset - offset in the requester event struct to place the
* requester-provided callback data
* msg_callback_misc_data - requester-provided callback data
*
*/ */
void resource_lp_get( void resource_lp_get(
msg_header *header, uint64_t req,
uint64_t req,
int block_on_unavail, int block_on_unavail,
int msg_size, tw_lp *sender,
int msg_header_offset, struct codes_mctx const * map_ctx,
int msg_callback_offset, int tag,
int msg_callback_misc_size, msg_header const *h,
int msg_callback_misc_offset, struct codes_cb_info const *cb);
void *msg_callback_misc_data,
tw_lp *sender);
/* no callback for frees thus far */ /* no callback for frees thus far */
void resource_lp_free(uint64_t req, tw_lp *sender); void resource_lp_free(
uint64_t req,
tw_lp *sender,
struct codes_mctx const * map_ctx);
void resource_lp_reserve( void resource_lp_reserve(
msg_header *header,
uint64_t req, uint64_t req,
int block_on_unavail, int block_on_unavail,
int msg_size, tw_lp *sender,
int msg_header_offset, struct codes_mctx const * map_ctx,
int msg_callback_offset, int tag,
int msg_callback_misc_size, msg_header const *h,
int msg_callback_misc_offset, struct codes_cb_info const *cb);
void *msg_callback_misc_data,
tw_lp *sender);
void resource_lp_get_reserved( void resource_lp_get_reserved(
msg_header *header,
uint64_t req, uint64_t req,
resource_token_t tok, resource_token_t tok,
int block_on_unavail, int block_on_unavail,
int msg_size, tw_lp *sender,
int msg_header_offset, struct codes_mctx const * map_ctx,
int msg_callback_offset, int tag,
int msg_callback_misc_size, msg_header const *h,
int msg_callback_misc_offset, struct codes_cb_info const *cb);
void *msg_callback_misc_data,
tw_lp *sender);
void resource_lp_free_reserved( void resource_lp_free_reserved(
uint64_t req, uint64_t req,
resource_token_t tok, resource_token_t tok,
tw_lp *sender); tw_lp *sender,
struct codes_mctx const * map_ctx);
/* rc functions - thankfully, they only use codes-local-latency, so no need /* rc functions - thankfully, they only use codes-local-latency, so no need
* to pass in any arguments */ * to pass in any arguments */
......
...@@ -4,14 +4,15 @@ ...@@ -4,14 +4,15 @@
* *
*/ */
#include "codes/resource-lp.h" #include <codes/codes-callback.h>
#include "codes/resource.h" #include <codes/resource-lp.h>
#include "codes/codes_mapping.h" #include <codes/resource.h>
#include "codes/configuration.h" #include <codes/codes_mapping.h>
#include "codes/jenkins-hash.h" #include <codes/configuration.h>
#include "codes/quicklist.h" #include <codes/jenkins-hash.h>
#include "codes/lp-io.h" #include <codes/quicklist.h>
#include "ross.h" #include <codes/lp-io.h>
#include <ross.h>
#include <assert.h> #include <assert.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
...@@ -62,17 +63,10 @@ struct resource_msg_internal{ ...@@ -62,17 +63,10 @@ struct resource_msg_internal{
* 0 - send the callback immediately if resource unavailable. * 0 - send the callback immediately if resource unavailable.
* 1 - send the callback when memory is available (danger - deadlock * 1 - send the callback when memory is available (danger - deadlock
* possible) */ * possible) */
int block_on_unavail; int block_on_unavail;
/* callback data */ /* callback data */
msg_header h_callback; struct codes_cb_params cb;
int msg_size; };
int msg_header_offset;
int msg_callback_offset;
/* user-provided data */
int msg_callback_misc_size;
int msg_callback_misc_offset;
char msg_callback_misc[RESOURCE_MAX_CALLBACK_PAYLOAD];
};
struct resource_msg { struct resource_msg {
struct resource_msg_internal i, i_rc; struct resource_msg_internal i, i_rc;
...@@ -148,46 +142,24 @@ void resource_lp_ind_init( ...@@ -148,46 +142,24 @@ void resource_lp_ind_init(
} }
static void resource_response( static void resource_response(
struct resource_msg_internal *m, struct codes_cb_params const * p,
tw_lp *lp, tw_lp *lp,
int ret, int ret,
resource_token_t tok){ resource_token_t tok)
/* send return message */ {
msg_header h; SANITY_CHECK_CB(&p->info, resource_return);
msg_set_header(m->h_callback.magic, m->h_callback.event_type,
lp->gid, &h); tw_event *e = tw_event_new(p->h.src, codes_local_latency(lp), lp);
void * m = tw_event_data(e);
resource_callback c;
c.ret = ret; GET_INIT_CB_PTRS(p, m, lp->gid, h, tag, rc, resource_return);
c.tok = tok;
rc->ret = ret;
/* before we send the message, sanity check the sizes */ rc->tok = tok;
if (m->msg_size >= m->msg_header_offset+sizeof(h) &&
m->msg_size >= m->msg_callback_offset+sizeof(c) && tw_event_send(e);
m->msg_size >= m->msg_callback_offset+m->msg_callback_misc_size){
tw_event *e = codes_event_new(m->h_callback.src,
codes_local_latency(lp), lp);
void *msg = tw_event_data(e);
memcpy(((char*)msg)+m->msg_header_offset, &h, sizeof(h));
memcpy(((char*)msg)+m->msg_callback_offset, &c, sizeof(c));
if (m->msg_callback_misc_size > 0){
memcpy(((char*)msg)+m->msg_callback_misc_offset,
m->msg_callback_misc, m->msg_callback_misc_size);
}
tw_event_send(e);
}
else{
tw_error(TW_LOC,
"message size not large enough to hold header/callback/misc"
" structures\n"
"msg size: %3d, header off/size: %d, %d\n"
" callback off/size: %d, %d\n"
" callback misc size: %d",
m->msg_size, m->msg_header_offset, (int)sizeof(h),
m->msg_callback_offset, (int)sizeof(c),
m->msg_callback_misc_size);
}
} }
static void resource_response_rc(tw_lp *lp){ static void resource_response_rc(tw_lp *lp){
codes_local_latency_reverse(lp); codes_local_latency_reverse(lp);
} }
...@@ -220,7 +192,7 @@ static void handle_resource_get( ...@@ -220,7 +192,7 @@ static void handle_resource_get(
} }
if (send_ack){ if (send_ack){
b->c1 = 1; b->c1 = 1;
resource_response(&m->i, lp, ret, TOKEN_DUMMY); resource_response(&m->i.cb, lp, ret, TOKEN_DUMMY);
} }
b->c2 = !ret; b->c2 = !ret;
...@@ -296,7 +268,7 @@ static void handle_resource_deq( ...@@ -296,7 +268,7 @@ static void handle_resource_deq(
/* success, dequeue (saving as rc) and send to client */ /* success, dequeue (saving as rc) and send to client */
qlist_del(front); qlist_del(front);
m->i_rc = p->m; m->i_rc = p->m;
resource_response(&p->m, lp, ret, TOKEN_DUMMY); resource_response(&p->m.cb, lp, ret, TOKEN_DUMMY);
free(p); free(p);
/* additionally attempt to dequeue next one down */ /* additionally attempt to dequeue next one down */
tw_event *e = codes_event_new(lp->gid, codes_local_latency(lp), lp); tw_event *e = codes_event_new(lp->gid, codes_local_latency(lp), lp);
...@@ -341,7 +313,7 @@ static void handle_resource_reserve( ...@@ -341,7 +313,7 @@ static void handle_resource_reserve(
resource_token_t tok; resource_token_t tok;
int ret = resource_reserve(m->i.req, &tok, &ns->r); int ret = resource_reserve(m->i.req, &tok, &ns->r);
assert(!ret); assert(!ret);
resource_response(&m->i, lp, ret, tok); resource_response(&m->i.cb, lp, ret, tok);
} }
static void handle_resource_reserve_rc( static void handle_resource_reserve_rc(
resource_state * ns, resource_state * ns,
...@@ -481,194 +453,118 @@ void resource_lp_configure(){ ...@@ -481,194 +453,118 @@ void resource_lp_configure(){
} }
static void resource_lp_issue_event_base( static void resource_lp_issue_event_base(
msg_header *header, enum resource_event type,
uint64_t req, uint64_t req,
resource_token_t tok, /* only used in reserve_get/free */ resource_token_t tok, /* only used in reserve_get/free */
int block_on_unavail, int block_on_unavail,
int msg_size,
int msg_header_offset,
int msg_callback_offset,
int msg_callback_misc_size,
int msg_callback_misc_offset,
void *msg_callback_misc_data,
enum resource_event type,
tw_lp *sender, tw_lp *sender,
const char * annotation, struct codes_mctx const * map_ctx,
int ignore_annotations){ int tag,
msg_header const *h,
tw_lpid resource_lpid; struct codes_cb_info const *cb)
{
/* map out the lpid of the resource */ if (cb)
int mapping_rep_id, mapping_offset, dummy; SANITY_CHECK_CB(cb, resource_return);
char lp_group_name[MAX_NAME_LENGTH];
int resource_count; tw_lpid resource_lpid =
// TODO: currently ignoring annotations... perhaps give annotation as a codes_mctx_to_lpid(map_ctx, RESOURCE_LP_NM, sender);
// parameter?
codes_mapping_get_lp_info(sender->gid, lp_group_name, &dummy, tw_event *e = tw_event_new(resource_lpid, codes_local_latency(sender),
NULL, &dummy, NULL,
&mapping_rep_id, &mapping_offset);
resource_count = codes_mapping_get_lp_count(lp_group_name, 1,
RESOURCE_LP_NM, annotation, ignore_annotations);
codes_mapping_get_lp_id(lp_group_name, RESOURCE_LP_NM, annotation,
ignore_annotations, mapping_rep_id, mapping_offset % resource_count,
&resource_lpid);
tw_event *e = codes_event_new(resource_lpid, codes_local_latency(sender),
sender); sender);
/* set message info */ resource_msg *m = tw_event_data(e);
resource_msg *m = (resource_msg*)tw_event_data(e);
msg_set_header(resource_magic, type, sender->gid, &m->i.h); msg_set_header(resource_magic, type, sender->gid, &m->i.h);
m->i.req = req; m->i.req = req;
m->i.tok = tok; m->i.tok = tok;
m->i.block_on_unavail = block_on_unavail; m->i.block_on_unavail = block_on_unavail;
if (map_ctx != NULL && cb != NULL && h != NULL) {
/* set callback info */ m->i.cb.info = *cb;
if (header != NULL){ m->i.cb.h = *h;
m->i.h_callback = *header; m->i.cb.tag = tag;
}
m->i.msg_size = msg_size;
m->i.msg_header_offset = msg_header_offset;
m->i.msg_callback_offset = msg_callback_offset;
if (msg_callback_misc_size > 0){
assert(msg_callback_misc_size <= RESOURCE_MAX_CALLBACK_PAYLOAD);
m->i.msg_callback_misc_size = msg_callback_misc_size;
m->i.msg_callback_misc_offset = msg_callback_misc_offset;
memcpy(m->i.msg_callback_misc, msg_callback_misc_data,
msg_callback_misc_size);
}
else{
m->i.msg_callback_misc_size = 0;
m->i.msg_callback_misc_offset = 0;
} }
tw_event_send(e); tw_event_send(e);
} }
static void resource_lp_issue_event_annotated( void resource_lp_get(
msg_header *header,
uint64_t req, uint64_t req,
resource_token_t tok, /* only used in reserve_get/free */
int block_on_unavail, int block_on_unavail,
int msg_size,
int msg_header_offset,
int msg_callback_offset,
int msg_callback_misc_size,
int msg_callback_misc_offset,
void *msg_callback_misc_data,
enum resource_event type,
tw_lp *sender, tw_lp *sender,
const char * annotation, struct codes_mctx const * map_ctx,
int ignore_annotations){ int tag,
resource_lp_issue_event_base(header, req, tok, block_on_unavail, msg_size, msg_header const *h,
msg_header_offset, msg_callback_offset, msg_callback_misc_size, struct codes_cb_info const *cb)
msg_callback_misc_offset, msg_callback_misc_data, type, sender, {
annotation, ignore_annotations); resource_lp_issue_event_base(RESOURCE_GET, req, 0, block_on_unavail,
} sender, map_ctx, tag, h, cb);
static void resource_lp_issue_event(
msg_header *header,
uint64_t req,
resource_token_t tok, /* only used in reserve_get/free */
int block_on_unavail,
int msg_size,
int msg_header_offset,
int msg_callback_offset,
int msg_callback_misc_size,
int msg_callback_misc_offset,
void *msg_callback_misc_data,
enum resource_event type,
tw_lp *sender) {
resource_lp_issue_event_base(header, req, tok, block_on_unavail, msg_size,
msg_header_offset, msg_callback_offset, msg_callback_misc_size,
msg_callback_misc_offset, msg_callback_misc_data, type, sender,
NULL, 1);
}
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,
int msg_callback_misc_size,
int msg_callback_misc_offset,
void *msg_callback_misc_data,
tw_lp *sender){
resource_lp_issue_event(header, req, 0, block_on_unavail,
msg_size, msg_header_offset, msg_callback_offset,
msg_callback_misc_size, msg_callback_misc_offset,
msg_callback_misc_data, RESOURCE_GET, sender);
} }
/* no callback for frees thus far */ /* no callback for frees thus far */
void resource_lp_free(uint64_t req, tw_lp *sender){ void resource_lp_free(
resource_lp_issue_event(NULL, req, 0, -1, -1,-1,-1, 0, 0, NULL, uint64_t req,
RESOURCE_FREE, sender); tw_lp *sender,
struct codes_mctx const * map_ctx)
{
resource_lp_issue_event_base(RESOURCE_FREE, req, 0, -1, sender, map_ctx,
0, NULL, NULL);
} }
void resource_lp_reserve( void resource_lp_reserve(
msg_header *header,
uint64_t req, uint64_t req,
int block_on_unavail, int block_on_unavail,
int msg_size, tw_lp *sender,
int msg_header_offset, struct codes_mctx const * map_ctx,
int msg_callback_offset, int tag,
int msg_callback_misc_size, msg_header const *h,
int msg_callback_misc_offset, struct codes_cb_info const *cb)
void *msg_callback_misc_data, {
tw_lp *sender){ resource_lp_issue_event_base(RESOURCE_RESERVE, req, 0, block_on_unavail,
resource_lp_issue_event(header, req, 0, block_on_unavail, msg_size, sender, map_ctx, tag, h, cb);
msg_header_offset, msg_callback_offset, msg_callback_misc_size,
msg_callback_misc_offset, msg_callback_misc_data, RESOURCE_RESERVE,
sender);
} }
void resource_lp_get_reserved( void resource_lp_get_reserved(
msg_header *header,
uint64_t req, uint64_t req,
resource_token_t tok, resource_token_t tok,
int block_on_unavail, int block_on_unavail,
int msg_size, tw_lp *sender,
int msg_header_offset, struct codes_mctx const * map_ctx,
int msg_callback_offset, int tag,
int msg_callback_misc_size, msg_header const *h,
int msg_callback_misc_offset, struct codes_cb_info const *cb)
void *msg_callback_misc_data, {
tw_lp *sender){ resource_lp_issue_event_base(RESOURCE_GET, req, tok, block_on_unavail,
resource_lp_issue_event(header, req, tok, block_on_unavail, msg_size, sender, map_ctx, tag, h, cb);
msg_header_offset, msg_callback_offset, msg_callback_misc_size,
msg_callback_misc_offset, msg_callback_misc_data, RESOURCE_GET,
sender);
} }
void resource_lp_free_reserved( void resource_lp_free_reserved(
uint64_t req, uint64_t req,
resource_token_t tok, resource_token_t tok,
tw_lp *sender){ tw_lp *sender,
resource_lp_issue_event(NULL, req, tok, -1,-1,-1,-1, 0,0,NULL, struct codes_mctx const * map_ctx)
RESOURCE_FREE, sender); {
resource_lp_issue_event_base(RESOURCE_FREE, req, tok, -1,
sender, map_ctx, 0, NULL, NULL);
} }
/* rc functions - thankfully, they only use codes-local-latency, so no need /* rc functions - thankfully, they only use codes-local-latency, so no need
* to pass in any arguments */ * to pass in any arguments */
static void resource_lp_issue_event_rc(tw_lp *sender){ static void resource_lp_issue_event_base_rc(tw_lp *sender){
codes_local_latency_reverse(sender); codes_local_latency_reverse(sender);
} }
void resource_lp_get_rc(tw_lp *sender){ void resource_lp_get_rc(tw_lp *sender){
resource_lp_issue_event_rc(sender); resource_lp_issue_event_base_rc(sender);
} }
void resource_lp_free_rc(tw_lp *sender){ void resource_lp_free_rc(tw_lp *sender){
resource_lp_issue_event_rc(sender); resource_lp_issue_event_base_rc(sender);
} }
void resource_lp_reserve_rc(tw_lp *sender){ void resource_lp_reserve_rc(tw_lp *sender){
resource_lp_issue_event_rc(sender); resource_lp_issue_event_base_rc(sender);
} }
void resource_lp_get_reserved_rc(tw_lp *sender){ void resource_lp_get_reserved_rc(tw_lp *sender){
resource_lp_issue_event_rc(sender); resource_lp_issue_event_base_rc(sender);
} }
void resource_lp_free_reserved_rc(tw_lp *sender){ void resource_lp_free_reserved_rc(tw_lp *sender){
resource_lp_issue_event_rc(sender); resource_lp_issue_event_base_rc(sender);
} }
/* /*
......
...@@ -4,11 +4,13 @@ ...@@ -4,11 +4,13 @@
* *
*/ */
#include "codes/resource.h" #include <codes/resource.h>
#include "codes/resource-lp.h" #include <codes/resource-lp.h>
#include "codes/lp-msg.h" #include <codes/lp-msg.h>
#include "codes/configuration.h" #include <codes/configuration.h>
#include "codes/codes_mapping.h" #include <codes/codes_mapping.h>
#include <codes/codes-callback.h>
#include <codes/codes-mapping-context.h>
#include <stdint.h>