Skip to contentSkip to conversation

pthread_cond_brodcast/1-2.c hung when mem left is not enough

PATCH Superseded DAN LI 2 participants 2 messages Oct 12, 2012

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

DAN LI

author
#0 lore raw

PATCH v5 1/1 pthread_cond_brodcast/1-2.c hung when mem left is not enough

pthread_cond_brodcast/1-2.c try to create as many childrens(thread or process) as possible,however,if current free memory is exhausted before all childrens are started,the case will timeout and hung since it's stated with program "t0".

---
 .../interfaces/pthread_cond_broadcast/1-2.c        | 40 +++++++++++++++++++---
 testcases/open_posix_testsuite/include/mem_info.h  | 40 ++++++++++++++++++++++
 2 files changed, 76 insertions(+), 4 deletions(-)
 create mode 100644 testcases/open_posix_testsuite/include/mem_info.h
(quoted diff) +0 -0

b/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_broadcast/1-2.c index f6ad9df..6b27f40 100644

testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_broadcast/1-2.c +36 -4
@@ -49,6 +49,7 @@
 #include <sys/wait.h>
 #include <semaphore.h>
 
+#include "mem_info.h"
 #include "../testfrmw/testfrmw.h"
 #include "../testfrmw/testfrmw.c"
 
@@ -82,8 +83,8 @@
 #endif
 
 /* Do not create more than this amount of children: */
-#define MAX_PROCESS_CHILDREN  (200)
-#define MAX_THREAD_CHILDREN   (1000)
+static int max_process_children  = 200;
+static int max_thread_children = 1000;
 
 #define TIMEOUT  (180)
 
@@ -243,6 +244,35 @@ void *timer(void *arg)
 	return NULL; /* For compiler */
 }
 
+static void children_number(void)
+{
+	struct sysinfo sysinformation;
+	int avail_number;
+	unsigned long freeram;
+	unsigned long per_process;
+	unsigned long min_stack;
+
+	min_stack = sysconf(_SC_THREAD_STACK_MIN);
+
+	freeram = getfreeram();
+	if (freeram == 0)
+		return;
+
+	per_process = min_stack * max_thread_children;
+	if (per_process > freeram)
+		UNTESTED("Not enough memory.");
+
+	avail_number = freeram / per_process;
+
+	if (avail_number < 10)
+		UNTESTED("Not enough memory.");
+
+	max_process_children = (avail_number < max_process_children ?
+					avail_number : max_process_children);
+
+	return;
+}
+
 int main(int argc, char *argv[])
 {
 	int ret;
@@ -268,6 +298,8 @@ int main(int argc, char *argv[])
 
 	output_init();
 
+	children_number();
+
 	/* check the system abilities */
 	pshared = sysconf(_SC_THREAD_PROCESS_SHARED);
 	cs = sysconf(_SC_CLOCK_SELECTION);
@@ -476,7 +508,7 @@ int main(int argc, char *argv[])
 				} else {
 					ret = errno;
 				}
-			} while ((ret == 0) && (child_count < MAX_THREAD_CHILDREN));
+			} while ((ret == 0) && (child_count < max_thread_children));
 			#if VERBOSE > 2
 			output("[parent] Created %i children threads\n", child_count);
 			#endif
@@ -504,7 +536,7 @@ int main(int argc, char *argv[])
 				} else {
 					ret = errno;
 				}
-			} while ((ret == 0) && (child_count < MAX_PROCESS_CHILDREN));
+			} while ((ret == 0) && (child_count < max_process_children));
 			#if VERBOSE > 2
 			output("[parent] Created %i children processes\n", child_count);
 			#endif
testcases/open_posix_testsuite/include/mem_info.h new file +40 -0
new file mode 100644
index 0000000..1669216
@@ -0,0 +1,40 @@
+/*
+ *
+ *   Copyright (c) 2012, DAN LI
+ *
+ *   This program is free software;  you can redistribute it and/or modify
+ *   it under the terms in version 2 of the GNU General Public License as
+ *   published by the Free Software Foundation.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ *   the GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program;  if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ *   Author:  DAN LI <li.dan AT cn fujitsu com>
+ *   Date:    10/12/2012
+ */
+
+#ifdef __linux__
+#include <sys/sysinfo.h>
+
+static int getfreeram(void)
+{
+	int ret;
+	struct sysinfo sysinformation;
+
+	ret = sysinfo(&sysinformation);
+	if (ret != 0)
+		return 0;
+	return sysinformation.freeram;
+}
+#else
+static int getfreeram(void)
+{
+	return 0;
+}
+#endif
Signature · 12 lines
1.7.12

------------------------------------------------------------------------------
Don't let slow site performance ruin your business. Deploy New Relic APM
Deploy New Relic app performance management and know exactly
what is happening inside your Ruby, Python, PHP, Java, and .NET app
Try New Relic at no cost today and get our sweet Data Nerd shirt too!
http://p.sf.net/sfu/newrelic-dev2dev
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#1 lore raw
Quoted 4 lines · DAN LI

