* [LTP] [PATCH] Avoid compiler optimisation of malloc calls
@ 2012-10-16 14:17 Chris Dearman
2012-10-17 16:04 ` chrubis
2012-10-17 17:35 ` Chris Dearman
0 siblings, 2 replies; 4+ messages in thread
From: Chris Dearman @ 2012-10-16 14:17 UTC (permalink / raw)
To: ltp-list; +Cc: Chris Dearman
clang understands the malloc library call and can optimise calls to
it. In particular it will avoid calling malloc completely if it
detects that the result is not used.
Signed-off-by: Chris Dearman <chris@mips.com>
---
.../conformance/interfaces/pthread_cond_init/4-1.c | 19
++++++++++++-------
1 files changed, 12 insertions(+), 7 deletions(-)
diff --git
a/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_init/4-1.c
b/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_init/4-1.c
index 287fda1..7932ec2 100644
---
a/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_init/4-1.c
+++
b/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_init/4-1.c
@@ -50,7 +50,7 @@
#define ERR_MSG(f, rc) printf("Failed: func: %s rc: %s (%u)\n", \
f, strerror(rc), rc);
-/* Max memory for child is 81B */
+/* Max memory for child is 1MB */
#define MAX_MEM ((1<<20))
/*
@@ -59,8 +59,8 @@
*/
static void child(void)
{
- char *curr;
- char *prev = NULL;
+ void *curr;
+ void *prev = NULL;
struct rlimit rl;
pthread_cond_t cond;
pthread_condattr_t attr;
@@ -76,10 +76,15 @@ static void child(void)
exit(PTS_UNRESOLVED);
}
- /* Consume all memory we can */
- do {
- curr = malloc(1);
- } while (curr);
+ /*
+ * Consume all memory we can
+ * It's important to use the malloc() return value in a
+ * meaningful way to bypass potential compiler optimisations.
+ */
+ while ((curr = malloc(sizeof(void *)))) {
+ *(void **)curr = prev;
+ prev = curr;
+ }
if (errno != ENOMEM) {
ERR_MSG("malloc()", errno);
exit(PTS_UNRESOLVED);
--
1.7.1
------------------------------------------------------------------------------
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] 4+ messages in thread
* Re: [LTP] [PATCH] Avoid compiler optimisation of malloc calls
2012-10-16 14:17 [LTP] [PATCH] Avoid compiler optimisation of malloc calls Chris Dearman
@ 2012-10-17 16:04 ` chrubis
2012-10-17 17:35 ` Chris Dearman
1 sibling, 0 replies; 4+ messages in thread
From: chrubis @ 2012-10-17 16:04 UTC (permalink / raw)
To: Chris Dearman; +Cc: ltp-list
Hi!
> clang understands the malloc library call and can optimise calls to
> it. In particular it will avoid calling malloc completely if it
> detects that the result is not used.
Both patches are okay, but seems to be corrupted (git am wasn't able to
understand them).
Could you send these again (possibly with git send-email) or send a pull
request from repo forked on github or anything else that would work?
--
Cyril Hrubis
chrubis@suse.cz
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_sfd2d_oct
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 4+ messages in thread
* [LTP] [PATCH] Avoid compiler optimisation of malloc calls
2012-10-16 14:17 [LTP] [PATCH] Avoid compiler optimisation of malloc calls Chris Dearman
2012-10-17 16:04 ` chrubis
@ 2012-10-17 17:35 ` Chris Dearman
2012-10-18 1:36 ` Wanlong Gao
1 sibling, 1 reply; 4+ messages in thread
From: Chris Dearman @ 2012-10-17 17:35 UTC (permalink / raw)
To: ltp-list
[-- Attachment #1: Type: text/plain, Size: 349 bytes --]
clang understands the malloc library call and can optimise calls to
it. In particular it will avoid calling malloc completely if it
detects that the result is not used.
Signed-off-by: Chris Dearman <chris@mips.com>
---
.../conformance/interfaces/pthread_cond_init/4-1.c | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)
[-- Attachment #2: avoid-compiler-optimisation-of.patch --]
[-- Type: text/plain, Size: 1266 bytes --]
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_init/4-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_init/4-1.c
index 287fda1..06accd6 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_init/4-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_init/4-1.c
@@ -50,7 +50,7 @@
#define ERR_MSG(f, rc) printf("Failed: func: %s rc: %s (%u)\n", \
f, strerror(rc), rc);
-/* Max memory for child is 81B */
+/* Max memory for child is 1MB */
#define MAX_MEM ((1<<20))
/*
@@ -59,8 +59,8 @@
*/
static void child(void)
{
- char *curr;
- char *prev = NULL;
+ void *curr;
+ void *prev = NULL;
struct rlimit rl;
pthread_cond_t cond;
pthread_condattr_t attr;
@@ -76,10 +76,15 @@ static void child(void)
exit(PTS_UNRESOLVED);
}
- /* Consume all memory we can */
- do {
- curr = malloc(1);
- } while (curr);
+ /*
+ * Consume all memory we can
+ * It's importamt to use the malloc() return value in a
+ * meaningful way to bypass potential compiler optimisations.
+ */
+ while ((curr = malloc(sizeof(void *)))) {
+ *(void **)curr = prev;
+ prev = curr;
+ }
if (errno != ENOMEM) {
ERR_MSG("malloc()", errno);
exit(PTS_UNRESOLVED);
[-- Attachment #3: Type: text/plain, Size: 240 bytes --]
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_sfd2d_oct
[-- Attachment #4: Type: text/plain, Size: 155 bytes --]
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [LTP] [PATCH] Avoid compiler optimisation of malloc calls
2012-10-17 17:35 ` Chris Dearman
@ 2012-10-18 1:36 ` Wanlong Gao
0 siblings, 0 replies; 4+ messages in thread
From: Wanlong Gao @ 2012-10-18 1:36 UTC (permalink / raw)
To: Chris Dearman; +Cc: ltp-list
On 10/18/2012 01:35 AM, Chris Dearman wrote:
> clang understands the malloc library call and can optimise calls to
> it. In particular it will avoid calling malloc completely if it
> detects that the result is not used.
>
> Signed-off-by: Chris Dearman <chris@mips.com>
Pushed with Cyril's Ack, thank you.
Wanlong Gao
> ---
> .../conformance/interfaces/pthread_cond_init/4-1.c | 19 ++++++++++++-------
> 1 file changed, 12 insertions(+), 7 deletions(-)
>
>
>
> ------------------------------------------------------------------------------
> Everyone hates slow websites. So do we.
> Make your web apps faster with AppDynamics
> Download AppDynamics Lite for free today:
> http://p.sf.net/sfu/appdyn_sfd2d_oct
>
>
>
> _______________________________________________
> Ltp-list mailing list
> Ltp-list@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/ltp-list
>
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_sfd2d_oct
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-10-18 1:38 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-16 14:17 [LTP] [PATCH] Avoid compiler optimisation of malloc calls Chris Dearman
2012-10-17 16:04 ` chrubis
2012-10-17 17:35 ` Chris Dearman
2012-10-18 1:36 ` Wanlong Gao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox