1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
9 #include <rte_common.h>
11 #include <rte_cycles.h>
13 #include "rte_meter.h"
15 #ifndef RTE_METER_TB_PERIOD_MIN
16 #define RTE_METER_TB_PERIOD_MIN 100
20 rte_meter_get_tb_params(uint64_t hz, uint64_t rate, uint64_t *tb_period, uint64_t *tb_bytes_per_period)
25 *tb_bytes_per_period = 0;
26 *tb_period = RTE_METER_TB_PERIOD_MIN;
30 period = ((double) hz) / ((double) rate);
32 if (period >= RTE_METER_TB_PERIOD_MIN) {
33 *tb_bytes_per_period = 1;
34 *tb_period = (uint64_t) period;
36 *tb_bytes_per_period = (uint64_t) ceil(RTE_METER_TB_PERIOD_MIN / period);
37 *tb_period = (hz * (*tb_bytes_per_period)) / rate;
42 rte_meter_srtcm_profile_config(struct rte_meter_srtcm_profile *p,
43 struct rte_meter_srtcm_params *params)
45 uint64_t hz = rte_get_tsc_hz();
47 /* Check input parameters */
51 ((params->cbs == 0) && (params->ebs == 0)))
54 /* Initialize srTCM run-time structure */
57 rte_meter_get_tb_params(hz, params->cir, &p->cir_period,
58 &p->cir_bytes_per_period);
64 rte_meter_srtcm_config(struct rte_meter_srtcm *m,
65 struct rte_meter_srtcm_profile *p)
67 /* Check input parameters */
68 if ((m == NULL) || (p == NULL))
71 /* Initialize srTCM run-time structure */
72 m->time = rte_get_tsc_cycles();
80 rte_meter_trtcm_profile_config(struct rte_meter_trtcm_profile *p,
81 struct rte_meter_trtcm_params *params)
83 uint64_t hz = rte_get_tsc_hz();
85 /* Check input parameters */
90 (params->pir < params->cir) ||
95 /* Initialize trTCM run-time structure */
98 rte_meter_get_tb_params(hz, params->cir, &p->cir_period,
99 &p->cir_bytes_per_period);
100 rte_meter_get_tb_params(hz, params->pir, &p->pir_period,
101 &p->pir_bytes_per_period);
107 rte_meter_trtcm_config(struct rte_meter_trtcm *m,
108 struct rte_meter_trtcm_profile *p)
110 /* Check input parameters */
111 if ((m == NULL) || (p == NULL))
114 /* Initialize trTCM run-time structure */
115 m->time_tc = m->time_tp = rte_get_tsc_cycles();
123 rte_meter_trtcm_rfc4115_profile_config(
124 struct rte_meter_trtcm_rfc4115_profile *p,
125 struct rte_meter_trtcm_rfc4115_params *params)
127 uint64_t hz = rte_get_tsc_hz();
129 /* Check input parameters */
132 (params->cir != 0 && params->cbs == 0) ||
133 (params->eir != 0 && params->ebs == 0))
136 /* Initialize trTCM run-time structure */
137 p->cbs = params->cbs;
138 p->ebs = params->ebs;
139 rte_meter_get_tb_params(hz, params->cir, &p->cir_period,
140 &p->cir_bytes_per_period);
141 rte_meter_get_tb_params(hz, params->eir, &p->eir_period,
142 &p->eir_bytes_per_period);
148 rte_meter_trtcm_rfc4115_config(
149 struct rte_meter_trtcm_rfc4115 *m,
150 struct rte_meter_trtcm_rfc4115_profile *p)
152 /* Check input parameters */
153 if ((m == NULL) || (p == NULL))
156 /* Initialize trTCM run-time structure */
157 m->time_tc = m->time_te = rte_get_tsc_cycles();