controller_trace.c 13.5 KB
Newer Older
Jeroen Vreeken's avatar
Jeroen Vreeken committed
1
/*
Jeroen Vreeken's avatar
Jeroen Vreeken committed
2
3
	Copyright Jeroen Vreeken (pe1rxq@amsat.org), 2007, 2013
	Copyright Stichting C.A. Muller Radioastronomiestation, 2007, 2013
Jeroen Vreeken's avatar
Jeroen Vreeken committed
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

	This program 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 program 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/>.

 */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <pthread.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <signal.h>
#include <errno.h>
Jeroen Vreeken's avatar
Jeroen Vreeken committed
33
#include <limits.h>
Jeroen Vreeken's avatar
Jeroen Vreeken committed
34
35
36

#include <controller/controller_block.h>
#include <controller/controller_trace.h>
Jeroen Vreeken's avatar
Jeroen Vreeken committed
37
#include <controller/controller_time.h>
38
#include <controller/controller_mem.h>
Jeroen Vreeken's avatar
Jeroen Vreeken committed
39
#include <log/log.h>
40
#include <trace/trace.h>
Jeroen Vreeken's avatar
Jeroen Vreeken committed
41
42
43

static int nr_traces = 0;
static struct controller_trace_name *trace_list = NULL;
44
long interval_nsec;
Jeroen Vreeken's avatar
Jeroen Vreeken committed
45

46
47
48
49
50
51
52
53
54
55
56
static bool timespec_mod(struct timespec *t, struct timespec *tdiv)
{
	/* TODO: make a proper mod taking both fields into account */
	if (tdiv->tv_sec) {
		return t->tv_sec % tdiv->tv_sec || t->tv_nsec;
	} else if (tdiv->tv_nsec) {
		return t->tv_nsec % tdiv->tv_nsec;
	}
	return false;
}

Jeroen Vreeken's avatar
Jeroen Vreeken committed
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
struct controller_trace_name *controller_trace_get(int nr)
{
	return &trace_list[nr];
}

int controller_trace_nr(void)
{
	return nr_traces;
}

void controller_trace_list_add(struct controller_trace_name *trace)
{
	struct controller_trace_name *tmp;

	nr_traces++;
	tmp = realloc(trace_list, sizeof(struct controller_trace) * nr_traces);
	if (tmp) {
		trace_list = tmp;
		memcpy(&trace_list[nr_traces-1], trace,
		    sizeof(struct controller_trace));
77
		log_send(LOG_T_DEBUG, "Added trace %s [%s] using %s.%s",
Jeroen Vreeken's avatar
Jeroen Vreeken committed
78
79
80
81
82
83
84
85
86
87
88
		    trace->name, trace->unit, 
		    trace->blockname, trace->termname);
	} else
		nr_traces--;
}

#define TRACE_LEN	1024

struct trace_hdl {
	int free;

89
	struct trace trace;
Jeroen Vreeken's avatar
Jeroen Vreeken committed
90
	bool added;
91
92
	enum trace_interval_type type;
	long nsec;
93

Jeroen Vreeken's avatar
Jeroen Vreeken committed
94
	char tracename[100];
95
	struct controller_trace ctrace;
96
	union controller_trace_value last;
Jeroen Vreeken's avatar
Jeroen Vreeken committed
97
	union controller_trace_value buffer[TRACE_LEN];
Jeroen Vreeken's avatar
Jeroen Vreeken committed
98
	bool valuesend;
Jeroen Vreeken's avatar
Jeroen Vreeken committed
99
100
101
102
103
104
105
};

static int nr_trace_hdl;
static struct trace_hdl *trace_hdl;

static int controller_trace_server_port;

Jeroen Vreeken's avatar
Jeroen Vreeken committed
106
/* Thes are created when starting the server and sent to each new client */
107
struct trace_pkt *controller_trace_pkt_caps;
108
109
110
struct trace_pkt *controller_trace_pkt_interval;
struct trace_pkt *controller_trace_pkt_list;

