SlsDetectorCPUAffinity.sip 9.23 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//###########################################################################
// This file is part of LImA, a Library for Image Acquisition
//
// Copyright (C) : 2009-2011
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//###########################################################################

23

24
25
26
27
28
29
30
31
32
33
// namespace SlsDetector
// {
// typedef std::vector<CPUAffinity> CPUAffinityList;
// };

%MappedType SlsDetector::CPUAffinityList
{
%TypeHeaderCode
#include "SlsDetectorCPUAffinity.h"
#include "sipAPIlimaslsdetector.h"
34
#include "SlsDetectorSip.h"
35
36
37
38
39

using namespace lima::SlsDetector;
%End

%ConvertToTypeCode
40
41
42
43
	typedef SipSequence<CPUAffinityList> Seq;
	Seq seq(sipType_SlsDetector_CPUAffinity);
	return seq.convertToTypeCode(sipPy, sipCppPtr, sipIsErr,
				     sipTransferObj);
44
45
46
%End

%ConvertFromTypeCode
47
48
49
	typedef SipSequence<CPUAffinityList> Seq;
	Seq seq(sipType_SlsDetector_CPUAffinity);
	return seq.convertFromTypeCode(sipCpp);
50
51
52
53
%End
};


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
// namespace SlsDetector
// {
// typedef std::vector<RecvCPUAffinity> RecvCPUAffinityList;
// };

%MappedType SlsDetector::RecvCPUAffinityList
{
%TypeHeaderCode
#include "SlsDetectorCPUAffinity.h"
#include "sipAPIlimaslsdetector.h"
#include "SlsDetectorSip.h"

using namespace lima::SlsDetector;
%End

%ConvertToTypeCode
	typedef SipSequence<RecvCPUAffinityList> Seq;
	Seq seq(sipType_SlsDetector_RecvCPUAffinity);
	return seq.convertToTypeCode(sipPy, sipCppPtr, sipIsErr,
				     sipTransferObj);
%End

%ConvertFromTypeCode
	typedef SipSequence<RecvCPUAffinityList> Seq;
	Seq seq(sipType_SlsDetector_RecvCPUAffinity);
	return seq.convertFromTypeCode(sipCpp);
%End
};


84
85
86
87
88
89
90
91
92
93
94
// namespace SlsDetector
// {
// typedef std::vector<SlsDetector::NetDevGroupCPUAffinity>
//					 NetDevGroupCPUAffinityList;
// };

%MappedType SlsDetector::NetDevGroupCPUAffinityList
{
%TypeHeaderCode
#include "SlsDetectorCPUAffinity.h"
#include "sipAPIlimaslsdetector.h"
95
#include "SlsDetectorSip.h"
96
97
98
99
100

using namespace lima::SlsDetector;
%End

%ConvertToTypeCode
101
102
103
104
	typedef SipSequence<NetDevGroupCPUAffinityList> Seq;
	Seq seq(sipType_SlsDetector_NetDevGroupCPUAffinity);
	return seq.convertToTypeCode(sipPy, sipCppPtr, sipIsErr,
				     sipTransferObj);
105
106
107
%End

%ConvertFromTypeCode
108
109
110
	typedef SipSequence<NetDevGroupCPUAffinityList> Seq;
	Seq seq(sipType_SlsDetector_NetDevGroupCPUAffinity);
	return seq.convertFromTypeCode(sipCpp);
111
112
113
114
%End
};


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
// namespace SlsDetector
// {
// typedef std::map<int, NetDevRxQueueCPUAffinity> NetDevRxQueueAffinityMap;
// };

%MappedType SlsDetector::NetDevRxQueueAffinityMap
{
%TypeHeaderCode
#include "SlsDetectorCPUAffinity.h"
#include "sipAPIlimaslsdetector.h"
#include "SlsDetectorSip.h"

using namespace lima::SlsDetector;
%End

%ConvertToTypeCode
	typedef SipMap<NetDevRxQueueAffinityMap> Map;
	Map map(NULL, sipType_SlsDetector_NetDevRxQueueCPUAffinity);
	return map.convertToTypeCode(sipPy, sipCppPtr, sipIsErr,
				     sipTransferObj);
%End

%ConvertFromTypeCode
	typedef SipMap<NetDevRxQueueAffinityMap> Map;
	Map map(NULL, sipType_SlsDetector_NetDevRxQueueCPUAffinity);
	return map.convertFromTypeCode(sipCpp);
%End
};


