public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [libgo] Account for 32-bit fds_bits on Solaris 2
@ 2011-03-31 15:50 Rainer Orth
  2011-03-31 16:05 ` Ian Lance Taylor
  2011-03-31 20:53 ` Ian Lance Taylor
  0 siblings, 2 replies; 8+ messages in thread
From: Rainer Orth @ 2011-03-31 15:50 UTC (permalink / raw)
  To: gcc-patches; +Cc: Ian Lance Taylor

While debugging why several libgo tests on Solaris 2/SPARC were hanging
in select (cf. PR go/48242, go/48243), I found that fd_set is

typedef struct fd_set {
        long    fds_bits[__howmany(FD_SETSIZE, FD_NFDBITS)];
} fd_set;

The current implementation of the FD* funcs in sysfile_posix.go assumes
64-bit fds_bits.  While this doesn't make a difference on little-endian
hosts, on big-endian SPARC the wrong bits are set, leading to the
observed hang since there is no activity on those random fds.

The following patch fixes this by moving the FD* implementation to two
new sysfile_fdset{32, 64}.go files to fix this.  There's almost
certainly a cleaner/shorter implemenation, but this worked for me.
While the affected tests don't hang anymore now, they still don't finish
successfully, among others due to PR go/48222.

	Rainer


2011-03-24  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

	* syscalls/sysfile_posix.go (FdSet_t, FDSet, FDClr, FDIsSet)
	(FDZero): Move ...
	* syscalls/sysfile_fdset64.go: ... here.
	New file.
	* syscalls/sysfile_fdset32.go: New file.
	* Makefile.am (syscall_fdset_file): Use them.
	(go_syscall_files): Add $(syscall_fdset_file).
	* Makefile.in: Regenerate.

diff -r e65d996c30c7 libgo/Makefile.am
--- a/libgo/Makefile.am	Thu Mar 24 17:24:32 2011 +0100
+++ b/libgo/Makefile.am	Thu Mar 24 20:25:57 2011 +0100
@@ -1214,6 +1214,20 @@
 endif # !LIBGO_IS_SOLARIS
 endif # !LIBGO_IS_LINUX
 
+# Define for struct fd_set.
+if LIBGO_IS_SOLARIS
+if LIBGO_IS_386
+syscall_fdset_file = syscalls/sysfile_fdset32.go
+else # !LIBGO_IS_386
+if LIBGO_IS_SPARC
+syscall_fdset_file = syscalls/sysfile_fdset32.go
+else # !LIBGO_IS_386 && !LIBGO_IS_SPARC
+syscall_fdset_file = syscalls/sysfile_fdset64.go
+endif # !LIBGO_IS_386 && !LIBGO_IS_SPARC
+endif # !LIBGO_IS_386 && !LIBGO_IS_SPARC
+else # !LIBGO_IS_SOLARIS
+syscall_fdset_file = syscalls/sysfile_fdset64.go
+endif # !LIBGO_IS_SOLARIS
 
 # Define ForkExec, PtraceForkExec, Exec, and Waitpid.
 if LIBGO_IS_RTEMS
@@ -1307,6 +1321,7 @@
 	syscalls/syscall_$(GOOS).go \
 	$(GO_SYSCALLS_SYSCALL_OS_ARCH_FILE) \
 	syscalls/sysfile_posix.go \
+	$(syscall_fdset_file) \
 	sysinfo.go \
 	syscall_arch.go
 go_syscall_c_files = \
