Ver código fonte

try to fix unistd functions

Corentin Salingue 12 anos atrás
pai
commit
62cafe2c61
3 arquivos alterados com 42 adições e 17 exclusões
  1. 29 14
      src/core/disk_ops/disk_unistd.c
  2. 2 1
      src/datawizard/malloc.c
  3. 11 2
      tests/disk/disk_compute.c

+ 29 - 14
src/core/disk_ops/disk_unistd.c

@@ -19,12 +19,14 @@
 #include <stdlib.h>
 #include <stdlib.h>
 #include <sys/stat.h>
 #include <sys/stat.h>
 #include <sys/time.h>
 #include <sys/time.h>
+#include <stdint.h>
 
 
 #include <starpu.h>
 #include <starpu.h>
 #include <core/disk.h>
 #include <core/disk.h>
 #include <core/perfmodel/perfmodel.h>
 #include <core/perfmodel/perfmodel.h>
 
 
 #define NITER	64
 #define NITER	64
+#define SIZE_BENCH (4*getpagesize())
 
 
 /* ------------------- use UNISTD to write on disk -------------------  */
 /* ------------------- use UNISTD to write on disk -------------------  */
 
 
@@ -115,14 +117,14 @@ starpu_unistd_open (void *base, void *pos, size_t size)
 	strcpy(baseCpy,(char *) base);
 	strcpy(baseCpy,(char *) base);
 	strcat(baseCpy,(char *) pos);
 	strcat(baseCpy,(char *) pos);
 
 
-	int id = open(baseCpy, O_DIRECT);
+	int id = open(baseCpy, O_RDWR | O_DIRECT);
 	if (id < 0)
 	if (id < 0)
 	{
 	{
 		free(obj);
 		free(obj);
 		free(baseCpy);
 		free(baseCpy);
 		return NULL;
 		return NULL;
 	}
 	}
-	
+
 	obj->descriptor = id;
 	obj->descriptor = id;
 	obj->path = baseCpy;
 	obj->path = baseCpy;
 	obj->size = size;
 	obj->size = size;
@@ -149,11 +151,16 @@ static ssize_t
 starpu_unistd_read (void *base STARPU_ATTRIBUTE_UNUSED, void *obj, void *buf, off_t offset, size_t size)
 starpu_unistd_read (void *base STARPU_ATTRIBUTE_UNUSED, void *obj, void *buf, off_t offset, size_t size)
 {
 {
 	struct starpu_unistd_obj * tmp = (struct starpu_unistd_obj *) obj;
 	struct starpu_unistd_obj * tmp = (struct starpu_unistd_obj *) obj;
-	
+
 	int res = lseek(tmp->descriptor, offset, SEEK_SET); 
 	int res = lseek(tmp->descriptor, offset, SEEK_SET); 
-	STARPU_ASSERT_MSG(res >= 0, "Stdio read failed");
+	STARPU_ASSERT_MSG(res >= 0, "Starpu Disk unistd read failed");
+
+	STARPU_ASSERT_MSG((size % getpagesize()) == 0, "You can only read a multiple of page size %u Bytes (Here %u)", getpagesize(), (int) size);
+
+	STARPU_ASSERT_MSG((((uintptr_t) buf) % getpagesize()) == 0, "You have to use starpu_malloc function");
 
 
 	ssize_t nb = read(tmp->descriptor, buf, size);
 	ssize_t nb = read(tmp->descriptor, buf, size);
+	STARPU_ASSERT_MSG(res >= 0, "Starpu Disk unistd read failed");
 	
 	
 	return nb;
 	return nb;
 }
 }
@@ -164,11 +171,16 @@ static ssize_t
 starpu_unistd_write (void *base STARPU_ATTRIBUTE_UNUSED, void *obj, const void *buf, off_t offset, size_t size)
 starpu_unistd_write (void *base STARPU_ATTRIBUTE_UNUSED, void *obj, const void *buf, off_t offset, size_t size)
 {
 {
 	struct starpu_unistd_obj * tmp = (struct starpu_unistd_obj *) obj;
 	struct starpu_unistd_obj * tmp = (struct starpu_unistd_obj *) obj;
-	
+
 	int res = lseek(tmp->descriptor, offset, SEEK_SET); 
 	int res = lseek(tmp->descriptor, offset, SEEK_SET); 
-	STARPU_ASSERT_MSG(res >= 0, "Stdio write failed");
+	STARPU_ASSERT_MSG(res >= 0, "Starpu Disk unistd write failed");
 
 
+	STARPU_ASSERT_MSG((size % getpagesize()) == 0, "You can only write a multiple of page size %u Bytes (Here %u)", getpagesize(), (int) size);
+
+	STARPU_ASSERT_MSG((((uintptr_t)buf) % getpagesize()) == 0, "You have to use starpu_malloc function");
+	
 	ssize_t nb = write (tmp->descriptor, buf, size);
 	ssize_t nb = write (tmp->descriptor, buf, size);
+	STARPU_ASSERT_MSG(res >= 0, "Starpu Disk unistd write failed");
 
 
 	return nb;
 	return nb;
 }
 }
