diff --git a/config.aix.mk b/config.aix.mk index f0dca338..e502dff2 100644 --- a/config.aix.mk +++ b/config.aix.mk @@ -218,7 +218,7 @@ else TESTGEN = ${ROOTPATH}/src/usr/cxxtest/cxxtestgen.pl endif -INCDIR = ${ROOTPATH}/src/include /usr/include /usr/include/sys . +INCDIR = . ${ROOTPATH}/src/include /usr/include /usr/include/sys _INCDIRS = ${INCDIR} ${EXTRAINCDIR} INCFLAGS = $(addprefix -I, ${_INCDIRS} ) ASMINCFLAGS = $(addprefix $(lastword -Wa,-I), ${_INCDIRS}) diff --git a/config.linux.mk b/config.linux.mk index 9085ff38..b0b1aeac 100644 --- a/config.linux.mk +++ b/config.linux.mk @@ -244,7 +244,7 @@ endif ASMFLAGS = ${COMMONFLAGS} CXXFLAGS += ${CFLAGS} -fno-rtti -fno-exceptions -Wall -INCDIR = ${ROOTPATH}/src/include . /usr/include /usr/include/misc +INCDIR = . ${ROOTPATH}/src/include /usr/include /usr/include/misc _INCDIRS = ${INCDIR} ${EXTRAINCDIR} INCFLAGS = $(addprefix -I, ${_INCDIRS} ) ASMINCFLAGS = $(addprefix $(lastword -Wa,-I), ${_INCDIRS}) diff --git a/debian/cxlflash.symbols b/debian/cxlflash.symbols index 2814f6ba..111ee398 100644 --- a/debian/cxlflash.symbols +++ b/debian/cxlflash.symbols @@ -21,7 +21,6 @@ libarkdb-0.so cxlflash #MINVER# am_malloc@Base 4.3~ am_realloc@Base 4.3~ ardes@Base 4.3~ - ari_active@Base 4.3~ ark_actual@Base 4.3~ ark_allocated@Base 4.3~ ark_anyreturn@Base 4.3~ @@ -96,6 +95,8 @@ libarkdb-0.so cxlflash #MINVER# bl_len@Base 4.3~ bl_new@Base 4.3~ bl_next@Base 4.3~ + bls_add@Base 4.3~ + bls_rem@Base 4.3~ bl_rechain@Base 4.3~ bl_release@Base 4.3~ bl_reserve@Base 4.3~ @@ -122,7 +123,6 @@ libarkdb-0.so cxlflash #MINVER# bv_get@Base 4.3~ bv_new@Base 4.3~ bv_set@Base 4.3~ - c_strings@Base 4.3~ check_alloc_error_injects@Base 4.3~ check_harv_error_injects@Base 4.3~ check_sched_error_injects@Base 4.3~ @@ -164,6 +164,7 @@ libarkdb-0.so cxlflash #MINVER# pAT@Base 4.3~ pool_function@Base 4.3~ popcount@Base 4.3~ + process_unmapQ@Base 4.3~ ptr_align@Base 4.3~ queue_deq@Base 4.3~ queue_deq_unsafe@Base 4.3~ diff --git a/src/block/bin/blockio.c b/src/block/bin/blockio.c index 5f38728c..6b202323 100644 --- a/src/block/bin/blockio.c +++ b/src/block/bin/blockio.c @@ -114,6 +114,7 @@ typedef struct uint64_t tlat_rd; uint64_t tlat_wr; uint32_t tmiss; + uint32_t unmap; size_t lba; size_t last_lba; uint32_t nblocks; @@ -135,6 +136,7 @@ uint32_t COMP = 0; uint32_t eto = 1000000; uint32_t lto = 10000; uint32_t hbar = 0; +uint32_t UNMAP = 0; double ns_per_tick = 0; /** @@ -317,8 +319,16 @@ void run_async(SGDEV_t *dev) *----------------------------------------------------------------*/ for (i=0; iWR && dev->issNid, dev->wbuf, dev->lba, dev->nblocks, - &rtag, NULL, CBLK_ARW_WAIT_CMD_FLAGS); + if (dev->unmap) + { + rc = cblk_aunmap(dev->id, dev->wbuf, dev->lba, dev->nblocks, + &rtag, NULL, CBLK_ARW_WAIT_CMD_FLAGS); + } + else + { + rc = cblk_awrite(dev->id, dev->wbuf, dev->lba, dev->nblocks, + &rtag, NULL, CBLK_ARW_WAIT_CMD_FLAGS); + } if (0 == rc) {OP_BEG(dev,(dev->op+rtag),WRITE);} else if (EBUSY == errno) {break;} else {IO_ISS_ERR(WRITE);} @@ -420,12 +430,13 @@ int main(int argc, char **argv) uint32_t tmiss = 0; uint32_t esecs = 0; uint64_t sticks = 0; - pthread_t pth[8]; + chunk_attrs_t attrs; + pthread_t pth[32]; /*-------------------------------------------------------------------------- * process and verify input parms *------------------------------------------------------------------------*/ - while (FF != (c=getopt(argc, argv, "d:r:q:n:s:e:S:R:l:phivD"))) + while (FF != (c=getopt(argc, argv, "d:r:q:n:s:e:S:R:l:phivUD"))) { switch (c) { @@ -441,6 +452,7 @@ int main(int argc, char **argv) case 'p': plun = 1; break; case 'i': intrp_thds = 1; break; case 'D': DEBUG = 1; break; + case 'U': UNMAP = 1; break; case 'v': verbose = 1; break; case 'h': case '?': usage(); break; @@ -520,7 +532,8 @@ int main(int argc, char **argv) _4K*nblocks, rc); exit(0); } - memset(devs[i].wbuf,0x79,_4K*nblocks); + if (UNMAP) {memset(devs[i].wbuf,0, _4K*nblocks);} + else {memset(devs[i].wbuf,0x79,_4K*nblocks);} } /*-------------------------------------------------------------------------- @@ -567,6 +580,19 @@ int main(int argc, char **argv) exit(errno); } } + + if (UNMAP) + { + dev->unmap = 1; + bzero(&attrs, sizeof(attrs)); + cblk_get_attrs(dev->id, &attrs, 0); + if (!(attrs.flags1 & CFLSH_ATTR_UNMAP)) + { + printf("%s: unmap is not supported\n", devStrs[i]); + dev->unmap=0; + } + } + debug("open: %s dev:%p id:%d nblks:%ld\n", devStrs[i],dev, dev->id, dev->last_lba+1); @@ -617,6 +643,7 @@ int main(int argc, char **argv) /*-------------------------------------------------------------------------- * print IO stats *------------------------------------------------------------------------*/ + if (cnt==0) {goto cleanup;} printf("r:%d q:%d s:%d p:%d n:%d i:%d v:%d eto:%d miss:%d/%d \ lat:%d mbps:%d iops:%d", nRD, QD, nsecs, plun, nblocks, @@ -630,6 +657,7 @@ lat:%d mbps:%d iops:%d", (uint32_t)((tlat_wr*ns_per_tick)/cnt_wr/1000));} printf("\n"); fflush(stdout); +cleanup: /*-------------------------------------------------------------------------- * cleanup *------------------------------------------------------------------------*/ diff --git a/src/block/cflash_block.c b/src/block/cflash_block.c index 784c8588..f6a432ea 100644 --- a/src/block/cflash_block.c +++ b/src/block/cflash_block.c @@ -738,6 +738,7 @@ int cblk_build_issue_rw_cmd(cflsh_chunk_t *chunk, int *cmd_index, void *buf,cfla cflsh_async_thread_cmp_t *async_data; #endif cflsh_cmd_mgm_t *cmd = NULL; + size_t buf_len=0; CFLASH_BLOCK_LOCK(chunk->lock); @@ -931,22 +932,25 @@ int cblk_build_issue_rw_cmd(cflsh_chunk_t *chunk, int *cmd_index, void *buf,cfla if (op_code == SCSI_READ_16) { - local_flags = CFLASH_READ_DIR_OP; - chunk->cmd_info[cmd->index].flags |= CFLSH_MODE_READ; + buf_len = CAPI_FLASH_BLOCK_SIZE * nblocks; + local_flags = CFLASH_READ_DIR_OP; + chunk->cmd_info[cmd->index].flags |= CFLSH_MODE_READ; } else if (op_code == SCSI_WRITE_16) { - local_flags = CFLASH_WRITE_DIR_OP; - chunk->cmd_info[cmd->index].flags |= CFLSH_MODE_WRITE; - + buf_len = CAPI_FLASH_BLOCK_SIZE * nblocks; + local_flags = CFLASH_WRITE_DIR_OP; + chunk->cmd_info[cmd->index].flags |= CFLSH_MODE_WRITE; + } else if (op_code == SCSI_WRITE_SAME_16) { - local_flags = CFLASH_WRITE_DIR_OP; - chunk->cmd_info[cmd->index].flags |= CFLSH_MODE_WRITE; - + buf_len = CAPI_FLASH_BLOCK_SIZE; + local_flags = CFLASH_WRITE_DIR_OP; + chunk->cmd_info[cmd->index].flags |= CFLSH_MODE_WRITE; + } - CBLK_BUILD_ADAP_CMD(chunk,cmd,buf,(CAPI_FLASH_BLOCK_SIZE * nblocks),local_flags); + CBLK_BUILD_ADAP_CMD(chunk,cmd,buf,buf_len,local_flags); cdb = CBLK_GET_CMD_CDB(chunk,cmd); diff --git a/src/block/test/fvt_block.C b/src/block/test/fvt_block.C index 7358e45a..7c382129 100644 --- a/src/block/test/fvt_block.C +++ b/src/block/test/fvt_block.C @@ -6053,6 +6053,195 @@ TEST(Block_FVT_Suite, BLK_API_FVT_plun_polling_unmap_rw_tst) } } +/** +******************************************************************************** +** \brief +*******************************************************************************/ +TEST(Block_FVT_Suite, BLK_API_FVT_plun_unmap_BIG_BLOCKS) +{ + int open_flags=0; + chunk_id_t id = 0; + int flags = 0; + int max_reqs = 64; + int er_no = 0; + int open_cnt = 1; + int ret = 0; + size_t temp_sz = 64*1024; // 16 unmap cmds, 256mb + int blks = 4096; + chunk_attrs_t attrs; + + ASSERT_EQ(0,blk_fvt_setup(1)); + + blk_open_tst(&id, max_reqs, &er_no, open_cnt, open_flags, mode); + ASSERT_NE(NULL_CHUNK_ID, id); + + bzero(&attrs, sizeof(attrs)); + ret = cblk_get_attrs(id, &attrs, 0); + ASSERT_EQ(ret,0); + + if (attrs.flags1 & CFLSH_ATTR_UNMAP) + { + char *buf = NULL; + int rc = 0; + int tag = -1; + uint64_t status = 0; + + if ((rc=posix_memalign((void**)&buf, 128, 4096*temp_sz))) + { + EXPECT_EQ(rc,0); + goto exit; + } + + rc = cblk_write(id, buf, 0, blks, 0); + ASSERT_EQ(blks, rc); + rc = cblk_unmap(id, buf, 0, blks, 0); + ASSERT_EQ(blks, rc); + + rc = cblk_awrite(id, buf, 0, blks, &tag, NULL, CBLK_ARW_WAIT_CMD_FLAGS); + ASSERT_EQ(0, rc); + rc=cblk_aresult(id, &tag, &status, CBLK_ARESULT_BLOCKING); + ASSERT_EQ(blks, rc); + ASSERT_EQ(0, errno); + + rc = cblk_aunmap(id, buf, 0, blks, &tag, NULL, CBLK_ARW_WAIT_CMD_FLAGS); + ASSERT_EQ(0, rc); + rc=cblk_aresult(id, &tag, &status, CBLK_ARESULT_BLOCKING); + ASSERT_EQ(blks, rc); + ASSERT_EQ(0, errno); + free(buf); + } + else + { + TESTCASE_SKIP("unmap is not supported"); + } + +exit: + blk_open_tst_cleanup(flags, &ret,&er_no); + EXPECT_EQ(0, ret); +} + +/** +******************************************************************************** +** \brief +*******************************************************************************/ +TEST(Block_FVT_Suite, BLK_API_FVT_vlun_unmap_scrub_small) +{ + int open_flags = CBLK_OPN_VIRT_LUN | CBLK_OPN_SCRUB_DATA; + chunk_id_t id = 0; + int flags = 0; + int max_reqs = 64; + int er_no = 0; + int open_cnt = 1; + int ret = 0; + size_t temp_sz = 5000; + chunk_attrs_t attrs; + + ASSERT_EQ(0,blk_fvt_setup(1)); + + blk_open_tst(&id, max_reqs, &er_no, open_cnt, open_flags, mode); + ASSERT_NE(NULL_CHUNK_ID, id); + + bzero(&attrs, sizeof(attrs)); + ret = cblk_get_attrs(id, &attrs, 0); + ASSERT_EQ(ret,0); + + blk_fvt_get_set_lun_size(id, &temp_sz, 0, 2, &ret,&er_no); + EXPECT_EQ(0, ret); + + if (attrs.flags1 & CFLSH_ATTR_UNMAP) + { + char buf[4096] = {0}; + int rc = 0; + int tag = -1; + uint64_t status = 0; + + rc = cblk_write(id, buf, 0, 1, 0); + ASSERT_EQ(1, rc); + rc = cblk_unmap(id, buf, 0, 1, 0); + ASSERT_EQ(1, rc); + + rc = cblk_awrite(id, buf, 0, 1, &tag, NULL, CBLK_ARW_WAIT_CMD_FLAGS); + ASSERT_EQ(0, rc); + rc=cblk_aresult(id, &tag, &status, CBLK_ARESULT_BLOCKING); + ASSERT_EQ(1, rc); + ASSERT_EQ(0, errno); + + rc = cblk_aunmap(id, buf, 0, 1, &tag, NULL, CBLK_ARW_WAIT_CMD_FLAGS); + ASSERT_EQ(0, rc); + rc=cblk_aresult(id, &tag, &status, CBLK_ARESULT_BLOCKING); + ASSERT_EQ(1, rc); + ASSERT_EQ(0, errno); + } + else + { + TESTCASE_SKIP("unmap is not supported"); + } + + blk_open_tst_cleanup(flags, &ret,&er_no); + EXPECT_EQ(0, ret); +} + +/** +******************************************************************************** +** \brief +*******************************************************************************/ +TEST(Block_FVT_Suite, BLK_API_FVT_vlun_unmap_scrub_big) +{ + int open_flags = CBLK_OPN_VIRT_LUN | CBLK_OPN_SCRUB_DATA; + chunk_id_t id = 0; + int flags = 0; + int max_reqs = 64; + int er_no = 0; + int open_cnt = 1; + int ret = 0; + size_t temp_sz = 500000; + chunk_attrs_t attrs; + + ASSERT_EQ(0,blk_fvt_setup(1)); + + blk_open_tst(&id, max_reqs, &er_no, open_cnt, open_flags, mode); + ASSERT_NE(NULL_CHUNK_ID, id); + + bzero(&attrs, sizeof(attrs)); + ret = cblk_get_attrs(id, &attrs, 0); + ASSERT_EQ(ret,0); + + blk_fvt_get_set_lun_size(id, &temp_sz, 0, 2, &ret,&er_no); + EXPECT_EQ(0, ret); + + if (attrs.flags1 & CFLSH_ATTR_UNMAP) + { + char buf[4096] = {0}; + int rc = 0; + int tag = -1; + uint64_t status = 0; + + rc = cblk_write(id, buf, 0, 1, 0); + ASSERT_EQ(1, rc); + rc = cblk_unmap(id, buf, 0, 1, 0); + ASSERT_EQ(1, rc); + + rc = cblk_awrite(id, buf, 0, 1, &tag, NULL, CBLK_ARW_WAIT_CMD_FLAGS); + ASSERT_EQ(0, rc); + rc=cblk_aresult(id, &tag, &status, CBLK_ARESULT_BLOCKING); + ASSERT_EQ(1, rc); + ASSERT_EQ(0, errno); + + rc = cblk_aunmap(id, buf, 0, 1, &tag, NULL, CBLK_ARW_WAIT_CMD_FLAGS); + ASSERT_EQ(0, rc); + rc=cblk_aresult(id, &tag, &status, CBLK_ARESULT_BLOCKING); + ASSERT_EQ(1, rc); + ASSERT_EQ(0, errno); + } + else + { + TESTCASE_SKIP("unmap is not supported"); + } + + blk_open_tst_cleanup(flags, &ret,&er_no); + EXPECT_EQ(0, ret); +} + TEST(Block_FVT_Suite, BLK_API_FVT_plun_blocking_perf_test) { diff --git a/src/build/install/makefile b/src/build/install/makefile index 13a4d2be..1b9fca20 100644 --- a/src/build/install/makefile +++ b/src/build/install/makefile @@ -297,6 +297,7 @@ endif cxlflash-test: @#TEST ONLY CONTENT - DO NOT SHIP + @mkdir -p ${BIN_DIR} @mkdir -p ${TEST_DIR} ifneq ($(TARGET_PLATFORM),x86_64) ${INSTALL} ${TESTSRCDIR}/blk_test ${TEST_DIR} @@ -372,7 +373,9 @@ ${FW_FILES}: fi cxlflashimage: ${FW_FILES} + @mkdir -p ${SHARE_DIR} @mkdir -p ${AFU_BIN} + ${INSTALL} -m 644 ${RESOURCEDIR}/afu_versions ${SHARE_DIR} @if [[ -e ${RESOURCEDIR}/flashgt_nvme_nsq ]]; then \ echo ${INSTALL} ${RESOURCEDIR}/flashgt_nvme_nsq ${AFU_BIN}; \ ${INSTALL} ${RESOURCEDIR}/flashgt_nvme_nsq ${AFU_BIN}; \ diff --git a/src/build/install/resources/cflash_depends b/src/build/install/resources/cflash_depends index e23524ef..12d5e66e 100755 --- a/src/build/install/resources/cflash_depends +++ b/src/build/install/resources/cflash_depends @@ -56,7 +56,7 @@ then then echo "ERROR: unable to reach the internet for required packages. A firewall may be up, telnet to www.ibm.com and rerun to update" else - apt-get -y install software-properties-common python3-software-properties python3 libudev-dev libcxl-dev dh-systemd help2man sg3-utils make cscope ctags doxygen git + apt-get -y install -f software-properties-common python3-software-properties python3 libudev-dev libcxl-dev dh-systemd help2man sg3-utils make cscope ctags doxygen git fi fi diff --git a/src/build/install/resources/cflash_perst b/src/build/install/resources/cflash_perst index 7bcadc02..9f858f8f 100755 --- a/src/build/install/resources/cflash_perst +++ b/src/build/install/resources/cflash_perst @@ -92,8 +92,12 @@ if ($ARGV[0]) } if ($prthelp) {usage();} -#check permissions -(! (`groups $ENV{'USER'}` =~ / cxl/ || `id -u $ENV{'USER'}` == 0)) && die "You do not have enough permissions\n"; +#check sudo permissions +if (`id -u` != 0) +{ + print "Run with sudo permissions\n"; + exit -2; +} #check cxlflash is not loaded system("lsmod | grep cxlflash >/dev/null"); diff --git a/src/build/install/resources/cflash_reset b/src/build/install/resources/cflash_reset index 851fb176..8c5eac87 100755 --- a/src/build/install/resources/cflash_reset +++ b/src/build/install/resources/cflash_reset @@ -95,8 +95,12 @@ if ( `cat /etc/redhat-release 2>/dev/null` =~ "Red Hat" ) {$redhat=1;} if (! $force) {print "sorry, not supported yet\n"; exit 0;} -#check permissions -(! (`groups $ENV{'USER'}` =~ / cxl/ || `id -u $ENV{'USER'}` == 0)) && die "You do not have enough permissions\n"; +#check sudo permissions +if (`id -u` != 0) +{ + print "Run with sudo permissions\n"; + exit -2; +} #------------------------------------------------------------------------------- # Make stdout autoflush diff --git a/src/build/install/resources/cflash_version b/src/build/install/resources/cflash_version index 2352da04..bac9a6ec 100755 --- a/src/build/install/resources/cflash_version +++ b/src/build/install/resources/cflash_version @@ -102,6 +102,7 @@ then fi EXISTS_K_VER=$(dpkg -l |grep $(uname -a|awk '{print $3}')|grep linux-image|grep -v extra|awk '{print $3}') + if [[ -z ${EXISTS_K_VER} ]]; then EXISTS_K_VER=$(uname -a|awk '{print $3}'); fi n1=$(echo $EXISTS_K_VER|awk -F. '{print $1}') n2=$(echo $EXISTS_K_VER|awk -F. '{print $2}') n3=$(echo $EXISTS_K_VER|awk -F. '{print $3}'|awk -F- '{print $1}') @@ -147,10 +148,7 @@ then if [[ -e /usr/bin/capi_flash ]] then - IFS=$'\n' - adaps=($(capi_flash -l 2>/dev/null)) - unset IFS - for line in "${adaps[@]}" + capi_flash -l | while read -r line do if [[ $VM ]] then diff --git a/src/build/install/resources/cflashutils b/src/build/install/resources/cflashutils index 0be19c77..c0baf803 100755 --- a/src/build/install/resources/cflashutils +++ b/src/build/install/resources/cflashutils @@ -69,8 +69,9 @@ chluntable() "$LUNMODE_SIO-$LUNMODE_LEGACY" ) echo "INFO: Removing LUN $targetlun from Super IO table."; sed "/$targetlun=.*/d" $SIOTABLE > ${SIOTABLE}.new; - mv $SIOTABLE ${SIOTABLE}.bak; - mv ${SIOTABLE}.new $SIOTABLE; + cp -f $SIOTABLE ${SIOTABLE}.bak; + cp -f ${SIOTABLE}.new $SIOTABLE; + rm -f ${SIOTABLE}.new; ;; "$LUNMODE_SIO-$LUNMODE_SIO" ) echo "INFO: LUN $targetlun is already in SIO mode. No action needed."; diff --git a/src/build/version.txt b/src/build/version.txt index 99805be8..da1c3967 100644 --- a/src/build/version.txt +++ b/src/build/version.txt @@ -1 +1 @@ -4.3.2560 +4.3.2580 diff --git a/src/cflash/test/cflash_test.h b/src/cflash/test/cflash_test.h index 790742d3..0466a005 100644 --- a/src/cflash/test/cflash_test.h +++ b/src/cflash/test/cflash_test.h @@ -584,6 +584,7 @@ enum TEST_DETACH_DIFF_PROC, TEST_FC_PR_RESET_VLUN, TEST_FC_PR_RESET_PLUN, + E_TEST_PORT_OFF_ON_GT_PLUN, /*********** EXCP CASE *************/ EXCP_VLUN_DISABLE, EXCP_PLUN_DISABLE, @@ -832,6 +833,7 @@ int diskSizeCheck( char * , float ); void identifyHostType( void ); int diskToWWID ( char * WWID); int WWIDtoDisk ( char * WWID); +int diskToPortnAFU( char * diskName , char * afuName, char * portName); #endif int test_spio_vlun(int); int test_spio_plun(); @@ -906,4 +908,5 @@ int get_max_res_hndl_by_capacity(char *dev); int max_ctx_cross_limit(); int cflash_query_ue(void *buf, size_t len); int test_vlun_max_transfer(); +int test_port_offline_online_GTplus(); #endif /*__CFLASH_TEST_H__ */ diff --git a/src/cflash/test/cflash_test_engine.c b/src/cflash/test/cflash_test_engine.c index 21f9544c..d6225de4 100644 --- a/src/cflash/test/cflash_test_engine.c +++ b/src/cflash/test/cflash_test_engine.c @@ -798,6 +798,9 @@ int mc_test_engine(mc_test_t test_name) case TEST_VLUN_MAX_TRANSFER: rc = test_vlun_max_transfer(); break; + case E_TEST_PORT_OFF_ON_GT_PLUN: + rc = test_port_offline_online_GTplus(); + break; default: rc = -1; diff --git a/src/cflash/test/cflash_test_error.c b/src/cflash/test/cflash_test_error.c index 41b1bdba..6880459e 100644 --- a/src/cflash/test/cflash_test_error.c +++ b/src/cflash/test/cflash_test_error.c @@ -455,6 +455,19 @@ int mc_invalid_ioarcb(int cmd) send_cmd(p_ctx); } rc = wait_resp(p_ctx); +#ifndef _AIX + /* + As mentioned in defect#SW359926, afu_rc=0x62 for GT card + for reference rc = afu_rc | scsi_rc | afu_rc + example:- GT card rc = 0x62 | 0x0 | 0x58 + and Corsa Card rc = 0x0 | 0x0 | 0x58 + */ + if ( cmd == 3 && is_UA_device( p_ctx->dev ) == FALSE ) + { + if ( rc == 0x7A ) + rc = 0x58 ; + } +#endif if ( cmd >= 9 && cmd <= 13) { if (!rc_flags) @@ -948,3 +961,78 @@ int test_fc_port_reset_plun() ctx_close(p_ctx); return rc; } + + + +int test_port_offline_online_GTplus() +{ + int rc; +#ifndef _AIX + struct ctx myctx; + + struct ctx *p_ctx = &myctx; + + pthread_t thread; + + char afuName[MAXBUFF]; + char portName[MAXBUFF]; + + char cmdToRun[MAXBUFF]; + + __u64 stride= 0x100; + + pid = getpid(); + + rc = ctx_init(p_ctx); + CHECK_RC(rc, "Context init failed"); + + //thread to handle AFU interrupt & events + pthread_create(&thread, NULL, ctx_rrq_rx, p_ctx); + + //for PLUN 2nd argument(lba_size) would be ignored + rc = create_resource(p_ctx, 0, DK_UDF_ASSIGN_PATH, LUN_DIRECT); + CHECK_RC(rc, "create LUN_DIRECT failed"); + rc = compare_size(p_ctx->last_lba, p_ctx->last_phys_lba); + CHECK_RC(rc, "failed compare_size"); + + rc = do_io(p_ctx, stride); + + CHECK_RC(rc, "IO failed"); + + diskToPortnAFU(cflash_path, afuName, portName) ; + + sprintf(cmdToRun,"/usr/bin/cxl_afu_status -d %s -p %s | grep \"link up\"",afuName ,portName); + debug("%d:%s\n",pid,cmdToRun); + rc = system(cmdToRun); + CHECK_RC(rc,"cxl_afu_status failed"); + + sprintf(cmdToRun,"/usr/bin/cflash_inject -d %s -offline", strrchr( cflash_path, '/') + 1); + debug("%d:%s\n",pid,cmdToRun); + rc = system(cmdToRun); + CHECK_RC(rc,"cxl_afu_inject failed"); + + rc = do_io(p_ctx, stride); + if (rc == 0 ) + CHECK_RC(1, "IO should fail"); + + sprintf(cmdToRun,"/usr/bin/cflash_inject -d %s -online", strrchr( cflash_path, '/') + 1); + debug("%d:%s\n",pid,cmdToRun); + rc = system(cmdToRun); + CHECK_RC(rc,"cxl_afu_inject failed"); + + rc = do_io(p_ctx, stride); + CHECK_RC(rc, "IO should not fail"); + + sprintf(cmdToRun,"/usr/bin/cxl_afu_status -d %s -p %s | grep \"link up\"",afuName ,portName); + debug("%d:%s\n",pid,cmdToRun); + + rc = system(cmdToRun); + CHECK_RC(rc,"cxl_afu_status failed"); + + pthread_cancel(thread); + close_res(p_ctx); + ctx_close(p_ctx); +#endif + return rc; + +} diff --git a/src/cflash/test/cflash_test_util.c b/src/cflash/test/cflash_test_util.c index 37a94041..239bedb7 100644 --- a/src/cflash/test/cflash_test_util.c +++ b/src/cflash/test/cflash_test_util.c @@ -3965,6 +3965,22 @@ int ioctl_dk_capi_attach_reuse(struct ctx *p_ctx,struct ctx *p_ctx_1, __u16 lun_ p_ctx->block_size = capi_attach.block_size; #endif +#ifdef DK_CXLFLASH_APP_CLOSE_ADAP_FD + // if context attach returns DK_CXLFLASH_APP_CLOSE_ADAP_FD flag + if (p_ctx->return_flags & DK_CXLFLASH_APP_CLOSE_ADAP_FD) + { + p_ctx->close_adap_fd_flag = TRUE; + } + +#endif + +#ifdef DK_CXLFLASH_CONTEXT_SQ_CMD_MODE + if ( p_ctx->return_flags & DK_CXLFLASH_CONTEXT_SQ_CMD_MODE ) + { + p_ctx->sq_mode_flag = TRUE ; + } +#endif + //default rwbuff handling 4K, Lorge trasnfer handled exclusive p_ctx->blk_len = BLOCK_SIZE/p_ctx->block_size; p_ctx->adap_fd = capi_attach.adap_fd; @@ -4053,6 +4069,10 @@ int ioctl_dk_capi_attach_reuse(struct ctx *p_ctx,struct ctx *p_ctx_1, __u16 lun_ p_ctx_1->context_id=p_ctx->context_id; capi_attach.context_id=p_ctx->context_id; capi_attach.hdr.flags = DK_CXLFLASH_ATTACH_REUSE_CONTEXT; +#if defined(DK_CXLFLASH_APP_CLOSE_ADAP_FD) || defined(DK_CXLFLASH_CONTEXT_SQ_CMD_MODE) + capi_attach.hdr.return_flags = 0; +#endif + rc = ioctl(p_ctx_1->fd, DK_CXLFLASH_ATTACH, &capi_attach); #endif debug("%d:... DK_CAPI_ATTACH called with REUSE flag...\n", pid); @@ -4091,12 +4111,25 @@ int ioctl_dk_capi_attach_reuse(struct ctx *p_ctx,struct ctx *p_ctx_1, __u16 lun_ p_ctx_1->return_flags = capi_attach.return_flags; p_ctx_1->block_size = capi_attach.block_size; #else +#ifdef DK_CXLFLASH_APP_CLOSE_ADAP_FD + /* After Al-Viro changes cxlflash driver will not cache the adap fd; + So application needs to re-use the adap fd returned in first context attach */ + if ( capi_attach.adap_fd == -1 ) + { + capi_attach.adap_fd = p_ctx->adap_fd; + } + else + { + CHECK_RC(1,"adap fd not returned -1"); + } +#endif p_ctx_1->p_host_map = mmap(NULL,p_ctx_1->mmio_size,PROT_READ|PROT_WRITE, MAP_SHARED, //p_ctx->adap_fd,0); capi_attach.adap_fd,0); if (p_ctx_1->p_host_map == MAP_FAILED) { - fprintf(stderr,"map failed for 0x%lx mmio_size %d errno\n", - p_ctx_1->mmio_size, errno); + p_ctx_1->adap_fd = capi_attach.adap_fd; + fprintf(stderr,"map failed for mmio_size 0x%lx errno %d adap_fd %d\n", + p_ctx_1->mmio_size, errno,p_ctx_1->adap_fd); CHECK_RC(1,"mmap failed"); } p_ctx_1->context_id = capi_attach.context_id; @@ -4105,6 +4138,7 @@ int ioctl_dk_capi_attach_reuse(struct ctx *p_ctx,struct ctx *p_ctx_1, __u16 lun_ p_ctx_1->chunk_size = NUM_BLOCKS; p_ctx_1->return_flags = capi_attach.hdr.return_flags; p_ctx_1->block_size = capi_attach.block_size; + #endif //default rwbuff handling 4K, Lorge trasnfer handled exclusive @@ -4326,25 +4360,34 @@ int ioctl_dk_capi_attach_reuse_all_disk( ) rc = ioctl(new_ctx[i]->fd, DK_CAPI_ATTACH, &capi_attach); #else rc = ioctl(new_ctx[i]->fd, DK_CXLFLASH_ATTACH, &capi_attach); + new_ctx[i]->context_id = capi_attach.context_id; #endif debug("%d:...First DK_CAPI_ATTACH called ...\n", pid); if (rc) { CHECK_RC(errno, "FIRST DK_CAPI_ATTACH failed"); } + } + else { #ifdef _AIX new_ctx[i]->context_id=new_ctx[0]->context_id; new_ctx[i]->flags = capi_attach.flags = DK_AF_REUSE_CTX; + debug("%d:----------- Start DK_CAPI_ATTACH with REUSE flag ----------\n", pid); debug("%d:dev=%s fd=%d Ver=%u flags=0X%"PRIX64"\n", pid,new_ctx[i]->dev,new_ctx[i]->fd,new_ctx[i]->version,new_ctx[i]->flags); rc = ioctl(new_ctx[i]->fd, DK_CAPI_ATTACH, &capi_attach); #else new_ctx[i]->context_id=new_ctx[0]->context_id; + capi_attach.context_id = new_ctx[0]->context_id; capi_attach.hdr.flags = DK_CXLFLASH_ATTACH_REUSE_CONTEXT; + +#if defined(DK_CXLFLASH_APP_CLOSE_ADAP_FD) || defined(DK_CXLFLASH_CONTEXT_SQ_CMD_MODE) + capi_attach.hdr.return_flags = 0; +#endif rc = ioctl(new_ctx[i]->fd, DK_CXLFLASH_ATTACH, &capi_attach); #endif debug("%d:... DK_CAPI_ATTACH called with REUSE flag...\n", pid); @@ -4352,13 +4395,22 @@ int ioctl_dk_capi_attach_reuse_all_disk( ) { CHECK_RC(errno, "DK_CAPI_ATTACH with REUSE flag failed"); } - } - - debug("%d:mmio=%p mmio_size=0X%"PRIX64" ctx_id=0X%"PRIX64" last_lba=0X%"PRIX64" block_size=0X%"PRIX64" chunk_size=0X%"PRIX64" max_xfer=0X%"PRIX64"\n", - pid,new_ctx[i]->p_host_map,new_ctx[i]->mmio_size,new_ctx[i]->context_id, - new_ctx[i]->last_phys_lba,new_ctx[i]->block_size,new_ctx[i]->chunk_size,new_ctx[i]->max_xfer); +#ifdef DK_CXLFLASH_APP_CLOSE_ADAP_FD + /* After Al-Viro changes cxlflash driver will not cache the adap fd; + So application needs to re-use the adap fd returned in first context attach */ + if ( capi_attach.adap_fd == -1 ) + { + capi_attach.adap_fd = new_ctx[0]->adap_fd; + } + else + { + new_ctx[i]->adap_fd = capi_attach.adap_fd; + debug("%d:adap fd returned in using reuse flag-> %d \n",pid,new_ctx[i]->adap_fd); + CHECK_RC(1,"adap fd not returned -1"); + } +#endif - debug("%d:------------- End DK_CAPI_ATTACH with REUSE flag -------------\n", pid); + } new_ctx[i]->mmio_size = capi_attach.mmio_size; @@ -4383,6 +4435,7 @@ int ioctl_dk_capi_attach_reuse_all_disk( ) new_ctx[i]->return_flags = capi_attach.return_flags; new_ctx[i]->block_size = capi_attach.block_size; #else + new_ctx[i]->p_host_map = mmap(NULL,new_ctx[i]->mmio_size,PROT_READ|PROT_WRITE, MAP_SHARED, capi_attach.adap_fd,0); if (new_ctx[i]->p_host_map == MAP_FAILED) @@ -4401,7 +4454,7 @@ int ioctl_dk_capi_attach_reuse_all_disk( ) //default rwbuff handling 4K, Lorge trasnfer handled exclusive new_ctx[i]->blk_len = BLOCK_SIZE/new_ctx[i]->block_size; - new_ctx[i]->adap_fd = new_ctx[i]->adap_fd;//capi_attach.adap_fd; + new_ctx[i]->adap_fd = capi_attach.adap_fd; new_ctx[i]->ctx_hndl = CTX_HNDLR_MASK & new_ctx[i]->context_id; new_ctx[i]->unused_lba = new_ctx[i]->last_phys_lba +1; @@ -4588,6 +4641,9 @@ int ioctl_dk_capi_attach_reuse_loop(struct ctx *p_ctx,struct ctx *p_ctx_1 ) #else p_ctx_1->context_id=p_ctx->context_id; capi_attach.hdr.flags = DK_CXLFLASH_ATTACH_REUSE_CONTEXT; +#if defined(DK_CXLFLASH_APP_CLOSE_ADAP_FD) || defined(DK_CXLFLASH_CONTEXT_SQ_CMD_MODE) + capi_attach.hdr.return_flags = 0; +#endif rc = ioctl(p_ctx_1->fd, DK_CXLFLASH_ATTACH, &capi_attach); #endif debug("%d:... DK_CAPI_ATTACH called with REUSE flag...\n", pid); @@ -4626,6 +4682,18 @@ int ioctl_dk_capi_attach_reuse_loop(struct ctx *p_ctx,struct ctx *p_ctx_1 ) p_ctx_1->return_flags = capi_attach.return_flags; p_ctx_1->block_size = capi_attach.block_size; #else +#ifdef DK_CXLFLASH_APP_CLOSE_ADAP_FD + /* After Al-Viro changes cxlflash driver will not cache the adap fd; + So application needs to re-use the adap fd returned in first context attach */ + if ( capi_attach.adap_fd == -1 ) + { + capi_attach.adap_fd = p_ctx->adap_fd; + } + else + { + CHECK_RC(1,"adap fd not returned -1"); + } +#endif p_ctx_1->p_host_map = mmap(NULL,p_ctx_1->mmio_size,PROT_READ|PROT_WRITE, MAP_SHARED, //p_ctx->adap_fd,0); capi_attach.adap_fd,0); if (p_ctx_1->p_host_map == MAP_FAILED) @@ -5294,7 +5362,7 @@ int is_UA_device( char * diskName ) } // only supporting for scsi_generic device - iKey = strlen(diskName)-4 ; + iKey = strlen("/dev/"); sprintf(blockCheckP,"ls -d /sys/devices/*/*/" "%s/*/*/host*/target*/*:*:*:*/scsi_generic/* | grep -w %s >/dev/null 2>&1",tmpBuff,&diskName[iKey]); rc = system(blockCheckP); @@ -5447,3 +5515,177 @@ int cflash_query_ue(void *buf, size_t len) return ue_found; } + +#ifndef _AIX +/* + * NAME: diskToPortnAFU + * + * FUNCTION: function takes disk name as input + * It returns the AFU and port name + * for GT and GT+ card + * + * RETURNS: + * + * return non-zero if failed + * + */ + +int diskToPortnAFU( char * diskName , char * afuName, char * portName) +{ + + int iCount =0; + int rc =0; + int iTer =0; + int iKey =0; + + FILE *fileP; + char tmpBuff[MAXBUFF]; + char npBuff[MAXNP][MAXBUFF]; + + const char *initCmdP = "lspci |egrep \"0601|0628\" | awk '{ print $1}' > /tmp/trashFile"; + + rc = system(initCmdP); + if ( rc != 0) + { + fprintf(stderr,"%d: Failed in lspci \n",pid); + goto xerror ; + } + + fileP = fopen("/tmp/trashFile", "r"); + + if (NULL == fileP) + { + fprintf(stderr,"%d: Error opening file /tmp/trashFile \n", pid); + rc = EINVAL ; + goto xerror ; + } + + while (fgets(tmpBuff,MAXBUFF, fileP) != NULL) + { + while (iTer < MAXBUFF) + { + if (tmpBuff[iTer] =='\n') + { + tmpBuff[iTer]='\0'; + break; + } + + iTer++; + } + + iKey = strlen("/dev/"); + + sprintf(npBuff[iCount],"ls -l /sys/bus/pci/devices/" + "%s/pci***:**/***:**:**.*/host*/" + "target*:*:*/*:*:*:*/scsi_generic | grep %s >/dev/null 2>&1",tmpBuff,&diskName[iKey]); + + rc = system(npBuff[iCount]); + if ( rc == 0 ) + { + fclose(fileP); + break; + } + + iCount++; + } + + /* Now get the AFU name */ + + sprintf(npBuff[iCount],"ls -d /sys/devices/*/*/" + "%s/cxl/card*/afu*.0/afu*m | awk -F '/' '{ print $10 }' > /tmp/trashFile", tmpBuff); + + rc = system(npBuff[iCount]); + if ( rc != 0) + { + fprintf(stderr,"%d: failed to find AFU name\n",pid); + rc = EINVAL ; + goto xerror ; + } + + fileP = fopen("/tmp/trashFile", "r"); + if (NULL == fileP) + { + fprintf(stderr,"%d: Error opening file /tmp/trashFile \n", pid); + rc = EINVAL ; + goto xerror ; + } + + if ( NULL == fgets(afuName,MAXBUFF, fileP) ) + { + fprintf(stderr,"%d: Error in file /tmp/trashFile \n", pid); + rc = EINVAL ; + goto xerror ; + } + + if ( fclose(fileP) == EOF ) + { + fprintf(stderr,"%d: Error closin the file /tmp/trashFile \n", pid); + rc = EINVAL ; + goto xerror ; + } + + iTer = 0 ; + + while (iTer < MAXBUFF) + { + if (afuName[iTer] =='\n') + { + afuName[iTer]='\0'; + break; + } + iTer++; + } + + sprintf(npBuff[iCount],"ls -d /sys/devices/*/*/" + "%s/*/*/host*/target*:*:*/*:*:*:*/" + "scsi_generic/%s | awk -F ':' '{print $10}' > /tmp/trashFile" ,tmpBuff,&diskName[iKey]); + + rc = system(npBuff[iCount]); + if ( rc != 0) + { + fprintf(stderr,"%d: failed to find AFU name\n",pid); + rc = EINVAL ; + goto xerror ; + } + + fileP = fopen("/tmp/trashFile", "r"); + if (NULL == fileP) + { + fprintf(stderr,"%d: Error opening file /tmp/trashFile \n", pid); + rc = EINVAL ; + goto xerror ; + } + + if ( NULL == fgets(portName,MAXBUFF, fileP) ) + { + fprintf(stderr,"%d: Error in file /tmp/trashFile \n", pid); + rc = EINVAL ; + goto xerror ; + } + + if ( fclose(fileP) == EOF ) + { + fprintf(stderr,"%d: Error closin the file /tmp/trashFile \n", pid); + rc = EINVAL ; + goto xerror ; + } + + iTer = 0 ; + + while (iTer < MAXBUFF) + { + if (portName[iTer] =='\n') + { + portName[iTer]='\0'; + break; + } + iTer++; + } + + + +xerror: + return rc; +} + +#endif diff --git a/src/cflash/test/fvt_cflash.C b/src/cflash/test/fvt_cflash.C index 00444085..49e2f011 100644 --- a/src/cflash/test/fvt_cflash.C +++ b/src/cflash/test/fvt_cflash.C @@ -1087,6 +1087,12 @@ TEST(Cflash_FVT_Suite, G_7_1_203) ASSERT_EQ(0,mc_test_engine(G_ioctl_7_1_203)); } +#ifndef AIX +TEST(Cflash_FVT_Suite, E_port_offonline_GT_plun) +{ + ASSERT_EQ(0,mc_test_engine(E_TEST_PORT_OFF_ON_GT_PLUN)); +} +#endif #ifdef AIX_MANUAL diff --git a/src/include/ticks.h b/src/include/ticks.h index b8a1364a..169b05f9 100644 --- a/src/include/ticks.h +++ b/src/include/ticks.h @@ -24,6 +24,7 @@ /* IBM_PROLOG_END_TAG */ #ifndef _TICKS_H__ #define _TICKS_H__ +#include #include #include #include @@ -146,8 +147,8 @@ static __inline__ double time_diff(struct timeval x , struct timeval y) ******************************************************************************/ static __inline__ double time_per_tick(int n, int del) { - double *td = malloc(n * sizeof(double)); - double *tv = malloc(n * sizeof(double)); + double *td = (double*)malloc(n * sizeof(double)); + double *tv = (double*)malloc(n * sizeof(double)); struct timeval tvs; struct timeval tve; ticks ts; diff --git a/src/kv/am.c b/src/kv/am.c index 1d937cd2..b825b488 100644 --- a/src/kv/am.c +++ b/src/kv/am.c @@ -23,18 +23,10 @@ /* */ /* IBM_PROLOG_END_TAG */ -#include -#include -#include - #ifndef _AIX #include "zmalloc.h" #endif -#include -#include -#include -#include #include int x = 1; diff --git a/src/kv/ari.c b/src/kv/ari.c deleted file mode 100644 index a2ce70a7..00000000 --- a/src/kv/ari.c +++ /dev/null @@ -1,29 +0,0 @@ -/* IBM_PROLOG_BEGIN_TAG */ -/* This is an automatically generated prolog. */ -/* */ -/* $Source: src/kv/ari.c $ */ -/* */ -/* IBM Data Engine for NoSQL - Power Systems Edition User Library Project */ -/* */ -/* Contributors Listed Below - COPYRIGHT 2014,2015 */ -/* [+] International Business Machines Corp. */ -/* */ -/* */ -/* Licensed under the Apache License, Version 2.0 (the "License"); */ -/* you may not use this file except in compliance with the License. */ -/* You may obtain a copy of the License at */ -/* */ -/* http://www.apache.org/licenses/LICENSE-2.0 */ -/* */ -/* Unless required by applicable law or agreed to in writing, software */ -/* distributed under the License is distributed on an "AS IS" BASIS, */ -/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or */ -/* implied. See the License for the specific language governing */ -/* permissions and limitations under the License. */ -/* */ -/* IBM_PROLOG_END_TAG */ - - -#include "ark.h" - -int ari_active = 0; diff --git a/src/kv/ari.h b/src/kv/ari.h deleted file mode 100644 index 9f9f3398..00000000 --- a/src/kv/ari.h +++ /dev/null @@ -1,32 +0,0 @@ -/* IBM_PROLOG_BEGIN_TAG */ -/* This is an automatically generated prolog. */ -/* */ -/* $Source: src/kv/ari.h $ */ -/* */ -/* IBM Data Engine for NoSQL - Power Systems Edition User Library Project */ -/* */ -/* Contributors Listed Below - COPYRIGHT 2014,2015 */ -/* [+] International Business Machines Corp. */ -/* */ -/* */ -/* Licensed under the Apache License, Version 2.0 (the "License"); */ -/* you may not use this file except in compliance with the License. */ -/* You may obtain a copy of the License at */ -/* */ -/* http://www.apache.org/licenses/LICENSE-2.0 */ -/* */ -/* Unless required by applicable law or agreed to in writing, software */ -/* distributed under the License is distributed on an "AS IS" BASIS, */ -/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or */ -/* implied. See the License for the specific language governing */ -/* permissions and limitations under the License. */ -/* */ -/* IBM_PROLOG_END_TAG */ -#ifndef __ARI_H__ -#define __ARI_H__ - - - -extern int ari_active; - -#endif diff --git a/src/kv/ark.h b/src/kv/ark.h index 6bd611f3..8f7d9c37 100644 --- a/src/kv/ark.h +++ b/src/kv/ark.h @@ -32,19 +32,51 @@ #define __ARK_H__ #include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef _OS_INTERNAL +#include +#else +#include +#endif + +#include -#include "hash.h" -#include "bl.h" -#include "ea.h" -#include "bt.h" -#include "tag.h" -#include "queue.h" -#include "sq.h" -#include "ut.h" +#ifndef TRUE +#define TRUE 1 +#endif +#ifndef FALSE +#define FALSE 0 +#endif /* if on, then KV_TRC_HEX traces up to 64 bytes of key/value */ #define DUMP_KV 0 +#define ARK_UQ_SIZE 255 + #define ARK_VERBOSE_SIZE_DEF (1024*1024) #define ARK_VERBOSE_BSIZE_DEF 4096 #define ARK_VERBOSE_HASH_DEF (200*1024) @@ -266,14 +298,21 @@ typedef struct _ark uint32_t htcN; // # of hash cache BL *bl; // block lists + BL *blu; // block lists waiting for unmap + + struct _tcb *utcbs; // unmap tcbs + struct _iocb *ucbs; // unmap iocbs + struct _ea *ea; // in memory store space struct _rcb *rcbs; struct _tcb *tcbs; struct _iocb *iocbs; struct _scb *poolthreads; struct _pt *pts; + struct _tags *rtags; struct _tags *ttags; + struct _tags *utags; uint32_t min_bt; // min size of inb/oub uint32_t issT; @@ -283,10 +322,14 @@ typedef struct _ark uint64_t get_latT; uint64_t exi_latT; uint64_t del_latT; + uint64_t um_latT; uint64_t set_opsT; uint64_t get_opsT; uint64_t exi_opsT; uint64_t del_opsT; + uint64_t um_opsT; + + ticks utime; // time since last unmaps processes double ns_per_tick; ark_stats_t pers_stats; } _ARK; @@ -301,6 +344,10 @@ typedef struct _scb queue_t *taskQ; queue_t *scheduleQ; queue_t *harvestQ; + + queue_t *uscheduleQ; + queue_t *uharvestQ; + int32_t poolstate; int32_t rlast; int32_t dogc; @@ -394,13 +441,13 @@ typedef struct _ari #define ARK_RAND_START 18 #define ARK_FIRST_START 19 #define ARK_NEXT_START 20 +#define ARK_UNMAP_PROCESS 21 // operation typedef struct _tcb { int32_t rtag; int32_t ttag; - int32_t state; int32_t sthrd; uint64_t vbsize; @@ -439,17 +486,18 @@ typedef struct _iocb uint64_t start; uint64_t new_start; uint64_t cnt; + int32_t state; int32_t op; int32_t tag; uint32_t issT; uint32_t cmpT; - uint32_t rd; uint32_t lat; uint64_t stime; uint32_t hmissN; uint32_t aflags; uint32_t io_error; uint32_t io_done; + uint32_t eagain; } iocb_t; int64_t ark_take_pool(_ARK *_arkp, ark_stats_t *stats, uint64_t n); @@ -465,12 +513,40 @@ int ark_next_async_tag(_ARK *ark, uint64_t klen, void *key, _ARI *_arip, int32_t int ark_anyreturn(_ARK *ark, int *tag, int64_t *res); +void *pool_function(void *arg); + +int ark_enq_cmd(int cmd, _ARK *_arkp,uint64_t klen,void *key,uint64_t vbuflen,void *vbuf,uint64_t voff, + void (*cb)(int errcode, uint64_t dt,int64_t res), uint64_t dt, int32_t pthr, int *ptag); + +int ark_wait_tag(_ARK *_arkp, int tag, int *errcode, int64_t *res); + +void ark_set_finish(_ARK *_arkp, int tid, tcb_t *tcbp); +void ark_set_write(_ARK *_arkp, int tid, tcb_t *tcbp); +void ark_set_process(_ARK *_arkp, int tid, tcb_t *tcbp); +void ark_set_process_inb(_ARK *_arkp, int tid, tcb_t *tcbp); +void ark_set_start(_ARK *_arkp, int tid, tcb_t *tcbp); + +void ark_get_start(_ARK *_arkp, int tid, tcb_t *tcbp); +void ark_get_finish(_ARK *_arkp, int tid, tcb_t *tcbp); +void ark_get_process(_ARK *_arkp, int tid, tcb_t *tcbp); + +void ark_del_start(_ARK *_arkp, int tid, tcb_t *tcbp); +void ark_del_process(_ARK *_arkp, int tid, tcb_t *tcbp); +void ark_del_finish(_ARK *_arkp, int32_t tid, tcb_t *tcbp); + +void ark_exist_start(_ARK *_arkp, int tid, tcb_t *tcbp); +void ark_exist_finish(_ARK *_arkp, int tid, tcb_t *tcbp); + +void ea_async_io_schedule(_ARK *_arkp, int32_t tid, iocb_t *iocbp); +void ea_async_io_harvest (_ARK *_arkp, int32_t tid, iocb_t *iocbp); + /** ******************************************************************************* * \brief * init iocb struct for IO ******************************************************************************/ static __inline__ void ea_async_io_init(_ARK *_arkp, + iocb_t *iocbp, int op, void *addr, ark_io_list_t *blist, @@ -479,10 +555,7 @@ static __inline__ void ea_async_io_init(_ARK *_arkp, int32_t tag, int32_t io_done) { - iocb_t *iocbp = &(_arkp->iocbs[tag]); - tcb_t *iotcbp = &(_arkp->tcbs[tag]); - - iotcbp->state = ARK_IO_SCHEDULE; + iocbp->state = ARK_IO_SCHEDULE; iocbp->ea = _arkp->ea; iocbp->op = op; iocbp->addr = addr; @@ -491,13 +564,13 @@ static __inline__ void ea_async_io_init(_ARK *_arkp, iocbp->start = start; iocbp->issT = 0; iocbp->cmpT = 0; - iocbp->rd = 0; iocbp->lat = 0; iocbp->hmissN = 0; iocbp->aflags = CBLK_GROUP_RAID0; iocbp->io_error = 0; iocbp->io_done = io_done; iocbp->tag = tag; + iocbp->eagain = 0; return; } diff --git a/src/kv/ark_mod.h b/src/kv/ark_mod.h deleted file mode 100644 index b5279cd0..00000000 --- a/src/kv/ark_mod.h +++ /dev/null @@ -1,101 +0,0 @@ -/* IBM_PROLOG_BEGIN_TAG */ -/* This is an automatically generated prolog. */ -/* */ -/* $Source: src/kv/ark_mod.h $ */ -/* */ -/* IBM Data Engine for NoSQL - Power Systems Edition User Library Project */ -/* */ -/* Contributors Listed Below - COPYRIGHT 2014,2015 */ -/* [+] International Business Machines Corp. */ -/* */ -/* */ -/* Licensed under the Apache License, Version 2.0 (the "License"); */ -/* you may not use this file except in compliance with the License. */ -/* You may obtain a copy of the License at */ -/* */ -/* http://www.apache.org/licenses/LICENSE-2.0 */ -/* */ -/* Unless required by applicable law or agreed to in writing, software */ -/* distributed under the License is distributed on an "AS IS" BASIS, */ -/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or */ -/* implied. See the License for the specific language governing */ -/* permissions and limitations under the License. */ -/* */ -/* IBM_PROLOG_END_TAG */ - -#ifndef __ARK_MOD_H__ -#define __ARK_MOD_H__ - -#include -#include "ark.h" -#include "bl.h" -#include "bt.h" - -#define ARK_SET_PROCESS_INB 1 -#define ARK_SET_WRITE 2 -#define ARK_SET_FINISH 3 -#define ARK_IO_DONE 4 -#define ARK_IO_HARVEST 5 -#define ARK_IO_SCHEDULE 6 -#define ARK_CMD_DONE 7 - -// operation -typedef struct _atp { - _ARK *_arkp; - - uint64_t klen; - void *key; - uint64_t vlen; - void *val; - uint64_t voff; - - uint64_t pos; - int64_t res; - - void (*cb)(int errcode, uint64_t dt, int64_t res); - uint64_t dt; - - int32_t cmd; - int32_t state; - int32_t tag; - int32_t task; - int32_t rc; - int32_t error; - - uint64_t inblen; - uint64_t oublen; - BTP inb; // input bucket space - aligned - BTP inb_orig; // input bucket space - BTP oub; // output bucket space - aligned - BTP oub_orig; // output bucket space - uint64_t vbsize; - uint8_t *vb; // value buffer space - aligned - uint8_t *vb_orig; // value buffer space - uint8_t *vval; // value buffer space - uint64_t vblkcnt; - int64_t vblk; - uint64_t hpos; - uint64_t hblk; - int64_t nblk; - uint64_t blen; - int64_t vvlen; - int32_t new_key; - -} ATP; - -typedef struct _aio -{ - EA *ea; - int32_t op; - void *addr; - ark_io_list_t *blist; - uint64_t nblks; - uint64_t start; - uint64_t new_start; - uint64_t cnt; - int32_t task; - uint32_t io_errno; - uint32_t io_done; -} AIO; - -#endif diff --git a/src/kv/arkdb.c b/src/kv/arkdb.c index b66af4f3..f105959d 100644 --- a/src/kv/arkdb.c +++ b/src/kv/arkdb.c @@ -26,36 +26,7 @@ #include REVISION_TAGS(arkdb); #endif -#include -#include -#include -#include -#include -#include -#include -#include -#include "am.h" -#include "ut.h" -#include "tag.h" -#include "vi.h" -#include "ea.h" -#include "bl.h" -#include "arkdb.h" -#include "ark.h" -#include "arp.h" -#include - -#ifdef _OS_INTERNAL -#include -#else -#include "capiblock.h" -#endif - -#include - -#include -#include -#include +#include KV_Trace_t arkdb_kv_trace; KV_Trace_t *pAT = &arkdb_kv_trace; @@ -393,6 +364,15 @@ int ark_check_persistence(_ARK *_arkp, uint64_t flags) blp->n, blp->w, rc); goto error_exit; } + _arkp->blu = bl_new(blp->n, blp->w); + if (_arkp->blu == NULL) + { + if (!errno) {KV_TRC_FFDC(pAT, "UNSET_ERRNO"); errno=ENOMEM;} + rc = errno; + KV_TRC_FFDC(pAT, "bl_new failed: n:%ld w:%ld rc:%d", + blp->n, blp->w, rc); + goto error_exit; + } _arkp->bl->count = blp->count; _arkp->bl->head = blp->head; _arkp->bl->hold = blp->hold; @@ -586,6 +566,15 @@ int ark_create_verbose(char *path, ARK **arkret, if (bl_reserve(ark->bl, ark->pers_max_blocks)) {goto ark_create_bl_err;} } + // Create the unmap block list + ark->blu = bl_new(ark->bcount, ark->blkbits); + if (ark->blu == NULL) + { + if (!errno) {KV_TRC_FFDC(pAT, "UNSET_ERRNO"); errno=ENOMEM;} + rc = errno; + KV_TRC_FFDC(pAT, "Block list initialization failed: %d", rc); + goto ark_create_blu_err; + } } else { @@ -640,12 +629,20 @@ int ark_create_verbose(char *path, ARK **arkret, goto ark_create_ttag_err; } + ark->utags = tag_new(ARK_UQ_SIZE); + if ( NULL == ark->utags ) + { + rc = ENOMEM; + KV_TRC_FFDC(pAT, "Tag initialization for utags failed: %d", rc); + goto ark_create_utag_err; + } + am_sz = ark->nasyncs * sizeof(rcb_t); ark->rcbs = am_malloc(am_sz); if ( NULL == ark->rcbs ) { rc = ENOMEM; - KV_TRC_FFDC(pAT, "Out of memory allocation of %"PRIu64" bytes for request control blocks", (ark->nasyncs * sizeof(rcb_t))); + KV_TRC_FFDC(pAT, "Out of memory allocation of %ld bytes for request control blocks", (ark->nasyncs * sizeof(rcb_t))); goto ark_create_rcbs_err; } memset(ark->rcbs,0,am_sz); @@ -655,7 +652,7 @@ int ark_create_verbose(char *path, ARK **arkret, if ( NULL == ark->tcbs ) { rc = ENOMEM; - KV_TRC_FFDC(pAT, "Out of memory allocation of %"PRIu64" bytes for task control blocks", (ark->ntasks * sizeof(rcb_t))); + KV_TRC_FFDC(pAT, "Out of memory allocation of %d bytes for tcbs", am_sz); goto ark_create_tcbs_err; } memset(ark->tcbs,0,am_sz); @@ -665,17 +662,27 @@ int ark_create_verbose(char *path, ARK **arkret, if ( NULL == ark->iocbs ) { rc = ENOMEM; - KV_TRC_FFDC(pAT, "Out of memory allocation of %"PRIu64" bytes for io control blocks", (ark->ntasks * sizeof(iocb_t))); + KV_TRC_FFDC(pAT, "Out of memory allocation of %d bytes for iocbs", am_sz); goto ark_create_iocbs_err; } memset(ark->iocbs,0,am_sz); + am_sz = ARK_UQ_SIZE * sizeof(iocb_t); + ark->ucbs = am_malloc(am_sz); + if ( NULL == ark->ucbs ) + { + rc = ENOMEM; + KV_TRC_FFDC(pAT, "Out of memory allocation of %d bytes for ucbs", am_sz); + goto ark_create_ucbs_err; + } + memset(ark->ucbs,0,am_sz); + am_sz = ark->nthrds * sizeof(scb_t); ark->poolthreads = am_malloc(am_sz); if ( NULL == ark->poolthreads ) { rc = ENOMEM; - KV_TRC_FFDC(pAT, "Out of memory allocation of %"PRIu64" bytes for server thread control blocks", (ark->nthrds * sizeof(scb_t))); + KV_TRC_FFDC(pAT, "Out of memory allocation of %d bytes for scbs", am_sz); goto ark_create_poolthreads_err; } memset(ark->poolthreads,0,am_sz); @@ -732,7 +739,7 @@ int ark_create_verbose(char *path, ARK **arkret, if ( ark->pts == NULL ) { rc = ENOMEM; - KV_TRC_FFDC(pAT, "Out of memory allocation for %"PRIu64" bytes for server thread data", (sizeof(PT) * ark->nthrds)); + KV_TRC_FFDC(pAT, "Out of memory allocation for %ld bytes for server thread data", (sizeof(PT) * ark->nthrds)); goto ark_create_taskloop_err; } memset(ark->pts,0,am_sz); @@ -758,11 +765,13 @@ int ark_create_verbose(char *path, ARK **arkret, pthread_mutex_init(&(scbp->poolmutex), NULL); pthread_cond_init(&(scbp->poolcond), NULL); - scbp->reqQ = queue_new(ark->nasyncs); - scbp->cmpQ = queue_new(ark->ntasks); - scbp->taskQ = queue_new(ark->ntasks); - scbp->scheduleQ = queue_new(ark->ntasks); - scbp->harvestQ = queue_new(ark->ntasks); + scbp->reqQ = queue_new(ark->nasyncs); + scbp->cmpQ = queue_new(ark->ntasks); + scbp->taskQ = queue_new(ark->ntasks); + scbp->scheduleQ = queue_new(ark->ntasks); + scbp->harvestQ = queue_new(ark->ntasks); + scbp->uscheduleQ = queue_new(ARK_UQ_SIZE); + scbp->uharvestQ = queue_new(ARK_UQ_SIZE); pt->id = i; pt->ark = ark; @@ -776,8 +785,12 @@ int ark_create_verbose(char *path, ARK **arkret, ark->pcmd = PT_RUN; + /* sucess, goto end */ goto ark_create_return; +/*------------------------------------------------------------------------------------- + * process ark create errors + * ----------------------------------------------------------------------------------*/ ark_create_poolloop_err: for (; i >= 0; i--) @@ -795,11 +808,13 @@ int ark_create_verbose(char *path, ARK **arkret, pthread_mutex_destroy(&(scbp->poolmutex)); pthread_cond_destroy(&(scbp->poolcond)); - if (scbp->reqQ) {queue_free(scbp->reqQ);} - if (scbp->cmpQ) {queue_free(scbp->cmpQ);} - if (scbp->taskQ) {queue_free(scbp->taskQ);} - if (scbp->scheduleQ) {queue_free(scbp->scheduleQ);} - if (scbp->harvestQ) {queue_free(scbp->harvestQ);} + if (scbp->reqQ) {queue_free(scbp->reqQ);} + if (scbp->cmpQ) {queue_free(scbp->cmpQ);} + if (scbp->taskQ) {queue_free(scbp->taskQ);} + if (scbp->scheduleQ) {queue_free(scbp->scheduleQ);} + if (scbp->harvestQ) {queue_free(scbp->harvestQ);} + if (scbp->uscheduleQ) {queue_free(scbp->uscheduleQ);} + if (scbp->uharvestQ) {queue_free(scbp->uharvestQ);} } } @@ -831,6 +846,13 @@ int ark_create_verbose(char *path, ARK **arkret, } ark_create_poolthreads_err: + KV_TRC_DBG(pAT, "free ucbs"); + if (ark->ucbs) + { + am_free(ark->ucbs); + } + +ark_create_ucbs_err: KV_TRC_DBG(pAT, "free iocbs"); if (ark->iocbs) { @@ -852,6 +874,14 @@ int ark_create_verbose(char *path, ARK **arkret, } ark_create_rcbs_err: + KV_TRC_DBG(pAT, "free utags"); + if (ark->utags) + { + tag_free(ark->utags); + } + +ark_create_utag_err: + KV_TRC_DBG(pAT, "free ttags"); if (ark->ttags) { @@ -874,6 +904,10 @@ int ark_create_verbose(char *path, ARK **arkret, am_free(ark->htc_orig); ark_create_htc_err: + KV_TRC_DBG(pAT, "blu_delete"); + bl_delete(ark->blu); + +ark_create_blu_err: KV_TRC_DBG(pAT, "bl_delete"); bl_delete(ark->bl); @@ -951,6 +985,8 @@ int ark_delete(ARK *ark) queue_free(scbp->taskQ); queue_free(scbp->scheduleQ); queue_free(scbp->harvestQ); + queue_free(scbp->uscheduleQ); + queue_free(scbp->uharvestQ); pthread_mutex_destroy(&(scbp->poolmutex)); pthread_cond_destroy(&(scbp->poolcond)); @@ -979,6 +1015,9 @@ int ark_delete(ARK *ark) am_free (_arkp->tcbs[i].aiol); } + KV_TRC_DBG(pAT, "free ucbs"); + am_free(_arkp->ucbs); + KV_TRC_DBG(pAT, "free iocbs"); am_free(_arkp->iocbs); @@ -988,6 +1027,9 @@ int ark_delete(ARK *ark) KV_TRC_DBG(pAT, "free rcbs"); am_free(_arkp->rcbs); + KV_TRC_DBG(pAT, "free utags"); + if (_arkp->utags) {tag_free(_arkp->utags);} + KV_TRC_DBG(pAT, "free ttags"); if (_arkp->ttags) {tag_free(_arkp->ttags);} @@ -1019,6 +1061,9 @@ int ark_delete(ARK *ark) KV_TRC_DBG(pAT, "bl_delete"); bl_delete(_arkp->bl); + KV_TRC_DBG(pAT, "blu_delete"); + bl_delete(_arkp->blu); + KV_TRC(pAT, "done, free arkp %p", _arkp); am_free(_arkp); @@ -1741,11 +1786,12 @@ int ark_count(ARK *ark, int64_t *count) ******************************************************************************/ int ark_flush(ARK *ark) { - int rc = 0; - int i = 0; - _ARK *_arkp = (_ARK *)ark; - hash_t *ht = NULL; - BL *bl = NULL; + _ARK *_arkp = (_ARK *)ark; + hash_t *ht = NULL; + BL *bl = NULL; + BL *blu = NULL; + int rc = 0; + int i = 0; if (ark == NULL) { @@ -1772,20 +1818,31 @@ int ark_flush(ARK *ark) KV_TRC_FFDC(pAT, "rc = %d", rc); goto ark_flush_err; } + // Create the unmap block list + blu = bl_new(_arkp->bcount, _arkp->blkbits); + if (blu == NULL) + { + if (!errno) {KV_TRC_FFDC(pAT, "UNSET_ERRNO"); errno=ENOMEM;} + rc = errno; + KV_TRC_FFDC(pAT, "rc = %d", rc); + goto ark_flush_err; + } // If we've made it here then we delete the old // hash and block list structures and set the new ones hash_free(_arkp->ht); bl_delete(_arkp->bl); + bl_delete(_arkp->blu); - _arkp->ht = ht; - _arkp->bl = bl; + _arkp->ht = ht; + _arkp->bl = bl; + _arkp->blu = blu; // We need to reset the counts for each pool thread - for (i = 0; i < _arkp->nthrds; i++) + for (i=0; i<_arkp->nthrds; i++) { - _arkp->poolthreads[i].poolstats.blk_cnt = 0; - _arkp->poolthreads[i].poolstats.kv_cnt = 0; + _arkp->poolthreads[i].poolstats.blk_cnt = 0; + _arkp->poolthreads[i].poolstats.kv_cnt = 0; _arkp->poolthreads[i].poolstats.byte_cnt = 0; } @@ -1794,15 +1851,9 @@ int ark_flush(ARK *ark) { // If we ran into an error, delete the newly // created hash and block lists structures - if (ht) - { - hash_free(ht); - } - - if (bl) - { - bl_delete(bl); - } + if (ht) {hash_free(ht);} + if (bl) {bl_delete(bl);} + if (blu) {bl_delete(blu);} } return rc; diff --git a/src/kv/arp.c b/src/kv/arp.c index 9eec0ee1..ae4fc05c 100644 --- a/src/kv/arp.c +++ b/src/kv/arp.c @@ -28,24 +28,7 @@ * \brief * ark thread pool functions ******************************************************************************/ -#include -#include -#include -#include - -#include -#include - -#include -#include -#include -#include #include -#include -#include -#include -#include -#include /** ******************************************************************************* @@ -119,22 +102,39 @@ int ark_anyreturn(_ARK *_arkp, int *tag, int64_t *res) ******************************************************************************/ int64_t ark_take_pool(_ARK *_arkp, ark_stats_t *stats, uint64_t n) { + int64_t i = 0; int64_t rc = 0; uint64_t blk = 0; pthread_mutex_lock(&_arkp->mainmutex); + /* if there are enough blocks in the unmap list, use them */ + if (_arkp->blu->count >= n) + { + /* move n blocks 1 at a time from unmap list */ + for (i=0; iblu); + bl_drop(_arkp->bl, blk); + } + blk = bl_take(_arkp->bl, n); + KV_TRC_EXT3(pAT, "TK_UM blk:%ld n:%ld bl:%ld blu:%ld", + blk, n, _arkp->bl->count, _arkp->blu->count); + goto blu_done; + } + bl_check_take(_arkp->bl, n); if (bl_left(_arkp->bl) < n) { BL *bl = NULL; + BL *blu = NULL; int64_t cursize = _arkp->size; int64_t atleast = n * _arkp->bsize; int64_t newsize = cursize + atleast + (_arkp->grow * _arkp->bsize); uint64_t newbcnt = newsize / _arkp->bsize; - KV_TRC(pAT, "RESIZE n:%ld cur:%ld new:%ld", + KV_TRC(pAT, "TK_RESZ n:%ld cur:%ld new:%ld", n, cursize/_arkp->bsize, newbcnt); rc = ea_resize(_arkp->ea, _arkp->bsize, newbcnt); @@ -143,16 +143,22 @@ int64_t ark_take_pool(_ARK *_arkp, ark_stats_t *stats, uint64_t n) rc = -1; goto error; } - bl = bl_resize(_arkp->bl, newbcnt, _arkp->bl->w); if (bl == NULL) { rc = -1; goto error; } + blu = bl_resize(_arkp->blu, newbcnt, _arkp->blu->w); + if (blu == NULL) + { + rc = -1; + goto error; + } _arkp->size = newsize; _arkp->bl = bl; + _arkp->blu = blu; } blk = bl_take(_arkp->bl, n); @@ -162,16 +168,21 @@ int64_t ark_take_pool(_ARK *_arkp, ark_stats_t *stats, uint64_t n) goto error; } +blu_done: + rc = blk; + _arkp->blkused += n; stats->blk_cnt += n; - rc = blk; - KV_TRC_EXT3(pAT, "TK_POOL blk:%ld n:%ld used:%ld", blk, n, _arkp->blkused); + KV_TRC_EXT3(pAT, "BL_STAT INC blk:%ld nblks:%ld used:%ld cnt:%ld", + blk, n, _arkp->blkused, stats->blk_cnt); error: pthread_mutex_unlock(&_arkp->mainmutex); - if (rc <= 0) KV_TRC_FFDC(pAT, "ERROR"); + if (rc <= 0) {KV_TRC_FFDC(pAT, "ERROR");} + + KV_TRC_EXT3(pAT, "BL_TAKE blk:%ld used:%ld", rc, _arkp->blkused); return rc; } @@ -181,24 +192,172 @@ int64_t ark_take_pool(_ARK *_arkp, ark_stats_t *stats, uint64_t n) ******************************************************************************/ void ark_drop_pool(_ARK *_arkp, ark_stats_t *stats, uint64_t blk) { - int64_t nblks = 0; + int64_t nblks = 0; + int i = 0; + uint64_t tblk = 0; - if (!blk) {return;} + if (blk <= 0) {KV_TRC_FFDC(pAT, "bad blk:%ld", blk); return;} pthread_mutex_lock(&_arkp->mainmutex); + nblks = bl_drop(_arkp->bl, blk); if (nblks == -1) { - KV_TRC_FFDC(pAT, "failure, unable to decrement blocks for blk:%ld", blk); + KV_TRC_FFDC(pAT, "ERROR unable to free chain for blk:%ld", blk); } else { _arkp->blkused -= nblks; stats->blk_cnt -= nblks; + KV_TRC_EXT3(pAT, "BL_STAT DEC blk:%ld nblks:%ld used:%ld cnt:%ld", + blk, nblks, _arkp->blkused, stats->blk_cnt); + } + + /*------------------------------------------------------------------------ + * if unmap is supported, mv UNMAP blks from bl to blu + *----------------------------------------------------------------------*/ + if (_arkp->ea->unmap) + { + for (i=0; ibl,1)) <= 0) + { + KV_TRC_FFDC(pAT, "ERROR bl_take i:%d nblks:%ld", i, nblks); + break; + } + KV_TRC_EXT3(pAT, "UM_bl TAKE bl:%p i:%d blk:%ld nblks:%ld", + _arkp->bl, i, tblk, nblks); + + /* drop single blk to blu */ + if (bls_add(_arkp->blu,tblk) <= 0) + { + KV_TRC_EXT3(pAT, "UM_blu DROP bl:%p i:%d blk:%ld nblks:%ld", + _arkp->blu, i, tblk, nblks); + bl_drop(_arkp->bl,tblk); + KV_TRC_FFDC(pAT, "ERROR bl_drop i:%d blk:%ld", i, tblk); + break; + } + KV_TRC_EXT3(pAT, "UM_blu DROP blk:%ld", tblk); + } } + pthread_mutex_unlock(&_arkp->mainmutex); - KV_TRC_EXT3(pAT, "DR_POOL blk:%ld drop:%ld used:%ld", - blk, nblks, _arkp->blkused); + + KV_TRC_EXT3(pAT, "BL_DROP blk:%ld used:%ld", blk, _arkp->blkused); +} + +/** + ******************************************************************************* + * \brief + * schedule/harvest/complete unmaps + ******************************************************************************/ +void process_unmapQ(_ARK *_arkp, int id, int iss) +{ + scb_t *scbp = &(_arkp->poolthreads[id]); + iocb_t *iocbp = NULL; + queue_t *usq = scbp->uscheduleQ; + queue_t *uhq = scbp->uharvestQ; + int32_t utag = 0; + int32_t max = ARK_UQ_SIZE; + int i = 0; + uint64_t blk = 0; + + if (!_arkp->blu->count && !usq->c && !uhq->c) {return;} + + max = _arkp->blu->count>max ? max : _arkp->blu->count; + + /*------------------------------------------------------------------------ + * process blu and queue UNMAPs + *----------------------------------------------------------------------*/ + for (i=0; iss && iutime = getticks(); + if (EAGAIN == tag_unbury(_arkp->utags, &utag)) {break;} + + if (i==0) + { + KV_TRC_IO(pAT, "UM_Q tid:%d max:%d blu:%ld", + id, max, _arkp->blu->count); + } + + iocb_t *iocbp = &(_arkp->ucbs[utag]); + ark_io_list_t *aiol = NULL; + + if (!(aiol=am_malloc(sizeof(ark_io_list_t)))) + { + tag_bury(_arkp->utags, utag); + break; + } + + if ((blk=bls_rem(_arkp->blu)) <= 0) + { + tag_bury(_arkp->utags, utag); + break; + } + aiol[0].blkno = blk; + aiol[0].a_tag.tag = -1; + ea_async_io_init(_arkp, iocbp, ARK_EA_UNMAP, (void *)_arkp->ea->zbuf, + aiol, 1, 0, utag, ARK_CMD_DONE); + queue_enq_unsafe(usq, utag); + } + + /*------------------------------------------------------------------------ + * harvest UNMAPs + *----------------------------------------------------------------------*/ + max=uhq->c; + for (i=0; iucbs[utag]); + + if (iocbp->state==ARK_IO_HARVEST) {ea_async_io_harvest(_arkp,id,iocbp);} + + if (iocbp->state==ARK_IO_SCHEDULE) {queue_enq_unsafe(usq, utag);} + else if (iocbp->state==ARK_IO_HARVEST) {queue_enq_unsafe(uhq, utag);} + else if (iocbp->state==ARK_CMD_DONE) + { + pthread_mutex_lock(&_arkp->mainmutex); + if (bl_drop(_arkp->bl, iocbp->blist[0].blkno) <= 0) + {KV_TRC_FFDC(pAT, "ERROR bl_drop:%ld",iocbp->blist[0].blkno);} + pthread_mutex_unlock(&_arkp->mainmutex); + + am_free(iocbp->blist); + tag_bury(_arkp->utags, iocbp->tag); + _arkp->um_opsT += 1; + _arkp->um_latT += iocbp->lat; + } + } + + /*------------------------------------------------------------------------ + * schedule UNMAPs + *----------------------------------------------------------------------*/ + max=usq->c; + for (i=0; iucbs[utag]); + + if (iocbp->state==ARK_IO_SCHEDULE) {ea_async_io_schedule(_arkp,id,iocbp);} + + if (iocbp->state==ARK_IO_SCHEDULE) {queue_enq_unsafe(usq, utag);} + else if (iocbp->state==ARK_IO_HARVEST) {queue_enq_unsafe(uhq, utag);} + else if (iocbp->state==ARK_CMD_DONE) + { + pthread_mutex_lock(&_arkp->mainmutex); + if (bl_drop(_arkp->bl, iocbp->blist[0].blkno) <= 0) + {KV_TRC_FFDC(pAT, "ERROR bl_drop:%ld",iocbp->blist[0].blkno);} + pthread_mutex_unlock(&_arkp->mainmutex); + + am_free(iocbp->blist); + tag_bury(_arkp->utags, iocbp->tag); + _arkp->um_opsT += 1; + _arkp->um_latT += iocbp->lat; + } + if (iocbp->eagain) {iocbp->eagain=0; break;} + } } /** @@ -218,8 +377,8 @@ int ark_enq_cmd(int cmd, _ARK *_arkp, uint64_t klen, void *key, if ( (_arkp == NULL) || ((klen > 0) && (key == NULL))) { - KV_TRC_FFDC(pAT, "rc = EINVAL: cmd %d, ark %p, \ - key %p, klen %"PRIu64"", cmd, _arkp, key, klen); + KV_TRC_FFDC(pAT, "ERROR EINVAL cmd:%d ark:%p key:%p klen:%ld", + cmd, _arkp, key, klen); rc = EINVAL; goto ark_enq_cmd_err; } @@ -291,7 +450,8 @@ int ark_enq_cmd(int cmd, _ARK *_arkp, uint64_t klen, void *key, void ark_rand_pool(_ARK *_arkp, int id, tcb_t *tcbp) { // find the hashtable position - rcb_t *rcbp = &(_arkp->rcbs[tcbp->rtag]); + rcb_t *rcbp = &(_arkp->rcbs[tcbp->rtag]); + iocb_t *iocbp = &(_arkp->iocbs[tcbp->ttag]); int32_t found = 0; int32_t i = 0; int32_t ea_rc = 0; @@ -416,7 +576,7 @@ void ark_rand_pool(_ARK *_arkp, int id, tcb_t *tcbp) } ark_rand_pool_err: - tcbp->state = ARK_CMD_DONE; + iocbp->state = ARK_CMD_DONE; } /** @@ -428,7 +588,8 @@ void ark_rand_pool(_ARK *_arkp, int id, tcb_t *tcbp) ******************************************************************************/ void ark_first_pool(_ARK *_arkp, int id, tcb_t *tcbp) { - rcb_t *rcbp = &(_arkp->rcbs[tcbp->rtag]); + rcb_t *rcbp = &(_arkp->rcbs[tcbp->rtag]); + iocb_t *iocbp = &(_arkp->iocbs[tcbp->ttag]); _ARI *_arip = NULL; uint64_t i; int32_t rc = 0; @@ -559,7 +720,7 @@ void ark_first_pool(_ARK *_arkp, int id, tcb_t *tcbp) _arip->bt = NULL; } - tcbp->state = ARK_CMD_DONE; + iocbp->state = ARK_CMD_DONE; } /** @@ -571,7 +732,8 @@ void ark_first_pool(_ARK *_arkp, int id, tcb_t *tcbp) ******************************************************************************/ void ark_next_pool(_ARK *_arkp, int id, tcb_t *tcbp) { - rcb_t *rcbp = &(_arkp->rcbs[tcbp->rtag]); + rcb_t *rcbp = &(_arkp->rcbs[tcbp->rtag]); + iocb_t *iocbp = &(_arkp->iocbs[tcbp->ttag]); _ARI *_arip = (_ARI *)rcbp->val; uint64_t i; int32_t rc = 0; @@ -764,7 +926,7 @@ void ark_next_pool(_ARK *_arkp, int id, tcb_t *tcbp) _arip->bt = NULL; } - tcbp->state = ARK_CMD_DONE; + iocbp->state = ARK_CMD_DONE; } /** @@ -900,6 +1062,8 @@ void *pool_function(void *arg) queue_t *tq = scbp->taskQ; queue_t *sq = scbp->scheduleQ; queue_t *hq = scbp->harvestQ; + queue_t *usq = scbp->uscheduleQ; + queue_t *uhq = scbp->uharvestQ; int32_t i = 0; uint64_t hval = 0; uint64_t hlba = 0; @@ -911,47 +1075,41 @@ void *pool_function(void *arg) KV_TRC_DBG(pAT, "start tid:%d nactive:%d", id, _arkp->nactive); + _arkp->utime = getticks(); + /*---------------------------------------------------------------------------- - * Run until the thread state is EXIT or the global - * state, ark_exit, is not set showing we are shutting - * down the ark db. + * Run until the thread state is EXIT *--------------------------------------------------------------------------*/ - while ((scbp->poolstate != PT_EXIT)) + while (scbp->poolstate != PT_EXIT) { /*------------------------------------------------------------------------ * harvest IOs *----------------------------------------------------------------------*/ MAX_POLL = queue_count(hq); - if (MAX_POLL) - { - MAX_POLL = MAX_POLL < 10 ? 1 : MAX_POLL/10; - } + if (MAX_POLL) {MAX_POLL = MAX_POLL<10 ? 1 : MAX_POLL/10;} + for (i=0; itcbs[ttag]); iocbp = &(_arkp->iocbs[ttag]); - rcbp = &(_arkp->rcbs[tcbp->rtag]); KV_TRC_EXT3(pAT, "HQ_DEQ tid:%d ttag:%3d state:%d", - id, ttag, tcbp->state); + id, ttag, iocbp->state); - if (tcbp->state == ARK_IO_HARVEST) + if (iocbp->state == ARK_IO_HARVEST) { - ea_async_io_harvest(_arkp, id, tcbp, iocbp, rcbp); + ea_async_io_harvest(_arkp, id, iocbp); if (iocbp->hmissN) {++tmiss;} } // place the iocb on a queue for the next step - if (tcbp->state==ARK_IO_SCHEDULE) {queue_enq_unsafe(sq, ttag);} - else if (tcbp->state==ARK_IO_HARVEST) {queue_enq_unsafe(hq, ttag);} - else if (tcbp->state==ARK_CMD_DONE) {queue_enq_unsafe(cq, ttag);} - else {queue_enq_unsafe(tq, ttag);} + if (iocbp->state==ARK_IO_SCHEDULE) {queue_enq_unsafe(sq, ttag);} + else if (iocbp->state==ARK_IO_HARVEST) {queue_enq_unsafe(hq, ttag);} + else if (iocbp->state==ARK_CMD_DONE) {queue_enq_unsafe(cq, ttag);} + else {queue_enq_unsafe(tq, ttag);} } /*------------------------------------------------------------------------ @@ -960,25 +1118,29 @@ void *pool_function(void *arg) int sN=sq->c; for (i=0; itcbs[ttag]); iocbp = &(_arkp->iocbs[ttag]); KV_TRC_EXT3(pAT, "SQ_DEQ tid:%d ttag:%3d state:%d", - id, ttag, tcbp->state); + id, ttag, iocbp->state); - if (tcbp->state == ARK_IO_SCHEDULE) - {ea_async_io_schedule(_arkp, id, tcbp, iocbp);} + if (iocbp->state == ARK_IO_SCHEDULE) + {ea_async_io_schedule(_arkp, id, iocbp);} // place the iocb on a queue for the next step - if (tcbp->state==ARK_IO_SCHEDULE) {queue_enq_unsafe(sq, ttag);} - else if (tcbp->state==ARK_IO_HARVEST) {queue_enq_unsafe(hq, ttag);} - else if (tcbp->state==ARK_CMD_DONE) {queue_enq_unsafe(cq, ttag);} - else {queue_enq_unsafe(tq, ttag);} + if (iocbp->state==ARK_IO_SCHEDULE) {queue_enq_unsafe(sq, ttag);} + else if (iocbp->state==ARK_IO_HARVEST) {queue_enq_unsafe(hq, ttag);} + else if (iocbp->state==ARK_CMD_DONE) {queue_enq_unsafe(cq, ttag);} + else {queue_enq_unsafe(tq, ttag);} + if (iocbp->eagain) {iocbp->eagain=0; break;} + } + + if (_arkp->ea->unmap) + { + process_unmapQ(_arkp, id, 300utime,_arkp->ns_per_tick)); } /*------------------------------------------------------------------------ @@ -987,7 +1149,7 @@ void *pool_function(void *arg) * in the task queue *----------------------------------------------------------------------*/ queue_lock(rq); - if (!rq->c && !tq->c && !sq->c && !hq->c && !cq->c) + if (!rq->c && !tq->c && !sq->c && !hq->c && !cq->c && !usq->c && !uhq->c) { ticks delta; iticks = getticks(); @@ -1005,6 +1167,7 @@ void *pool_function(void *arg) { rcb_t *rcbp = NULL; tcb_t *tcbp = NULL; + iocb_t *iocbp = NULL; int32_t rtag = 0; int32_t ttag = 0; int32_t tskrc = EAGAIN; @@ -1037,13 +1200,15 @@ void *pool_function(void *arg) break; } - tcbp = &(_arkp->tcbs[ttag]); - tcbp->rtag = rtag; - rcbp->ttag = ttag; - tcbp->state = init_task_state(_arkp, tcbp); - tcbp->sthrd = rcbp->sthrd; - tcbp->ttag = ttag; - tcbp->new_key = 0; + tcbp = &(_arkp->tcbs[ttag]); + iocbp = &(_arkp->iocbs[ttag]); + tcbp->rtag = rtag; + rcbp->ttag = ttag; + iocbp->state = init_task_state(_arkp, tcbp); + iocbp->io_error = 0; + tcbp->sthrd = rcbp->sthrd; + tcbp->ttag = ttag; + tcbp->new_key = 0; hlba = HASH_LBA(hval); HASH_SET(_arkp->ht, rcbp->pos, HASH_MAKE(1, ttag, hlba)); (void)queue_enq_unsafe(tq, ttag); @@ -1081,9 +1246,10 @@ void *pool_function(void *arg) if (queue_deq_unsafe(tq, &ttag) != 0) {continue;} - tcbp = &(_arkp->tcbs[ttag]); - iocbp = &(_arkp->iocbs[ttag]); - s = tcbp->state; + tcbp = &(_arkp->tcbs[ttag]); + iocbp = &(_arkp->iocbs[ttag]); + tcbp->ttag = ttag; + s = iocbp->state; KV_TRC_EXT3(pAT, "TQ_DEQ tid:%d ttag:%3d state:%d ", id, ttag, s); @@ -1106,37 +1272,37 @@ void *pool_function(void *arg) /*-------------------------------------------------------------------- * schedule the first IO right way *------------------------------------------------------------------*/ - if (tcbp->state == ARK_IO_SCHEDULE) + if (iocbp->state == ARK_IO_SCHEDULE) { iocbp = &(_arkp->iocbs[ttag]); - ea_async_io_schedule(_arkp, id, tcbp, iocbp); + ea_async_io_schedule(_arkp, id, iocbp); } /*-------------------------------------------------------------------- * requeue task *------------------------------------------------------------------*/ - if (tcbp->state == ARK_IO_SCHEDULE) + if (iocbp->state == ARK_IO_SCHEDULE) { KV_TRC_EXT3(pAT, "SQ_ENQ tid:%d ttag:%3d state:%d ", - id, ttag, tcbp->state); + id, ttag, iocbp->state); queue_enq_unsafe(sq,ttag); } - else if (tcbp->state == ARK_IO_HARVEST) + else if (iocbp->state == ARK_IO_HARVEST) { KV_TRC_EXT3(pAT, "HQ_ENQ tid:%d ttag:%3d state:%d ", - id, ttag, tcbp->state); + id, ttag, iocbp->state); queue_enq_unsafe(hq,ttag); } - else if (tcbp->state == ARK_CMD_DONE) + else if (iocbp->state == ARK_CMD_DONE) { KV_TRC_EXT3(pAT, "CQ_ENQ tid:%d ttag:%3d state:%d ", - id, ttag, tcbp->state); + id, ttag, iocbp->state); queue_enq_unsafe(cq,ttag); } else { KV_TRC_EXT3(pAT, "TQ_ENQ tid:%d ttag:%3d state:%d ", - id, ttag, tcbp->state); + id, ttag, iocbp->state); (void)queue_enq_unsafe(tq, ttag); } } @@ -1149,6 +1315,7 @@ void *pool_function(void *arg) { rcb_t *rcbp = NULL; tcb_t *tcbp = NULL; + iocb_t *iocbp = NULL; int32_t rtag = 0; int32_t ttag = 0; @@ -1157,15 +1324,21 @@ void *pool_function(void *arg) tcbp = &(_arkp->tcbs[ttag]); rtag = tcbp->rtag; rcbp = &(_arkp->rcbs[rtag]); + iocbp = &(_arkp->iocbs[ttag]); KV_TRC_EXT3(pAT, "CQ_DEQ tid:%d ttag:%3d state:%d ", - id, ttag, tcbp->state); + id, ttag, iocbp->state); - if (tcbp->state == ARK_CMD_DONE) + if (iocbp->state == ARK_CMD_DONE) { uint32_t lat = UDELTA(rcbp->stime, _arkp->ns_per_tick); UPDATE_LAT(_arkp, rcbp, lat); + if (iocbp->io_error) + { + rcbp->res = -1; + rcbp->rc = iocbp->io_error; + } hlba = HASH_LBA(HASH_GET(_arkp->ht, rcbp->pos)); HASH_SET(_arkp->ht, rcbp->pos, HASH_MAKE(0, 0, hlba)); if (rcbp->cb) @@ -1194,7 +1367,7 @@ void *pool_function(void *arg) else { KV_TRC_EXT3(pAT, "FFDC CQ tid:%d ttag:%3d state:%d UNKNOWN_STATE", - id, ttag, tcbp->state); + id, ttag, iocbp->state); } } @@ -1207,23 +1380,25 @@ void *pool_function(void *arg) _arkp->del_opsT; uint64_t latT = _arkp->set_latT + _arkp->get_latT + _arkp->exi_latT +\ _arkp->del_latT; - uint64_t lat=0,set_lat=0,get_lat=0,exi_lat=0,del_lat=0,QDA=0; + uint64_t lat=0,set_lat=0,get_lat=0,exi_lat=0,del_lat=0,um_lat=0,QDA=0; if (opsT) {lat = latT/opsT;} if (_arkp->set_opsT) {set_lat = _arkp->set_latT/_arkp->set_opsT;} if (_arkp->get_opsT) {get_lat = _arkp->get_latT/_arkp->get_opsT;} if (_arkp->exi_opsT) {exi_lat = _arkp->exi_latT/_arkp->exi_opsT;} if (_arkp->del_opsT) {del_lat = _arkp->del_latT/_arkp->del_opsT;} + if (_arkp->um_opsT) {um_lat = _arkp->um_latT/_arkp->um_opsT;} if (_arkp->QDT) {QDA = _arkp->QDT/_arkp->QDN;} KV_TRC_PERF1(pAT,"IO: tid:%d PERF opsT:%7ld lat:%7ld " - "opsT(%7ld %7ld %7ld %7ld) " - "lat(%7ld %6ld %6ld %6ld) QD:%4ld issT:%4d", + "opsT(%7ld %7ld %7ld %7ld %7ld) " + "lat(%7ld %6ld %6ld %6ld %6ld) QD:%4ld issT:%4d", id, opsT, lat, _arkp->set_opsT, _arkp->get_opsT, _arkp->exi_opsT, - _arkp->del_opsT, - set_lat, get_lat, exi_lat, del_lat, + _arkp->del_opsT, _arkp->um_opsT, + set_lat, get_lat, exi_lat, del_lat, um_lat, QDA, _arkp->issT); KV_TRC_PERF2(pAT,"IO: tid:%d QUEUES rq:%3d tq:%3d sq:%4d hq:%4d " - "cq:%4d", id, rq->c, tq->c, sq->c, hq->c, cq->c); + "cq:%4d usq:%4d uhq:%4d", + id, rq->c, tq->c, sq->c, hq->c, cq->c, usq->c, uhq->c); _arkp->set_latT = 0; _arkp->get_latT = 0; _arkp->exi_latT = 0; @@ -1271,6 +1446,14 @@ void *pool_function(void *arg) } } + /* allow unmaps to finish */ + while (_arkp->ea->unmap && (_arkp->blu->count || usq->c || uhq->c)) + {process_unmapQ(_arkp, id, 1);} + + KV_TRC_PERF2(pAT,"IO: tid:%d QUEUES rq:%3d tq:%3d sq:%4d hq:%4d " + "cq:%4d usq:%4d uhq:%4d", + id, rq->c, tq->c, sq->c, hq->c, cq->c, usq->c, uhq->c); + KV_TRC_FFDC(pAT, "PSTATS kv:%8ld ops:%8ld ios:%8ld bytes:%8ld blks:%8ld", scbp->poolstats.kv_cnt + _arkp->pers_stats.kv_cnt, scbp->poolstats.ops_cnt, diff --git a/src/kv/arp.h b/src/kv/arp.h deleted file mode 100644 index d4a6ac09..00000000 --- a/src/kv/arp.h +++ /dev/null @@ -1,65 +0,0 @@ -/* IBM_PROLOG_BEGIN_TAG */ -/* This is an automatically generated prolog. */ -/* */ -/* $Source: src/kv/arp.h $ */ -/* */ -/* IBM Data Engine for NoSQL - Power Systems Edition User Library Project */ -/* */ -/* Contributors Listed Below - COPYRIGHT 2014,2015 */ -/* [+] International Business Machines Corp. */ -/* */ -/* */ -/* Licensed under the Apache License, Version 2.0 (the "License"); */ -/* you may not use this file except in compliance with the License. */ -/* You may obtain a copy of the License at */ -/* */ -/* http://www.apache.org/licenses/LICENSE-2.0 */ -/* */ -/* Unless required by applicable law or agreed to in writing, software */ -/* distributed under the License is distributed on an "AS IS" BASIS, */ -/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or */ -/* implied. See the License for the specific language governing */ -/* permissions and limitations under the License. */ -/* */ -/* IBM_PROLOG_END_TAG */ - -#ifndef __ARP_H__ -#define __ARP_H__ - - -void *pool_function(void *arg); - -int ark_enq_cmd(int cmd, _ARK *_arkp,uint64_t klen,void *key,uint64_t vbuflen,void *vbuf,uint64_t voff, - void (*cb)(int errcode, uint64_t dt,int64_t res), uint64_t dt, int32_t pthr, int *ptag); - -int ark_wait_tag(_ARK *_arkp, int tag, int *errcode, int64_t *res); - -void ark_set_finish(_ARK *_arkp, int tid, tcb_t *tcbp); -void ark_set_write(_ARK *_arkp, int tid, tcb_t *tcbp); -void ark_set_process(_ARK *_arkp, int tid, tcb_t *tcbp); -void ark_set_process_inb(_ARK *_arkp, int tid, tcb_t *tcbp); -void ark_set_start(_ARK *_arkp, int tid, tcb_t *tcbp); - -void ark_get_start(_ARK *_arkp, int tid, tcb_t *tcbp); -void ark_get_finish(_ARK *_arkp, int tid, tcb_t *tcbp); -void ark_get_process(_ARK *_arkp, int tid, tcb_t *tcbp); - -void ark_del_start(_ARK *_arkp, int tid, tcb_t *tcbp); -void ark_del_process(_ARK *_arkp, int tid, tcb_t *tcbp); -void ark_del_finish(_ARK *_arkp, int32_t tid, tcb_t *tcbp); - -void ark_exist_start(_ARK *_arkp, int tid, tcb_t *tcbp); -void ark_exist_finish(_ARK *_arkp, int tid, tcb_t *tcbp); - -int ea_async_io_schedule(_ARK *_arkp, - int32_t tid, - tcb_t *tcbp, - iocb_t *iocbp); -int ea_async_io_harvest(_ARK *_arkp, - int32_t tid, - tcb_t *tcbp, - iocb_t *iocbp, - rcb_t *iorcbp); - - -#endif diff --git a/src/kv/arp_del.c b/src/kv/arp_del.c index 7199a9e0..6f28ba9a 100644 --- a/src/kv/arp_del.c +++ b/src/kv/arp_del.c @@ -23,21 +23,7 @@ /* */ /* IBM_PROLOG_END_TAG */ -#include -#include -#include -#include - -#include -#include -#include #include -#include -#include -#include -#include - -#include /** ******************************************************************************* @@ -48,7 +34,6 @@ void ark_del_start(_ARK *_arkp, int tid, tcb_t *tcbp) { scb_t *scbp = &(_arkp->poolthreads[tid]); rcb_t *rcbp = &(_arkp->rcbs[tcbp->rtag]); - tcb_t *iotcbp = &(_arkp->tcbs[rcbp->ttag]); iocb_t *iocbp = &(_arkp->iocbs[rcbp->ttag]); int32_t rc = 0; @@ -75,7 +60,7 @@ void ark_del_start(_ARK *_arkp, int tid, tcb_t *tcbp) tid, tcbp->ttag, rcbp->pos, rcbp->key, rcbp->klen, rcbp->pos); rcbp->res = -1; rcbp->rc = ENOENT; - tcbp->state = ARK_CMD_DONE; + iocbp->state = ARK_CMD_DONE; goto ark_del_start_err; } @@ -88,7 +73,7 @@ void ark_del_start(_ARK *_arkp, int tid, tcb_t *tcbp) tid, tcbp->ttag, rcbp->pos, rcbp->key, rcbp->klen, rcbp->pos); rcbp->res = -1; rcbp->rc = ENOENT; - tcbp->state = ARK_CMD_DONE; + iocbp->state = ARK_CMD_DONE; goto ark_del_start_err; } @@ -103,7 +88,7 @@ void ark_del_start(_ARK *_arkp, int tid, tcb_t *tcbp) KV_TRC_FFDC(pAT, "bt_realloc failed ttag:%d", tcbp->ttag); rcbp->res = -1; rcbp->rc = rc; - tcbp->state = ARK_CMD_DONE; + iocbp->state = ARK_CMD_DONE; goto ark_del_start_err; } tcbp->inb_size = tcbp->blen*_arkp->bsize; @@ -127,7 +112,7 @@ void ark_del_start(_ARK *_arkp, int tid, tcb_t *tcbp) { rcbp->res = -1; rcbp->rc = ENOMEM; - tcbp->state = ARK_CMD_DONE; + iocbp->state = ARK_CMD_DONE; KV_TRC_FFDC(pAT, "bl_rechain failed, ttag:%d", tcbp->ttag); goto ark_del_start_err; } @@ -136,14 +121,14 @@ void ark_del_start(_ARK *_arkp, int tid, tcb_t *tcbp) KV_TRC(pAT, "RD_HASH tid:%d ttag:%3d pos:%6ld", tid, tcbp->ttag, rcbp->pos); // Schedule the IO to read the hash entry from storage - ea_async_io_init(_arkp, ARK_EA_READ, (void *)tcbp->inb, tcbp->aiol, + ea_async_io_init(_arkp, iocbp, ARK_EA_READ, (void *)tcbp->inb, tcbp->aiol, tcbp->blen, 0, tcbp->ttag, ARK_DEL_PROCESS); if (MEM_FASTPATH) { - ea_async_io_schedule(_arkp, tid, iotcbp, iocbp); - ea_async_io_harvest (_arkp, tid, iotcbp, iocbp, rcbp); - if (iotcbp->state == ARK_DEL_PROCESS) {ark_del_process(_arkp, tid, tcbp);} + ea_async_io_schedule(_arkp, tid, iocbp); + ea_async_io_harvest (_arkp, tid, iocbp); + if (iocbp->state == ARK_DEL_PROCESS) {ark_del_process(_arkp, tid, tcbp);} } ark_del_start_err: @@ -159,7 +144,6 @@ void ark_del_process(_ARK *_arkp, int tid, tcb_t *tcbp) { scb_t *scbp = &(_arkp->poolthreads[tid]); rcb_t *rcbp = &(_arkp->rcbs[tcbp->rtag]); - tcb_t *iotcbp = &(_arkp->tcbs[rcbp->ttag]); iocb_t *iocbp = &(_arkp->iocbs[rcbp->ttag]); uint64_t blkcnt = 0; uint64_t exivlen = 0; @@ -190,7 +174,7 @@ void ark_del_process(_ARK *_arkp, int tid, tcb_t *tcbp) KV_TRC_FFDC(pAT, "bt_reallocif rc != 0, ttag:%3d", tcbp->ttag); rcbp->res = -1; rcbp->rc = rc; - tcbp->state = ARK_CMD_DONE; + iocbp->state = ARK_CMD_DONE; goto ark_del_process_err; } tcbp->oub_size = new_btsize; @@ -201,6 +185,8 @@ void ark_del_process(_ARK *_arkp, int tid, tcb_t *tcbp) rcbp->res = bt_del_def(tcbp->oub, tcbp->inb, rcbp->klen, rcbp->key, (uint8_t*)&dblk, &oldvlen); + KV_TRC(pAT,"EXISTS hblk:%ld dblk:%ld", tcbp->hblk, dblk); + // Return the blocks of the hash entry back to // the free list ark_drop_pool(_arkp, &(scbp->poolstats), tcbp->hblk); @@ -226,7 +212,7 @@ void ark_del_process(_ARK *_arkp, int tid, tcb_t *tcbp) blkcnt, tcbp->ttag); rcbp->rc = ENOSPC; rcbp->res = -1; - tcbp->state = ARK_CMD_DONE; + iocbp->state = ARK_CMD_DONE; goto ark_del_process_err; } @@ -235,7 +221,7 @@ void ark_del_process(_ARK *_arkp, int tid, tcb_t *tcbp) { rcbp->res = -1; rcbp->rc = ENOMEM; - tcbp->state = ARK_CMD_DONE; + iocbp->state = ARK_CMD_DONE; KV_TRC_FFDC(pAT, "bl_rechain failed, ttag:%d", tcbp->ttag); goto ark_del_process_err; } @@ -249,14 +235,14 @@ void ark_del_process(_ARK *_arkp, int tid, tcb_t *tcbp) tid, tcbp->ttag, rcbp->pos, tcbp->bytes); // Schedule the WRITE IO of the updated hash entry. - ea_async_io_init(_arkp, ARK_EA_WRITE, (void *)tcbp->oub, + ea_async_io_init(_arkp, iocbp, ARK_EA_WRITE, (void *)tcbp->oub, tcbp->aiol, blkcnt, 0, tcbp->ttag, ARK_DEL_FINISH); if (MEM_FASTPATH) { - ea_async_io_schedule(_arkp, tid, iotcbp, iocbp); - ea_async_io_harvest (_arkp, tid, iotcbp, iocbp, rcbp); - if (iotcbp->state == ARK_DEL_FINISH) {ark_del_finish(_arkp,tid,tcbp);} + ea_async_io_schedule(_arkp, tid, iocbp); + ea_async_io_harvest (_arkp, tid, iocbp); + if (iocbp->state == ARK_DEL_FINISH) {ark_del_finish(_arkp,tid,tcbp);} } } else @@ -277,7 +263,7 @@ void ark_del_process(_ARK *_arkp, int tid, tcb_t *tcbp) tid, tcbp->ttag, rcbp->pos, rcbp->key, rcbp->klen, rcbp->pos); rcbp->rc = ENOENT; rcbp->res = -1; - tcbp->state = ARK_CMD_DONE; + iocbp->state = ARK_CMD_DONE; } ark_del_process_err: @@ -293,6 +279,7 @@ void ark_del_finish(_ARK *_arkp, int32_t tid, tcb_t *tcbp) { rcb_t *rcbp = &(_arkp->rcbs[tcbp->rtag]); scb_t *scbp = &(_arkp->poolthreads[tid]); + iocb_t *iocbp = &(_arkp->iocbs[rcbp->ttag]); scbp->poolstats.kv_cnt -= 1; scbp->poolstats.byte_cnt -= tcbp->bytes; @@ -325,7 +312,7 @@ void ark_del_finish(_ARK *_arkp, int32_t tid, tcb_t *tcbp) } } - tcbp->state = ARK_CMD_DONE; + iocbp->state = ARK_CMD_DONE; return; } diff --git a/src/kv/arp_exist.c b/src/kv/arp_exist.c index ac212da0..f016ce0f 100644 --- a/src/kv/arp_exist.c +++ b/src/kv/arp_exist.c @@ -23,21 +23,7 @@ /* */ /* IBM_PROLOG_END_TAG */ -#include -#include -#include -#include - -#include -#include -#include #include -#include -#include -#include -#include - -#include /** ******************************************************************************* @@ -48,7 +34,6 @@ void ark_exist_start(_ARK *_arkp, int tid, tcb_t *tcbp) { scb_t *scbp = &(_arkp->poolthreads[tid]); rcb_t *rcbp = &(_arkp->rcbs[tcbp->rtag]); - tcb_t *iotcbp = &(_arkp->tcbs[rcbp->ttag]); iocb_t *iocbp = &(_arkp->iocbs[rcbp->ttag]); int32_t rc = 0; @@ -71,11 +56,11 @@ void ark_exist_start(_ARK *_arkp, int tid, tcb_t *tcbp) // Set the error if (tcbp->hblk == 0) { - KV_TRC(pAT, "ENOENT tid:%d ttag:%3d key:%p klen:%ld pos:%ld", + KV_TRC(pAT, "ENOENT tid:%d ttag:%3d key:%p klen:%ld pos:%ld", tid, tcbp->ttag, rcbp->key, rcbp->klen, rcbp->pos); rcbp->res = -1; rcbp->rc = ENOENT; - tcbp->state = ARK_CMD_DONE; + iocbp->state = ARK_CMD_DONE; goto ark_exist_start_err; } @@ -93,7 +78,7 @@ void ark_exist_start(_ARK *_arkp, int tid, tcb_t *tcbp) KV_TRC_FFDC(pAT, "bt_realloc failed tcbp:%p ttag:%d", tcbp, tcbp->ttag); rcbp->res = -1; rcbp->rc = rc; - tcbp->state = ARK_CMD_DONE; + iocbp->state = ARK_CMD_DONE; goto ark_exist_start_err; } tcbp->inb_size = tcbp->blen*_arkp->bsize; @@ -117,21 +102,21 @@ void ark_exist_start(_ARK *_arkp, int tid, tcb_t *tcbp) { rcbp->res = -1; rcbp->rc = ENOMEM; - tcbp->state = ARK_CMD_DONE; + iocbp->state = ARK_CMD_DONE; KV_TRC_FFDC(pAT, "bl_rechain failed, ttag:%d", tcbp->ttag); goto ark_exist_start_err; } tcbp->aiolN = tcbp->blen; KV_TRC(pAT, "RD_HASH tid:%d ttag:%3d", tid, tcbp->ttag); - ea_async_io_init(_arkp, ARK_EA_READ, (void *)tcbp->inb, tcbp->aiol, + ea_async_io_init(_arkp, iocbp, ARK_EA_READ, (void *)tcbp->inb, tcbp->aiol, tcbp->blen, 0, tcbp->ttag, ARK_EXIST_FINISH); if (MEM_FASTPATH) { - ea_async_io_schedule(_arkp, tid, iotcbp, iocbp); - ea_async_io_harvest (_arkp, tid, iotcbp, iocbp, rcbp); - if (iotcbp->state == ARK_EXIST_FINISH) {ark_exist_finish(_arkp,tid,tcbp);} + ea_async_io_schedule(_arkp, tid, iocbp); + ea_async_io_harvest (_arkp, tid, iocbp); + if (iocbp->state == ARK_EXIST_FINISH) {ark_exist_finish(_arkp,tid,tcbp);} } ark_exist_start_err: @@ -145,7 +130,8 @@ void ark_exist_start(_ARK *_arkp, int tid, tcb_t *tcbp) ******************************************************************************/ void ark_exist_finish(_ARK *_arkp, int tid, tcb_t *tcbp) { - rcb_t *rcbp = &(_arkp->rcbs[tcbp->rtag]); + rcb_t *rcbp = &(_arkp->rcbs[tcbp->rtag]); + iocb_t *iocbp = &(_arkp->iocbs[rcbp->ttag]); KV_TRC(pAT, "INB_GET tid:%d ttag:%3d tot:%ld used:%ld", tid, tcbp->ttag, tcbp->inb_size, tcbp->inb->len); @@ -158,10 +144,10 @@ void ark_exist_finish(_ARK *_arkp, int tid, tcb_t *tcbp) tid, tcbp->ttag, rcbp->pos, rcbp->key, rcbp->klen); rcbp->rc = ENOENT; rcbp->res = -1; - tcbp->state = ARK_CMD_DONE; + iocbp->state = ARK_CMD_DONE; } - tcbp->state = ARK_CMD_DONE; + iocbp->state = ARK_CMD_DONE; return; } diff --git a/src/kv/arp_get.c b/src/kv/arp_get.c index 9fa2f279..ed8437e0 100644 --- a/src/kv/arp_get.c +++ b/src/kv/arp_get.c @@ -23,21 +23,7 @@ /* */ /* IBM_PROLOG_END_TAG */ -#include -#include -#include -#include - -#include -#include -#include #include -#include -#include -#include -#include - -#include /** ******************************************************************************* @@ -47,7 +33,6 @@ void ark_get_start(_ARK *_arkp, int tid, tcb_t *tcbp) { scb_t *scbp = &(_arkp->poolthreads[tid]); rcb_t *rcbp = &(_arkp->rcbs[tcbp->rtag]); - tcb_t *iotcbp = &(_arkp->tcbs[rcbp->ttag]); iocb_t *iocbp = &(_arkp->iocbs[rcbp->ttag]); int32_t rc = 0; @@ -74,7 +59,7 @@ void ark_get_start(_ARK *_arkp, int tid, tcb_t *tcbp) tid, tcbp->ttag, rcbp->pos, rcbp->key, rcbp->klen); rcbp->res = -1; rcbp->rc = ENOENT; - tcbp->state = ARK_CMD_DONE; + iocbp->state = ARK_CMD_DONE; goto ark_get_start_err; } @@ -95,7 +80,7 @@ void ark_get_start(_ARK *_arkp, int tid, tcb_t *tcbp) KV_TRC_FFDC(pAT, "bt_realloc failed ttag:%d", tcbp->ttag); rcbp->res = -1; rcbp->rc = rc; - tcbp->state = ARK_CMD_DONE; + iocbp->state = ARK_CMD_DONE; goto ark_get_start_err; } tcbp->inb_size = tcbp->blen*_arkp->bsize; @@ -118,7 +103,7 @@ void ark_get_start(_ARK *_arkp, int tid, tcb_t *tcbp) { rcbp->res = -1; rcbp->rc = ENOMEM; - tcbp->state = ARK_CMD_DONE; + iocbp->state = ARK_CMD_DONE; KV_TRC_FFDC(pAT, "bl_rechain failed, ttag:%d", tcbp->ttag); goto ark_get_start_err; } @@ -127,14 +112,14 @@ void ark_get_start(_ARK *_arkp, int tid, tcb_t *tcbp) KV_TRC(pAT, "RD_HASH tid:%d ttag:%3d pos:%6ld blk#:%5ld hblk:%6ld nblks:%ld", tid, tcbp->ttag, rcbp->pos, tcbp->aiol[0].blkno,tcbp->hblk,tcbp->blen); - ea_async_io_init(_arkp, ARK_EA_READ, (void *)tcbp->inb, tcbp->aiol, + ea_async_io_init(_arkp, iocbp, ARK_EA_READ, (void *)tcbp->inb, tcbp->aiol, tcbp->blen, 0, tcbp->ttag, ARK_GET_PROCESS); if (MEM_FASTPATH) { - ea_async_io_schedule(_arkp, tid, iotcbp, iocbp); - ea_async_io_harvest (_arkp, tid, iotcbp, iocbp, rcbp); - if (iotcbp->state == ARK_GET_PROCESS) {ark_get_process(_arkp, tid, tcbp);} + ea_async_io_schedule(_arkp, tid, iocbp); + ea_async_io_harvest (_arkp, tid, iocbp); + if (iocbp->state == ARK_GET_PROCESS) {ark_get_process(_arkp, tid, tcbp);} } ark_get_start_err: @@ -149,7 +134,6 @@ void ark_get_process(_ARK *_arkp, int tid, tcb_t *tcbp) { scb_t *scbp = &(_arkp->poolthreads[tid]); rcb_t *rcbp = &(_arkp->rcbs[tcbp->rtag]); - tcb_t *iotcbp = &(_arkp->tcbs[rcbp->ttag]); iocb_t *iocbp = &(_arkp->iocbs[rcbp->ttag]); uint8_t *new_vb = NULL; uint64_t vblk = 0; @@ -194,7 +178,7 @@ void ark_get_process(_ARK *_arkp, int tid, tcb_t *tcbp) KV_TRC_FFDC(pAT, "am_realloc failed ttag:%d", tcbp->ttag); rcbp->rc = ENOMEM; rcbp->res = -1; - tcbp->state = ARK_CMD_DONE; + iocbp->state = ARK_CMD_DONE; goto ark_get_process_err; } @@ -210,7 +194,7 @@ void ark_get_process(_ARK *_arkp, int tid, tcb_t *tcbp) { rcbp->res = -1; rcbp->rc = ENOMEM; - tcbp->state = ARK_CMD_DONE; + iocbp->state = ARK_CMD_DONE; KV_TRC_FFDC(pAT, "bl_rechain failed, ttag:%d", tcbp->ttag); goto ark_get_process_err; } @@ -222,14 +206,14 @@ void ark_get_process(_ARK *_arkp, int tid, tcb_t *tcbp) tid, tcbp->ttag, rcbp->pos, rcbp->vlen); // Schedule the READ of the key's value into the // variable buffer. - ea_async_io_init(_arkp, ARK_EA_READ, (void *)tcbp->vb, + ea_async_io_init(_arkp, iocbp, ARK_EA_READ, (void *)tcbp->vb, tcbp->aiol, tcbp->blen, 0, tcbp->ttag, ARK_GET_FINISH); if (MEM_FASTPATH) { - ea_async_io_schedule(_arkp, tid, iotcbp, iocbp); - ea_async_io_harvest (_arkp, tid, iotcbp, iocbp, rcbp); - if (iotcbp->state == ARK_GET_FINISH) {ark_get_finish(_arkp,tid,tcbp);} + ea_async_io_schedule(_arkp, tid, iocbp); + ea_async_io_harvest (_arkp, tid, iocbp); + if (iocbp->state == ARK_GET_FINISH) {ark_get_finish(_arkp,tid,tcbp);} } } else @@ -246,7 +230,7 @@ void ark_get_process(_ARK *_arkp, int tid, tcb_t *tcbp) tid, tcbp->ttag, rcbp->pos, rcbp->key, rcbp->klen); rcbp->rc = ENOENT; rcbp->res = -1; - tcbp->state = ARK_CMD_DONE; + iocbp->state = ARK_CMD_DONE; } ark_get_process_err: @@ -261,6 +245,7 @@ void ark_get_process(_ARK *_arkp, int tid, tcb_t *tcbp) void ark_get_finish(_ARK *_arkp, int tid, tcb_t *tcbp) { rcb_t *rcbp = &(_arkp->rcbs[tcbp->rtag]); + iocb_t *iocbp = &(_arkp->iocbs[rcbp->ttag]); if (DUMP_KV) { @@ -281,7 +266,7 @@ void ark_get_finish(_ARK *_arkp, int tid, tcb_t *tcbp) } rcbp->res = tcbp->vvlen; - tcbp->state = ARK_CMD_DONE; + iocbp->state = ARK_CMD_DONE; return; } diff --git a/src/kv/arp_set.c b/src/kv/arp_set.c index ac6b240d..e5f71434 100644 --- a/src/kv/arp_set.c +++ b/src/kv/arp_set.c @@ -23,22 +23,7 @@ /* */ /* IBM_PROLOG_END_TAG */ -#include -#include -#include -#include - -#include -#include -#include #include -#include -#include -#include -#include -#include - -#include /** ******************************************************************************* @@ -48,7 +33,6 @@ void ark_set_start(_ARK *_arkp, int tid, tcb_t *tcbp) { scb_t *scbp = &(_arkp->poolthreads[tid]); rcb_t *rcbp = &(_arkp->rcbs[tcbp->rtag]); - tcb_t *iotcbp = &(_arkp->tcbs[rcbp->ttag]); iocb_t *iocbp = &(_arkp->iocbs[rcbp->ttag]); uint64_t new_vbsize = 0; int32_t rc = 0; @@ -95,7 +79,7 @@ void ark_set_start(_ARK *_arkp, int tid, tcb_t *tcbp) { rcbp->res = -1; rcbp->rc = ENOMEM; - tcbp->state = ARK_CMD_DONE; + iocbp->state = ARK_CMD_DONE; KV_TRC_FFDC(pAT, "realloc failed, ttag = %d rc = %d", tcbp->ttag, rc); goto ark_set_start_err; } @@ -146,7 +130,7 @@ void ark_set_start(_ARK *_arkp, int tid, tcb_t *tcbp) { rcbp->res = -1; rcbp->rc = rc; - tcbp->state = ARK_CMD_DONE; + iocbp->state = ARK_CMD_DONE; KV_TRC_FFDC(pAT, "bt_reallocif failed, ttag:%3d rc:%d errno:%d", tcbp->ttag, rc, errno); goto ark_set_start_err; @@ -172,7 +156,7 @@ void ark_set_start(_ARK *_arkp, int tid, tcb_t *tcbp) { rcbp->res = -1; rcbp->rc = ENOMEM; - tcbp->state = ARK_CMD_DONE; + iocbp->state = ARK_CMD_DONE; KV_TRC_FFDC(pAT, "bl_rechain failed, ttag:%d", tcbp->ttag); goto ark_set_start_err; } @@ -181,14 +165,14 @@ void ark_set_start(_ARK *_arkp, int tid, tcb_t *tcbp) KV_TRC(pAT, "RD_HASH tid:%d ttag:%3d pos:%6ld hblk:%6ld nblks:%ld", tid, tcbp->ttag, rcbp->pos, tcbp->hblk, tcbp->blen); - ea_async_io_init(_arkp, ARK_EA_READ, + ea_async_io_init(_arkp, iocbp, ARK_EA_READ, (void *)tcbp->inb, tcbp->aiol, tcbp->blen, 0, tcbp->ttag, ARK_SET_PROCESS); if (MEM_FASTPATH) { - ea_async_io_schedule(_arkp, tid, iotcbp, iocbp); - ea_async_io_harvest (_arkp, tid, iotcbp, iocbp, rcbp); + ea_async_io_schedule(_arkp, tid, iocbp); + ea_async_io_harvest (_arkp, tid, iocbp); ark_set_process (_arkp, tid, tcbp); } } @@ -206,7 +190,6 @@ void ark_set_process(_ARK *_arkp, int tid, tcb_t *tcbp) { scb_t *scbp = &(_arkp->poolthreads[tid]); rcb_t *rcbp = &(_arkp->rcbs[tcbp->rtag]); - tcb_t *iotcbp = &(_arkp->tcbs[rcbp->ttag]); iocb_t *iocbp = &(_arkp->iocbs[rcbp->ttag]); uint64_t oldvlen = 0; uint64_t oldvdf = 0; @@ -254,7 +237,7 @@ void ark_set_process(_ARK *_arkp, int tid, tcb_t *tcbp) KV_TRC_FFDC(pAT, "bt_reallocif rc != 0, ttag:%3d", tcbp->ttag); rcbp->res = -1; rcbp->rc = rc; - tcbp->state = ARK_CMD_DONE; + iocbp->state = ARK_CMD_DONE; goto ark_set_process_err; } tcbp->oub_size = new_btsize; @@ -287,7 +270,7 @@ void ark_set_process(_ARK *_arkp, int tid, tcb_t *tcbp) { rcbp->res = -1; rcbp->rc = ENOSPC; - tcbp->state = ARK_CMD_DONE; + iocbp->state = ARK_CMD_DONE; KV_TRC_FFDC(pAT, "FFDC tid:%d ttag:%3d pos:%6ld ark_take_pool " "%ld failed rc = %d", tid, tcbp->ttag, rcbp->pos, tcbp->vblkcnt, rc); @@ -324,7 +307,7 @@ void ark_set_process(_ARK *_arkp, int tid, tcb_t *tcbp) { rcbp->res = -1; rcbp->rc = ENOSPC; - tcbp->state = ARK_CMD_DONE; + iocbp->state = ARK_CMD_DONE; KV_TRC_FFDC(pAT, "FFDC tid:%d ttag:%3d pos:%6ld ark_take_pool " "%ld failed rc = %d", tid, tcbp->ttag, rcbp->pos, tcbp->vblkcnt, rc); @@ -345,7 +328,7 @@ void ark_set_process(_ARK *_arkp, int tid, tcb_t *tcbp) { rcbp->res = -1; rcbp->rc = ENOSPC; - tcbp->state = ARK_CMD_DONE; + iocbp->state = ARK_CMD_DONE; KV_TRC_FFDC(pAT, "FFDC tid:%d ttag:%3d pos:%6ld ark_take_pool " "%ld failed rc = %d", tid, tcbp->ttag, rcbp->pos, tcbp->vblkcnt, rc); @@ -407,7 +390,7 @@ void ark_set_process(_ARK *_arkp, int tid, tcb_t *tcbp) tid, tcbp->ttag, rcbp->pos, tcbp->vblkcnt,tcbp->new_key); rcbp->rc = ENOMEM; rcbp->res = -1; - tcbp->state = ARK_CMD_DONE; + iocbp->state = ARK_CMD_DONE; goto ark_set_process_err; } @@ -421,7 +404,7 @@ void ark_set_process(_ARK *_arkp, int tid, tcb_t *tcbp) { rcbp->res = -1; rcbp->rc = ENOMEM; - tcbp->state = ARK_CMD_DONE; + iocbp->state = ARK_CMD_DONE; KV_TRC_FFDC(pAT, "bl_rechain failed, ttag:%d", tcbp->ttag); goto ark_set_process_err; } @@ -429,14 +412,14 @@ void ark_set_process(_ARK *_arkp, int tid, tcb_t *tcbp) scbp->poolstats.io_cnt += tcbp->vblkcnt; - ea_async_io_init(_arkp, ARK_EA_WRITE, (void*)tcbp->vb, + ea_async_io_init(_arkp, iocbp, ARK_EA_WRITE, (void*)tcbp->vb, tcbp->aiol, tcbp->vblkcnt, 0, tcbp->ttag, ARK_SET_WRITE); if (MEM_FASTPATH) { - ea_async_io_schedule(_arkp, tid, iotcbp, iocbp); - ea_async_io_harvest (_arkp, tid, iotcbp, iocbp, rcbp); - if (iotcbp->state == ARK_SET_WRITE) {ark_set_write(_arkp, tid, tcbp);} + ea_async_io_schedule(_arkp, tid, iocbp); + ea_async_io_harvest (_arkp, tid, iocbp); + if (iocbp->state == ARK_SET_WRITE) {ark_set_write(_arkp, tid, tcbp);} } } else @@ -457,7 +440,6 @@ void ark_set_write(_ARK *_arkp, int tid, tcb_t *tcbp) { rcb_t *rcbp = &(_arkp->rcbs[tcbp->rtag]); scb_t *scbp = &(_arkp->poolthreads[tid]); - tcb_t *iotcbp = &(_arkp->tcbs[rcbp->ttag]); iocb_t *iocbp = &(_arkp->iocbs[rcbp->ttag]); uint64_t blkcnt = 0; @@ -481,7 +463,7 @@ void ark_set_write(_ARK *_arkp, int tid, tcb_t *tcbp) blkcnt, tcbp->ttag); rcbp->rc = ENOSPC; rcbp->res = -1; - tcbp->state = ARK_CMD_DONE; + iocbp->state = ARK_CMD_DONE; goto ark_set_write_err; } } @@ -492,9 +474,9 @@ void ark_set_write(_ARK *_arkp, int tid, tcb_t *tcbp) if (bl_rechain(&tcbp->aiol, _arkp->bl, tcbp->nblk, blkcnt, tcbp->aiolN)) { - rcbp->res = -1; - rcbp->rc = ENOMEM; - tcbp->state = ARK_CMD_DONE; + rcbp->res = -1; + rcbp->rc = ENOMEM; + iocbp->state = ARK_CMD_DONE; KV_TRC_FFDC(pAT, "bl_rechain failed, ttag:%d", tcbp->ttag); goto ark_set_write_err; } @@ -505,14 +487,14 @@ void ark_set_write(_ARK *_arkp, int tid, tcb_t *tcbp) scbp->poolstats.io_cnt += blkcnt; - ea_async_io_init(_arkp, ARK_EA_WRITE, (void *)tcbp->oub, + ea_async_io_init(_arkp, iocbp, ARK_EA_WRITE, (void *)tcbp->oub, tcbp->aiol, blkcnt, 0, tcbp->ttag, ARK_SET_FINISH); if (MEM_FASTPATH) { - ea_async_io_schedule(_arkp, tid, iotcbp, iocbp); - ea_async_io_harvest (_arkp, tid, iotcbp, iocbp, rcbp); - if (iotcbp->state == ARK_SET_FINISH) {ark_set_finish(_arkp, tid, tcbp);} + ea_async_io_schedule(_arkp, tid, iocbp); + ea_async_io_harvest (_arkp, tid, iocbp); + if (iocbp->state == ARK_SET_FINISH) {ark_set_finish(_arkp, tid, tcbp);} } ark_set_write_err: @@ -528,6 +510,7 @@ void ark_set_finish(_ARK *_arkp, int tid, tcb_t *tcbp) { scb_t *scbp = &(_arkp->poolthreads[tid]); rcb_t *rcbp = &(_arkp->rcbs[tcbp->rtag]); + iocb_t *iocbp = &(_arkp->iocbs[rcbp->ttag]); uint64_t blkcnt = 0; HASH_SET(_arkp->ht, rcbp->pos, HASH_MAKE(1, tcbp->ttag, tcbp->nblk)); @@ -565,7 +548,7 @@ void ark_set_finish(_ARK *_arkp, int tid, tcb_t *tcbp) scbp->poolstats.kv_cnt += tcbp->new_key; scbp->poolstats.byte_cnt += tcbp->bytes; rcbp->res = rcbp->vlen; - tcbp->state = ARK_CMD_DONE; + iocbp->state = ARK_CMD_DONE; KV_TRC(pAT, "HASHSET tid:%d ttag:%3d pos:%6ld nblk:%5ld bytes:%ld " "byte_cnt:%ld", diff --git a/src/kv/bin/kv_perf.c b/src/kv/bin/kv_perf.c index 93009d3b..28b85e96 100644 --- a/src/kv/bin/kv_perf.c +++ b/src/kv/bin/kv_perf.c @@ -680,7 +680,7 @@ int main(int argc, char **argv) /*-------------------------------------------------------------------------- * process and verify input parms *------------------------------------------------------------------------*/ - while (FF != (c=getopt(argc, argv, "d:q:s:l:v:k:n:rhSM"))) + while (FF != (c=getopt(argc, argv, "d:q:s:l:v:k:rhSMn"))) { switch (c) { diff --git a/src/kv/bl.c b/src/kv/bl.c index ec3884f3..0d14c21d 100644 --- a/src/kv/bl.c +++ b/src/kv/bl.c @@ -22,16 +22,7 @@ /* permissions and limitations under the License. */ /* */ /* IBM_PROLOG_END_TAG */ -#include -#include -#include - -#include -#include -#include -#include - -#include +#include /** ******************************************************************************* @@ -83,9 +74,9 @@ int bl_init_chain_link(BL *bl) rc = (bl->top == bl->n); - KV_TRC_DBG(pAT, "CHN_NEW n:%ld top:%ld count:%ld hd:%ld availN:%ld " + KV_TRC_DBG(pAT, "CHN_NEW bl:%p n:%ld top:%ld count:%ld hd:%ld availN:%ld " "chainN:%ld chain_exception:%ld rc:%d", - bl->n, bl->top, bl->count, bl->head, availN, chainN, + bl, bl->n, bl->top, bl->count, bl->head, availN, chainN, chain_end, rc); exception: pthread_rwlock_unlock(&(bl->iv_rwlock)); @@ -261,7 +252,7 @@ int64_t bl_end(BL *bl, int64_t b) } if (b <= 0 || b >= bl->n) { - KV_TRC_FFDC(pAT, "NULL bl"); + KV_TRC_FFDC(pAT, "bad blk:%ld n:%ld", b,bl->n); return -1; } @@ -299,7 +290,7 @@ void bl_check_take(BL *bl, int64_t n) avail = bl->n - bl->top -1; // if we need blocks and we have uninitialized blocks, init them - if (n > bl->count && avail) + if (n > bl->count && avail > 0) { KV_TRC_DBG(pAT, "CHN_ADD bl:%p n:%ld bl->n:%ld top:%ld count:%ld " "hd:%ld avail:%ld", @@ -435,6 +426,90 @@ int64_t bl_drop(BL *bl, int64_t b) return n; } +/** + ******************************************************************************* + * \brief + * add a single block into a bls + ******************************************************************************/ +int64_t bls_add(BL *bl, int64_t b) +{ + if (!bl || b<=0 || b>=bl->n) + { + KV_TRC_FFDC(pAT, "invalid parm bl:%p b:%ld ", bl, b); + return -1; + } + + pthread_rwlock_rdlock(&(bl->iv_rwlock)); + + if (iv_set(bl->list,b,bl->head) < 0) + { + KV_TRC_FFDC(pAT, "invalid index bl:%p b:%ld hd:%ld", + bl, b, bl->head); + return 0; + } + bl->head = b; + bl->count += 1; + + KV_TRC_DBG(pAT, "BLS_ADD bl:%p b:%ld cnt:%ld hold:%ld top:%ld hd:%ld", + bl, b, bl->count, bl->hold, bl->top, bl->head); + + pthread_rwlock_unlock(&(bl->iv_rwlock)); + return 1; +} + +/** + ******************************************************************************* + * \brief + * remove a block from a bls + ******************************************************************************/ +int64_t bls_rem(BL *bl) +{ + int64_t ret = 0; + int64_t new_hd = 0; + + if (!bl) + { + KV_TRC_FFDC(pAT, "NULL bl"); + return -1; + } + + if (bl->count <= 0) + { + KV_TRC_FFDC(pAT, "No free blocks bl:%p bl->count %ld", + bl, bl->count); + return -1; + } + + pthread_rwlock_rdlock(&(bl->iv_rwlock)); + + KV_TRC_DBG(pAT, "BLS_REM bl:%p count:%ld top:%ld hd:%ld", + bl, bl->count, bl->top, bl->head); + + ret = bl->head; + + if ((new_hd=iv_get(bl->list,ret)) < 0) + { + KV_TRC_FFDC(pAT, "invalid index bl:%p ret:%ld", bl, ret); + ret = -1; + goto exception; + } + if (iv_set(bl->list,ret,0) < 0) + { + KV_TRC_FFDC(pAT, "invalid index bl:%p ret:%ld", bl, ret); + ret = -1; + goto exception; + } + bl->head = new_hd; + bl->count -= 1; + + KV_TRC_DBG(pAT, "BLS_REM bl:%p ret_hd:%ld count:%ld top:%ld " + "hd:%ld", + bl, ret, bl->count, bl->top, bl->head); +exception: + pthread_rwlock_unlock(&(bl->iv_rwlock)); + return ret; +} + /** ******************************************************************************* * \brief diff --git a/src/kv/bl.h b/src/kv/bl.h index be577a21..8b52a7c8 100644 --- a/src/kv/bl.h +++ b/src/kv/bl.h @@ -27,8 +27,13 @@ #include #include -#include "iv.h" +#include + +#ifdef _OS_INTERNAL +#include +#else #include +#endif #define BL_INITN 10000 @@ -71,6 +76,12 @@ void bl_check_take(BL *bl, int64_t n); // put a chain back, return the length of returned chain, negative is error int64_t bl_drop(BL *bl, int64_t b); +// add single block +int64_t bls_add(BL *bl, int64_t b); + +// remove single block +int64_t bls_rem(BL *bl); + // number of items left int64_t bl_left(BL *bl); diff --git a/src/kv/bt.c b/src/kv/bt.c index e485ab81..99be6fc5 100644 --- a/src/kv/bt.c +++ b/src/kv/bt.c @@ -22,18 +22,7 @@ /* permissions and limitations under the License. */ /* */ /* IBM_PROLOG_END_TAG */ -#include -#include -#include -#include -#include - -#include #include -#include -#include -#include -#include /** ******************************************************************************* diff --git a/src/kv/bv.c b/src/kv/bv.c index 974ae0b5..8a32c89e 100644 --- a/src/kv/bv.c +++ b/src/kv/bv.c @@ -22,14 +22,7 @@ /* permissions and limitations under the License. */ /* */ /* IBM_PROLOG_END_TAG */ -#include -#include -#include - -#include "am.h" -#include "ut.h" -#include "bv.h" -#include +#include #define BPW 8 #define WRD uint8_t diff --git a/src/kv/ea.c b/src/kv/ea.c index f84dcc90..27c7ed2e 100644 --- a/src/kv/ea.c +++ b/src/kv/ea.c @@ -22,17 +22,8 @@ /* permissions and limitations under the License. */ /* */ /* IBM_PROLOG_END_TAG */ -#include -#include -#include -#include "bl.h" -#include "ea.h" -#include "am.h" - -#include -#include -#include +#include static int cflsh_blk_lib_init = 0; @@ -80,6 +71,11 @@ EA *ea_new(const char *path, uint64_t bsize, int basyncs, path, bsize, *size, *bcount, errno); goto error_exit; } + memset(ea,0,sizeof(EA)); + pthread_rwlock_init(&(ea->ea_rwlock), NULL); + ea->bsize = bsize; + ea->bcount = *bcount; + ea->size = *size; // We need to check the path parameter to see if // we are going to use memory or a file/capi @@ -102,6 +98,9 @@ EA *ea_new(const char *path, uint64_t bsize, int basyncs, *bcount = ((*size) / bsize); ea->st_memory = store; + if ((ea->zbuf=am_malloc(ea->bsize))) {memset(ea->zbuf,0,ea->bsize);} + else goto error_exit; + ea->unmap = 1; } else { @@ -193,14 +192,18 @@ EA *ea_new(const char *path, uint64_t bsize, int basyncs, strncpy(ea->st_device, path, plen); } - // Fill in the EA struct - pthread_rwlock_init(&(ea->ea_rwlock), NULL); - ea->bsize = bsize; - ea->bcount = *bcount; - ea->size = *size; + chunk_attrs_t attrs; + + bzero(&attrs, sizeof(attrs)); + if ((rc=cblk_get_attrs(ea->st_flash, &attrs, CBLK_GROUP_RAID0)) == 0) + { + if ((ea->zbuf=am_malloc(ea->bsize))) {memset(ea->zbuf,0,ea->bsize);} + else goto error_exit; + ea->unmap = attrs.flags1 & CFLSH_ATTR_UNMAP; + } - KV_TRC(pAT, "path(%s) id:%d bsize %"PRIu64" size %"PRIu64" bcount %"PRIu64"", - path, ea->st_flash, bsize, *size, *bcount); + KV_TRC(pAT, "path(%s) id:%d bsize:%ld size:%ld bcount:%ld unmap:%ld", + path, ea->st_flash, bsize, *size, *bcount, ea->unmap); goto done; error_exit: @@ -477,11 +480,9 @@ int ea_delete(EA *ea) am_free(ea->st_device); } - if ( rc == 0 ) - { - KV_TRC(pAT, "free ea %p", ea); - am_free(ea); - } + KV_TRC(pAT, "free ea %p", ea); + am_free(ea->zbuf); + am_free(ea); return rc; } diff --git a/src/kv/ea.h b/src/kv/ea.h index 991bf20e..1b78f3c8 100644 --- a/src/kv/ea.h +++ b/src/kv/ea.h @@ -26,17 +26,11 @@ #define __EA_H__ #include -#include "ark.h" -#include "bl.h" - -#ifdef _OS_INTERNAL -#include -#else -#include "capiblock.h" -#endif +#include #define ARK_EA_READ 0 #define ARK_EA_WRITE 1 +#define ARK_EA_UNMAP 2 #define st_memory store.memory #define st_flash store.flash.chkid @@ -55,11 +49,14 @@ typedef union _store_id { #define ARK_EA_BLK_ASYNC_CMDS 4096 -typedef struct _ea { +typedef struct _ea +{ pthread_rwlock_t ea_rwlock; uint64_t bsize; uint64_t bcount; uint64_t size; + uint64_t unmap; + char *zbuf; store_id_t store; #define EA_STORE_TYPE_MEMORY 1 diff --git a/src/kv/ea_mod.c b/src/kv/ea_mod.c index f9bb7b94..13bbee78 100644 --- a/src/kv/ea_mod.c +++ b/src/kv/ea_mod.c @@ -29,45 +29,17 @@ * \brief * init/schedule/harvest functions for async IO ******************************************************************************/ -#include -#include -#include - #include -#include -#include -#include -#include - -#ifdef _OS_INTERNAL -#include -#else -#include "capiblock.h" -#endif - -#include -#include -#include - -#ifndef TRUE -#define TRUE 1 -#endif -#ifndef FALSE -#define FALSE 0 -#endif /** ******************************************************************************* * \brief - * return TRUE if all IOs for the iocb are successfully completed, else FALSE ******************************************************************************/ -int ea_async_io_schedule(_ARK *_arkp, - int32_t tid, - tcb_t *iotcbp, - iocb_t *iocbp) +void ea_async_io_schedule(_ARK *_arkp, + int32_t tid, + iocb_t *iocbp) { EA *ea = iocbp->ea; - int32_t rc = TRUE; int32_t arc = 0; void *prc = 0; int64_t i = 0; @@ -75,9 +47,13 @@ int ea_async_io_schedule(_ARK *_arkp, uint8_t *m_addr = NULL; char *ot = NULL; - KV_TRC_IO(pAT, "IO_BEG: tid:%d ttag:%3d start:%4"PRIu64" " - "issT:%3d cmpT:%3d nblks:%3"PRIu64" addr:%p", - tid, iocbp->tag, iocbp->start, + if (iocbp->op == ARK_EA_READ) {ot="RD";} + else if (iocbp->op == ARK_EA_WRITE) {ot="WR";} + else {ot="UM";} + + KV_TRC_IO(pAT, "%s_BEG tid:%d ttag:%3d start:%4ld " + "issT:%3d cmpT:%3d nblks:%3ld addr:%p", + ot, tid, iocbp->tag, iocbp->start, iocbp->issT, iocbp->cmpT, iocbp->nblks, iocbp->addr); ARK_SYNC_EA_READ(iocbp->ea); @@ -85,31 +61,29 @@ int ea_async_io_schedule(_ARK *_arkp, iocbp->io_error = 0; iocbp->stime = getticks(); - if (iocbp->op == ARK_EA_READ) {ot="IO_RD";} - else {ot="IO_WR";} - for (i=iocbp->start; inblks; i++) { if (ea->st_type == EA_STORE_TYPE_MEMORY) { p_addr = ((uint8_t *)(iocbp->addr)) + (i * ea->bsize); m_addr = ea->st_memory + (iocbp->blist[i].blkno * ea->bsize); - iocbp->issT += 1; ++_arkp->issT; + iocbp->issT += 1; + _arkp->issT += 1; - if (ARK_EA_READ == iocbp->op) {prc = memcpy(p_addr,m_addr,ea->bsize);} - else {prc = memcpy(m_addr,p_addr,ea->bsize);} + if (ARK_EA_READ == iocbp->op) {prc = memcpy(p_addr,m_addr,ea->bsize);} + else if (ARK_EA_WRITE == iocbp->op) {prc = memcpy(m_addr,p_addr,ea->bsize);} + else if (ARK_EA_UNMAP == iocbp->op) {prc = memset(m_addr,0,ea->bsize);} if (check_sched_error_injects(iocbp->op)) {prc=NULL;} // if memcpy failed, fail the iocb if (prc == NULL) { - rc=FALSE; - KV_TRC_FFDC(pAT,"IO_ERR: tid:%d ttag:%3d issT:%3d cmpT:%3d " - "nblks:%3ld blkno:%"PRIi64" errno:%d", - tid, iocbp->tag, iocbp->issT, iocbp->cmpT, + KV_TRC_FFDC(pAT,"%s_ERR tid:%d ttag:%3d issT:%3d cmpT:%3d " + "nblks:%3ld blkno:%ld errno:%d", + ot, tid, iocbp->tag, iocbp->issT, iocbp->cmpT, iocbp->nblks, iocbp->blist[i].blkno, errno); - if (!errno) {KV_TRC_FFDC(pAT, "IO: UNSET_ERRNO"); errno=EIO;} + if (!errno) {KV_TRC_FFDC(pAT, "%s_ERR UNSET_ERRNO", ot); errno=EIO;} iocbp->io_error = errno; break; } @@ -117,105 +91,133 @@ int ea_async_io_schedule(_ARK *_arkp, } else // r/w to hw { - p_addr = ((uint8_t *)iocbp->addr) + (i * ea->bsize); - iocbp->issT += 1; ++_arkp->issT; + p_addr = ((uint8_t *)iocbp->addr) + (i * ea->bsize); if (check_sched_error_injects(iocbp->op)) { arc = -1; } - else if ( iocbp->op == ARK_EA_READ ) + else if (iocbp->op == ARK_EA_READ) { - iocbp->rd = 1; arc = cblk_cg_aread(ea->st_flash, p_addr, iocbp->blist[i].blkno,1, &(iocbp->blist[i].a_tag), NULL, iocbp->aflags); } + else if (iocbp->op == ARK_EA_WRITE) + { + arc = cblk_cg_awrite(ea->st_flash, p_addr, + iocbp->blist[i].blkno, 1, + &(iocbp->blist[i].a_tag), + NULL, iocbp->aflags); + } + else if (iocbp->op == ARK_EA_UNMAP) + { + arc = cblk_cg_aunmap(ea->st_flash, iocbp->addr, + iocbp->blist[i].blkno, 1, + &(iocbp->blist[i].a_tag), + NULL, iocbp->aflags); + } else { - arc = cblk_cg_awrite(ea->st_flash, p_addr,iocbp->blist[i].blkno,1, - &(iocbp->blist[i].a_tag), NULL, iocbp->aflags); + KV_TRC_FFDC(pAT,"%s_ERR tid:%d ttag:%3d issT:%3d cmpT:%3d " + "nblks:%3ld blkno:%ld op:%d UNKNOWN_OP", + ot, tid, iocbp->tag, iocbp->issT, iocbp->cmpT, + iocbp->nblks, iocbp->blist[i].blkno, iocbp->op); + iocbp->issT += 1; + iocbp->cmpT += 1; } - if (arc == 0) {rc=FALSE;} // good status + if (arc == 0) + { /* success */ + iocbp->issT += 1; + _arkp->issT += 1; + } else if (arc < 0) { - rc=FALSE; if (errno == EAGAIN) { - iocbp->issT -= 1; --_arkp->issT; + iocbp->eagain=1; // return, and an ark thread will re-schedule this iocb - KV_TRC(pAT,"IO: tid:%d ttag:%3d EAGAIN " + KV_TRC(pAT,"%s_EAGN tid:%d ttag:%3d EAGAIN " "issT:%3d cmpT:%3d nblks:%3ld blkno:%"PRIi64"", - tid, iocbp->tag, iocbp->issT, iocbp->cmpT, + ot, tid, iocbp->tag, iocbp->issT, iocbp->cmpT, iocbp->nblks, iocbp->blist[i].blkno); break; } // Something bad went wrong, fail the iocb - KV_TRC_FFDC(pAT,"IO_ERR: tid:%d ttag:%3d issT:%3d cmpT:%3d " + KV_TRC_FFDC(pAT,"%s_ERR tid:%d ttag:%3d issT:%3d cmpT:%3d " "nblks:%3ld blkno:%"PRIi64" errno:%d", - tid, iocbp->tag, iocbp->issT, iocbp->cmpT, + ot, tid, iocbp->tag, iocbp->issT, iocbp->cmpT, iocbp->nblks, iocbp->blist[i].blkno, errno); if (!errno) {KV_TRC_FFDC(pAT, "IO: UNSET_ERRNO"); errno=EIO;} - iocbp->cmpT += 1; iocbp->io_error = errno; break; } else if (arc > 0) { - KV_TRC(pAT,"IO_CMP: tid:%d ttag:%3d a_tag:%4d IMMEDIATE " + KV_TRC(pAT,"%s_CMP tid:%d ttag:%3d a_tag:%4d IMMEDIATE " "issT:%3d cmpT:%3d nblks:%3ld blkno:%"PRIi64"", - tid, iocbp->tag, iocbp->blist[i].a_tag.tag, + ot, tid, iocbp->tag, iocbp->blist[i].a_tag.tag, iocbp->issT, iocbp->cmpT, iocbp->nblks, iocbp->blist[i].blkno); - ++iocbp->issT; - ++iocbp->cmpT; + _arkp->issT += 1; + iocbp->issT += 1; + iocbp->cmpT += 1; iocbp->blist[i].a_tag.tag = -1; // mark as harvested } } - KV_TRC_IO(pAT, "%s: tid:%d ttag:%3d a_tag:%4d issT:%3d cmpT:%3d " - "nblks:%3ld blkno:%5"PRIi64"", ot,tid, iocbp->tag, + KV_TRC_IO(pAT, "%s_ISS tid:%d ttag:%3d a_tag:%4d issT:%3d cmpT:%3d " + "nblks:%3ld blkno:%5"PRIi64"", ot, tid, iocbp->tag, iocbp->blist[i].a_tag.tag, iocbp->issT, iocbp->cmpT, iocbp->nblks, iocbp->blist[i].blkno); } /* if a cmd schedule failed OR cmds are waiting for harvest, call harvest */ - if ((iocbp->io_error) || - (iocbp->issT && (iocbp->issT != iocbp->cmpT))) + if (iocbp->io_error || (iocbp->issT && (iocbp->issT != iocbp->cmpT))) { - iotcbp->state = ARK_IO_HARVEST; - iocbp->start = i; + iocbp->state = ARK_IO_HARVEST; + iocbp->start = i; } ARK_SYNC_EA_UNLOCK(iocbp->ea); - return rc; + return; } /** ******************************************************************************* * \brief - * return TRUE if the IOs for the iocb are successfully completed, else FALSE ******************************************************************************/ -int ea_async_io_harvest(_ARK *_arkp, - int32_t tid, - tcb_t *iotcbp, - iocb_t *iocbp, - rcb_t *iorcbp) +void ea_async_io_harvest(_ARK *_arkp, + int32_t tid, + iocb_t *iocbp) { EA *ea = iocbp->ea; int32_t i = 0; int32_t arc = 0; int32_t hrvst = (iocbp->aflags & CBLK_ARESULT_NO_HARVEST)==0; - int32_t rc = FALSE; uint64_t status = 0; + char *ot = NULL; + + if (iocbp->op == ARK_EA_READ) {ot="RD";} + else if (iocbp->op == ARK_EA_WRITE) {ot="WR";} + else {ot="UM";} for (i=0; inblks; i++) { if (EA_STORE_TYPE_MEMORY == ea->st_type) { - // the IO has already been done in the schedule function, - // so mark it completed - arc = 1; + /* add artificial delay for unmap ops */ + if (iocbp->op == ARK_EA_UNMAP && + UDELTA(iocbp->stime,_arkp->ns_per_tick) < 1000) + { + arc=0; + } + else + { + // the IO has already been done in the schedule function, + // so mark it completed + arc = 1; + } } else { @@ -230,9 +232,9 @@ int ea_async_io_harvest(_ARK *_arkp, if (arc == 0 && iocbp->issT > iocbp->cmpT) { - KV_TRC_DBG(pAT,"IO: tid:%d ttag:%3d a_tag:%4d issT:%3d cmpT:%3d " + KV_TRC_DBG(pAT,"%s_WAIT tid:%d ttag:%3d a_tag:%4d issT:%3d cmpT:%3d " "nblks:%3ld blkno:%5ld hrvst:%d WAIT_NOT_CMP", - tid, iocbp->tag, iocbp->blist[i].a_tag.tag, + ot, tid, iocbp->tag, iocbp->blist[i].a_tag.tag, iocbp->issT, iocbp->cmpT, iocbp->nblks, iocbp->blist[i].blkno, hrvst); ++iocbp->hmissN; @@ -245,9 +247,9 @@ int ea_async_io_harvest(_ARK *_arkp, if (arc < 0) { - KV_TRC_FFDC(pAT, "IO_ERR: tid:%d ttag:%3d a_tag:%4d issT:%3d " + KV_TRC_FFDC(pAT, "%s_ERR tid:%d ttag:%3d a_tag:%4d issT:%3d " "cmpT:%3d nblks:%3ld lat:%d errno=%d", - tid, iocbp->tag, iocbp->blist[i].a_tag.tag, + ot, tid, iocbp->tag, iocbp->blist[i].a_tag.tag, iocbp->issT, iocbp->cmpT, iocbp->nblks, iocbp->lat, errno); if (!errno) {KV_TRC_FFDC(pAT, "UNSET_ERRNO"); errno=EIO;} @@ -256,11 +258,11 @@ int ea_async_io_harvest(_ARK *_arkp, else { iocbp->hmissN=0; - KV_TRC_IO(pAT,"IO_CMP: tid:%d ttag:%3d a_tag:%4d issT:%3d " - "cmpT:%3d nblks:%3ld blkno:%5ld rd:%d lat:%d", - tid, iocbp->tag, iocbp->blist[i].a_tag.tag, + KV_TRC_IO(pAT,"%s_CMP tid:%d ttag:%3d a_tag:%4d issT:%3d " + "cmpT:%3d nblks:%3ld blkno:%5ld lat:%d", + ot, tid, iocbp->tag, iocbp->blist[i].a_tag.tag, iocbp->issT, iocbp->cmpT, iocbp->nblks, - iocbp->blist[i].blkno, iocbp->rd, iocbp->lat); + iocbp->blist[i].blkno, iocbp->lat); } iocbp->blist[i].a_tag.tag = -1; // mark as harvested @@ -272,51 +274,48 @@ int ea_async_io_harvest(_ARK *_arkp, // completed for this iocb, then fail this iocb if (iocbp->issT == iocbp->cmpT) { - iorcbp->res = -1; - iorcbp->rc = iocbp->io_error; - iotcbp->state = ARK_CMD_DONE; - KV_TRC_FFDC(pAT, "IO: tid:%d ttag:%3d ERROR_DONE rc:%d", - tid, iocbp->tag, iorcbp->rc); + iocbp->state = ARK_CMD_DONE; + KV_TRC_FFDC(pAT, "%s_ERRD tid:%d ttag:%3d ERROR_DONE rc:%d", + ot, tid, iocbp->tag, iocbp->io_error); } else { // IOs outstanding, harvest the remaining IOs for this iocb - KV_TRC_FFDC(pAT,"IO: tid:%d ttag:%3d ERROR_RE_HARVEST " + KV_TRC_FFDC(pAT,"%s_ERRH tid:%d ttag:%3d ERROR_RE_HARVEST " "issT:%3d cmpT:%3d nblks:%3ld", - tid, iocbp->tag, iocbp->issT, iocbp->cmpT, + ot, tid, iocbp->tag, iocbp->issT, iocbp->cmpT, iocbp->nblks); } } // if all IO has completed successfully for this iocb, done else if (iocbp->cmpT == iocbp->nblks) { - rc=TRUE; - iotcbp->state = iocbp->io_done; - KV_TRC(pAT, "IO_END: tid:%d ttag:%3d SUCCESS cmpT:%d", - tid, iocbp->tag, iocbp->cmpT); + iocbp->state = iocbp->io_done; + KV_TRC(pAT, "%s_END tid:%d ttag:%3d SUCCESS cmpT:%d", + ot, tid, iocbp->tag, iocbp->cmpT); } // if more blks need a harvest else if (iocbp->cmpT < iocbp->issT) { - iotcbp->state = ARK_IO_HARVEST; - KV_TRC_IO(pAT,"IO: tid:%d ttag:%3d hrvst:%4d " + iocbp->state = ARK_IO_HARVEST; + KV_TRC_IO(pAT,"%s_HRV tid:%d ttag:%3d hrvst:%4d " "issT:%3d cmpT:%3d nblks:%3ld RE_HARVEST_PART", - tid, iocbp->tag, hrvst, iocbp->issT, iocbp->cmpT, iocbp->nblks); + ot, tid, iocbp->tag, hrvst, iocbp->issT, iocbp->cmpT, iocbp->nblks); } // if more blks need an IO, schedule else if (iocbp->issT < iocbp->nblks) { - iotcbp->state = ARK_IO_SCHEDULE; - KV_TRC_IO(pAT,"IO: tid:%d ttag:%3d hrvst:%4d " + iocbp->state = ARK_IO_SCHEDULE; + KV_TRC_IO(pAT,"%s_SCH tid:%d ttag:%3d hrvst:%4d " "issT:%3d cmpT:%3d, nblks:%3"PRIi64" RE_SCHEDULE", - tid, iocbp->tag, hrvst, iocbp->issT, iocbp->cmpT, iocbp->nblks); + ot, tid, iocbp->tag, hrvst, iocbp->issT, iocbp->cmpT, iocbp->nblks); } else { // all IOs have been issued but not all are completed, do harvest - KV_TRC_IO(pAT,"IO: tid:%d ttag:%3d hrvst:%4d " + KV_TRC_IO(pAT,"%s_HRV tid:%d ttag:%3d hrvst:%4d " "issT:%3d cmpT:%3d nblks:%3ld RE_HARVEST", - tid, iocbp->tag, hrvst, iocbp->issT, iocbp->cmpT, iocbp->nblks); + ot, tid, iocbp->tag, hrvst, iocbp->issT, iocbp->cmpT, iocbp->nblks); } - return rc; + return; } diff --git a/src/kv/hash.c b/src/kv/hash.c index d8896712..2257e3f5 100644 --- a/src/kv/hash.c +++ b/src/kv/hash.c @@ -23,10 +23,7 @@ /* */ /* IBM_PROLOG_END_TAG */ -#include -#include "am.h" -#include "hash.h" -#include +#include hash_t *hash_new(uint64_t n) { hash_t *hash = am_malloc(sizeof(hash_t) + n * sizeof(uint64_t)); diff --git a/src/kv/ht.c b/src/kv/ht.c index 35ee5613..4f4aaba2 100644 --- a/src/kv/ht.c +++ b/src/kv/ht.c @@ -23,18 +23,7 @@ /* */ /* IBM_PROLOG_END_TAG */ -#include -#include -#include - -#include "am.h" -#include "bv.h" -#include "iv.h" - -#include "ht.h" - -#include -#include +#include uint64_t ht_hash(uint8_t *buf, uint64_t n) { uint64_t sum = 0; diff --git a/src/kv/iv.c b/src/kv/iv.c index e5930cd9..a9767e5b 100644 --- a/src/kv/iv.c +++ b/src/kv/iv.c @@ -22,16 +22,7 @@ /* permissions and limitations under the License. */ /* */ /* IBM_PROLOG_END_TAG */ -#include -#include -#include -#include -#include "am.h" - -#include "ut.h" -#include "iv.h" -#include -#include +#include #define IVINLINE // inline #define IVSAFE // if (i<0 & i>=bv->n) exit(987); diff --git a/src/kv/kv.c b/src/kv/kv.c deleted file mode 100644 index 49a8c571..00000000 --- a/src/kv/kv.c +++ /dev/null @@ -1,25 +0,0 @@ -/* IBM_PROLOG_BEGIN_TAG */ -/* This is an automatically generated prolog. */ -/* */ -/* $Source: src/kv/kv.c $ */ -/* */ -/* IBM Data Engine for NoSQL - Power Systems Edition User Library Project */ -/* */ -/* Contributors Listed Below - COPYRIGHT 2014,2015 */ -/* [+] International Business Machines Corp. */ -/* */ -/* */ -/* Licensed under the Apache License, Version 2.0 (the "License"); */ -/* you may not use this file except in compliance with the License. */ -/* You may obtain a copy of the License at */ -/* */ -/* http://www.apache.org/licenses/LICENSE-2.0 */ -/* */ -/* Unless required by applicable law or agreed to in writing, software */ -/* distributed under the License is distributed on an "AS IS" BASIS, */ -/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or */ -/* implied. See the License for the specific language governing */ -/* permissions and limitations under the License. */ -/* */ -/* IBM_PROLOG_END_TAG */ - diff --git a/src/kv/makefile b/src/kv/makefile index 95bbf42a..0e1651f4 100644 --- a/src/kv/makefile +++ b/src/kv/makefile @@ -28,7 +28,7 @@ UNAME=$(shell uname) ROOTPATH = ../.. SUBDIRS = bin.d test.d -OBJS = ut.o cl.o ea.o ll.o bv.o iv.o si.o vi.o bl.o bt.o arkdb.o am.o ari.o \ +OBJS = ut.o cl.o ea.o ll.o bv.o iv.o si.o vi.o bl.o bt.o arkdb.o am.o \ arp.o arp_set.o arp_get.o arp_del.o arp_exist.o tag.o ea_mod.o queue.o \ hash.o tg.o ht.o kv_inject.o diff --git a/src/kv/queue.c b/src/kv/queue.c index 7c7be411..4909fc3f 100644 --- a/src/kv/queue.c +++ b/src/kv/queue.c @@ -24,9 +24,8 @@ /* IBM_PROLOG_END_TAG */ #include - -#include "am.h" -#include "queue.h" +#include +#include #include queue_t *queue_new(uint32_t n) { diff --git a/src/kv/sq.c b/src/kv/sq.c index 4d9768ae..98c5e0df 100644 --- a/src/kv/sq.c +++ b/src/kv/sq.c @@ -22,17 +22,7 @@ /* permissions and limitations under the License. */ /* */ /* IBM_PROLOG_END_TAG */ -#include -#include -#include -#include - -#include "am.h" - -#include "sq.h" - -#include -#include +#include int sq_sizeof(int n, int m) {return sizeof(SQ) + n*m;} int sq_count(SQP sq) {return sq->cnt;} diff --git a/src/kv/tag.c b/src/kv/tag.c index 369aff17..b99b6008 100644 --- a/src/kv/tag.c +++ b/src/kv/tag.c @@ -23,11 +23,7 @@ /* */ /* IBM_PROLOG_END_TAG */ -#include -#include "tag.h" -#include "am.h" -#include -#include +#include tags_t* tag_new(uint32_t n) { diff --git a/src/kv/test/fvt_kv_tst_simple.C b/src/kv/test/fvt_kv_tst_simple.C index 6d726439..4ebe64db 100644 --- a/src/kv/test/fvt_kv_tst_simple.C +++ b/src/kv/test/fvt_kv_tst_simple.C @@ -45,6 +45,7 @@ extern "C" } uint64_t seed = 0xFF00000000000000; +extern KV_Trace_t *pAT; /** ******************************************************************************* @@ -93,6 +94,8 @@ TEST(FVT_KV_GOOD_PATH, SIMPLE_iv) uint32_t i = 0; IV *iv = NULL; + KV_TRC_OPEN(pAT, "arkdb"); + ASSERT_TRUE(iv_set(iv, 0, 0) < 0); ASSERT_TRUE(iv_get(iv, 0) < 0); @@ -114,6 +117,8 @@ TEST(FVT_KV_GOOD_PATH, SIMPLE_iv) for (i=n-1; i>=0 && i 0); + ASSERT_EQ(bls_add(blu,blk),1); + } +} + +/** + ******************************************************************************* + * \brief + * test BL functions + ******************************************************************************/ +TEST(FVT_KV_GOOD_PATH, SIMPLE_unmap_bl) +{ + uint64_t n = 10; + uint64_t w = ARK_VERBOSE_BLKBITS_DEF; + BL *bl = NULL; + BL *blu = NULL; + int64_t a = 0; + int64_t b = 0; + int64_t c = 0; + int64_t d = 0; + uint32_t alen = 3; + uint32_t blen = 1; + uint32_t clen = 2; + uint32_t dlen = 7; + uint32_t i = 0; + + KV_TRC_OPEN(pAT, "arkdb"); + + bl = bl_new(n, w); + blu = bl_new(n, w); + ASSERT_TRUE(NULL != bl); + ASSERT_TRUE(NULL != blu); + + /* init */ + ASSERT_EQ(bl_init_chain_link(bl), 0); + ASSERT_EQ(bl_left(bl), 8); + ASSERT_EQ(bl_left(blu), 0); + + /* take chains */ + ASSERT_EQ((a=bl_take(bl,alen)), 1); ASSERT_EQ(bl_left(bl), 5); + ASSERT_EQ((b=bl_take(bl,blen)), 4); ASSERT_EQ(bl_left(bl), 4); + ASSERT_EQ((c=bl_take(bl,clen)), 5); ASSERT_EQ(bl_left(bl), 2); + + /* update bl and blu with chains for unmap */ + rdy_unmap(bl, blu, b); ASSERT_EQ(bl_left(blu), 1); ASSERT_EQ(bl_left(bl), 2); + rdy_unmap(bl, blu, c); ASSERT_EQ(bl_left(blu), 3); ASSERT_EQ(bl_left(bl), 2); + rdy_unmap(bl, blu, a); ASSERT_EQ(bl_left(blu), 6); ASSERT_EQ(bl_left(bl), 2); + + uint32_t left=bl_left(blu); + + /* mark unmaps complete */ + for (i=0; i 0); + ASSERT_EQ(bl_drop(bl,a),1); + } + + /* verify */ + ASSERT_EQ(bl_left(bl), 8); + ASSERT_EQ(bl_left(blu), 0); + + /* do it again, with a resize */ + + /* take chains */ + ASSERT_EQ((b=bl_take(bl,blen)), 4); ASSERT_EQ(bl_left(bl), 7); + ASSERT_EQ((a=bl_take(bl,alen)), 5); ASSERT_EQ(bl_left(bl), 4); + ASSERT_EQ((c=bl_take(bl,clen)), 2); ASSERT_EQ(bl_left(bl), 2); + + ASSERT_EQ(bl_resize(bl, bl->n*2, bl->w), bl); + ASSERT_EQ(bl_resize(blu, blu->n*2, blu->w), blu); + + ASSERT_EQ(bl_left(bl), 2); + ASSERT_EQ(bl_left(blu), 0); + + ASSERT_EQ((d=bl_take(bl,dlen)), 7); ASSERT_EQ(bl_left(bl), 5); + + /* update bl and blu with chains for unmap */ + rdy_unmap(bl, blu, c); ASSERT_EQ(bl_left(blu), 2); ASSERT_EQ(bl_left(bl), 5); + rdy_unmap(bl, blu, d); ASSERT_EQ(bl_left(blu), 9); ASSERT_EQ(bl_left(bl), 5); + rdy_unmap(bl, blu, b); ASSERT_EQ(bl_left(blu), 10); ASSERT_EQ(bl_left(bl), 5); + rdy_unmap(bl, blu, a); ASSERT_EQ(bl_left(blu), 13); ASSERT_EQ(bl_left(bl), 5); + + left=bl_left(blu); + + /* mark unmaps complete */ + for (i=0; i 0); + ASSERT_EQ(bl_drop(bl,a),1); + } + + /* verify */ + ASSERT_EQ(bl_left(bl), 18); + ASSERT_EQ(bl_left(blu), 0); + + /* cleanup */ + bl_delete(bl); + bl_delete(blu); } /** @@ -188,6 +329,8 @@ TEST(FVT_KV_GOOD_PATH, SIMPLE_bt) uint64_t oldvdf; uint64_t oldvlen; + KV_TRC_OPEN(pAT, "arkdb"); + bt1 = bt_new(128, 8, sizeof(uint64_t), &bt1_orig); ASSERT_TRUE(NULL != bt1); bt2 = bt_new(128, 8, sizeof(uint64_t), &bt2_orig); @@ -323,6 +466,8 @@ TEST(FVT_KV_GOOD_PATH, SIMPLE_bt) bt_delete(bt1_orig); bt_delete(bt2_orig); + + KV_TRC_CLOSE(pAT); } /** diff --git a/src/kv/vi.c b/src/kv/vi.c index 74995b54..72e64916 100644 --- a/src/kv/vi.c +++ b/src/kv/vi.c @@ -23,7 +23,7 @@ /* */ /* IBM_PROLOG_END_TAG */ -#include "vi.h" +#include uint64_t vi_enc64(uint64_t n, uint8_t *buf) { uint64_t len = 0;