pthread_cond_brodcast/1-2.c try to create as many childrens(thread or process) as possible,however,if current free memory is exhausted before all childrens are started,the case will timeout and hung since it's stated with program "t0".

You should make patch against the newest ltp tree.

Thanks,
Wanlong Gao

Quoted 132 lines
---
 .../interfaces/pthread_cond_broadcast/1-2.c        | 40 +++++++++++++++++++---
 testcases/open_posix_testsuite/include/mem_info.h  | 40 ++++++++++++++++++++++
 2 files changed, 76 insertions(+), 4 deletions(-)
 create mode 100644 testcases/open_posix_testsuite/include/mem_info.h
testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_broadcast/1-2.c +36 -4
index f6ad9df..6b27f40 100644
@@ -49,6 +49,7 @@
 #include <sys/wait.h>
 #include <semaphore.h>
 
+#include "mem_info.h"
 #include "../testfrmw/testfrmw.h"
 #include "../testfrmw/testfrmw.c"
 
@@ -82,8 +83,8 @@
 #endif
 
 /* Do not create more than this amount of children: */
-#define MAX_PROCESS_CHILDREN  (200)
-#define MAX_THREAD_CHILDREN   (1000)
+static int max_process_children  = 200;
+static int max_thread_children = 1000;
 
 #define TIMEOUT  (180)
 
@@ -243,6 +244,35 @@ void *timer(void *arg)
 	return NULL; /* For compiler */
 }
 
+static void children_number(void)
+{
+	struct sysinfo sysinformation;
+	int avail_number;
+	unsigned long freeram;
+	unsigned long per_process;
+	unsigned long min_stack;
+
+	min_stack = sysconf(_SC_THREAD_STACK_MIN);
+
+	freeram = getfreeram();
+	if (freeram == 0)
+		return;
+
+	per_process = min_stack * max_thread_children;
+	if (per_process > freeram)
+		UNTESTED("Not enough memory.");
+
+	avail_number = freeram / per_process;
+
+	if (avail_number < 10)
+		UNTESTED("Not enough memory.");
+
+	max_process_children = (avail_number < max_process_children ?
+					avail_number : max_process_children);
+
+	return;
+}
+
 int main(int argc, char *argv[])
 {
 	int ret;
@@ -268,6 +298,8 @@ int main(int argc, char *argv[])
 
 	output_init();
 
+	children_number();
+
 	/* check the system abilities */
 	pshared = sysconf(_SC_THREAD_PROCESS_SHARED);
 	cs = sysconf(_SC_CLOCK_SELECTION);
@@ -476,7 +508,7 @@ int main(int argc, char *argv[])
 				} else {
 					ret = errno;
 				}
-			} while ((ret == 0) && (child_count < MAX_THREAD_CHILDREN));
+			} while ((ret == 0) && (child_count < max_thread_children));
 			#if VERBOSE > 2
 			output("[parent] Created %i children threads\n", child_count);
 			#endif
@@ -504,7 +536,7 @@ int main(int argc, char *argv[])
 				} else {
 					ret = errno;
 				}
-			} while ((ret == 0) && (child_count < MAX_PROCESS_CHILDREN));
+			} while ((ret == 0) && (child_count < max_process_children));
 			#if VERBOSE > 2
 			output("[parent] Created %i children processes\n", child_count);
 			#endif
testcases/open_posix_testsuite/include/mem_info.h new file +30 -0
new file mode 100644
index 0000000..1669216
@@ -0,0 +1,40 @@
+/*
+ *
+ *   Copyright (c) 2012, DAN LI
+ *
+ *   This program is free software;  you can redistribute it and/or modify
+ *   it under the terms in version 2 of the GNU General Public License as
+ *   published by the Free Software Foundation.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ *   the GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program;  if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ *   Author:  DAN LI <li.dan AT cn fujitsu com>
+ *   Date:    10/12/2012
+ */
+
+#ifdef __linux__
+#include <sys/sysinfo.h>
+
+static int getfreeram(void)
+{
+	int ret;
+	struct sysinfo sysinformation;
+
+	ret = sysinfo(&sysinformation);

testcases/open_posix_testsuite/include/mem_info.h line 40

Quoted 10 lines
testcases/open_posix_testsuite/include/mem_info.h new file +10 -0
+	if (ret != 0)
+		return 0;
+	return sysinformation.freeram;
+}
+#else
+static int getfreeram(void)
+{
+	return 0;
+}
+#endif

------------------------------------------------------------------------------
Don't let slow site performance ruin your business. Deploy New Relic APM Deploy New Relic app performance management and know exactly what is happening inside your Ruby, Python, PHP, Java, and .NET app Try New Relic at no cost today and get our sweet Data Nerd shirt too!
http://p.sf.net/sfu/newrelic-dev2dev
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list