File: ofi_profile.h

package info (click to toggle)
mpich 4.3.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 101,184 kB
  • sloc: ansic: 1,040,629; cpp: 82,270; javascript: 40,763; perl: 27,933; python: 16,041; sh: 14,676; xml: 14,418; f90: 12,916; makefile: 9,270; fortran: 8,046; java: 4,635; asm: 324; ruby: 103; awk: 27; lisp: 19; php: 8; sed: 4
file content (249 lines) | stat: -rw-r--r-- 7,048 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/*
 * Copyright (c) 2023 Intel Corporation. All rights reserved.
 *
 * This software is available to you under a choice of one of two
 * licenses.  You may choose to be licensed under the terms of the GNU
 * General Public License (GPL) Version 2, available from the file
 * COPYING in the main directory of this source tree, or the
 * BSD license below:
 *
 *     Redistribution and use in source and binary forms, with or
 *     without modification, are permitted provided that the following
 *     conditions are met:
 *
 *      - Redistributions of source code must retain the above
 *	copyright notice, this list of conditions and the following
 *	disclaimer.
 *
 *      - Redistributions in binary form must reproduce the above
 *	copyright notice, this list of conditions and the following
 *	disclaimer in the documentation and/or other materials
 *	provided with the distribution.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#ifndef _OFI_PROFILE_H_
#define _OFI_PROFILE_H_

#include <string.h>
#include <stdint.h>
#include <assert.h>

#include <ofi_str.h>

#include <rdma/fabric.h>
#include <rdma/fi_profile.h>

#ifdef __cplusplus
extern "C" {
#endif

/*
 * variable and event id is uint32_t.
 * last 16 bits is for an unique number, upper bits is FI_PROV_SPECFIC_XXX
 * (refer fi_ext.h)
 * common pre-defined variables/events will be <idx>
 * provider-defined variables/events will be -FI_PROV_SPECIFIC_XXX + <idx>
 */
#define OFI_PROF_ID_MASK     0xffff       // bit 15-0

extern size_t ofi_common_var_count;
extern size_t ofi_common_event_count;

typedef int (*ofi_prof_callback_t)(struct fid_profile *prof_fid,
				   struct fi_profile_desc *event, void *param,
				   size_t size, void *context);

#define OFI_VAR_DATATYPE_U64(desc)     \
	(((desc)->datatype_sel == fi_primitive_type) && \
	 ((desc)->datatype.primitive <= FI_UINT64))

#define OFI_VAR_ENABLED(desc)		((desc)->name)
#define OFI_EVENT_ENABLED(desc)		((desc)->name)

struct util_pcb {
	ofi_prof_callback_t cb;
	void *context;
};

struct util_prof_data {
	union {
		uint64_t u64;
		void *pt;
	} value;
	size_t size;
};

/*
 * varilist: contains variables
 *    [0, ofi_common_var_count-1]: pre-defined common variables.
 *    [ofi_common_var_count, ...]: provider-specific variables.
 * eventlist: contains events
 *    [0, ofi_common_event_count-1]: pre-defined common events.
 *    [ofi_common_event_count, ...]: provider-specific events.
 */
struct util_profile {
	struct fid_profile prof_fid;
	struct fid *fid;
	struct fi_provider *prov;

	uint64_t flags;

	size_t varlist_size;
	size_t var_count;
	struct fi_profile_desc *varlist;
	void **vars;
	struct util_prof_data *data;
	bool data_cached;

	size_t eventlist_size;
	size_t event_count;
	struct fi_profile_desc *eventlist;
	struct util_pcb *pcb;
};

#define OFI_PROF_DATA_CACHED(prof)      (prof)->data_cached
#define OFI_PROF_START_READS(prof)    \
	do { (prof)->data_cached = true; } while (0)
#define OFI_PROF_END_READS(prof)      \
	do {  (prof)->data_cached = false; } while (0)


static inline int
ofi_prof_id2_idx(uint32_t id, size_t common_desc_count)
{
	int idx = id & OFI_PROF_ID_MASK;

	return (id >> 16) ? (common_desc_count + idx) : idx;
}

