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;
34 rte_meter_srtcm_config(struct rte_meter_srtcm *m, struct rte_meter_srtcm_params *params)
38 /* Check input parameters */
39 if ((m == NULL) || (params == NULL)) {
43 if ((params->cir == 0) || ((params->cbs == 0) && (params->ebs == 0))) {
47 /* Initialize srTCM run-time structure */
48 hz = rte_get_tsc_hz();
49 m->time = rte_get_tsc_cycles();
50 m->tc = m->cbs = params->cbs;
51 m->te = m->ebs = params->ebs;
52 rte_meter_get_tb_params(hz, params->cir, &m->cir_period, &m->cir_bytes_per_period);
54 RTE_LOG(INFO, METER, "Low level srTCM config: \n"
55 "\tCIR period = %" PRIu64 ", CIR bytes per period = %" PRIu64 "\n",
56 m->cir_period, m->cir_bytes_per_period);
62 rte_meter_trtcm_config(struct rte_meter_trtcm *m, struct rte_meter_trtcm_params *params)
66 /* Check input parameters */
67 if ((m == NULL) || (params == NULL)) {
71 if ((params->cir == 0) || (params->pir == 0) || (params->pir < params->cir) ||
72 (params->cbs == 0) || (params->pbs == 0)) {
76 /* Initialize trTCM run-time structure */
77 hz = rte_get_tsc_hz();
78 m->time_tc = m->time_tp = rte_get_tsc_cycles();
79 m->tc = m->cbs = params->cbs;
80 m->tp = m->pbs = params->pbs;
81 rte_meter_get_tb_params(hz, params->cir, &m->cir_period, &m->cir_bytes_per_period);
82 rte_meter_get_tb_params(hz, params->pir, &m->pir_period, &m->pir_bytes_per_period);
84 RTE_LOG(INFO, METER, "Low level trTCM config: \n"
85 "\tCIR period = %" PRIu64 ", CIR bytes per period = %" PRIu64 "\n"
86 "\tPIR period = %" PRIu64 ", PIR bytes per period = %" PRIu64 "\n",
87 m->cir_period, m->cir_bytes_per_period,
88 m->pir_period, m->pir_bytes_per_period);