diff -r e65d996c30c7 libgo/syscalls/sysfile_fdset32.go
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libgo/syscalls/sysfile_fdset32.go	Thu Mar 24 20:25:57 2011 +0100
@@ -0,0 +1,35 @@
+// sysfile_fdset.go -- POSIX fd_set handling for 32-bit fds_bits.
+
+// Copyright 2010, 2011 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Support for struct fd_set.
+
+package syscall
+
+type FdSet_t struct {
+	Fds_bits [(FD_SETSIZE + 31) / 32]int32;
+}
+
+func FDSet(fd int, set *FdSet_t) {
+	set.Fds_bits[fd / 32] |= (1 << (uint)(fd % 32))
+}
+
+func FDClr(fd int, set *FdSet_t) {
+	set.Fds_bits[fd / 32] &= ^(1 << (uint)(fd % 32))
+}
+
+func FDIsSet(fd int, set *FdSet_t) bool {
+	if set.Fds_bits[fd / 32] & (1 << (uint)(fd % 32)) != 0 {
+		return true
+	} else {
+		return false
+	}
+}
+
+func FDZero(set *FdSet_t) {
+	for i := 0; i < ((FD_SETSIZE + 63) / 32); i++ {
+		set.Fds_bits[i] = 0
+	}
+}
diff -r e65d996c30c7 libgo/syscalls/sysfile_fdset64.go
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libgo/syscalls/sysfile_fdset64.go	Thu Mar 24 20:25:57 2011 +0100
@@ -0,0 +1,35 @@
+// sysfile_fdset.go -- POSIX fd_set handling for 64-bit fds_bits.
+
+// Copyright 2010, 2011 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Support for struct fd_set.
+
+package syscall
+
+type FdSet_t struct {
+	Fds_bits [(FD_SETSIZE + 63) / 64]int64;
+}
+
+func FDSet(fd int, set *FdSet_t) {
+	set.Fds_bits[fd / 64] |= (1 << (uint)(fd % 64))
+}
+
+func FDClr(fd int, set *FdSet_t) {
+	set.Fds_bits[fd / 64] &= ^(1 << (uint)(fd % 64))
+}
+
+func FDIsSet(fd int, set *FdSet_t) bool {
+	if set.Fds_bits[fd / 64] & (1 << (uint)(fd % 64)) != 0 {
+		return true
+	} else {
+		return false
+	}
+}
+
+func FDZero(set *FdSet_t) {
+	for i := 0; i < ((FD_SETSIZE + 63) / 64); i++ {
+		set.Fds_bits[i] = 0
+	}
+}
diff -r e65d996c30c7 libgo/syscalls/sysfile_posix.go
--- a/libgo/syscalls/sysfile_posix.go	Thu Mar 24 17:24:32 2011 +0100
+++ b/libgo/syscalls/sysfile_posix.go	Thu Mar 24 20:25:57 2011 +0100
@@ -181,32 +181,6 @@
   return;
 }
 
