Skip to content

Commit

Permalink
Code rework to address Jinshan's comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
wli5 committed Mar 17, 2017
1 parent 44f040a commit bfdca09
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 33 deletions.
12 changes: 6 additions & 6 deletions module/zfs/gzip.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
}
Expand All @@ -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 */
}
Expand Down
47 changes: 28 additions & 19 deletions module/zfs/qat_compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -142,7 +151,7 @@ qat_clean(void)
}

num_inst = 0;
qat_init_done = 0;
qat_init_done = B_FALSE;
}

int
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
16 changes: 8 additions & 8 deletions module/zfs/qat_compress.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,15 @@
#include <sys/zio.h>
#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);
/*
Expand Down Expand Up @@ -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

0 comments on commit bfdca09

Please sign in to comment.