ethdev: remove unnecessary null check
[dpdk.git] / lib / sched / rte_pie.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2020 Intel Corporation
3  */
4
5 #include <stdlib.h>
6
7 #include "rte_pie.h"
8 #include <rte_common.h>
9 #include <rte_cycles.h>
10 #include <rte_malloc.h>
11
12 #ifdef __INTEL_COMPILER
13 #pragma warning(disable:2259) /* conversion may lose significant bits */
14 #endif
15
16 int
17 rte_pie_rt_data_init(struct rte_pie *pie)
18 {
19         if (pie == NULL) {
20                 /* Allocate memory to use the PIE data structure */
21                 pie = rte_malloc(NULL, sizeof(struct rte_pie), 0);
22
23                 if (pie == NULL)
24                         RTE_LOG(ERR, SCHED, "%s: Memory allocation fails\n", __func__);
25
26                 return -1;
27         }
28
29         pie->active = 0;
30         pie->in_measurement = 0;
31         pie->departed_bytes_count = 0;
32         pie->start_measurement = 0;
33         pie->last_measurement = 0;
34         pie->qlen = 0;
35         pie->avg_dq_time = 0;
36         pie->burst_allowance = 0;
37         pie->qdelay_old = 0;
38         pie->drop_prob = 0;
39         pie->accu_prob = 0;
40
41         return 0;
42 }
43
44 int
45 rte_pie_config_init(struct rte_pie_config *pie_cfg,
46         const uint16_t qdelay_ref,
47         const uint16_t dp_update_interval,
48         const uint16_t max_burst,
49         const uint16_t tailq_th)
50 {
51         uint64_t tsc_hz = rte_get_tsc_hz();
52
53         if (pie_cfg == NULL)
54                 return -1;
55
56         if (qdelay_ref <= 0) {
57                 RTE_LOG(ERR, SCHED,
58                         "%s: Incorrect value for qdelay_ref\n", __func__);
59                 return -EINVAL;
60         }
61
62         if (dp_update_interval <= 0) {
63                 RTE_LOG(ERR, SCHED,
64                         "%s: Incorrect value for dp_update_interval\n", __func__);
65                 return -EINVAL;
66         }
67
68         if (max_burst <= 0) {
69                 RTE_LOG(ERR, SCHED,
70                         "%s: Incorrect value for max_burst\n", __func__);
71                 return -EINVAL;
72         }
73
74         if (tailq_th <= 0) {
75                 RTE_LOG(ERR, SCHED,
76                         "%s: Incorrect value for tailq_th\n", __func__);
77                 return -EINVAL;
78         }
79
80         pie_cfg->qdelay_ref = (tsc_hz * qdelay_ref) / 1000;
81         pie_cfg->dp_update_interval = (tsc_hz * dp_update_interval) / 1000;
82         pie_cfg->max_burst = (tsc_hz * max_burst) / 1000;
83         pie_cfg->tailq_th = tailq_th;
84
85         return 0;
86 }