public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "olegendo at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/50457] SH2A atomic functions
Date: Mon, 24 Sep 2012 14:20:00 -0000	[thread overview]
Message-ID: <bug-50457-4-KKDte6REpw@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-50457-4@http.gcc.gnu.org/bugzilla/>


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50457

Oleg Endo <olegendo at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
   Last reconfirmed|                            |2012-09-24
                 CC|                            |kkojima at gcc dot gnu.org
         Resolution|INVALID                     |
     Ever Confirmed|0                           |1

--- Comment #3 from Oleg Endo <olegendo at gcc dot gnu.org> 2012-09-24 14:19:41 UTC ---
Uhm, I've been thinking .... 

In fact, the current atomic sequences (-msoft-atomic) are not compatible with
anything but SH3* and SH4*.  This is because everything < SH3 (including SH2A)
pushes SR and PC on the stack (R15) when an exception occurs, and for that the
stack pointer must always be valid.  The crashes mentioned in the original
description are caused by the invalid stack pointer.  I'm sorry for not
noticing this when replying/closing this PR prematurely.

I don't know how linux/glibc have been handling atomic ops on SH2 or SH2A, but
I've got an idea that would work in a bare-metal setup.

Instead of signaling the 'is in atomic sequence' condition through R15, it can
be signaled through a thread local variable.  For example a compare_and_swap
sequence might look like this:

        mov          #(0f-1f),r1       ! sequence length is held in R1
        mova        1f,r0
    .align 2
        mov.l        r0,@(#x,gbr)    ! enter atomic sequence by setting the
                                                ! exit point to the thread
local variable.
                                                ! #x is user defined through -m
option
0:
        mov.<bwl> @r1,%0
        mov            #0,r0
        cmp/eq       %0,%4
        bf                1f
        mov.<bwl> %3,@%1
1:     mov.l           r0,@(#x,gbr)    ! set thread local variable to nullptr,
                                                   ! which exits the atomic
sequence.

The check in the exception handling code for the 'is in atomic sequence'
would be:
  @(#x,gbr) != 0 && @(0,r15) < @(#x,gbr)

The atomic sequence rewind step in the exception handling code would be:
  @(0,r15) = @(#x,gbr) + r1

My assumption here is that gbr points to the execution context
housekeeping structure, which is also accessible from user space.  I've briefly
checked the code of glibc and this seems to be the case.

Problems will occur when the gbr is modified by user code (inline asm etc).
So user code should not modify the gbr, or at least do it in a controlled way.
But I think this issue can be ignored for now.

The execution context struct must be modified to hold the additional variable
for atomic sequences.

The thread library / kernel will need a modification (the kernel will need a
modification
on SH2(A) anyway), so that @(#x,gbr) is initialized to zero on thread creation.

Kaz, could you please provide some feedback on this idea?


  parent reply	other threads:[~2012-09-24 14:20 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-19 17:40 [Bug target/50457] New: " philip.stearns.andtr at gmail dot com
2012-02-26 23:19 ` [Bug target/50457] " olegendo at gcc dot gnu.org
2012-02-26 23:27 ` olegendo at gcc dot gnu.org
2012-09-24 14:20 ` olegendo at gcc dot gnu.org [this message]
2012-09-25  0:53 ` kkojima at gcc dot gnu.org
2012-09-25 10:54 ` olegendo at gcc dot gnu.org
2012-09-25 11:33 ` kkojima at gcc dot gnu.org
2012-10-01  8:34 ` olegendo at gcc dot gnu.org
2012-10-01 13:50 ` olegendo at gcc dot gnu.org
2012-10-01 23:30 ` kkojima at gcc dot gnu.org
2012-10-01 23:39 ` olegendo at gcc dot gnu.org
2012-10-02  0:55 ` olegendo at gcc dot gnu.org
2012-10-02  2:18 ` kkojima at gcc dot gnu.org
2012-10-02 10:58 ` olegendo at gcc dot gnu.org
2012-10-03 21:36 ` olegendo at gcc dot gnu.org
2012-10-08  0:21 ` olegendo at gcc dot gnu.org
2012-11-12 20:57 ` olegendo at gcc dot gnu.org
2015-09-21  1:54 ` olegendo at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-50457-4-KKDte6REpw@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).