Re: [PATCH] Simple testsuite for MIG.

2016-03-29 Thread Justus Winter
Quoting Flavio Cruz (2016-03-25 17:19:06)
> This includes a set of valid and invalid definition files that MIG will
> try to process. For valid definitions, GCC will compile the stubs to
> check if valid C code was generated.
> 
> * configure.ac: Add new test Makefiles.
> * Makefile.am: Add SUBDIRS.
> * tests/Makeconf.am: Automake definitions shared by all test subdirectories.
> * tests/test_lib.sh: Library of functions shared by all test drivers.
> * tests/good/run_good_test.sh: Script to run valid definition files.
> * tests/good/Makefile.am: New file.
> * tests/bad/run_bad_test.sh: Script to run invalid definition files.
> * tests/bad/Makefile.am: New file.
> * tests/generate-only/run_generate_only.sh: Script to run valid
> definition files that should be generated only.
> * tests/generate-only/Makefile.am: New file.
> * tests/includes/*.h: Test header files that are included by test stubs.
> * tests/good/*.defs: Valid definition files where generated stubs can
> be compiled.
> * tests/generate_only/*.defs: Valid definition files that can be
> generated but no compilation should be attempted.
> * tests/bad/*.defs: Definition files with some mistakes that should be
> recognized by MIG.
> ---
> 
> Hey,
> 
> On Wed, Mar 23, 2016 at 11:17:03AM +0100, Justus Winter wrote:
> > Quoting Flavio Cruz (2016-03-23 01:31:13)
> > > This includes a set of valid and invalid definition files that MIG will
> > > try to process. For valid definitions, GCC will compile the stubs to
> > > check if valid C code was generated.
> > 
> > Love the idea, but 1/ this breaks out of tree (vpath) builds, 2/ I
> > believe the traditional GNU make target for tests is 'check', 3/ the
> > test suite fails on Linux b/c of missing mach/mig_support.h, finally
> > 4/ automake has a test driver that might be useful.
> 
> Thanks for the comments! I think I have addressed all of them. Let me
> know if there's anything else missing.

Awesome!  Unfortunately:


   GNU MIG 1.6: tests/good/test-suite.log
   

# TOTAL: 7
# PASS:  6
# SKIP:  0
# XFAIL: 0
# FAIL:  1
# XPASS: 0
# ERROR: 0

.. contents:: :depth: 2

FAIL: import


Generating stubs for import...
Compiling stubs for import...
import-server.c:42:20: fatal error: server.h: No such file or directory
compilation terminated.
ERROR: Could not compile stubs for import
FAIL import.defs (exit status: 1)

Justus



Re: [PATCH,boehm-gc] Use mmap instead of brk on kfreebsd & hurd too

2016-03-29 Thread Thomas Schwinge
Hi!

On Sun, 31 Aug 2014 17:20:04 +0200, Samuel Thibault  
wrote:
> Please use mmap instead of brk on kfreebsd and hurd too.
> Also, using anonymous memory is faster on the Hurd.

> [patch]

Thanks; finally committed in r234534:

commit 04a4d1ce0425912054b6f8db5bc15029bf87e055
Author: tschwinge 
Date:   Tue Mar 29 21:05:07 2016 +

[Hurd, kFreeBSD] boehm-gc: Use mmap instead of brk

boehm-gc/
* configure.host: Set gc_use_mmap on *-kfreebsd-gnu* and *-gnu*.
* include/private/gcconfig.h [HURD && USE_MMAP]: Define
USE_MMAP_ANON.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@234534 
138bc75d-0d04-0410-961f-82ee72b054a4
---
 boehm-gc/ChangeLog  | 6 ++
 boehm-gc/configure.host | 2 +-
 boehm-gc/include/private/gcconfig.h | 2 +-
 3 files changed, 8 insertions(+), 2 deletions(-)

diff --git boehm-gc/ChangeLog boehm-gc/ChangeLog
index c41734a..6896c67 100644
--- boehm-gc/ChangeLog
+++ boehm-gc/ChangeLog
@@ -1,3 +1,9 @@
+2016-03-29  Samuel Thibault  
+
+   * configure.host: Set gc_use_mmap on *-kfreebsd-gnu* and *-gnu*.
+   * include/private/gcconfig.h [HURD && USE_MMAP]: Define
+   USE_MMAP_ANON.
+
 2016-03-16  Andreas Schwab  
 
* include/private/gcconfig.h [AARCH64] (ALIGNMENT, CPP_WORDSZ):
diff --git boehm-gc/configure.host boehm-gc/configure.host
index 97f4dac..229a038 100644
--- boehm-gc/configure.host
+++ boehm-gc/configure.host
@@ -41,7 +41,7 @@ else
 fi
 
 case "${host}" in
-  *-linux*)
+  *-linux*|*-kfreebsd-gnu*|*-gnu*)
 gc_use_mmap=yes
 ;;
 esac
diff --git boehm-gc/include/private/gcconfig.h 
boehm-gc/include/private/gcconfig.h
index aa81f15..44b9d7d 100644
--- boehm-gc/include/private/gcconfig.h
+++ boehm-gc/include/private/gcconfig.h
@@ -2137,7 +2137,7 @@
 #   endif
 # endif
 
-#if defined(LINUX) && defined(USE_MMAP)
+#if (defined(LINUX) || defined(HURD)) && defined(USE_MMAP)
 /* The kernel may do a somewhat better job merging mappings etc.   */
 /* with anonymous mappings.
*/
 #   define USE_MMAP_ANON


