Messages in this thread | | | Date | Tue, 30 Nov 1999 20:38:17 -0500 (EST) | From | "Richard B. Johnson" <> | Subject | Re: Shared memory not SMP safe to user-mode code |
| |
On Wed, 1 Dec 1999, Petr Vandrovec Ing. VTEI wrote:
> > typedef struct { > > unsigned int pad0; > > unsigned int pad1; > > unsigned int pad2; > > unsigned int i; > > unsigned int j; > > unsigned int spin; > You should mark at least 'spin' as volatile, otherwise bad optimization > can occur... > > static __inline__ unsigned int unique() > > { > > int ret; > > __asm__ __volatile__( "rdtsc\n" > > : "=eax" (ret) > > : /* No inputs */ > > : "eax", "edx" ); > > return ret; > And remove "eax" from list of used register to get it compile in gcc-2.95.2 > Parent: > > while(pars->spin) > > key = unique(); > > pars->spin += key; > > if(pars->spin != key) > > { > > } > > if(pars->i < pars->j) > > fprintf(stderr, "i = %08x, j = %08x\n", pars->i, pars->j); > > else > > fprintf(stderr, "Good\n"); > > pars->spin -= key; > > Son: > > while(pars->spin) > > key = unique(); > > pars->spin += key; > > pars->i++; > > pars->j++; > > pars->spin -= key; > > } > Look into code. Son is for any reason started first. While it does > > pars->spin -= key; > while (pars->spin) key = unique(); > pars->spin += key; > > Operations: read, sub, write, read, compare, read, add, write > So there is <-------------------------> > this window to switch to parent. But parent does > while (pars->spin) key = unique(); > and this includes 'rdtsc' which is not very fast (and without -O2 it does > also call/ret). If you add 'unique()' after 'pars->spin -= key;', it will > happilly print couple of 'Good' (after some time it will core dump). > Best regards, > Petr Vandrovec > vandrove@vc.cvut.cz > Compilation with -S -O2 show that no bad optimization is done. In fact, the code works perfectly once the flush() macro was added. If you core-dump and have the flush() macro, the problem is the missing "$" in:
"\tpushl $1f\n" |__ needs this.
Cheers, Dick Johnson
Penguin : Linux version 2.3.13 on an i686 machine (400.59 BogoMips). Warning : It's hard to remain at the trailing edge of technology.
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/
| |