1 #!/usr/bin/env python2.7
2 import sys, os, signal, time
3 from xseg import xseg_api as xseg
7 xconf = xseg.xseg_config()
8 cb_null_ptrtype = xseg.CFUNCTYPE(None, xseg.POINTER(xseg.xseg), xseg.uint32_t)
21 xseg.xseg_prepare_wait(ctx, mportno)
22 if nr_submitted < nr_requests and nr_flying < concurrent_reqs:
23 xreqp = xseg.xseg_get_request(ctx, mportno)
26 xseg.xseg_cancel_wait(ctx, mportno)
27 if xseg.xseg_prep_request(xreq, 2, 4096) < 0:
28 xseg.xseg_put_request(ctx, xreq.portno, xreq)
36 srl = xseg.xseg_submit(ctx, dportno, xreq)
37 xseg.xseg_signal(ctx, dportno)
38 except Exception as e:
41 xreqp = xseg.xseg_receive(ctx, mportno)
44 xseg.xseg_cancel_wait(ctx, mportno)
47 xseg.xseg_put_request(ctx, recv.portno, recv)
48 except Exception as e:
51 if recv == None and xreq == None:
52 xseg.xseg_wait_signal(ctx, 1000)
54 if nr_received >= nr_requests:
57 print ("Elapsed: %lf\n", time.time() - t)
58 print "submitted %ld, received %ld\n" % (nr_submitted, nr_received)
61 xseg.xseg_initialize()
62 xseg.xseg_parse_spec("segdev:xsegbd:", xconf)
63 ctx=xseg.xseg_join(xconf.type, xconf.name, "posix", xseg.cast(0, cb_null_ptrtype))
64 xseg.xseg_bind_port(ctx, mportno)
68 if __name__ == '__main__':
69 nr_requests = int(sys.argv[1])
70 concurrent_reqs = int(sys.argv[2])