Grüße
 Thomas


signature.asc
Description: PGP signature


Re: [PATCH] hurd: align -p and -pg behavior on Linux

2016-03-29 Thread Thomas Schwinge
Hi!

On Wed, 24 Feb 2016 23:46:36 +0100, I wrote:
> On Sat, 19 Sep 2015 14:00:23 +0200, Samuel Thibault  
> wrote:
> > On Linux, -p and -pg do not make gcc link against libc_p.a, only
> > -profile does (as documented in r11246), and thus people expect -p
> 
> (Yo, 20 years ago...)
> 
> > and -pg to work without libc_p.a installed (it is actually even not
> > available any more in Debian).  We should thus rather make the Hurd port
> > do the same to avoid build failures.
> 
> Conceptually, ACK.

> I'm now testing the following patch:

Now committed in r234535:

commit 9b2eb5d3268cf674f9a6964479f20428e0b43500
Author: tschwinge 
Date:   Tue Mar 29 21:17:53 2016 +

[Hurd] Specs maintenance

gcc/
* config/gnu.h (CPP_SPEC, LIB_SPEC): Don't override.
* config/i386/gnu.h (STARTFILE_SPEC): Use gcrt1.o instead of
gcrt0.o if linking dynamically.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@234535 
138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/ChangeLog | 6 ++
 gcc/config/gnu.h  | 8 
 gcc/config/i386/gnu.h | 4 ++--
 3 files changed, 8 insertions(+), 10 deletions(-)

diff --git gcc/ChangeLog gcc/ChangeLog
index 866531f..37e2504 100644
--- gcc/ChangeLog
+++ gcc/ChangeLog
@@ -1,3 +1,9 @@
+2016-03-29  Thomas Schwinge  
+
+   * config/gnu.h (CPP_SPEC, LIB_SPEC): Don't override.
+   * config/i386/gnu.h (STARTFILE_SPEC): Use gcrt1.o instead of
+   gcrt0.o if linking dynamically.
+
 2016-03-10  Jan Hubicka  
 
PR ipa/70283
diff --git gcc/config/gnu.h gcc/config/gnu.h
index 1d98ec8..1dbecda 100644
--- gcc/config/gnu.h
+++ gcc/config/gnu.h
@@ -19,14 +19,6 @@ You should have received a copy of the GNU General Public 
License
 along with GCC.  If not, see .
 */
 
