public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 5/6] Cygwin: cygtls: move local_clib member to start of class
  2017-11-13 15:46 [PATCH 0/6] newlib/Cygwin: Allow more inlining of locale_t stuff Corinna Vinschen
@ 2017-11-13 15:46 ` Corinna Vinschen
  2017-11-13 15:46 ` [PATCH 6/6] Cygwin: ___getreent: Expose assembler inline implementation into userspace Corinna Vinschen
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: Corinna Vinschen @ 2017-11-13 15:46 UTC (permalink / raw)
  To: newlib

From: Corinna Vinschen <corinna@vinschen.de>

So local_clib has a constant address offset in TLS so we can
expose the address into userspace.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
---
 winsup/cygwin/cygtls.h       |  6 ++++--
 winsup/cygwin/tlsoffsets.h   | 24 ++++++++++++------------
 winsup/cygwin/tlsoffsets64.h | 24 ++++++++++++------------
 3 files changed, 28 insertions(+), 26 deletions(-)

diff --git a/winsup/cygwin/cygtls.h b/winsup/cygwin/cygtls.h
index 18d9378f88ec..70bd36e4401d 100644
--- a/winsup/cygwin/cygtls.h
+++ b/winsup/cygwin/cygtls.h
@@ -170,13 +170,15 @@ typedef uintptr_t __tlsstack_t;
 class _cygtls
 {
 public:
-  /* Please keep these two declarations first */
-  struct _local_storage locals;
+  /* Please keep these two declarations first, especially the union must
+     remain at the start of this class.  Its position is referenced from
+     userspace. */
   union
   {
     struct _reent local_clib;
     char __dontuse[8 * ((sizeof(struct _reent) + 4) / 8)];
   };
+  struct _local_storage locals;
   /**/
   void (*func) /*gentls_offsets*/(int, siginfo_t *, void *)/*gentls_offsets*/;
   int saved_errno;
diff --git a/winsup/cygwin/tlsoffsets.h b/winsup/cygwin/tlsoffsets.h
index 13d1003e334f..2513a055a3af 100644
--- a/winsup/cygwin/tlsoffsets.h
+++ b/winsup/cygwin/tlsoffsets.h
@@ -1,12 +1,12 @@
 //;# autogenerated:  Do not edit.
 
 //; $tls::start_offset = -12700;
-//; $tls::locals = -12700;
-//; $tls::plocals = 0;
-//; $tls::local_clib = -10980;
-//; $tls::plocal_clib = 1720;
-//; $tls::__dontuse = -10980;
-//; $tls::p__dontuse = 1720;
+//; $tls::local_clib = -12700;
+//; $tls::plocal_clib = 0;
+//; $tls::__dontuse = -12700;
+//; $tls::p__dontuse = 0;
+//; $tls::locals = -11612;
+//; $tls::plocals = 1088;
 //; $tls::func = -9892;
 //; $tls::pfunc = 2808;
 //; $tls::saved_errno = -9888;
@@ -63,12 +63,12 @@
 //; $tls::pinitialized = 4852;
 //; __DATA__
 
-#define tls_locals (-12700)
-#define tls_plocals (0)
-#define tls_local_clib (-10980)
-#define tls_plocal_clib (1720)
-#define tls___dontuse (-10980)
-#define tls_p__dontuse (1720)
+#define tls_local_clib (-12700)
+#define tls_plocal_clib (0)
+#define tls___dontuse (-12700)
+#define tls_p__dontuse (0)
+#define tls_locals (-11612)
+#define tls_plocals (1088)
 #define tls_func (-9892)
 #define tls_pfunc (2808)
 #define tls_saved_errno (-9888)
diff --git a/winsup/cygwin/tlsoffsets64.h b/winsup/cygwin/tlsoffsets64.h
index d137408d0e0c..9388cadd8e2c 100644
--- a/winsup/cygwin/tlsoffsets64.h
+++ b/winsup/cygwin/tlsoffsets64.h
@@ -1,12 +1,12 @@
 //;# autogenerated:  Do not edit.
 
 //; $tls::start_offset = -12800;
-//; $tls::locals = -12800;
-//; $tls::plocals = 0;
-//; $tls::local_clib = -10624;
-//; $tls::plocal_clib = 2176;
-//; $tls::__dontuse = -10624;
-//; $tls::p__dontuse = 2176;
+//; $tls::local_clib = -12800;
+//; $tls::plocal_clib = 0;
+//; $tls::__dontuse = -12800;
+//; $tls::p__dontuse = 0;
+//; $tls::locals = -10912;
+//; $tls::plocals = 1888;
 //; $tls::func = -8736;
 //; $tls::pfunc = 4064;
 //; $tls::saved_errno = -8728;
@@ -63,12 +63,12 @@
 //; $tls::pinitialized = 7768;
 //; __DATA__
 
-#define tls_locals (-12800)
-#define tls_plocals (0)
-#define tls_local_clib (-10624)
-#define tls_plocal_clib (2176)
-#define tls___dontuse (-10624)
-#define tls_p__dontuse (2176)
+#define tls_local_clib (-12800)
+#define tls_plocal_clib (0)
+#define tls___dontuse (-12800)
+#define tls_p__dontuse (0)
+#define tls_locals (-10912)
+#define tls_plocals (1888)
 #define tls_func (-8736)
 #define tls_pfunc (4064)
 #define tls_saved_errno (-8728)
-- 
2.9.5

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

* [PATCH 2/6] newlib: ctype.h: Remove empty #if block
  2017-11-13 15:46 [PATCH 0/6] newlib/Cygwin: Allow more inlining of locale_t stuff Corinna Vinschen
  2017-11-13 15:46 ` [PATCH 5/6] Cygwin: cygtls: move local_clib member to start of class Corinna Vinschen
  2017-11-13 15:46 ` [PATCH 6/6] Cygwin: ___getreent: Expose assembler inline implementation into userspace Corinna Vinschen
@ 2017-11-13 15:46 ` Corinna Vinschen
  2017-11-13 15:46 ` [PATCH 1/6] reent: Initialize _locale pointer with &__globale_locale Corinna Vinschen
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: Corinna Vinschen @ 2017-11-13 15:46 UTC (permalink / raw)
  To: newlib

From: Corinna Vinschen <corinna@vinschen.de>

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
---
 newlib/libc/include/ctype.h | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/newlib/libc/include/ctype.h b/newlib/libc/include/ctype.h
index 06458cbda47a..12b626281d59 100644
--- a/newlib/libc/include/ctype.h
+++ b/newlib/libc/include/ctype.h
@@ -156,9 +156,6 @@ const char *__locale_ctype_ptr_l (locale_t);
 #  endif /* _MB_EXTENDED_CHARSETS* */
 # endif /* __GNUC__ */
 
-#if __POSIX_VISIBLE >= 200809
-#endif /* __POSIX_VISIBLE >= 200809 */
-
 #endif /* !__cplusplus */
 
 /* For C++ backward-compatibility only.  */
-- 
2.9.5

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

* [PATCH 0/6] newlib/Cygwin: Allow more inlining of locale_t stuff
@ 2017-11-13 15:46 Corinna Vinschen
  2017-11-13 15:46 ` [PATCH 5/6] Cygwin: cygtls: move local_clib member to start of class Corinna Vinschen
                   ` (6 more replies)
  0 siblings, 7 replies; 10+ messages in thread
From: Corinna Vinschen @ 2017-11-13 15:46 UTC (permalink / raw)
  To: newlib

From: Corinna Vinschen <corinna@vinschen.de>

This patch series exposes most of the locale_t stuff into userspace,
thus allowing to inline locale and ctype access.

On Cygwin a speedup can only be accomplished by additionally exposing
Cygwin's __getreent into userspace and fixing certain, as of yet variable
aspects of the TLS implementation.

This code speeds up ctype by roughly 60% on Cygwin.

Corinna Vinschen (6):
  reent: Initialize _locale pointer with &__globale_locale
  newlib: ctype.h: Remove empty #if block
  newlib: Expose locale structs and function in new header sys/_locale.h
  Cygwin: expose CYGTLS_PADSIZE as __CYGTLS_PADSIZE in userspace
  Cygwin: cygtls: move local_clib member to start of class
  Cygwin: ___getreent: Expose assembler inline implementation into
    userspace

 newlib/libc/include/ctype.h                        |  12 +--
 newlib/libc/include/locale.h                       |  29 +-----
 newlib/libc/include/sys/_locale.h                  | 103 +++++++++++++++++++++
 newlib/libc/include/sys/reent.h                    |   5 +-
 newlib/libc/locale/locale.c                        |  25 ++---
 newlib/libc/locale/newlocale.c                     |   4 +-
 newlib/libc/locale/setlocale.h                     |  55 +----------
 newlib/libc/locale/uselocale.c                     |   4 +-
 newlib/libc/sys/linux/include/setlocale.h          |   3 +-
 winsup/cygwin/cygtls.cc                            |   3 +-
 winsup/cygwin/cygtls.h                             |  10 +-
 winsup/cygwin/dcrt0.cc                             |   3 +-
 winsup/cygwin/external.cc                          |   2 +-
 winsup/cygwin/gentls_offsets                       |   4 +-
 winsup/cygwin/how-cygtls-works.txt                 |  10 +-
 .../cygwin/_cygtls_padsize.h}                      |   5 +-
 winsup/cygwin/include/cygwin/config.h              |  14 +--
 winsup/cygwin/init.cc                              |   2 +-
 winsup/cygwin/miscfuncs.cc                         |  10 +-
 winsup/cygwin/tlsoffsets.h                         |  24 ++---
 winsup/cygwin/tlsoffsets64.h                       |  24 ++---
 winsup/utils/strace.cc                             |   4 +-
 22 files changed, 189 insertions(+), 166 deletions(-)
 create mode 100644 newlib/libc/include/sys/_locale.h
 rename winsup/cygwin/{cygtls_padsize.h => include/cygwin/_cygtls_padsize.h} (60%)

