Skip to contentSkip to conversation

v2:updated mmap2.c for low memory target

PATCH In review Shang Yanfeng 2 participants 2 messages Jan 19, 2012 – Jan 20, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 v2:updated mmap2.c for low memory target

many low memory boards don't have 1G memory,so add get_free_mem function for low memory target,limit 1000M for n32 file system test.

---
 testcases/kernel/mem/mtest06/mmap2.c |   50 ++++++++++++++++++++++++++-------
 1 files changed, 39 insertions(+), 11 deletions(-)
testcases/kernel/mem/mtest06/mmap2.c +39 -11
index aa9dc33..d83ba54 100644
@@ -69,13 +69,14 @@
 #include <signal.h>
 #include <sys/time.h>
 #include <sys/wait.h>
+#include <sys/sysinfo.h>
 #include <signal.h>
 #include <string.h>
 #include "test.h"
 #include "usctest.h"
 
 /* Defines								      */
-#define GB 1000000000
+#define MB 1048576 
 #ifndef TRUE
 #define TRUE 1
 #endif
@@ -96,7 +97,7 @@
 /*                                                                            */
 /******************************************************************************/
 static int
-mkfile(int size) 		/* size of the file to be generated in GB     */
+mkfile(int size) 		/* size of the file to be generated in MB     */
 {
     int  fd;			/* file descriptior of tmpfile		      */
     int  index = 0;		/* index into the file, fill it with a's      */
@@ -118,7 +119,7 @@ mkfile(int size) 		/* size of the file to be generated in GB     */
     }
 
     /* fill the file with the character a */
-    while (index < (size * GB))
+    while (index < (size * MB))
     {
         index += 4096;
         if (write(fd, buff, 4096) == -1)
@@ -165,6 +166,21 @@ sig_handler(int signal)         /* signal number, set to handle SIGALRM       */
     exit(0);
 }
 
+/*******************************************************************************/
+/* Function:	get_free_mem                                                   */
+/* Description: get the free memory.                                          */ 
+/* Return:	free memory with M					       */
+/*******************************************************************************/
+unsigned long get_free_mem()
+{
+	struct sysinfo board_sysinfo;
+	unsigned long avail_mem;
+	if(sysinfo(&board_sysinfo))
+		perror("sysinfo failed\n");
+	avail_mem = board_sysinfo.freeram/MB;
+	return avail_mem;
+}
+
 /******************************************************************************//*								 	      */
 /* Function:	usage							      */
 /*									      */
@@ -180,7 +196,7 @@ usage(char *progname)           /* name of this program                       */
 	       "\t -a set map_flags to MAP_ANONYMOUS\n"
                "\t -h help, usage message.\n"
                "\t -p set map_flag to MAP_PRIVATE.\tdefault: MAP_SHARED\n"
-               "\t -s size of the file/memory to be mmaped.\tdefault: 1GB\n"
+               "\t -s size of the file/memory to be mmaped.\tdefault: 1000MB\n"
                "\t -x time for which test is to be run.\tdefault: 24 Hrs\n",
                     progname);
     exit(-1);