145
146
// namespace SlsDetector
// {
147
// typedef std::map<PixelDepth, GlobalCPUAffinity> PixelDepthCPUAffinityMap;
148
149
150
151
152
153
154
// };

%MappedType SlsDetector::PixelDepthCPUAffinityMap
{
%TypeHeaderCode
#include "SlsDetectorCPUAffinity.h"
#include "sipAPIlimaslsdetector.h"
155
#include "SlsDetectorSip.h"
156
157
158

using namespace lima::SlsDetector;

159
160
161
162
#ifndef SIP_TYPE_INT_IMPL_PixelDepth
SipTypeIntImpl(PixelDepth);
#define SIP_TYPE_INT_IMPL_PixelDepth
#endif
163
164
165
%End

%ConvertToTypeCode
166
167
168
169
170
	typedef SipMap<PixelDepthCPUAffinityMap> Map;
	Map map(sipType_SlsDetector_PixelDepth,
	        sipType_SlsDetector_GlobalCPUAffinity);
	return map.convertToTypeCode(sipPy, sipCppPtr, sipIsErr,
				     sipTransferObj);
171
172
173
%End

%ConvertFromTypeCode
174
175
176
177
	typedef SipMap<PixelDepthCPUAffinityMap> Map;
	Map map(sipType_SlsDetector_PixelDepth,
	        sipType_SlsDetector_GlobalCPUAffinity);
	return map.convertFromTypeCode(sipCpp);
178
179
180
%End
};

181

182
183
184
185
186
187
188
namespace SlsDetector
{

%TypeHeaderCode
#include "SlsDetectorCamera.h"
%End

189
class SystemCmd
190
191
{
public:
192
	SystemCmd(std::string cmd, std::string desc = "", bool try_sudo = true);
193

194
195
196
	static void setUseSudo(bool use_sudo);
	static bool getUseSudo();

197
198
199
200
201
202
203
204
	void addArgs(std::string args);
%MethodCode
	Py_BEGIN_ALLOW_THREADS
	sipCpp->args() << *a0;
	Py_END_ALLOW_THREADS
%End

	int execute();
205
206
207

 private:
	SystemCmd(const SlsDetector::SystemCmd& o);
208
209
210
211
212
213
214
};

class CPUAffinity
{
public:
	CPUAffinity(unsigned long m = 0);

215
216
	static int getNbSystemCPUs(bool max_nb = false);
	static int getNbHexDigits(bool max_nb = false);
217
218
	static unsigned long allCPUs(bool max_nb = false);

219
220
	int getNbCPUs() const;

221
222
223
224
	//void initCPUSet(cpu_set_t& cpu_set) const;
	void applyToTask(int task, bool incl_threads = true,
			 bool use_taskset = true) const;

225
226
227
	unsigned long getMask() const;
	unsigned long getZeroDefaultMask() const;

228
229
	operator unsigned long() const;

230
	SlsDetector::CPUAffinity& operator |=(const SlsDetector::CPUAffinity& o);
231
232
233

	bool isDefault() const;

234
235
236
	void getNUMANodeMask(std::vector<unsigned long>& node_mask /Out/,
			     int& max_node /Out/);

237
238
239
240
	static std::string getProcDir(bool local_threads);
	static std::string getTaskProcDir(int task, bool is_thread);
};

241
242
// typedef std::vector<CPUAffinity> CPUAffinityList;

243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
SlsDetector::CPUAffinity CPUAffinityList_all(
				const SlsDetector::CPUAffinityList& l);

class IrqMgr
{
 public:
	IrqMgr(std::string net_dev = "");
	~IrqMgr();

	void setDev(std::string net_dev);

	std::vector<int> getIrqList();
	void updateRxQueueIrqAffinity(bool default_affinity);
};

258
259
260
261
262
263
264
265
266
267
struct NetDevRxQueueCPUAffinity {
	SlsDetector::CPUAffinity irq;
	SlsDetector::CPUAffinity processing;

	bool isDefault() const;
	SlsDetector::CPUAffinity all() const;
};

// typedef std::map<int, NetDevRxQueueCPUAffinity> NetDevRxQueueAffinityMap;

268
269
270
bool NetDevRxQueueAffinityMap_isDefault(
			const SlsDetector::NetDevRxQueueAffinityMap& m);

271
272
273
274
class NetDevRxQueueMgr
{
 public:
	NetDevRxQueueMgr(std::string dev = "");
275
276
	~NetDevRxQueueMgr();

277
278
279
280
	void setDev(std::string dev);