-- 
2.9.5

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

* [PATCH 6/6] Cygwin: ___getreent: Expose assembler inline implementation into userspace
  2017-11-13 15:46 [PATCH 0/6] newlib/Cygwin: Allow more inlining of locale_t stuff Corinna Vinschen
  2017-11-13 15:46 ` [PATCH 5/6] Cygwin: cygtls: move local_clib member to start of class Corinna Vinschen
@ 2017-11-13 15:46 ` Corinna Vinschen
  2017-11-13 15:46 ` [PATCH 2/6] newlib: ctype.h: Remove empty #if block Corinna Vinschen
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: Corinna Vinschen @ 2017-11-13 15:46 UTC (permalink / raw)
  To: newlib

From: Corinna Vinschen <corinna@vinschen.de>

Now that we fixed the offsets and now that local_clib is always at the
start of the TLS area, we can use the stack offset of the TLS area as
pointer to the local _reent.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
---
 winsup/cygwin/include/cygwin/config.h | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/winsup/cygwin/include/cygwin/config.h b/winsup/cygwin/include/cygwin/config.h
index 282637b67130..55f2b2d8964d 100644
--- a/winsup/cygwin/include/cygwin/config.h
+++ b/winsup/cygwin/include/cygwin/config.h
@@ -34,15 +34,10 @@ extern "C" {
    Cygwin internal data structure) into newlib.  The machinery to
    compute these offsets already exists for the sake of gendef so
    we might as well just use it here.  */
+#include <cygwin/_cygtls_padsize.h>
 
-#if defined (_COMPILING_NEWLIB) || defined (__INSIDE_CYGWIN__)
-#ifdef __x86_64__
-#include "../tlsoffsets64.h"
-#else
-#include "../tlsoffsets.h"
-#endif
 __attribute__((__gnu_inline__))
-extern inline struct _reent *__getreent (void)
+extern inline struct _reent *___getreent (void)
 {
   register char *ret;
 #ifdef __x86_64__
@@ -50,9 +45,10 @@ extern inline struct _reent *__getreent (void)
 #else
   __asm __volatile__ ("movl %%fs:4,%0" : "=r" (ret));
 #endif
-  return (struct _reent *) (ret + tls_local_clib);
+  return (struct _reent *) (ret - __CYGTLS_PADSIZE);
 }
-#endif /* _COMPILING_NEWLIB || __INSIDE_CYGWIN__ */
+#undef __getreent
+#define __getreent()	(___getreent())
 
 #ifdef __x86_64__
 # define __SYMBOL_PREFIX
-- 
2.9.5

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

* [PATCH 1/6] reent: Initialize _locale pointer with &__globale_locale
  2017-11-13 15:46 [PATCH 0/6] newlib/Cygwin: Allow more inlining of locale_t stuff Corinna Vinschen
                   ` (2 preceding siblings ...)
  2017-11-13 15:46 ` [PATCH 2/6] newlib: ctype.h: Remove empty #if block Corinna Vinschen
@ 2017-11-13 15:46 ` Corinna Vinschen
  2017-11-13 15:52 ` [PATCH 4/6] Cygwin: expose CYGTLS_PADSIZE as __CYGTLS_PADSIZE in userspace Corinna Vinschen
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: Corinna Vinschen @ 2017-11-13 15:46 UTC (permalink / raw)
  To: newlib

From: Corinna Vinschen <corinna@vinschen.de>

This simplifies __get_current_locale for usage as an inline function
in the next step.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
---
 newlib/libc/include/sys/reent.h | 5 +++--
 newlib/libc/locale/setlocale.h  | 2 +-
 newlib/libc/locale/uselocale.c  | 4 ++--
 winsup/cygwin/cygtls.cc         | 1 +
 winsup/cygwin/dcrt0.cc          | 1 +
 5 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/newlib/libc/include/sys/reent.h b/newlib/libc/include/sys/reent.h
index c045ca549584..0051b970e087 100644
--- a/newlib/libc/include/sys/reent.h
+++ b/newlib/libc/include/sys/reent.h
@@ -38,6 +38,7 @@ typedef __uint32_t __ULong;
 struct _reent;
 
 struct __locale_t;
+extern struct __locale_t __global_locale;
 
 /*
  * If _REENT_SMALL is defined, we make struct _reent as small as possible,
@@ -431,7 +432,7 @@ extern const struct __sFILE_fake __sf_fake_stderr;
     _NULL, \
     0, \
     0, \
-    _NULL, \
+    &__globale_locale, \
     _NULL, \
     _NULL, \
     0, \
@@ -664,7 +665,7 @@ extern __FILE __sf[3];
     0, \
     "", \
     0, \
-    _NULL, \
+    &__global_locale, \
     0, \
     _NULL, \
     _NULL, \
diff --git a/newlib/libc/locale/setlocale.h b/newlib/libc/locale/setlocale.h
index 85a38d58664f..7f648caafded 100644
--- a/newlib/libc/locale/setlocale.h
+++ b/newlib/libc/locale/setlocale.h
@@ -227,7 +227,7 @@ __get_locale_r (struct _reent *r)
 _ELIDABLE_INLINE struct __locale_t *
 __get_current_locale (void)
 {
-  return _REENT->_locale ?: __get_global_locale ();
+  return _REENT->_locale;
 }
 
 /* Only access fixed "C" locale using this function.  Fake for !_MB_CAPABLE
diff --git a/newlib/libc/locale/uselocale.c b/newlib/libc/locale/uselocale.c
index 810590fc027c..0246f5f0698c 100644
--- a/newlib/libc/locale/uselocale.c
+++ b/newlib/libc/locale/uselocale.c
@@ -61,10 +61,10 @@ _uselocale_r (struct _reent *p, struct __locale_t *newloc)
   struct __locale_t *current_locale;
 
   current_locale = __get_locale_r (p);
-  if (!current_locale)
+  if (!current_locale || current_locale == &__global_locale)
     current_locale = LC_GLOBAL_LOCALE;
   if (newloc == LC_GLOBAL_LOCALE)
-    p->_locale = NULL;
+    p->_locale = &__global_locale;
   else if (newloc)
     p->_locale = newloc;
   return current_locale;
diff --git a/winsup/cygwin/cygtls.cc b/winsup/cygwin/cygtls.cc
index 1a2213d1f686..7c5936a109a5 100644
--- a/winsup/cygwin/cygtls.cc
+++ b/winsup/cygwin/cygtls.cc
@@ -64,6 +64,7 @@ _cygtls::init_thread (void *x, DWORD (*func) (void *, void *))
 	  local_clib.__cleanup = _GLOBAL_REENT->__cleanup;
 	  local_clib.__sglue._niobs = 3;
 	  local_clib.__sglue._iobs = &_GLOBAL_REENT->__sf[0];
+	  local_clib._locale = &__global_locale;
 	}
     }
 
diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc
index ea6adcbbd2e5..70198e27453d 100644
--- a/winsup/cygwin/dcrt0.cc
+++ b/winsup/cygwin/dcrt0.cc
@@ -740,6 +740,7 @@ dll_crt0_0 ()
   _impure_ptr->_stdin = &_impure_ptr->__sf[0];
   _impure_ptr->_stdout = &_impure_ptr->__sf[1];
   _impure_ptr->_stderr = &_impure_ptr->__sf[2];
+  _impure_ptr->_locale = &__global_locale;
   user_data->impure_ptr = _impure_ptr;
   user_data->impure_ptr_ptr = &_impure_ptr;
 
-- 
2.9.5

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

* [PATCH 4/6] Cygwin: expose CYGTLS_PADSIZE as __CYGTLS_PADSIZE in userspace
  2017-11-13 15:46 [PATCH 0/6] newlib/Cygwin: Allow more inlining of locale_t stuff Corinna Vinschen
                   ` (3 preceding siblings ...)
  2017-11-13 15:46 ` [PATCH 1/6] reent: Initialize _locale pointer with &__globale_locale Corinna Vinschen
@ 2017-11-13 15:52 ` Corinna Vinschen
  2017-11-13 15:59 ` [PATCH 3/6] newlib: Expose locale structs and function in new header sys/_locale.h Corinna Vinschen
  2017-11-13 20:02 ` [PATCH 0/6] newlib/Cygwin: Allow more inlining of locale_t stuff Corinna Vinschen
  6 siblings, 0 replies; 10+ messages in thread
