diff --git a/module/zfs/gzip.c b/module/zfs/gzip.c index 78ffddc8aa6b..e5871a5ff413 100644 --- a/module/zfs/gzip.c +++ b/module/zfs/gzip.c @@ -57,9 +57,9 @@ gzip_compress(void *s_start, void *d_start, size_t s_len, size_t d_len, int n) ASSERT(d_len <= s_len); - if (use_qat(s_len)) { - if (qat_compress(0, s_start, s_len, d_start, d_len, &dstlen) == - CPA_STATUS_SUCCESS) + if (qat_should_use(s_len)) { + if (qat_compress(QAT_COMPRESS, s_start, + s_len, d_start, d_len, &dstlen) == CPA_STATUS_SUCCESS) return ((size_t)dstlen); /* if hardware compress fail, do it again with software */ } @@ -83,9 +83,9 @@ gzip_decompress(void *s_start, void *d_start, size_t s_len, size_t d_len, int n) ASSERT(d_len >= s_len); - if (use_qat(d_len)) { - if (qat_compress(1, s_start, s_len, d_start, d_len, &dstlen) == - CPA_STATUS_SUCCESS) + if (qat_should_use(d_len)) { + if (qat_compress(QAT_DECOMPRESS, s_start, s_len, + d_start, d_len, &dstlen) == CPA_STATUS_SUCCESS) return (0); /* if hardware de-compress fail, do it again with software */ } diff --git a/module/zfs/qat_compress.c b/module/zfs/qat_compress.c index 38df250dacae..e36cd6833849 100644 --- a/module/zfs/qat_compress.c +++ b/module/zfs/qat_compress.c @@ -71,8 +71,13 @@ static CpaDcSessionHandle session_handles[MAX_INSTANCES]; static CpaBufferList **buffer_array[MAX_INSTANCES]; static Cpa16U num_inst = 0; static Cpa16U inst = 0; -static int qat_init_done = 0; -int zfs_qat_disable = B_FALSE; +static boolean_t qat_init_done = B_FALSE; +int zfs_qat_disable = 0; + +#define QAT_STAT_INCR(stat, val) \ + atomic_add_64(&qat_stats.stat.value.ui64, (val)); +#define QAT_STAT_BUMP(stat) \ + QAT_STAT_INCR(stat, 1); #define PHYS_CONTIG_ALLOC(pp_mem_addr, size_bytes) \ mem_alloc_contig((void *)(pp_mem_addr), (size_bytes)) @@ -99,7 +104,7 @@ qat_dc_callback(void *p_callback, CpaStatus status) static inline CpaStatus mem_alloc_contig(void **pp_mem_addr, Cpa32U size_bytes) { - *pp_mem_addr = kmalloc_node(size_bytes, GFP_KERNEL, 0); + *pp_mem_addr = kmalloc(size_bytes, GFP_KERNEL); if (NULL == *pp_mem_addr) return (CPA_STATUS_RESOURCE); return (CPA_STATUS_SUCCESS); @@ -132,8 +137,12 @@ qat_clean(void) buff_num++) { CpaBufferList *buffer_inter = buffer_array[inst][buff_num]; - PHYS_CONTIG_FREE(buffer_inter->pBuffers->pData); - PHYS_CONTIG_FREE(buffer_inter->pBuffers); + if (buffer_inter->pBuffers) { + PHYS_CONTIG_FREE( + buffer_inter->pBuffers->pData); + PHYS_CONTIG_FREE( + buffer_inter->pBuffers); + } PHYS_CONTIG_FREE( buffer_inter->pPrivateMetaData); PHYS_CONTIG_FREE(buffer_inter); @@ -142,7 +151,7 @@ qat_clean(void) } num_inst = 0; - qat_init_done = 0; + qat_init_done = B_FALSE; } int @@ -157,9 +166,6 @@ qat_init(void) CpaDcSessionSetupData sd = {0}; Cpa16U inst; - if (qat_init_done != 0) - return (0); - status = cpaDcGetNumInstances(&num_inst); if (status != CPA_STATUS_SUCCESS || num_inst == 0) return (-1); @@ -215,6 +221,9 @@ qat_init(void) status = PHYS_CONTIG_ALLOC( &buffer_array[inst][buff_num]->pBuffers-> pData, 2 * QAT_MAX_BUF_SIZE); + if (status != CPA_STATUS_SUCCESS) + goto fail; + buffer_array[inst][buff_num]->numBuffers = 1; buffer_array[inst][buff_num]->pBuffers-> dataLenInBytes = 2 * QAT_MAX_BUF_SIZE; @@ -248,16 +257,16 @@ qat_init(void) if (status != CPA_STATUS_SUCCESS) goto fail; } + qat_ksp = kstat_create("zfs", 0, "qat", "misc", KSTAT_TYPE_NAMED, sizeof (qat_stats) / sizeof (kstat_named_t), KSTAT_FLAG_VIRTUAL); - if (qat_ksp != NULL) { qat_ksp->ks_data = &qat_stats; kstat_install(qat_ksp); } - qat_init_done = 1; + qat_init_done = B_TRUE; return (0); fail: qat_clean(); @@ -275,20 +284,20 @@ qat_fini(void) } } -int -use_qat(size_t s_len) +boolean_t +qat_should_use(size_t s_len) { - if (zfs_qat_disable == B_TRUE || - qat_init_done == 0 || + if (zfs_qat_disable || + !qat_init_done || s_len < QAT_MIN_BUF_SIZE || s_len > QAT_MAX_BUF_SIZE) { - return (0); + return (B_FALSE); } - return (1); + return (B_TRUE); } int -qat_compress(int dir, char *src, int src_len, +qat_compress(qat_compress_dir_t dir, char *src, int src_len, char *dst, int dst_len, size_t *c_len) { CpaInstanceHandle dc_inst_handle; @@ -407,7 +416,7 @@ qat_compress(int dir, char *src, int src_len, init_completion(&complete); - if (dir == 0) /* compress */ { + if (dir == QAT_COMPRESS) { QAT_STAT_BUMP(comp_requests); QAT_STAT_INCR(comp_total_in_bytes, src_len); diff --git a/module/zfs/qat_compress.h b/module/zfs/qat_compress.h index 9960287ea9c2..daaff984a7a7 100644 --- a/module/zfs/qat_compress.h +++ b/module/zfs/qat_compress.h @@ -26,10 +26,15 @@ #include #include "cpa.h" #include "dc/cpa_dc.h" +typedef enum qat_compress_dir { + QAT_COMPRESS = 0, + QAT_DECOMPRESS = 1, +} qat_compress_dir_t; extern int qat_init(void); extern void qat_fini(void); -extern int use_qat(size_t s_len); -extern int qat_compress(int dir, char *src, int src_len, +extern boolean_t qat_should_use(size_t s_len); +extern int qat_compress(qat_compress_dir_t dir, + char *src, int src_len, char *dst, int dst_len, size_t *c_len); /* @@ -72,16 +77,11 @@ typedef struct qat_stats { extern qat_stats_t qat_stats; -#define QAT_STAT_INCR(stat, val) \ - atomic_add_64(&qat_stats.stat.value.ui64, (val)); -#define QAT_STAT_BUMP(stat) \ - QAT_STAT_INCR(stat, 1); - #else #define CPA_STATUS_SUCCESS 0 #define qat_init() #define qat_fini() -#define use_qat(s_len) 0 +#define qat_should_use(s_len) 0 #define qat_compress(dir, s, sl, d, dl, cl) 0 #endif #endif