public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Use set_thread_area syscall for threading
@ 2002-08-01 15:48 Jakub Jelinek
  2002-08-01 18:25 ` Ulrich Drepper
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2002-08-01 15:48 UTC (permalink / raw)
  To: Ulrich Drepper; +Cc: Glibc hackers

Hi!

I gave this some more testing yesterday and it seems to work just fine.

2002-08-02  Jakub Jelinek  <jakub@redhat.com>

	* sysdeps/unix/sysv/linux/kernel-features.h
	(__ASSUME_SET_THREAD_AREA_SYSCALL): Define.

	* sysdeps/i386/useldt.h (DO_MODIFY_LDT): Move from INIT_THREAD_SELF.
	(INIT_THREAD_SELF): Use sys_thread_area syscall instead if available.
	(FREE_THREAD): Avoid modify_ldt if using GDT.
	* sysdeps/i386/pspinlock.c (__have_no_set_thread_area): New.

--- libc/linuxthreads/sysdeps/i386/useldt.h.jj	2002-07-29 15:14:52.000000000 +0200
+++ libc/linuxthreads/sysdeps/i386/useldt.h	2002-07-29 17:58:04.000000000 +0200
@@ -22,6 +22,7 @@
 #ifndef __ASSEMBLER__
 #include <stddef.h>	/* For offsetof.  */
 #include <stdlib.h>	/* For abort().  */
+#include <sysdep.h>	/* For INLINE_SYSCALL.  */
 
 
 /* We don't want to include the kernel header.  So duplicate the
@@ -61,24 +62,74 @@ extern int __modify_ldt (int, struct mod
   __self;								      \
 })
 
-/* Initialize the thread-unique value.  */
-#define INIT_THREAD_SELF(descr, nr) \
-{									      \
+#define DO_MODIFY_LDT(descr, nr) \
+({									      \
   struct modify_ldt_ldt_s ldt_entry =					      \
     { nr, (unsigned long int) descr, sizeof (struct _pthread_descr_struct),   \
       1, 0, 0, 0, 0, 1, 0 };						      \
   if (__modify_ldt (1, &ldt_entry, sizeof (ldt_entry)) != 0)		      \
     abort ();								      \
-  __asm__ __volatile__ ("movw %w0, %%gs" : : "q" (nr * 8 + 7));		      \
+  nr * 8 + 7;								      \
+})
+
+/* Initialize the thread-unique value.  */
+#ifdef __ASSUME_SET_THREAD_AREA_SYSCALL
+#define INIT_THREAD_SELF(descr, nr) \
+{									      \
+  int __gs = INLINE_SYSCALL (set_thread_area, 2, descr, 1);		      \
+  if (__gs == -1)							      \
+    abort ();								      \
+  __asm__ __volatile__ ("movw %w0, %%gs" : : "q" (__gs));		      \
 }
+#elif defined __NR_set_thread_area
+
+/* Defined in pspinlock.c.  */
+extern int __have_no_set_thread_area;
+
+#define INIT_THREAD_SELF(descr, nr) \
+{									      \
+  int __gs = -1;							      \
+  if (! __builtin_expect (__have_no_set_thread_area, 0))		      \
+    {									      \
+      if ((__gs = INLINE_SYSCALL (set_thread_area, 2, descr, 1)) == -1	      \
+	  && errno == ENOSYS)						      \
+	__have_no_set_thread_area = 1;					      \
+    }									      \
+  if (__builtin_expect (__gs == -1, 0))					      \
+    __gs = DO_MODIFY_LDT (descr, nr);					      \
+  __asm__ __volatile__ ("movw %w0, %%gs" : : "q" (__gs));		      \
+}
+#else
+#define INIT_THREAD_SELF(descr, nr) \
+{									      \
+  int __gs = DO_MODIFY_LDT (descr, nr);					      \
+  __asm__ __volatile__ ("movw %w0, %%gs" : : "q" (__gs));		      \
+}
+#endif
 
 /* Free resources associated with thread descriptor.  */
+#ifdef __ASSUME_SET_THREAD_AREA_SYSCALL
+#define FREE_THREAD(descr, nr) do { } while (0)
+#elif defined __NR_set_thread_area
+#define FREE_THREAD(descr, nr) \
+{									      \
+  int __gs;								      \
+  __asm__ __volatile__ ("movw %%gs, %w0" : "=q" (__gs));		      \
+  if (__builtin_expect (__gs & 4, 0))					      \
+    {									      \
+      struct modify_ldt_ldt_s ldt_entry =				      \
+	{ nr, 0, 0, 0, 0, 1, 0, 1, 0, 0 };				      \
+      __modify_ldt (1, &ldt_entry, sizeof (ldt_entry));			      \
+    }									      \
+}
+#else
 #define FREE_THREAD(descr, nr) \
 {									      \
   struct modify_ldt_ldt_s ldt_entry =					      \
     { nr, 0, 0, 0, 0, 1, 0, 1, 0, 0 };					      \
   __modify_ldt (1, &ldt_entry, sizeof (ldt_entry));			      \
 }
+#endif
 
 /* Read member of the thread descriptor directly.  */
 #define THREAD_GETMEM(descr, member) \
--- libc/linuxthreads/sysdeps/i386/pspinlock.c.jj	2001-01-02 14:17:38.000000000 +0100
+++ libc/linuxthreads/sysdeps/i386/pspinlock.c	2002-07-29 15:35:10.000000000 +0200
@@ -95,3 +95,5 @@ __pthread_spin_destroy (pthread_spinlock
   return 0;
 }
 weak_alias (__pthread_spin_destroy, pthread_spin_destroy)
+
+int __have_no_set_thread_area;
--- libc/sysdeps/unix/sysv/linux/kernel-features.h.jj	2002-07-23 10:06:16.000000000 +0200
+++ libc/sysdeps/unix/sysv/linux/kernel-features.h	2002-07-29 18:07:09.000000000 +0200
@@ -1,6 +1,6 @@
 /* Set flags signalling availability of kernel features based on given
    kernel version number.
-   Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
+   Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -184,6 +184,12 @@
 # define __ASSUME_MMAP2_SYSCALL		1
 #endif
 
+/* On x86, the set_thread_area syscall was introduced in 2.5.29, but its
+   semantics was changed in 2.5.30.  */
+#if __LINUX_KERNEL_VERSION >= 132382 && defined __i386__
+# define __ASSUME_SET_THREAD_AREA_SYSCALL	1
+#endif
+
 /* There are an infinite number of PA-RISC kernel versions numbered
    2.4.0.  But they've not really been released as such.  We require
    and expect the final version here.  */

	Jakub

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

* Re: [PATCH] Use set_thread_area syscall for threading
  2002-08-01 15:48 [PATCH] Use set_thread_area syscall for threading Jakub Jelinek
@ 2002-08-01 18:25 ` Ulrich Drepper
  0 siblings, 0 replies; 2+ messages in thread
From: Ulrich Drepper @ 2002-08-01 18:25 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Glibc hackers

Jakub Jelinek wrote:

> I gave this some more testing yesterday and it seems to work just fine.

Looks good.  I've applied it with one little additional change.  Thanks,

-- 
---------------.                          ,-.   1325 Chesapeake Terrace
Ulrich Drepper  \    ,-------------------'   \  Sunnyvale, CA 94089 USA
Red Hat          `--' drepper at redhat.com   `------------------------

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

end of thread, other threads:[~2002-08-02  1:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-08-01 15:48 [PATCH] Use set_thread_area syscall for threading Jakub Jelinek
2002-08-01 18:25 ` Ulrich Drepper

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