From: Corinna Vinschen @ 2017-11-13 15:52 UTC (permalink / raw)
  To: newlib

From: Corinna Vinschen <corinna@vinschen.de>

This definition will be fixed from now on so we can use it as
offset operator in userspace.  The definition gets exposed in
a file cygwin/_cygtls_padsize.h which in turn is included by
cygwin/config.h.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
---
 winsup/cygwin/cygtls.cc                                        |  2 +-
 winsup/cygwin/cygtls.h                                         |  4 +---
 winsup/cygwin/dcrt0.cc                                         |  2 +-
 winsup/cygwin/external.cc                                      |  2 +-
 winsup/cygwin/gentls_offsets                                   |  4 ++--
 winsup/cygwin/how-cygtls-works.txt                             | 10 +++++-----
 .../{cygtls_padsize.h => include/cygwin/_cygtls_padsize.h}     |  5 ++---
 winsup/cygwin/init.cc                                          |  2 +-
 winsup/cygwin/miscfuncs.cc                                     | 10 +++++-----
 winsup/utils/strace.cc                                         |  4 ++--
 10 files changed, 21 insertions(+), 24 deletions(-)
 rename winsup/cygwin/{cygtls_padsize.h => include/cygwin/_cygtls_padsize.h} (60%)

diff --git a/winsup/cygwin/cygtls.cc b/winsup/cygwin/cygtls.cc
index 7c5936a109a5..207ebf89c6a1 100644
--- a/winsup/cygwin/cygtls.cc
+++ b/winsup/cygwin/cygtls.cc
@@ -20,7 +20,7 @@ details. */
 void
 _cygtls::call (DWORD (*func) (void *, void *), void *arg)
 {
-  char buf[CYGTLS_PADSIZE];
+  char buf[__CYGTLS_PADSIZE];
   /* Initialize this thread's ability to respond to things like
      SIGSEGV or SIGFPE. */
   exception protect;
diff --git a/winsup/cygwin/cygtls.h b/winsup/cygwin/cygtls.h
index 39dba1380ce1..18d9378f88ec 100644
--- a/winsup/cygwin/cygtls.h
+++ b/winsup/cygwin/cygtls.h
@@ -276,14 +276,12 @@ private:
 };
 #pragma pack(pop)
 
-#include "cygtls_padsize.h"
-
 /*gentls_offsets*/
 
 #include "cygerrno.h"
 #include "ntdll.h"
 
-#define _my_tls (*((_cygtls *) ((PBYTE) NtCurrentTeb()->Tib.StackBase - CYGTLS_PADSIZE)))
+#define _my_tls (*((_cygtls *) ((PBYTE) NtCurrentTeb()->Tib.StackBase - __CYGTLS_PADSIZE)))
 extern _cygtls *_main_tls;
 extern _cygtls *_sig_tls;
 
diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc
index 70198e27453d..cbfab7daf993 100644
--- a/winsup/cygwin/dcrt0.cc
+++ b/winsup/cygwin/dcrt0.cc
@@ -1094,7 +1094,7 @@ dll_crt0 (per_process *uptr)
 }
 
 /* This must be called by anyone who uses LoadLibrary to load cygwin1.dll.
-   You must have CYGTLS_PADSIZE bytes reserved at the bottom of the stack
+   You must have __CYGTLS_PADSIZE bytes reserved at the bottom of the stack
    calling this function, and that storage must not be overwritten until you
    unload cygwin1.dll, as it is used for _my_tls.  It is best to load
    cygwin1.dll before spawning any additional threads in your process.
diff --git a/winsup/cygwin/external.cc b/winsup/cygwin/external.cc
index 6aae32aea472..30ebb4eb24f5 100644
--- a/winsup/cygwin/external.cc
+++ b/winsup/cygwin/external.cc
@@ -432,7 +432,7 @@ cygwin_internal (cygwin_getinfo_types t, ...)
 	res = 0;
 	break;
       case CW_CYGTLS_PADSIZE:
-	res = CYGTLS_PADSIZE;
+	res = __CYGTLS_PADSIZE;
 	break;
       case CW_SET_DOS_FILE_WARNING:
 	{
diff --git a/winsup/cygwin/gentls_offsets b/winsup/cygwin/gentls_offsets
index 745ea27a035c..be778f5cf0ed 100755
--- a/winsup/cygwin/gentls_offsets
+++ b/winsup/cygwin/gentls_offsets
@@ -66,11 +66,11 @@ main(int argc, char **argv)
 {
   $struct *foo;
 # define foo_beg ((char *) foo)
-# define offset(f) ((unsigned)((int) (((char *) &(foo->f)) - foo_beg) - CYGTLS_PADSIZE))
+# define offset(f) ((unsigned)((int) (((char *) &(foo->f)) - foo_beg) - __CYGTLS_PADSIZE))
 # define poffset(f) ((unsigned)(((char *) &(foo->f)) - ((char *) foo)))
 EOF
     print TMP 'puts ("//;# autogenerated:  Do not edit.\n");', "\n\n";
-    print TMP "printf (\"//; \$tls::start_offset = -%d;\\n\", CYGTLS_PADSIZE);\n";
+    print TMP "printf (\"//; \$tls::start_offset = -%d;\\n\", __CYGTLS_PADSIZE);\n";
     for my $f (@fields) {
 	print TMP '  printf ("//; $tls::', $f, ' = %d;\n", ', "offset($f));\n";
 	print TMP '  printf ("//; $tls::p', $f, ' = %d;\n", ', "poffset($f));\n";
diff --git a/winsup/cygwin/how-cygtls-works.txt b/winsup/cygwin/how-cygtls-works.txt
index 8bba0a7a0043..2f5e0ccf67e9 100644
--- a/winsup/cygwin/how-cygtls-works.txt
+++ b/winsup/cygwin/how-cygtls-works.txt
@@ -1,7 +1,7 @@
 Contributed by Max Kaehn
 
 All cygwin threads have separate context in an object of class _cygtls.  The
-storage for this object is kept on the stack in the bottom CYGTLS_PADSIZE
+storage for this object is kept on the stack in the bottom __CYGTLS_PADSIZE
 bytes.  Each thread references the storage via the Thread Environment Block
 (aka Thread Information Block), which Windows maintains for each user thread
 in the system, with the address in the FS segment register.  The memory
@@ -34,13 +34,13 @@ And accesses cygtls like this:
 Initialization always goes through _cygtls::init_thread().  It works
 in the following ways:
 
-* In the main thread, _dll_crt0() provides CYGTLS_PADSIZE bytes on the stack
+* In the main thread, _dll_crt0() provides __CYGTLS_PADSIZE bytes on the stack
   and passes them to initialize_main_tls(), which calls _cygtls::init_thread().
   It then calls dll_crt0_1(), which terminates with cygwin_exit() rather than
   by returning, so the storage never goes out of scope.
 
   If you load cygwin1.dll dynamically from a non-cygwin application, it is
-  vital that the bottom CYGTLS_PADSIZE bytes of the stack are not in use
+  vital that the bottom __CYGTLS_PADSIZE bytes of the stack are not in use
   before you call cygwin_dll_init().  See winsup/testsuite/cygload for
   more information.
 
@@ -49,7 +49,7 @@ in the following ways:
   - dll_entry() calls munge_threadfunc(), which grabs the function pointer
     for the thread from the stack frame and substitutes threadfunc_fe(),
   - which then passes the original function pointer to _cygtls::call(),
-  - which then allocates CYGTLS_PADSIZE bytes on the stack and hands them
+  - which then allocates __CYGTLS_PADSIZE bytes on the stack and hands them
     to call2(),
   - which allocates an exception_list object on the stack and hands it to
     init_exceptions() (in exceptions.cc), which attaches it to the end of
@@ -60,7 +60,7 @@ in the following ways:
 
 Note that the padding isn't necessarily going to be just where the _cygtls
 structure lives; it just makes sure there's enough room on the stack when the
-CYGTLS_PADSIZE bytes down from there are overwritten.
+__CYGTLS_PADSIZE bytes down from there are overwritten.
 
 
 Debugging
diff --git a/winsup/cygwin/cygtls_padsize.h b/winsup/cygwin/include/cygwin/_cygtls_padsize.h
similarity index 60%
rename from winsup/cygwin/cygtls_padsize.h
rename to winsup/cygwin/include/cygwin/_cygtls_padsize.h
index d3f024ad341a..d011d76ea36a 100644
--- a/winsup/cygwin/cygtls_padsize.h
+++ b/winsup/cygwin/include/cygwin/_cygtls_padsize.h
@@ -4,9 +4,8 @@ This software is a copyrighted work licensed under the terms of the
 Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
 details. */
 
-/* FIXME: Find some way to autogenerate this value */
 #ifdef __x86_64__
-const int CYGTLS_PADSIZE = 12800;	/* Must be 16-byte aligned */
+#define __CYGTLS_PADSIZE	12800
 #else
-const int CYGTLS_PADSIZE = 12700;
+#define __CYGTLS_PADSIZE	12700
 #endif
diff --git a/winsup/cygwin/init.cc b/winsup/cygwin/init.cc
index aeeeac7725fc..db7ed11e2c8e 100644
--- a/winsup/cygwin/init.cc
+++ b/winsup/cygwin/init.cc
@@ -99,7 +99,7 @@ dll_entry (HANDLE h, DWORD reason, void *static_load)
 	 initialized to NULL, so subsequent calls to locale-specific functions
 	 will always fall back to __global_locale, rather then crash due to
 	 _REENT->_locale having an arbitrary value. */
-      alloca_dummy = alloca (CYGTLS_PADSIZE);
+      alloca_dummy = alloca (__CYGTLS_PADSIZE);
       memcpy (_REENT, _GLOBAL_REENT, sizeof (struct _reent));
 
       dll_crt0_0 ();
diff --git a/winsup/cygwin/miscfuncs.cc b/winsup/cygwin/miscfuncs.cc
index e2ab7a0809fd..9760f3951d2f 100644
--- a/winsup/cygwin/miscfuncs.cc
+++ b/winsup/cygwin/miscfuncs.cc
@@ -397,7 +397,7 @@ pthread_wrapper (PVOID arg)
       SetThreadStackGuarantee (&wrapper_arg.guardsize);
     }
   /* Initialize new _cygtls. */