-/* Provide GCC options for standard feature-test macros.  */
-#undef CPP_SPEC
-#define CPP_SPEC "%{posix:-D_POSIX_SOURCE}"
-
-/* Default C library spec.  */
-#undef LIB_SPEC
-#define LIB_SPEC "%{pthread:-lpthread} %{pg|p|profile:-lc_p;:-lc}"
-
 #undef GNU_USER_TARGET_OS_CPP_BUILTINS
 #define GNU_USER_TARGET_OS_CPP_BUILTINS()  \
 do {   \
diff --git gcc/config/i386/gnu.h gcc/config/i386/gnu.h
index c726d31..9d2f94f 100644
--- gcc/config/i386/gnu.h
+++ gcc/config/i386/gnu.h
@@ -27,11 +27,11 @@ along with GCC.  If not, see .
 #undef STARTFILE_SPEC
 #if defined HAVE_LD_PIE
 #define STARTFILE_SPEC \
-  "%{!shared: 
%{pg|p|profile:gcrt0.o%s;pie:Scrt1.o%s;static:crt0.o%s;:crt1.o%s}} \
+  "%{!shared: 
%{pg|p|profile:%{static:gcrt0.o%s;:gcrt1.o%s};pie:Scrt1.o%s;static:crt0.o%s;:crt1.o%s}}
 \
crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s}"
 #else
 #define STARTFILE_SPEC \
-  "%{!shared: %{pg|p|profile:gcrt0.o%s;static:crt0.o%s;:crt1.o%s}} \
+  "%{!shared: 
%{pg|p|profile:%{static:gcrt0.o%s;:gcrt1.o%s};static:crt0.o%s;:crt1.o%s}} \
crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s}"
 #endif
 


Grüße
 Thomas


signature.asc
Description: PGP signature


Re: [PATCH] hurd: align -p and -pg behavior on Linux

2016-03-29 Thread Samuel Thibault
Hello,

Thomas Schwinge, on Tue 29 Mar 2016 23:19:09 +0200, wrote:
> On Wed, 24 Feb 2016 23:46:36 +0100, I wrote:
> > On Sat, 19 Sep 2015 14:00:23 +0200, Samuel Thibault 
> >  wrote:
> > > On Linux, -p and -pg do not make gcc link against libc_p.a, only
> > > -profile does (as documented in r11246), and thus people expect -p
> > 
> > (Yo, 20 years ago...)
> > 
> > > and -pg to work without libc_p.a installed (it is actually even not
> > > available any more in Debian).  We should thus rather make the Hurd port
> > > do the same to avoid build failures.
> > 
> > Conceptually, ACK.
> 
> > I'm now testing the following patch:
> 
> Now committed in r234535:

Groovy :)

Could you also commit to gcc 5 branches so we get it in Debian without
having to poke Doko?

Samuel



[PATCH mig] Robustness fix.

2016-03-29 Thread Justus Winter
---
 tests/includes/all.h| 1 +
 tests/includes/server.h | 1 +
 tests/includes/user.h   | 1 +
 3 files changed, 3 insertions(+)

diff --git a/tests/includes/all.h b/tests/includes/all.h
index e69de29..6e25b02 100644
--- a/tests/includes/all.h
+++ b/tests/includes/all.h
@@ -0,0 +1 @@
+/* Empty.  */
diff --git a/tests/includes/server.h b/tests/includes/server.h
index e69de29..6e25b02 100644
--- a/tests/includes/server.h
+++ b/tests/includes/server.h
@@ -0,0 +1 @@
+/* Empty.  */
diff --git a/tests/includes/user.h b/tests/includes/user.h
index e69de29..6e25b02 100644
--- a/tests/includes/user.h
+++ b/tests/includes/user.h
@@ -0,0 +1 @@
+/* Empty.  */
-- 
2.1.4




Re: [PATCH] Simple testsuite for MIG.

2016-03-29 Thread Justus Winter
I like it a lot.  May I suggest the following robustness fix?  Seems
like the empty files are lost somewhere in my ci/package building
setup.  Also I think we want copyright notices at least in the
framework files, not sure about the test vectors.  Thougths?

Justus





Re: [PATCH] Use uint32_t instead of unsigned32_t.

