xref: /f-stack/dpdk/app/test-eventdev/evt_common.h (revision 2bfe3f2e)
1 /*
2  *   BSD LICENSE
3  *
4  *   Copyright (C) Cavium, Inc 2017.
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
14  *       the documentation and/or other materials provided with the
15  *       distribution.
16  *     * Neither the name of Cavium, Inc nor the names of its
17  *       contributors may be used to endorse or promote products derived
18  *       from this software without specific prior written permission.
19  *
20  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #ifndef _EVT_COMMON_
34 #define _EVT_COMMON_
35 
36 #include <rte_common.h>
37 #include <rte_debug.h>
38 #include <rte_eventdev.h>
39 #include <rte_service.h>
40 
41 #define CLNRM  "\x1b[0m"
42 #define CLRED  "\x1b[31m"
43 #define CLGRN  "\x1b[32m"
44 #define CLYEL  "\x1b[33m"
45 
46 #define evt_err(fmt, args...) \
47 	fprintf(stderr, CLRED"error: %s() "fmt CLNRM "\n", __func__, ## args)
48 
49 #define evt_info(fmt, args...) \
50 	fprintf(stdout, CLYEL""fmt CLNRM "\n", ## args)
51 
52 #define EVT_STR_FMT 20
53 
54 #define evt_dump(str, fmt, val...) \
55 	printf("\t%-*s : "fmt"\n", EVT_STR_FMT, str, ## val)
56 
57 #define evt_dump_begin(str) printf("\t%-*s : {", EVT_STR_FMT, str)
58 
59 #define evt_dump_end printf("\b}\n")
60 
61 #define EVT_MAX_STAGES           64
62 #define EVT_MAX_PORTS            256
63 #define EVT_MAX_QUEUES           256
64 
65 static inline bool
66 evt_has_distributed_sched(uint8_t dev_id)
67 {
68 	struct rte_event_dev_info dev_info;
69 
70 	rte_event_dev_info_get(dev_id, &dev_info);
71 	return (dev_info.event_dev_cap & RTE_EVENT_DEV_CAP_DISTRIBUTED_SCHED) ?
72 			true : false;
73 }
74 
75 static inline bool
76 evt_has_burst_mode(uint8_t dev_id)
77 {
78 	struct rte_event_dev_info dev_info;
79 
80 	rte_event_dev_info_get(dev_id, &dev_info);
81 	return (dev_info.event_dev_cap & RTE_EVENT_DEV_CAP_BURST_MODE) ?
82 			true : false;
83 }
84 
85 
86 static inline bool
87 evt_has_all_types_queue(uint8_t dev_id)
88 {
89 	struct rte_event_dev_info dev_info;
90 
91 	rte_event_dev_info_get(dev_id, &dev_info);
92 	return (dev_info.event_dev_cap & RTE_EVENT_DEV_CAP_QUEUE_ALL_TYPES) ?
93 			true : false;
94 }
95 
96 static inline int
97 evt_service_setup(uint8_t dev_id)
98 {
99 	uint32_t service_id;
100 	int32_t core_cnt;
101 	unsigned int lcore = 0;
102 	uint32_t core_array[RTE_MAX_LCORE];
103 	uint8_t cnt;
104 	uint8_t min_cnt = UINT8_MAX;
105 
106 	if (evt_has_distributed_sched(dev_id))
107 		return 0;
108 
109 	if (!rte_service_lcore_count())
110 		return -ENOENT;
111 
112 	if (!rte_event_dev_service_id_get(dev_id, &service_id)) {
113 		core_cnt = rte_service_lcore_list(core_array,
114 				RTE_MAX_LCORE);
115 		if (core_cnt < 0)
116 			return -ENOENT;
117 		/* Get the core which has least number of services running. */
118 		while (core_cnt--) {
119 			/* Reset default mapping */
120 			rte_service_map_lcore_set(service_id,
121 					core_array[core_cnt], 0);
122 			cnt = rte_service_lcore_count_services(
123 					core_array[core_cnt]);
124 			if (cnt < min_cnt) {
125 				lcore = core_array[core_cnt];
126 				min_cnt = cnt;
127 			}
128 		}
129 		if (rte_service_map_lcore_set(service_id, lcore, 1))
130 			return -ENOENT;
131 	}
132 	return 0;
133 }
134 
135 #endif /*  _EVT_COMMON_*/
136