service: allow to disable core check
[dpdk.git] / lib / librte_eal / common / rte_service.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2017 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #include <stdio.h>
35 #include <unistd.h>
36 #include <inttypes.h>
37 #include <limits.h>
38 #include <string.h>
39 #include <dirent.h>
40
41 #include <rte_service.h>
42 #include "include/rte_service_component.h"
43
44 #include <rte_eal.h>
45 #include <rte_lcore.h>
46 #include <rte_common.h>
47 #include <rte_debug.h>
48 #include <rte_cycles.h>
49 #include <rte_atomic.h>
50 #include <rte_memory.h>
51 #include <rte_malloc.h>
52
53 #define RTE_SERVICE_NUM_MAX 64
54
55 #define SERVICE_F_REGISTERED    (1 << 0)
56 #define SERVICE_F_STATS_ENABLED (1 << 1)
57 #define SERVICE_F_START_CHECK   (1 << 2)
58
59 /* runstates for services and lcores, denoting if they are active or not */
60 #define RUNSTATE_STOPPED 0
61 #define RUNSTATE_RUNNING 1
62
63 /* internal representation of a service */
64 struct rte_service_spec_impl {
65         /* public part of the struct */
66         struct rte_service_spec spec;
67
68         /* atomic lock that when set indicates a service core is currently
69          * running this service callback. When not set, a core may take the
70          * lock and then run the service callback.
71          */
72         rte_atomic32_t execute_lock;
73
74         /* API set/get-able variables */
75         int8_t app_runstate;
76         int8_t comp_runstate;
77         uint8_t internal_flags;
78
79         /* per service statistics */
80         uint32_t num_mapped_cores;
81         uint64_t calls;
82         uint64_t cycles_spent;
83 } __rte_cache_aligned;
84
85 /* the internal values of a service core */
86 struct core_state {
87         /* map of services IDs are run on this core */
88         uint64_t service_mask;
89         uint8_t runstate; /* running or stopped */
90         uint8_t is_service_core; /* set if core is currently a service core */
91
92         /* extreme statistics */
93         uint64_t calls_per_service[RTE_SERVICE_NUM_MAX];
94 } __rte_cache_aligned;
95
96 static uint32_t rte_service_count;
97 static struct rte_service_spec_impl *rte_services;
98 static struct core_state *lcore_states;
99 static uint32_t rte_service_library_initialized;
100
101 int32_t rte_service_init(void)
102 {
103         if (rte_service_library_initialized) {
104                 printf("service library init() called, init flag %d\n",
105                         rte_service_library_initialized);
106                 return -EALREADY;
107         }
108
109         rte_services = rte_calloc("rte_services", RTE_SERVICE_NUM_MAX,
110                         sizeof(struct rte_service_spec_impl),
111                         RTE_CACHE_LINE_SIZE);
112         if (!rte_services) {
113                 printf("error allocating rte services array\n");
114                 return -ENOMEM;
115         }
116
117         lcore_states = rte_calloc("rte_service_core_states", RTE_MAX_LCORE,
118                         sizeof(struct core_state), RTE_CACHE_LINE_SIZE);
119         if (!lcore_states) {
120                 printf("error allocating core states array\n");
121                 return -ENOMEM;
122         }
123
124         int i;
125         int count = 0;
126         struct rte_config *cfg = rte_eal_get_configuration();
127         for (i = 0; i < RTE_MAX_LCORE; i++) {
128                 if (lcore_config[i].core_role == ROLE_SERVICE) {
129                         if ((unsigned int)i == cfg->master_lcore)
130                                 continue;
131                         rte_service_lcore_add(i);
132                         count++;
133                 }
134         }
135
136         rte_service_library_initialized = 1;
137         return 0;
138 }
139
140 /* returns 1 if service is registered and has not been unregistered
141  * Returns 0 if service never registered, or has been unregistered
142  */
143 static inline int
144 service_valid(uint32_t id)
145 {
146         return !!(rte_services[id].internal_flags & SERVICE_F_REGISTERED);
147 }
148
149 /* validate ID and retrieve service pointer, or return error value */
150 #define SERVICE_VALID_GET_OR_ERR_RET(id, service, retval) do {          \
151         if (id >= RTE_SERVICE_NUM_MAX || !service_valid(id))            \
152                 return retval;                                          \
153         service = &rte_services[id];                                    \
154 } while (0)
155
156 /* returns 1 if statistics should be colleced for service
157  * Returns 0 if statistics should not be collected for service
158  */
159 static inline int
160 service_stats_enabled(struct rte_service_spec_impl *impl)
161 {
162         return !!(impl->internal_flags & SERVICE_F_STATS_ENABLED);
163 }
164
165 static inline int
166 service_mt_safe(struct rte_service_spec_impl *s)
167 {
168         return !!(s->spec.capabilities & RTE_SERVICE_CAP_MT_SAFE);
169 }
170
171 int32_t rte_service_set_stats_enable(uint32_t id, int32_t enabled)
172 {
173         struct rte_service_spec_impl *s;
174         SERVICE_VALID_GET_OR_ERR_RET(id, s, 0);
175
176         if (enabled)
177                 s->internal_flags |= SERVICE_F_STATS_ENABLED;
178         else
179                 s->internal_flags &= ~(SERVICE_F_STATS_ENABLED);
180
181         return 0;
182 }
183
184 int32_t rte_service_set_runstate_mapped_check(uint32_t id, int32_t enabled)
185 {
186         struct rte_service_spec_impl *s;
187         SERVICE_VALID_GET_OR_ERR_RET(id, s, 0);
188
189         if (enabled)
190                 s->internal_flags |= SERVICE_F_START_CHECK;
191         else
192                 s->internal_flags &= ~(SERVICE_F_START_CHECK);
193
194         return 0;
195 }
196
197 uint32_t
198 rte_service_get_count(void)
199 {
200         return rte_service_count;
201 }
202
203 int32_t rte_service_get_by_name(const char *name, uint32_t *service_id)
204 {
205         if (!service_id)
206                 return -EINVAL;
207
208         int i;
209         for (i = 0; i < RTE_SERVICE_NUM_MAX; i++) {
210                 if (service_valid(i) &&
211                                 strcmp(name, rte_services[i].spec.name) == 0) {
212                         *service_id = i;
213                         return 0;
214                 }
215         }
216
217         return -ENODEV;
218 }
219
220 const char *
221 rte_service_get_name(uint32_t id)
222 {
223         struct rte_service_spec_impl *s;
224         SERVICE_VALID_GET_OR_ERR_RET(id, s, 0);
225         return s->spec.name;
226 }
227
228 int32_t
229 rte_service_probe_capability(uint32_t id, uint32_t capability)
230 {
231         struct rte_service_spec_impl *s;
232         SERVICE_VALID_GET_OR_ERR_RET(id, s, -EINVAL);
233         return !!(s->spec.capabilities & capability);
234 }
235
236 int32_t
237 rte_service_component_register(const struct rte_service_spec *spec,
238                                uint32_t *id_ptr)
239 {
240         uint32_t i;
241         int32_t free_slot = -1;
242
243         if (spec->callback == NULL || strlen(spec->name) == 0)
244                 return -EINVAL;
245
246         for (i = 0; i < RTE_SERVICE_NUM_MAX; i++) {
247                 if (!service_valid(i)) {
248                         free_slot = i;
249                         break;
250                 }
251         }
252
253         if ((free_slot < 0) || (i == RTE_SERVICE_NUM_MAX))
254                 return -ENOSPC;
255
256         struct rte_service_spec_impl *s = &rte_services[free_slot];
257         s->spec = *spec;
258         s->internal_flags |= SERVICE_F_REGISTERED | SERVICE_F_START_CHECK;
259
260         rte_smp_wmb();
261         rte_service_count++;
262
263         if (id_ptr)
264                 *id_ptr = free_slot;
265
266         return 0;
267 }
268
269 int32_t
270 rte_service_component_unregister(uint32_t id)
271 {
272         uint32_t i;
273         struct rte_service_spec_impl *s;
274         SERVICE_VALID_GET_OR_ERR_RET(id, s, -EINVAL);
275
276         rte_service_count--;
277         rte_smp_wmb();
278
279         s->internal_flags &= ~(SERVICE_F_REGISTERED);
280
281         /* clear the run-bit in all cores */
282         for (i = 0; i < RTE_MAX_LCORE; i++)
283                 lcore_states[i].service_mask &= ~(UINT64_C(1) << id);
284
285         memset(&rte_services[id], 0, sizeof(struct rte_service_spec_impl));
286
287         return 0;
288 }
289
290 int32_t
291 rte_service_component_runstate_set(uint32_t id, uint32_t runstate)
292 {
293         struct rte_service_spec_impl *s;
294         SERVICE_VALID_GET_OR_ERR_RET(id, s, -EINVAL);
295
296         if (runstate)
297                 s->comp_runstate = RUNSTATE_RUNNING;
298         else
299                 s->comp_runstate = RUNSTATE_STOPPED;
300
301         rte_smp_wmb();
302         return 0;
303 }
304
305 int32_t
306 rte_service_runstate_set(uint32_t id, uint32_t runstate)
307 {
308         struct rte_service_spec_impl *s;
309         SERVICE_VALID_GET_OR_ERR_RET(id, s, -EINVAL);
310
311         if (runstate)
312                 s->app_runstate = RUNSTATE_RUNNING;
313         else
314                 s->app_runstate = RUNSTATE_STOPPED;
315
316         rte_smp_wmb();
317         return 0;
318 }
319
320 int32_t
321 rte_service_runstate_get(uint32_t id)
322 {
323         struct rte_service_spec_impl *s;
324         SERVICE_VALID_GET_OR_ERR_RET(id, s, -EINVAL);
325         rte_smp_rmb();
326
327         int check_disabled = !(s->internal_flags & SERVICE_F_START_CHECK);
328         int lcore_mapped = (s->num_mapped_cores > 0);
329
330         return (s->app_runstate == RUNSTATE_RUNNING) &&
331                 (s->comp_runstate == RUNSTATE_RUNNING) &&
332                 (check_disabled | lcore_mapped);
333 }
334
335 static inline void
336 rte_service_runner_do_callback(struct rte_service_spec_impl *s,
337                                struct core_state *cs, uint32_t service_idx)
338 {
339         void *userdata = s->spec.callback_userdata;
340
341         if (service_stats_enabled(s)) {
342                 uint64_t start = rte_rdtsc();
343                 s->spec.callback(userdata);
344                 uint64_t end = rte_rdtsc();
345                 s->cycles_spent += end - start;
346                 cs->calls_per_service[service_idx]++;
347                 s->calls++;
348         } else
349                 s->spec.callback(userdata);
350 }
351
352
353 static inline int32_t
354 service_run(uint32_t i, struct core_state *cs, uint64_t service_mask)
355 {
356         if (!service_valid(i))
357                 return -EINVAL;
358         struct rte_service_spec_impl *s = &rte_services[i];
359         if (s->comp_runstate != RUNSTATE_RUNNING ||
360                         s->app_runstate != RUNSTATE_RUNNING ||
361                         !(service_mask & (UINT64_C(1) << i)))
362                 return -ENOEXEC;
363
364         /* check do we need cmpset, if MT safe or <= 1 core
365          * mapped, atomic ops are not required.
366          */
367         const int use_atomics = (service_mt_safe(s) == 0) &&
368                                 (s->num_mapped_cores > 1);
369         if (use_atomics) {
370                 if (!rte_atomic32_cmpset((uint32_t *)&s->execute_lock, 0, 1))
371                         return -EBUSY;
372
373                 rte_service_runner_do_callback(s, cs, i);
374                 rte_atomic32_clear(&s->execute_lock);
375         } else
376                 rte_service_runner_do_callback(s, cs, i);
377
378         return 0;
379 }
380
381 int32_t rte_service_run_iter_on_app_lcore(uint32_t id)
382 {
383         /* run service on calling core, using all-ones as the service mask */
384         struct core_state *cs = &lcore_states[rte_lcore_id()];
385         return service_run(id, cs, UINT64_MAX);
386 }
387
388 static int32_t
389 rte_service_runner_func(void *arg)
390 {
391         RTE_SET_USED(arg);
392         uint32_t i;
393         const int lcore = rte_lcore_id();
394         struct core_state *cs = &lcore_states[lcore];
395
396         while (lcore_states[lcore].runstate == RUNSTATE_RUNNING) {
397                 const uint64_t service_mask = cs->service_mask;
398
399                 for (i = 0; i < RTE_SERVICE_NUM_MAX; i++) {
400                         /* return value ignored as no change to code flow */
401                         service_run(i, cs, service_mask);
402                 }
403
404                 rte_smp_rmb();
405         }
406
407         lcore_config[lcore].state = WAIT;
408
409         return 0;
410 }
411
412 int32_t
413 rte_service_lcore_count(void)
414 {
415         int32_t count = 0;
416         uint32_t i;
417         for (i = 0; i < RTE_MAX_LCORE; i++)
418                 count += lcore_states[i].is_service_core;
419         return count;
420 }
421
422 int32_t
423 rte_service_lcore_list(uint32_t array[], uint32_t n)
424 {
425         uint32_t count = rte_service_lcore_count();
426         if (count > n)
427                 return -ENOMEM;
428
429         if (!array)
430                 return -EINVAL;
431
432         uint32_t i;
433         uint32_t idx = 0;
434         for (i = 0; i < RTE_MAX_LCORE; i++) {
435                 struct core_state *cs = &lcore_states[i];
436                 if (cs->is_service_core) {
437                         array[idx] = i;
438                         idx++;
439                 }
440         }
441
442         return count;
443 }
444
445 int32_t
446 rte_service_lcore_count_services(uint32_t lcore)
447 {
448         if (lcore >= RTE_MAX_LCORE)
449                 return -EINVAL;
450
451         struct core_state *cs = &lcore_states[lcore];
452         if (!cs->is_service_core)
453                 return -ENOTSUP;
454
455         return __builtin_popcountll(cs->service_mask);
456 }
457
458 int32_t
459 rte_service_start_with_defaults(void)
460 {
461         /* create a default mapping from cores to services, then start the
462          * services to make them transparent to unaware applications.
463          */
464         uint32_t i;
465         int ret;
466         uint32_t count = rte_service_get_count();
467
468         int32_t lcore_iter = 0;
469         uint32_t ids[RTE_MAX_LCORE] = {0};
470         int32_t lcore_count = rte_service_lcore_list(ids, RTE_MAX_LCORE);
471
472         if (lcore_count == 0)
473                 return -ENOTSUP;
474
475         for (i = 0; (int)i < lcore_count; i++)
476                 rte_service_lcore_start(ids[i]);
477
478         for (i = 0; i < count; i++) {
479                 /* do 1:1 core mapping here, with each service getting
480                  * assigned a single core by default. Adding multiple services
481                  * should multiplex to a single core, or 1:1 if there are the
482                  * same amount of services as service-cores
483                  */
484                 ret = rte_service_map_lcore_set(i, ids[lcore_iter], 1);
485                 if (ret)
486                         return -ENODEV;
487
488                 lcore_iter++;
489                 if (lcore_iter >= lcore_count)
490                         lcore_iter = 0;
491
492                 ret = rte_service_runstate_set(i, 1);
493                 if (ret)
494                         return -ENOEXEC;
495         }
496
497         return 0;
498 }
499
500 static int32_t
501 service_update(struct rte_service_spec *service, uint32_t lcore,
502                 uint32_t *set, uint32_t *enabled)
503 {
504         uint32_t i;
505         int32_t sid = -1;
506
507         for (i = 0; i < RTE_SERVICE_NUM_MAX; i++) {
508                 if ((struct rte_service_spec *)&rte_services[i] == service &&
509                                 service_valid(i)) {
510                         sid = i;
511                         break;
512                 }
513         }
514
515         if (sid == -1 || lcore >= RTE_MAX_LCORE)
516                 return -EINVAL;
517
518         if (!lcore_states[lcore].is_service_core)
519                 return -EINVAL;
520
521         uint64_t sid_mask = UINT64_C(1) << sid;
522         if (set) {
523                 if (*set) {
524                         lcore_states[lcore].service_mask |= sid_mask;
525                         rte_services[sid].num_mapped_cores++;
526                 } else {
527                         lcore_states[lcore].service_mask &= ~(sid_mask);
528                         rte_services[sid].num_mapped_cores--;
529                 }
530         }
531
532         if (enabled)
533                 *enabled = !!(lcore_states[lcore].service_mask & (sid_mask));
534
535         rte_smp_wmb();
536
537         return 0;
538 }
539
540 int32_t
541 rte_service_map_lcore_set(uint32_t id, uint32_t lcore, uint32_t enabled)
542 {
543         struct rte_service_spec_impl *s;
544         SERVICE_VALID_GET_OR_ERR_RET(id, s, -EINVAL);
545         uint32_t on = enabled > 0;
546         return service_update(&s->spec, lcore, &on, 0);
547 }
548
549 int32_t
550 rte_service_map_lcore_get(uint32_t id, uint32_t lcore)
551 {
552         struct rte_service_spec_impl *s;
553         SERVICE_VALID_GET_OR_ERR_RET(id, s, -EINVAL);
554         uint32_t enabled;
555         int ret = service_update(&s->spec, lcore, 0, &enabled);
556         if (ret == 0)
557                 return enabled;
558         return ret;
559 }
560
561 int32_t rte_service_lcore_reset_all(void)
562 {
563         /* loop over cores, reset all to mask 0 */
564         uint32_t i;
565         for (i = 0; i < RTE_MAX_LCORE; i++) {
566                 lcore_states[i].service_mask = 0;
567                 lcore_states[i].is_service_core = 0;
568                 lcore_states[i].runstate = RUNSTATE_STOPPED;
569         }
570         for (i = 0; i < RTE_SERVICE_NUM_MAX; i++)
571                 rte_services[i].num_mapped_cores = 0;
572
573         rte_smp_wmb();
574
575         return 0;
576 }
577
578 static void
579 set_lcore_state(uint32_t lcore, int32_t state)
580 {
581         /* mark core state in hugepage backed config */
582         struct rte_config *cfg = rte_eal_get_configuration();
583         cfg->lcore_role[lcore] = state;
584
585         /* mark state in process local lcore_config */
586         lcore_config[lcore].core_role = state;
587
588         /* update per-lcore optimized state tracking */
589         lcore_states[lcore].is_service_core = (state == ROLE_SERVICE);
590 }
591
592 int32_t
593 rte_service_lcore_add(uint32_t lcore)
594 {
595         if (lcore >= RTE_MAX_LCORE)
596                 return -EINVAL;
597         if (lcore_states[lcore].is_service_core)
598                 return -EALREADY;
599
600         set_lcore_state(lcore, ROLE_SERVICE);
601
602         /* ensure that after adding a core the mask and state are defaults */
603         lcore_states[lcore].service_mask = 0;
604         lcore_states[lcore].runstate = RUNSTATE_STOPPED;
605
606         rte_smp_wmb();
607
608         return rte_eal_wait_lcore(lcore);
609 }
610
611 int32_t
612 rte_service_lcore_del(uint32_t lcore)
613 {
614         if (lcore >= RTE_MAX_LCORE)
615                 return -EINVAL;
616
617         struct core_state *cs = &lcore_states[lcore];
618         if (!cs->is_service_core)
619                 return -EINVAL;
620
621         if (cs->runstate != RUNSTATE_STOPPED)
622                 return -EBUSY;
623
624         set_lcore_state(lcore, ROLE_RTE);
625
626         rte_smp_wmb();
627         return 0;
628 }
629
630 int32_t
631 rte_service_lcore_start(uint32_t lcore)
632 {
633         if (lcore >= RTE_MAX_LCORE)
634                 return -EINVAL;
635
636         struct core_state *cs = &lcore_states[lcore];
637         if (!cs->is_service_core)
638                 return -EINVAL;
639
640         if (cs->runstate == RUNSTATE_RUNNING)
641                 return -EALREADY;
642
643         /* set core to run state first, and then launch otherwise it will
644          * return immediately as runstate keeps it in the service poll loop
645          */
646         lcore_states[lcore].runstate = RUNSTATE_RUNNING;
647
648         int ret = rte_eal_remote_launch(rte_service_runner_func, 0, lcore);
649         /* returns -EBUSY if the core is already launched, 0 on success */
650         return ret;
651 }
652
653 int32_t
654 rte_service_lcore_stop(uint32_t lcore)
655 {
656         if (lcore >= RTE_MAX_LCORE)
657                 return -EINVAL;
658
659         if (lcore_states[lcore].runstate == RUNSTATE_STOPPED)
660                 return -EALREADY;
661
662         uint32_t i;
663         uint64_t service_mask = lcore_states[lcore].service_mask;
664         for (i = 0; i < RTE_SERVICE_NUM_MAX; i++) {
665                 int32_t enabled = service_mask & (UINT64_C(1) << i);
666                 int32_t service_running = rte_service_runstate_get(i);
667                 int32_t only_core = rte_services[i].num_mapped_cores == 1;
668
669                 /* if the core is mapped, and the service is running, and this
670                  * is the only core that is mapped, the service would cease to
671                  * run if this core stopped, so fail instead.
672                  */
673                 if (enabled && service_running && only_core)
674                         return -EBUSY;
675         }
676
677         lcore_states[lcore].runstate = RUNSTATE_STOPPED;
678
679         return 0;
680 }
681
682 static void
683 rte_service_dump_one(FILE *f, struct rte_service_spec_impl *s,
684                      uint64_t all_cycles, uint32_t reset)
685 {
686         /* avoid divide by zero */
687         if (all_cycles == 0)
688                 all_cycles = 1;
689
690         int calls = 1;
691         if (s->calls != 0)
692                 calls = s->calls;
693
694         fprintf(f, "  %s: stats %d\tcalls %"PRIu64"\tcycles %"
695                         PRIu64"\tavg: %"PRIu64"\n",
696                         s->spec.name, service_stats_enabled(s), s->calls,
697                         s->cycles_spent, s->cycles_spent / calls);
698
699         if (reset) {
700                 s->cycles_spent = 0;
701                 s->calls = 0;
702         }
703 }
704
705 static void
706 service_dump_calls_per_lcore(FILE *f, uint32_t lcore, uint32_t reset)
707 {
708         uint32_t i;
709         struct core_state *cs = &lcore_states[lcore];
710
711         fprintf(f, "%02d\t", lcore);
712         for (i = 0; i < RTE_SERVICE_NUM_MAX; i++) {
713                 if (!service_valid(i))
714                         continue;
715                 fprintf(f, "%"PRIu64"\t", cs->calls_per_service[i]);
716                 if (reset)
717                         cs->calls_per_service[i] = 0;
718         }
719         fprintf(f, "\n");
720 }
721
722 int32_t rte_service_dump(FILE *f, uint32_t id)
723 {
724         uint32_t i;
725         int print_one = (id != UINT32_MAX);
726
727         uint64_t total_cycles = 0;
728
729         for (i = 0; i < RTE_SERVICE_NUM_MAX; i++) {
730                 if (!service_valid(i))
731                         continue;
732                 total_cycles += rte_services[i].cycles_spent;
733         }
734
735         /* print only the specified service */
736         if (print_one) {
737                 struct rte_service_spec_impl *s;
738                 SERVICE_VALID_GET_OR_ERR_RET(id, s, -EINVAL);
739                 fprintf(f, "Service %s Summary\n", s->spec.name);
740                 uint32_t reset = 0;
741                 rte_service_dump_one(f, s, total_cycles, reset);
742                 return 0;
743         }
744
745         /* print all services, as UINT32_MAX was passed as id */
746         fprintf(f, "Services Summary\n");
747         for (i = 0; i < RTE_SERVICE_NUM_MAX; i++) {
748                 if (!service_valid(i))
749                         continue;
750                 uint32_t reset = 1;
751                 rte_service_dump_one(f, &rte_services[i], total_cycles, reset);
752         }
753
754         fprintf(f, "Service Cores Summary\n");
755         for (i = 0; i < RTE_MAX_LCORE; i++) {
756                 if (lcore_config[i].core_role != ROLE_SERVICE)
757                         continue;
758
759                 uint32_t reset = 1;
760                 service_dump_calls_per_lcore(f, i, reset);
761         }
762
763         return 0;
764 }