Jeroen Vreeken's avatar
Jeroen Vreeken committed
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

static enum trace_value_type termtype2tracetype(enum controller_block_term_type type)
{
	switch (type) {
		case CONTROLLER_BLOCK_TERM_FLOAT:
			return TRACE_VALUE_TYPE_FLOAT;
		case CONTROLLER_BLOCK_TERM_BOOL:
			return TRACE_VALUE_TYPE_BOOL;
		case CONTROLLER_BLOCK_TERM_UINT8:
			return TRACE_VALUE_TYPE_UINT8;
		case CONTROLLER_BLOCK_TERM_UINT16:
			return TRACE_VALUE_TYPE_UINT16;
		case CONTROLLER_BLOCK_TERM_UINT32:
			return TRACE_VALUE_TYPE_UINT32;
		case CONTROLLER_BLOCK_TERM_SINT8:
			return TRACE_VALUE_TYPE_SINT8;
		case CONTROLLER_BLOCK_TERM_SINT16:
			return TRACE_VALUE_TYPE_SINT16;
		case CONTROLLER_BLOCK_TERM_SINT32:
			return TRACE_VALUE_TYPE_SINT32;
		default:
			break;
	}
	return -1;
}

Jeroen Vreeken's avatar
Jeroen Vreeken committed
137
138
139
static void *controller_trace_handle(void *arg)
{
	int i;
Jeroen Vreeken's avatar
Jeroen Vreeken committed
140
141
142
	fd_set fdrx;
	int high;
	struct timeval tv;
Jeroen Vreeken's avatar
Jeroen Vreeken committed
143
	long usec = controller_time_sample_period_get() * 1000000;
Jeroen Vreeken's avatar
Jeroen Vreeken committed
144
145

	while (1) {
Jeroen Vreeken's avatar
Jeroen Vreeken committed
146
147
148
		FD_ZERO(&fdrx);
		high = 0;
		
Jeroen Vreeken's avatar
Jeroen Vreeken committed
149
150
151
		for (i = 0; i < nr_trace_hdl; i++) {
			if (trace_hdl[i].free)
				continue;
Jeroen Vreeken's avatar
Jeroen Vreeken committed
152
153
154
155
156
			
			trace_fd_set(&trace_hdl[i].trace, &fdrx, &high);
		}
		
		tv.tv_sec = 0;
Jeroen Vreeken's avatar
Jeroen Vreeken committed
157
		tv.tv_usec = usec;
Jeroen Vreeken's avatar
Jeroen Vreeken committed
158
	
Jeroen Vreeken's avatar
Jeroen Vreeken committed
159
		select(high + 1, &fdrx, NULL, NULL, &tv);
Jeroen Vreeken's avatar
Jeroen Vreeken committed
160
		
Jeroen Vreeken's avatar
Jeroen Vreeken committed
161
162
163
164
165
166
167
168
169
170
171
		for (i = 0; i < nr_trace_hdl; i++) {
			if (trace_hdl[i].free)
				continue;
			
			trace_handle(&trace_hdl[i].trace, &fdrx);
		}

		for (i = 0; i < nr_trace_hdl; i++) if (trace_hdl[i].trace.name_set) {
			size_t wr_pos, rd_pos;
			size_t len;
			int j;
Jeroen Vreeken's avatar
Jeroen Vreeken committed
172
		
Jeroen Vreeken's avatar
Jeroen Vreeken committed
173
174
			wr_pos = trace_hdl[i].ctrace.wr_pos;
			rd_pos = trace_hdl[i].ctrace.rd_pos;
Jeroen Vreeken's avatar
Jeroen Vreeken committed
175
			__sync_synchronize();
Jeroen Vreeken's avatar
Jeroen Vreeken committed
176
177
178
179
180
181

			if (wr_pos != rd_pos) {
				struct trace_pkt *pkt;
				
				if (rd_pos >= wr_pos)
					len = trace_hdl[i].ctrace.len - rd_pos;
182
				else {
Jeroen Vreeken's avatar
Jeroen Vreeken committed
183
					len = wr_pos - rd_pos;
184
185
				}
				
Jeroen Vreeken's avatar
Jeroen Vreeken committed
186
187
				pkt = trace_packet_new();
	
Jeroen Vreeken's avatar
Jeroen Vreeken committed
188
189
				for (j = 0; j < len; j++) {
					size_t pos = rd_pos+j;
190
191
					bool sendtime = false;
					bool sendval = false;
Jeroen Vreeken's avatar
Jeroen Vreeken committed
192
					
193
194
195
196
					if (trace_hdl[i].nsec < 0) {
						sendval = true;
						trace_hdl[i].nsec = 0;
					}
Jeroen Vreeken's avatar
Jeroen Vreeken committed
197
					if (pos == trace_hdl[i].ctrace.timestamp_pos) {
198
199
200
201
202
						trace_hdl[i].nsec = 0;
						sendtime = true;
					}
					
					if (trace_hdl[i].type == TRACE_INTERVAL_TYPE_INTERVAL) {
203
204
205
206
207
208
						struct timespec t;

						t.tv_sec = trace_hdl[i].ctrace.timestamp;
						t.tv_nsec = trace_hdl[i].nsec;
						
						sendval = !timespec_mod(&t, &trace_hdl[i].trace.interval);
209
210
211
212
						/* No need to send time every second if values are send
						   less than once a second */
						if (&trace_hdl[i].trace.interval.tv_sec)
							sendtime = sendval;
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
					} else if (trace_hdl[i].type == TRACE_INTERVAL_TYPE_CHANGED) {
						uint32_t bufval = 0;
						uint32_t last = 0;
						
						switch (trace_hdl[i].trace.type) {
							case TRACE_VALUE_TYPE_BOOL:
							case TRACE_VALUE_TYPE_SINT8:
							case TRACE_VALUE_TYPE_UINT8:
								bufval = trace_hdl[i].ctrace.buffer[rd_pos+j].u8;
								last = trace_hdl[i].last.u8;
								trace_hdl[i].last.u8 = bufval;
								break;
							case TRACE_VALUE_TYPE_UINT16:
							case TRACE_VALUE_TYPE_SINT16:
								bufval = trace_hdl[i].ctrace.buffer[rd_pos+j].u16;
								last = trace_hdl[i].last.u16;
								trace_hdl[i].last.u16 = bufval;
								break;
							case TRACE_VALUE_TYPE_UINT32:
							case TRACE_VALUE_TYPE_SINT32:
							case TRACE_VALUE_TYPE_FLOAT:
								bufval = trace_hdl[i].ctrace.buffer[rd_pos+j].u32;
								last = trace_hdl[i].last.u32;
								trace_hdl[i].last.u32 = bufval;
								break;
						}
Jeroen Vreeken's avatar
Jeroen Vreeken committed
239
						if (bufval != last || !trace_hdl[i].valuesend) {
240
241
							sendtime = true;
							sendval = true;
Jeroen Vreeken's avatar
Jeroen Vreeken committed
242
							trace_hdl[i].valuesend = true;
243
244
245
246
						}
					}

					if (sendtime) {
Jeroen Vreeken's avatar
Jeroen Vreeken committed
247
248
						struct timespec t;
						
249
250
251
						if (pkt->len) {
							trace_packet_write(&trace_hdl[i].trace, pkt);
							trace_packet_put(pkt);
Jeroen Vreeken's avatar
Jeroen Vreeken committed
252
						
253
254
							pkt = trace_packet_new();
						}
255

Jeroen Vreeken's avatar
Jeroen Vreeken committed
256
						t.tv_sec = trace_hdl[i].ctrace.timestamp;
257
						t.tv_nsec = trace_hdl[i].nsec;
Jeroen Vreeken's avatar
Jeroen Vreeken committed
258
259
260
261
262
263
264
265
						trace_packet_timestamp_set(
							pkt, &t);
						trace_packet_write(&trace_hdl[i].trace, pkt);
						trace_packet_put(pkt);

						pkt = trace_packet_new();
					}
				
266
					if (sendval) {
267
						trace_packet_value_add(pkt, 0,
268
269
270
271
						    (void*)&trace_hdl[i].ctrace.buffer[rd_pos+j],
						    trace_hdl[i].trace.type);
					}
					trace_hdl[i].nsec += interval_nsec;
Jeroen Vreeken's avatar
Jeroen Vreeken committed
272
				}
Jeroen Vreeken's avatar
Jeroen Vreeken committed
273
274
275
276
277
278

				trace_packet_write(&trace_hdl[i].trace, pkt);
				trace_packet_put(pkt);
			
				trace_hdl[i].ctrace.rd_pos += len;
				if (trace_hdl[i].ctrace.rd_pos >= trace_hdl[i].ctrace.len)
279
					trace_hdl[i].ctrace.rd_pos %= trace_hdl[i].ctrace.len;
Jeroen Vreeken's avatar
Jeroen Vreeken committed
280
281
282
283
284
285
286
			}
		}
	}

	return NULL;
}

