Commit 7a94693d authored by Jonathan Jenkins's avatar Jonathan Jenkins

Initial cut of buffer mgmt LP

parent 5dfddcf8
/*
* Copyright (C) 2014 University of Chicago.
* See COPYRIGHT notice in top-level directory.
*
*/
/* this header defines the user-facing functionality needed to interact with a
* resource LP. All of the LP-specific implementation details are in the
* corresponding C file */
#ifndef RESOURCE_LP_H
#define RESOURCE_LP_H
#include "ross.h"
#include "codes/lp-msg.h"
#include "codes/resource.h"
#include <stdint.h>
typedef struct {
int ret;
/* in the case of a reserve, need to return the token */
resource_token_t tok;
} resource_callback;
void resource_lp_init();
/* Wrappers for the underlying resource structure.
* Implicitly maps the given LPID to it's group and repetition, then messages
* the resource LP with the request.
* Msg_size is where to
* The "set" function is the initializer, to be called by exactly one LP in the
* group that contains the resource to initialize */
void resource_lp_set(tw_lpid src, uint64_t avail);
/* The following functions expect the sending LP to put its gid in the
* header->src field, along with its magic and callback event type */
void resource_lp_get(
msg_header *header,
uint64_t req,
int msg_size,
int msg_header_offset,
int msg_callback_offset,
tw_lp *sender);
/* no callback for frees thus far */
void resource_lp_free(msg_header *header, uint64_t req, tw_lp *sender);
void resource_lp_reserve(
msg_header *header,
uint64_t req,
int msg_size,
int msg_header_offset,
int msg_callback_offset,
tw_lp *sender);
void resource_lp_get_reserved(
msg_header *header,
uint64_t req,
resource_token_t tok,
int msg_size,
int msg_header_offset,
int msg_callback_offset,
tw_lp *sender);
void resource_lp_free_reserved(
msg_header *header,
uint64_t req,
resource_token_t tok,
tw_lp *sender);
/* rc functions - thankfully, they only use codes-local-latency, so no need
* to pass in any arguments */
void resource_lp_get_rc(tw_lp *sender);
void resource_lp_free_rc(tw_lp *sender);
void resource_lp_reserve_rc(tw_lp *sender);
void resource_lp_get_reserved_rc(tw_lp *sender);
void resource_lp_free_reserved_rc(tw_lp *sender);
#endif /* end of include guard: RESOURCE_LP_H */
/*
* Local variables:
* c-indent-level: 4
* c-basic-offset: 4
* End:
*
* vim: ts=8 sts=4 sw=4 expandtab
*/
/*
* Copyright (C) 2014 University of Chicago.
* See COPYRIGHT notice in top-level directory.
*
*/
/* Implementation of a simple "resource" data structure for lps to get and
* retrieve. Additionally allows 'reservations' of a resource for
* later use, allowing claiming of the resource without requiring the LP to
* reimplement resource functionality. General requests go through the
* "general" pool (unreserved part of the resource and
* reservation-specific requests go through their specific pools. */
#ifndef RESOURCE_H
#define RESOURCE_H
#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);
/* Release req units of the resource from the general pool. */
void resource_free(uint64_t req, resource *r);
/* Reservation functions, same return value as get.
* These functions expect exactly one caller per LP group as
* defined by the codes configuration
* 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];
unsigned int num_tokens;
};
#endif /* end of include guard: RESOURCE_H */
/*
* Local variables:
* c-indent-level: 4
* c-basic-offset: 4
* End:
*
* vim: ts=8 sts=4 sw=4 expandtab
*/
......@@ -54,7 +54,9 @@ nobase_include_HEADERS = \
codes/lp-io.h \
codes/lp-msg.h \
codes/jenkins-hash.h \
codes/codes-workload.h
codes/codes-workload.h \
codes/resource.h \
codes/resource-lp.h
src_libcodes_base_a_SOURCES = \
codes/codesparser.h \
......@@ -91,6 +93,8 @@ src_libcodes_base_a_SOURCES = \
src/util/lp-io.c \
src/util/lp-msg.c \
src/util/lookup3.c \
src/util/resource.c \
src/util/resource-lp.c \
codes/codeslogging.h \
src/logging/codeslogging.c \
codes/timeline.h \
......
This diff is collapsed.
/*
* Copyright (C) 2014 University of Chicago.
* See COPYRIGHT notice in top-level directory.
*
*/
#include "codes/resource.h"
#include <assert.h>
/* initialize with avail capacity, all unreserved */
void resource_init(uint64_t avail, resource *r){
r->avail = 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){
return 1;
}
else{
r->avail -= req;
return 0;
}
}
/* Release req units of the resource from the general pool. */
void resource_free(uint64_t req, resource *r){
r->avail += req;
}
/* Reservation functions, same return value as get.
* These functions expect exactly one caller per LP group as
* 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]){
return 1;
}
else{
r->reserved_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
* c-basic-offset: 4
* End:
*
* vim: ts=8 sts=4 sw=4 expandtab
*/
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