	void apply(int queue,
		   const SlsDetector::NetDevRxQueueCPUAffinity& queue_affinity);
281
	void apply(const SlsDetector::NetDevRxQueueAffinityMap& affinity_map);
282
283
284
285

	std::vector<int> getRxQueueList();
};

286
287
struct NetDevGroupCPUAffinity {
	std::vector<std::string> name_list;
288
289
290
291
	SlsDetector::NetDevRxQueueAffinityMap queue_affinity;

	bool isDefault() const;
	SlsDetector::CPUAffinity all() const;
292
293
294
295
296
};

// typedef std::vector<SlsDetector::NetDevGroupCPUAffinity> 
//					NetDevGroupCPUAffinityList;

297
298
299
SlsDetector::CPUAffinity NetDevGroupCPUAffinityList_all(
			const SlsDetector::NetDevGroupCPUAffinityList& l);

300
class SystemCPUAffinityMgr
301
302
{
public:
303
304
	SystemCPUAffinityMgr();
	~SystemCPUAffinityMgr();
305
306
307
308
309
310

	enum Filter {
		All, MatchAffinity, NoMatchAffinity, ThisProc=0x10
	};

	static std::vector<int> getProcList(
311
312
		SlsDetector::SystemCPUAffinityMgr::Filter filter
			= SlsDetector::SystemCPUAffinityMgr::All,
313
314
		SlsDetector::CPUAffinity cpu_affinity = 0);
	static std::vector<int> getThreadList(
315
316
		SlsDetector::SystemCPUAffinityMgr::Filter filter
			= SlsDetector::SystemCPUAffinityMgr::All,
317
318
319
320
		SlsDetector::CPUAffinity cpu_affinity = 0);

	void setOtherCPUAffinity(
		SlsDetector::CPUAffinity affinity);
321
322
	void setNetDevCPUAffinity(
		const SlsDetector::NetDevGroupCPUAffinityList& netdev_list);
323
324
};

325
struct RecvCPUAffinity {
326
	SlsDetector::CPUAffinityList listeners;
327

328
	RecvCPUAffinity();
329
330
331
332
	SlsDetector::CPUAffinity all() const;
	// RecvCPUAffinity& operator =(CPUAffinity a);
};

333
334
// typedef std::vector<RecvCPUAffinity> RecvCPUAffinityList;

335
336
337
SlsDetector::CPUAffinity RecvCPUAffinityList_all(
				const SlsDetector::RecvCPUAffinityList& l);

338
struct GlobalCPUAffinity {
339
	SlsDetector::RecvCPUAffinityList recv;
340
	SlsDetector::CPUAffinityList model_threads;
341
342
	SlsDetector::CPUAffinity lima;
	SlsDetector::CPUAffinity other;
343
	SlsDetector::NetDevGroupCPUAffinityList netdev;
344
345

	GlobalCPUAffinity();
346
	SlsDetector::CPUAffinity all() const;
347
348
};

349
// typedef std::map<SlsDetector::PixelDepth, SlsDetector::GlobalCPUAffinity> 
350
351
//						PixelDepthCPUAffinityMap;

352
class GlobalCPUAffinityMgr
353
354
355
356
357
{
public:
	class ProcessingFinishedEvent
	{
	public:
358
		ProcessingFinishedEvent(SlsDetector::GlobalCPUAffinityMgr *mgr);
359
360
361
362
363
364
365
		~ProcessingFinishedEvent();

		void processingFinished();

		void registerStatusCallback(CtControl *ct_control);
	};

366
367
	GlobalCPUAffinityMgr(SlsDetector::Camera *cam = NULL);
	~GlobalCPUAffinityMgr();
368
	
369
	void applyAndSet(const SlsDetector::GlobalCPUAffinity& o);
370
371
	void updateRecvRestart();

372
	SlsDetector::GlobalCPUAffinityMgr::
373
374
375
376
377
378
379
380
	ProcessingFinishedEvent *getProcessingFinishedEvent();

	void prepareAcq();
	void startAcq();
	void stopAcq();
	void recvFinished();
	void limaFinished();
	void waitLimaFinished();
381
	void cleanUp();
382
383
384
385
};


}; // namespace SlsDetector