Skip to content

Commit

Permalink
Fixed python to sync up with unvme.h and minor changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Deyoung Hong committed Oct 20, 2017
1 parent a793c4b commit 11a99a5
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 39 deletions.
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#

include ./Makefile.def

INSTALLDIR ?= /usr/local
SUBDIRS := src test ioengine doc

Expand Down
2 changes: 1 addition & 1 deletion Makefile.def
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ CPPFLAGS+=-D_GNU_SOURCE

# To use identity map for DMA address # for faster submission time
# (but may cause DMA overlapping for applications with high memory usage)
#CPPFLAGS+=-DUNVME_IDENTITY_MAP_DMA
CPPFLAGS+=-DUNVME_IDENTITY_MAP_DMA

# To build the ioengine modules, specify fio directory where header files are
#FIODIR:=/opt/fio
Expand Down
8 changes: 4 additions & 4 deletions src/unvme.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ typedef struct _unvme_ns {
u16 pageshift; ///< page size shift value
u16 bpshift; ///< block to page shift
u16 nbpp; ///< number of blocks per page
u16 qcount; ///< number of I/O queues
u16 maxqcount; ///< max number of queues supported
u32 qsize; ///< I/O queue size
u32 maxqsize; ///< max queue size supported
u16 maxbpio; ///< max number of blocks per I/O
u16 maxppio; ///< max number of pages per I/O
u16 maxiopq; ///< max number of I/O submissions per queue
u16 nscount; ///< number of namespaces available
u32 qcount; ///< number of I/O queues
u32 maxqcount; ///< max number of queues supported
u32 qsize; ///< I/O queue size
u32 maxqsize; ///< max queue size supported
void* ses; ///< associated session
} unvme_ns_t;

Expand Down
12 changes: 6 additions & 6 deletions src/unvme_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ static int unvme_check_completion(unvme_queue_t* q, int timeout, u32* cqe_cs)
do {
cid = nvme_check_completion(q->nvmeq, &err, cqe_cs);
if (cid >= 0 || timeout == 0) break;
if (endtsc == 0) endtsc = rdtsc() + timeout * q->nvmeq->dev->rdtsec;
else sched_yield();
if (endtsc) sched_yield();
else endtsc = rdtsc() + timeout * q->nvmeq->dev->rdtsec;
} while (rdtsc() < endtsc);
if (cid < 0) return cid;

