Re: MIPS / targetOS strange behavior



tbroberg_nospam@xxxxxxxx wrote:
In this snippet from a semaphore post routine, sem->count is -1 before
execution and 0 after, but the wrong branch is taken about once a week
if it feels like it.

++sem->count;
lw v0, 20(s3) ; s3 contains a pointer to the semaphore
struct, offset 20 is the count within the semaphore
addiu v0, v0, 1 ; Increment count
sw v0, 20(s3) ; Write count out to semaphore structure

if ((savedSemCount = sem->count) <= 0)
lw v0, 20(s3) ; Load count v0 again (Why didn't the compiler
optimize this out?)
bgtz v0, *+212 ; Branch if semaphore count now positive

Is anybody aware of any cases where the processor itself might muck
this up and load the wrong v

Try disassembling the binary to check that the delay slot
between store/load is actually filled, and that there is
no (broken) reordering.

I assume sem->count is declared volatile, and this is why
you get an explicit reload for each reference.

Are you using gcc w/gas? Gas automatically fills delay slots,
and gcc got a bunch of delay slot changes in 4.0.1. Either
way, check the actual output, not just .s files produced by the
compiler.
.



Relevant Pages

  • Re: Threading low performance
    ... I effectly thought about the context-switching, ... First I create that semaphore with no jeton. ... BOOL bRelease = ReleaseSemaphore(hSemaphore, 1, ... // create the parameters struct ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Threading low performance
    ... I effectly thought about the context-switching, ... hyperthreading activated and setting thread affinity on the second ... First I create that semaphore with no jeton. ... // create the parameters struct ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Threading low performance
    ... adding threads to do the same work as a single thread decreases ... First I create that semaphore with no jeton. ... BOOL bRelease = ReleaseSemaphore(hSemaphore, 1, ... // create the parameters struct ...
    (microsoft.public.win32.programmer.kernel)
  • [PATCH] Replace completions with semaphores
    ... -static inline void init_completion ... +#define completion semaphore ... +struct semaphore; ...
    (Linux-Kernel)
  • [PATCH 12/12] Convert asm/semaphore.h users to linux/semaphore.h
    ... If you can't get a semaphore, ... struct jffs2_inode_info { ... sema_t structure just maps to struct semaphore in Linux kernel. ...
    (Linux-Kernel)