static inline struct fi_profile_desc *
ofi_prof_var_id2_desc(struct util_profile *prof, uint32_t var_id)
{
	int idx = ofi_prof_id2_idx(var_id, ofi_common_var_count);
	if ((idx < prof->varlist_size) &&
	    (OFI_EVENT_ENABLED(&(prof->varlist[idx])))) {
		return &(prof->varlist[idx]);
	} else {
		return NULL;
	}
}

static inline struct fi_profile_desc *
ofi_prof_event_id2_desc(struct util_profile *prof, uint32_t event_id)
{
	int idx = ofi_prof_id2_idx(event_id, ofi_common_event_count);
	if ((idx < prof->eventlist_size) &&
	    (OFI_EVENT_ENABLED(&(prof->eventlist[idx])))) {
		return &(prof->eventlist[idx]);
	} else {
		return NULL;
	}
}

static inline void
ofi_prof_event_notify(struct util_profile *prof, uint32_t event,
		      void *param, size_t size)
{
	int idx = ofi_prof_id2_idx(event, ofi_common_event_count);
	struct util_pcb *pcb;

	if ((idx < prof->eventlist_size) &&
	    (OFI_EVENT_ENABLED(&(prof->eventlist[idx])))) {
		pcb = &(prof->pcb[idx]);
		pcb->cb(&(prof->prof_fid), &(prof->eventlist[idx]),
			param, size, pcb->context);
	}
}

static inline uint64_t
ofi_var_data_u64(void *var, enum fi_datatype type)
{
	switch(type) {
	case FI_INT8:
		return (uint64_t)(*(int8_t *)var);
	case FI_UINT8:
		return (uint64_t)(*(uint8_t *)var);
	case FI_INT16:
		return (uint64_t)(*(int16_t *)var);
	case FI_UINT16:
		return (uint64_t)(*(uint16_t *)var);
	case FI_INT32:
		return (uint64_t)(*(int32_t *)var);
	case FI_UINT32:
		return (uint64_t)(*(uint32_t *)var);
	case FI_INT64:
		return (uint64_t)(*(int64_t *)var);
	case FI_UINT64:
		return (uint64_t)(*(uint64_t *)var);
	default:
		break;
	}
	return 0;
}

static inline ssize_t
ofi_prof_read_u64(struct util_profile *prof, int idx,
		  void *data, size_t *size)
{
	uint64_t *val64 = (uint64_t *)data;

	if (*size < sizeof(uint64_t))
		return -FI_ETOOSMALL;

	if (prof->data_cached) 
		*val64 = prof->data[idx].value.u64;
	else
		*val64 = ofi_var_data_u64(prof->vars[idx],
					  prof->varlist[idx].datatype.primitive);

	return sizeof(uint64_t);
}

static inline ssize_t
ofi_prof_read_cached_data(struct util_profile *prof, int idx,
			  void *data, size_t *size)
{
	if (*size < prof->data[idx].size)
		return -FI_ETOOSMALL;

	memcpy(data, prof->data[idx].value.pt, prof->data[idx].size);
	return prof->data[idx].size;
}

int ofi_prof_init(struct util_profile *prof, struct fid *fid,
		  uint64_t flags, void *context, struct fi_profile_ops *ops,
		  int prov_vars_size, int prov_events_size);

void ofi_prof_reset(struct util_profile *prof, uint64_t flags);
ssize_t ofi_prof_query_vars(struct util_profile *prof,
			    struct fi_profile_desc *varlist, size_t *count);
ssize_t ofi_prof_query_events(struct util_profile *prof,
			      struct fi_profile_desc *eventlist, size_t *count);
int ofi_prof_reg_callback(struct util_profile *prof, uint32_t event,
			  ofi_prof_callback_t cb, void *context);

void ofi_prof_add_common_vars(struct util_profile *prof);
void ofi_prof_add_common_events(struct util_profile *prof);
int ofi_prof_add_var(struct util_profile *prof, uint32_t var_id,
		     struct fi_profile_desc *desc, void *var);
int ofi_prof_add_event(struct util_profile *prof, uint32_t event_id,
		       struct fi_profile_desc *desc);

int ofi_prof_pcb_noop(struct fid_profile *prof_fid, 
		      struct fi_profile_desc *event, void *param,
		      size_t size, void *context);

#ifdef __cplusplus
}
#endif

#endif /* _OFI_PROFILE_H_ */