test_writesame*_unmap: Optimize result buffer comparison
While running the test tool I noticed that a significant number of CPU cycles was spent in test_writesame10_unmap(). Rewrite the comparison loop such that it needs fewer CPU cycles. Use the same comparison code in test_writesame16_unmap(). Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
This commit is contained in:
committed by
Ronnie Sahlberg
parent
52e45096df
commit
12eea9756b
@@ -26,11 +26,28 @@
|
|||||||
#include "iscsi-test-cu.h"
|
#include "iscsi-test-cu.h"
|
||||||
|
|
||||||
|
|
||||||
|
static const unsigned char zeroBlock[4096];
|
||||||
|
|
||||||
|
static int all_zeroes(const unsigned char *buf, unsigned size)
|
||||||
|
{
|
||||||
|
unsigned j, e;
|
||||||
|
|
||||||
|
for (j = 0; j < size; j += sizeof(zeroBlock)) {
|
||||||
|
e = size - j;
|
||||||
|
if (sizeof(zeroBlock) < e)
|
||||||
|
e = sizeof(zeroBlock);
|
||||||
|
if (memcmp(buf + j, zeroBlock, e) != 0)
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
test_writesame10_unmap(void)
|
test_writesame10_unmap(void)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
unsigned int i, j;
|
unsigned int i;
|
||||||
unsigned char *buf = alloca(256 * block_size);
|
unsigned char *buf = alloca(256 * block_size);
|
||||||
|
|
||||||
CHECK_FOR_DATALOSS;
|
CHECK_FOR_DATALOSS;
|
||||||
@@ -66,11 +83,7 @@ test_writesame10_unmap(void)
|
|||||||
i * block_size, block_size,
|
i * block_size, block_size,
|
||||||
0, 0, 0, 0, 0, buf,
|
0, 0, 0, 0, 0, buf,
|
||||||
EXPECT_STATUS_GOOD);
|
EXPECT_STATUS_GOOD);
|
||||||
for (j = 0; j < block_size * i; j++) {
|
CU_ASSERT(all_zeroes(buf, i * block_size));
|
||||||
if (buf[j] != 0) {
|
|
||||||
CU_ASSERT_EQUAL(buf[j], 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
logging(LOG_VERBOSE, "LBPRZ is clear. Skip the read "
|
logging(LOG_VERBOSE, "LBPRZ is clear. Skip the read "
|
||||||
"and verify zero test");
|
"and verify zero test");
|
||||||
@@ -105,11 +118,7 @@ test_writesame10_unmap(void)
|
|||||||
i * block_size, block_size,
|
i * block_size, block_size,
|
||||||
0, 0, 0, 0, 0, buf,
|
0, 0, 0, 0, 0, buf,
|
||||||
EXPECT_STATUS_GOOD);
|
EXPECT_STATUS_GOOD);
|
||||||
for (j = 0; j < block_size * i; j++) {
|
CU_ASSERT(all_zeroes(buf, i * block_size));
|
||||||
if (buf[j] != 0) {
|
|
||||||
CU_ASSERT_EQUAL(buf[j], 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
logging(LOG_VERBOSE, "LBPRZ is clear. Skip the read "
|
logging(LOG_VERBOSE, "LBPRZ is clear. Skip the read "
|
||||||
"and verify zero test");
|
"and verify zero test");
|
||||||
@@ -181,11 +190,7 @@ test_writesame10_unmap(void)
|
|||||||
i * block_size, block_size,
|
i * block_size, block_size,
|
||||||
0, 0, 0, 0, 0, buf,
|
0, 0, 0, 0, 0, buf,
|
||||||
EXPECT_STATUS_GOOD);
|
EXPECT_STATUS_GOOD);
|
||||||
for (j = 0; j < block_size * i; j++) {
|
CU_ASSERT(all_zeroes(buf, i * block_size));
|
||||||
if (buf[j] != 0) {
|
|
||||||
CU_ASSERT_EQUAL(buf[j], 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
logging(LOG_VERBOSE, "LBPRZ is clear. Skip the read "
|
logging(LOG_VERBOSE, "LBPRZ is clear. Skip the read "
|
||||||
"and verify zero test");
|
"and verify zero test");
|
||||||
|
|||||||
@@ -25,13 +25,29 @@
|
|||||||
#include "iscsi-test-cu.h"
|
#include "iscsi-test-cu.h"
|
||||||
|
|
||||||
|
|
||||||
|
static const unsigned char zeroBlock[4096];
|
||||||
|
|
||||||
|
static int all_zeroes(const unsigned char *buf, unsigned size)
|
||||||
|
{
|
||||||
|
unsigned j, e;
|
||||||
|
|
||||||
|
for (j = 0; j < size; j += sizeof(zeroBlock)) {
|
||||||
|
e = size - j;
|
||||||
|
if (sizeof(zeroBlock) < e)
|
||||||
|
e = sizeof(zeroBlock);
|
||||||
|
if (memcmp(buf + j, zeroBlock, e) != 0)
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
test_writesame16_unmap(void)
|
test_writesame16_unmap(void)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
unsigned int i, j;
|
unsigned int i;
|
||||||
unsigned char *buf;
|
unsigned char *buf;
|
||||||
unsigned char *zeroBlock;
|
|
||||||
|
|
||||||
CHECK_FOR_DATALOSS;
|
CHECK_FOR_DATALOSS;
|
||||||
CHECK_FOR_THIN_PROVISIONING;
|
CHECK_FOR_THIN_PROVISIONING;
|
||||||
@@ -41,8 +57,6 @@ test_writesame16_unmap(void)
|
|||||||
logging(LOG_VERBOSE, LOG_BLANK_LINE);
|
logging(LOG_VERBOSE, LOG_BLANK_LINE);
|
||||||
logging(LOG_VERBOSE, "Test WRITESAME16 of 1-256 blocks at the start of the LUN");
|
logging(LOG_VERBOSE, "Test WRITESAME16 of 1-256 blocks at the start of the LUN");
|
||||||
buf = malloc(65536 * block_size);
|
buf = malloc(65536 * block_size);
|
||||||
zeroBlock = alloca(block_size);
|
|
||||||
memset(zeroBlock, 0, block_size);
|
|
||||||
for (i = 1; i <= 256; i++) {
|
for (i = 1; i <= 256; i++) {
|
||||||
logging(LOG_VERBOSE, "Write %d blocks of 0xFF", i);
|
logging(LOG_VERBOSE, "Write %d blocks of 0xFF", i);
|
||||||
memset(buf, 0xff, i * block_size);
|
memset(buf, 0xff, i * block_size);
|
||||||
@@ -70,9 +84,7 @@ test_writesame16_unmap(void)
|
|||||||
i * block_size, block_size,
|
i * block_size, block_size,
|
||||||
0, 0, 0, 0, 0, buf,
|
0, 0, 0, 0, 0, buf,
|
||||||
EXPECT_STATUS_GOOD);
|
EXPECT_STATUS_GOOD);
|
||||||
for (j = 0; j < i; j++) {
|
CU_ASSERT(all_zeroes(buf, i * block_size));
|
||||||
CU_ASSERT_EQUAL(memcmp(buf + j*block_size, zeroBlock, block_size), 0);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
logging(LOG_VERBOSE, "LBPRZ is clear. Skip the read "
|
logging(LOG_VERBOSE, "LBPRZ is clear. Skip the read "
|
||||||
"and verify zero test");
|
"and verify zero test");
|
||||||
@@ -105,9 +117,7 @@ test_writesame16_unmap(void)
|
|||||||
i * block_size, block_size,
|
i * block_size, block_size,
|
||||||
0, 0, 0, 0, 0, buf,
|
0, 0, 0, 0, 0, buf,
|
||||||
EXPECT_STATUS_GOOD);
|
EXPECT_STATUS_GOOD);
|
||||||
for (j = 0; j < i; j++) {
|
CU_ASSERT(all_zeroes(buf, i * block_size));
|
||||||
CU_ASSERT_EQUAL(memcmp(buf + j*block_size, zeroBlock, block_size), 0);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
logging(LOG_VERBOSE, "LBPRZ is clear. Skip the read "
|
logging(LOG_VERBOSE, "LBPRZ is clear. Skip the read "
|
||||||
"and verify zero test");
|
"and verify zero test");
|
||||||
@@ -178,9 +188,7 @@ test_writesame16_unmap(void)
|
|||||||
i * block_size, block_size,
|
i * block_size, block_size,
|
||||||
0, 0, 0, 0, 0, buf,
|
0, 0, 0, 0, 0, buf,
|
||||||
EXPECT_STATUS_GOOD);
|
EXPECT_STATUS_GOOD);
|
||||||
for (j = 0; j < i; j++) {
|
CU_ASSERT(all_zeroes(buf, i * block_size));
|
||||||
CU_ASSERT_EQUAL(memcmp(buf + j*block_size, zeroBlock, block_size), 0);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
logging(LOG_VERBOSE, "LBPRZ is clear. Skip the read "
|
logging(LOG_VERBOSE, "LBPRZ is clear. Skip the read "
|
||||||
"and verify zero test");
|
"and verify zero test");
|
||||||
@@ -230,9 +238,7 @@ test_writesame16_unmap(void)
|
|||||||
i * block_size, block_size,
|
i * block_size, block_size,
|
||||||
0, 0, 0, 0, 0, buf,
|
0, 0, 0, 0, 0, buf,
|
||||||
EXPECT_STATUS_GOOD);
|
EXPECT_STATUS_GOOD);
|
||||||
for (j = 0; j < i; j++) {
|
CU_ASSERT(all_zeroes(buf, i * block_size));
|
||||||
CU_ASSERT_EQUAL(memcmp(buf + j*block_size, zeroBlock, block_size), 0);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
logging(LOG_VERBOSE, "LBPRZ is clear. Skip the read "
|
logging(LOG_VERBOSE, "LBPRZ is clear. Skip the read "
|
||||||
"and verify zero test");
|
"and verify zero test");
|
||||||
|
|||||||
Reference in New Issue
Block a user