* [LTP] [PATCH v6] pthread_cond_brodcast/1-2.c hung when mem left is not enough
@ 2012-10-12 8:13 DAN LI
2012-10-15 15:21 ` chrubis
0 siblings, 1 reply; 2+ messages in thread
From: DAN LI @ 2012-10-12 8:13 UTC (permalink / raw)
To: LTP list
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".
Signed-off-by: DAN LI <li.dan@cn.fujitsu.com>
---
.../interfaces/pthread_cond_broadcast/1-2.c | 16 +++------
testcases/open_posix_testsuite/include/mem_info.h | 40 ++++++++++++++++++++++
2 files changed, 45 insertions(+), 11 deletions(-)
create mode 100644 testcases/open_posix_testsuite/include/mem_info.h
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_broadcast/1-2.c
b/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_broadcast/1-2.c
index b59bbfc..df93f4b 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_broadcast/1-2.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_broadcast/1-2.c
@@ -50,6 +50,7 @@
#include <semaphore.h>
#include <sys/sysinfo.h>
+#include <mem_info.h>
#include "../testfrmw/testfrmw.h"
#include "../testfrmw/testfrmw.c"
@@ -244,20 +245,19 @@ void *timer(void *arg)
return NULL; /* For compiler */
}
-#ifdef __linux__
static void children_number(void)
{
struct sysinfo sysinformation;
- int ret;
int avail_number;
+ unsigned long freeram;
unsigned long per_process;
unsigned long min_stack;
min_stack = sysconf(_SC_THREAD_STACK_MIN);
- ret = sysinfo(&sysinformation);
- if (ret != 0)
- UNRESOLVED(ret, "Failed to get system information.");
+ freeram = getfreeram();
+ if (freeram == 0)
+ return;
per_process = min_stack * max_thread_children;
if (per_process > sysinformation.freeram)
@@ -273,12 +273,6 @@ static void children_number(void)
return;
}
-#else
-static void children_number(void)
-{
- return;
-}
-#endif
int main(int argc, char *argv[])
{
diff --git a/testcases/open_posix_testsuite/include/mem_info.h b/testcases/open_posix_testsuite/include/mem_info.h
new file mode 100644
index 0000000..1669216
--- /dev/null
+++ b/testcases/open_posix_testsuite/include/mem_info.h
@@ -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
--
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
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [LTP] [PATCH v6] pthread_cond_brodcast/1-2.c hung when mem left is not enough
2012-10-12 8:13 [LTP] [PATCH v6] pthread_cond_brodcast/1-2.c hung when mem left is not enough DAN LI
@ 2012-10-15 15:21 ` chrubis
0 siblings, 0 replies; 2+ messages in thread
From: chrubis @ 2012-10-15 15:21 UTC (permalink / raw)
To: DAN LI; +Cc: LTP list
Hi!
> +#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
I think that there is still the same problem as in the first version.
Are you sure that sysinfo.freeram is reasonable number? Because as far
as I understand it this nuber shows amount of ram that is not used
currently. So when you run the test inside of LTP testsuite the number
may be quite low as there may be a lot of data cached in the buffers
because buffers are flushed only when there is memory pressure.
I've checked docs for both fork() and pthread_create() and both of them
shall indicate that there are no resources to create process/thread by
setting errno to EAGAIN (fork() may additionally return ENOMEM too). So
we could create processes until counter is reached or we got ENOMEM
which should be 100% portable.
--
Cyril Hrubis
chrubis@suse.cz
------------------------------------------------------------------------------
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
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-10-15 15:23 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-12 8:13 [LTP] [PATCH v6] pthread_cond_brodcast/1-2.c hung when mem left is not enough DAN LI
2012-10-15 15:21 ` chrubis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox