Example #1
0
int main(int argc, const char *argv[]) {
        test_be();
        test_le();
        test_ne();
        return 0;
}
static void time_attr(struct osd_device *osd, int numpg, int numattr, 
		      int numiter, int test, const char *func)
{
	int ret = 0;
	int i = 0;
	uint64_t start, end;
	uint32_t usedlen = 0;
	uint8_t *cp = 0;
	uint64_t val = 0;
	double *t = 0;
	double mu, sd;
	struct list_entry *attr = NULL, *vattr = NULL;
	const uint32_t le_sz = roundup8(18), vle_sz = roundup8(50);
	const char uidp[] = "        unidentified attributes page   ";

	if (test < 1 || test > 9)
		return;

	t = Calloc(numiter, sizeof(*t));
	attr = Calloc(numpg*numattr, le_sz);
	vattr = Calloc(numpg*numattr, vle_sz);
	if (!t || !attr)
		return;

	switch (test) {
	case 1:
	case 2:
	case 3:
		val = 4;
		ret = attr_set_attr(osd->dbc, 1, 1, 2, 22, &val, sizeof(val));
		assert(ret == 0);
		usedlen = 0;
		memset(attr, 0, le_sz);
		ret = attr_get_attr(osd->dbc, 1, 1, 2, 22, le_sz, attr, 
				    RTRVD_SET_ATTR_LIST, &usedlen);
		assert(ret == 0);
		assert(usedlen == le_sz);
		cp = (uint8_t *)attr;
		test_le(2, 22, sizeof(val), &val, cp);
		ret = attr_delete_attr(osd->dbc, 1, 1, 2, 22);
		assert(ret == 0);
		usedlen = 0;
		memset(attr, 0, le_sz);
		ret = attr_get_attr(osd->dbc, 1, 1, 2, 22, le_sz, attr, 
				    RTRVD_SET_ATTR_LIST, &usedlen);
		assert(ret == -ENOENT);
		break;
	case 4:
	case 5:
	case 6:
		if (numpg*numattr < 2) {
			fprintf(stderr, "numpg*numattr < 2\n");
			return;
		}
		val = 200;
		ret = attr_set_attr(osd->dbc, 1, 1, 2, 22, &val, sizeof(val));
		assert(ret == 0);
		val = 400;
		ret = attr_set_attr(osd->dbc, 1, 1, 4, 44, &val, sizeof(val));
		assert(ret == 0);
		usedlen = 0;
		memset(attr, 0, 2*le_sz);
		ret = attr_get_all_attrs(osd->dbc, 1, 1, 2*le_sz, attr, 
				    RTRVD_SET_ATTR_LIST, &usedlen);
		assert(ret == 0);
		assert(usedlen == 2*le_sz);
		val = 200;
		cp = (uint8_t *)attr;
		test_le(2, 22, sizeof(val), &val, cp);
		val = 400;
		cp += le_sz;
		test_le(4, 44, sizeof(val), &val, cp);
		ret = attr_delete_all(osd->dbc, 1, 1);
		assert(ret == 0);
		usedlen = 0;
		memset(attr, 0, 2*le_sz);
		ret = attr_get_attr(osd->dbc, 1, 1, 2, 22, le_sz, attr, 
				    RTRVD_SET_ATTR_LIST, &usedlen);
		assert(ret == -ENOENT);
		ret = attr_get_attr(osd->dbc, 1, 1, 4, 44, le_sz, attr, 
				    RTRVD_SET_ATTR_LIST, &usedlen);
		assert(ret == -ENOENT);
		break;
	case 7:
		if (numpg*numattr < 4) {
			fprintf(stderr, "numpg*numattr < 4\n");
			goto out;
		}
		val = 200;
		ret = attr_set_attr(osd->dbc, 1, 1, 2, 22, &val, sizeof(val));
		assert(ret == 0);
		val = 400;
		ret = attr_set_attr(osd->dbc, 1, 1, 4, 44, &val, sizeof(val));
		assert(ret == 0);
		usedlen = 0;
		memset(vattr, 0, 2*vle_sz);
		ret = attr_get_dir_page(osd->dbc, 1, 1, USEROBJECT_PG,
					vle_sz*2, vattr, RTRVD_SET_ATTR_LIST,
					&usedlen);
		assert(ret == 0);
		assert(usedlen == vle_sz*2);
		cp = (uint8_t *)vattr;
		test_le(USEROBJECT_PG, 2, sizeof(uidp), uidp, cp);
		cp += vle_sz;
		test_le(USEROBJECT_PG, 4, sizeof(uidp), uidp, cp);
		ret = attr_delete_all(osd->dbc, 1, 1);
		assert(ret == 0);
		usedlen = 0;
		memset(attr, 0, 2*le_sz);
		ret = attr_get_attr(osd->dbc, 1, 1, 2, 22, le_sz, attr, 
				    RTRVD_SET_ATTR_LIST, &usedlen);
		assert(ret == -ENOENT);
		ret = attr_get_attr(osd->dbc, 1, 1, 4, 44, le_sz, attr, 
				    RTRVD_SET_ATTR_LIST, &usedlen);
		assert(ret == -ENOENT);
		break;
	case 8:
		if (numpg*numattr < 4) {
			fprintf(stderr, "numpg*numattr < 4\n");
			goto out;
		}
		for (i = 0; i < 4; i++) {
			val = i*100 + 1;
			ret = attr_set_attr(osd->dbc, 1, 1, i, 1, &val, 
					    sizeof(val));
			assert(ret == 0);
			ret = attr_set_attr(osd->dbc, 1, 1, i, 2, &val, 
					    sizeof(val));
			assert(ret == 0);
		}
		usedlen = 0;
		memset(attr, 0, 4*le_sz);
		ret = attr_get_for_all_pages(osd->dbc, 1, 1, 1, 4*le_sz, attr,
					     RTRVD_SET_ATTR_LIST, &usedlen);
		assert(ret == 0);
		assert(usedlen == 4*le_sz);
		cp = (uint8_t *)attr;
		for (i = 0; i < 4; i++) {
			val = i*100 + 1;
			test_le(i, 1, sizeof(val), &val, cp);
			cp += le_sz;
		}
		ret = attr_delete_all(osd->dbc, 1, 1);
		assert(ret == 0);
		usedlen = 0;
		memset(attr, 0, 4*le_sz);
		for (i = 0; i < 4; i++) {
			ret = attr_get_attr(osd->dbc, 1, 1, i, 1, le_sz, attr, 
					    RTRVD_SET_ATTR_LIST, &usedlen);
			assert(ret == -ENOENT);
			ret = attr_get_attr(osd->dbc, 1, 1, i, 2, le_sz, attr, 
					    RTRVD_SET_ATTR_LIST, &usedlen);
			assert(ret == -ENOENT);
		}
		break;
	case 9:
		if (numpg*numattr < 2) {
			fprintf(stderr, "numpg*numattr < 2\n");
			goto out;
		}
		for (i = 0; i < 2; i++) {
			val = i*100 + 1;
			ret = attr_set_attr(osd->dbc, 1, 1, i, 1, &val, 
					    sizeof(val));
			assert(ret == 0);
			ret = attr_set_attr(osd->dbc, 1, 1, i, 2, &val, 
					    sizeof(val));
			assert(ret == 0);
		}
		usedlen = 0;
		memset(attr, 0, 2*le_sz);
		ret = attr_get_page_as_list(osd->dbc, 1, 1, 1, 2*le_sz, attr,
					    RTRVD_SET_ATTR_LIST, &usedlen);
		assert(ret == 0);
		assert(usedlen == 2*le_sz);
		cp = (uint8_t *)attr;
		val = 101;
		test_le(1, 1, 8, &val, cp);
		cp += le_sz;
		test_le(1, 2, 8, &val, cp);
		ret = attr_delete_all(osd->dbc, 1, 1);
		assert(ret == 0);
		usedlen = 0;
		memset(attr, 0, 2*le_sz);
		for (i = 0; i < 2; i++) {
			ret = attr_get_attr(osd->dbc, 1, 1, i, 1, le_sz, attr, 
					    RTRVD_SET_ATTR_LIST, &usedlen);
			assert(ret == -ENOENT);
			ret = attr_get_attr(osd->dbc, 1, 1, i, 2, le_sz, attr, 
					    RTRVD_SET_ATTR_LIST, &usedlen);
			assert(ret == -ENOENT);
		}
		break;
	default:
		goto out;
	}

	for (i = 0; i < numiter;  i++) {
		/* set up; time test no. 4 */
		t[i] = 0.0;

		switch (test) {
		case 2:
		case 3:
			/* set one attr used to get/del */
			val = 400;
			ret = attr_set_attr(osd->dbc, 2, 2, 1, 1, &val,
					    sizeof(val));
			assert(ret == 0);
		case 1:
		case 5:
		case 6:
		case 7:
		case 8:
		case 9:
			pre_create_attrs(osd, numpg, numattr); 
			break;
		case 4: {
			int np, na;
			for (np = 1; np < numpg+1; np++) {
				for (na = 1; na < numattr+1; na++) {
					val = na;
					rdtsc(start);
					ret = attr_set_attr(osd->dbc, 1, 1,
							    np, na, &val, 
							    sizeof(val));
					rdtsc(end);
					assert(ret == 0);
					t[i] += (double)(end - start) / mhz;
				}
			}
			break;
		}
		default:
			goto out;
		}

		/* test */
		switch (test) {
		case 1:
			val = 400;
			rdtsc(start);
			ret = attr_set_attr(osd->dbc, 2, 2, 1, 1, 
					    &val, sizeof(val));
			rdtsc(end);
			assert(ret == 0);
			break;
		case 2:
			usedlen = 0;
			memset(attr, 0, le_sz);
			rdtsc(start);
			ret = attr_get_attr(osd->dbc, 2, 2, 1, 1, le_sz, attr, 
					    RTRVD_SET_ATTR_LIST, &usedlen);
			rdtsc(end);
			assert(ret == 0);
			assert(usedlen == le_sz);
			break;
		case 3:
			usedlen = 0;
			memset(attr, 0, le_sz);
			rdtsc(start);
			ret = attr_delete_attr(osd->dbc, 2, 2, 1, 1);
			rdtsc(end);
			assert(ret == 0);
			break;
		case 4:
			break;
		case 5:
			rdtsc(start);
			ret = attr_get_all_attrs(osd->dbc, 1, 1,
						 numpg*numattr*le_sz, attr,
						 RTRVD_SET_ATTR_LIST,
						 &usedlen);
			rdtsc(end);
			assert(ret == 0);
			assert(usedlen == (numpg*numattr*le_sz));
			break;
		case 6:
			rdtsc(start);
			ret = attr_delete_all(osd->dbc, 1, 1);
			rdtsc(end);
			assert(ret == 0);
			break;
		case 7:
			rdtsc(start);
			ret = attr_get_dir_page(osd->dbc, 1, 1, USEROBJECT_PG,
						numpg*vle_sz, vattr, 
						RTRVD_SET_ATTR_LIST, 
						&usedlen);
			rdtsc(end);
			assert(ret == 0);
			assert(usedlen == numpg*vle_sz);
			break;
		case 8:
			rdtsc(start);
			ret = attr_get_for_all_pages(osd->dbc, 1, 1, 1,
						     numpg*le_sz, attr,
						     RTRVD_SET_ATTR_LIST,
						     &usedlen);
			rdtsc(end);
			assert(ret == 0);
			assert(usedlen == numpg*le_sz);
			break;
		case 9:
			rdtsc(start);
			ret = attr_get_page_as_list(osd->dbc, 1, 1, 1,
						    numattr*le_sz, attr,
						    RTRVD_SET_ATTR_LIST,
						    &usedlen);
			rdtsc(end);
			assert(ret == 0);
			assert(usedlen == numattr*le_sz);
			break;
		default:
			goto out;
		}

		if (test != 4)
			t[i] = (double) (end - start) / mhz;
		end = start = 0;

		/* cleanup */
		switch (test) {
		case 1:
		case 2:
			ret = attr_delete_attr(osd->dbc, 2, 2, 1, 1);
			assert(ret == 0);
		case 3:
		case 4:
		case 5:
			break;
		case 6:
		case 7:
		case 8:
		case 9:
			ret = attr_delete_all(osd->dbc, 1, 1);
			assert(ret == 0);
			break;
		default:
			goto out;
		}
	}

	mu = mean(t, numiter);
	sd = stddev(t, mu, numiter);
	printf("%s numiter %d numpg %d numattr %d test %d avg %lf +- %lf "
	       " us\n", func, numiter, numpg, numattr, test, mu, sd); 

out:
	free(t);
	free(attr);
	free(vattr);
}