ssg-internal.h 2.85 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
#include "uthash.h"
19
#include "utlist.h"
20

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

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

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

42
/* SSG internal dataypes */
43

44
typedef struct ssg_member_state
45
{
46
    ssg_member_id_t id;
47
    char *addr_str;
48
    hg_addr_t addr;
49 50
    struct ssg_member_state *next;
    UT_hash_handle hh;
51
} ssg_member_state_t;
52

53 54 55 56 57 58
/* 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
59 60
    int owner_status;
    int ref_count;
61 62 63
} ssg_group_descriptor_t;

typedef struct ssg_group_view
64
{
Shane Snyder's avatar
Shane Snyder committed
65
    unsigned int size;
66 67
    ssg_member_state_t *member_list;
    ssg_member_state_t *member_map;
68
} ssg_group_view_t;
Shane Snyder's avatar
Shane Snyder committed
69

70
typedef struct ssg_group
Jonathan Jenkins's avatar
Jonathan Jenkins committed
71
{
72
    char *name;
Shane Snyder's avatar
Shane Snyder committed
73
    ssg_member_id_t self_id;
74
    ssg_group_view_t view;
75
    ssg_group_descriptor_t *descriptor;
76
    void *fd_ctx; /* failure detector context (currently just SWIM) */
77 78
    ssg_membership_update_cb update_cb;
    void *update_cb_dat;
79
    UT_hash_handle hh;
80 81 82 83 84 85 86 87 88
} 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;
89

90
typedef struct ssg_instance
91 92 93
{
    margo_instance_id mid;
    ssg_group_t *group_table;
94 95 96 97 98 99 100 101
    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
102
};
Shane Snyder's avatar
Shane Snyder committed
103

104 105 106 107
/* SSG internal function prototypes */

#define ssg_hashlittle2 hashlittle2
extern void hashlittle2(const void *key, size_t length, uint32_t *pc, uint32_t *pb);
108 109
static inline uint64_t ssg_hash64_str(const char * str)
{
Shane Snyder's avatar
Shane Snyder committed
110
    uint32_t lower = 0, upper = 0;
111
    uint64_t hash;
112
    ssg_hashlittle2(str, strlen(str), &lower, &upper);
113 114 115
    hash = lower + (((uint64_t)upper)<<32);
    return hash;
}
116 117 118

void ssg_register_rpcs(
    void);
119 120 121 122 123
int ssg_group_attach_send(
    ssg_group_descriptor_t * group_descriptor,
    char ** group_name,
    int * group_size, 
    void ** view_buf);
124 125 126
void ssg_apply_membership_update(
    ssg_group_t *g,
    ssg_membership_update_t update);
127

128
/* XXX: is this right? can this be a global? */
129
extern ssg_instance_t *ssg_inst; 
130

Shane Snyder's avatar
Shane Snyder committed
131 132 133
#ifdef __cplusplus
}
#endif