public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* mutex in frame code
@ 1999-01-25 14:44 Ulrich Drepper
  1999-01-26  5:06 ` Jeffrey A Law
  1999-01-31 23:58 ` Ulrich Drepper
  0 siblings, 2 replies; 70+ messages in thread
From: Ulrich Drepper @ 1999-01-25 14:44 UTC (permalink / raw)
  To: egcs; +Cc: drepper

We've recently adding to the frame installation functions in frame.c
code to protect the installation of the frame element to a global list
by an semaphore.  E.g., the __register_frame_info is

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void
__register_frame_info (void *begin, struct object *ob)
{
  ob->fde_begin = begin;

  ob->pc_begin = ob->pc_end = 0;
  ob->fde_array = 0;
  ob->count = 0;

  init_object_mutex_once ();
  __gthread_mutex_lock (&object_mutex);

  ob->next = objects;
  objects = ob;

  __gthread_mutex_unlock (&object_mutex);
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

There is a major flaw in this code.  It could use the thread functions
before the thread library is initialized.  E.g., a simple program
using pthreads could would use the libraries libpthread.so and
libc.so.  Due to the dependencies the C library is initialized first.
Part of the initialization is registration of a frame.  But now the C
library initialization will use the thread library though it is not
yet initialized.

This so far lead to no problems since in most thread implementations
the mutex functions do not need special initialization but others do.
In fact, I found this problem because the library I'm writing has this
problem.


Looking at the code one can see that the lock is used to insert into a
single-linked list.  This can be done safely without locks with an
compare & exchange instruction:

	do
	  {
	    struct object *last = objects;
	    ob->next = objects;
	  }
	while (compxchg (ob, last, ob) != 0);

with an appropriate compxchg function.  This function would be very
system-specific so Jason proposed to have a __builtin_cmpxchg function
and put the system specific bits into the .md files.


Now there is the problem that not all processors have such an opcode.
This is where the problems start.  E.g., the i386 processor has no
such opcode while i486 and up do.  I think this is the situation for
some other processor families as well.  Using the opcode nevertheless
would mean that there is not anymore full backward compatibility.
I.e., a gcc compiled for i486 will not work on i386 anymore.  I don't
think this is a problem personally.  We already have similar
restrictions (i686 code cannot be used on earlier processors) and i386
are also not anymore the commonly found platform.


One way to work around not having a compare & exchange opcode is using
spinlocks.  This works in most situations so at least one can assume
these processors still be supported.  The only situations where this
fails is with threads of different priority (priority inversion).


What I suggest is to add the __builtin_cmpxchg code.  It will be using
the asm opcode if allowed and fall back to a spinlock implementations
in the case where there is no such opcode.  If compiled without thread
support the opcode even compiles to no code at all.


Comments?

-- 
---------------.      drepper at gnu.org  ,-.   1325 Chesapeake Terrace
Ulrich Drepper  \    ,-------------------'   \  Sunnyvale, CA 94089 USA
Cygnus Solutions `--' drepper at cygnus.com   `------------------------

^ permalink raw reply	[flat|nested] 70+ messages in thread
* Re: mutex in frame code
@ 1999-01-26 13:20 Mike Stump
  1999-01-31 23:58 ` Mike Stump
  1999-02-01  7:38 ` Richard Earnshaw
  0 siblings, 2 replies; 70+ messages in thread
From: Mike Stump @ 1999-01-26 13:20 UTC (permalink / raw)
  To: jbuck, law; +Cc: drepper, egcs

> From: Joe Buck <jbuck@Synopsys.COM>
> To: law@cygnus.com
> Date: Tue, 26 Jan 99 9:54:36 PST

> But for i386, we have -mcpu=x -march=y, and -mcpu for Intel means
> the same as -mtune on Sparc!  -march is used to generate code that
> requires a particular processor.

This is unfortunate.  We need a command decision to bit the bullet and
then to make the ports conform to this decision and document it.
:-(  My guess is the SPARC port is wrong and should be fixed.

^ permalink raw reply	[flat|nested] 70+ messages in thread
* Re: mutex in frame code
@ 1999-02-02 10:24 Mike Stump
       [not found] ` < 199902021823.KAA13030@kankakee.wrs.com >
  1999-02-28 22:53 ` Mike Stump
  0 siblings, 2 replies; 70+ messages in thread
From: Mike Stump @ 1999-02-02 10:24 UTC (permalink / raw)
  To: dje; +Cc: egcs

> Date: Tue, 02 Feb 1999 13:04:20 -0500
> From: David Edelsohn <dje@watson.ibm.com>

> I am voting that we implement all three consistently across all
> ports.

David and I agree.  Does anyone disagree?  If so, why?  Specifically,
we are talking about changing the x86 and mips ports to fall in line
with _all_ the other ports, and that these three options be documented
machine independently (specific values of course will be machine
dependent).  Did I miss any ports?

-mcpu=486 I propose will be the same as -march=486 -mtune=486, I don't
believe it means that now, but I think it means -march=386 -mtune=486
currently.

^ permalink raw reply	[flat|nested] 70+ messages in thread

end of thread, other threads:[~1999-02-28 22:53 UTC | newest]

Thread overview: 70+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-01-25 14:44 mutex in frame code Ulrich Drepper
1999-01-26  5:06 ` Jeffrey A Law
1999-01-26  7:48   ` Ulrich Drepper
1999-01-31 23:58     ` Ulrich Drepper
1999-01-26  9:54   ` Joe Buck
1999-01-26  9:57     ` Jeffrey A Law
1999-01-26 10:23       ` Joe Buck
1999-01-26 10:27         ` David Edelsohn
1999-01-26 10:42           ` Joe Buck
1999-01-26 10:56             ` David Edelsohn
1999-01-26 11:28               ` Joe Buck
1999-01-26 11:44                 ` David Edelsohn
1999-01-31 23:58                   ` David Edelsohn
1999-01-31 23:58                 ` Joe Buck
1999-01-31 23:58               ` David Edelsohn
1999-01-26 11:02             ` Nick Ing-Simmons
1999-01-31 23:58               ` Nick Ing-Simmons
1999-01-31 23:58             ` Joe Buck
1999-01-31 23:58           ` David Edelsohn
1999-01-26 13:17         ` Gabriel Dos Reis
1999-01-31 23:58           ` Gabriel Dos Reis
1999-01-31 23:58         ` Joe Buck
     [not found]       ` <36AE692E.A5DD45E6@manhattanproject.com>
1999-01-26 17:27         ` gperf switch Clark Evans
1999-01-26 18:18           ` Alexandre Oliva
1999-01-26 19:57             ` Donn Terry
1999-01-31 23:58               ` Donn Terry
1999-01-31 23:58             ` Alexandre Oliva
1999-01-31 23:58           ` Clark Evans
1999-01-31 23:58       ` mutex in frame code Jeffrey A Law
1999-01-31 23:58     ` Joe Buck
1999-01-31 23:58   ` Jeffrey A Law
1999-01-31 23:58 ` Ulrich Drepper
1999-01-26 13:20 Mike Stump
1999-01-31 23:58 ` Mike Stump
1999-02-01  7:38 ` Richard Earnshaw
     [not found]   ` < 199902011536.PAA05753@sun52.NIS.cambridge >
1999-02-01  9:35     ` Richard Henderson
     [not found]       ` < 19990201093544.A18419@cygnus.com >
1999-02-01  9:53         ` David Edelsohn
     [not found]           ` < 9902011752.AA89026@marc.watson.ibm.com >
1999-02-01 10:07             ` Joe Buck
     [not found]               ` < 199902011806.KAA02061@atrus.synopsys.com >
1999-02-01 10:16                 ` David Edelsohn
     [not found]                   ` < 9902011816.AA33418@marc.watson.ibm.com >
1999-02-01 10:48                     ` Zack Weinberg
     [not found]                       ` < 199902011848.NAA27796@blastula.phys.columbia.edu >
1999-02-01 10:54                         ` David Edelsohn
     [not found]                           ` < 9902011854.AA89036@marc.watson.ibm.com >
1999-02-01 11:09                             ` Joe Buck
     [not found]                               ` < 199902011907.LAA05591@atrus.synopsys.com >
1999-02-01 11:25                                 ` David Edelsohn
1999-02-28 22:53                                   ` David Edelsohn
1999-02-28 22:53                               ` Joe Buck
1999-02-28 22:53                           ` David Edelsohn
1999-02-28 22:53                       ` Zack Weinberg
1999-02-01 10:54                     ` Joe Buck
1999-02-28 22:53                       ` Joe Buck
1999-02-01 23:00                     ` Matthias Urlichs
     [not found]                       ` < 19990202080023.B15962@noris.de >
1999-02-02 10:04                         ` David Edelsohn
1999-02-28 22:53                           ` David Edelsohn
1999-02-28 22:53                       ` Matthias Urlichs
1999-02-28 22:53                   ` David Edelsohn
1999-02-28 22:53               ` Joe Buck
1999-02-01 10:25             ` Zack Weinberg
     [not found]               ` < 199902011825.NAA27565@blastula.phys.columbia.edu >
1999-02-01 10:32                 ` David Edelsohn
1999-02-28 22:53                   ` David Edelsohn
1999-02-28 22:53               ` Zack Weinberg
1999-02-28 22:53           ` David Edelsohn
1999-02-01  9:54         ` Richard Earnshaw
1999-02-28 22:53           ` Richard Earnshaw
1999-02-28 22:53       ` Richard Henderson
1999-02-28 22:53   ` Richard Earnshaw
1999-02-02 10:24 Mike Stump
     [not found] ` < 199902021823.KAA13030@kankakee.wrs.com >
1999-02-02 12:40   ` Gavin Romig-Koch
     [not found]     ` < 14007.25134.285874.916089@cetus.cygnus.com >
1999-02-03  3:30       ` Richard Earnshaw
1999-02-28 22:53         ` Richard Earnshaw
1999-02-28 22:53     ` Gavin Romig-Koch
1999-02-28 22:53 ` Mike Stump

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).