[Pvfs2-cvs] commit by vilayann in pvfs2-1/test/posix: libstat.c getdents.c module.mk.in stat.c

CVS commit program cvs at parl.clemson.edu
Thu Aug 31 22:26:17 EDT 2006


Update of /projects/cvsroot/pvfs2-1/test/posix
In directory parlweb1:/tmp/cvs-serv8343/posix

Modified Files:
      Tag: posix-extensions-branch
	getdents.c module.mk.in stat.c 
Added Files:
      Tag: posix-extensions-branch
	libstat.c 
Log Message:
Added new file that can intercept stat family and replay them as statlite system calls..
Perhaps, this could be LD_PRELOAD'ed to show benefits for some compilation workloads..?



--- /dev/null	2004-06-24 14:04:38.000000000 -0400
+++ libstat.c	2006-08-31 22:26:17.000000000 -0400
@@ -0,0 +1,168 @@
+#include <stdio.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <linux/types.h>
+#include <assert.h>
+#include <linux/dirent.h>
+#include <linux/unistd.h>
+
+#define S_SLITE_SIZET     0x1
+#define S_SLITE_BLKSIZE   0x2
+#define S_SLITE_BLOCKS    0x4
+#define S_SLITE_ATIME     0x8
+#define S_SLITE_MTIME     0x10
+#define S_SLITE_CTIME     0x20
+#define S_SLITE_ALL       (S_SLITE_SIZET | S_SLITE_BLKSIZE | S_SLITE_BLOCKS \
+									S_SLITE_ATIME | S_SLITE_MTIME   | S_SLITE_CTIME)
+
+#define SLITE_SIZET(m)    ((m) & S_SLITE_SIZET)
+#define SLITE_BLKSIZE(m)  ((m) & S_SLITE_BLKSIZE)
+#define SLITE_BLOCKS(m)   ((m) & S_SLITE_BLOCKS)
+#define SLITE_ATIME(m)    ((m) & S_SLITE_ATIME)
+#define SLITE_MTIME(m)    ((m) & S_SLITE_MTIME)
+#define SLITE_CTIME(m)    ((m) & S_SLITE_CTIME)
+
+#if defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__)
+/* FIXME:
+ * PLEASE CHANGE THIS SYSTEM
+ * CALL NUMBER IN CASE YOUR
+ * ARCHITECTURE IS NOT IA-32 
+ * OR IF YOUR KERNEL SYSCALL NUMBERS
+ * ARE DIFFERENT. YOU HAVE BEEN WARNED!!!!!
+ */
+#define __NR_newstatlite 313
+#define __NR_newlstatlite 314
+#define __NR_newfstatlite 315
+
+struct kernel_stat_lite {
+	unsigned long  st_dev;
+	unsigned long  st_ino;
+	unsigned short st_mode;
+	unsigned short st_nlink;
+	unsigned short st_uid;
+	unsigned short st_gid;
+	unsigned long  st_rdev;
+	unsigned long  st_litemask;
+	unsigned long  st_size;
+	unsigned long  st_blksize;
+	unsigned long  st_blocks;
+	unsigned long  st_atim;
+	unsigned long  st_atime_nsec;
+	unsigned long  st_mtim;
+	unsigned long  st_mtime_nsec;
+	unsigned long  st_ctim;
+	unsigned long  st_ctime_nsec;
+	unsigned long  __unused4;
+	unsigned long  __unused5;
+};
+
+#elif defined (x86_64) || defined (__x86_64__)
+
+#define __NR_newstatlite   275
+#define __NR_newlstatlite  276
+#define __NR_newfstatlite  277
+
+struct kernel_stat_lite {
+	unsigned long	st_dev;
+	unsigned long	st_ino;
+	unsigned long	st_nlink;
+
+	unsigned int	st_mode;
+	unsigned int	st_uid;
+	unsigned int	st_gid;
+	unsigned int	__pad0;
+	unsigned long	st_rdev;
+	unsigned long  st_litemask;
+	long		st_size;
+	long		st_blksize;
+	long		st_blocks;	/* Number 512-byte blocks allocated. */
+
+	unsigned long	st_atim;
+	unsigned long 	st_atime_nsec; 
+	unsigned long	st_mtim;
+	unsigned long	st_mtime_nsec;
+	unsigned long	st_ctim;
+	unsigned long   st_ctime_nsec;
+  	long		__unused[3];
+};
+#endif
+
+static int newstatlite(const char *, struct kernel_stat_lite *);
+static int newfstatlite(int, struct kernel_stat_lite *);
+static int newlstatlite(const char *, struct kernel_stat_lite *);
+static int getdents(uint, struct dirent *, uint);
+
+_syscall2(int, newstatlite, const char *, path, struct kernel_stat_lite *, buf);
+_syscall2(int, newfstatlite, int, filedes, struct kernel_stat_lite *, buf);
+_syscall2(int, newlstatlite, const char *, path, struct kernel_stat_lite *, buf);
+
+static void copy_statlite_to_stat(struct kernel_stat_lite *slbuf,
+		struct stat *sbuf)
+{
+	sbuf->st_dev = slbuf->st_dev;
+	sbuf->st_ino = slbuf->st_ino;
+	sbuf->st_mode = slbuf->st_mode;
+	sbuf->st_nlink = slbuf->st_nlink;
+	sbuf->st_uid = slbuf->st_uid;
+	sbuf->st_gid = slbuf->st_gid;
+	sbuf->st_rdev = slbuf->st_rdev;
+	sbuf->st_size = 0;
+	sbuf->st_blksize = slbuf->st_blksize;
+	sbuf->st_blocks = slbuf->st_blocks;
+	sbuf->st_atime = slbuf->st_atim;
+	sbuf->st_mtime = slbuf->st_mtim;
+	sbuf->st_ctime = slbuf->st_ctim;
+}
+
+int stat(const char *pathname, struct stat *sbuf)
+{
+	struct kernel_stat_lite slbuf;
+	int ret;
+	memset(&slbuf, 0, sizeof(slbuf));
+	slbuf.st_litemask = S_SLITE_ATIME | 
+		S_SLITE_MTIME |
+		S_SLITE_CTIME | 
+		S_SLITE_BLKSIZE |
+		S_SLITE_BLOCKS;
+	ret = newstatlite(pathname, &slbuf);
+	if (ret < 0)
+		return ret;
+	copy_statlite_to_stat(&slbuf, sbuf);
+	return 0;
+}
+
+int lstat(const char *pathname, struct stat *sbuf)
+{
+	struct kernel_stat_lite slbuf;
+	int ret;
+	memset(&slbuf, 0, sizeof(slbuf));
+	slbuf.st_litemask = S_SLITE_ATIME | 
+		S_SLITE_MTIME |
+		S_SLITE_CTIME | 
+		S_SLITE_BLKSIZE |
+		S_SLITE_BLOCKS;
+	ret = newlstatlite(pathname, &slbuf);
+	if (ret < 0)
+		return ret;
+	copy_statlite_to_stat(&slbuf, sbuf);
+	return 0;
+}
+
+int fstat(int fd, struct stat *sbuf)
+{
+	struct kernel_stat_lite slbuf;
+	int ret;
+	memset(&slbuf, 0, sizeof(slbuf));
+	slbuf.st_litemask = S_SLITE_ATIME | 
+		S_SLITE_MTIME |
+		S_SLITE_CTIME | 
+		S_SLITE_BLKSIZE |
+		S_SLITE_BLOCKS;
+	ret = newfstatlite(fd, &slbuf);
+	if (ret < 0)
+		return ret;
+	copy_statlite_to_stat(&slbuf, sbuf);
+	return 0;
+}

