Commit 8d2455ca authored by paul luse's avatar paul luse Committed by Darek Stojaczyk
Browse files

bdev/compress: always use QAT if available



The next patch in this series introduces and RPC that makes the
selection more flexible.

Signed-off-by: default avatarpaul luse <paul.e.luse@intel.com>
Change-Id: I55617d3c37b51cf9474c358cb92f5218397c0c58
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/457157


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: default avatarDarek Stojaczyk <dariusz.stojaczyk@intel.com>
parent 5d55704d
Loading
Loading
Loading
Loading
+39 −21
Original line number Diff line number Diff line
@@ -59,15 +59,8 @@
#define COMP_BDEV_NAME "compress"
#define BACKING_IO_SZ (4 * 1024)

/* To add support for new device types, follow the examples of the following...
 * Note that the string names are defined by the DPDK PMD in question so be
 * sure to use the exact names.
 */
#define MAX_NUM_DRV_TYPES 1
#define ISAL_PMD "compress_isal"
/* TODO: #define QAT_PMD "tbd" */
const char *g_drv_names[MAX_NUM_DRV_TYPES] = { ISAL_PMD };

#define QAT_PMD "compress_qat"
#define NUM_MBUFS		512
#define POOL_CACHE_SIZE		256

@@ -147,6 +140,7 @@ struct comp_bdev_io {
static struct rte_mempool *g_mbuf_mp = NULL;			/* mbuf mempool */
static struct rte_mempool *g_comp_op_mp = NULL;			/* comp operations, must be rte* mempool */
static struct rte_mbuf_ext_shared_info g_shinfo = {};		/* used by DPDK mbuf macros */
static bool g_qat_available = false;
/* Create shrared (between all ops per PMD) compress xforms. */
static struct rte_comp_xform g_comp_xform = (struct rte_comp_xform)
{
@@ -287,6 +281,10 @@ create_compress_dev(uint8_t index, uint16_t num_lcores)

	TAILQ_INSERT_TAIL(&g_compress_devs, device, link);

	if (strcmp(device->cdev_info.driver_name, QAT_PMD) == 0) {
		g_qat_available = true;
	}

	return 0;

err:
@@ -353,6 +351,10 @@ vbdev_init_compress_drivers(void)
		}
	}

	if (g_qat_available == true) {
		SPDK_NOTICELOG("initialized QAT PMD\n");
	}

	g_shinfo.free_cb = shinfo_free_cb;

	return 0;
@@ -1101,7 +1103,7 @@ _prepare_for_load_init(struct spdk_bdev *bdev)

