ssg-internal.h 2.51 KB
Newer Older
1 2 3 4 5
/*
 * Copyright (c) 2016 UChicago Argonne, LLC
 *
 * See COPYRIGHT in top-level directory.
 */
Shane Snyder's avatar
Shane Snyder committed
6

Jonathan Jenkins's avatar
Jonathan Jenkins committed
7
#pragma once
Shane Snyder's avatar
Shane Snyder committed
8

Shane Snyder's avatar
Shane Snyder committed
9 10
#include <stdint.h>
#include <inttypes.h>
11

Shane Snyder's avatar
Shane Snyder committed
12
#include <mercury.h>
Shane Snyder's avatar
Shane Snyder committed
13
#include <mercury_proc_string.h>
Shane Snyder's avatar
Shane Snyder committed
14
#include <abt.h>
Jonathan Jenkins's avatar
Jonathan Jenkins committed
15
#include <margo.h>
16

17
#include "ssg.h"
18 19
#include "uthash.h"

20 21 22 23
#ifdef __cplusplus
extern "C" {
#endif

24
#define SSG_MAGIC_NR 17321588
Jonathan Jenkins's avatar
Jonathan Jenkins committed
25

26 27
/* debug printing macro for SSG */
/* TODO: direct debug output to file? */
28
/* TODO: how do we debug attachers? */
Shane Snyder's avatar
Shane Snyder committed
29
#ifdef DEBUG
30
#define SSG_DEBUG(__g, __fmt, ...) do { \
Shane Snyder's avatar
Shane Snyder committed
31
    double __now = ABT_get_wtime(); \
32
    fprintf(stdout, "%.6lf <%s:%"PRIu64">: " __fmt, __now, \
33
        __g->name, __g->self_id, ## __VA_ARGS__); \
34
    fflush(stdout); \
Shane Snyder's avatar
Shane Snyder committed
35 36
} while(0)
#else
37
#define SSG_DEBUG(__g, __fmt, ...) do { \
Shane Snyder's avatar
Shane Snyder committed
38 39 40
} while(0)
#endif

41
/* SSG internal dataypes */
42

43
typedef struct ssg_member_state
44
{
45
    char *addr_str;
46
    hg_addr_t addr;
47
    int is_member;
48
} ssg_member_state_t;
49

50 51 52 53 54 55
/* TODO: associate a version number with a descriptor */
typedef struct ssg_group_descriptor
{
    uint64_t magic_nr;
    uint64_t name_hash;
    char *addr_str;
Shane Snyder's avatar
Shane Snyder committed
56 57
    int owner_status;
    int ref_count;
58 59 60
} ssg_group_descriptor_t;

typedef struct ssg_group_view
61
{
Shane Snyder's avatar
Shane Snyder committed
62
    unsigned int size;
63
    ssg_member_state_t *member_states;
64
} ssg_group_view_t;
Shane Snyder's avatar
Shane Snyder committed
65

66
typedef struct ssg_group
Jonathan Jenkins's avatar
Jonathan Jenkins committed
67
{
68 69
    char *name;
    ssg_group_descriptor_t *descriptor;
Shane Snyder's avatar
Shane Snyder committed
70
    ssg_member_id_t self_id;
71
    ssg_group_view_t view;
72
    void *fd_ctx; /* failure detector context (currently just SWIM) */
73 74
    ssg_membership_update_cb update_cb;
    void *update_cb_dat;
75
    UT_hash_handle hh;
76 77 78 79 80 81 82 83 84
} ssg_group_t;

typedef struct ssg_attached_group
{
    char *name;
    ssg_group_descriptor_t *descriptor;
    ssg_group_view_t view;
    UT_hash_handle hh;
} ssg_attached_group_t;
85

86
typedef struct ssg_instance
87 88 89
{
    margo_instance_id mid;
    ssg_group_t *group_table;
90 91 92 93 94 95 96 97
    ssg_attached_group_t *attached_group_table;
} ssg_instance_t;

enum ssg_group_descriptor_owner_status
{
    SSG_OWNER_IS_UNASSOCIATED = 0,
    SSG_OWNER_IS_MEMBER,
    SSG_OWNER_IS_ATTACHER
Jonathan Jenkins's avatar
Jonathan Jenkins committed
98
};
Shane Snyder's avatar
Shane Snyder committed
99

100 101 102 103 104 105 106
/* SSG internal function prototypes */

#define ssg_hashlittle2 hashlittle2
extern void hashlittle2(const void *key, size_t length, uint32_t *pc, uint32_t *pb);

void ssg_register_rpcs(
    void);
107 108 109 110 111
int ssg_group_attach_send(
    ssg_group_descriptor_t * group_descriptor,
    char ** group_name,
    int * group_size, 
    void ** view_buf);
112 113 114
void ssg_apply_membership_update(
    ssg_group_t *g,
    ssg_membership_update_t update);
115

116
/* XXX: is this right? can this be a global? */
117
extern ssg_instance_t *ssg_inst; 
118

Shane Snyder's avatar
Shane Snyder committed
119 120 121
#ifdef __cplusplus
}
#endif