mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-31 06:15:24 +00:00
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: Andrey Vagin <avagin@openvz.org> Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
committed by
Pavel Emelyanov
parent
28f063ab9c
commit
a59fd3533f
@@ -1,7 +1,60 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.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 */
|
||||
#define CRCPOLY 0xedb88320
|
||||
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)
|
||||
uint32_t rnd = 0;
|
||||
unsigned shift;
|
||||
|
||||
if (length > FAST_SIZE)
|
||||
return datagen_fast(buffer, length, crc);
|
||||
|
||||
for (shift = 0; length-- > 4; buffer++, shift--, rnd >>= 8) {
|
||||
if (!shift) {
|
||||
shift = 4;
|
||||
@@ -58,6 +114,9 @@ int datachk(const uint8_t *buffer, unsigned length, uint32_t *crc)
|
||||
{
|
||||
uint32_t read_crc;
|
||||
|
||||
if (length > FAST_SIZE)
|
||||
return datachk_fast(buffer, length, crc);
|
||||
|
||||
for (; length-- > 4; buffer++)
|
||||
*crc = crc32_le8(*crc, *buffer);
|
||||
|
||||
|
Reference in New Issue
Block a user