Expand Down Expand Up @@ -197,7 +197,7 @@ static u16 unvme_get_cid(unvme_desc_t* desc)
* @param bufsz buffer size
* @return DMA address or -1L if error.
*/
static inline u64 unvme_map_dma(const unvme_ns_t* ns, void* buf, u64 bufsz)
static u64 unvme_map_dma(const unvme_ns_t* ns, void* buf, u64 bufsz)
{
unvme_device_t* dev = ((unvme_session_t*)ns->ses)->dev;
#ifdef UNVME_IDENTITY_MAP_DMA
Expand Down Expand Up @@ -238,10 +238,10 @@ static inline u64 unvme_map_dma(const unvme_ns_t* ns, void* buf, u64 bufsz)
* @param bufsz buffer size
* @param prp1 returned prp1 value
* @param prp2 returned prp2 value
* @return DMA address or -1 if error.
* @return 0 if ok else -1 if buffer address error.
*/
static inline int unvme_map_prps(const unvme_ns_t* ns, unvme_queue_t* q, int cid,
void* buf, u64 bufsz, u64* prp1, u64* prp2)
static int unvme_map_prps(const unvme_ns_t* ns, unvme_queue_t* q, int cid,
void* buf, u64 bufsz, u64* prp1, u64* prp2)
{
u64 addr = unvme_map_dma(ns, buf, bufsz);
if (addr == -1L) return -1;
Expand Down
2 changes: 1 addition & 1 deletion src/unvme_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ typedef struct _unvme_desc {
u32 opc; ///< op code
u32 id; ///< descriptor id
void* sentinel; ///< sentinel check
struct _unvme_queue* q; ///< IO queue context owner
struct _unvme_queue* q; ///< queue context owner
struct _unvme_desc* prev; ///< previous descriptor node
struct _unvme_desc* next; ///< next descriptor node
int error; ///< error status
Expand Down
24 changes: 12 additions & 12 deletions src/unvme_nvme.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ static int nvme_ctlr_enable(nvme_device_t* dev, nvme_controller_config_t cc)
static int nvme_submit_cmd(nvme_queue_t* q)
{
int tail = q->sq_tail;
HEX_DUMP(&q->sq[tail], sizeof(nvme_sq_entry_t));
//HEX_DUMP(&q->sq[tail], sizeof(nvme_sq_entry_t));
if (++tail == q->size) tail = 0;
#if 0
// Some SSD does not advance sq_head properly (e.g. Intel DC D3600)
Expand Down Expand Up @@ -174,7 +174,7 @@ int nvme_check_completion(nvme_queue_t* q, int* stat, u32* cqe_cs)
#endif

if (*stat == 0) {
DEBUG_FN("q=%d h=%d cid=%#x (C)", q->id, q->sq_head, cqe->cid);
DEBUG_FN("q=%d h=%d cid=%#x (C)", q->id, q->cq_head, cqe->cid);
} else {
ERROR("q=%d cid=%#x stat=%#x (dnr=%d m=%d sct=%d sc=%#x) (C)",
q->id, cqe->cid, *stat, cqe->dnr, cqe->m, cqe->sct, cqe->sc);
Expand Down Expand Up @@ -236,7 +236,7 @@ int nvme_acmd_identify(nvme_device_t* dev, int nsid, u64 prp1, u64 prp2)
cmd->common.prp2 = prp2;
cmd->cns = nsid == 0 ? 1 : 0;

DEBUG_FN("cid=%#x nsid=%d", cid, nsid);
DEBUG_FN("t=%d h=%d cid=%#x nsid=%d", adminq->sq_tail, adminq->sq_head, cid, nsid);
int err = nvme_submit_cmd(adminq);
if (!err) err = nvme_wait_completion(adminq, cid, 30);
return err;
Expand Down Expand Up @@ -269,7 +269,7 @@ int nvme_acmd_get_log_page(nvme_device_t* dev, int nsid,
cmd->lid = lid;
cmd->numd = numd;

DEBUG_FN("cid=%#x lid=%d", cid, lid);
DEBUG_FN("t=%d h=%d cid=%#x lid=%d", adminq->sq_tail, adminq->sq_head, cid, lid);
int err = nvme_submit_cmd(adminq);
if (!err) err = nvme_wait_completion(adminq, cid, 30);
return err;
Expand Down Expand Up @@ -302,7 +302,7 @@ int nvme_acmd_get_features(nvme_device_t* dev, int nsid,
cmd->fid = fid;
*res = -1;

DEBUG_FN("cid=%#x fid=%d", cid, fid);
DEBUG_FN("t=%d h=%d cid=%#x fid=%d", adminq->sq_tail, adminq->sq_head, cid, fid);
int err = nvme_submit_cmd(adminq);
if (!err) err = nvme_wait_completion(adminq, cid, 30);
if (!err) *res = adminq->cq[cid].cs;
Expand Down Expand Up @@ -337,7 +337,7 @@ int nvme_acmd_set_features(nvme_device_t* dev, int nsid,
cmd->val = *res;
*res = -1;

DEBUG_FN("cid=%#x fid=%d", cid, fid);
DEBUG_FN("t=%d h=%d cid=%#x fid=%d", adminq->sq_tail, adminq->sq_head, cid, fid);
int err = nvme_submit_cmd(adminq);
if (!err) err = nvme_wait_completion(adminq, cid, 30);
if (!err) *res = adminq->cq[cid].cs;
Expand Down Expand Up @@ -365,7 +365,7 @@ int nvme_acmd_create_cq(nvme_queue_t* ioq, u64 prp)
cmd->qid = ioq->id;
cmd->qsize = ioq->size - 1;

DEBUG_FN("q=%d cid=%#x qs=%d", ioq->id, cid, ioq->size);
DEBUG_FN("t=%d h=%d cid=%#x cq=%d qs=%d", adminq->sq_tail, adminq->sq_head, cid, ioq->id, ioq->size);
int err = nvme_submit_cmd(adminq);
if (!err) err = nvme_wait_completion(adminq, cid, 30);
return err;
Expand Down Expand Up @@ -394,7 +394,7 @@ int nvme_acmd_create_sq(nvme_queue_t* ioq, u64 prp)
cmd->cqid = ioq->id;
cmd->qsize = ioq->size - 1;

DEBUG_FN("q=%d cid=%#x qs=%d", ioq->id, cid, ioq->size);
DEBUG_FN("t=%d h=%d cid=%#x sq=%d qs=%d", adminq->sq_tail, adminq->sq_head, cid, ioq->id, ioq->size);
int err = nvme_submit_cmd(adminq);
if (!err) err = nvme_wait_completion(adminq, cid, 30);
return err;
Expand All @@ -418,8 +418,8 @@ static inline int nvme_acmd_delete_ioq(nvme_queue_t* ioq, int opc)
cmd->common.cid = cid;
cmd->qid = ioq->id;

DEBUG_FN("%cq=%d cid=%#x",
opc == NVME_ACMD_DELETE_CQ ? 'c' : 's', ioq->id, cid);
DEBUG_FN("t=%d h=%d cid=%#x %cq=%d", adminq->sq_tail, adminq->sq_head, cid,
opc == NVME_ACMD_DELETE_CQ ? 'c' : 's', ioq->id);
int err = nvme_submit_cmd(adminq);
if (!err) err = nvme_wait_completion(adminq, cid, 30);
return err;
Expand Down Expand Up @@ -500,8 +500,8 @@ int nvme_cmd_rw(nvme_queue_t* ioq, int opc, u16 cid, int nsid,
cmd->common.prp2 = prp2;
cmd->slba = slba;
cmd->nlb = nlb - 1;
DEBUG_FN("q=%d t=%d h=%d cid=%#x nsid=%d lba=%#lx nb=%#x (%c)",
ioq->id, ioq->sq_tail, ioq->sq_head, cid, nsid, slba, nlb,
DEBUG_FN("q=%d t=%d h=%d cid=%#x nsid=%d lba=%#lx nb=%#x prp=%#lx.%#lx (%c)",
ioq->id, ioq->sq_tail, ioq->sq_head, cid, nsid, slba, nlb, prp1, prp2,
opc == NVME_CMD_READ? 'R' : 'W');
return nvme_submit_cmd(ioq);
}
Expand Down
10 changes: 5 additions & 5 deletions test/python/unvme.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ class unvme_ns(ctypes.Structure):
("maxbpio", c_uint16), # max number of blocks per I/O
("maxppio", c_uint16), # max number of pages per I/O
("maxiopq", c_uint16), # max number of I/O submissions per queue
("qcount", c_uint16), # number of I/O queues
("maxqcount", c_uint16), # max number of queues supported
("qsize", c_uint16), # I/O queue size
("maxqsize", c_uint16), # max queue size supported
("nscount", c_uint16), # number of namespaces available
("ses", POINTER(c_uint32)) # associated session
("qcount", c_uint32), # number of I/O queues
("maxqcount", c_uint32), # max number of queues supported
("qsize", c_uint32), # I/O queue size
("maxqsize", c_uint32), # max queue size supported
("ses", POINTER(c_uint64)) # associated session
]

# I/O descriptor structure
Expand Down
12 changes: 6 additions & 6 deletions test/python/unvme_wr_ex.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ def verifyBuffer(self, buf, lba, nlb):
pat = (lba << 24) | b
for w in range(self.wpb):
if buf[i] != pat:
self.error("ERROR: data miscompare at lba #%lx" % lba)
self.error("ERROR: data miscompare at lba %#lx" % lba)
i = i + 1
lba = lba + 1

def pickqbc(self, seed):
random.seed(self.seed + seed)
nlb = random.randint(1, self.maxnlb)
lba = random.randrange(0, self.ns.blockcount - nlb - 1)
q = (lba + nlb) % self.ns.maxqcount
q = (lba + nlb) % self.ns.qcount
return q, lba, nlb

def syncTest(self):
Expand Down Expand Up @@ -107,17 +107,17 @@ def asyncTest(self):

# Main program.
parser = argparse.ArgumentParser()
parser.add_argument('--ioc', help="number of IOs per test", default=8)
parser.add_argument('--nlb', help="max number of blocks per IO", default=65536)
parser.add_argument('--ioc', help="number of IOs per test", type=int, default=8)
parser.add_argument('--nlb', help="max number of blocks per IO", type=int, default=65536)
parser.add_argument('pci', help="PCI device name (as 0a:00.0[/1] format)")
if len(sys.argv) == 1:
parser.print_help()
sys.exit(1)
opts = parser.parse_args()

print("RANDOM WRITE-READ EXAMPLE TEST BEGIN")
print("PYTHON RANDOM WRITE-READ EXAMPLE TEST BEGIN")
ex = WRTest(opts.pci, opts.ioc, opts.nlb)
ex.syncTest()
ex.asyncTest()
print("RANDOM WRITE-READ EXAMPLE TEST COMPLETE")
print("PYTHON RANDOM WRITE-READ EXAMPLE TEST COMPLETE")

4 changes: 4 additions & 0 deletions test/unvme-test
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@ excmd() {
for d in $*; do
excmd unvme-setup bind $d
excmd unvme/unvme_info $d
excmd unvme/unvme_get_features $d
excmd unvme/unvme_sim_test $d
excmd unvme/unvme_api_test $d
excmd unvme/unvme_mts_test $d
excmd unvme/unvme_lat_test $d

echo -e "\n\$ python ${PDIR}/python/unvme_wr_ex.py $d ($(date))"
python ${PDIR}/python/unvme_wr_ex.py $d
done

if [ $# -gt 1 ]; then
Expand Down
8 changes: 6 additions & 2 deletions test/unvme/unvme_api_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,12 @@ int main(int argc, char** argv)
p = buf[i];
VERBOSE(" verify.%-2d %#8x %p %#lx\n", i, nlb, p, slba);
for (w = 0; w < size; w++) {
if (p[w] != ((w << 32) + i))
errx(1, "mismatch lba=%#lx word=%#lx", slba, w);
if (p[w] != ((w << 32) + i)) {
w *= sizeof(w);
slba += w / ns->blocksize;
w %= ns->blocksize;
errx(1, "miscompare at lba %#lx offset %#lx", slba, w);
}
}
slba += nlb;
}
Expand Down

0 comments on commit 11a99a5

Please sign in to comment.