ssg-internal.h 2.79 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"
Shane Snyder's avatar
Shane Snyder committed
18
#include "swim-fd/swim-fd.h"
19
#include "uthash.h"
20
#include "utlist.h"
21

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

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

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

43
/* SSG internal dataypes */
44

45
typedef struct ssg_member_state
46
{
47
    ssg_member_id_t id;
48
    char *addr_str;
49
    hg_addr_t addr;
Shane Snyder's avatar
Shane Snyder committed
50
    swim_member_state_t swim_state;
51 52
    struct ssg_member_state *next;
    UT_hash_handle hh;
53
} ssg_member_state_t;
54

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

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

71
typedef struct ssg_group
Jonathan Jenkins's avatar
Jonathan Jenkins committed
72
{
73
    char *name;
Shane Snyder's avatar
Shane Snyder committed
74
    ssg_member_id_t self_id;
75
    ssg_group_view_t view;
76
    ssg_group_descriptor_t *descriptor;
Shane Snyder's avatar
Shane Snyder committed
77
    swim_context_t *swim_ctx;
Shane Snyder's avatar
Shane Snyder committed
78
    ssg_member_state_t *member_list;
79 80
    ssg_membership_update_cb update_cb;
    void *update_cb_dat;
81
    UT_hash_handle hh;
82 83 84 85 86 87 88 89 90
} 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;
91

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

106 107 108 109
/* SSG internal function prototypes */

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

void ssg_register_rpcs(
    void);
121 122 123 124 125
int ssg_group_attach_send(
    ssg_group_descriptor_t * group_descriptor,
    char ** group_name,
    int * group_size, 
    void ** view_buf);
126

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

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