Index: getdents.c
===================================================================
RCS file: /projects/cvsroot/pvfs2-1/test/posix/Attic/getdents.c,v
diff -p -u -r1.1.2.5 -r1.1.2.6
--- getdents.c	31 Aug 2006 22:11:49 -0000	1.1.2.5
+++ getdents.c	1 Sep 2006 02:26:17 -0000	1.1.2.6
@@ -6,6 +6,8 @@
 #include <string.h>
 #include <assert.h>
 #include <unistd.h>
+#include <time.h>
+#include <sys/time.h>
 #include <errno.h>
 #include <linux/types.h>
 #include <linux/dirent.h>
@@ -24,6 +26,7 @@ static int recurse = 0;
 /* whether to use 64 bit calls or 32 bit ones */
 static int use_64 = 0;
 static char path[256] = ".";
+static int nlevels = 0, nobjects = 0;
 
 #if defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__)
 /* FIXME:
@@ -685,9 +688,11 @@ static int path_walk(struct files *root_
 	}
 	if (ret < 0)
 		goto err;
+	nobjects++;
 	/* Are we looking at a directory? */
 	if (is_dir) 
 	{
+		nlevels++;
 		/* Use plain old getdents interface */
 		if (dir_fd >= 0 && use_direntplus == 0) 
 		{
@@ -963,11 +968,19 @@ err:
 	return ret;
 }
 
+static double Wtime(void)
+{
+    struct timeval t;
+    gettimeofday(&t, NULL);
+    return((double)t.tv_sec * 1e03 + (double)(t.tv_usec) * 1e-03);
+}
 
 static int do_flatten_hierarchy(void)
 {
 	struct files *filp = NULL;
+	double begin, end;
 
+	begin = Wtime();
 	/* traverse the tree and prune out unnecessary files and flatten the hierarchy */
 	path_init(path);
 	/* walk the tree */
@@ -979,6 +992,13 @@ static int do_flatten_hierarchy(void)
 			return -1;
 		}
 	}
