Go to:
Gentoo Home
Documentation
Forums
Lists
Bugs
Planet
Store
Wiki
Get Gentoo!
Gentoo's Bugzilla – Attachment 13968 Details for
Bug 23649
sparc32(sun4m)-SMP, two threads simultaneously in '-lm' heavily => SegFault
Home
|
New
–
[Ex]
|
Browse
|
Search
|
Privacy Policy
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
The source of the segfault generator program.
spin.c (text/plain), 4.52 KB, created by
Ferris McCormick (RETIRED)
on 2003-06-28 11:11:13 UTC
(
hide
)
Description:
The source of the segfault generator program.
Filename:
MIME Type:
Creator:
Ferris McCormick (RETIRED)
Created:
2003-06-28 11:11:13 UTC
Size:
4.52 KB
patch
obsolete
>/* SegFault generator for SS20-SMP, kernel 2.4.21 > * Attachment for GenToo Bug #23649. > * > * > * compile with > * "gcc -O2 spin.c -o spin -lm -lpthread" > * execute: > * spin [number-of-threads [do-math?]] > * First parameter is the number of spawned threads, default = 1. > * Second parameter if present says that each thread should do a lot > * of "d=cos(d)" operations. > * > * On my sparc20-SMP, the call > * spin 2 M > * will always generate a SegFault very quickly. > * spin 1 M > * is OK > * spin {3|4|5..} M > * seem OK > * > * On my Ultra2-SMP, everything seems OK. > */ > >/* Spin in place, > * now and then showing progress. > */ >#include <stdio.h> >#include <pthread.h> >#include <math.h> >static int MATH = 0; /* non-zero to turn on the 'cos' calls */ > >/* Lock a mutex, report an error if impossible */ > >static inline int >LOCK(pthread_mutex_t* lock, int key) { > int stat; > stat = pthread_mutex_lock(lock); > if(stat) { > fprintf(stderr,"At %d, lock fails with stat=%d\n",key,stat); > } > return stat; >} > >/* Unlock a mutex, report an error if impossible */ > >static inline int >UNLOCK(pthread_mutex_t* lock, int key) { > int stat; > stat = pthread_mutex_unlock(lock); > if(stat) { > fprintf(stderr,"At %d, unlock fails with stat=%d\n",key,stat); > } > return stat; >} > >/* a Pthread parameter structure, mimicking a main entry. > * Here, we use -ac- to be the thread's identifier, > * and -av- is always a two element array of mutex pointers. > * The first mutex is the global synchronizer; > * The second mutex is local between the thread and main. > * assume at entry all threads are LOCK status. > */ > >struct parm { > int ac; > void** av; >} ; > >/* And, the thread > * with its potential cosine spin. > * N.B., the cos decision depends on the VALUE of > * a global variable, but the thread writes no global variables. > */ >void* >spinner(void* p) { /* p is a pointer to a parm, in which ac is parm, av[] is mutex* */ > int id; > int k; > int spin = 0; > int stat; > double d = 0.0; > pthread_mutex_t* lock[2]; > id = ((struct parm*)p) -> ac; > lock[0] = (pthread_mutex_t*) ( ((struct parm*)p) -> av[0]); > lock[1] = (pthread_mutex_t*) ( ((struct parm*)p) -> av[1]); > fprintf(stderr,"Entering spinner %d\n",id); > /* > * Forever loop > */ > for(k=100; k > 0; k += 100) { > stat = LOCK(lock[1],k+10+id); > stat += UNLOCK(lock[0],k+id); > spin++; > if((spin % (1000+id)) == id) fprintf(stderr,"spinner %d registering %d\n",id, spin); > if(stat) return (void*) stat; > if(MATH) { > for (stat = 0; stat < 500; stat++) d = cos(d); > } > } >} > >int >main(int argc, char** argv) { > struct parm* p; > int stat; > int thr_cnt; > int i, k; > pthread_mutex_t glob = PTHREAD_MUTEX_INITIALIZER; > pthread_mutex_t lock[20] = { PTHREAD_MUTEX_INITIALIZER, > PTHREAD_MUTEX_INITIALIZER > }; > pthread_t thr[2]; > > /* Figure out how many threads we want, and whether they should exercise > * the cosine function. > */ > > if(argc < 2) thr_cnt = 1; > else { > thr_cnt = (int) atoi(argv[1]); > if(thr_cnt < 1) thr_cnt = 1; > } > MATH = (argc > 2); > fprintf(stderr,"Spinning with %d threads %s\n",thr_cnt, > MATH ? "and 500 'd=cos(d);' per spinner" : "but no math overhead"); > stat = LOCK(&glob,-1); > > /* LOCK ALL mutexes, > * used later or not. > */ > > for (i=0; i < 20; ++i) { > stat += LOCK(&lock[i],-2); > } > if(stat) return stat; > > /* Start some spinners. */ > > for(i=0; i < thr_cnt; ++i) { > /* Allocate a unique parameter block for each thread */ > p = (struct parm*) malloc(sizeof(struct parm)); > if(p == NULL) { > fprintf(stderr,"Can't allocate parameter\n"); > return (-1); > } > > p -> ac = i+1; /* Thread ID */ > p -> av = (void**) calloc(2,sizeof(void*)); > if(p == NULL) { > fprintf(stderr,"Can't allocate thread pointers, %d\n", i); > return (-1); > } > /* Fill in the mutex addresses */ > (p->av)[0] = (void*) &glob; > (p->av)[1] = (void*) &(lock[i]); > stat = pthread_create(thr+i, NULL, spinner, (void*) p); > } > /* That's it. > * Now, just keep them in sync, and report progress every now > * and then. > */ > for(k=1; k > 0; k++) { > for(i=0; i < thr_cnt; ++i) { > stat = UNLOCK(&lock[i],k+k+i); > stat += LOCK(&glob,k+k); > if (stat) return stat; > } > if((k % 1000) == 0) fprintf(stderr,"Register main with k=%d\n", k); > } > return 0; /* NOT REACHED */ >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 23649
:
13968
|
14040