@@ -181,6 +193,9 @@ starpu_unistd_plug (void *parameter)
 	char * tmp = malloc(sizeof(char)*(strlen(parameter)+1));
 	char * tmp = malloc(sizeof(char)*(strlen(parameter)+1));
 	STARPU_ASSERT(tmp != NULL);
 	STARPU_ASSERT(tmp != NULL);
 	strcpy(tmp,(char *) parameter);
 	strcpy(tmp,(char *) parameter);
+
+	starpu_malloc_set_align(getpagesize());
+	
 	return (void *) tmp;	
 	return (void *) tmp;	
 }
 }
 
 
@@ -202,14 +217,13 @@ get_unistd_bandwidth_between_disk_and_main_ram(unsigned node)
 	struct timeval start;
 	struct timeval start;
 	struct timeval end;
 	struct timeval end;
 
 
-	starpu_malloc_set_align(getpagesize());
-	
 	srand (time (NULL)); 
 	srand (time (NULL)); 
-	char * buf = malloc(SIZE_DISK_MIN*sizeof(char));
+	char * buf;
+	posix_memalign((void *) &buf, getpagesize(), SIZE_BENCH*sizeof(char));
 	STARPU_ASSERT(buf != NULL);
 	STARPU_ASSERT(buf != NULL);
 	
 	
 	/* allocate memory */
 	/* allocate memory */
-	void * mem = _starpu_disk_alloc(node, SIZE_DISK_MIN);
+	void * mem = _starpu_disk_alloc(node, SIZE_BENCH);
 	/* fail to alloc */
 	/* fail to alloc */
 	if (mem == NULL)
 	if (mem == NULL)
 		return 0;
 		return 0;
@@ -218,7 +232,7 @@ get_unistd_bandwidth_between_disk_and_main_ram(unsigned node)
 	gettimeofday(&start, NULL);
 	gettimeofday(&start, NULL);
 	for (iter = 0; iter < NITER; ++iter)
 	for (iter = 0; iter < NITER; ++iter)
 	{
 	{
-		_starpu_disk_write(node, mem, buf, 0, SIZE_DISK_MIN);
+		_starpu_disk_write(node, mem, buf, 0, SIZE_BENCH);
 	}
 	}
 	gettimeofday(&end, NULL);
 	gettimeofday(&end, NULL);
 	timing_slowness = (double)((end.tv_sec - start.tv_sec)*1000000 + (end.tv_usec - start.tv_usec));
 	timing_slowness = (double)((end.tv_sec - start.tv_sec)*1000000 + (end.tv_usec - start.tv_usec));
@@ -227,19 +241,20 @@ get_unistd_bandwidth_between_disk_and_main_ram(unsigned node)
 	/* free memory */
 	/* free memory */
 	free(buf);
 	free(buf);
 
 
-	buf = malloc(sizeof(char));
+	
+	posix_memalign((void *) &buf, getpagesize(), getpagesize()*sizeof(char));
 	STARPU_ASSERT(buf != NULL);
 	STARPU_ASSERT(buf != NULL);
 
 
 	/* Measure latency */
 	/* Measure latency */
 	gettimeofday(&start, NULL);
 	gettimeofday(&start, NULL);
 	for (iter = 0; iter < NITER; ++iter)
 	for (iter = 0; iter < NITER; ++iter)
 	{
 	{
-		_starpu_disk_write(node, mem, buf, rand() % (SIZE_DISK_MIN -1) , 1);
+		_starpu_disk_write(node, mem, buf, rand() % (SIZE_BENCH -1) , getpagesize());
 	}
 	}
 	gettimeofday(&end, NULL);
 	gettimeofday(&end, NULL);
 	timing_latency = (double)((end.tv_sec - start.tv_sec)*1000000 + (end.tv_usec - start.tv_usec));
 	timing_latency = (double)((end.tv_sec - start.tv_sec)*1000000 + (end.tv_usec - start.tv_usec));
 
 