Jeroen Vreeken's avatar
Jeroen Vreeken committed
287
288
289
290
static void handler_close(struct trace *trace)
{
	struct trace_hdl *hdl = trace->private;
	
Jeroen Vreeken's avatar
Jeroen Vreeken committed
291
	if (hdl->added)
Jeroen Vreeken's avatar
Jeroen Vreeken committed
292
293
		controller_block_trace_del(&hdl->ctrace);

Jeroen Vreeken's avatar
Jeroen Vreeken committed
294
295
296
	log_send(LOG_T_DEBUG, "Trace connection closed");

	hdl->added = false;
Jeroen Vreeken's avatar
Jeroen Vreeken committed
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
	hdl->free = 1;
}

static void handler_name(struct trace *trace, char *name)
{
	struct trace_hdl *hdl = trace->private;
	int j;
	char *blockname;
	char *termname;
	bool found = false;
	struct trace_pkt *pkt;

	strcpy(hdl->tracename, name);

	log_send(LOG_T_DEBUG, "Starting trace for %s", name);

	/* Check the list of defined traces */
	for (j = 0; j < nr_traces; j++) {
		if (!strcmp(hdl->tracename,
		    trace_list[j].name)) {
			blockname = trace_list[j].blockname;
			termname = trace_list[j].termname;
			found = true;
			break;
		}
	}
	/* If not found, check if it is a "block.term" format */
	if (!found) {
		blockname = hdl->tracename;
		termname = hdl->tracename;
		while (termname[0] && termname[0] != '.')
			termname++;
			if (termname[0] == '.') {
				termname[0] = 0;
				termname++;
		}
	}

	hdl->ctrace.len = TRACE_LEN;
	hdl->ctrace.buffer = hdl->buffer;

338
339
	memset(hdl->buffer, 0, sizeof(union controller_trace_value) * TRACE_LEN);

Jeroen Vreeken's avatar
Jeroen Vreeken committed
340
341
342
343
344
345
	if (controller_block_trace_add(
	    blockname,
	    termname,
	    &hdl->ctrace)) {
		trace_close(&hdl->trace);
		hdl->free = 1;
Jeroen Vreeken's avatar
Jeroen Vreeken committed
346
347
		log_send(LOG_T_DEBUG, "Could not add trace");
		return;
Jeroen Vreeken's avatar
Jeroen Vreeken committed
348
	}
Jeroen Vreeken's avatar
Jeroen Vreeken committed
349
	hdl->added = true;
Jeroen Vreeken's avatar
Jeroen Vreeken committed
350
351
352
353
354
355
356
357
358

	pkt = trace_packet_new();
	
	hdl->trace.type = termtype2tracetype(hdl->ctrace.type);
	trace_packet_type_set(pkt, termtype2tracetype(hdl->ctrace.type));
	trace_packet_write(trace, pkt);
	trace_packet_put(pkt);
}

