blob: a3b4a0217e09d79b281e829c50eb0bccd99ebc6b [file] [log] [blame]
Igor Opaniukab88c952017-02-14 13:22:54 +02001/*
2 * Copyright (c) 2016, Linaro Limited
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#include <errno.h>
29#include <fcntl.h>
30#include <inttypes.h>
31#include <limits.h>
32#include <libgen.h>
33#include <pthread.h>
34#include <string.h>
35#include <stdio.h>
36#include <stdbool.h>
37#include <stdlib.h>
38#include <sys/types.h>
39#include <sys/mman.h>
40#include <sys/stat.h>
41#include <sys/wait.h>
42#include <unistd.h>
Igor Opaniukf1f3fd02017-09-14 15:34:56 +030043#include <yaml.h>
Igor Opaniukab88c952017-02-14 13:22:54 +020044
45#include "benchmark_aux.h"
Igor Opaniukf1f3fd02017-09-14 15:34:56 +030046#include "common.h"
Igor Opaniukab88c952017-02-14 13:22:54 +020047
Igor Opaniukf1f3fd02017-09-14 15:34:56 +030048#define MAX_SCALAR 20
49static struct tee_ts_global *bench_ts_global;
Igor Opaniukab88c952017-02-14 13:22:54 +020050
51static const TEEC_UUID pta_benchmark_uuid = PTA_BENCHMARK_UUID;
Igor Opaniukab88c952017-02-14 13:22:54 +020052static TEEC_Context ctx;
53static TEEC_Session sess;
54
Igor Opaniuk55fcc4a2018-02-06 19:20:22 +020055static sig_atomic_t is_running;
Igor Opaniukf1f3fd02017-09-14 15:34:56 +030056static yaml_emitter_t emitter;
57
Igor Opaniuk3d566ae2018-01-29 02:41:33 +020058struct consumer_param {
59 pid_t child_pid;
60 char *ts_filepath;
61};
Igor Opaniukf1f3fd02017-09-14 15:34:56 +030062void sigint_handler(int data)
63{
64 (void)data;
65
66 is_running = 0;
67}
68
Igor Opaniukab88c952017-02-14 13:22:54 +020069static void open_bench_pta(void)
70{
71 TEEC_Result res;
72 uint32_t err_origin;
73
74 res = TEEC_InitializeContext(NULL, &ctx);
75 tee_check_res(res, "TEEC_InitializeContext");
76
77 res = TEEC_OpenSession(&ctx, &sess, &pta_benchmark_uuid,
78 TEEC_LOGIN_PUBLIC, NULL, NULL, &err_origin);
79 tee_check_res(res, "TEEC_OpenSession");
80}
81
82static void close_bench_pta(void)
83{
84 /* release benchmark timestamp shm */
Igor Opaniukab88c952017-02-14 13:22:54 +020085 TEEC_CloseSession(&sess);
86 TEEC_FinalizeContext(&ctx);
87}
88
Igor Opaniuk55fcc4a2018-02-06 19:20:22 +020089static void alloc_bench_buf(uint32_t cores)
Igor Opaniukab88c952017-02-14 13:22:54 +020090{
91 TEEC_Result res;
92 TEEC_Operation op = { 0 };
93 uint32_t ret_orig;
Igor Opaniuk55fcc4a2018-02-06 19:20:22 +020094 intptr_t paddr_ts_buf = 0;
95 size_t size;
Igor Opaniukab88c952017-02-14 13:22:54 +020096
Igor Opaniuk55fcc4a2018-02-06 19:20:22 +020097 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INOUT,
98 TEEC_VALUE_INPUT, TEEC_NONE, TEEC_NONE);
Igor Opaniukab88c952017-02-14 13:22:54 +020099
Igor Opaniuk55fcc4a2018-02-06 19:20:22 +0200100 op.params[1].value.a = cores;
Igor Opaniukab88c952017-02-14 13:22:54 +0200101
Igor Opaniuk55fcc4a2018-02-06 19:20:22 +0200102 res = TEEC_InvokeCommand(&sess, BENCHMARK_CMD_REGISTER_MEMREF,
Igor Opaniukab88c952017-02-14 13:22:54 +0200103 &op, &ret_orig);
104 tee_check_res(res, "TEEC_InvokeCommand");
Igor Opaniuk55fcc4a2018-02-06 19:20:22 +0200105
106 paddr_ts_buf = op.params[0].value.a;
107 size = op.params[0].value.b;
108
109 INFO("ts buffer paddr = %x, size = %d\n", paddr_ts_buf, size);
110 if (paddr_ts_buf) {
111
112 bench_ts_global = mmap_paddr(paddr_ts_buf, size);
113 if (!bench_ts_global)
114 ERROR_EXIT("Failed to allocate timestamp buffer");
115 } else {
116 ERROR_EXIT("Failed to allocate timestamp buffer");
117 }
Igor Opaniukab88c952017-02-14 13:22:54 +0200118}
119
Igor Opaniuk55fcc4a2018-02-06 19:20:22 +0200120static void free_bench_buf(void)
Igor Opaniukab88c952017-02-14 13:22:54 +0200121{
122 TEEC_Result res;
123 TEEC_Operation op = { 0 };
124 uint32_t ret_orig;
125
126 op.paramTypes = TEEC_PARAM_TYPES(TEEC_NONE,
127 TEEC_NONE, TEEC_NONE, TEEC_NONE);
128
129 res = TEEC_InvokeCommand(&sess, BENCHMARK_CMD_UNREGISTER,
130 &op, &ret_orig);
131 tee_check_res(res, "TEEC_InvokeCommand");
132}
133
134static void usage(char *progname)
135{
136 fprintf(stderr, "Call latency benchmark tool for OP-TEE\n\n");
137 fprintf(stderr, "Usage:\n");
138 fprintf(stderr, " %s -h\n", progname);
139 fprintf(stderr, " %s host_app [host_app_args]\n", progname);
140 fprintf(stderr, "Options:\n");
141 fprintf(stderr, " -h Print this help and exit\n");
142 fprintf(stderr, " host_app Path to host app to benchmark\n");
143 fprintf(stderr, " host_app_args Original host app args\n");
144}
145
146static int timestamp_pop(struct tee_ts_cpu_buf *cpu_buf,
Igor Opaniuk55fcc4a2018-02-06 19:20:22 +0200147 struct tee_time_st *ts)
Igor Opaniukab88c952017-02-14 13:22:54 +0200148{
149 uint64_t ts_tail;
150
151 if (!cpu_buf && !ts)
152 return RING_BADPARM;
153
154 if (cpu_buf->tail >= cpu_buf->head)
155 return RING_NODATA;
156
157 ts_tail = cpu_buf->tail++;
158 *ts = cpu_buf->stamps[ts_tail & TEE_BENCH_MAX_MASK];
159
160 return 0;
161}
162
Igor Opaniukf1f3fd02017-09-14 15:34:56 +0300163static bool init_emitter(FILE *ts_file)
164{
165 yaml_event_t event;
166
167 if (!yaml_emitter_initialize(&emitter))
168 ERROR_RETURN_FALSE("Can't initialize YAML emitter");
169
170 yaml_emitter_set_canonical(&emitter, 0);
171 yaml_emitter_set_unicode(&emitter, 1);
172 yaml_emitter_set_output_file(&emitter, ts_file);
173
174 /* Stream start */
175 if (!yaml_stream_start_event_initialize(&event, YAML_UTF8_ENCODING))
176 ERROR_GOTO(emitter_delete,
Igor Opaniuk66e23bf2018-02-06 19:18:59 +0200177 "Failed to initialize YAML stream start event");
Igor Opaniukf1f3fd02017-09-14 15:34:56 +0300178 if (!yaml_emitter_emit(&emitter, &event))
Igor Opaniuk66e23bf2018-02-06 19:18:59 +0200179 ERROR_GOTO(emitter_delete,
180 "Failed to emit YAML stream start event");
Igor Opaniukf1f3fd02017-09-14 15:34:56 +0300181
182 /* Document start */
183 if (!yaml_document_start_event_initialize(&event,
Igor Opaniuk66e23bf2018-02-06 19:18:59 +0200184 NULL, NULL, NULL, YAML_IMPLICIT))
Igor Opaniukf1f3fd02017-09-14 15:34:56 +0300185 ERROR_GOTO(emitter_delete,
Igor Opaniuk66e23bf2018-02-06 19:18:59 +0200186 "Failed to initialize YAML document start event");
Igor Opaniukf1f3fd02017-09-14 15:34:56 +0300187 if (!yaml_emitter_emit(&emitter, &event))
Igor Opaniuk66e23bf2018-02-06 19:18:59 +0200188 ERROR_GOTO(emitter_delete,
189 "Failed to emit YAML doc start event");
Igor Opaniukf1f3fd02017-09-14 15:34:56 +0300190
191 /* Mapping start */
192 if (!yaml_mapping_start_event_initialize(&event,
193 NULL, NULL , YAML_IMPLICIT,
194 YAML_ANY_SEQUENCE_STYLE))
195 ERROR_GOTO(emitter_delete,
Igor Opaniuk66e23bf2018-02-06 19:18:59 +0200196 "Failed to initialize YAML mapping start event");
Igor Opaniukf1f3fd02017-09-14 15:34:56 +0300197 if (!yaml_emitter_emit(&emitter, &event))
198 ERROR_GOTO(emitter_delete,
Igor Opaniuk66e23bf2018-02-06 19:18:59 +0200199 "Failed to emit YAML sequence mapping event");
Igor Opaniukf1f3fd02017-09-14 15:34:56 +0300200 /* Key timestamps */
201 yaml_scalar_event_initialize(&event, NULL, NULL,
202 (yaml_char_t *)"timestamps", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE);
203 if (!yaml_emitter_emit(&emitter, &event))
204 ERROR_RETURN_FALSE("Failed to emit YAML scalar");
205
206 /* Sequence start */
207 if (!yaml_sequence_start_event_initialize(&event,
208 NULL, NULL , YAML_IMPLICIT,
209 YAML_ANY_SEQUENCE_STYLE))
210 ERROR_GOTO(emitter_delete,
Igor Opaniuk66e23bf2018-02-06 19:18:59 +0200211 "Failed to initialize YAML sequence start event");
Igor Opaniukf1f3fd02017-09-14 15:34:56 +0300212 if (!yaml_emitter_emit(&emitter, &event))
Igor Opaniuk66e23bf2018-02-06 19:18:59 +0200213 ERROR_GOTO(emitter_delete,
214 "Failed to emit YAML sequence start event");
Igor Opaniukf1f3fd02017-09-14 15:34:56 +0300215
216 return true;
217emitter_delete:
218 yaml_emitter_delete(&emitter);
219 return false;
220}
221
222static void deinit_emitter()
223{
224 yaml_event_t event;
225
226 /* Sequence cmd */
227 if (!yaml_sequence_end_event_initialize(&event))
228 ERROR_GOTO(emitter_delete,
Igor Opaniuk66e23bf2018-02-06 19:18:59 +0200229 "Failed to initialize YAML sequence end event");
Igor Opaniukf1f3fd02017-09-14 15:34:56 +0300230 if (!yaml_emitter_emit(&emitter, &event))
Igor Opaniuk66e23bf2018-02-06 19:18:59 +0200231 ERROR_GOTO(emitter_delete,
232 "Failed to emit YAML sequence end event");
Igor Opaniukf1f3fd02017-09-14 15:34:56 +0300233
234 /* Mapping end */
235 if (!yaml_mapping_end_event_initialize(&event))
236 ERROR_GOTO(emitter_delete,
Igor Opaniuk66e23bf2018-02-06 19:18:59 +0200237 "Failed to initialize YAML mapping end event");
Igor Opaniukf1f3fd02017-09-14 15:34:56 +0300238 if (!yaml_emitter_emit(&emitter, &event))
239 ERROR_GOTO(emitter_delete,
Igor Opaniuk66e23bf2018-02-06 19:18:59 +0200240 "Failed to emit YAML mapping end event");
Igor Opaniukf1f3fd02017-09-14 15:34:56 +0300241
242 /* Document end */
243 if (!yaml_document_end_event_initialize(&event, 0))
244 ERROR_GOTO(emitter_delete,
Igor Opaniuk66e23bf2018-02-06 19:18:59 +0200245 "Failed to initialize YAML document end event");
Igor Opaniukf1f3fd02017-09-14 15:34:56 +0300246 if (!yaml_emitter_emit(&emitter, &event))
247 ERROR_GOTO(emitter_delete, "Failed to emit YAML doc end event");
248
249 /* Stream end */
250 if (!yaml_stream_end_event_initialize(&event))
251 ERROR_GOTO(emitter_delete,
Igor Opaniuk66e23bf2018-02-06 19:18:59 +0200252 "Failed to initialise YAML stream end event");
Igor Opaniukf1f3fd02017-09-14 15:34:56 +0300253 if (!yaml_emitter_emit(&emitter, &event))
Igor Opaniuk66e23bf2018-02-06 19:18:59 +0200254 ERROR_GOTO(emitter_delete,
255 "Failed to emit YAML stream end event");
Igor Opaniukf1f3fd02017-09-14 15:34:56 +0300256
257emitter_delete:
258 yaml_emitter_delete(&emitter);
259}
260
261static bool fill_map(char *var, char *value)
262{
263 yaml_event_t event;
264
265 yaml_scalar_event_initialize(&event, NULL, NULL,
266 (yaml_char_t *)var, -1, 1, 1, YAML_PLAIN_SCALAR_STYLE);
267 if (!yaml_emitter_emit(&emitter, &event))
268 ERROR_RETURN_FALSE("Failed to emit YAML scalar");
269
270 yaml_scalar_event_initialize(&event, NULL, NULL,
271 (yaml_char_t *)value, -1, 1, 1, YAML_PLAIN_SCALAR_STYLE);
272 if (!yaml_emitter_emit(&emitter, &event))
273 ERROR_RETURN_FALSE("Failed to emit YAML scalar");
274
275 return true;
276}
277
278static bool fill_timestamp(uint32_t core, uint64_t count, uint64_t addr,
279 const char *subsystem)
280{
281 yaml_event_t event;
282 char data[MAX_SCALAR];
283
284 /* Mapping start */
285 if (!yaml_mapping_start_event_initialize(&event,
286 NULL, NULL , YAML_IMPLICIT,
287 YAML_ANY_SEQUENCE_STYLE))
Igor Opaniuk66e23bf2018-02-06 19:18:59 +0200288 ERROR_RETURN_FALSE(
289 "Failed to initialize YAML mapping start event");
Igor Opaniukf1f3fd02017-09-14 15:34:56 +0300290 if (!yaml_emitter_emit(&emitter, &event))
291 ERROR_RETURN_FALSE("Failed to emit YAML mapping start event");
292
293 snprintf(data, MAX_SCALAR, "%" PRIu32, core);
294 fill_map("core", data);
295
296 snprintf(data, MAX_SCALAR, "%" PRIu64, count);
297 fill_map("counter", data);
298
299 snprintf(data, MAX_SCALAR, "0x%" PRIx64, addr);
300 fill_map("address", data);
301
302 snprintf(data, MAX_SCALAR, "%s", subsystem);
303 fill_map("component", data);
304
305 /* Mapping end */
306 if (!yaml_mapping_end_event_initialize(&event))
Igor Opaniuk66e23bf2018-02-06 19:18:59 +0200307 ERROR_RETURN_FALSE(
308 "Failed to initialize YAML mapping end event");
Igor Opaniukf1f3fd02017-09-14 15:34:56 +0300309 if (!yaml_emitter_emit(&emitter, &event))
310 ERROR_RETURN_FALSE("Failed to emit YAML mapping end event");
311
312 return true;
313}
314
315/*
316 * Consume all timestamps from per-cpu ringbuffers and put everything into
317 * the yaml file.
318 */
Igor Opaniukab88c952017-02-14 13:22:54 +0200319static void *ts_consumer(void *arg)
320{
Yves Leflochb31789d2017-08-01 14:51:18 +0200321 unsigned int i;
322 int ret;
Igor Opaniukab88c952017-02-14 13:22:54 +0200323 bool ts_received = false;
324 uint32_t cores;
325 struct tee_time_st ts_data;
326 FILE *ts_file;
Igor Opaniuk3d566ae2018-01-29 02:41:33 +0200327 struct consumer_param *prm = (struct consumer_param *)arg;
328 char *tsfile_path = prm->ts_filepath;
329 pid_t child_pid = prm->child_pid;
330 size_t teec_dyn_addr = 0;
Igor Opaniukab88c952017-02-14 13:22:54 +0200331
Igor Opaniukab88c952017-02-14 13:22:54 +0200332 if (!tsfile_path)
Igor Opaniukf1f3fd02017-09-14 15:34:56 +0300333 ERROR_GOTO(exit, "Wrong timestamp file path");
Igor Opaniukab88c952017-02-14 13:22:54 +0200334
335 cores = get_cores();
336 if (!cores)
Igor Opaniukf1f3fd02017-09-14 15:34:56 +0300337 ERROR_GOTO(exit, "Can't receive amount of avalable cores");
Igor Opaniukab88c952017-02-14 13:22:54 +0200338
339 ts_file = fopen(tsfile_path, "w");
340 if (!ts_file)
Igor Opaniukf1f3fd02017-09-14 15:34:56 +0300341 ERROR_GOTO(exit, "Can't open timestamp file");
342
343 if (!init_emitter(ts_file))
Igor Opaniuk66e23bf2018-02-06 19:18:59 +0200344 ERROR_GOTO(file_close,
345 "Error occurred in emitter initialization");
Igor Opaniukab88c952017-02-14 13:22:54 +0200346
347 while (is_running) {
348 ts_received = false;
349 for (i = 0; i < cores; i++) {
350 ret = timestamp_pop(&bench_ts_global->cpu_buf[i],
351 &ts_data);
352 if (!ret) {
353 ts_received = true;
Igor Opaniuk55fcc4a2018-02-06 19:20:22 +0200354 DBG("Timestamp: core = %u; tick = %lld; "
355 "pc = 0x%" PRIx64 "; system = %s",
356 i, ts_data.cnt, ts_data.addr,
357 bench_str_src(ts_data.src));
Igor Opaniuk3d566ae2018-01-29 02:41:33 +0200358 if (!teec_dyn_addr) {
359 teec_dyn_addr = get_library_load_offset
360 (child_pid,
361 LIBTEEC_NAME);
362 INFO("Libteec load address = %x",
363 teec_dyn_addr);
364 }
365 if (ts_data.src == TEE_BENCH_CLIENT) {
366 DBG("ts_addr = %llx, teec_addr = %x",
367 ts_data.addr, teec_dyn_addr);
368 ts_data.addr -= teec_dyn_addr;
369 }
Igor Opaniukf1f3fd02017-09-14 15:34:56 +0300370 if (!fill_timestamp(i, ts_data.cnt,
Igor Opaniuk55fcc4a2018-02-06 19:20:22 +0200371 ts_data.addr,
372 bench_str_src(ts_data.src)))
373 ERROR_GOTO(deinit_yaml,
374 "Adding timestamp failed");
Igor Opaniukf1f3fd02017-09-14 15:34:56 +0300375
Igor Opaniukab88c952017-02-14 13:22:54 +0200376 }
377 }
378
Yves Leflochb31789d2017-08-01 14:51:18 +0200379 if (!ts_received) {
Igor Opaniukf1f3fd02017-09-14 15:34:56 +0300380 if (is_running) {
381 DBG("yielding...");
Igor Opaniukab88c952017-02-14 13:22:54 +0200382 sched_yield();
Igor Opaniukf1f3fd02017-09-14 15:34:56 +0300383 } else {
384 ERROR_GOTO(deinit_yaml,
Igor Opaniuk55fcc4a2018-02-06 19:20:22 +0200385 "No new data in the per-cpu ringbuffers"
386 );
Igor Opaniukf1f3fd02017-09-14 15:34:56 +0300387 }
Yves Leflochb31789d2017-08-01 14:51:18 +0200388 }
Igor Opaniukab88c952017-02-14 13:22:54 +0200389 }
390
Igor Opaniukf1f3fd02017-09-14 15:34:56 +0300391deinit_yaml:
392 deinit_emitter();
Igor Opaniukab88c952017-02-14 13:22:54 +0200393file_close:
394 fclose(ts_file);
395exit:
396 return NULL;
397}
398
399int main(int argc, char *argv[])
400{
401 int i;
402 int status;
403 pid_t pid;
404 char testapp_path[PATH_MAX];
405 char **testapp_argv;
406 char *res;
407 char *tsfile_path;
408 uint32_t cores;
409 pthread_t consumer_thread;
Igor Opaniuk3d566ae2018-01-29 02:41:33 +0200410 struct consumer_param prm;
Igor Opaniukab88c952017-02-14 13:22:54 +0200411
412 if (argc == 1) {
413 usage(argv[0]);
414 return 0;
415 }
416
417 /* Parse command line */
418 for (i = 1; i < argc; i++) {
419 if (!strcmp(argv[i], "-h")) {
420 usage(argv[0]);
421 return 0;
422 }
423 }
424
Igor Opaniukf1f3fd02017-09-14 15:34:56 +0300425 signal(SIGINT, sigint_handler);
426
427 INFO("1. Opening Benchmark Static TA...");
Igor Opaniukab88c952017-02-14 13:22:54 +0200428 open_bench_pta();
429
430 cores = get_cores();
431 if (!cores)
Igor Opaniukf1f3fd02017-09-14 15:34:56 +0300432 ERROR_EXIT("Receiving amount of active cores failed");
Igor Opaniukab88c952017-02-14 13:22:54 +0200433
Igor Opaniukf1f3fd02017-09-14 15:34:56 +0300434 INFO("2. Allocating per-core buffers, cores detected = %d",
Igor Opaniukab88c952017-02-14 13:22:54 +0200435 cores);
Igor Opaniuk55fcc4a2018-02-06 19:20:22 +0200436 alloc_bench_buf(cores);
Igor Opaniukab88c952017-02-14 13:22:54 +0200437
438 res = realpath(argv[1], testapp_path);
439 if (!res)
440 tee_errx("Failed to get realpath", EXIT_FAILURE);
441
442 alloc_argv(argc, argv, &testapp_argv);
443
Igor Opaniukf1f3fd02017-09-14 15:34:56 +0300444 INFO("3. Starting origin host app %s ...", testapp_path);
Igor Opaniukab88c952017-02-14 13:22:54 +0200445
446 /* fork/exec here */
447 pid = fork();
448
449 if (pid == -1) {
Igor Opaniukf1f3fd02017-09-14 15:34:56 +0300450 DBG("fork() failed");
451 ERROR_EXIT("Starting origin host application failed.");
Igor Opaniukab88c952017-02-14 13:22:54 +0200452 } else if (pid > 0) {
453 is_running = 1;
Igor Opaniukab88c952017-02-14 13:22:54 +0200454 tsfile_path = malloc(strlen(testapp_path) +
455 strlen(TSFILE_NAME_SUFFIX) + 1);
456 if (!tsfile_path)
Igor Opaniuk66e23bf2018-02-06 19:18:59 +0200457 ERROR_EXIT("Memory allocation failed the file path.");
Igor Opaniukab88c952017-02-14 13:22:54 +0200458
459 tsfile_path[0] = '\0';
460 strcat(tsfile_path, testapp_path);
461 strcat(tsfile_path, TSFILE_NAME_SUFFIX);
462
Igor Opaniukf1f3fd02017-09-14 15:34:56 +0300463 INFO("Dumping timestamps to %s ...", tsfile_path);
Igor Opaniukab88c952017-02-14 13:22:54 +0200464 print_line();
465
Igor Opaniuk3d566ae2018-01-29 02:41:33 +0200466 prm.child_pid = pid;
467 prm.ts_filepath = tsfile_path;
468
Igor Opaniukab88c952017-02-14 13:22:54 +0200469 if (pthread_create(&consumer_thread, NULL,
Igor Opaniuk3d566ae2018-01-29 02:41:33 +0200470 ts_consumer, &prm)) {
Igor Opaniukf1f3fd02017-09-14 15:34:56 +0300471 DBG( "Error creating ts consumer thread");
472 ERROR_EXIT("Can't start process of reading timestamps");
Igor Opaniukab88c952017-02-14 13:22:54 +0200473 }
474 /* wait for child app exits */
475 waitpid(pid, &status, 0);
476 is_running = 0;
477
478 /* wait for our consumer thread terminate */
479 if (pthread_join(consumer_thread, NULL)) {
Igor Opaniukf1f3fd02017-09-14 15:34:56 +0300480 DBG("Error joining thread");
Igor Opaniuk66e23bf2018-02-06 19:18:59 +0200481 ERROR_EXIT("Couldn't start consuming timestamps");
Igor Opaniukab88c952017-02-14 13:22:54 +0200482 }
483 }
484 else {
485 execvp(testapp_path, testapp_argv);
Igor Opaniukf1f3fd02017-09-14 15:34:56 +0300486 DBG("execve() failed");
487 ERROR_EXIT("Starting origin host application failed");
Igor Opaniukab88c952017-02-14 13:22:54 +0200488 }
489
Igor Opaniukf1f3fd02017-09-14 15:34:56 +0300490 INFO("4. Done benchmark");
Igor Opaniukab88c952017-02-14 13:22:54 +0200491
492 dealloc_argv(argc-1, testapp_argv);
Igor Opaniuk55fcc4a2018-02-06 19:20:22 +0200493 free_bench_buf();
Igor Opaniukab88c952017-02-14 13:22:54 +0200494 close_bench_pta();
495 return 0;
496}