Saturday, December 9, 2017

Quick DPDK log

1.DPDK log level
#define RTE_LOG_EMERG 1U /**< System is unusable. */
#define RTE_LOG_ALERT 2U /**< Action must be taken immediately. */
#define RTE_LOG_CRIT 3U /**< Critical conditions. */
#define RTE_LOG_ERR 4U /**< Error conditions. */
#define RTE_LOG_WARNING 5U /**< Warning conditions. */
#define RTE_LOG_NOTICE 6U /**< Normal but significant condition. */
#define RTE_LOG_INFO 7U /**< Informational. */
#define RTE_LOG_DEBUG 8U /**< Debug-level messages. */

rte_set_log_level(); 
eg:rte_set_log_level(RTE_LOG_DEBUG    );  
rte_set_log_level() was called inside rte_eal_init()

2.DPDK log types

defined in "./liblibrte_eal/common/include/rte_log.h":

#define RTE_LOGTYPE_EAL 0x00000001 /**< Log related to eal. */
#define RTE_LOGTYPE_MALLOC 0x00000002 /**< Log related to malloc. */
#define RTE_LOGTYPE_RING 0x00000004 /**< Log related to ring. */
#define RTE_LOGTYPE_MEMPOOL 0x00000008 /**< Log related to mempool. */
#define RTE_LOGTYPE_TIMER 0x00000010 /**< Log related to timers. */
#define RTE_LOGTYPE_PMD 0x00000020 /**< Log related to poll mode driver. */
#define RTE_LOGTYPE_HASH 0x00000040 /**< Log related to hash table. */
#define RTE_LOGTYPE_LPM 0x00000080 /**< Log related to LPM. */
#define RTE_LOGTYPE_KNI 0x00000100 /**< Log related to KNI. */
#define RTE_LOGTYPE_ACL 0x00000200 /**< Log related to ACL. */
#define RTE_LOGTYPE_POWER 0x00000400 /**< Log related to power. */
#define RTE_LOGTYPE_METER 0x00000800 /**< Log related to QoS meter. */
#define RTE_LOGTYPE_SCHED 0x00001000 /**< Log related to QoS port scheduler. */
#define RTE_LOGTYPE_PORT 0x00002000 /**< Log related to port. */
#define RTE_LOGTYPE_TABLE 0x00004000 /**< Log related to table. */
#define RTE_LOGTYPE_PIPELINE 0x00008000 /**< Log related to pipeline. */

/* these log types can be used in an application */
#define RTE_LOGTYPE_USER1 0x01000000 /**< User-defined log type 1. */
#define RTE_LOGTYPE_USER2 0x02000000 /**< User-defined log type 2. */
#define RTE_LOGTYPE_USER3 0x04000000 /**< User-defined log type 3. */
#define RTE_LOGTYPE_USER4 0x08000000 /**< User-defined log type 4. */
#define RTE_LOGTYPE_USER5 0x10000000 /**< User-defined log type 5. */
#define RTE_LOGTYPE_USER6 0x20000000 /**< User-defined log type 6. */
#define RTE_LOGTYPE_USER7 0x40000000 /**< User-defined log type 7. */
#define RTE_LOGTYPE_USER8 0x80000000 /**< User-defined log type 8. */

3. support syslog
configuration in syslog.conf

4. eal command line option
--log-level
eg: ./build/l2fwd -c 3 -n 4  --log-level  8  

5. log example code
  File *my_log = fopen("./my_log.txt", "a");
  rte_openlog_stream(my_log);
  rte_log_set_global_level(RTE_LOG_WARNING);
  RTE_LOG(ERR, USER8, "my test log, id: %d\n", 1688);

Thursday, February 23, 2017

Makefile template

CC=gcc
DEBUG = -g
CFLAGS=-c -Wall $(DEBUG) -I../build/include/
LDFLAGS=-L../build/lib/
LDLIBS=-lrte_cfgfile -lrte_eal
SOURCES=test_cfg.c
OBJECTS=$(SOURCES:.c=.o)
EXECUTABLE=test_cfg
all: $(SOURCES) $(EXECUTABLE)
$(EXECUTABLE): $(OBJECTS)
    # $(CC) $(LDFLAGS) $(OBJECTS) -o $@
    # $(CC) $(OBJECTS) -o $@ $(LDFLAGS)
    $(CC) $(OBJECTS) $(LDFLAGS) $(LDLIBS) -o $@

.c.o:
     $(CC) $(CFLAGS) $< -o $@
clean:
     rm -rf *.o $(EXECUTABLE)

stack-frame-layout-on-x86-64

Argument passing on Linux x64
I'm going to simplify the discussion here on purpose and focus on integer/pointer arguments [3]. According to the ABI, the first 6 integer or pointer arguments to a function are passed in registers. The first is placed in rdi, the second in rsi, the third in rdx, and then rcx, r8 and r9. Only the 7th argument and onwards are passed on the stack.
The stack frame
With the above in mind, let's see how the stack frame for this C function looks:

long myfunc(long a, long b, long c, long d,
long e, long f, long g, long h)
{
     long xx = a * b * c * d * e * f * g * h;
     long yy = a + b + c + d + e + f + g + h;
     long zz = utilfunc(xx, yy, xx % yy);
     return zz + 20;
}

This is the stack frame: referenced from:
stack-frame-layout-on-x86-64