-	_starpu_disk_free(node, mem, SIZE_DISK_MIN);
+	_starpu_disk_free(node, mem, SIZE_BENCH);
 	free(buf);
 	free(buf);
 
 
 	_starpu_save_bandwidth_and_latency_disk((NITER/timing_slowness)*1000000, (NITER/timing_slowness)*1000000,
 	_starpu_save_bandwidth_and_latency_disk((NITER/timing_slowness)*1000000, (NITER/timing_slowness)*1000000,

+ 2 - 1
src/datawizard/malloc.c

@@ -189,6 +189,7 @@ int starpu_malloc_flags(void **A, size_t dim, int flags)
 #ifdef STARPU_HAVE_POSIX_MEMALIGN
 #ifdef STARPU_HAVE_POSIX_MEMALIGN
 	if (_malloc_align != sizeof(void*))
 	if (_malloc_align != sizeof(void*))
 	{
 	{
+		
 		if (posix_memalign(A, _malloc_align, dim))
 		if (posix_memalign(A, _malloc_align, dim))
 		{
 		{
 			ret = -ENOMEM;
 			ret = -ENOMEM;
@@ -369,7 +370,7 @@ starpu_malloc_on_node(unsigned dst_node, size_t size)
 	{
 	{
 		case STARPU_CPU_RAM:
 		case STARPU_CPU_RAM:
 		{
 		{
-			addr = (uintptr_t)malloc(size);
+			addr = (uintptr_t)starpu_malloc((void**) &addr, size);
 			break;
 			break;
 		}
 		}
 #if defined(STARPU_USE_CUDA) || defined(STARPU_SIMGRID)
 #if defined(STARPU_USE_CUDA) || defined(STARPU_SIMGRID)

+ 11 - 2
tests/disk/disk_compute.c

@@ -18,14 +18,16 @@
  * Use mechanism to push datas from main ram to disk ram
  * Use mechanism to push datas from main ram to disk ram
  */
  */
 
 
+#include <fcntl.h>
 #include <starpu.h>
 #include <starpu.h>
 #include <stdlib.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <stdio.h>
 #include <sys/types.h>
 #include <sys/types.h>
+#include <sys/stat.h>
 #include <unistd.h>
 #include <unistd.h>
 #include <math.h>
 #include <math.h>
 
 
-#define NX (100)
+#define NX (1024)
 
 
 int main(int argc, char **argv)
 int main(int argc, char **argv)
 {
 {
@@ -73,7 +75,7 @@ int main(int argc, char **argv)
 
 
 	starpu_malloc_flags((void **)&A, NX*sizeof(int), STARPU_MALLOC_COUNT);
 	starpu_malloc_flags((void **)&A, NX*sizeof(int), STARPU_MALLOC_COUNT);
 	starpu_malloc_flags((void **)&C, NX*sizeof(int), STARPU_MALLOC_COUNT);
 	starpu_malloc_flags((void **)&C, NX*sizeof(int), STARPU_MALLOC_COUNT);
- 
+	
 	unsigned int j;
 	unsigned int j;
 	/* you register them in a vector */
 	/* you register them in a vector */
 	for(j = 0; j < NX; ++j)
 	for(j = 0; j < NX; ++j)
@@ -96,6 +98,9 @@ int main(int argc, char **argv)
 	/* close the file */
 	/* close the file */
 	fclose(f);
 	fclose(f);
 
 
+	int descriptor = open(path_file_start, O_RDWR);
+	fdatasync(descriptor);
+	close(descriptor);
 
 
 	/* create a file to store result */
 	/* create a file to store result */
 	f = fopen(path_file_end, "wb+");
 	f = fopen(path_file_end, "wb+");
@@ -108,6 +113,10 @@ int main(int argc, char **argv)
 	/* close the file */
 	/* close the file */
 	fclose(f);
 	fclose(f);
 
 
+        descriptor = open(path_file_end, O_RDWR);
+        fdatasync(descriptor);
+        close(descriptor);
+
 	/* And now, you want to use your datas in StarPU */
 	/* And now, you want to use your datas in StarPU */
 	/* Open the file ON the disk */
 	/* Open the file ON the disk */
 	void * data = starpu_disk_open(dd, (void *) name_file_start, NX*sizeof(int));
 	void * data = starpu_disk_open(dd, (void *) name_file_start, NX*sizeof(int));