xref: /dpdk/examples/multi_process/client_server_mp/shared/common.h (revision dada9ef6edc59015b6674b5a95258787c71401b0)
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2012 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 
35 #ifndef _COMMON_H_
36 #define _COMMON_H_
37 
38 #define MAX_CLIENTS             16
39 
40 /*
41  * Shared port info, including statistics information for display by server.
42  * Structure will be put in a memzone.
43  * - All port id values share one cache line as this data will be read-only
44  * during operation.
45  * - All rx statistic values share cache lines, as this data is written only
46  * by the server process. (rare reads by stats display)
47  * - The tx statistics have values for all ports per cache line, but the stats
48  * themselves are written by the clients, so we have a distinct set, on different
49  * cache lines for each client to use.
50  */
51 struct rx_stats{
52 	uint64_t rx[RTE_MAX_ETHPORTS];
53 } __rte_cache_aligned;
54 
55 struct tx_stats{
56 	uint64_t tx[RTE_MAX_ETHPORTS];
57 	uint64_t tx_drop[RTE_MAX_ETHPORTS];
58 } __rte_cache_aligned;
59 
60 struct port_info {
61 	uint8_t num_ports;
62 	uint8_t id[RTE_MAX_ETHPORTS];
63 	volatile struct rx_stats rx_stats;
64 	volatile struct tx_stats tx_stats[MAX_CLIENTS];
65 };
66 
67 /* define common names for structures shared between server and client */
68 #define MP_CLIENT_RXQ_NAME "MProc_Client_%u_RX"
69 #define PKTMBUF_POOL_NAME "MProc_pktmbuf_pool"
70 #define MZ_PORT_INFO "MProc_port_info"
71 
72 /*
73  * Given the rx queue name template above, get the queue name
74  */
75 static inline const char *
76 get_rx_queue_name(unsigned id)
77 {
78 	/* buffer for return value. Size calculated by %u being replaced
79 	 * by maximum 3 digits (plus an extra byte for safety) */
80 	static char buffer[sizeof(MP_CLIENT_RXQ_NAME) + 2];
81 
82 	rte_snprintf(buffer, sizeof(buffer) - 1, MP_CLIENT_RXQ_NAME, id);
83 	return buffer;
84 }
85 
86 #define RTE_LOGTYPE_APP RTE_LOGTYPE_USER1
87 
88 #endif
89