1 /* SPDX-License-Identifier: BSD-3-Clause */ 2 /* Copyright(c) 2007-2022 Intel Corporation */ 3 /* $FreeBSD$ */ 4 /** 5 ***************************************************************************** 6 * @file dc_stats.c 7 * 8 * @ingroup Dc_DataCompression 9 * 10 * @description 11 * Implementation of the Data Compression stats operations. 12 * 13 *****************************************************************************/ 14 15 /* 16 ******************************************************************************* 17 * Include public/global header files 18 ******************************************************************************* 19 */ 20 #include "cpa.h" 21 #include "cpa_dc.h" 22 #include "icp_accel_devices.h" 23 #include "icp_adf_debug.h" 24 /* 25 ******************************************************************************* 26 * Include private header files 27 ******************************************************************************* 28 */ 29 #include "lac_common.h" 30 #include "icp_accel_devices.h" 31 #include "sal_statistics.h" 32 #include "dc_session.h" 33 #include "dc_datapath.h" 34 #include "lac_mem_pools.h" 35 #include "sal_service_state.h" 36 #include "sal_types_compression.h" 37 #include "dc_stats.h" 38 39 CpaStatus 40 dcStatsInit(sal_compression_service_t *pService) 41 { 42 CpaStatus status = CPA_STATUS_SUCCESS; 43 44 pService->pCompStatsArr = 45 LAC_OS_MALLOC(COMPRESSION_NUM_STATS * sizeof(QatUtilsAtomic)); 46 47 if (pService->pCompStatsArr == NULL) { 48 status = CPA_STATUS_RESOURCE; 49 } 50 51 if (CPA_STATUS_SUCCESS == status) { 52 COMPRESSION_STATS_RESET(pService); 53 } 54 55 return status; 56 } 57 58 void 59 dcStatsFree(sal_compression_service_t *pService) 60 { 61 if (NULL != pService->pCompStatsArr) { 62 LAC_OS_FREE(pService->pCompStatsArr); 63 } 64 } 65 66 CpaStatus 67 cpaDcGetStats(CpaInstanceHandle dcInstance, CpaDcStats *pStatistics) 68 { 69 sal_compression_service_t *pService = NULL; 70 CpaInstanceHandle insHandle = NULL; 71 72 if (CPA_INSTANCE_HANDLE_SINGLE == dcInstance) { 73 insHandle = dcGetFirstHandle(); 74 } else { 75 insHandle = dcInstance; 76 } 77 78 pService = (sal_compression_service_t *)insHandle; 79 80 LAC_CHECK_NULL_PARAM(insHandle); 81 LAC_CHECK_NULL_PARAM(pStatistics); 82 SAL_RUNNING_CHECK(insHandle); 83 84 SAL_CHECK_INSTANCE_TYPE(insHandle, SAL_SERVICE_TYPE_COMPRESSION); 85 86 /* Retrieves the statistics for compression */ 87 COMPRESSION_STATS_GET(pStatistics, pService); 88 89 return CPA_STATUS_SUCCESS; 90 } 91