EM-ODP  3.7.0
Event Machine on ODP
event_machine_helper.c
1 /*
2  * Copyright (c) 2012, Nokia Siemens Networks
3  * Copyright (c) 2015-2023, Nokia Solutions and Networks
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * * Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  * * Neither the name of the copyright holder nor the names of its
16  * contributors may be used to endorse or promote products derived
17  * from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #include <libgen.h> /* basename() */
33 #include <unistd.h> /* ssize_t */
34 #include "em_include.h"
35 #include <odp_api.h>
37 
38 int
39 em_error_format_string(char *str, size_t size, em_eo_t eo, em_status_t error,
40  em_escope_t escope, va_list args)
41 {
42  int ret = -1;
43 
44  if (!EM_ESCOPE(escope) || (ssize_t)size <= 0)
45  return 0;
46 
47  /*
48  * va_list contains: __FILE__, __func__, __LINE__, (format),
49  * ## __VA_ARGS__ as reported by the INTERNAL_ERROR macro.
50  */
51  char *file = va_arg(args, char*);
52  const char *func = va_arg(args, const char*);
53  const int line = va_arg(args, const int);
54  const char *format = va_arg(args, const char*);
55  const char *base = basename(file);
56  char eo_str[sizeof("EO:xxxxxx-abdc ") + EM_EO_NAME_LEN];
57  const uint64_t loc_err_cnt = em_locm.error_count;
58  const uint64_t glob_err_cnt = load_global_err_cnt();
59 
60  if (eo == EM_EO_UNDEF) {
61  eo_str[0] = '\0';
62  } else {
63  char eo_name[EM_EO_NAME_LEN];
64  size_t nlen;
65 
66  nlen = em_eo_get_name(eo, eo_name, sizeof(eo_name));
67  eo_name[nlen] = '\0';
68 
69  snprintf(eo_str, sizeof(eo_str),
70  "EO:%" PRI_EO "-\"%s\" ", eo, eo_name);
71  eo_str[sizeof(eo_str) - 1] = '\0';
72  }
73 
74  ret =
75  snprintf(str, size, "\n"
76  "EM ERROR:0x%08X ESCOPE:0x%08X %s\n"
77  "core:%02i ecount:%" PRIu64 "(%" PRIu64 ") %s:%i %s()\n",
78  error, escope, eo_str, em_core_id(),
79  glob_err_cnt, loc_err_cnt, base, line, func);
80 
81  if (ret > 0 && ret < (int64_t)size) {
82 #pragma GCC diagnostic push
83 #pragma GCC diagnostic ignored "-Wformat-nonliteral"
84  ret += vsnprintf(str + ret, size - ret, format, args);
85 #pragma GCC diagnostic pop
86  if (ret > 0 && ret < (int64_t)size)
87  ret += snprintf(str + ret, size - ret, "\n");
88  }
89 
90  str[size - 1] = '\0';
91 
92  return MIN((int64_t)size, ret + 1);
93 }
94 
95 void em_version_print(void)
96 {
97  print_version_info();
98 }
99 
100 void em_info_print(void)
101 {
102  print_em_info();
103 }
104 
105 int
107 {
108  return logic_to_phys_core_id(em_core_id);
109 }
110 
111 void
113 {
114  if (em_core_mask_equal(logic, &em_shm->core_map.logic_mask)) {
115  em_core_mask_copy(phys, &em_shm->core_map.phys_mask);
116  } else {
117  em_core_mask_zero(phys);
118  for (int i = 0; i < EM_MAX_CORES; i++) {
119  int phys_core;
120 
121  if (em_core_mask_isset(i, logic)) {
122  phys_core = logic_to_phys_core_id(i);
123  em_core_mask_set(phys_core, phys);
124  }
125  }
126  }
127 }
128 
130 {
131  if (EM_DEBUG_TIMESTAMP_ENABLE == 0)
132  return 0;
133 
134  if (unlikely(tsp >= EM_DEBUG_TSP_LAST || tsp < 0))
135  return 0;
136  else
137  return em_locm.debug_ts[tsp];
138 }
em_core_mask_zero
void em_core_mask_zero(em_core_mask_t *mask)
Definition: event_machine_hw_specific.c:43
em_core_mask_set
void em_core_mask_set(int core, em_core_mask_t *mask)
Definition: event_machine_hw_specific.c:48
em_core_mask_equal
int em_core_mask_equal(const em_core_mask_t *mask1, const em_core_mask_t *mask2)
Definition: event_machine_hw_specific.c:71
em_version_print
void em_version_print(void)
Print EM related version information.
Definition: event_machine_helper.c:95
em_eo_get_name
size_t em_eo_get_name(em_eo_t eo, char *name, size_t maxlen)
Definition: event_machine_eo.c:236
em_error_format_string
int em_error_format_string(char *str, size_t size, em_eo_t eo, em_status_t error, em_escope_t escope, va_list args)
Definition: event_machine_helper.c:39
em_locm
ENV_LOCAL em_locm_t em_locm
PRI_EO
#define PRI_EO
Definition: event_machine_types.h:97
em_info_print
void em_info_print(void)
Print miscellaneous EM information.
Definition: event_machine_helper.c:100
EM_EO_UNDEF
#define EM_EO_UNDEF
Definition: event_machine_types.h:95
print_em_info
void print_em_info(void)
Definition: em_info.c:426
em_core_mask_isset
int em_core_mask_isset(int core, const em_core_mask_t *mask)
Definition: event_machine_hw_specific.c:58
em_debug_tsp_t
em_debug_tsp_t
Definition: event_machine_debug.h:53
em_core_mask_t
Definition: event_machine_hw_types.h:242
em_core_id_get_physical
int em_core_id_get_physical(int core)
Definition: event_machine_helper.c:106
EM_ESCOPE
#define EM_ESCOPE(escope)
Definition: event_machine_types.h:365
EM_EO_NAME_LEN
#define EM_EO_NAME_LEN
Definition: event_machine_config.h:155
em_locm_t::debug_ts
uint64_t debug_ts[EM_DEBUG_TSP_LAST]
Definition: em_mem.h:239
em_escope_t
uint32_t em_escope_t
Definition: event_machine_types.h:348
em_status_t
uint32_t em_status_t
Definition: event_machine_types.h:321
event_machine_debug.h
em_core_mask_copy
void em_core_mask_copy(em_core_mask_t *dst, const em_core_mask_t *src)
Definition: event_machine_hw_specific.c:82
em_shm
em_shm_t * em_shm
Definition: event_machine_init.c:41
em_include.h
em_core_id
int em_core_id(void)
Definition: event_machine_core.c:34
EM_DEBUG_TIMESTAMP_ENABLE
#define EM_DEBUG_TIMESTAMP_ENABLE
Definition: event_machine_config.h:325
em_core_mask_get_physical
void em_core_mask_get_physical(em_core_mask_t *phys, const em_core_mask_t *logic)
Definition: event_machine_helper.c:112
em_locm_t::error_count
uint64_t error_count
Definition: em_mem.h:227
em_debug_timestamp
uint64_t em_debug_timestamp(em_debug_tsp_t tsp)
Definition: event_machine_helper.c:129