1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2020 Intel Corporation
3 */
4
5 #include <errno.h>
6 #include <stdlib.h>
7 #include <string.h>
8
9 #include "rte_sched_log.h"
10 #include "rte_pie.h"
11
12 #ifdef __INTEL_COMPILER
13 #pragma warning(disable:2259) /* conversion may lose significant bits */
14 #endif
15
16 int
rte_pie_rt_data_init(struct rte_pie * pie)17 rte_pie_rt_data_init(struct rte_pie *pie)
18 {
19 if (pie == NULL) {
20 SCHED_LOG(ERR, "%s: Invalid addr for pie", __func__);
21 return -EINVAL;
22 }
23
24 memset(pie, 0, sizeof(*pie));
25
26 return 0;
27 }
28
29 int
rte_pie_config_init(struct rte_pie_config * pie_cfg,const uint16_t qdelay_ref,const uint16_t dp_update_interval,const uint16_t max_burst,const uint16_t tailq_th)30 rte_pie_config_init(struct rte_pie_config *pie_cfg,
31 const uint16_t qdelay_ref,
32 const uint16_t dp_update_interval,
33 const uint16_t max_burst,
34 const uint16_t tailq_th)
35 {
36 uint64_t tsc_hz = rte_get_tsc_hz();
37
38 if (pie_cfg == NULL)
39 return -1;
40
41 if (qdelay_ref <= 0) {
42 SCHED_LOG(ERR,
43 "%s: Incorrect value for qdelay_ref", __func__);
44 return -EINVAL;
45 }
46
47 if (dp_update_interval <= 0) {
48 SCHED_LOG(ERR,
49 "%s: Incorrect value for dp_update_interval", __func__);
50 return -EINVAL;
51 }
52
53 if (max_burst <= 0) {
54 SCHED_LOG(ERR,
55 "%s: Incorrect value for max_burst", __func__);
56 return -EINVAL;
57 }
58
59 if (tailq_th <= 0) {
60 SCHED_LOG(ERR,
61 "%s: Incorrect value for tailq_th", __func__);
62 return -EINVAL;
63 }
64
65 pie_cfg->qdelay_ref = (tsc_hz * qdelay_ref) / 1000;
66 pie_cfg->dp_update_interval = (tsc_hz * dp_update_interval) / 1000;
67 pie_cfg->max_burst = (tsc_hz * max_burst) / 1000;
68 pie_cfg->tailq_th = tailq_th;
69
70 return 0;
71 }
72