gso: support TCP/IPv4 GSO
[dpdk.git] / lib / librte_eal / common / include / rte_log.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-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 #ifndef _RTE_LOG_H_
35 #define _RTE_LOG_H_
36
37 /**
38  * @file
39  *
40  * RTE Logs API
41  *
42  * This file provides a log API to RTE applications.
43  */
44
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48
49 #include <stdint.h>
50 #include <stdio.h>
51 #include <stdarg.h>
52
53 #include <rte_common.h>
54
55 struct rte_log_dynamic_type;
56
57 /** The rte_log structure. */
58 struct rte_logs {
59         uint32_t type;  /**< Bitfield with enabled logs. */
60         uint32_t level; /**< Log level. */
61         FILE *file;     /**< Output file set by rte_openlog_stream, or NULL. */
62         size_t dynamic_types_len;
63         struct rte_log_dynamic_type *dynamic_types;
64 };
65
66 /** Global log informations */
67 extern struct rte_logs rte_logs;
68
69 /* SDK log type */
70 #define RTE_LOGTYPE_EAL        0 /**< Log related to eal. */
71 #define RTE_LOGTYPE_MALLOC     1 /**< Log related to malloc. */
72 #define RTE_LOGTYPE_RING       2 /**< Log related to ring. */
73 #define RTE_LOGTYPE_MEMPOOL    3 /**< Log related to mempool. */
74 #define RTE_LOGTYPE_TIMER      4 /**< Log related to timers. */
75 #define RTE_LOGTYPE_PMD        5 /**< Log related to poll mode driver. */
76 #define RTE_LOGTYPE_HASH       6 /**< Log related to hash table. */
77 #define RTE_LOGTYPE_LPM        7 /**< Log related to LPM. */
78 #define RTE_LOGTYPE_KNI        8 /**< Log related to KNI. */
79 #define RTE_LOGTYPE_ACL        9 /**< Log related to ACL. */
80 #define RTE_LOGTYPE_POWER     10 /**< Log related to power. */
81 #define RTE_LOGTYPE_METER     11 /**< Log related to QoS meter. */
82 #define RTE_LOGTYPE_SCHED     12 /**< Log related to QoS port scheduler. */
83 #define RTE_LOGTYPE_PORT      13 /**< Log related to port. */
84 #define RTE_LOGTYPE_TABLE     14 /**< Log related to table. */
85 #define RTE_LOGTYPE_PIPELINE  15 /**< Log related to pipeline. */
86 #define RTE_LOGTYPE_MBUF      16 /**< Log related to mbuf. */
87 #define RTE_LOGTYPE_CRYPTODEV 17 /**< Log related to cryptodev. */
88 #define RTE_LOGTYPE_EFD       18 /**< Log related to EFD. */
89 #define RTE_LOGTYPE_EVENTDEV  19 /**< Log related to eventdev. */
90 #define RTE_LOGTYPE_GSO       20 /**< Log related to GSO. */
91
92 /* these log types can be used in an application */
93 #define RTE_LOGTYPE_USER1     24 /**< User-defined log type 1. */
94 #define RTE_LOGTYPE_USER2     25 /**< User-defined log type 2. */
95 #define RTE_LOGTYPE_USER3     26 /**< User-defined log type 3. */
96 #define RTE_LOGTYPE_USER4     27 /**< User-defined log type 4. */
97 #define RTE_LOGTYPE_USER5     28 /**< User-defined log type 5. */
98 #define RTE_LOGTYPE_USER6     29 /**< User-defined log type 6. */
99 #define RTE_LOGTYPE_USER7     30 /**< User-defined log type 7. */
100 #define RTE_LOGTYPE_USER8     31 /**< User-defined log type 8. */
101
102 /** First identifier for extended logs */
103 #define RTE_LOGTYPE_FIRST_EXT_ID 32
104
105 /* Can't use 0, as it gives compiler warnings */
106 #define RTE_LOG_EMERG    1U  /**< System is unusable.               */
107 #define RTE_LOG_ALERT    2U  /**< Action must be taken immediately. */
108 #define RTE_LOG_CRIT     3U  /**< Critical conditions.              */
109 #define RTE_LOG_ERR      4U  /**< Error conditions.                 */
110 #define RTE_LOG_WARNING  5U  /**< Warning conditions.               */
111 #define RTE_LOG_NOTICE   6U  /**< Normal but significant condition. */
112 #define RTE_LOG_INFO     7U  /**< Informational.                    */
113 #define RTE_LOG_DEBUG    8U  /**< Debug-level messages.             */
114
115 /**
116  * Change the stream that will be used by the logging system.
117  *
118  * This can be done at any time. The f argument represents the stream
119  * to be used to send the logs. If f is NULL, the default output is
120  * used (stderr).
121  *
122  * @param f
123  *   Pointer to the stream.
124  * @return
125  *   - 0 on success.
126  *   - Negative on error.
127  */
128 int rte_openlog_stream(FILE *f);
129
130 /**
131  * Set the global log level.
132  *
133  * After this call, logs with a level lower or equal than the level
134  * passed as argument will be displayed.
135  *
136  * @param level
137  *   Log level. A value between RTE_LOG_EMERG (1) and RTE_LOG_DEBUG (8).
138  */
139 void rte_log_set_global_level(uint32_t level);
140
141 /**
142  * Deprecated, replaced by rte_log_set_global_level().
143  */
144 __rte_deprecated
145 void rte_set_log_level(uint32_t level);
146
147 /**
148  * Get the global log level.
149  *
150  * @return
151  *   The current global log level.
152  */
153 uint32_t rte_log_get_global_level(void);
154
155 /**
156  * Deprecated, replaced by rte_log_get_global_level().
157  */
158 __rte_deprecated
159 uint32_t rte_get_log_level(void);
160
161 /**
162  * Enable or disable the log type.
163  *
164  * @param type
165  *   Log type, for example, RTE_LOGTYPE_EAL.
166  * @param enable
167  *   True for enable; false for disable.
168  */
169 __rte_deprecated
170 void rte_set_log_type(uint32_t type, int enable);
171
172 /**
173  * Get the global log type.
174  */
175 __rte_deprecated
176 uint32_t rte_get_log_type(void);
177
178 /**
179  * Get the log level for a given type.
180  *
181  * @param logtype
182  *   The log type identifier.
183  * @return
184  *   0 on success, a negative value if logtype is invalid.
185  */
186 int rte_log_get_level(uint32_t logtype);
187
188 /**
189  * Set the log level for a given type.
190  *
191  * @param pattern
192  *   The regexp identifying the log type.
193  * @param level
194  *   The level to be set.
195  * @return
196  *   0 on success, a negative value if level is invalid.
197  */
198 int rte_log_set_level_regexp(const char *pattern, uint32_t level);
199
200 /**
201  * Set the log level for a given type.
202  *
203  * @param logtype
204  *   The log type identifier.
205  * @param level
206  *   The level to be set.
207  * @return
208  *   0 on success, a negative value if logtype or level is invalid.
209  */
210 int rte_log_set_level(uint32_t logtype, uint32_t level);
211
212 /**
213  * Get the current loglevel for the message being processed.
214  *
215  * Before calling the user-defined stream for logging, the log
216  * subsystem sets a per-lcore variable containing the loglevel and the
217  * logtype of the message being processed. This information can be
218  * accessed by the user-defined log output function through this
219  * function.
220  *
221  * @return
222  *   The loglevel of the message being processed.
223  */
224 int rte_log_cur_msg_loglevel(void);
225
226 /**
227  * Get the current logtype for the message being processed.
228  *
229  * Before calling the user-defined stream for logging, the log
230  * subsystem sets a per-lcore variable containing the loglevel and the
231  * logtype of the message being processed. This information can be
232  * accessed by the user-defined log output function through this
233  * function.
234  *
235  * @return
236  *   The logtype of the message being processed.
237  */
238 int rte_log_cur_msg_logtype(void);
239
240 /**
241  * Register a dynamic log type
242  *
243  * If a log is already registered with the same type, the returned value
244  * is the same than the previous one.
245  *
246  * @param name
247  *   The string identifying the log type.
248  * @return
249  *   - >0: success, the returned value is the log type identifier.
250  *   - (-ENONEM): cannot allocate memory.
251  */
252 int rte_log_register(const char *name);
253
254 /**
255  * Dump log information.
256  *
257  * Dump the global level and the registered log types.
258  *
259  * @param f
260  *   The output stream where the dump should be sent.
261  */
262 void rte_log_dump(FILE *f);
263
264 /**
265  * Generates a log message.
266  *
267  * The message will be sent in the stream defined by the previous call
268  * to rte_openlog_stream().
269  *
270  * The level argument determines if the log should be displayed or
271  * not, depending on the global rte_logs variable.
272  *
273  * The preferred alternative is the RTE_LOG() because it adds the
274  * level and type in the logged string.
275  *
276  * @param level
277  *   Log level. A value between RTE_LOG_EMERG (1) and RTE_LOG_DEBUG (8).
278  * @param logtype
279  *   The log type, for example, RTE_LOGTYPE_EAL.
280  * @param format
281  *   The format string, as in printf(3), followed by the variable arguments
282  *   required by the format.
283  * @return
284  *   - 0: Success.
285  *   - Negative on error.
286  */
287 int rte_log(uint32_t level, uint32_t logtype, const char *format, ...)
288 #ifdef __GNUC__
289 #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 2))
290         __attribute__((cold))
291 #endif
292 #endif
293         __attribute__((format(printf, 3, 4)));
294
295 /**
296  * Generates a log message.
297  *
298  * The message will be sent in the stream defined by the previous call
299  * to rte_openlog_stream().
300  *
301  * The level argument determines if the log should be displayed or
302  * not, depending on the global rte_logs variable. A trailing
303  * newline may be added if needed.
304  *
305  * The preferred alternative is the RTE_LOG() because it adds the
306  * level and type in the logged string.
307  *
308  * @param level
309  *   Log level. A value between RTE_LOG_EMERG (1) and RTE_LOG_DEBUG (8).
310  * @param logtype
311  *   The log type, for example, RTE_LOGTYPE_EAL.
312  * @param format
313  *   The format string, as in printf(3), followed by the variable arguments
314  *   required by the format.
315  * @param ap
316  *   The va_list of the variable arguments required by the format.
317  * @return
318  *   - 0: Success.
319  *   - Negative on error.
320  */
321 int rte_vlog(uint32_t level, uint32_t logtype, const char *format, va_list ap)
322         __attribute__((format(printf,3,0)));
323
324 /**
325  * Generates a log message.
326  *
327  * The RTE_LOG() is a helper that prefixes the string with the log level
328  * and type, and call rte_log().
329  *
330  * @param l
331  *   Log level. A value between EMERG (1) and DEBUG (8). The short name is
332  *   expanded by the macro, so it cannot be an integer value.
333  * @param t
334  *   The log type, for example, EAL. The short name is expanded by the
335  *   macro, so it cannot be an integer value.
336  * @param ...
337  *   The fmt string, as in printf(3), followed by the variable arguments
338  *   required by the format.
339  * @return
340  *   - 0: Success.
341  *   - Negative on error.
342  */
343 #define RTE_LOG(l, t, ...)                                      \
344          rte_log(RTE_LOG_ ## l,                                 \
345                  RTE_LOGTYPE_ ## t, # t ": " __VA_ARGS__)
346
347 /**
348  * Generates a log message for data path.
349  *
350  * Similar to RTE_LOG(), except that it is removed at compilation time
351  * if the RTE_LOG_DP_LEVEL configuration option is lower than the log
352  * level argument.
353  *
354  * @param l
355  *   Log level. A value between EMERG (1) and DEBUG (8). The short name is
356  *   expanded by the macro, so it cannot be an integer value.
357  * @param t
358  *   The log type, for example, EAL. The short name is expanded by the
359  *   macro, so it cannot be an integer value.
360  * @param ...
361  *   The fmt string, as in printf(3), followed by the variable arguments
362  *   required by the format.
363  * @return
364  *   - 0: Success.
365  *   - Negative on error.
366  */
367 #define RTE_LOG_DP(l, t, ...)                                   \
368         (void)((RTE_LOG_ ## l <= RTE_LOG_DP_LEVEL) ?            \
369          rte_log(RTE_LOG_ ## l,                                 \
370                  RTE_LOGTYPE_ ## t, # t ": " __VA_ARGS__) :     \
371          0)
372
373 #ifdef __cplusplus
374 }
375 #endif
376
377 #endif /* _RTE_LOG_H_ */