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