359
360
361
362
static void handler_interval(struct trace *trace, 
    struct timespec *interval, enum trace_interval_type type)
{
	struct trace_hdl *hdl = trace->private;
363
	struct trace_pkt *pkt;
364
	
365
366
	log_send(LOG_T_DEBUG, "Setting interval %ld.%09ld type %d", 
	    interval->tv_sec, interval->tv_nsec, type);
367
368

	hdl->type = type;
369
370
371
372
373
374
375
376

	/* Send back interval to client (as ACK) */
	pkt = trace_packet_new();
	trace_packet_interval_set(pkt, 
	    interval, type);
	trace_packet_write(trace, pkt);
	trace_packet_put(pkt);

377
378
379
}


Jeroen Vreeken's avatar
Jeroen Vreeken committed
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
static void *controller_trace_server(void *arg)
{
	int listen_sock;
	struct sockaddr_in sockaddr;
	int val;
	
	signal(SIGPIPE, SIG_IGN);
	
	listen_sock = socket(AF_INET, SOCK_STREAM, 0);
	if (listen_sock < 0) {
		perror("socket() failed");
		return NULL;
	}
	
	sockaddr.sin_family = AF_INET;
	sockaddr.sin_addr.s_addr = htonl(INADDR_ANY);
	sockaddr.sin_port = htons(controller_trace_server_port);
	
	val = 1;
	setsockopt(listen_sock, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(int));

	if (bind(listen_sock,
	    (struct sockaddr *)&sockaddr, sizeof(sockaddr)) < 0) {
		perror("bind() failed");
		close(listen_sock);
		return NULL;
	}
	
	if (listen(listen_sock, 8) < 0) {
		perror("listen() failed");
		close(listen_sock);
		return NULL;
	}
	
	while (1) {
		int client;
		struct sockaddr_in sockaddr_client;
		socklen_t len;
		
		len = sizeof(sockaddr_client);
		client = accept(listen_sock,
		    (struct sockaddr *)&sockaddr_client, &len);
		
		if (client >= 0) {
			int i;
			
			for (i = 0; i < nr_trace_hdl; i++) {
				if (!trace_hdl[i].free)
					continue;
				
430
				trace_initialize_fd(&trace_hdl[i].trace, client);
Jeroen Vreeken's avatar
Jeroen Vreeken committed
431
432

				/* Send info to client */
433
434
				trace_packet_write(&trace_hdl[i].trace,
				    controller_trace_pkt_caps);
435
436
437
438
				trace_packet_write(&trace_hdl[i].trace,
				    controller_trace_pkt_interval);
				trace_packet_write(&trace_hdl[i].trace,
				    controller_trace_pkt_list);
Jeroen Vreeken's avatar
Jeroen Vreeken committed
439
440
			
				trace_hdl[i].trace.name_set = false;
Jeroen Vreeken's avatar
Jeroen Vreeken committed
441
				trace_hdl[i].added = false;
442
443
				trace_hdl[i].type = TRACE_INTERVAL_TYPE_INTERVAL;
				trace_hdl[i].nsec = -1;
Jeroen Vreeken's avatar
Jeroen Vreeken committed
444
				trace_hdl[i].valuesend = false;
445
				
Jeroen Vreeken's avatar
Jeroen Vreeken committed
446
				trace_hdl[i].free = 0;
Jeroen Vreeken's avatar
Jeroen Vreeken committed
447
448
				break;
			}
449
450
451
			if (i == nr_trace_hdl) {
				log_send(LOG_T_ERROR, 
				    "No free trace handlers, closing trace connection");
Jeroen Vreeken's avatar
Jeroen Vreeken committed
452
				close(client);
453
			}
Jeroen Vreeken's avatar
Jeroen Vreeken committed
454
		} else {
455
456
			log_send(LOG_T_ERROR, "accept() failed: %s",
			    strerror(errno));
Jeroen Vreeken's avatar
Jeroen Vreeken committed
457
458
459
460
461
462
463
464
465
466
		}
	}

	return NULL;
}

