FD.io VPP  v17.07.01-10-g3be13f0
Vector Packet Processing
hqos.c
Go to the documentation of this file.
1 /*
2  * Copyright(c) 2016 Intel Corporation. All rights reserved.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <unistd.h>
18 #include <sys/stat.h>
19 #include <sys/mount.h>
20 #include <string.h>
21 #include <fcntl.h>
22 
23 #include <vppinfra/vec.h>
24 #include <vppinfra/error.h>
25 #include <vppinfra/format.h>
26 #include <vppinfra/bitmap.h>
27 
28 #include <vnet/vnet.h>
29 #include <vnet/ethernet/ethernet.h>
30 #include <dpdk/device/dpdk.h>
31 
32 #include <vlib/unix/physmem.h>
33 #include <vlib/pci/pci.h>
34 #include <vlibmemory/api.h>
35 #include <vlibmemory/vl_memory_msg_enum.h> /* enumerate all vlib messages */
36 
37 #define vl_typedefs /* define message structures */
39 #undef vl_typedefs
40 
41 /* instantiate all the print functions we know about */
42 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
43 #define vl_printfun
45 #undef vl_printfun
46 
47 #include <dpdk/device/dpdk_priv.h>
48 
49 /***
50  *
51  * HQoS default configuration values
52  *
53  ***/
54 
55 static dpdk_device_config_hqos_t hqos_params_default = {
56  .hqos_thread_valid = 0,
57 
58  .swq_size = 4096,
59  .burst_enq = 256,
60  .burst_deq = 220,
61 
62  /*
63  * Packet field to identify the subport.
64  *
65  * Default value: Since only one subport is defined by default (see below:
66  * n_subports_per_port = 1), the subport ID is hardcoded to 0.
67  */
68  .pktfield0_slabpos = 0,
69  .pktfield0_slabmask = 0,
70 
71  /*
72  * Packet field to identify the pipe.
73  *
74  * Default value: Assuming Ethernet/IPv4/UDP packets, UDP payload bits 12 .. 23
75  */
76  .pktfield1_slabpos = 40,
77  .pktfield1_slabmask = 0x0000000FFF000000LLU,
78 
79  /* Packet field used as index into TC translation table to identify the traffic
80  * class and queue.
81  *
82  * Default value: Assuming Ethernet/IPv4 packets, IPv4 DSCP field
83  */
84  .pktfield2_slabpos = 8,
85  .pktfield2_slabmask = 0x00000000000000FCLLU,
86  .tc_table = {
87  0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
88  0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
89  0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
90  0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
91  },
92 
93  /* port */
94  .port = {
95  .name = NULL, /* Set at init */
96  .socket = 0, /* Set at init */
97  .rate = 1250000000, /* Assuming 10GbE port */
98  .mtu = 14 + 1500, /* Assuming Ethernet/IPv4 pkt (Ethernet FCS not included) */
99  .frame_overhead = RTE_SCHED_FRAME_OVERHEAD_DEFAULT,
100  .n_subports_per_port = 1,
101  .n_pipes_per_subport = 4096,
102  .qsize = {64, 64, 64, 64},
103  .pipe_profiles = NULL, /* Set at config */
104  .n_pipe_profiles = 1,
105 
106 #ifdef RTE_SCHED_RED
107  .red_params = {
108  /* Traffic Class 0 Colors Green / Yellow / Red */
109  [0][0] = {.min_th = 48,.max_th = 64,.maxp_inv =
110  10,.wq_log2 = 9},
111  [0][1] = {.min_th = 40,.max_th = 64,.maxp_inv =
112  10,.wq_log2 = 9},
113  [0][2] = {.min_th = 32,.max_th = 64,.maxp_inv =
114  10,.wq_log2 = 9},
115 
116  /* Traffic Class 1 - Colors Green / Yellow / Red */
117  [1][0] = {.min_th = 48,.max_th = 64,.maxp_inv =
118  10,.wq_log2 = 9},
119  [1][1] = {.min_th = 40,.max_th = 64,.maxp_inv =
120  10,.wq_log2 = 9},
121  [1][2] = {.min_th = 32,.max_th = 64,.maxp_inv =
122  10,.wq_log2 = 9},
123 
124  /* Traffic Class 2 - Colors Green / Yellow / Red */
125  [2][0] = {.min_th = 48,.max_th = 64,.maxp_inv =
126  10,.wq_log2 = 9},
127  [2][1] = {.min_th = 40,.max_th = 64,.maxp_inv =
128  10,.wq_log2 = 9},
129  [2][2] = {.min_th = 32,.max_th = 64,.maxp_inv =
130  10,.wq_log2 = 9},
131 
132  /* Traffic Class 3 - Colors Green / Yellow / Red */
133  [3][0] = {.min_th = 48,.max_th = 64,.maxp_inv =
134  10,.wq_log2 = 9},
135  [3][1] = {.min_th = 40,.max_th = 64,.maxp_inv =
136  10,.wq_log2 = 9},
137  [3][2] = {.min_th = 32,.max_th = 64,.maxp_inv =
138  10,.wq_log2 = 9}
139  },
140 #endif /* RTE_SCHED_RED */
141  },
142 };
143 
144 static struct rte_sched_subport_params hqos_subport_params_default = {
145  .tb_rate = 1250000000, /* 10GbE line rate (measured in bytes/second) */
146  .tb_size = 1000000,
147  .tc_rate = {1250000000, 1250000000, 1250000000, 1250000000},
148  .tc_period = 10,
149 };
150 
151 static struct rte_sched_pipe_params hqos_pipe_params_default = {
152  .tb_rate = 305175, /* 10GbE line rate divided by 4K pipes */
153  .tb_size = 1000000,
154  .tc_rate = {305175, 305175, 305175, 305175},
155  .tc_period = 40,
156 #ifdef RTE_SCHED_SUBPORT_TC_OV
157  .tc_ov_weight = 1,
158 #endif
159  .wrr_weights = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
160 };
161 
162 /***
163  *
164  * HQoS configuration
165  *
166  ***/
167 
168 int
170 {
171  int count = __builtin_popcountll (mask);
172  int pos_lead = sizeof (u64) * 8 - __builtin_clzll (mask);
173  int pos_trail = __builtin_ctzll (mask);
174  int count_expected = __builtin_popcount (n - 1);
175 
176  /* Handle the exceptions */
177  if (n == 0)
178  return -1; /* Error */
179 
180  if ((mask == 0) && (n == 1))
181  return 0; /* OK */
182 
183  if (((mask == 0) && (n != 1)) || ((mask != 0) && (n == 1)))
184  return -2; /* Error */
185 
186  /* Check that mask is contiguous */
187  if ((pos_lead - pos_trail) != count)
188  return -3; /* Error */
189 
190  /* Check that mask contains the expected number of bits set */
191  if (count != count_expected)
192  return -4; /* Error */
193 
194  return 0; /* OK */
195 }
196 
197 void
199  hqos, u32 pipe_profile_id)
200 {
201  memcpy (&hqos->pipe[pipe_profile_id], &hqos_pipe_params_default,
202  sizeof (hqos_pipe_params_default));
203 }
204 
205 void
207 {
208  struct rte_sched_subport_params *subport_params;
209  struct rte_sched_pipe_params *pipe_params;
210  u32 *pipe_map;
211  u32 i;
212 
213  memcpy (hqos, &hqos_params_default, sizeof (hqos_params_default));
214 
215  /* pipe */
216  vec_add2 (hqos->pipe, pipe_params, hqos->port.n_pipe_profiles);
217 
218  for (i = 0; i < vec_len (hqos->pipe); i++)
219  memcpy (&pipe_params[i],
221 
222  hqos->port.pipe_profiles = hqos->pipe;
223 
224  /* subport */
225  vec_add2 (hqos->subport, subport_params, hqos->port.n_subports_per_port);
226 
227  for (i = 0; i < vec_len (hqos->subport); i++)
228  memcpy (&subport_params[i],
230  sizeof (hqos_subport_params_default));
231 
232  /* pipe profile */
233  vec_add2 (hqos->pipe_map,
234  pipe_map,
235  hqos->port.n_subports_per_port * hqos->port.n_pipes_per_subport);
236 
237  for (i = 0; i < vec_len (hqos->pipe_map); i++)
238  pipe_map[i] = 0;
239 }
240 
241 /***
242  *
243  * HQoS init
244  *
245  ***/
246 
247 clib_error_t *
249 {
251  char name[32];
252  u32 subport_id, i;
253  int rv;
254 
255  /* Detect the set of worker threads */
256  int worker_thread_first = 0;
257  int worker_thread_count = 0;
258 
259  uword *p = hash_get_mem (tm->thread_registrations_by_name, "workers");
261  p ? (vlib_thread_registration_t *) p[0] : 0;
262 
263  if (tr && tr->count > 0)
264  {
265  worker_thread_first = tr->first_index;
266  worker_thread_count = tr->count;
267  }
268 
269  /* Allocate the per-thread device data array */
272  memset (xd->hqos_wt, 0, tm->n_vlib_mains * sizeof (xd->hqos_wt[0]));
273 
275  memset (xd->hqos_ht, 0, sizeof (xd->hqos_ht[0]));
276 
277  /* Allocate space for one SWQ per worker thread in the I/O TX thread data structure */
278  vec_validate (xd->hqos_ht->swq, worker_thread_count);
279 
280  /* SWQ */
281  for (i = 0; i < worker_thread_count + 1; i++)
282  {
283  u32 swq_flags = RING_F_SP_ENQ | RING_F_SC_DEQ;
284 
285  snprintf (name, sizeof (name), "SWQ-worker%u-to-device%u", i,
286  xd->device_index);
287  xd->hqos_ht->swq[i] =
288  rte_ring_create (name, hqos->swq_size, xd->cpu_socket, swq_flags);
289  if (xd->hqos_ht->swq[i] == NULL)
290  return clib_error_return (0,
291  "SWQ-worker%u-to-device%u: rte_ring_create err",
292  i, xd->device_index);
293  }
294 
295  /*
296  * HQoS
297  */
298 
299  /* HQoS port */
300  snprintf (name, sizeof (name), "HQoS%u", xd->device_index);
301  hqos->port.name = strdup (name);
302  if (hqos->port.name == NULL)
303  return clib_error_return (0, "HQoS%u: strdup err", xd->device_index);
304 
305  hqos->port.socket = rte_eth_dev_socket_id (xd->device_index);
306  if (hqos->port.socket == SOCKET_ID_ANY)
307  hqos->port.socket = 0;
308 
309  xd->hqos_ht->hqos = rte_sched_port_config (&hqos->port);
310  if (xd->hqos_ht->hqos == NULL)
311  return clib_error_return (0, "HQoS%u: rte_sched_port_config err",
312  xd->device_index);
313 
314  /* HQoS subport */
315  for (subport_id = 0; subport_id < hqos->port.n_subports_per_port;
316  subport_id++)
317  {
318  u32 pipe_id;
319 
320  rv =
321  rte_sched_subport_config (xd->hqos_ht->hqos, subport_id,
322  &hqos->subport[subport_id]);
323  if (rv)
324  return clib_error_return (0,
325  "HQoS%u subport %u: rte_sched_subport_config err (%d)",
326  xd->device_index, subport_id, rv);
327 
328  /* HQoS pipe */
329  for (pipe_id = 0; pipe_id < hqos->port.n_pipes_per_subport; pipe_id++)
330  {
331  u32 pos = subport_id * hqos->port.n_pipes_per_subport + pipe_id;
332  u32 profile_id = hqos->pipe_map[pos];
333 
334  rv =
335  rte_sched_pipe_config (xd->hqos_ht->hqos, subport_id, pipe_id,
336  profile_id);
337  if (rv)
338  return clib_error_return (0,
339  "HQoS%u subport %u pipe %u: rte_sched_pipe_config err (%d)",
340  xd->device_index, subport_id, pipe_id,
341  rv);
342  }
343  }
344 
345  /* Set up per-thread device data for the I/O TX thread */
346  xd->hqos_ht->hqos_burst_enq = hqos->burst_enq;
347  xd->hqos_ht->hqos_burst_deq = hqos->burst_deq;
348  vec_validate (xd->hqos_ht->pkts_enq, 2 * hqos->burst_enq - 1);
349  vec_validate (xd->hqos_ht->pkts_deq, hqos->burst_deq - 1);
350  xd->hqos_ht->pkts_enq_len = 0;
351  xd->hqos_ht->swq_pos = 0;
352  xd->hqos_ht->flush_count = 0;
353 
354  /* Set up per-thread device data for each worker thread */
355  for (i = 0; i < worker_thread_count + 1; i++)
356  {
357  u32 tid;
358  if (i)
359  tid = worker_thread_first + (i - 1);
360  else
361  tid = i;
362 
363  xd->hqos_wt[tid].swq = xd->hqos_ht->swq[i];
366  xd->hqos_wt[tid].hqos_field0_slabshr =
367  __builtin_ctzll (hqos->pktfield0_slabmask);
370  xd->hqos_wt[tid].hqos_field1_slabshr =
371  __builtin_ctzll (hqos->pktfield1_slabmask);
374  xd->hqos_wt[tid].hqos_field2_slabshr =
375  __builtin_ctzll (hqos->pktfield2_slabmask);
376  memcpy (xd->hqos_wt[tid].hqos_tc_table, hqos->tc_table,
377  sizeof (hqos->tc_table));
378  }
379 
380  return 0;
381 }
382 
383 /***
384  *
385  * HQoS run-time
386  *
387  ***/
388 /*
389  * dpdk_hqos_thread - Contains the main loop of an HQoS thread.
390  *
391  * w
392  * Information for the current thread
393  */
396 {
397  dpdk_main_t *dm = &dpdk_main;
398  u32 thread_index = vm->thread_index;
399  u32 dev_pos;
400 
401  dev_pos = 0;
402  while (1)
403  {
405 
406  u32 n_devs = vec_len (dm->devices_by_hqos_cpu[thread_index]);
407  if (dev_pos >= n_devs)
408  dev_pos = 0;
409 
411  vec_elt_at_index (dm->devices_by_hqos_cpu[thread_index], dev_pos);
412  dpdk_device_t *xd = vec_elt_at_index (dm->devices, dq->device);
413 
415  u32 device_index = xd->device_index;
416  u16 queue_id = dq->queue_id;
417 
418  struct rte_mbuf **pkts_enq = hqos->pkts_enq;
419  u32 pkts_enq_len = hqos->pkts_enq_len;
420  u32 swq_pos = hqos->swq_pos;
421  u32 n_swq = vec_len (hqos->swq), i;
422  u32 flush_count = hqos->flush_count;
423 
424  for (i = 0; i < n_swq; i++)
425  {
426  /* Get current SWQ for this device */
427  struct rte_ring *swq = hqos->swq[swq_pos];
428 
429  /* Read SWQ burst to packet buffer of this device */
430  pkts_enq_len += rte_ring_sc_dequeue_burst (swq,
431  (void **)
432  &pkts_enq[pkts_enq_len],
433 #if RTE_VERSION >= RTE_VERSION_NUM(17, 5, 0, 0)
434  hqos->hqos_burst_enq, 0);
435 #else
436  hqos->hqos_burst_enq);
437 #endif
438 
439  /* Get next SWQ for this device */
440  swq_pos++;
441  if (swq_pos >= n_swq)
442  swq_pos = 0;
443  hqos->swq_pos = swq_pos;
444 
445  /* HWQ TX enqueue when burst available */
446  if (pkts_enq_len >= hqos->hqos_burst_enq)
447  {
448  u32 n_pkts = rte_eth_tx_burst (device_index,
449  (uint16_t) queue_id,
450  pkts_enq,
451  (uint16_t) pkts_enq_len);
452 
453  for (; n_pkts < pkts_enq_len; n_pkts++)
454  rte_pktmbuf_free (pkts_enq[n_pkts]);
455 
456  pkts_enq_len = 0;
457  flush_count = 0;
458  break;
459  }
460  }
461  if (pkts_enq_len)
462  {
463  flush_count++;
464  if (PREDICT_FALSE (flush_count == HQOS_FLUSH_COUNT_THRESHOLD))
465  {
466  rte_sched_port_enqueue (hqos->hqos, pkts_enq, pkts_enq_len);
467 
468  pkts_enq_len = 0;
469  flush_count = 0;
470  }
471  }
472  hqos->pkts_enq_len = pkts_enq_len;
473  hqos->flush_count = flush_count;
474 
475  /* Advance to next device */
476  dev_pos++;
477  }
478 }
479 
482 {
483  dpdk_main_t *dm = &dpdk_main;
484  u32 thread_index = vm->thread_index;
485  u32 dev_pos;
486 
487  dev_pos = 0;
488  while (1)
489  {
491 
492  u32 n_devs = vec_len (dm->devices_by_hqos_cpu[thread_index]);
493  if (PREDICT_FALSE (n_devs == 0))
494  {
495  dev_pos = 0;
496  continue;
497  }
498  if (dev_pos >= n_devs)
499  dev_pos = 0;
500 
502  vec_elt_at_index (dm->devices_by_hqos_cpu[thread_index], dev_pos);
503  dpdk_device_t *xd = vec_elt_at_index (dm->devices, dq->device);
504 
506  u32 device_index = xd->device_index;
507  u16 queue_id = dq->queue_id;
508 
509  struct rte_mbuf **pkts_enq = hqos->pkts_enq;
510  struct rte_mbuf **pkts_deq = hqos->pkts_deq;
511  u32 pkts_enq_len = hqos->pkts_enq_len;
512  u32 swq_pos = hqos->swq_pos;
513  u32 n_swq = vec_len (hqos->swq), i;
514  u32 flush_count = hqos->flush_count;
515 
516  /*
517  * SWQ dequeue and HQoS enqueue for current device
518  */
519  for (i = 0; i < n_swq; i++)
520  {
521  /* Get current SWQ for this device */
522  struct rte_ring *swq = hqos->swq[swq_pos];
523 
524  /* Read SWQ burst to packet buffer of this device */
525  pkts_enq_len += rte_ring_sc_dequeue_burst (swq,
526  (void **)
527  &pkts_enq[pkts_enq_len],
528 #if RTE_VERSION >= RTE_VERSION_NUM(17, 5, 0, 0)
529  hqos->hqos_burst_enq, 0);
530 #else
531  hqos->hqos_burst_enq);
532 #endif
533 
534  /* Get next SWQ for this device */
535  swq_pos++;
536  if (swq_pos >= n_swq)
537  swq_pos = 0;
538  hqos->swq_pos = swq_pos;
539 
540  /* HQoS enqueue when burst available */
541  if (pkts_enq_len >= hqos->hqos_burst_enq)
542  {
543  rte_sched_port_enqueue (hqos->hqos, pkts_enq, pkts_enq_len);
544 
545  pkts_enq_len = 0;
546  flush_count = 0;
547  break;
548  }
549  }
550  if (pkts_enq_len)
551  {
552  flush_count++;
553  if (PREDICT_FALSE (flush_count == HQOS_FLUSH_COUNT_THRESHOLD))
554  {
555  rte_sched_port_enqueue (hqos->hqos, pkts_enq, pkts_enq_len);
556 
557  pkts_enq_len = 0;
558  flush_count = 0;
559  }
560  }
561  hqos->pkts_enq_len = pkts_enq_len;
562  hqos->flush_count = flush_count;
563 
564  /*
565  * HQoS dequeue and HWQ TX enqueue for current device
566  */
567  {
568  u32 pkts_deq_len, n_pkts;
569 
570  pkts_deq_len = rte_sched_port_dequeue (hqos->hqos,
571  pkts_deq,
572  hqos->hqos_burst_deq);
573 
574  for (n_pkts = 0; n_pkts < pkts_deq_len;)
575  n_pkts += rte_eth_tx_burst (device_index,
576  (uint16_t) queue_id,
577  &pkts_deq[n_pkts],
578  (uint16_t) (pkts_deq_len - n_pkts));
579  }
580 
581  /* Advance to next device */
582  dev_pos++;
583  }
584 }
585 
586 void
588 {
589  vlib_main_t *vm;
591  dpdk_main_t *dm = &dpdk_main;
592 
593  vm = vlib_get_main ();
594 
596 
597  clib_time_init (&vm->clib_time);
599 
600  /* Wait until the dpdk init sequence is complete */
601  while (tm->worker_thread_release == 0)
603 
604  if (vec_len (dm->devices_by_hqos_cpu[vm->thread_index]) == 0)
605  return
606  clib_error
607  ("current I/O TX thread does not have any devices assigned to it");
608 
611  else
613 }
614 
615 void
617 {
620  dpdk_hqos_thread (w);
621 }
622 
623 /* *INDENT-OFF* */
624 VLIB_REGISTER_THREAD (hqos_thread_reg, static) =
625 {
626  .name = "hqos-threads",
627  .short_name = "hqos-threads",
628  .function = dpdk_hqos_thread_fn,
629 };
630 /* *INDENT-ON* */
631 
632 /*
633  * HQoS run-time code to be called by the worker threads
634  */
635 #define BITFIELD(byte_array, slab_pos, slab_mask, slab_shr) \
636 ({ \
637  u64 slab = *((u64 *) &byte_array[slab_pos]); \
638  u64 val = (rte_be_to_cpu_64(slab) & slab_mask) >> slab_shr; \
639  val; \
640 })
641 
642 #define RTE_SCHED_PORT_HIERARCHY(subport, pipe, traffic_class, queue, color) \
643  ((((u64) (queue)) & 0x3) | \
644  ((((u64) (traffic_class)) & 0x3) << 2) | \
645  ((((u64) (color)) & 0x3) << 4) | \
646  ((((u64) (subport)) & 0xFFFF) << 16) | \
647  ((((u64) (pipe)) & 0xFFFFFFFF) << 32))
648 
649 void
651  struct rte_mbuf **pkts, u32 n_pkts)
652 {
653  u32 i;
654 
655  for (i = 0; i < (n_pkts & (~0x3)); i += 4)
656  {
657  struct rte_mbuf *pkt0 = pkts[i];
658  struct rte_mbuf *pkt1 = pkts[i + 1];
659  struct rte_mbuf *pkt2 = pkts[i + 2];
660  struct rte_mbuf *pkt3 = pkts[i + 3];
661 
662  u8 *pkt0_data = rte_pktmbuf_mtod (pkt0, u8 *);
663  u8 *pkt1_data = rte_pktmbuf_mtod (pkt1, u8 *);
664  u8 *pkt2_data = rte_pktmbuf_mtod (pkt2, u8 *);
665  u8 *pkt3_data = rte_pktmbuf_mtod (pkt3, u8 *);
666 
667  u64 pkt0_subport = BITFIELD (pkt0_data, hqos->hqos_field0_slabpos,
668  hqos->hqos_field0_slabmask,
669  hqos->hqos_field0_slabshr);
670  u64 pkt0_pipe = BITFIELD (pkt0_data, hqos->hqos_field1_slabpos,
671  hqos->hqos_field1_slabmask,
672  hqos->hqos_field1_slabshr);
673  u64 pkt0_dscp = BITFIELD (pkt0_data, hqos->hqos_field2_slabpos,
674  hqos->hqos_field2_slabmask,
675  hqos->hqos_field2_slabshr);
676  u32 pkt0_tc = hqos->hqos_tc_table[pkt0_dscp & 0x3F] >> 2;
677  u32 pkt0_tc_q = hqos->hqos_tc_table[pkt0_dscp & 0x3F] & 0x3;
678 
679  u64 pkt1_subport = BITFIELD (pkt1_data, hqos->hqos_field0_slabpos,
680  hqos->hqos_field0_slabmask,
681  hqos->hqos_field0_slabshr);
682  u64 pkt1_pipe = BITFIELD (pkt1_data, hqos->hqos_field1_slabpos,
683  hqos->hqos_field1_slabmask,
684  hqos->hqos_field1_slabshr);
685  u64 pkt1_dscp = BITFIELD (pkt1_data, hqos->hqos_field2_slabpos,
686  hqos->hqos_field2_slabmask,
687  hqos->hqos_field2_slabshr);
688  u32 pkt1_tc = hqos->hqos_tc_table[pkt1_dscp & 0x3F] >> 2;
689  u32 pkt1_tc_q = hqos->hqos_tc_table[pkt1_dscp & 0x3F] & 0x3;
690 
691  u64 pkt2_subport = BITFIELD (pkt2_data, hqos->hqos_field0_slabpos,
692  hqos->hqos_field0_slabmask,
693  hqos->hqos_field0_slabshr);
694  u64 pkt2_pipe = BITFIELD (pkt2_data, hqos->hqos_field1_slabpos,
695  hqos->hqos_field1_slabmask,
696  hqos->hqos_field1_slabshr);
697  u64 pkt2_dscp = BITFIELD (pkt2_data, hqos->hqos_field2_slabpos,
698  hqos->hqos_field2_slabmask,
699  hqos->hqos_field2_slabshr);
700  u32 pkt2_tc = hqos->hqos_tc_table[pkt2_dscp & 0x3F] >> 2;
701  u32 pkt2_tc_q = hqos->hqos_tc_table[pkt2_dscp & 0x3F] & 0x3;
702 
703  u64 pkt3_subport = BITFIELD (pkt3_data, hqos->hqos_field0_slabpos,
704  hqos->hqos_field0_slabmask,
705  hqos->hqos_field0_slabshr);
706  u64 pkt3_pipe = BITFIELD (pkt3_data, hqos->hqos_field1_slabpos,
707  hqos->hqos_field1_slabmask,
708  hqos->hqos_field1_slabshr);
709  u64 pkt3_dscp = BITFIELD (pkt3_data, hqos->hqos_field2_slabpos,
710  hqos->hqos_field2_slabmask,
711  hqos->hqos_field2_slabshr);
712  u32 pkt3_tc = hqos->hqos_tc_table[pkt3_dscp & 0x3F] >> 2;
713  u32 pkt3_tc_q = hqos->hqos_tc_table[pkt3_dscp & 0x3F] & 0x3;
714 
715  u64 pkt0_sched = RTE_SCHED_PORT_HIERARCHY (pkt0_subport,
716  pkt0_pipe,
717  pkt0_tc,
718  pkt0_tc_q,
719  0);
720  u64 pkt1_sched = RTE_SCHED_PORT_HIERARCHY (pkt1_subport,
721  pkt1_pipe,
722  pkt1_tc,
723  pkt1_tc_q,
724  0);
725  u64 pkt2_sched = RTE_SCHED_PORT_HIERARCHY (pkt2_subport,
726  pkt2_pipe,
727  pkt2_tc,
728  pkt2_tc_q,
729  0);
730  u64 pkt3_sched = RTE_SCHED_PORT_HIERARCHY (pkt3_subport,
731  pkt3_pipe,
732  pkt3_tc,
733  pkt3_tc_q,
734  0);
735 
736  pkt0->hash.sched.lo = pkt0_sched & 0xFFFFFFFF;
737  pkt0->hash.sched.hi = pkt0_sched >> 32;
738  pkt1->hash.sched.lo = pkt1_sched & 0xFFFFFFFF;
739  pkt1->hash.sched.hi = pkt1_sched >> 32;
740  pkt2->hash.sched.lo = pkt2_sched & 0xFFFFFFFF;
741  pkt2->hash.sched.hi = pkt2_sched >> 32;
742  pkt3->hash.sched.lo = pkt3_sched & 0xFFFFFFFF;
743  pkt3->hash.sched.hi = pkt3_sched >> 32;
744  }
745 
746  for (; i < n_pkts; i++)
747  {
748  struct rte_mbuf *pkt = pkts[i];
749 
750  u8 *pkt_data = rte_pktmbuf_mtod (pkt, u8 *);
751 
752  u64 pkt_subport = BITFIELD (pkt_data, hqos->hqos_field0_slabpos,
753  hqos->hqos_field0_slabmask,
754  hqos->hqos_field0_slabshr);
755  u64 pkt_pipe = BITFIELD (pkt_data, hqos->hqos_field1_slabpos,
756  hqos->hqos_field1_slabmask,
757  hqos->hqos_field1_slabshr);
758  u64 pkt_dscp = BITFIELD (pkt_data, hqos->hqos_field2_slabpos,
759  hqos->hqos_field2_slabmask,
760  hqos->hqos_field2_slabshr);
761  u32 pkt_tc = hqos->hqos_tc_table[pkt_dscp & 0x3F] >> 2;
762  u32 pkt_tc_q = hqos->hqos_tc_table[pkt_dscp & 0x3F] & 0x3;
763 
764  u64 pkt_sched = RTE_SCHED_PORT_HIERARCHY (pkt_subport,
765  pkt_pipe,
766  pkt_tc,
767  pkt_tc_q,
768  0);
769 
770  pkt->hash.sched.lo = pkt_sched & 0xFFFFFFFF;
771  pkt->hash.sched.hi = pkt_sched >> 32;
772  }
773 }
774 
775 /*
776  * fd.io coding-style-patch-verification: ON
777  *
778  * Local Variables:
779  * eval: (c-set-style "gnu")
780  * End:
781  */
VLIB_REGISTER_THREAD(hqos_thread_reg, static)
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:436
sll srl srl sll sra u16x4 i
Definition: vector_sse2.h:337
static struct rte_sched_subport_params hqos_subport_params_default
Definition: hqos.c:144
dpdk_main_t dpdk_main
Definition: init.c:36
#define clib_error(format, args...)
Definition: error.h:62
#define NULL
Definition: clib.h:55
u32 thread_index
Definition: main.h:159
dpdk_device_and_queue_t ** devices_by_hqos_cpu
Definition: dpdk.h:338
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
Definition: vec.h:561
struct rte_sched_port_params port
Definition: dpdk.h:262
struct rte_mbuf ** pkts_enq
Definition: dpdk.h:135
struct rte_ring ** swq
Definition: dpdk.h:134
struct rte_sched_port * hqos
Definition: dpdk.h:137
clib_time_t clib_time
Definition: main.h:62
#define vec_validate_aligned(V, I, A)
Make sure vector is long enough for given index (no header, specified alignment)
Definition: vec.h:447
#define BITFIELD(byte_array, slab_pos, slab_mask, slab_shr)
Definition: hqos.c:635
static void vlib_worker_thread_barrier_check(void)
Definition: threads.h:356
struct rte_sched_pipe_params * pipe
Definition: dpdk.h:264
#define static_always_inline
Definition: clib.h:85
struct rte_mbuf ** pkts_deq
Definition: dpdk.h:136
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
#define clib_error_return(e, args...)
Definition: error.h:99
unsigned long u64
Definition: types.h:89
u32 device_index
Definition: dpdk.h:151
dpdk_device_hqos_per_worker_thread_t * hqos_wt
Definition: dpdk.h:197
void * thread_mheap
Definition: threads.h:95
static_always_inline void dpdk_hqos_thread_internal_hqos_dbg_bypass(vlib_main_t *vm)
Definition: hqos.c:395
#define PREDICT_FALSE(x)
Definition: clib.h:97
void clib_time_init(clib_time_t *c)
Definition: time.c:175
int dpdk_hqos_validate_mask(u64 mask, u32 n)
Definition: hqos.c:169
#define HQOS_FLUSH_COUNT_THRESHOLD
Definition: dpdk.h:242
static_always_inline uword vlib_get_thread_index(void)
Definition: threads.h:185
dpdk_device_t * devices
Definition: dpdk.h:337
static void * clib_mem_set_heap(void *heap)
Definition: mem.h:223
void vlib_worker_thread_init(vlib_worker_thread_t *w)
Definition: threads.c:417
#define ASSERT(truth)
unsigned int u32
Definition: types.h:88
#define DPDK_HQOS_DBG_BYPASS
Definition: dpdk.h:238
void dpdk_hqos_thread_fn(void *arg)
Definition: hqos.c:616
clib_error_t * dpdk_port_setup_hqos(dpdk_device_t *xd, dpdk_device_config_hqos_t *hqos)
Definition: hqos.c:248
Bitmaps built as vectors of machine words.
dpdk_device_hqos_per_hqos_thread_t * hqos_ht
Definition: dpdk.h:198
static_always_inline void dpdk_hqos_thread_internal(vlib_main_t *vm)
Definition: hqos.c:481
uword * thread_registrations_by_name
Definition: threads.h:261
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:23
void dpdk_hqos_metadata_set(dpdk_device_hqos_per_worker_thread_t *hqos, struct rte_mbuf **pkts, u32 n_pkts)
Definition: hqos.c:650
u64 uword
Definition: types.h:112
void dpdk_device_config_hqos_default(dpdk_device_config_hqos_t *hqos)
Definition: hqos.c:206
unsigned short u16
Definition: types.h:57
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
unsigned char u8
Definition: types.h:56
uint32_t * pipe_map
Definition: dpdk.h:265
void dpdk_hqos_thread(vlib_worker_thread_t *w)
Definition: hqos.c:587
#define hash_get_mem(h, key)
Definition: hash.h:268
static vlib_thread_main_t * vlib_get_thread_main()
Definition: global_funcs.h:32
struct rte_sched_subport_params * subport
Definition: dpdk.h:263
i8 cpu_socket
Definition: dpdk.h:167
#define RTE_SCHED_PORT_HIERARCHY(subport, pipe, traffic_class, queue, color)
Definition: hqos.c:642
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:67
void dpdk_device_config_hqos_pipe_profile_default(dpdk_device_config_hqos_t *hqos, u32 pipe_profile_id)
Definition: hqos.c:198
volatile u32 worker_thread_release
Definition: threads.h:302
static struct rte_sched_pipe_params hqos_pipe_params_default
Definition: hqos.c:151
CLIB vectors are ubiquitous dynamically resized arrays with by user defined "headers".