[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[PATCH] couple of small bugs



This patch fixes two bugs.  The first is a simple uninitialized
variable an the second is a powerpc specific data consistancy
problem.

Also, I am unable to figure out how internal locks (like the
stack_cache_lock) are guaranteed to be in a consistant state in a
child process.  Would it be useful to register (via __register_atfork)
pre and post fork routines that lock and unlock all of these locks to
ensure consitancy in the child of the lock values and the data they
protect?


This is my first submitted patch, so if the format is incorrect let me
know and I will correct it next time.
-------------------------------------------

# This is a BitKeeper generated patch for the following project:
# Project Name: nptl
# This patch format is intended for GNU patch command version 2.5 or higher.
# This patch includes the following deltas:
#	           ChangeSet	1.2     -> 1.5
#	nptl/sysdeps/unix/sysv/linux/powerpc/lowlevellock.h	1.1     -> 1.3
#	nptl/pthread_setconcurrency.c	1.1     -> 1.3
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 03/07/24	jschopp threadlp13 austin ibm com	1.3
# Fixed a bug in lll_mutex_unlock and lll_mutex_unlock_force
# --------------------------------------------
# 03/07/24	jschopp threadlp13 austin ibm com	1.4
# initialized uninitialized variable __concurrency_level
# --------------------------------------------
# 03/07/24	jschopp threadlp13 austin ibm com	1.5
# Update the origins for previous bug fixes.
# --------------------------------------------
#
diff -Nru a/nptl/pthread_setconcurrency.c b/nptl/pthread_setconcurrency.c
--- a/nptl/pthread_setconcurrency.c	Thu Jul 24 17:23:51 2003
+++ b/nptl/pthread_setconcurrency.c	Thu Jul 24 17:23:51 2003
@@ -1,6 +1,7 @@
 /* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper redhat com>, 2002.
+                  Joel Schopp <jschopp us ibm com>, 2003.

    The GNU C Library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
@@ -22,7 +23,9 @@


 /* Global definition.  Needed in pthread_getconcurrency as well.  */
-int __concurrency_level;
+/* Standards say if the pthread_setconcurrency function was not
+ * called return 0 */
+int __concurrency_level = 0;


 int
diff -Nru a/nptl/sysdeps/unix/sysv/linux/powerpc/lowlevellock.h b/nptl/sysdeps/unix/sysv/linux/powerpc/lowlevellock.h
--- libc/nptl/sysdeps/unix/sysv/linux/powerpc/lowlevellock.h	Thu Jul 24 17:23:51 2003
+++ libc/nptl/sysdeps/unix/sysv/linux/powerpc/lowlevellock.h	Thu Jul 24 17:23:51 2003
@@ -1,6 +1,7 @@
 /* Copyright (C) 2003 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Paul Mackerras <paulus au ibm com>, 2003.
+                  Joel Schopp <jschopp us ibm com>, 2003.

    The GNU C Library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
@@ -75,12 +76,26 @@
     INTERNAL_SYSCALL_ERROR_P (__ret, __err) ? -__ret : __ret;		      \
   })

+/* lwsync is exactly like sync for all pre Power4 architectures
+ * for Power4 and greater it is a lot like sync but different
+ * enough to have much written about the differences.  I will skip
+ * the dissertation here and simply say that using lwsync instead
+ * of sync in locks means that 1. all data read under locks is
+ * guaranteed to be consistant 2. data read not under a lock has
+ * a remote chance of being stale on another processor even after
+ * the lwsync has occured.  lwsync has the advantage of being faster
+ * compared to sync.  Those who gave us lwsync intended it to be
+ * used for unlocking locks.
+ */
+
 #ifdef UP
 # define __lll_acq_instr	""
 # define __lll_rel_instr	""
+# define __lll_rel_lw_instr     ""
 #else
 # define __lll_acq_instr	"isync"
 # define __lll_rel_instr	"sync"
+# define __lll_rel_lw_instr     "lwsync"
 #endif

 /* Set *futex to 1 if it is 0, atomically.  Returns the old value */
@@ -139,7 +154,9 @@
 #define lll_mutex_unlock(lock) \
   ((void) ({								      \
     int *__futex = &(lock);						      \
-    int __val = atomic_exchange_rel (__futex, 0);			      \
+    int __val;                                                                \
+    __asm __volatile (__lll_rel_lw_instr ::: "memory");			      \
+    __val = atomic_exchange_rel (__futex, 0);              		      \
     if (__builtin_expect (__val > 1, 0))				      \
       lll_futex_wake (__futex, 1);					      \
   }))
@@ -147,6 +164,7 @@
 #define lll_mutex_unlock_force(lock) \
   ((void) ({								      \
     int *__futex = &(lock);						      \
+    __asm __volatile (__lll_rel_lw_instr ::: "memory");			      \
     *__futex = 0;							      \
     lll_futex_wake (__futex, 1);					      \
   }))






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]