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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
|
/*
* pmmodule.c
*
* C module to access pm data (preemption and migration ovd and length)
* from python.
*
* The rationale is to process the bulk of a sample set using C, then
* move only the interesting values to Python.
*/
#include <Python.h>
#include <numpy/arrayobject.h>
#include "pm_common.h"
static struct ovd_plen *preempt = NULL;
static struct ovd_plen *samel2 = NULL;
static struct ovd_plen *samechip = NULL;
static struct ovd_plen *offchip = NULL;
static int pcount = 0;
static int l2count = 0;
static int chipcount = 0;
static int offcount = 0;
static int loaded(int set)
{
static int load = 0;
if(!load && set)
load = 1;
return load;
}
static void cleanup()
{
free(preempt);
if(samel2)
free(samel2);
free(samechip);
free(offchip);
}
/*
* pm_load: load raw data from filename and process overheads
* for hierarchy of up to L3 cache levels
*
* @filename: raw data file
* @cores_per_l2: number of cores that share an L2 cache
* if (cores_per_l2 == 0) then all cores in a chip share
* the L2 cache (i.e., no L3)
* @num_phys_cpu: number of physical sockets
*
* TODO this should be (re)integrated at some point, to allow NUMA / other
* topologies evaluations
* @cores_per_chip: number of cores per chip (they can share a L3 or a L2
* cache. This is decided by the cores_per_l2 value)
*/
static PyObject* pm_load(PyObject *self, PyObject *args)
{
const char *filename;
unsigned int cores_per_l2;
unsigned int num_phys_cpu;
int wss;
int tss;
struct full_ovd_plen *full_costs = NULL;
int num_samples;
if (!PyArg_ParseTuple(args, "sIIii", &filename, &cores_per_l2,
&num_phys_cpu, &wss, &tss))
return NULL;
/* get valid overheads from raw file */
if ((num_samples = get_valid_ovd(filename, &full_costs, wss, tss)) < 0)
goto err;
if ((preempt = malloc(num_samples * sizeof(struct ovd_plen))) < 0)
goto err;
memset(preempt, 0, num_samples * sizeof(struct ovd_plen));
if (cores_per_l2) {
if((samel2 = malloc(num_samples * sizeof(struct ovd_plen))) < 0)
goto err_samel2;
memset(samel2, 0, num_samples * sizeof(struct ovd_plen));
}
if((samechip = malloc(num_samples * sizeof(struct ovd_plen))) < 0)
goto err_samechip;
memset(samechip, 0, num_samples * sizeof(struct ovd_plen));
if((offchip = malloc(num_samples * sizeof(struct ovd_plen))) < 0)
goto err_offchip;
memset(offchip, 0, num_samples * sizeof(struct ovd_plen));
/* get p/m overheads and lengths */
get_ovd_plen_umaxeon(full_costs, num_samples, cores_per_l2, num_phys_cpu,
preempt, &pcount, samel2, &l2count, samechip, &chipcount,
offchip, &offcount);
loaded(1);
free(full_costs);
Py_INCREF(Py_None);
return Py_None;
err_offchip:
free(samechip);
err_samechip:
if(cores_per_l2)
free(samel2);
err_samel2:
free(preempt);
err:
free(full_costs);
PyErr_Format(PyExc_ValueError, "Cannot load / analyze raw data");
return NULL;
}
/* return the preemption (ovd, length) NumPy array with shape (pcount,2) */
static PyObject* pm_get_preemption(PyObject *self, PyObject *args)
{
PyArrayObject *py_preempt;
npy_intp shape[2];
int i;
long long *tmp;
if (!loaded(0)) {
PyErr_Format(PyExc_ValueError, "pm not Loaded!");
return NULL;
}
shape[0] = pcount;
shape[1] = 2;
if (!PyArg_ParseTuple(args,""))
return NULL;
py_preempt = (PyArrayObject *) PyArray_SimpleNew(2,shape,NPY_LONGLONG);
if (!py_preempt)
goto err_alloc;
for (i = 0; i < pcount; i++) {
tmp = (long long *) PyArray_GETPTR2(py_preempt, i, 0);
if(!tmp)
goto err;
*tmp = (long long) preempt[i].ovd;
tmp = (long long *) PyArray_GETPTR2(py_preempt, i, 1);
if(!tmp)
goto err;
*tmp = (long long) preempt[i].plen;
}
free(preempt);
return (PyObject *) py_preempt;
err:
PyArray_free(py_preempt);
err_alloc:
PyErr_Format(PyExc_ValueError, "pm_get_preemption Error");
cleanup();
return NULL;
}
/* return the samel2 (ovd, length) NumPy array with shape (l2count,2) */
static PyObject* pm_get_samel2(PyObject *self, PyObject *args)
{
PyArrayObject *py_samel2;
npy_intp shape[2];
int i;
long long *tmp;
if (!loaded(0)) {
PyErr_Format(PyExc_ValueError, "pm not Loaded!");
return NULL;
}
shape[0] = l2count;
shape[1] = 2;
if (!PyArg_ParseTuple(args,""))
return NULL;
py_samel2 = (PyArrayObject *) PyArray_SimpleNew(2,shape,NPY_LONGLONG);
if (!py_samel2)
goto err_alloc;
for (i = 0; i < l2count; i++) {
tmp = (long long *) PyArray_GETPTR2(py_samel2, i, 0);
if(!tmp)
goto err;
*tmp = (long long) samel2[i].ovd;
tmp = (long long *) PyArray_GETPTR2(py_samel2, i, 1);
if(!tmp)
goto err;
*tmp = (long long) samel2[i].plen;
}
free(samel2);
return (PyObject *) py_samel2;
err:
PyArray_free(py_samel2);
err_alloc:
PyErr_Format(PyExc_ValueError, "pm_get_preemption Error");
cleanup();
return NULL;
}
/* return the samechip (ovd, length) NumPy array with shape (chipcount,2) */
static PyObject* pm_get_samechip(PyObject *self, PyObject *args)
{
PyArrayObject *py_samechip;
npy_intp shape[2];
int i;
long long *tmp;
if (!loaded(0)) {
PyErr_Format(PyExc_ValueError, "pm not Loaded!");
return NULL;
}
shape[0] = chipcount;
shape[1] = 2;
if (!PyArg_ParseTuple(args,""))
return NULL;
py_samechip = (PyArrayObject *) PyArray_SimpleNew(2,shape,NPY_LONGLONG);
if (!py_samechip)
goto err_alloc;
for (i = 0; i < chipcount; i++) {
tmp = (long long *) PyArray_GETPTR2(py_samechip, i, 0);
if(!tmp)
goto err;
*tmp = (long long) samechip[i].ovd;
tmp = (long long *) PyArray_GETPTR2(py_samechip, i, 1);
if(!tmp)
goto err;
*tmp = (long long) samechip[i].plen;
}
free(samechip);
return (PyObject *) py_samechip;
err:
PyArray_free(py_samechip);
err_alloc:
PyErr_Format(PyExc_ValueError, "pm_get_preemption Error");
cleanup();
return NULL;
}
/* return the offchip (ovd, length) NumPy array with shape (offcount,2) */
static PyObject* pm_get_offchip(PyObject *self, PyObject *args)
{
PyArrayObject *py_offchip;
npy_intp shape[2];
int i;
long long *tmp;
if (!loaded(0)) {
PyErr_Format(PyExc_ValueError, "pm not Loaded!");
return NULL;
}
shape[0] = offcount;
shape[1] = 2;
if (!PyArg_ParseTuple(args,""))
return NULL;
py_offchip = (PyArrayObject *) PyArray_SimpleNew(2,shape,NPY_LONGLONG);
if (!py_offchip)
goto err_alloc;
for (i = 0; i < offcount; i++) {
tmp = (long long *) PyArray_GETPTR2(py_offchip, i, 0);
if(!tmp)
goto err;
*tmp = (long long) offchip[i].ovd;
tmp = (long long *) PyArray_GETPTR2(py_offchip, i, 1);
if(!tmp)
goto err;
*tmp = (long long) offchip[i].plen;
}
free(offchip);
return (PyObject *) py_offchip;
err:
PyArray_free(py_offchip);
err_alloc:
PyErr_Format(PyExc_ValueError, "pm_get_preemption Error");
cleanup();
return NULL;
}
static PyMethodDef PmMethods[] = {
{"load", pm_load, METH_VARARGS, "Load data from raw files"},
{"getPreemption", pm_get_preemption, METH_VARARGS,
"Get preemption overheads - length"},
{"getL2Migration", pm_get_samel2, METH_VARARGS,
"Get L2 Migration overheads - length"},
{"getOnChipMigration", pm_get_samechip, METH_VARARGS,
"Get Chip (L2 or L3) overheads - length"},
{"getOffChipMigration", pm_get_offchip, METH_VARARGS,
"Get Off Chip overheads - length"},
{NULL, NULL, 0, NULL}
};
PyMODINIT_FUNC initpm(void)
{
PyObject *pm;
pm = Py_InitModule("pm", PmMethods);
if(!pm)
return;
/* required by NumPy */
import_array();
}
|