File: ofi_perf.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 (187 lines) | stat: -rw-r--r-- 4,408 bytes parent folder | download | duplicates (8)
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
/*
 * Copyright (c) 2018 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_PERF_H_
#define _OFI_PERF_H_

#include "config.h"

#include <assert.h>
#include <string.h>
#include <ofi_osd.h>
#include <rdma/providers/fi_prov.h>


#ifdef __cplusplus
extern "C" {
#endif


enum ofi_perf_domain {
	OFI_PMU_CPU,
	OFI_PMU_CACHE,
	OFI_PMU_OS,
	OFI_PMU_NIC
};

enum {
	OFI_PMC_FLAG_READ	= 1 << 0,
	OFI_PMC_FLAG_WRITE	= 1 << 1,
	OFI_PMC_FLAG_MISS	= 1 << 2,
};

enum {
	OFI_PMC_CPU_CYCLES,
	OFI_PMC_CPU_INSTR,
};

enum {
	OFI_PMC_CACHE_L1_DATA,
	OFI_PMC_CACHE_L1_INSTR,
	OFI_PMC_CACHE_TLB_DATA,
	OFI_PMC_CACHE_TLB_INSTR,
};

enum {
	OFI_PMC_OS_PAGE_FAULT
};

/* NIC counters TBD */

struct ofi_perf_data {
	uint64_t	start;
	uint64_t	sum;
	uint64_t	events;
};


void ofi_perf_init(void);
extern enum ofi_perf_domain	perf_domain;
extern uint32_t			perf_cntr;
extern uint32_t			perf_flags;


/*
 * Performance management unit:
 *
 * Access to a PMU is platform specific.  If an osd.h file provides methods
 * to access a PMU, it should define HAVE_LINUX_PERF_RDPMC and provide
 * implementations for the following functions.  Platforms that do not
 * support PMUs will default to no-op definitions.
 */

#if HAVE_LINUX_PERF_RDPMC

struct ofi_perf_ctx;

int ofi_pmu_open(struct ofi_perf_ctx **ctx,
		 enum ofi_perf_domain domain, uint32_t cntr_id, uint32_t flags);
uint64_t ofi_pmu_read(struct ofi_perf_ctx *ctx);
void ofi_pmu_close(struct ofi_perf_ctx *ctx);

#else /* HAVE_LINUX_PERF_RDPMC */

struct ofi_perf_ctx {
	int dummy;
};

static inline int ofi_pmu_open(struct ofi_perf_ctx **ctx,
			       enum ofi_perf_domain domain, uint32_t cntr_id,
			       uint32_t flags)
{
	*ctx = NULL;
	return 0;
}

static inline uint64_t ofi_pmu_read(struct ofi_perf_ctx *ctx)
{
	return 0;
}

static inline void ofi_pmu_close(struct ofi_perf_ctx *ctx)
{
}
#endif /* HAVE_LINUX_PERF_RDPMC */


static inline void ofi_perf_reset(struct ofi_perf_data *data)
{
	memset(data, 0, sizeof *data);
}

static inline void ofi_perf_start(struct ofi_perf_ctx *ctx,
				  struct ofi_perf_data *data)
{
	data->start = ofi_pmu_read(ctx);
}

static inline void ofi_perf_end(struct ofi_perf_ctx *ctx,
				struct ofi_perf_data *data)
{
	data->sum += ofi_pmu_read(ctx) - data->start;
	data->events++;
}


struct ofi_perfset {
	const struct fi_provider *prov;
	size_t			size;
	struct ofi_perf_ctx	*ctx;
	struct ofi_perf_data	*data;
};

int ofi_perfset_create(const struct fi_provider *prov,
		       struct ofi_perfset *set, size_t size,
		       enum ofi_perf_domain domain, uint32_t cntr_id,
		       uint32_t flags);
void ofi_perfset_close(struct ofi_perfset *set);

void ofi_perfset_log(struct ofi_perfset *set, const char **names);

static inline void ofi_perfset_start(struct ofi_perfset *set, size_t index)
{
	assert(index < set->size);
	ofi_perf_start(set->ctx, &set->data[index]);
}

static inline void ofi_perfset_end(struct ofi_perfset *set, size_t index)
{
	assert(index < set->size);
	ofi_perf_end(set->ctx, &set->data[index]);
}


#ifdef __cplusplus
}
#endif

#endif /* _OFI_PERF_H_ */