]> git.proxmox.com Git - ceph.git/blob - ceph/src/seastar/dpdk/app/test/test_sched.c
import 15.2.0 Octopus source
[ceph.git] / ceph / src / seastar / dpdk / app / test / test_sched.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
3 */
4
5 #include <stdlib.h>
6 #include <stdio.h>
7 #include <string.h>
8 #include <stdint.h>
9 #include <unistd.h>
10
11 #include "test.h"
12
13 #include <rte_cycles.h>
14 #include <rte_ether.h>
15 #include <rte_ip.h>
16 #include <rte_byteorder.h>
17 #include <rte_sched.h>
18
19
20 #define SUBPORT 0
21 #define PIPE 1
22 #define TC 2
23 #define QUEUE 3
24
25 static struct rte_sched_subport_params subport_param[] = {
26 {
27 .tb_rate = 1250000000,
28 .tb_size = 1000000,
29
30 .tc_rate = {1250000000, 1250000000, 1250000000, 1250000000},
31 .tc_period = 10,
32 },
33 };
34
35 static struct rte_sched_pipe_params pipe_profile[] = {
36 { /* Profile #0 */
37 .tb_rate = 305175,
38 .tb_size = 1000000,
39
40 .tc_rate = {305175, 305175, 305175, 305175},
41 .tc_period = 40,
42
43 .wrr_weights = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
44 },
45 };
46
47 static struct rte_sched_port_params port_param = {
48 .socket = 0, /* computed */
49 .rate = 0, /* computed */
50 .mtu = 1522,
51 .frame_overhead = RTE_SCHED_FRAME_OVERHEAD_DEFAULT,
52 .n_subports_per_port = 1,
53 .n_pipes_per_subport = 1024,
54 .qsize = {32, 32, 32, 32},
55 .pipe_profiles = pipe_profile,
56 .n_pipe_profiles = 1,
57 };
58
59 #define NB_MBUF 32
60 #define MBUF_DATA_SZ (2048 + RTE_PKTMBUF_HEADROOM)
61 #define MEMPOOL_CACHE_SZ 0
62 #define SOCKET 0
63
64
65 static struct rte_mempool *
66 create_mempool(void)
67 {
68 struct rte_mempool * mp;
69
70 mp = rte_mempool_lookup("test_sched");
71 if (!mp)
72 mp = rte_pktmbuf_pool_create("test_sched", NB_MBUF,
73 MEMPOOL_CACHE_SZ, 0, MBUF_DATA_SZ, SOCKET);
74
75 return mp;
76 }
77
78 static void
79 prepare_pkt(struct rte_sched_port *port, struct rte_mbuf *mbuf)
80 {
81 struct ether_hdr *eth_hdr;
82 struct vlan_hdr *vlan1, *vlan2;
83 struct ipv4_hdr *ip_hdr;
84
85 /* Simulate a classifier */
86 eth_hdr = rte_pktmbuf_mtod(mbuf, struct ether_hdr *);
87 vlan1 = (struct vlan_hdr *)(&eth_hdr->ether_type );
88 vlan2 = (struct vlan_hdr *)((uintptr_t)&eth_hdr->ether_type + sizeof(struct vlan_hdr));
89 eth_hdr = (struct ether_hdr *)((uintptr_t)&eth_hdr->ether_type + 2 *sizeof(struct vlan_hdr));
90 ip_hdr = (struct ipv4_hdr *)((uintptr_t)eth_hdr + sizeof(eth_hdr->ether_type));
91
92 vlan1->vlan_tci = rte_cpu_to_be_16(SUBPORT);
93 vlan2->vlan_tci = rte_cpu_to_be_16(PIPE);
94 eth_hdr->ether_type = rte_cpu_to_be_16(ETHER_TYPE_IPv4);
95 ip_hdr->dst_addr = IPv4(0,0,TC,QUEUE);
96
97
98 rte_sched_port_pkt_write(port, mbuf, SUBPORT, PIPE, TC, QUEUE,
99 RTE_COLOR_YELLOW);
100
101 /* 64 byte packet */
102 mbuf->pkt_len = 60;
103 mbuf->data_len = 60;
104 }
105
106
107 /**
108 * test main entrance for library sched
109 */
110 static int
111 test_sched(void)
112 {
113 struct rte_mempool *mp = NULL;
114 struct rte_sched_port *port = NULL;
115 uint32_t pipe;
116 struct rte_mbuf *in_mbufs[10];
117 struct rte_mbuf *out_mbufs[10];
118 int i;
119
120 int err;
121
122 mp = create_mempool();
123 TEST_ASSERT_NOT_NULL(mp, "Error creating mempool\n");
124
125 port_param.socket = 0;
126 port_param.rate = (uint64_t) 10000 * 1000 * 1000 / 8;
127
128 port = rte_sched_port_config(&port_param);
129 TEST_ASSERT_NOT_NULL(port, "Error config sched port\n");
130
131 err = rte_sched_subport_config(port, SUBPORT, subport_param);
132 TEST_ASSERT_SUCCESS(err, "Error config sched, err=%d\n", err);
133
134 for (pipe = 0; pipe < port_param.n_pipes_per_subport; pipe ++) {
135 err = rte_sched_pipe_config(port, SUBPORT, pipe, 0);
136 TEST_ASSERT_SUCCESS(err, "Error config sched pipe %u, err=%d\n", pipe, err);
137 }
138
139 for (i = 0; i < 10; i++) {
140 in_mbufs[i] = rte_pktmbuf_alloc(mp);
141 TEST_ASSERT_NOT_NULL(in_mbufs[i], "Packet allocation failed\n");
142 prepare_pkt(port, in_mbufs[i]);
143 }
144
145
146 err = rte_sched_port_enqueue(port, in_mbufs, 10);
147 TEST_ASSERT_EQUAL(err, 10, "Wrong enqueue, err=%d\n", err);
148
149 err = rte_sched_port_dequeue(port, out_mbufs, 10);
150 TEST_ASSERT_EQUAL(err, 10, "Wrong dequeue, err=%d\n", err);
151
152 for (i = 0; i < 10; i++) {
153 enum rte_color color;
154 uint32_t subport, traffic_class, queue;
155
156 color = rte_sched_port_pkt_read_color(out_mbufs[i]);
157 TEST_ASSERT_EQUAL(color, RTE_COLOR_YELLOW, "Wrong color\n");
158
159 rte_sched_port_pkt_read_tree_path(port, out_mbufs[i],
160 &subport, &pipe, &traffic_class, &queue);
161
162 TEST_ASSERT_EQUAL(subport, SUBPORT, "Wrong subport\n");
163 TEST_ASSERT_EQUAL(pipe, PIPE, "Wrong pipe\n");
164 TEST_ASSERT_EQUAL(traffic_class, TC, "Wrong traffic_class\n");
165 TEST_ASSERT_EQUAL(queue, QUEUE, "Wrong queue\n");
166
167 }
168
169
170 struct rte_sched_subport_stats subport_stats;
171 uint32_t tc_ov;
172 rte_sched_subport_read_stats(port, SUBPORT, &subport_stats, &tc_ov);
173 #if 0
174 TEST_ASSERT_EQUAL(subport_stats.n_pkts_tc[TC-1], 10, "Wrong subport stats\n");
175 #endif
176 struct rte_sched_queue_stats queue_stats;
177 uint16_t qlen;
178 rte_sched_queue_read_stats(port, QUEUE, &queue_stats, &qlen);
179 #if 0
180 TEST_ASSERT_EQUAL(queue_stats.n_pkts, 10, "Wrong queue stats\n");
181 #endif
182
183 rte_sched_port_free(port);
184
185 return 0;
186 }
187
188 REGISTER_TEST_COMMAND(sched_autotest, test_sched);