-type FdSet_t struct {
-	Fds_bits [(FD_SETSIZE + 63) / 64]int64;
-}
-
-func FDSet(fd int, set *FdSet_t) {
-	set.Fds_bits[fd / 64] |= (1 << (uint)(fd % 64))
-}
-
-func FDClr(fd int, set *FdSet_t) {
-	set.Fds_bits[fd / 64] &= ^(1 << (uint)(fd % 64))
-}
-
-func FDIsSet(fd int, set *FdSet_t) bool {
-	if set.Fds_bits[fd / 64] & (1 << (uint)(fd % 64)) != 0 {
-		return true
-	} else {
-		return false
-	}
-}
-
-func FDZero(set *FdSet_t) {
-	for i := 0; i < ((FD_SETSIZE + 63) / 64); i++ {
-		set.Fds_bits[i] = 0
-	}
-}
-
 func Select(nfds int, r *FdSet_t, w *FdSet_t, e *FdSet_t, timeout *Timeval) (n int, errno int) {
   n = libc_select(nfds, (*byte)(unsafe.Pointer(r)),
 		  (*byte)(unsafe.Pointer(e)),

-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University

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

* Re: [libgo] Account for 32-bit fds_bits on Solaris 2
  2011-03-31 15:50 [libgo] Account for 32-bit fds_bits on Solaris 2 Rainer Orth
@ 2011-03-31 16:05 ` Ian Lance Taylor
  2011-03-31 16:12   ` Rainer Orth
  2011-03-31 20:09   ` Richard Henderson
  2011-03-31 20:53 ` Ian Lance Taylor
  1 sibling, 2 replies; 8+ messages in thread
From: Ian Lance Taylor @ 2011-03-31 16:05 UTC (permalink / raw)
  To: Rainer Orth; +Cc: gcc-patches

Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE> writes:

> While debugging why several libgo tests on Solaris 2/SPARC were hanging
> in select (cf. PR go/48242, go/48243), I found that fd_set is
>
> typedef struct fd_set {
>         long    fds_bits[__howmany(FD_SETSIZE, FD_NFDBITS)];
> } fd_set;
>
> The current implementation of the FD* funcs in sysfile_posix.go assumes
> 64-bit fds_bits.  While this doesn't make a difference on little-endian
> hosts, on big-endian SPARC the wrong bits are set, leading to the
> observed hang since there is no activity on those random fds.
>
> The following patch fixes this by moving the FD* implementation to two
> new sysfile_fdset{32, 64}.go files to fix this.  There's almost
> certainly a cleaner/shorter implemenation, but this worked for me.
> While the affected tests don't hang anymore now, they still don't finish
> successfully, among others due to PR go/48222.

What an annoying problem.  Sorry about that.  But why don't we just
change to byte?

Ian

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

* Re: [libgo] Account for 32-bit fds_bits on Solaris 2
  2011-03-31 16:05 ` Ian Lance Taylor
@ 2011-03-31 16:12   ` Rainer Orth
  2011-03-31 20:09   ` Richard Henderson
  1 sibling, 0 replies; 8+ messages in thread
From: Rainer Orth @ 2011-03-31 16:12 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: gcc-patches

Ian Lance Taylor <iant@google.com> writes:

> What an annoying problem.  Sorry about that.  But why don't we just
> change to byte?

If this causes the right bits to be set for big and little-endian hosts,
certainly fine with me.  I haven't tried yet, but the less different
code paths, the better.

	Rainer

-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University

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

* Re: [libgo] Account for 32-bit fds_bits on Solaris 2
  2011-03-31 16:05 ` Ian Lance Taylor
  2011-03-31 16:12   ` Rainer Orth
@ 2011-03-31 20:09   ` Richard Henderson
  2011-03-31 20:12     ` Ian Lance Taylor
  1 sibling, 1 reply; 8+ messages in thread
From: Richard Henderson @ 2011-03-31 20:09 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: Rainer Orth, gcc-patches

On 03/31/2011 09:03 AM, Ian Lance Taylor wrote:
> What an annoying problem.  Sorry about that.  But why don't we just
> change to byte?

That would work for little-endian, but not big-endian, at least not
without even worse ugliness in two different files.


r~

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

* Re: [libgo] Account for 32-bit fds_bits on Solaris 2
  2011-03-31 20:09   ` Richard Henderson
@ 2011-03-31 20:12     ` Ian Lance Taylor
  0 siblings, 0 replies; 8+ messages in thread
From: Ian Lance Taylor @ 2011-03-31 20:12 UTC (permalink / raw)
  To: Richard Henderson; +Cc: Rainer Orth, gcc-patches

Richard Henderson <rth@redhat.com> writes:

> On 03/31/2011 09:03 AM, Ian Lance Taylor wrote:
>> What an annoying problem.  Sorry about that.  But why don't we just
>> change to byte?
>
> That would work for little-endian, but not big-endian, at least not
> without even worse ugliness in two different files.

Yeah, I figured that out.  Different systems use different sizes for the
bitfield.  Ugh.

Ian

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

* Re: [libgo] Account for 32-bit fds_bits on Solaris 2
  2011-03-31 15:50 [libgo] Account for 32-bit fds_bits on Solaris 2 Rainer Orth
  2011-03-31 16:05 ` Ian Lance Taylor
@ 2011-03-31 20:53 ` Ian Lance Taylor
  2011-04-01  7:53   ` Rainer Orth
  1 sibling, 1 reply; 8+ messages in thread
From: Ian Lance Taylor @ 2011-03-31 20:53 UTC (permalink / raw)
  To: Rainer Orth; +Cc: gcc-patches, gofrontend-dev

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

Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE> writes:

> While debugging why several libgo tests on Solaris 2/SPARC were hanging
> in select (cf. PR go/48242, go/48243), I found that fd_set is
>
> typedef struct fd_set {
>         long    fds_bits[__howmany(FD_SETSIZE, FD_NFDBITS)];
> } fd_set;
>
> The current implementation of the FD* funcs in sysfile_posix.go assumes
> 64-bit fds_bits.  While this doesn't make a difference on little-endian
> hosts, on big-endian SPARC the wrong bits are set, leading to the
> observed hang since there is no activity on those random fds.
>
> The following patch fixes this by moving the FD* implementation to two
> new sysfile_fdset{32, 64}.go files to fix this.  There's almost
> certainly a cleaner/shorter implemenation, but this worked for me.
> While the affected tests don't hang anymore now, they still don't finish
> successfully, among others due to PR go/48222.

Thanks.  I'm going to try gambling that every uses the type "long" for
the fds_bits array.  If so, I think this patch will work.  Bootstrapped
and ran Go testsuite on x86_64-unknown-linux-gnu (forcing the use of
select).  Committed to mainline.

Ian


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch --]
[-- Type: text/x-diff, Size: 1085 bytes --]

diff -r bc59115c58cf libgo/syscalls/sysfile_posix.go
--- a/libgo/syscalls/sysfile_posix.go	Thu Mar 31 09:48:32 2011 -0700
+++ b/libgo/syscalls/sysfile_posix.go	Thu Mar 31 13:35:30 2011 -0700
@@ -181,20 +181,22 @@
   return;
 }
 
