Need a Atomic function for Mips 4000c - VxWorks

This is a discussion on Need a Atomic function for Mips 4000c - VxWorks ; Hi, I am working with Mips 4000c processor using vxWorks and i need a atomic function in it .ie the fuction should run fully at a time if it gets any interrupt, the fuction should starts again from the top. ...

+ Reply to Thread
Results 1 to 11 of 11

Thread: Need a Atomic function for Mips 4000c

  1. Need a Atomic function for Mips 4000c


    Hi,

    I am working with Mips 4000c processor using vxWorks and i
    need a atomic function in it .ie the fuction should run fully at a time
    if it gets any interrupt, the fuction should starts again from the top.
    In PowerPc processor there is an instruction "lwarx and stwcx". The
    lwarx reserve the address,If anybody modified it before it
    stores(stwcx) the reservervation will be failed and funtion will start
    execution from the top. I need such a function in Mips. Help me



    thank you

    Gomathi...


  2. Re: Need a Atomic function for Mips 4000c

    I guess you could try to call intLock() at the beginning of the
    function, and intUnlock() at the end of it. This will temporarily
    prevent interrupt to disturb your function.

    Or, you could try ll/sc (load-linked/store-conditional) instruction
    pair to achieve the goal. Refer mips r4k manual for more details.

    Gomathi 写道:

    > Hi,
    >
    > I am working with Mips 4000c processor using vxWorks and i
    > need a atomic function in it .ie the fuction should run fully at a time
    > if it gets any interrupt, the fuction should starts again from the top.
    > In PowerPc processor there is an instruction "lwarx and stwcx". The
    > lwarx reserve the address,If anybody modified it before it
    > stores(stwcx) the reservervation will be failed and funtion will start
    > execution from the top. I need such a function in Mips. Help me
    >
    >
    >
    > thank you
    >
    > Gomathi...



  3. Re: Need a Atomic function for Mips 4000c

    I tried ll/sc But it is not working well.
    sys:
    ll t0,(a0)
    add t0,t0,a1
    sc t0,(a0)
    beq t0,0,sys

    Just i need to add value of the pointer and the second value then i
    need to store it again to the same place. But it won't work properly. I
    think intLock and intUnlock is not a very good idea to use. It may
    affect some important interrupts.


  4. Re: Need a Atomic function for Mips 4000c

    Gomathi wrote:

    >I tried ll/sc But it is not working well.
    >sys:
    > ll t0,(a0)
    > add t0,t0,a1
    > sc t0,(a0)
    > beq t0,0,sys
    >
    >Just i need to add value of the pointer and the second value then i
    >need to store it again to the same place. But it won't work properly. I
    >think intLock and intUnlock is not a very good idea to use. It may
    >affect some important interrupts.


    Yes, locking interrupts will add to interrupt latency, but if your
    design cannot stand having interrupts locked for the time required
    to add a value to a pointer then you're likely going to have other
    severe problems. This is exactly the kind of thing for which intLock()
    and intUnlock() are intended.

    --
    ================================================== ======================
    Michael Kesti | "And like, one and one don't make
    | two, one and one make one."
    mrkesti at comcast dot net | - The Who, Bargain

  5. Re: Need a Atomic function for Mips 4000c

    Yes,You are right Michael. Now i am using that intLock and intUnlock.
    But i thought that ll and sc is better choice. But i don't know why it
    is not working. I think the problem is due to memory accesing.I read in
    book that When the data are not in the cache the SC will fail to stroe.
    How can i ensure that my data is always in the cache. I think this is
    the reason why the ll and sc is not working. Can any one say how to
    make sure that my data are in Cache.



    Gomathi...


  6. Re: Need a Atomic function for Mips 4000c

    Hi,
    I am sure that my data is in cache. So the problem is not due
    to memory accessing.


  7. Re: Need a Atomic function for Mips 4000c

    according to the manual, sc will only write the addressed location if
    there has been no competing access since the last ll, and, will leave a
    1/0 value in a register to indicate success or failure.

    so, if sc fails(0 left), it simply should be retried. Like this

    sys:
    ll t0,(a0)
    add t0,t0,a1
    sc t0,(a0)
    beq t0,0,sys

    Besides, I just wonder how did you know it isn't working.

    Gomathi 写道:

    > Yes,You are right Michael. Now i am using that intLock and intUnlock.
    > But i thought that ll and sc is better choice. But i don't know why it
    > is not working. I think the problem is due to memory accesing.I read in
    > book that When the data are not in the cache the SC will fail to stroe.
    > How can i ensure that my data is always in the cache. I think this is
    > the reason why the ll and sc is not working. Can any one say how to
    > make sure that my data are in Cache.
    >
    >
    >
    > Gomathi...



  8. Re: Need a Atomic function for Mips 4000c

    If it works well. I could find it very easily. This is the c code for
    similar program.

    void Atomic(UINT * a,int b)
    {
    *a=*a+b;
    }
    If i gets an interrupt and that interrupt may modify my address(address
    of a ) before i store the new value(*a+b), it'll surelly affect my
    sysetm. Got my point??. Thats why i need Atomic function.


  9. Re: Need a Atomic function for Mips 4000c

    Pls make sure your processor implements that instruction, because it's
    an optional part according to MIPS specification

    Gomathi 写道:

    > If it works well. I could find it very easily. This is the c code for
    > similar program.
    >
    > void Atomic(UINT * a,int b)
    > {
    > *a=*a+b;
    > }
    > If i gets an interrupt and that interrupt may modify my address(address
    > of a ) before i store the new value(*a+b), it'll surelly affect my
    > sysetm. Got my point??. Thats why i need Atomic function.



  10. Re: Need a Atomic function for Mips 4000c

    It's working. Because in some places it is some output. My question is
    why it could't work well.I am getting same out ,what i get in that c
    code.So it is working .But working good.. That's the problem


    Gomathi..........


  11. Re: Need a Atomic function for Mips 4000c

    It's working. Because in some places it is giving some output. My
    question is
    why it could't work well . I am getting same output ,what i get in
    that c
    code.So it is working .But not working good.. That's the problem

    Gomathi..........


+ Reply to Thread