199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause 299a2dd95SBruce Richardson * Copyright(c) 2017 Intel Corporation 399a2dd95SBruce Richardson */ 499a2dd95SBruce Richardson 599a2dd95SBruce Richardson #ifndef _RTE_BITRATE_H_ 699a2dd95SBruce Richardson #define _RTE_BITRATE_H_ 799a2dd95SBruce Richardson 899a2dd95SBruce Richardson #include <stdint.h> 999a2dd95SBruce Richardson 1099a2dd95SBruce Richardson #ifdef __cplusplus 1199a2dd95SBruce Richardson extern "C" { 1299a2dd95SBruce Richardson #endif 1399a2dd95SBruce Richardson 1499a2dd95SBruce Richardson /** 1599a2dd95SBruce Richardson * Bitrate statistics data structure. 1699a2dd95SBruce Richardson * This data structure is intentionally opaque. 1799a2dd95SBruce Richardson */ 1899a2dd95SBruce Richardson struct rte_stats_bitrates; 1999a2dd95SBruce Richardson 2099a2dd95SBruce Richardson 2199a2dd95SBruce Richardson /** 2299a2dd95SBruce Richardson * Allocate a bitrate statistics structure 2399a2dd95SBruce Richardson * 2499a2dd95SBruce Richardson * @return 2599a2dd95SBruce Richardson * - Pointer to structure on success 2699a2dd95SBruce Richardson * - NULL on error (zmalloc failure) 2799a2dd95SBruce Richardson */ 2899a2dd95SBruce Richardson struct rte_stats_bitrates *rte_stats_bitrate_create(void); 2999a2dd95SBruce Richardson 3099a2dd95SBruce Richardson /** 3199a2dd95SBruce Richardson * Free bitrate statistics structure 3299a2dd95SBruce Richardson * 3399a2dd95SBruce Richardson * @param bitrate_data 3499a2dd95SBruce Richardson * Pointer allocated by rte_stats_bitrate_create() 35*448e01f1SStephen Hemminger * If bitrate_data is NULL, no operation is performed. 3699a2dd95SBruce Richardson */ 3799a2dd95SBruce Richardson void rte_stats_bitrate_free(struct rte_stats_bitrates *bitrate_data); 3899a2dd95SBruce Richardson 3999a2dd95SBruce Richardson /** 4099a2dd95SBruce Richardson * Register bitrate statistics with the metric library. 4199a2dd95SBruce Richardson * 4299a2dd95SBruce Richardson * @param bitrate_data 4399a2dd95SBruce Richardson * Pointer allocated by rte_stats_bitrate_create() 4499a2dd95SBruce Richardson * 4599a2dd95SBruce Richardson * @return 4699a2dd95SBruce Richardson * Zero on success 4799a2dd95SBruce Richardson * Negative on error 4899a2dd95SBruce Richardson */ 4999a2dd95SBruce Richardson int rte_stats_bitrate_reg(struct rte_stats_bitrates *bitrate_data); 5099a2dd95SBruce Richardson 5199a2dd95SBruce Richardson 5299a2dd95SBruce Richardson /** 5399a2dd95SBruce Richardson * Calculate statistics for current time window. The period with which 5499a2dd95SBruce Richardson * this function is called should be the intended sampling window width. 5599a2dd95SBruce Richardson * 5699a2dd95SBruce Richardson * @param bitrate_data 5799a2dd95SBruce Richardson * Bitrate statistics data pointer 5899a2dd95SBruce Richardson * 5999a2dd95SBruce Richardson * @param port_id 6099a2dd95SBruce Richardson * Port id to calculate statistics for 6199a2dd95SBruce Richardson * 6299a2dd95SBruce Richardson * @return 6399a2dd95SBruce Richardson * - Zero on success 6499a2dd95SBruce Richardson * - Negative value on error 6599a2dd95SBruce Richardson */ 6699a2dd95SBruce Richardson int rte_stats_bitrate_calc(struct rte_stats_bitrates *bitrate_data, 6799a2dd95SBruce Richardson uint16_t port_id); 6899a2dd95SBruce Richardson 6999a2dd95SBruce Richardson #ifdef __cplusplus 7099a2dd95SBruce Richardson } 7199a2dd95SBruce Richardson #endif 7299a2dd95SBruce Richardson 7399a2dd95SBruce Richardson #endif /* _RTE_BITRATE_H_ */ 74