xref: /freebsd/sys/dev/qat/qat_api/common/compression/include/dc_stats.h (revision 71625ec9ad2a9bc8c09784fbd23b759830e0ee5f)
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /* Copyright(c) 2007-2022 Intel Corporation */
3 /**
4  *****************************************************************************
5  * @file dc_stats.h
6  *
7  * @ingroup Dc_DataCompression
8  *
9  * @description
10  *      Definition of the Data Compression stats parameters.
11  *
12  *****************************************************************************/
13 #ifndef DC_STATS_H_
14 #define DC_STATS_H_
15 
16 /* Number of Compression statistics */
17 #define COMPRESSION_NUM_STATS (sizeof(CpaDcStats) / sizeof(Cpa64U))
18 
19 #define COMPRESSION_STAT_INC(statistic, pService)                              \
20 	do {                                                                   \
21 		if (CPA_TRUE ==                                                \
22 		    pService->generic_service_info.stats->bDcStatsEnabled) {   \
23 			qatUtilsAtomicInc(                                     \
24 			    &pService->pCompStatsArr[offsetof(CpaDcStats,      \
25 							      statistic) /     \
26 						     sizeof(Cpa64U)]);         \
27 		}                                                              \
28 	} while (0)
29 
30 /* Macro to get all Compression stats (from internal array of atomics) */
31 #define COMPRESSION_STATS_GET(compStats, pService)                             \
32 	do {                                                                   \
33 		int i;                                                         \
34 		for (i = 0; i < COMPRESSION_NUM_STATS; i++) {                  \
35 			((Cpa64U *)compStats)[i] =                             \
36 			    qatUtilsAtomicGet(&pService->pCompStatsArr[i]);    \
37 		}                                                              \
38 	} while (0)
39 
40 /* Macro to reset all Compression stats */
41 #define COMPRESSION_STATS_RESET(pService)                                      \
42 	do {                                                                   \
43 		int i;                                                         \
44 		for (i = 0; i < COMPRESSION_NUM_STATS; i++) {                  \
45 			qatUtilsAtomicSet(0, &pService->pCompStatsArr[i]);     \
46 		}                                                              \
47 	} while (0)
48 
49 /**
50 *******************************************************************************
51 * @ingroup Dc_DataCompression
52 *      Initialises the compression stats
53 *
54 * @description
55 *      This function allocates and initialises the stats array to 0
56 *
57 * @param[in] pService          Pointer to a compression service structure
58 *
59 * @retval CPA_STATUS_SUCCESS   initialisation successful
60 * @retval CPA_STATUS_RESOURCE  array allocation failed
61 *
62 *****************************************************************************/
63 CpaStatus dcStatsInit(sal_compression_service_t *pService);
64 
65 /**
66 *******************************************************************************
67 * @ingroup Dc_DataCompression
68 *      Frees the compression stats
69 *
70 * @description
71 *      This function frees the stats array
72 *
73 * @param[in] pService          Pointer to a compression service structure
74 *
75 * @retval None
76 *
77 *****************************************************************************/
78 void dcStatsFree(sal_compression_service_t *pService);
79 
80 #endif /* DC_STATS_H_ */
81