|
From: Alexander P. <gl...@go...> - 2010-02-19 15:55:44
|
Hi everyone,
I'm getting strange assertion failures running the following test
under Nullgrind on Mac OS 10.5:
=====================================
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <signal.h>
#include <libkern/OSAtomic.h>
#include <pthread.h>
OSSpinLock sl(OS_SPINLOCK_INIT);
typedef void *(*worker_t)(void*);
typedef void (*Sigaction)(int, siginfo_t *, void *);
int GLOB=0;
static void EnableSigprof(Sigaction SignalHandler) {
struct sigaction sa;
sa.sa_sigaction = SignalHandler;
sa.sa_flags = SA_RESTART | SA_SIGINFO;
sigemptyset(&sa.sa_mask);
if (sigaction(SIGPROF, &sa, NULL) != 0) {
perror("sigaction");
abort();
}
struct itimerval timer;
timer.it_interval.tv_sec = 0;
timer.it_interval.tv_usec = 1000000 / 10000;
timer.it_value = timer.it_interval;
if (setitimer(ITIMER_PROF, &timer, 0) != 0) {
perror("setitimer");
abort();
}
}
void Worker() {
for (long int i = 0; i < 100000000; i++) {
void *x = malloc((i % 64) + 1);
free (x);
}
}
void SignalHandlerWithSpinlock(int, siginfo_t*, void*) {
OSSpinLockLock(&sl);
GLOB++;
OSSpinLockUnlock(&sl);
}
int main() {
EnableSigprof(SignalHandlerWithSpinlock);
pthread_t w_1;
pthread_t w_2;
pthread_create(&w_1, NULL, worker_t(Worker), NULL);
pthread_create(&w_2, NULL, worker_t(Worker), NULL);
pthread_join(w_1, NULL);
pthread_join(w_2, NULL);
printf("\tGLOB=%d\n", GLOB);
return 0;
}
=========================================
$ g++ bad_sigprof.cc -o bad_sigprof
$ valgrind --tool=none ./bad_sigprof
...
valgrind: m_syswrap/syswrap-main.c:1314 (vgPlain_client_syscall):
Assertion 'sci->status.what == SsIdle' failed.
==5469== at 0xF00864ED: ???
==5469== by 0xF00867A1: ???
==5469== by 0xF00E5C56: ???
==5469== by 0xF00E10A3: ???
==5469== by 0xF00E21F9: ???
==5469== by 0xF010893F: ???
sched status:
running_tid=1
Thread 1: status = VgTs_Runnable
==5469== at 0xF009DF2A: ???
==5469== by 0x1F7AC2: cerror (in /usr/lib/libSystem.B.dylib)
==5469== by 0x1F15: main (in ./bad_sigprof)
Thread 2: status = VgTs_Yielding
==5469== at 0x1F8035: malloc (in /usr/lib/libSystem.B.dylib)
==5469== by 0x228154: _pthread_start (in /usr/lib/libSystem.B.dylib)
==5469== by 0x228011: thread_start (in /usr/lib/libSystem.B.dylib)
Thread 3: status = VgTs_Yielding
==5469== at 0xFFFF0260: ???
==5469== by 0x1FD38C: free (in /usr/lib/libSystem.B.dylib)
==5469== by 0x1DDE: Worker() (in ./bad_sigprof)
==5469== by 0x228154: _pthread_start (in /usr/lib/libSystem.B.dylib)
==5469== by 0x228011: thread_start (in /usr/lib/libSystem.B.dylib)
Is there something wrong with the test or it's an error?
NB: ThreadSanitizer (code.google.com/p/data-race-test) consumes very
much memory on a similar test. Could it be due to repeated translation
of the signal handler?
Thanks,
Alexander Potapenko
Software Engineer
Google Moscow
|
|
From: Alexander P. <gl...@go...> - 2010-02-24 17:09:58
|
Created a bug report: https://bugs.kde.org/show_bug.cgi?id=228343 On Fri, Feb 19, 2010 at 6:55 PM, Alexander Potapenko <gl...@go...> wrote: > Hi everyone, > > I'm getting strange assertion failures running the following test > under Nullgrind on Mac OS 10.5: > > ===================================== > #include <stdio.h> > #include <stdlib.h> > #include <sys/time.h> > #include <signal.h> > #include <libkern/OSAtomic.h> > #include <pthread.h> > > OSSpinLock sl(OS_SPINLOCK_INIT); > typedef void *(*worker_t)(void*); > typedef void (*Sigaction)(int, siginfo_t *, void *); > > int GLOB=0; > > static void EnableSigprof(Sigaction SignalHandler) { > struct sigaction sa; > sa.sa_sigaction = SignalHandler; > sa.sa_flags = SA_RESTART | SA_SIGINFO; > sigemptyset(&sa.sa_mask); > if (sigaction(SIGPROF, &sa, NULL) != 0) { > perror("sigaction"); > abort(); > } > struct itimerval timer; > timer.it_interval.tv_sec = 0; > timer.it_interval.tv_usec = 1000000 / 10000; > timer.it_value = timer.it_interval; > if (setitimer(ITIMER_PROF, &timer, 0) != 0) { > perror("setitimer"); > abort(); > } > } > > void Worker() { > for (long int i = 0; i < 100000000; i++) { > void *x = malloc((i % 64) + 1); > free (x); > } > } > > void SignalHandlerWithSpinlock(int, siginfo_t*, void*) { > OSSpinLockLock(&sl); > GLOB++; > OSSpinLockUnlock(&sl); > } > > int main() { > EnableSigprof(SignalHandlerWithSpinlock); > pthread_t w_1; > pthread_t w_2; > pthread_create(&w_1, NULL, worker_t(Worker), NULL); > pthread_create(&w_2, NULL, worker_t(Worker), NULL); > pthread_join(w_1, NULL); > pthread_join(w_2, NULL); > printf("\tGLOB=%d\n", GLOB); > return 0; > } > ========================================= > > $ g++ bad_sigprof.cc -o bad_sigprof > $ valgrind --tool=none ./bad_sigprof > ... > valgrind: m_syswrap/syswrap-main.c:1314 (vgPlain_client_syscall): > Assertion 'sci->status.what == SsIdle' failed. > ==5469== at 0xF00864ED: ??? > ==5469== by 0xF00867A1: ??? > ==5469== by 0xF00E5C56: ??? > ==5469== by 0xF00E10A3: ??? > ==5469== by 0xF00E21F9: ??? > ==5469== by 0xF010893F: ??? > > sched status: > running_tid=1 > > Thread 1: status = VgTs_Runnable > ==5469== at 0xF009DF2A: ??? > ==5469== by 0x1F7AC2: cerror (in /usr/lib/libSystem.B.dylib) > ==5469== by 0x1F15: main (in ./bad_sigprof) > > Thread 2: status = VgTs_Yielding > ==5469== at 0x1F8035: malloc (in /usr/lib/libSystem.B.dylib) > ==5469== by 0x228154: _pthread_start (in /usr/lib/libSystem.B.dylib) > ==5469== by 0x228011: thread_start (in /usr/lib/libSystem.B.dylib) > > Thread 3: status = VgTs_Yielding > ==5469== at 0xFFFF0260: ??? > ==5469== by 0x1FD38C: free (in /usr/lib/libSystem.B.dylib) > ==5469== by 0x1DDE: Worker() (in ./bad_sigprof) > ==5469== by 0x228154: _pthread_start (in /usr/lib/libSystem.B.dylib) > ==5469== by 0x228011: thread_start (in /usr/lib/libSystem.B.dylib) > > > Is there something wrong with the test or it's an error? > NB: ThreadSanitizer (code.google.com/p/data-race-test) consumes very > much memory on a similar test. Could it be due to repeated translation > of the signal handler? > > Thanks, > Alexander Potapenko > Software Engineer > Google Moscow > -- Alexander Potapenko Software Engineer Google Moscow |