2016-03-29 Thread Flavio Cruz
Implement stdint.h and use it in gnumach.

Remove old type definitions such as signed* and unsigned*.

* Makefile.am: Add -ffreestanding.
* i386/i386/xen.h: Use uint64_t.
* i386/include/mach/i386/machine_types.defs: Use uint32_t and int32_t.
* i386/include/mach/i386/vm_types.h: Remove definitions of int*, uint*,
unsigned* and signed* types.
* i386/xen/xen.c: Use uint64_t.
* include/device/device_types.defs: Use uint32_t.
* include/mach/std_types.defs: Use POSIX types.
* include/mach/std_types.h: Include stdint.h.
* include/stdint.h: New file with POSIX types.
* include/sys/types.h: Include stdint.h.
* ipc/ipc_kmsg.c: Use uint64_t.
* kern/exception.c: Use uint32_t.
* linux/dev/include/linux/types.h: Remove POSIX types.
* xen/block.c: Use uint64_t.
* xen/net.c: Do not use removed unsigned*_t types.
* xen/ring.h: Use uint32_t instead.
* xen/store.c: Use uint32_t.
* xen/store.h: Use uint32_t.
* xen/time.c: Use POSIX types only.
* xen/time.h: Use uint64_t.
---
On Mon, Mar 28, 2016 at 10:59:48PM +0200, Samuel Thibault wrote:
> Samuel Thibault, on Tue 22 Mar 2016 23:32:40 +0100, wrote:
> > Flavio Cruz, on Sun 20 Mar 2016 22:01:10 +0100, wrote:
> > > I've tried to compile GNU Mach using stdint.h and
> > > -ffreestanding and so far so good, however I'm not sure if removing
> > > -nostdinc is a good idea since we may include some files from
> > > /usr/include that should not included (things like sys/types.h and
> > > sys/time.h which are implemented in gnumach/include).
> > 
> > Thinking again, perhaps we should just have our own posix-compliant
> > include/stdint.h (just like we have stddef.h and string.h), used for
> > kernel build, and installed headers can use the system's stdint.h
> 
> ping?
> 
> Samuel

Hey

Here's the updated gnumach patch with a "homegrown" stdint.h. Let me
know what you think.

diff --git a/Makefile.am b/Makefile.am
index 1c1bfff..bbcfc11 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -42,7 +42,7 @@ AM_LDFLAGS =
 #
 
 AM_CPPFLAGS += \
-   -nostdinc -imacros config.h
+   -ffreestanding -nostdinc -imacros config.h
 
 AM_CPPFLAGS += \
-I$(systype) \
diff --git a/i386/i386/xen.h b/i386/i386/xen.h
index c681187..49b0d52 100644
--- a/i386/i386/xen.h
+++ b/i386/i386/xen.h
@@ -356,8 +356,8 @@ _hypcall2(int, set_debugreg, int, reg, unsigned long, 
value);
 _hypcall1(unsigned long, get_debugreg, int, reg);
 
 /* x86-specific */
-MACH_INLINE unsigned64_t hyp_cpu_clock(void) {
-   unsigned64_t tsc;
+MACH_INLINE uint64_t hyp_cpu_clock(void) {
+   uint64_t tsc;
asm volatile("rdtsc":"=A"(tsc));
return tsc;
 }
diff --git a/i386/include/mach/i386/machine_types.defs 
b/i386/include/mach/i386/machine_types.defs
index 6ac17cf..6ff93db 100755
--- a/i386/include/mach/i386/machine_types.defs
+++ b/i386/include/mach/i386/machine_types.defs
@@ -47,7 +47,7 @@
  * a port in user space as an integer and
  * in kernel space as a pointer.
  */
-type natural_t = unsigned32;
+type natural_t = uint32_t;
 
 /*
  * An integer_t is the signed counterpart
@@ -56,6 +56,6 @@ type natural_t = unsigned32;
  * other types in a machine-independent
  * way.
  */
-type integer_t = int32;
+type integer_t = int32_t;
 
 #endif /* _MACHINE_MACHINE_TYPES_DEFS_ */
diff --git a/i386/include/mach/i386/vm_types.h 
b/i386/include/mach/i386/vm_types.h
index 4a58b1c..4e259f9 100644
--- a/i386/include/mach/i386/vm_types.h
+++ b/i386/include/mach/i386/vm_types.h
@@ -59,16 +59,6 @@ typedef unsigned int natural_t;
  */
 typedef intinteger_t;
 
-#ifndef _POSIX_SOURCE
-
-/*
- * An int32 is an integer that is at least 32 bits wide
- */
-typedef intint32;
-typedef unsigned int   uint32;
-
-#endif /* _POSIX_SOURCE */
-
 /*
  * A vm_offset_t is a type-neutral pointer,
  * e.g. an offset into a virtual memory space.
@@ -92,20 +82,6 @@ typedef unsigned long phys_addr_t;
  */
 typedefnatural_t   vm_size_t;
 
-/*
- * These types are _exactly_ as wide as indicated in their names.
- */
-typedef signed charsigned8_t;
-typedef signed short   signed16_t;
-typedef signed int signed32_t;
-typedef signed long long   signed64_t;
-typedef unsigned char  unsigned8_t;
-typedef unsigned short unsigned16_t;
-typedef unsigned int   unsigned32_t;
-typedef unsigned long long unsigned64_t;
-typedef float  float32_t;
-typedef double float64_t;
-
 #endif /* __ASSEMBLER__ */
 
 /*
diff --git a/i386/xen/xen.c b/i386/xen/xen.c
index a46ee2c..44d37e6 100644
--- a/i386/xen/xen.c
+++ b/i386/xen/xen.c
@@ -46,7 +46,7 @@ void hyp_failsafe_c_callback(struct failsafe_callback_regs 
*regs) {
 
 extern void return_to_iret;
 
-void hypclock_machine_intr(int old_ipl, void *ret_addr, struct 
i386_interrupt_state *regs, unsigned64_t delta) {
+void hypclock_machine_intr(int old_ipl, void *ret_addr, struct 
i386_interrupt_state *regs, uint64_t delta) {
if (ret_addr == &return_to_iret) {
clock_interrupt(del

Re: [PATCH] Simple testsuite for MIG.

2016-03-29 Thread Flavio Cruz
On Wed, Mar 30, 2016 at 01:41:17AM +0200, Justus Winter wrote:
> I like it a lot.  May I suggest the following robustness fix?  Seems
> like the empty files are lost somewhere in my ci/package building
> setup.  Also I think we want copyright notices at least in the
> framework files, not sure about the test vectors.  Thougths?

Sure. I agree that empty files are a bad idea. I'll let Samuel make the
call about copyright notices and then I'll resubmit the patch.

Flavio



Re: RFC: Lightweight synchronization mechanism for gnumach v2.0

2016-03-29 Thread Agustina Arzille

Hello, Samuel

On 03/28/2016 06:29 PM, Samuel Thibault wrote:

Agustina Arzille, on Fri 04 Mar 2016 11:32:10 -0300, wrote:

+#define GSYNC_NBUCKETS   512
+static struct gsync_hbucket gsync_buckets[GSYNC_NBUCKETS];

I'm wondering whether we could want to have buckets per task too?  What
does Linux do for private futexes?  Is 512 enough?  How much does Linux
use?

(not saying that we need this for commiting, rather for future work).


I actually started out with separate hash tables: One for process-local
objects, and a global one for shared gsync. However, after doing some
benchmarking, I found out that it wasn't more efficient, and it also
cluttered up the code. So I ended unifying both into a single table.

512 is simply a magic number that I found out to work fairly well without
being too big. I suppose we could run more tests and find a more
appropriate number.

As for Linux, they too use a global hash table, but its size is determined
by the number of CPUs (The actual size is 256 * NCPUS).


+static int
+valid_access_p (vm_map_t map, vm_offset_t addr,
+  vm_offset_t size, vm_prot_t prot)
+{
+  vm_map_entry_t entry;
+  return (vm_map_lookup_entry (map, addr, &entry) &&
+entry->vme_end >= addr + size &&
+(prot & entry->protection) == prot);
+}

Mmm, userland could be running gsync_wait in one thread, and munmap
in another thread, and make the kernel crash because munmap() got
effect beween the valid_access_p check and the actually dereference
in gsync_wait. I believe you need a vm_map_lock_read(current_map());
vm_map_unlock_read(current_map()); around the valid_access_p + actual
access part (and the same for wake and requeue).


Good catch. There's an issue, however:
For shared gsync objects, I'm using vm_map_lookup to find out the
vm object and offset. The problem is that said function expects the map
to be unlocked; as such, we still have that race. A simple workaround is
to do valid_access_p *again* after vm_map_lookup returns (It should be
faster since the vm hint should be set by then). However, it's a bit ugly.
I can't think of a better solution, though, and I have to admit I understand
very little about the vm system.


+  /* XXX: These codes aren't really descriptive, but it's
+   * the best I can think of right now. */
+  ret = ret == THREAD_INTERRUPTED ?
+KERN_ABORTED : KERN_TERMINATED;

I'd say invent new KERN_* values: neither ABORTED nor TERMINATED really
match the two cases happening here.


Will do.


+  simple_lock (&hbp->lock);
+
+  if (flags & GSYNC_MUTATE)
+__atomic_store_n ((unsigned int *)addr,
+  val, __ATOMIC_RELEASE);

Why using an atomic operation? AIUI, simple_lock already provides
atomicity.  You'd need atomic flags on the reader side too to really get
proper semantic actually.


It was mostly to enforce some ordering, but you're right in that it's
useless given the use of simple locks.


+   * Setting the amount to UINT_MAX
+   * should do the trick until we can manage a ridiculously
+   * large amount of waiters. */
+  unsigned int nw = (flags & GSYNC_BROADCAST) ? ~0U : 1;

[...]

+  while (--nw != 0 && !list_end (&hbp->entries, runp) &&
+gsync_key_eq (&node_to_waiter(runp)->key, &w.key));

It doesn't seem too costly to me to do instead


+  while ( (flags & GSYNC_BROADCAST || --nw != 0) && !list_end (&hbp->entries, 
runp) &&

Which avoids to introduce the not-so-happy trick altogether (and some
for requeue)


Yeah, I ended up simplifying things a bit with this.


+  else if ((unsigned long)bp1 < (unsigned long)bp2)
+{
+  simple_unlock (&bp2->lock);
+  simple_unlock (&bp1->lock);
+}
+  else
+{
+  simple_unlock (&bp1->lock);
+  simple_unlock (&bp2->lock);
+}

There's no real need to order unlocking, but why not :)


A pointless micro-optimization. It's gone now.


Thanks for your work!

BTW, how is your copyright assignment going?
Samuel


Slow. I sent the letter about 20 days ago, still no answer.

Anyway, here's the new patch. If someone knows of a better solution for
the vm_map_lookup issue as explained above, I'll gladly implement it.

diff --git a/Makefrag.am b/Makefrag.am
index 823ece5..94189e6 100644
--- a/Makefrag.am
+++ b/Makefrag.am
@@ -144,6 +144,8 @@ libkernel_a_SOURCES += \
kern/eventcount.h \
kern/exception.c \
kern/exception.h \
+   kern/gsync.c \
+   kern/gsync.h \
kern/host.c \
kern/host.h \
kern/ipc_host.c \
diff --git a/include/mach/gnumach.defs b/include/mach/gnumach.defs
index dd4da87..ad6aa88 100644
--- a/include/mach/gnumach.defs
+++ b/include/mach/gnumach.defs
@@ -84,3 +84,55 @@ simpleroutine task_set_name(
 routine register_new_task_notification(
host_priv   : host_priv_t;
notification: mach_port_send_t);
+
+/* Test that the contents of ADDR are equal to the 32-bit integer VAL1.
+ * If they are not, return immediately, otherwise, block until a
+ * matching 'gsync_wake' is do