@@ -204,7 +220,7 @@ int main(int argc,	    /* number of input parameters.		      */
      char **argv)	    /* pointer to the command line arguments.         */
 {
     int   fd;		    /* descriptor of temp file.		              */
-    int   fsize = 1;	    /* size of the temp file created. default 1GB     */
+    unsigned long  fsize = 1000;	    /* size of the temp file created. default 1000MB     */
     float exec_time = 24;    /* period of execution, default 24 hours.	      */
     int   c;		    /* command line options			      */
     int   sig_ndx;	    /* index into signal handler structure.	      */
@@ -234,6 +250,13 @@ int main(int argc,	    /* number of input parameters.		      */
 			   {-1,     "ENDSIG"}
 		   };
 
+	fsize = get_free_mem()/2;
+
+#if __WORDSIZE==32
+	if ( fsize > 1000 )
+		fprintf(stderr, "Using default fsize %ld MB\n", fsize = 1000);
+#endif
+
     while ((c =  getopt(argc, argv, "ahps:x:")) != -1)
     {
         switch(c)
@@ -249,8 +272,13 @@ int main(int argc,	    /* number of input parameters.		      */
 		map_flags = MAP_PRIVATE;
 		break;
 	    case 's':
+#if __WORDSIZE==32
+		if ((fsize = atoi(optarg)) == 0 || (fsize = atoi(optarg)) > 1000 )
+		    fprintf(stderr, "Using default fsize %ld MB\n", fsize = 1000);
+#else
 		if ((fsize = atoi(optarg)) == 0)
-		    fprintf(stderr, "Using default fsize %d GB\n", fsize = 1);
+			fprintf(stderr,"Using default fsize %ld MB\n", fsize = 1000);
+#endif
 		break;
             case 'x':
 		if ((exec_time = atof(optarg)) == 0)
@@ -266,7 +294,7 @@ int main(int argc,	    /* number of input parameters.		      */
 
     fprintf(stdout, "MM Stress test, map/write/unmap large file\n"
 		    "\tTest scheduled to run for:       %f\n"
-		    "\tSize of temp file in GB:         %d\n",
+		    "\tSize of temp file in MB:         %ld\n",
 			exec_time, fsize);
 
     /* set up time for which test has to be run */
@@ -308,7 +336,7 @@ int main(int argc,	    /* number of input parameters.		      */
 	    map_flags = map_flags|MAP_ANONYMOUS;
         }
 
-        if ((memptr = (char *)mmap(0,(fsize * GB), PROT_READ|PROT_WRITE,
+        if ((memptr = (char *)mmap(0,(fsize * MB), PROT_READ|PROT_WRITE,
 		     map_flags, fd, 0)) == (char *)-1)
         {
             perror("main(): mmap()");
@@ -319,16 +347,16 @@ int main(int argc,	    /* number of input parameters.		      */
 			    "changing file content to 'A'\n", memptr);
 
         /* Change the content of the file with A's, and commit changes */
-        memset(memptr, 'A', ((fsize * GB)/sizeof(char)));
+        memset(memptr, 'A', ((fsize * MB)/sizeof(char)));
 
-        if (msync(memptr, ((fsize * GB)/sizeof(char)),
+        if (msync(memptr, ((fsize * MB)/sizeof(char)),
 	                 MS_SYNC|MS_INVALIDATE) == -1)
         {
             perror("main(): msync()");
             exit (-1);
         }
 
-        if (munmap(memptr, (fsize * GB)/sizeof(char)) == -1)
+        if (munmap(memptr, (fsize * MB)/sizeof(char)) == -1)
         {
             perror("main(): munmap()");
             exit (-1);
Signature · 13 lines
1.6.3.1


------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#1 lore raw

Hi!

Quoted 2 lines

many low memory boards don't have 1G memory,so add get_free_mem function for low memory target,limit 1000M for n32 file system test.

First of all, please use checkpatch (a script that is packed with linux kernel sources) before submitting patch.

Ideally you may send a patch that fixes the formatting of the test in separate patch before you start fixing the test logic. That is an easy job. You first remove all the trivial comments from the code (there is a poluttion of useless coments in these mmap testcases) and then run checkpatch -f mmapX.c and do what you are told. That would ease the patch reviewing.

Quoted 1 line

That should be Signed-off-by: YanFeng Shang <[email protected]>

The best way to generate the signature is to use configure git email and name then with 'git commit -s' the Signed-off-by line is added automatically.

Quoted 98 lines
---
 testcases/kernel/mem/mtest06/mmap2.c |   50 ++++++++++++++++++++++++++-------
 1 files changed, 39 insertions(+), 11 deletions(-)
testcases/kernel/mem/mtest06/mmap2.c +28 -5
index aa9dc33..d83ba54 100644
@@ -69,13 +69,14 @@
 #include <signal.h>
 #include <sys/time.h>
 #include <sys/wait.h>
+#include <sys/sysinfo.h>
 #include <signal.h>
 #include <string.h>
 #include "test.h"
 #include "usctest.h"
 
 /* Defines								      */
-#define GB 1000000000
+#define MB 1048576 
 #ifndef TRUE
 #define TRUE 1
 #endif
@@ -96,7 +97,7 @@
 /*                                                                            */
 /******************************************************************************/
 static int
-mkfile(int size) 		/* size of the file to be generated in GB     */
+mkfile(int size) 		/* size of the file to be generated in MB     */
 {
     int  fd;			/* file descriptior of tmpfile		      */
     int  index = 0;		/* index into the file, fill it with a's      */
@@ -118,7 +119,7 @@ mkfile(int size) 		/* size of the file to be generated in GB     */
     }
 
     /* fill the file with the character a */
-    while (index < (size * GB))
+    while (index < (size * MB))
     {
         index += 4096;
         if (write(fd, buff, 4096) == -1)
@@ -165,6 +166,21 @@ sig_handler(int signal)         /* signal number, set to handle SIGALRM       */
     exit(0);
 }
 
+/*******************************************************************************/
+/* Function:	get_free_mem                                                   */
+/* Description: get the free memory.                                          */ 
+/* Return:	free memory with M					       */
+/*******************************************************************************/
+unsigned long get_free_mem()
+{
+	struct sysinfo board_sysinfo;
+	unsigned long avail_mem;
+	if(sysinfo(&board_sysinfo))
+		perror("sysinfo failed\n");
+	avail_mem = board_sysinfo.freeram/MB;
+	return avail_mem;
+}
+
 /******************************************************************************//*								 	      */
 /* Function:	usage							      */
 /*									      */
@@ -180,7 +196,7 @@ usage(char *progname)           /* name of this program                       */
 	       "\t -a set map_flags to MAP_ANONYMOUS\n"
                "\t -h help, usage message.\n"
                "\t -p set map_flag to MAP_PRIVATE.\tdefault: MAP_SHARED\n"
-               "\t -s size of the file/memory to be mmaped.\tdefault: 1GB\n"
+               "\t -s size of the file/memory to be mmaped.\tdefault: 1000MB\n"
                "\t -x time for which test is to be run.\tdefault: 24 Hrs\n",
                     progname);
     exit(-1);
@@ -204,7 +220,7 @@ int main(int argc,	    /* number of input parameters.		      */
      char **argv)	    /* pointer to the command line arguments.         */
 {
     int   fd;		    /* descriptor of temp file.		              */
-    int   fsize = 1;	    /* size of the temp file created. default 1GB     */
+    unsigned long  fsize = 1000;	    /* size of the temp file created. default 1000MB     */
     float exec_time = 24;    /* period of execution, default 24 hours.	      */
     int   c;		    /* command line options			      */
     int   sig_ndx;	    /* index into signal handler structure.	      */
@@ -234,6 +250,13 @@ int main(int argc,	    /* number of input parameters.		      */
 			   {-1,     "ENDSIG"}
 		   };
 
+	fsize = get_free_mem()/2;
+
+#if __WORDSIZE==32
+	if ( fsize > 1000 )
+		fprintf(stderr, "Using default fsize %ld MB\n", fsize = 1000);
+#endif
+
     while ((c =  getopt(argc, argv, "ahps:x:")) != -1)
     {
         switch(c)
@@ -249,8 +272,13 @@ int main(int argc,	    /* number of input parameters.		      */
 		map_flags = MAP_PRIVATE;

testcases/kernel/mem/mtest06/mmap2.c int main(int argc, /* number of input parameters. */ · line 281

Quoted 10 lines
testcases/kernel/mem/mtest06/mmap2.c +6 -1
 		break;
 	    case 's':
+#if __WORDSIZE==32
+		if ((fsize = atoi(optarg)) == 0 || (fsize = atoi(optarg)) > 1000 )
+		    fprintf(stderr, "Using default fsize %ld MB\n", fsize = 1000);
+#else
 		if ((fsize = atoi(optarg)) == 0)
-		    fprintf(stderr, "Using default fsize %d GB\n", fsize = 1);
+			fprintf(stderr,"Using default fsize %ld MB\n", fsize = 1000);
+#endif

Are you sure that it's a good idea to do this based on __WORDSIZE, there are 32 bit PC machines with plenty of gigabytes of RAM out there (my atom based netbook for example).

Quoted 41 lines
testcases/kernel/mem/mtest06/mmap2.c +5 -5
 		break;
             case 'x':
 		if ((exec_time = atof(optarg)) == 0)
@@ -266,7 +294,7 @@ int main(int argc,	    /* number of input parameters.		      */
 
     fprintf(stdout, "MM Stress test, map/write/unmap large file\n"
 		    "\tTest scheduled to run for:       %f\n"
-		    "\tSize of temp file in GB:         %d\n",
+		    "\tSize of temp file in MB:         %ld\n",
 			exec_time, fsize);
 
     /* set up time for which test has to be run */
@@ -308,7 +336,7 @@ int main(int argc,	    /* number of input parameters.		      */
 	    map_flags = map_flags|MAP_ANONYMOUS;
         }
 
-        if ((memptr = (char *)mmap(0,(fsize * GB), PROT_READ|PROT_WRITE,
+        if ((memptr = (char *)mmap(0,(fsize * MB), PROT_READ|PROT_WRITE,
 		     map_flags, fd, 0)) == (char *)-1)
         {
             perror("main(): mmap()");
@@ -319,16 +347,16 @@ int main(int argc,	    /* number of input parameters.		      */
 			    "changing file content to 'A'\n", memptr);
 
         /* Change the content of the file with A's, and commit changes */
-        memset(memptr, 'A', ((fsize * GB)/sizeof(char)));
+        memset(memptr, 'A', ((fsize * MB)/sizeof(char)));
 
-        if (msync(memptr, ((fsize * GB)/sizeof(char)),
+        if (msync(memptr, ((fsize * MB)/sizeof(char)),
 	                 MS_SYNC|MS_INVALIDATE) == -1)
         {
             perror("main(): msync()");
             exit (-1);
         }
 
-        if (munmap(memptr, (fsize * GB)/sizeof(char)) == -1)
+        if (munmap(memptr, (fsize * MB)/sizeof(char)) == -1)
         {
             perror("main(): munmap()");
             exit (-1);
Signature · 13 lines
Cyril Hrubis
[email protected]

------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list