-  _my_tls.init_thread (wrapper_arg.stackbase - CYGTLS_PADSIZE,
+  _my_tls.init_thread (wrapper_arg.stackbase - __CYGTLS_PADSIZE,
 		       (DWORD (*)(void*, void*)) wrapper_arg.func);
 #ifndef __x86_64__
   /* Copy exception list over to new stack.  I'm not quite sure how the
@@ -440,7 +440,7 @@ pthread_wrapper (PVOID arg)
 	   movq  8(%%rbx), %%r13	# Load thread arg into r13	\n\
 	   movq  16(%%rbx), %%rcx	# Load stackaddr into rcx	\n\
 	   movq  24(%%rbx), %%rsp	# Load stackbase into rsp	\n\
-	   subq  %[CYGTLS], %%rsp	# Subtract CYGTLS_PADSIZE	\n\
+	   subq  %[CYGTLS], %%rsp	# Subtract __CYGTLS_PADSIZE	\n\
 	   				# (here we are 16 bytes aligned)\n\
 	   subq  $32, %%rsp		# Subtract another 32 bytes	\n\
 	   				# (shadow space for arg regs)	\n\
@@ -456,7 +456,7 @@ pthread_wrapper (PVOID arg)
 	   movq  %%r13, %%rcx		# Move thread arg to 1st arg reg\n\
 	   call  *%%r12			# Call thread func		\n"
 	   : : [WRAPPER_ARG] "o" (wrapper_arg),
-	       [CYGTLS] "i" (CYGTLS_PADSIZE));
+	       [CYGTLS] "i" (__CYGTLS_PADSIZE));
 #else
   __asm__ ("\n\
 	   leal  %[WRAPPER_ARG], %%ebx	# Load &wrapper_arg into ebx	\n\
@@ -464,7 +464,7 @@ pthread_wrapper (PVOID arg)
 	   movl  4(%%ebx), %%ecx	# Load thread arg into ecx	\n\
 	   movl  8(%%ebx), %%edx	# Load stackaddr into edx	\n\
 	   movl  12(%%ebx), %%ebx	# Load stackbase into ebx	\n\
-	   subl  %[CYGTLS], %%ebx	# Subtract CYGTLS_PADSIZE	\n\
+	   subl  %[CYGTLS], %%ebx	# Subtract __CYGTLS_PADSIZE	\n\
 	   subl  $4, %%ebx		# Subtract another 4 bytes	\n\
 	   movl  %%ebx, %%esp		# Set esp			\n\
 	   xorl  %%ebp, %%ebp		# Set ebp to 0			\n\
@@ -487,7 +487,7 @@ pthread_wrapper (PVOID arg)
 	   popl  %%eax			# Pop thread_func address	\n\
 	   call  *%%eax			# Call thread func		\n"
 	   : : [WRAPPER_ARG] "o" (wrapper_arg),
-	       [CYGTLS] "i" (CYGTLS_PADSIZE));
+	       [CYGTLS] "i" (__CYGTLS_PADSIZE));
 #endif
   /* pthread::thread_init_wrapper calls pthread::exit, which
      in turn calls ExitThread, so we should never arrive here. */
diff --git a/winsup/utils/strace.cc b/winsup/utils/strace.cc
index ae62cdc5f2ba..1e1985eaf95a 100644
--- a/winsup/utils/strace.cc
+++ b/winsup/utils/strace.cc
@@ -24,7 +24,7 @@ details. */
 #include "../cygwin/include/sys/strace.h"
 #include "../cygwin/include/sys/cygwin.h"
 #include "../cygwin/include/cygwin/version.h"
-#include "../cygwin/cygtls_padsize.h"
+#include "../cygwin/include/cygwin/_cygtls_padsize.h"
 #include "path.h"
 #undef cygwin_internal
 #include "loadlib.h"
@@ -1189,7 +1189,7 @@ main (int argc, char **argv)
      This is required to make sure cygwin_internal calls into Cygwin work
      reliably.  This problem has been noticed under AllocationPreference
      registry setting to 0x100000 (TOP_DOWN). */
-  char buf[CYGTLS_PADSIZE];
+  char buf[__CYGTLS_PADSIZE];
 
   RtlSecureZeroMemory (buf, sizeof (buf));
   exit (main2 (argc, argv));
-- 
2.9.5

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

* [PATCH 3/6] newlib: Expose locale structs and function in new header sys/_locale.h
  2017-11-13 15:46 [PATCH 0/6] newlib/Cygwin: Allow more inlining of locale_t stuff Corinna Vinschen
                   ` (4 preceding siblings ...)
  2017-11-13 15:52 ` [PATCH 4/6] Cygwin: expose CYGTLS_PADSIZE as __CYGTLS_PADSIZE in userspace Corinna Vinschen
@ 2017-11-13 15:59 ` Corinna Vinschen
  2017-11-13 20:02 ` [PATCH 0/6] newlib/Cygwin: Allow more inlining of locale_t stuff Corinna Vinschen
  6 siblings, 0 replies; 10+ messages in thread
From: Corinna Vinschen @ 2017-11-13 15:59 UTC (permalink / raw)
  To: newlib

From: Corinna Vinschen <corinna@vinschen.de>

* This allows to convert some accessor functions for locale_t into
  inline functions.

* Use these inline functions in ctype.h to speed up ctype functionality.

* This also exposes ENCODING_LEN.  Move it to private namespace by
  renaming to _LC_ENCODING_LEN.

* Add a comment to make sure nobody removes the non-inline functions
  __locale_ctype_ptr and __locale_ctype_ptr_l.  They are required for
  backward compatibility on Cygwin at least.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
---
 newlib/libc/include/ctype.h               |   9 +--
 newlib/libc/include/locale.h              |  29 +--------
 newlib/libc/include/sys/_locale.h         | 103 ++++++++++++++++++++++++++++++
 newlib/libc/locale/locale.c               |  25 ++++----
 newlib/libc/locale/newlocale.c            |   4 +-
 newlib/libc/locale/setlocale.h            |  55 +---------------
 newlib/libc/sys/linux/include/setlocale.h |   3 +-
 7 files changed, 128 insertions(+), 100 deletions(-)
 create mode 100644 newlib/libc/include/sys/_locale.h

diff --git a/newlib/libc/include/ctype.h b/newlib/libc/include/ctype.h
index 12b626281d59..2337917bc713 100644
--- a/newlib/libc/include/ctype.h
+++ b/newlib/libc/include/ctype.h
@@ -3,6 +3,7 @@
 
 #include "_ansi.h"
 #include <sys/cdefs.h>
+#include <sys/_locale.h>
 
 #if __POSIX_VISIBLE >= 200809 || __MISC_VISIBLE || defined (_COMPILING_NEWLIB)
 #include <xlocale.h>
@@ -66,8 +67,7 @@ extern int toascii_l (int __c, locale_t __l);
 #define _X	0100
 #define	_B	0200
 
-const char *__locale_ctype_ptr (void);
-# define __CTYPE_PTR	(__locale_ctype_ptr ())
+# define __CTYPE_PTR	(__get_current_locale()->ctype_ptr)
 
 #ifndef __cplusplus
 /* These macros are intentionally written in a manner that will trigger
@@ -100,8 +100,9 @@ const char *__locale_ctype_ptr (void);
 #endif
 
 #if __POSIX_VISIBLE >= 200809
-const char *__locale_ctype_ptr_l (locale_t);
-#define __ctype_lookup_l(__c,__l) ((__locale_ctype_ptr_l(__l)+sizeof(""[__c]))[(int)(__c)])
+
+#define __locale_ctype_ptr_l(__l)	((__l)->ctype_ptr)
+#define __ctype_lookup_l(__c,__l) ((((const char *)((__l)->ctype_ptr))+sizeof(""[__c]))[(int)(__c)])
 
 #define	isalpha_l(__c,__l)	(__ctype_lookup_l(__c,__l)&(_U|_L))
 #define	isupper_l(__c,__l)	((__ctype_lookup_l(__c,__l)&(_U|_L))==_U)
diff --git a/newlib/libc/include/locale.h b/newlib/libc/include/locale.h
index 8ba88a90ca90..587e7637973f 100644
--- a/newlib/libc/include/locale.h
+++ b/newlib/libc/include/locale.h
@@ -9,6 +9,7 @@
 
 #include "_ansi.h"
 #include <sys/cdefs.h>
+#include <sys/_locale.h>
 
 #define __need_NULL
 #include <stddef.h>
@@ -39,34 +40,6 @@
 
 _BEGIN_STD_C
 
-struct lconv
-{
-  char *decimal_point;
-  char *thousands_sep;
-  char *grouping;
-  char *int_curr_symbol;
-  char *currency_symbol;
-  char *mon_decimal_point;
-  char *mon_thousands_sep;
-  char *mon_grouping;
-  char *positive_sign;
-  char *negative_sign;
-  char int_frac_digits;
-  char frac_digits;
-  char p_cs_precedes;
-  char p_sep_by_space;
-  char n_cs_precedes;
-  char n_sep_by_space;
-  char p_sign_posn;
-  char n_sign_posn;
-  char int_n_cs_precedes;
-  char int_n_sep_by_space;
-  char int_n_sign_posn;
-  char int_p_cs_precedes;
-  char int_p_sep_by_space;
-  char int_p_sign_posn;
-};
-
 struct _reent;
 char *_EXFUN(_setlocale_r,(struct _reent *, int, const char *));
 struct lconv *_EXFUN(_localeconv_r,(struct _reent *));
diff --git a/newlib/libc/include/sys/_locale.h b/newlib/libc/include/sys/_locale.h
new file mode 100644
index 000000000000..187a2e45a07a
--- /dev/null
+++ b/newlib/libc/include/sys/_locale.h
@@ -0,0 +1,103 @@
+/*
+	sys/_locale.h
+	Definition of userspace exposed locale structs.
+*/
+
+#ifndef _SYS__LOCALE_H_
+#define _SYS__LOCALE_H_
+
+#include <newlib.h>
+#include <sys/config.h>
+#include <sys/reent.h>
+
+#define _LC_LAST      7
+#define _LC_ENCODING_LEN 31
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct lconv
+{
+  char *decimal_point;
+  char *thousands_sep;
+  char *grouping;
+  char *int_curr_symbol;
+  char *currency_symbol;
+  char *mon_decimal_point;
+  char *mon_thousands_sep;
+  char *mon_grouping;
+  char *positive_sign;
+  char *negative_sign;
+  char int_frac_digits;
+  char frac_digits;
+  char p_cs_precedes;
+  char p_sep_by_space;
+  char n_cs_precedes;
+  char n_sep_by_space;
+  char p_sign_posn;
+  char n_sign_posn;
+  char int_n_cs_precedes;
+  char int_n_sep_by_space;
+  char int_n_sign_posn;
+  char int_p_cs_precedes;
+  char int_p_sep_by_space;
+  char int_p_sign_posn;
+};
+
+struct __lc_cats
+{
+  const void	*ptr;
+  char		*buf;
+};
+
+struct __locale_t
+{
+  char			 categories[_LC_LAST][_LC_ENCODING_LEN + 1];
+  int			(*wctomb) (struct _reent *, char *, wchar_t,
+				   _mbstate_t *);
+  int			(*mbtowc) (struct _reent *, wchar_t *,
+				   const char *, size_t, _mbstate_t *);
+  int			 cjk_lang;
+  char			*ctype_ptr;
+  struct lconv		 lconv;
+#ifndef __HAVE_LOCALE_INFO__
+  char			 mb_cur_max[2];
+  char			 ctype_codeset[_LC_ENCODING_LEN + 1];
+  char			 message_codeset[_LC_ENCODING_LEN + 1];
+#else
+  struct __lc_cats	 lc_cat[_LC_LAST];
+#endif
+};
+
+/* In POSIX terms the global locale is the process-wide locale.  Use this
+   function to always refer to the global locale. */
+_ELIDABLE_INLINE struct __locale_t *
+__get_global_locale ()
+{
+  extern struct __locale_t __global_locale;
+  return &__global_locale;
+}
+
+/* Per REENT locale.  This is newlib-internal. */
+_ELIDABLE_INLINE struct __locale_t *
+__get_locale_r (struct _reent *r)
+{
+  return r->_locale;
+}
+
+/* In POSIX terms the current locale is the locale used by all functions
+   using locale info without providing a locale as parameter (*_l functions).
+   The current locale is either the locale of the current thread, if the
+   thread called uselocale, or the global locale if not. */
+_ELIDABLE_INLINE struct __locale_t *
+__get_current_locale (void)
+{
+  return _REENT->_locale;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _SYS__LOCALE_H_ */
diff --git a/newlib/libc/locale/locale.c b/newlib/libc/locale/locale.c
index b5402372c3f3..9cb1cb212f49 100644
--- a/newlib/libc/locale/locale.c
+++ b/newlib/libc/locale/locale.c
@@ -217,7 +217,7 @@ static char *categories[_LC_LAST] = {
  * This variable can be changed by any outside mechanism.  This allows,
  * for instance, to load the default locale from a file.
  */
-char __default_locale[ENCODING_LEN + 1] = DEFAULT_LOCALE;
+char __default_locale[_LC_ENCODING_LEN + 1] = DEFAULT_LOCALE;
 
 const struct __locale_t __C_locale =
 {
@@ -299,7 +299,7 @@ struct __locale_t __global_locale =
 /* Renamed from current_locale_string to make clear this is only the
    *global* string for setlocale (LC_ALL, NULL).  There's no equivalent
    functionality for uselocale. */
-static char global_locale_string[_LC_LAST * (ENCODING_LEN + 1/*"/"*/ + 1)];
+static char global_locale_string[_LC_LAST * (_LC_ENCODING_LEN + 1/*"/"*/ + 1)];
 static char *currentlocale (void);
 
 #endif /* _MB_CAPABLE */
@@ -319,8 +319,8 @@ _DEFUN(_setlocale_r, (p, category, locale),
     }
   return "C";
 #else /* _MB_CAPABLE */
-  static char new_categories[_LC_LAST][ENCODING_LEN + 1];
-  static char saved_categories[_LC_LAST][ENCODING_LEN + 1];
+  static char new_categories[_LC_LAST][_LC_ENCODING_LEN + 1];
+  static char saved_categories[_LC_LAST][_LC_ENCODING_LEN + 1];
   int i, j, len, saverr;
   const char *env, *r;
 
@@ -350,7 +350,7 @@ _DEFUN(_setlocale_r, (p, category, locale),
 	  for (i = 1; i < _LC_LAST; ++i)
 	    {
 	      env = __get_locale_env (p, i);
-	      if (strlen (env) > ENCODING_LEN)
+	      if (strlen (env) > _LC_ENCODING_LEN)
 		{
 		  p->_errno = EINVAL;
 		  return NULL;
@@ -361,7 +361,7 @@ _DEFUN(_setlocale_r, (p, category, locale),
       else
 	{
 	  env = __get_locale_env (p, category);
-	  if (strlen (env) > ENCODING_LEN)
+	  if (strlen (env) > _LC_ENCODING_LEN)
 	    {
 	      p->_errno = EINVAL;
 	      return NULL;
@@ -371,7 +371,7 @@ _DEFUN(_setlocale_r, (p, category, locale),
     }
   else if (category != LC_ALL)
     {
-      if (strlen (locale) > ENCODING_LEN)
+      if (strlen (locale) > _LC_ENCODING_LEN)
 	{
 	  p->_errno = EINVAL;
 	  return NULL;
@@ -382,7 +382,7 @@ _DEFUN(_setlocale_r, (p, category, locale),
     {
       if ((r = strchr (locale, '/')) == NULL)
 	{
-	  if (strlen (locale) > ENCODING_LEN)
+	  if (strlen (locale) > _LC_ENCODING_LEN)
 	    {
 	      p->_errno = EINVAL;
 	      return NULL;
@@ -403,7 +403,7 @@ _DEFUN(_setlocale_r, (p, category, locale),
 	    {
 	      if (i == _LC_LAST)
 		break;  /* Too many slashes... */
-	      if ((len = r - locale) > ENCODING_LEN)
+	      if ((len = r - locale) > _LC_ENCODING_LEN)
 		{
 		  p->_errno = EINVAL;
 		  return NULL;
@@ -490,7 +490,7 @@ __loadlocale (struct __locale_t *loc, int category, const char *new_locale)
      is extracted and stored in ctype_codeset or message_charset
      dependent on the cateogry. */
   char *locale = NULL;
-  char charset[ENCODING_LEN + 1];
+  char charset[_LC_ENCODING_LEN + 1];
   long val = 0;
   char *end, *c = NULL;
   int mbc_max;
@@ -516,7 +516,7 @@ __loadlocale (struct __locale_t *loc, int category, const char *new_locale)
      "th_TH.TIS-620".  If successful, the function returns with a pointer
      to the second argument, which is a buffer in which the replacement locale
      gets stored.  Otherwise the function returns NULL. */
-  char tmp_locale[ENCODING_LEN + 1];
+  char tmp_locale[_LC_ENCODING_LEN + 1];
   int ret = 0;
 
 restart:
@@ -991,6 +991,9 @@ _DEFUN_VOID (__locale_mb_cur_max)
 #endif
 }
 
+/* __locale_ctype_ptr_l and __locale_ctype_ptr have been exported and
+   needs to be retained for backward compat on Cygwin. */
+#undef __locale_ctype_ptr_l
 const char *
 __locale_ctype_ptr_l (struct __locale_t *locale)
 {
diff --git a/newlib/libc/locale/newlocale.c b/newlib/libc/locale/newlocale.c
index c8176256e09c..72660707038b 100644
--- a/newlib/libc/locale/newlocale.c
+++ b/newlib/libc/locale/newlocale.c
@@ -89,7 +89,7 @@ _newlocale_r (struct _reent *p, int category_mask, const char *locale,
 #ifndef _MB_CAPABLE
   return __get_C_locale ();
 #else /* _MB_CAPABLE */
-  char new_categories[_LC_LAST][ENCODING_LEN + 1];
+  char new_categories[_LC_LAST][_LC_ENCODING_LEN + 1];
   struct __locale_t tmp_locale, *new_locale;
   int i;
 
@@ -123,7 +123,7 @@ _newlocale_r (struct _reent *p, int category_mask, const char *locale,
 	     name verbatim. */
 	  const char *cat = (locale[0] == '\0') ? __get_locale_env (p, i)
 						: locale;
-	  if (strlen (cat) > ENCODING_LEN)
+	  if (strlen (cat) > _LC_ENCODING_LEN)
 	    {
 	      p->_errno = EINVAL;
 	      return NULL;
diff --git a/newlib/libc/locale/setlocale.h b/newlib/libc/locale/setlocale.h
index 7f648caafded..13599915f3c5 100644
--- a/newlib/libc/locale/setlocale.h
+++ b/newlib/libc/locale/setlocale.h
@@ -39,9 +39,7 @@
 
 __BEGIN_DECLS
 
-#define ENCODING_LEN 31
 #define CATEGORY_LEN 11
-#define _LC_LAST      7
 
 #ifdef __CYGWIN__
 struct lc_collate_T
@@ -49,7 +47,7 @@ struct lc_collate_T
   __uint32_t	 lcid;
   int	       (*mbtowc) (struct _reent *, wchar_t *, const char *, size_t,
 			  mbstate_t *);
-  char		 codeset[ENCODING_LEN + 1];
+  char		 codeset[_LC_ENCODING_LEN + 1];
 };
 extern const struct lc_collate_T _C_collate_locale;
 #endif
@@ -169,31 +167,6 @@ struct	lc_messages_T
 };
 extern const struct lc_messages_T _C_messages_locale;
 
-struct __lc_cats
-{
-  const void	*ptr;
-  char		*buf;
-};
-
-struct __locale_t
-{
-  char			 categories[_LC_LAST][ENCODING_LEN + 1];
-  int			(*wctomb) (struct _reent *, char *, wchar_t,
-				   mbstate_t *);
-  int			(*mbtowc) (struct _reent *, wchar_t *,
-				   const char *, size_t, mbstate_t *);
-  int			 cjk_lang;
-  char			*ctype_ptr;
-  struct lconv		 lconv;
-#ifndef __HAVE_LOCALE_INFO__
-  char			 mb_cur_max[2];
-  char			 ctype_codeset[ENCODING_LEN + 1];
-  char			 message_codeset[ENCODING_LEN + 1];
-#else
-  struct __lc_cats	 lc_cat[_LC_LAST];
-#endif
-};
-
 #ifdef _MB_CAPABLE
 extern char *__loadlocale (struct __locale_t *, int, const char *);
 extern const char *__get_locale_env(struct _reent *, int);
@@ -204,32 +177,6 @@ extern struct lconv *__localeconv_l (struct __locale_t *locale);
 extern size_t _wcsnrtombs_l (struct _reent *, char *, const wchar_t **,
 			     size_t, size_t, mbstate_t *, struct __locale_t *);
 
-/* In POSIX terms the global locale is the process-wide locale.  Use this
-   function to always refer to the global locale. */
-_ELIDABLE_INLINE struct __locale_t *
-__get_global_locale ()
-{
-  extern struct __locale_t __global_locale;
-  return &__global_locale;
-}
-
-/* Per REENT locale.  This is newlib-internal. */
-_ELIDABLE_INLINE struct __locale_t *
-__get_locale_r (struct _reent *r)
-{
-  return r->_locale;
-}
-
-/* In POSIX terms the current locale is the locale used by all functions
-   using locale info without providing a locale as parameter (*_l functions).
-   The current locale is either the locale of the current thread, if the
-   thread called uselocale, or the global locale if not. */
-_ELIDABLE_INLINE struct __locale_t *
-__get_current_locale (void)
-{
-  return _REENT->_locale;
-}
-
 /* Only access fixed "C" locale using this function.  Fake for !_MB_CAPABLE
    targets by returning ptr to globale locale. */
 _ELIDABLE_INLINE struct __locale_t *
diff --git a/newlib/libc/sys/linux/include/setlocale.h b/newlib/libc/sys/linux/include/setlocale.h
index 3eb769863c69..964056bb5288 100644
--- a/newlib/libc/sys/linux/include/setlocale.h
+++ b/newlib/libc/sys/linux/include/setlocale.h
@@ -29,7 +29,8 @@
 #ifndef _SETLOCALE_H_
 #define	_SETLOCALE_H_
 
-#define ENCODING_LEN 31
+#define _LC_ENCODING_LEN 31
+#define ENCODING_LEN _LC_ENCODING_LEN
 #define CATEGORY_LEN 11
 
 extern char *_PathLocale;
-- 
2.9.5

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

* Re: [PATCH 0/6] newlib/Cygwin: Allow more inlining of locale_t stuff
  2017-11-13 15:46 [PATCH 0/6] newlib/Cygwin: Allow more inlining of locale_t stuff Corinna Vinschen
                   ` (5 preceding siblings ...)
  2017-11-13 15:59 ` [PATCH 3/6] newlib: Expose locale structs and function in new header sys/_locale.h Corinna Vinschen
@ 2017-11-13 20:02 ` Corinna Vinschen
  2017-11-14  7:56   ` Sebastian Huber
  6 siblings, 1 reply; 10+ messages in thread
From: Corinna Vinschen @ 2017-11-13 20:02 UTC (permalink / raw)
  To: newlib

[-- Attachment #1: Type: text/plain, Size: 1550 bytes --]

On Nov 13 16:46, Corinna Vinschen wrote:
> From: Corinna Vinschen <corinna@vinschen.de>
> 
> This patch series exposes most of the locale_t stuff into userspace,
> thus allowing to inline locale and ctype access.
> 
> On Cygwin a speedup can only be accomplished by additionally exposing
> Cygwin's __getreent into userspace and fixing certain, as of yet variable
> aspects of the TLS implementation.
> 
> This code speeds up ctype by roughly 60% on Cygwin.

Please note that I won't push these changes as long as nobody actually
tested this.

The problem on Cygwin is that, whatever we change in locale_t and its
accessor functions, userspace has no access to the address of the _reent
struct within the TLS area yet.  Way back when, it was a conscious
decision not to do this, to keep the TLS area firmly hidden and
changable.

The downside is, userspace always needs at least one function call per
ctype invocation, either the locale_t function to fetch the locale
pointer, or the __getreent function to fetch the reent pointer.
Either way, the timing of a ctype test loop as discussed in
https://sourceware.org/ml/newlib/2017/msg01072.html and follow-ups
stays constant.

Only by exposing the reent pointer offset in the TLS area to
userspace allows to inline the entire code sequence and eventually
speeds up ctype.

Having said that, I'm not overly happy with the Cygwin __getreent
change.  I'm not sure if performance is worth the price here.


Corinna

-- 
Corinna Vinschen
Cygwin Maintainer
Red Hat

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

* Re: [PATCH 0/6] newlib/Cygwin: Allow more inlining of locale_t stuff
  2017-11-13 20:02 ` [PATCH 0/6] newlib/Cygwin: Allow more inlining of locale_t stuff Corinna Vinschen
@ 2017-11-14  7:56   ` Sebastian Huber
  2017-11-14  9:19     ` Corinna Vinschen
  0 siblings, 1 reply; 10+ messages in thread
From: Sebastian Huber @ 2017-11-14  7:56 UTC (permalink / raw)
  To: newlib

On 13/11/17 16:59, Corinna Vinschen wrote:
> Having said that, I'm not overly happy with the Cygwin __getreent
> change.  I'm not sure if performance is worth the price here.

There is also a price in terms of memory space here if we initialize 
_REENT->_locale with __global_locale. Applications not using this 
ctype/locale stuff will now also include the __global_locale.

-- 
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone   : +49 89 189 47 41-16
Fax     : +49 89 189 47 41-09
E-Mail  : sebastian.huber@embedded-brains.de
PGP     : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.

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

* Re: [PATCH 0/6] newlib/Cygwin: Allow more inlining of locale_t stuff
  2017-11-14  7:56   ` Sebastian Huber
@ 2017-11-14  9:19     ` Corinna Vinschen
  0 siblings, 0 replies; 10+ messages in thread
From: Corinna Vinschen @ 2017-11-14  9:19 UTC (permalink / raw)
  To: newlib

[-- Attachment #1: Type: text/plain, Size: 709 bytes --]

On Nov 14 08:23, Sebastian Huber wrote:
> On 13/11/17 16:59, Corinna Vinschen wrote:
> > Having said that, I'm not overly happy with the Cygwin __getreent
> > change.  I'm not sure if performance is worth the price here.
> 
> There is also a price in terms of memory space here if we initialize
> _REENT->_locale with __global_locale. Applications not using this
> ctype/locale stuff will now also include the __global_locale.

Isn't that always, or most of the time, the case anyway?  The
ctype functions call __locale_ctype_ptr() which in turn calls
__get_current_locale():

  return _REENT->_locale ?: __get_global_locale ();


Corinna

-- 
Corinna Vinschen
Cygwin Maintainer
Red Hat

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

end of thread, other threads:[~2017-11-14  9:18 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-13 15:46 [PATCH 0/6] newlib/Cygwin: Allow more inlining of locale_t stuff Corinna Vinschen
2017-11-13 15:46 ` [PATCH 5/6] Cygwin: cygtls: move local_clib member to start of class Corinna Vinschen
2017-11-13 15:46 ` [PATCH 6/6] Cygwin: ___getreent: Expose assembler inline implementation into userspace Corinna Vinschen
2017-11-13 15:46 ` [PATCH 2/6] newlib: ctype.h: Remove empty #if block Corinna Vinschen
2017-11-13 15:46 ` [PATCH 1/6] reent: Initialize _locale pointer with &__globale_locale Corinna Vinschen
2017-11-13 15:52 ` [PATCH 4/6] Cygwin: expose CYGTLS_PADSIZE as __CYGTLS_PADSIZE in userspace Corinna Vinschen
2017-11-13 15:59 ` [PATCH 3/6] newlib: Expose locale structs and function in new header sys/_locale.h Corinna Vinschen
2017-11-13 20:02 ` [PATCH 0/6] newlib/Cygwin: Allow more inlining of locale_t stuff Corinna Vinschen
2017-11-14  7:56   ` Sebastian Huber
2017-11-14  9:19     ` Corinna Vinschen

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