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)
22 double period = ((double) hz) / ((double) rate);
24 if (period >= RTE_METER_TB_PERIOD_MIN) {
25 *tb_bytes_per_period = 1;
26 *tb_period = (uint64_t) period;
28 *tb_bytes_per_period = (uint64_t) ceil(RTE_METER_TB_PERIOD_MIN / period);
29 *tb_period = (hz * (*tb_bytes_per_period)) / rate;
33 int __rte_experimental
34 rte_meter_srtcm_profile_config(struct rte_meter_srtcm_profile *p,
35 struct rte_meter_srtcm_params *params)
37 uint64_t hz = rte_get_tsc_hz();
39 /* Check input parameters */
43 ((params->cbs == 0) && (params->ebs == 0)))
46 /* Initialize srTCM run-time structure */
49 rte_meter_get_tb_params(hz, params->cir, &p->cir_period,
50 &p->cir_bytes_per_period);
56 rte_meter_srtcm_config(struct rte_meter_srtcm *m,
57 struct rte_meter_srtcm_profile *p)
59 /* Check input parameters */
60 if ((m == NULL) || (p == NULL))
63 /* Initialize srTCM run-time structure */
64 m->time = rte_get_tsc_cycles();
71 int __rte_experimental
72 rte_meter_trtcm_profile_config(struct rte_meter_trtcm_profile *p,
73 struct rte_meter_trtcm_params *params)
75 uint64_t hz = rte_get_tsc_hz();
77 /* Check input parameters */
82 (params->pir < params->cir) ||
87 /* Initialize trTCM run-time structure */
90 rte_meter_get_tb_params(hz, params->cir, &p->cir_period,
91 &p->cir_bytes_per_period);
92 rte_meter_get_tb_params(hz, params->pir, &p->pir_period,
93 &p->pir_bytes_per_period);
99 rte_meter_trtcm_config(struct rte_meter_trtcm *m,
100 struct rte_meter_trtcm_profile *p)
102 /* Check input parameters */
103 if ((m == NULL) || (p == NULL))
106 /* Initialize trTCM run-time structure */
107 m->time_tc = m->time_tp = rte_get_tsc_cycles();