+	end = Wtime();
+	if (use_direntplus)
+			  printf("getdents_plus (%d levels %d objects) took %g msecs\n",
+									nlevels, nobjects, (end - begin));
+	else
+			  printf("getdents (%d levels %d objects) took %g msecs\n",
+									nlevels, nobjects, (end - begin));
 	return 0;
 }
 

Index: module.mk.in
===================================================================
RCS file: /projects/cvsroot/pvfs2-1/test/posix/Attic/module.mk.in,v
diff -p -u -r1.1.2.6 -r1.1.2.7
--- module.mk.in	29 Aug 2006 23:28:53 -0000	1.1.2.6
+++ module.mk.in	1 Sep 2006 02:26:17 -0000	1.1.2.7
@@ -21,6 +21,9 @@ MPIMISCSRC += \
 	$(DIR)/sha1.c \
 	$(DIR)/sockio.c
 
+DLLSRC += \
+	$(DIR)/libstat.c
+
 MPITESTSRC += $(DIR)/openg-mpi.c $(DIR)/open.c
 
 MODCFLAGS_$(DIR)/getdents.c = -D_GNU_SOURCE

Index: stat.c
===================================================================
RCS file: /projects/cvsroot/pvfs2-1/test/posix/Attic/stat.c,v
diff -p -u -r1.1.2.2 -r1.1.2.3
--- stat.c	31 Aug 2006 22:11:49 -0000	1.1.2.2
+++ stat.c	1 Sep 2006 02:26:17 -0000	1.1.2.3
@@ -22,6 +22,8 @@ static int dirent_granularity = 4096;
 static int recurse = 0;
 static char path[256] = ".";
 static int use_lite = 0;
+static int nobjects = 0, nlevels = 0;
+
 #define S_SLITE_SIZET     0x1
 #define S_SLITE_BLKSIZE   0x2
 #define S_SLITE_BLOCKS    0x4
@@ -507,9 +509,11 @@ static int path_walk(struct files *root_
 	}
 	if (ret < 0)
 		goto err;
+	nobjects++;
 	/* Are we looking at a directory? */
 	if (is_dir) 
 	{
+		nlevels++;
 		/* Use plain old getdents interface */
 		if (dir_fd >= 0) 
 		{
@@ -592,11 +596,20 @@ err:
 	if (dir_fd > 0) close(dir_fd);
 	return ret;
 }
+
+static double Wtime(void)
+{
+    struct timeval t;
+    gettimeofday(&t, NULL);
+    return((double)t.tv_sec * 1e03 + (double)(t.tv_usec) * 1e-03);
+}
 	
 static int do_flatten_hierarchy(void)
 {
 	struct files *filp = NULL;
+	double begin, end;
 
+	begin = Wtime();
 	/* traverse the tree and prune out unnecessary files and flatten the hierarchy */
 	path_init(path);
 	/* walk the tree */
@@ -608,6 +621,13 @@ static int do_flatten_hierarchy(void)
 			return -1;
 		}
 	}
+	end = Wtime();
+	if (use_lite) 
+		printf("statlite (%d levels %d objects) took %g msecs\n",
+				nlevels, nobjects, (end - begin));
+	else 
+		printf("stat (%d levels %d objects) took %g msecs\n",
+				nlevels, nobjects, (end - begin));
 	return 0;
 }
 



More information about the Pvfs2-cvs mailing list