void controller_trace_server_start(int portnr, int max)
{
	pthread_t thread_id;
	pthread_attr_t attr;
467
	int i, j;
468
469
	double period;
	struct timespec interval;
Jeroen Vreeken's avatar
Jeroen Vreeken committed
470
	
471
472
	log_send(LOG_T_DEBUG, "Starting trace server on port %d, max %d clients",
	    portnr, max);
Jeroen Vreeken's avatar
Jeroen Vreeken committed
473

474
475
	trace_hdl = controller_mem_calloc(CONTROLLER_MEM_PERIODIC_WRITE,
	     max, sizeof(struct trace_hdl));
Jeroen Vreeken's avatar
Jeroen Vreeken committed
476
477
	if (!trace_hdl)
		return;
478

Jeroen Vreeken's avatar
Jeroen Vreeken committed
479
	nr_trace_hdl = max;
480
	for (i = 0; i < max; i++) {
Jeroen Vreeken's avatar
Jeroen Vreeken committed
481
		trace_hdl[i].free = 1;
482
		trace_initialize(&trace_hdl[i].trace, 8192);
Jeroen Vreeken's avatar
Jeroen Vreeken committed
483
484
485
486

		trace_hdl[i].trace.private = &trace_hdl[i];
		trace_hdl[i].trace.handler_close = handler_close;
		trace_hdl[i].trace.handler_name = handler_name;
487
		trace_hdl[i].trace.handler_interval = handler_interval;
488
489
	}
	
490
491
492
	controller_trace_pkt_caps = trace_packet_new();
	trace_packet_capabilities_set(controller_trace_pkt_caps, 0);
	
493
	controller_trace_pkt_interval = trace_packet_new();
Jeroen Vreeken's avatar
Jeroen Vreeken committed
494
	period = controller_time_sample_period_get();
495
496
497
498
499
500
	interval.tv_sec = period;
	period -= interval.tv_sec;
	period *= 1000000000.0;
	period += 0.5;
	interval.tv_nsec = period;
	interval_nsec = period;
501
	trace_packet_interval_set(controller_trace_pkt_interval,
502
	    &interval, TRACE_INTERVAL_TYPE_INTERVAL);
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
	
	controller_trace_pkt_list = trace_packet_new();
	for (i = 0; i < nr_traces; i++) {
		struct controller_block *block;
		struct controller_block_outterm *outterm;
	
		block = controller_block_find(trace_list[i].blockname);
		if (!block)
			continue;
		outterm = controller_block_find_outterm(block, trace_list[i].termname);
		if (!outterm)
			continue;

		trace_packet_list_add(controller_trace_pkt_list,
		    trace_list[i].name,
		    termtype2tracetype(outterm->type),
		    trace_list[i].unit);
	}
	for (i = 0; i < controller_block_nr(); i++) {
		struct controller_block *block = controller_block_get(i);
		for (j = 0; j < block->outputs; j++) {
			char tracename[strlen(block->name) + 1 + strlen(block->output[j].name) + 1];
			
			sprintf(tracename, "%s.%s", block->name, block->output[j].name);
			
			trace_packet_list_add(controller_trace_pkt_list,
			    tracename,
			    termtype2tracetype(block->output[j].type),
			    "");
		}
	}
Jeroen Vreeken's avatar
Jeroen Vreeken committed
534
535
536
537
538
539
	
	controller_block_trace_init(max);

	controller_trace_server_port = portnr;

	pthread_attr_init(&attr);
540
#ifndef __FreeBSD__
Jeroen Vreeken's avatar
Jeroen Vreeken committed
541
	pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN * 2);
542
#endif
Jeroen Vreeken's avatar
Jeroen Vreeken committed
543
544
545
546
547
	pthread_create(&thread_id, &attr,
	    controller_trace_server, NULL);
	pthread_create(&thread_id, &attr,
	    controller_trace_handle, NULL);
}