root/trunk/src/io/bmi/bmi-method-support.h @ 8304

Revision 8304, 7.7 KB (checked in by pcarns, 3 years ago)

merging bmi-experimental-branch to trunk

Line 
1/*
2 * (C) 2001 Clemson University and The University of Chicago
3 *
4 * See COPYING in top-level directory.
5 */
6
7/* These are some support functions and data types shared across the
8 * various BMI methods.
9 */
10
11#ifndef __BMI_METHOD_SUPPORT_H
12#define __BMI_METHOD_SUPPORT_H
13
14#include "quicklist.h"
15#include "bmi-types.h"
16#include "pint-event.h"
17
18#define BMI_MAX_CONTEXTS 16
19
20/* magic number for BMI headers and control messages */
21#define BMI_MAGIC_NR 51903
22
23#ifndef timersub
24# define timersub(a, b, result) \
25  do { \
26    (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
27    (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
28    if ((result)->tv_usec < 0) { \
29      --(result)->tv_sec; \
30      (result)->tv_usec += 1000000; \
31    } \
32  } while (0)
33#endif
34
35/********************************************************
36 * method interfaces and data structures
37 */
38
39/* This is the generic address structure which contains adressing
40 * information for every protocol we support.  The method routines
41 * upcast the void* to find their particular device information.
42 */
43struct bmi_method_addr
44{
45    int method_type;
46    int ref_count;
47    void *method_data;          /* area to be used by specific methods */
48    void *parent;               /* pointer back to generic BMI address info */ 
49    struct bmi_method_addr* primary;
50    struct bmi_method_addr* secondary;
51};
52typedef struct bmi_method_addr *bmi_method_addr_p;
53
54/* used to describe unexpected messages that arrive */
55struct bmi_method_unexpected_info
56{
57    bmi_error_code_t error_code;
58    bmi_method_addr_p addr;
59    void *buffer;
60    bmi_size_t size;
61    bmi_msg_tag_t tag;
62};
63
64/* flags that can be set per method to affect behavior */
65#define BMI_METHOD_FLAG_NO_POLLING 1
66
67/* This is the table of interface functions that must be provided by BMI
68 * methods.
69 */
70struct bmi_method_ops
71{
72    const char *method_name;
73    int flags;
74    int (*initialize) (bmi_method_addr_p, int, int);
75    int (*finalize) (void);
76    int (*set_info) (int, void *);
77    int (*get_info) (int, void *);
78    void *(*memalloc) (bmi_size_t, enum bmi_op_type);
79    int (*memfree) (void *, bmi_size_t, enum bmi_op_type);
80
81    int (*unexpected_free) (void *);
82
83    int (*test) (bmi_op_id_t,
84                 int *,
85                 bmi_error_code_t *,
86                 bmi_size_t *,
87                 void **,
88                 int,
89                 bmi_context_id);
90    int (*testsome) (int,
91                     bmi_op_id_t *,
92                     int *,
93                     int *,
94                     bmi_error_code_t *,
95                     bmi_size_t *,
96                     void **,
97                     int,
98                     bmi_context_id);
99    int (*testcontext) (int,
100                        bmi_op_id_t*,
101                        int *,
102                        bmi_error_code_t *,
103                        bmi_size_t *,
104                        void **,
105                        int,
106                        bmi_context_id);
107    int (*testunexpected) (int,
108                           int *,
109                           struct bmi_method_unexpected_info *,
110                           uint8_t,
111                           int);
112    bmi_method_addr_p (*method_addr_lookup) (const char *);
113    int (*post_send_list) (bmi_op_id_t *,
114                           bmi_method_addr_p,
115                           const void *const *,
116                           const bmi_size_t *,
117                           int,
118                           bmi_size_t,
119                           enum bmi_buffer_type,
120                           bmi_msg_tag_t,
121                           void *,
122                           bmi_context_id,
123                           PVFS_hint hints);
124    int (*post_recv_list) (bmi_op_id_t *,
125                           bmi_method_addr_p,
126                           void *const *,
127                           const bmi_size_t *,
128                           int,
129                           bmi_size_t,
130                           bmi_size_t *,
131                           enum bmi_buffer_type,
132                           bmi_msg_tag_t,
133                           void *,
134                           bmi_context_id,
135                           PVFS_hint Hints);
136    int (*post_sendunexpected_list) (bmi_op_id_t *,
137                                     bmi_method_addr_p,
138                                     const void *const *,
139                                     const bmi_size_t *,
140                                     int,
141                                     bmi_size_t,
142                                     enum bmi_buffer_type,
143                                     bmi_msg_tag_t,
144                                     uint8_t,
145                                     void *,
146                                     bmi_context_id,
147                                     PVFS_hint hints);
148    int (*open_context)(bmi_context_id);
149    void (*close_context)(bmi_context_id);
150    int (*cancel)(bmi_op_id_t, bmi_context_id);
151    const char* (*rev_lookup_unexpected)(bmi_method_addr_p);
152    int (*query_addr_range)(bmi_method_addr_p, const char *, int);
153};
154
155
156/*
157 * This structure is somewhat optional.  TCP and GM use the elements in
158 * here extensively, but IB, MX, Portals only use the bits required by
159 * the generic BMI layer.  Those are op_id and addr.  Everything else is
160 * ignored.  Would be nice to push most of method_op down into TCP and GM
161 * so other BMI implementations do not need to drag around the unused fields.
162 */
163struct method_op
164{
165    bmi_op_id_t op_id;          /* operation identifier */
166    enum bmi_op_type send_recv; /* type of operation */
167    void *user_ptr;             /* user_ptr associated with this op */
168    bmi_msg_tag_t msg_tag;      /* message tag */
169    uint8_t class;              /* message class (if unexpected) */
170    bmi_error_code_t error_code;        /* final status of operation */
171    bmi_size_t amt_complete;    /* how much is completed */
172    bmi_size_t env_amt_complete;        /* amount of the envelope that is completed */
173    void *buffer;               /* the memory region to transfer */
174    bmi_size_t actual_size;     /* total size of the transfer */
175    bmi_size_t expected_size;   /* expected size of the transfer */
176    bmi_method_addr_p addr;     /* peer address involved in the communication */
177    int mode;           /* operation mode */
178    bmi_context_id context_id;  /* context */
179    struct qlist_head op_list_entry;    /* op_list link */
180    struct qlist_head hash_link;        /* hash table link */
181    void *method_data;          /* for use by individual methods */
182
183        /************************************************************
184         * following items were added for convenience of methods that
185         * implement send_list and recv_list
186         */
187    void *const *buffer_list;           /* list of buffers */
188    const bmi_size_t *size_list;        /* list of buffer sizes */
189    int list_count;             /* # of items in buffer list */
190    int list_index;             /* index of current buffer to xfer */
191    /* how much is completed in current buffer */
192    bmi_size_t cur_index_complete;
193    PINT_event_id event_id;
194};
195typedef struct method_op method_op_st, *method_op_p;
196
197struct method_drop_addr_query
198{
199    struct bmi_method_addr* addr;
200    int response;
201};
202
203/***********************************************************
204 * utility functions provided for use by the network methods
205 */
206
207/* functions for managing operations */
208method_op_p bmi_alloc_method_op(bmi_size_t payload_size);
209void bmi_dealloc_method_op(method_op_p op_p);
210
211/* These functions can be used to manage generic address structures */
212bmi_method_addr_p bmi_alloc_method_addr(int method_type,
213                                bmi_size_t payload_size);
214void bmi_dealloc_method_addr(bmi_method_addr_p old_method_addr);
215
216/* string parsing utilities */
217char *string_key(const char *key,
218                 const char *id_string);
219
220#endif /* __BMI_METHOD_SUPPORT_H */
221
222/*
223 * Local variables:
224 *  c-indent-level: 4
225 *  c-basic-offset: 4
226 * End:
227 *
228 * vim: ts=8 sts=4 sw=4 expandtab
229 */
Note: See TracBrowser for help on using the browser.