Commit d005458e authored by Shane Snyder's avatar Shane Snyder

retool existing code into a server library

parent ec0a8846
......@@ -13,7 +13,7 @@ CLEANFILES = $(bin_SCRIPTS)
MAINTAINERCLEANFILES =
EXTRA_DIST =
BUILT_SOURCES =
include_HEADERS = include/bake-bulk.h include/bake-bulk-client.h
include_HEADERS = include/bake-bulk.h include/bake-bulk-client.h include/bake-bulk-server.h
EXTRA_DIST += \
prepare.sh
......@@ -26,8 +26,9 @@ AM_LIBS =
AM_CXXFLAGS = $(AM_CFLAGS)
lib_LTLIBRARIES = src/libbake-bulk-client.la
lib_LTLIBRARIES = src/libbake-bulk-client.la src/libbake-bulk-server.la
src_libbake_bulk_client_la_SOURCES =
src_libbake_bulk_server_la_SOURCES =
LDADD = src/libbake-bulk-client.la
......
......@@ -8,7 +8,6 @@
#define __BAKE_BULK_CLIENT_H
#include <stdint.h>
#include "bake-bulk.h"
/**
......
/*
* (C) 2016 The University of Chicago
*
* See COPYRIGHT in top-level directory.
*/
#ifndef __BAKE_BULK_SERVER_H
#define __BAKE_BULK_SERVER_H
#include <margo.h>
#include <libpmemobj.h>
#include "bake-bulk.h"
struct bake_bulk_root
{
bake_target_id_t target_id;
};
/**
* Register a bake server instance for a given Margo instance.
*
* @param[in] mid Margo instance identifier
* @param[in] bb_pmem_pool libpmem pool to use for the bake storage service
* @param[in] bb_pmem_root libpmem root for the bake pool
*/
void bake_server_register(
margo_instance_id mid,
PMEMobjpool *bb_pmem_pool,
struct bake_bulk_root *bb_pmem_root);
#endif /* __BAKE_BULK_SERVER_H */
src_libbake_bulk_client_la_SOURCES += \
src/bake-bulk-client.c
src_libbake_bulk_server_la_SOURCES += \
src/bake-bulk-server.c
bin_PROGRAMS += \
src/bake-bulk-server \
src/bb-shutdown \
src/bb-copy-to \
src/bb-copy-from \
src/bb-latency-bench
src_bake_bulk_server_SOURCES = \
src/bake-bulk-server.c \
src/bake-bulk-rpc.c
......@@ -5,7 +5,7 @@
*/
#include <assert.h>
#include <bake-bulk.h>
#include <bake-bulk-client.h>
#include <margo.h>
#include "uthash.h"
#include "bake-bulk-rpc.h"
......
This diff is collapsed.
......@@ -101,15 +101,6 @@ DECLARE_MARGO_RPC_HANDLER(bake_bulk_probe_ult)
/* noop */
DECLARE_MARGO_RPC_HANDLER(bake_bulk_noop_ult)
/* TODO: this should be somewhere else, just putting in this header for
* convenience right now. The type should only be visible to the server
* daemon and the rpc handlers.
*/
struct bake_bulk_root
{
bake_target_id_t target_id;
};
/* TODO: where should the encoder defs live? Not in bake-bulk-rpc.c because
* we don't really need the rpc handlers to be linked into clients...
......
/*
* (C) 2015 The University of Chicago
*
* See COPYRIGHT in top-level directory.
*/
#include <stdio.h>
#include <assert.h>
#include <unistd.h>
#include <uuid/uuid.h>
#include <abt.h>
#include <abt-snoozer.h>
#include <margo.h>
#include <libpmemobj.h>
#include <bake-bulk-server.h>
int main(int argc, char **argv)
{
int ret;
margo_instance_id mid;
ABT_xstream handler_xstream;
ABT_pool handler_pool;
hg_context_t *hg_context;
hg_class_t *hg_class;
char target_string[64];
PMEMoid root_oid;
PMEMobjpool *bb_pmem_pool = NULL;
struct bake_bulk_root *bb_pmem_root = NULL;
if(argc != 3)
{
fprintf(stderr, "Usage: bake-bulk-server <HG listening addr> <pmem pool>\n");
fprintf(stderr, " Example: ./bake-bulk-server tcp://localhost:1234 /dev/shm/foo.dat\n");
return(-1);
}
/* open pmem pool */
bb_pmem_pool = pmemobj_open(argv[2], NULL);
if(!bb_pmem_pool)
{
fprintf(stderr, "pmemobj_open: %s\n", pmemobj_errormsg());
return(-1);
}
/* find root */
root_oid = pmemobj_root(bb_pmem_pool, sizeof(*bb_pmem_root));
bb_pmem_root = pmemobj_direct(root_oid);
if(uuid_is_null(bb_pmem_root->target_id.id))
{
uuid_generate(bb_pmem_root->target_id.id);
pmemobj_persist(bb_pmem_pool, bb_pmem_root, sizeof(*bb_pmem_root));
}
uuid_unparse(bb_pmem_root->target_id.id, target_string);
fprintf(stderr, "BAKE target ID: %s\n", target_string);
/* boilerplate HG initialization steps */
/***************************************/
hg_class = HG_Init(argv[1], HG_TRUE);
if(!hg_class)
{
fprintf(stderr, "Error: HG_Init()\n");
return(-1);
}
hg_context = HG_Context_create(hg_class);
if(!hg_context)
{
fprintf(stderr, "Error: HG_Context_create()\n");
HG_Finalize(hg_class);
return(-1);
}
/* set up argobots */
/***************************************/
ret = ABT_init(argc, argv);
if(ret != 0)
{
fprintf(stderr, "Error: ABT_init()\n");
return(-1);
}
/* set primary ES to idle without polling */
ret = ABT_snoozer_xstream_self_set();
if(ret != 0)
{
fprintf(stderr, "Error: ABT_snoozer_xstream_self_set()\n");
return(-1);
}
/* Find primary pool to use for running rpc handlers */
ret = ABT_xstream_self(&handler_xstream);
if(ret != 0)
{
fprintf(stderr, "Error: ABT_xstream_self()\n");
return(-1);
}
ret = ABT_xstream_get_main_pools(handler_xstream, 1, &handler_pool);
if(ret != 0)
{
fprintf(stderr, "Error: ABT_xstream_get_main_pools()\n");
return(-1);
}
/* actually start margo */
/* provide argobots pools for driving communication progress and
* executing rpc handlers as well as class and context for Mercury
* communication.
*/
/***************************************/
mid = margo_init_pool(handler_pool, handler_pool, hg_context);
assert(mid);
/* XXX BAKE SERVER INIT */
/* NOTE: at this point this server ULT has two options. It can wait on
* whatever mechanism it wants to (however long the daemon should run and
* then call margo_finalize(). Otherwise, it can call
* margo_wait_for_finalize() on the assumption that it should block until
* some other entity calls margo_finalize().
*
* This example does the latter. Margo will be finalized by a special
* RPC from the client.
*
* This approach will allow the server to idle gracefully even when
* executed in "single" mode, in which the main thread of the server
* daemon and the progress thread for Mercury are executing in the same
* ABT pool.
*/
margo_wait_for_finalize(mid);
ABT_finalize();
HG_Context_destroy(hg_context);
HG_Finalize(hg_class);
pmemobj_close(bb_pmem_pool);
return(0);
}
This diff is collapsed.
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