/* Call reducelib to initialize a new volume */
static void
vbdev_init_reduce(struct spdk_bdev *bdev, const char *pm_path, const char *comp_pmd)
vbdev_init_reduce(struct spdk_bdev *bdev, const char *pm_path)
{
	struct vbdev_compress *meta_ctx;
	int rc;
@@ -1111,6 +1113,12 @@ vbdev_init_reduce(struct spdk_bdev *bdev, const char *pm_path, const char *comp_
		return;
	}

	if (g_qat_available == true) {
		meta_ctx->drv_name = QAT_PMD;
	} else {
		meta_ctx->drv_name = ISAL_PMD;
	}

	rc = spdk_bdev_open(meta_ctx->base_bdev, true, vbdev_compress_base_bdev_hotremove_cb,
			    meta_ctx->base_bdev, &meta_ctx->base_desc);
	if (rc) {
@@ -1120,10 +1128,6 @@ vbdev_init_reduce(struct spdk_bdev *bdev, const char *pm_path, const char *comp_
	}
	meta_ctx->base_ch = spdk_bdev_get_io_channel(meta_ctx->base_desc);

	/* TODO: we'll want to pass name and compression parms to this
	 * function so they can be persisted.  We'll need to retrieve them
	 * in load.
	 */
	spdk_reduce_vol_init(&meta_ctx->params, &meta_ctx->backing_dev,
			     pm_path,
			     vbdev_reduce_init_cb,
@@ -1223,7 +1227,7 @@ comp_bdev_ch_destroy_cb(void *io_device, void *ctx_buf)

/* RPC entry point for compression vbdev creation. */
int
create_compress_bdev(const char *bdev_name, const char *pm_path, const char *comp_pmd)
create_compress_bdev(const char *bdev_name, const char *pm_path)
{
	struct spdk_bdev *bdev;

@@ -1232,7 +1236,7 @@ create_compress_bdev(const char *bdev_name, const char *pm_path, const char *com
		return -ENODEV;
	}

	vbdev_init_reduce(bdev, pm_path, comp_pmd);
	vbdev_init_reduce(bdev, pm_path);
	return 0;
}

@@ -1308,10 +1312,11 @@ vbdev_compress_claim(struct vbdev_compress *comp_bdev)
		goto error_bdev_name;
	}

	/* TODO: need to persist either PMD name or ALGO and a bunch of
	 * other parms to reduce via init and read them back in the load path.
	 */
	if (g_qat_available == true) {
		comp_bdev->drv_name = QAT_PMD;
	} else {
		comp_bdev->drv_name = ISAL_PMD;
	}

	/* Note: some of the fields below will change in the future - for example,
	 * blockcnt specifically will not match (the compressed volume size will
@@ -1320,8 +1325,15 @@ vbdev_compress_claim(struct vbdev_compress *comp_bdev)
	comp_bdev->comp_bdev.product_name = COMP_BDEV_NAME;
	comp_bdev->comp_bdev.write_cache = comp_bdev->base_bdev->write_cache;

	if (strcmp(comp_bdev->drv_name, QAT_PMD) == 0) {
		comp_bdev->comp_bdev.required_alignment =
			spdk_max(spdk_u32log2(comp_bdev->base_bdev->blocklen),
				 comp_bdev->base_bdev->required_alignment);
		SPDK_NOTICELOG("QAT in use: Required alignment set to %u\n",
			       comp_bdev->comp_bdev.required_alignment);
	} else {
		comp_bdev->comp_bdev.required_alignment = comp_bdev->base_bdev->required_alignment;

	}
	comp_bdev->comp_bdev.optimal_io_boundary =
		comp_bdev->params.chunk_size / comp_bdev->params.logical_block_size;

@@ -1429,6 +1441,12 @@ vbdev_reduce_load_cb(void *cb_arg, struct spdk_reduce_vol *vol, int reduce_errno
		return;
	}

	if (g_qat_available == true) {
		meta_ctx->drv_name = QAT_PMD;
	} else {
		meta_ctx->drv_name = ISAL_PMD;
	}

	/* Update information following volume load. */
	meta_ctx->vol = vol;
	memcpy(&meta_ctx->params, spdk_reduce_vol_get_params(vol),
+1 −2
Original line number Diff line number Diff line
@@ -45,10 +45,9 @@ typedef void (*spdk_delete_compress_complete)(void *cb_arg, int bdeverrno);
 *
 * \param bdev_name Bdev on which compression bdev will be created.
 * \param pm_path Path to persistent memory.
 * \param comp_pmd Compression PMD name.
 * \return 0 on success, other on failure.
 */
int create_compress_bdev(const char *bdev_name, const char *pm_path, const char *comp_pmd);
int create_compress_bdev(const char *bdev_name, const char *pm_path);

/**
 * Delete compress bdev.
+1 −4
Original line number Diff line number Diff line
@@ -41,7 +41,6 @@
struct rpc_construct_compress {
	char *base_bdev_name;
	char *pm_path;
	char *comp_pmd;
};

/* Free the allocated memory resource after the RPC handling. */
@@ -50,14 +49,12 @@ free_rpc_construct_compress(struct rpc_construct_compress *r)
{
	free(r->base_bdev_name);
	free(r->pm_path);
	free(r->comp_pmd);
}

/* Structure to decode the input parameters for this RPC method. */
static const struct spdk_json_object_decoder rpc_construct_compress_decoders[] = {
	{"base_bdev_name", offsetof(struct rpc_construct_compress, base_bdev_name), spdk_json_decode_string},
	{"pm_path", offsetof(struct rpc_construct_compress, pm_path), spdk_json_decode_string},
	{"comp_pmd", offsetof(struct rpc_construct_compress, comp_pmd), spdk_json_decode_string},
};

/* Decode the parameters for this RPC method and properly construct the compress
@@ -79,7 +76,7 @@ spdk_rpc_construct_compress_bdev(struct spdk_jsonrpc_request *request,
		goto invalid;
	}

	rc = create_compress_bdev(req.base_bdev_name, req.pm_path, req.comp_pmd);
	rc = create_compress_bdev(req.base_bdev_name, req.pm_path);
	if (rc != 0) {
		goto invalid;
	}
+1 −3
Original line number Diff line number Diff line
@@ -139,13 +139,11 @@ if __name__ == "__main__":
    def construct_compress_bdev(args):
        print_string(rpc.bdev.construct_compress_bdev(args.client,
                                                      base_bdev_name=args.base_bdev_name,
                                                      pm_path=args.pm_path,
                                                      comp_pmd=args.comp_pmd))
                                                      pm_path=args.pm_path))
    p = subparsers.add_parser('construct_compress_bdev',
                              help='Add a compress vbdev')
    p.add_argument('-b', '--base_bdev_name', help="Name of the base bdev")
    p.add_argument('-p', '--pm_path', help="Path to persistent memory")
    p.add_argument('-d', '--comp_pmd', help="Name of the compression device driver")
    p.set_defaults(func=construct_compress_bdev)

    def delete_compress_bdev(args):
+2 −3
Original line number Diff line number Diff line
@@ -15,18 +15,17 @@ def set_bdev_options(client, bdev_io_pool_size=None, bdev_io_cache_size=None):
    return client.call('set_bdev_options', params)


def construct_compress_bdev(client, base_bdev_name, pm_path, comp_pmd):
def construct_compress_bdev(client, base_bdev_name, pm_path):
    """Construct a compress virtual block device.

    Args:
        base_bdev_name: name of the underlying base bdev
        pm_path: path to persistent memory
        comp_pmd: name of of the DPDK compression driver to use

    Returns:
        Name of created virtual block device.
    """
    params = {'base_bdev_name': base_bdev_name, 'pm_path': pm_path, 'comp_pmd': comp_pmd}
    params = {'base_bdev_name': base_bdev_name, 'pm_path': pm_path}

    return client.call('construct_compress_bdev', params)