Commit a59fd353 authored by Andrey Vagin's avatar Andrey Vagin Committed by Pavel Emelyanov

zdtm: make datagen/datachk faster for big chunks

Generate random data only for buffers with sizes less than FAST_SIZE
If a size of buffer is more that FAST_SIZE, the first FAST_SIZE bytes
are filled by random generator and then this chunk is used as pattern
for all other chunks.

With out this patch:
$ time bash -x test/zdtm.sh static/maps04
real	0m16.777s
user	0m0.054s
sys	0m0.724s

With this patch:
$ time bash -x test/zdtm.sh static/maps04
real	0m1.865s
user	0m0.128s
sys	0m0.745s
Signed-off-by: 's avatarAndrey Vagin <avagin@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 28f063ab
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include "zdtmtst.h" #include "zdtmtst.h"
/*
* Generate random data only for buffers with sizes less than FAST_SIZE
* If a size of buffer is more than FAST_SIZE, the first FAST_SIZE bytes
* are filled by random generator and then this chunk is used as pattern
* for all other chunks.
*/
#define FAST_SIZE 99971 /* Prime number */
static void datagen_fast(uint8_t *buffer, unsigned length, uint32_t *crc)
{
uint8_t *p;
datagen(buffer, FAST_SIZE, crc);
p = buffer + FAST_SIZE;
while (p < buffer + length) {
unsigned long size = FAST_SIZE;
if (p + FAST_SIZE > buffer + length)
size = buffer + length - p;
memcpy(p, buffer, size);
p += FAST_SIZE;
}
}
static int datachk_fast(const uint8_t *buffer, unsigned length, uint32_t *crc)
{
const uint8_t *p;
if (datachk(buffer, FAST_SIZE, crc))
return 1;
p = buffer + FAST_SIZE;
while (p < buffer + length) {
unsigned long size = FAST_SIZE;
if (p + FAST_SIZE > buffer + length)
size = buffer + length - p;
if (memcmp(p, buffer, size)) {
test_msg("Memory corruption [%p, %p]\n", p, p + size);
return 1;
}
p += FAST_SIZE;
}
return 0;
}
/* update CRC-32 */ /* update CRC-32 */
#define CRCPOLY 0xedb88320 #define CRCPOLY 0xedb88320
static inline uint32_t crc32_le8(uint32_t crc, uint8_t datum) static inline uint32_t crc32_le8(uint32_t crc, uint8_t datum)
...@@ -18,6 +71,9 @@ void datagen(uint8_t *buffer, unsigned length, uint32_t *crc) ...@@ -18,6 +71,9 @@ void datagen(uint8_t *buffer, unsigned length, uint32_t *crc)
uint32_t rnd = 0; uint32_t rnd = 0;
unsigned shift; unsigned shift;
if (length > FAST_SIZE)
return datagen_fast(buffer, length, crc);
for (shift = 0; length-- > 4; buffer++, shift--, rnd >>= 8) { for (shift = 0; length-- > 4; buffer++, shift--, rnd >>= 8) {
if (!shift) { if (!shift) {
shift = 4; shift = 4;
...@@ -58,6 +114,9 @@ int datachk(const uint8_t *buffer, unsigned length, uint32_t *crc) ...@@ -58,6 +114,9 @@ int datachk(const uint8_t *buffer, unsigned length, uint32_t *crc)
{ {
uint32_t read_crc; uint32_t read_crc;
if (length > FAST_SIZE)
return datachk_fast(buffer, length, crc);
for (; length-- > 4; buffer++) for (; length-- > 4; buffer++)
*crc = crc32_le8(*crc, *buffer); *crc = crc32_le8(*crc, *buffer);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment