コード例 #1
0
ファイル: blk.c プロジェクト: xguo/nvml
/*
 * nszero -- (internal) zero data in the namespace encapsulating the BTT
 *
 * This routine is provided to btt_init() to allow the btt module to
 * zero the memory pool containing the BTT layout.
 */
static int
nszero(void *ns, unsigned lane, size_t count, uint64_t off)
{
	struct pmemblk *pbp = (struct pmemblk *)ns;

	LOG(13, "pbp %p lane %u count %zu off %ju", pbp, lane, count, off);

	if (off + count > pbp->datasize) {
		ERR("offset + count (%zu) past end of data area (%zu)",
				off + count, pbp->datasize);
		errno = EINVAL;
		return -1;
	}

	void *dest = (char *)pbp->data + off;

	/* unprotect the memory (debug version only) */
	RANGE_RW(dest, count);

	pmem_memset_persist(dest, 0, count);

	/* protect the memory again (debug version only) */
	RANGE_RO(dest, count);

	return 0;
}
コード例 #2
0
ファイル: pmem_memset.cpp プロジェクト: krzycz/nvml
/*
 * libpmem_memset_persist -- perform operation using libpmem
 * pmem_memset_persist().
 */
static int
libpmem_memset_persist(void *dest, int c, size_t len)
{
	pmem_memset_persist(dest, c, len);

	return 0;
}
コード例 #3
0
ファイル: pmem_memset.cpp プロジェクト: krzycz/nvml
/*
 * warmup_persist -- does the warmup by writing the whole pool area
 */
static int
warmup_persist(struct memset_bench *mb)
{
	void *dest = mb->pmem_addr;
	int c = mb->const_b;
	size_t len = mb->fsize;

	pmem_memset_persist(dest, c, len);

	return 0;
}
コード例 #4
0
ファイル: pmem_movnt_align.c プロジェクト: mpusz/nvml
/*
 * check_memset -- check pmem_memset_no_drain function
 */
void
check_memset(void *dest, size_t len)
{
	char buff[len];
	memset(buff, 1, len);

	pmem_memset_persist(dest, 1, len);

	if (memcmp(dest, buff, len))
		FATAL("memset failed");
}
コード例 #5
0
ファイル: pmem_movnt_align.c プロジェクト: ChandKV/nvml
/*
 * check_memset -- check pmem_memset_no_drain function
 */
static void
check_memset(void *dest, size_t len)
{
	char *buff = malloc(sizeof(char) * len);
	memset(buff, 1, len);

	pmem_memset_persist(dest, 1, len);

	if (memcmp(dest, buff, len))
		UT_FATAL("memset failed");
	free(buff);
}
コード例 #6
0
ファイル: pmreorder_simple.c プロジェクト: krzycz/nvml
int
main(int argc, char *argv[])
{
	START(argc, argv, "pmreorder_simple");

	util_init();

	if ((argc != 3) || (strchr("gbcm", argv[1][0]) == NULL) ||
			argv[1][1] != '\0')
		UT_FATAL("usage: %s g|b|c|m file", argv[0]);

	int fd = OPEN(argv[2], O_RDWR);
	size_t size;
	/* mmap and register in valgrind pmemcheck */
	void *map = pmem_map_file(argv[2], 0, 0, 0, &size, NULL);
	UT_ASSERTne(map, NULL);

	struct three_field *structp = map;

	char opt = argv[1][0];

	/* clear the struct to get a consistent start state for writing */
	if (strchr("gb", opt))
		pmem_memset_persist(structp, 0, sizeof(*structp));
	else if (strchr("m", opt)) {
		/* set test values to log an inconsistent start state */
		pmem_memset_persist(&structp->flag, 1, sizeof(int));
		pmem_memset_persist(&structp->first_field, 0, sizeof(int) * 2);
		pmem_memset_persist(&structp->third_field, 1, sizeof(int));
		/* clear the struct to get back a consistent start state */
		pmem_memset_persist(structp, 0, sizeof(*structp));
	}

	/* verify that DEFAULT_REORDER restores default engine */
	VALGRIND_EMIT_LOG("PMREORDER_MARKER_CHANGE.BEGIN");

	switch (opt) {
		case 'g':
			write_consistent(structp);
			break;
		case 'b':
			write_inconsistent(structp);
			break;
		case 'm':
			write_consistent(structp);
			break;
		case 'c':
			return check_consistency(structp);
		default:
			UT_FATAL("Unrecognized option %c", opt);
	}
	VALGRIND_EMIT_LOG("PMREORDER_MARKER_CHANGE.END");

	/* check if undefined marker will not cause an issue */
	VALGRIND_EMIT_LOG("PMREORDER_MARKER_UNDEFINED.BEGIN");
	VALGRIND_EMIT_LOG("PMREORDER_MARKER_UNDEFINED.END");

	CLOSE(fd);

	DONE(NULL);
}
コード例 #7
0
ファイル: pmem_memset.c プロジェクト: tomaszkapela/nvml
int
main(int argc, char *argv[])
{
	int fd;
	size_t mapped_len;
	char *dest;
	char *dest1;
	char *ret;

	START(argc, argv, "pmem_memset");

	if (argc != 4)
		UT_FATAL("usage: %s file offset length", argv[0]);

	fd = OPEN(argv[1], O_RDWR);

	/* open a pmem file and memory map it */
	if ((dest = pmem_map_file(argv[1], 0, 0, 0, &mapped_len, NULL)) == NULL)
		UT_FATAL("!Could not mmap %s\n", argv[1]);

	int dest_off = atoi(argv[2]);
	size_t bytes = strtoul(argv[3], NULL, 0);

	char *buf = MALLOC(bytes);

	memset(dest, 0, bytes);
	util_persist_auto(util_fd_is_device_dax(fd), dest, bytes);
	dest1 = MALLOC(bytes);
	memset(dest1, 0, bytes);

	/*
	 * This is used to verify that the value of what a non persistent
	 * memset matches the outcome of the persistent memset. The
	 * persistent memset will match the file but may not be the
	 * correct or expected value.
	 */
	memset(dest1 + dest_off, 0x5A, bytes / 4);
	memset(dest1 + dest_off  + (bytes / 4), 0x46, bytes / 4);

	/* Test the corner cases */
	ret = pmem_memset_persist(dest + dest_off, 0x5A, 0);
	UT_ASSERTeq(ret, dest + dest_off);
	UT_ASSERTeq(*(char *)(dest + dest_off), 0);

	/*
	 * Do the actual memset with persistence.
	 */
	ret = pmem_memset_persist(dest + dest_off, 0x5A, bytes / 4);
	UT_ASSERTeq(ret, dest + dest_off);
	ret = pmem_memset_persist(dest + dest_off  + (bytes / 4),
					0x46, bytes / 4);
	UT_ASSERTeq(ret, dest + dest_off + (bytes / 4));

	if (memcmp(dest, dest1, bytes / 2))
		UT_ERR("%s: first %zu bytes do not match",
			argv[1], bytes / 2);

	LSEEK(fd, (off_t)0, SEEK_SET);
	if (READ(fd, buf, bytes / 2) == bytes / 2) {
		if (memcmp(buf, dest, bytes / 2))
			UT_ERR("%s: first %zu bytes do not match",
				argv[1], bytes / 2);
	}

	UT_ASSERTeq(pmem_unmap(dest, mapped_len), 0);

	FREE(dest1);
	FREE(buf);
	CLOSE(fd);

	DONE(NULL);
}
コード例 #8
0
ファイル: pmem_movnt_align.c プロジェクト: GBuella/nvml
static void *
pmem_memset_persist_wrapper(void *pmemdest, int c, size_t len, unsigned flags)
{
	(void) flags;
	return pmem_memset_persist(pmemdest, c, len);
}