+const nfdbits = unsafe.Sizeof(_C_long) * 8
+
 type FdSet_t struct {
-	Fds_bits [(FD_SETSIZE + 63) / 64]int64;
+	Fds_bits [(FD_SETSIZE + nfdbits - 1) / nfdbits]_C_long
 }
 
 func FDSet(fd int, set *FdSet_t) {
-	set.Fds_bits[fd / 64] |= (1 << (uint)(fd % 64))
+	set.Fds_bits[fd / nfdbits] |= (1 << (uint)(fd % nfdbits))
 }
 
 func FDClr(fd int, set *FdSet_t) {
-	set.Fds_bits[fd / 64] &= ^(1 << (uint)(fd % 64))
+	set.Fds_bits[fd / nfdbits] &^= (1 << (uint)(fd % nfdbits))
 }
 
 func FDIsSet(fd int, set *FdSet_t) bool {
-	if set.Fds_bits[fd / 64] & (1 << (uint)(fd % 64)) != 0 {
+	if set.Fds_bits[fd / nfdbits] & (1 << (uint)(fd % nfdbits)) != 0 {
 		return true
 	} else {
 		return false
@@ -202,7 +204,7 @@
 }
 
 func FDZero(set *FdSet_t) {
-	for i := 0; i < ((FD_SETSIZE + 63) / 64); i++ {
+	for i := range set.Fds_bits {
 		set.Fds_bits[i] = 0
 	}
 }

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

* Re: [libgo] Account for 32-bit fds_bits on Solaris 2
  2011-03-31 20:53 ` Ian Lance Taylor
@ 2011-04-01  7:53   ` Rainer Orth
  2011-04-01 22:54     ` Ian Lance Taylor
  0 siblings, 1 reply; 8+ messages in thread
From: Rainer Orth @ 2011-04-01  7:53 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: gcc-patches, gofrontend-dev

Ian Lance Taylor <iant@google.com> writes:

> Thanks.  I'm going to try gambling that every uses the type "long" for
> the fds_bits array.  If so, I think this patch will work.  Bootstrapped
> and ran Go testsuite on x86_64-unknown-linux-gnu (forcing the use of
> select).  Committed to mainline.

I fear you lost ;-)

* On Solaris, it's always long (i.e. either 32 or 64-bit).

* On IRIX 6.5, it's long for 32-bit and int for 64-bit (i.e. always
  32-bit), while 64-bit long is 64-bit.

* On Tru64 UNIX V5.1, it's always int (i.e. 32-bit), while long is
  64-bit.

This has to be system-dependent, I fear.

	Rainer

-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University

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

* Re: [libgo] Account for 32-bit fds_bits on Solaris 2
  2011-04-01  7:53   ` Rainer Orth
@ 2011-04-01 22:54     ` Ian Lance Taylor
  0 siblings, 0 replies; 8+ messages in thread
From: Ian Lance Taylor @ 2011-04-01 22:54 UTC (permalink / raw)
  To: Rainer Orth; +Cc: gcc-patches, gofrontend-dev

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

Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE> writes:

> Ian Lance Taylor <iant@google.com> writes:
>
>> Thanks.  I'm going to try gambling that every uses the type "long" for
>> the fds_bits array.  If so, I think this patch will work.  Bootstrapped
>> and ran Go testsuite on x86_64-unknown-linux-gnu (forcing the use of
>> select).  Committed to mainline.
>
> I fear you lost ;-)
>
> * On Solaris, it's always long (i.e. either 32 or 64-bit).
>
> * On IRIX 6.5, it's long for 32-bit and int for 64-bit (i.e. always
>   32-bit), while 64-bit long is 64-bit.
>
> * On Tru64 UNIX V5.1, it's always int (i.e. 32-bit), while long is
>   64-bit.
>
> This has to be system-dependent, I fear.

Bother.

OK, for my next attempt I committed the appended patch, in which
mksysinfo tries to guess the right type to use.  Let me know where this
fails.  Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu.
Committed to mainline.

Ian


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch --]
[-- Type: text/x-diff, Size: 1744 bytes --]

diff -r fa0bb5137d66 libgo/configure.ac
--- a/libgo/configure.ac	Thu Mar 31 22:09:27 2011 -0700
+++ b/libgo/configure.ac	Fri Apr 01 15:47:05 2011 -0700
@@ -417,7 +417,7 @@
   ;;
 esac
 
-AC_CHECK_HEADERS(sys/mman.h syscall.h sys/epoll.h sys/ptrace.h sys/syscall.h sys/user.h sys/utsname.h)
+AC_CHECK_HEADERS(sys/mman.h syscall.h sys/epoll.h sys/ptrace.h sys/syscall.h sys/user.h sys/utsname.h sys/select.h)
 AM_CONDITIONAL(HAVE_SYS_MMAN_H, test "$ac_cv_header_sys_mman_h" = yes)
 
 AC_CHECK_FUNCS(srandom random strerror_r strsignal wait4)
diff -r fa0bb5137d66 libgo/mksysinfo.sh
--- a/libgo/mksysinfo.sh	Thu Mar 31 22:09:27 2011 -0700
+++ b/libgo/mksysinfo.sh	Fri Apr 01 15:47:05 2011 -0700
@@ -73,6 +73,9 @@
 #if defined(HAVE_SYS_UTSNAME_H)
 #include <sys/utsname.h>
 #endif
+#if defined(HAVE_SYS_SELECT_H)
+#include <sys/select.h>
+#endif
 #include <unistd.h>
 EOF
 
@@ -438,4 +441,12 @@
       -e 's/_in_addr/[4]byte/g' \
     >> ${OUT}
 
+# Try to guess the type to use for fd_set.
+fd_set=`grep '^type _fd_set ' gen-sysinfo.go || true`
+fds_bits_type="_C_long"
+if test "$fd_set" != ""; then
+    fds_bits_type=`echo $fd_set | sed -e 's/.*[]]\([^;]*\); }$/\1/'`
+fi
+echo "type fds_bits_type $fds_bits_type" >> ${OUT}
+
 exit $?
diff -r fa0bb5137d66 libgo/syscalls/sysfile_posix.go
--- a/libgo/syscalls/sysfile_posix.go	Thu Mar 31 22:09:27 2011 -0700
+++ b/libgo/syscalls/sysfile_posix.go	Fri Apr 01 15:47:05 2011 -0700
@@ -181,10 +181,10 @@
   return;
 }
 
-const nfdbits = unsafe.Sizeof(_C_long) * 8
+const nfdbits = unsafe.Sizeof(fds_bits_type) * 8
 
 type FdSet_t struct {
-	Fds_bits [(FD_SETSIZE + nfdbits - 1) / nfdbits]_C_long
+	Fds_bits [(FD_SETSIZE + nfdbits - 1) / nfdbits]fds_bits_type
 }
 
 func FDSet(fd int, set *FdSet_t) {

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

end of thread, other threads:[~2011-04-01 22:54 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-31 15:50 [libgo] Account for 32-bit fds_bits on Solaris 2 Rainer Orth
2011-03-31 16:05 ` Ian Lance Taylor
2011-03-31 16:12   ` Rainer Orth
2011-03-31 20:09   ` Richard Henderson
2011-03-31 20:12     ` Ian Lance Taylor
2011-03-31 20:53 ` Ian Lance Taylor
2011-04-01  7:53   ` Rainer Orth
2011-04-01 22:54     ` Ian Lance Taylor

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