Debian Codegraph @

src/workload.c

raw symbols SCIP
1 // SPDX-License-Identifier: BSD-2-Clausecxx . . $ `<file>/src/workload.c`/
2 /*
3 * Copyright (c) 2025 Intel Corporation
4 */
5 #include "workload.h"cxx . . $ `<file>/src/workload.h`/
6 #include "stat.h"cxx . . $ `<file>/src/stat.h`/
7 #include <dlfcn.h>
8
9 /*
10 * Parse input for arguments store them in argc for count and argv for vector
11 * of arguments.
12 */
13 void string_to_argc_argvcxx . . $ string_to_argc_argv(67bbcfbfaaba5559).(const char *input, int *argc, char ***argv)
14 {
15 char *token;
16 int count = 1;
17 char *temp_input = strdupcxx . . $ strdup(a8b8e32347182212).(input); /* Duplicate to avoid modifying original */
18
19 /* First pass: count the number of arguments */
20 token = strtokcxx . . $ strtok(b7b3a83273496486).(temp_input, " ");
21 while (token != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
22 count++;
23 token = strtokcxx . . $ strtok(b7b3a83273496486).(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, " ");
24 }
25
26 /* Allocate memory for argv array */
27 *argv = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(count * sizeof(char *));
28 if (*argv == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
29 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Memory allocation failed\n");
30 exitcxx . . $ exit(3ca292c338df9bb3).(1);
31 }
32
33 /* Second pass: populate argv */
34 strcpycxx . . $ strcpy(b7b3a83273496486).(temp_input, input); /* Reset temp_input with original input */
35 int i = 1;
36 token = strtokcxx . . $ strtok(b7b3a83273496486).(temp_input, " ");
37 while (token != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
38 (*argv)[i++] = strdupcxx . . $ strdup(a8b8e32347182212).(token); /* Duplicate token and assign */
39 token = strtokcxx . . $ strtok(b7b3a83273496486).(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, " ");
40 }
41 (*argv)[0] = strdupcxx . . $ strdup(a8b8e32347182212).("Workload");
42
43 *argc = count; /* Set argc to the number of arguments */
44 freecxx . . $ free(5d22bdacc48458e8).(temp_input); /* Free the temporary input string */
45 }
46
47 void *workload_thread_routinecxx . . $ workload_thread_routine(9f162e79bfc6c74).(void *data)
48 {
49 struct thread_contextcxx . . $ thread_context# *thread_context = data;
50 struct workload_configcxx . . $ workload_config# *wl_cfg = thread_context->workloadcxx . . $ thread_context#workload.;
51 struct timespeccxx . . $ timespec# start_ts, timeout;
52
53 pthread_mutex_lockcxx . . $ pthread_mutex_lock(d89ae235521888f9).(&wl_cfg->workload_mutexcxx . . $ workload_config#workload_mutex.);
54 /* Run until we are ready to stop */
55 while (!thread_context->stopcxx . . $ thread_context#stop.) {
56 clock_gettimecxx . . $ clock_gettime(65aaefb2502b4987).(app_configcxx . . $ app_config..application_clock_idcxx . . $ application_config#application_clock_id., &start_ts);
57 timeout = start_ts;
58 timeout.tv_seccxx . . $ timespec#tv_sec.++;
59 /* Check for spurious wakeups */
60 if (wl_cfg->workload_runcxx . . $ workload_config#workload_run.) {
61 wl_cfg->workload_functioncxx . . $ workload_config#workload_function.(wl_cfg->workload_argccxx . . $ workload_config#workload_argc., wl_cfg->workload_argvcxx . . $ workload_config#workload_argv.);
62 wl_cfg->workload_donecxx . . $ workload_config#workload_done. = 1;
63 wl_cfg->workload_runcxx . . $ workload_config#workload_run. = 0;
64 stat_frame_workloadcxx . . $ stat_frame_workload(de8748302dcb85c).(wl_cfg->associated_framecxx . . $ workload_config#associated_frame.,
65 wl_cfg->workload_sequence_countercxx . . $ workload_config#workload_sequence_counter., start_ts);
66 wl_cfg->workload_sequence_countercxx . . $ workload_config#workload_sequence_counter.++;
67 }
68 pthread_cond_timedwaitcxx . . $ pthread_cond_timedwait(d8fcb9edac03ad51).(&wl_cfg->workload_condcxx . . $ workload_config#workload_cond., &wl_cfg->workload_mutexcxx . . $ workload_config#workload_mutex., &timeout);
69 }
70 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
71 }
72
73 void workload_context_initcxx . . $ workload_context_init(40f8e18c2538f155).(struct thread_contextcxx . . $ thread_context# *thread_context, char *workload_file,
74 char *workload_function, char *workload_arguments,
75 char *workload_setup_function, char *workload_setup_arguments,
76 enum stat_frame_typecxx . . $ stat_frame_type# frame_type)
77 {
78 struct workload_configcxx . . $ workload_config# *wl_cfg = thread_context->workloadcxx . . $ thread_context#workload.;
79 char *error;
80
81 wl_cfg->workload_handlercxx . . $ workload_config#workload_handler. = dlopencxx . . $ dlopen(fb9ec0bb113f3da8).(workload_file, RTLD_NOWcxx . . $ `<external>/10632388298615623587/dlfcn.h:25:9`! | RTLD_GLOBALcxx . . $ `<external>/10632388298615623587/dlfcn.h:33:9`!);
82
83 if (!wl_cfg->workload_handlercxx . . $ workload_config#workload_handler.) {
84 error = dlerrorcxx . . $ dlerror(41208ce6ca65dd58).();
85 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Error: Unable to open workload: %s. %s\n", workload_file, error);
86 exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!);
87 }
88
89 if (workload_setup_function != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
90 wl_cfg->workload_setup_functioncxx . . $ workload_config#workload_setup_function. =
91 dlsymcxx . . $ dlsym(5c3a2d84d269ab4b).(wl_cfg->workload_handlercxx . . $ workload_config#workload_handler., workload_setup_function);
92 if (!wl_cfg->workload_setup_functioncxx . . $ workload_config#workload_setup_function.) {
93 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Error: Unable to find setup function: %s\n",
94 workload_setup_function);
95 exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!);
96 }
97 }
98
99 wl_cfg->workload_functioncxx . . $ workload_config#workload_function. = dlsymcxx . . $ dlsym(5c3a2d84d269ab4b).(wl_cfg->workload_handlercxx . . $ workload_config#workload_handler., workload_function);
100 if (!wl_cfg->workload_functioncxx . . $ workload_config#workload_function.) {
101 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Error: Unable to find function: %s\n", workload_function);
102 exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!);
103 }
104
105 if (workload_arguments != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
106 string_to_argc_argvcxx . . $ string_to_argc_argv(67bbcfbfaaba5559).(workload_arguments, &(wl_cfg->workload_argccxx . . $ workload_config#workload_argc.),
107 &(wl_cfg->workload_argvcxx . . $ workload_config#workload_argv.));
108 } else {
109 wl_cfg->workload_argccxx . . $ workload_config#workload_argc. = 0;
110 wl_cfg->workload_argvcxx . . $ workload_config#workload_argv. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
111 }
112
113 if (workload_setup_arguments != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
114 string_to_argc_argvcxx . . $ string_to_argc_argv(67bbcfbfaaba5559).(workload_setup_arguments, &(wl_cfg->workload_setup_argccxx . . $ workload_config#workload_setup_argc.),
115 &(wl_cfg->workload_setup_argvcxx . . $ workload_config#workload_setup_argv.));
116 } else {
117 wl_cfg->workload_setup_argccxx . . $ workload_config#workload_setup_argc. = 0;
118 wl_cfg->workload_setup_argvcxx . . $ workload_config#workload_setup_argv. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
119 }
120
121 pthread_mutex_initcxx . . $ pthread_mutex_init(db9d29dab44ea1aa).(&wl_cfg->workload_mutexcxx . . $ workload_config#workload_mutex., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
122 pthread_cond_initcxx . . $ pthread_cond_init(fc876bc1ec1249fc).(&wl_cfg->workload_condcxx . . $ workload_config#workload_cond., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
123
124 wl_cfg->associated_framecxx . . $ workload_config#associated_frame. = frame_type;
125
126 /* Call the setup function if it exists */
127 if (wl_cfg->workload_setup_functioncxx . . $ workload_config#workload_setup_function. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
128 wl_cfg->workload_setup_functioncxx . . $ workload_config#workload_setup_function.(wl_cfg->workload_setup_argccxx . . $ workload_config#workload_setup_argc.,
129 wl_cfg->workload_setup_argvcxx . . $ workload_config#workload_setup_argv.);
130 }
131 }
132
133 void workload_thread_freecxx . . $ workload_thread_free(f7c2ab51214b7176).(struct thread_contextcxx . . $ thread_context# *thread_context)
134 {
135 if (!thread_context)
136 return;
137 dlclosecxx . . $ dlclose(dedf1e9b1c614a07).(thread_context->workloadcxx . . $ thread_context#workload.->workload_handlercxx . . $ workload_config#workload_handler.);
138 freecxx . . $ free(5d22bdacc48458e8).(thread_context->workloadcxx . . $ thread_context#workload.);
139 }
140
141 void workload_thread_wait_for_finishcxx . . $ workload_thread_wait_for_finish(f7c2ab51214b7176).(struct thread_contextcxx . . $ thread_context# *thread_context)
142 {
143 thread_context->stopcxx . . $ thread_context#stop. = 1;
144 if (!thread_context)
145 return;
146
147 pthread_joincxx . . $ pthread_join(269902cf949f12c5).(thread_context->workloadcxx . . $ thread_context#workload.->workload_task_idcxx . . $ workload_config#workload_task_id., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
148 }