Re: Build kernels with -ffreestanding?

2016-12-24 Thread Joerg Sonnenberger
On Sat, Dec 24, 2016 at 12:08:35AM +0100, Mark Kettenis wrote:
> We can get those optimizations back by doing:
> 
> #define memcpy(d, s, n) __builtin_memcpy((d), (s), (n))

You might still want to put a prototype in, just before the define.

Joerg



Re: Build kernels with -ffreestanding?

2016-12-24 Thread Mark Kettenis
> Date: Sun, 25 Dec 2016 09:40:05 +1100
> From: Jonathan Gray 
> 
> On Sat, Dec 24, 2016 at 05:07:11PM +0100, Mark Kettenis wrote:
> > > Date: Sat, 24 Dec 2016 00:08:35 +0100 (CET)
> > > From: Mark Kettenis 
> > > 
> > > We already do this on some architectures, but not on amd64 for
> > > example.  The main reason is that this disables memcpy() optimizations
> > > that have a measurable impact on the network stack performance.
> > > 
> > > We can get those optimizations back by doing:
> > > 
> > > #define memcpy(d, s, n) __builtin_memcpy((d), (s), (n))
> > > 
> > > I verified that gcc still does proper bounds checking on
> > > __builtin_memcpy(), so we don't lose that.
> > > 
> > > The nice thing about this solution is that we can choose explicitly
> > > which optimizations we want.  And as you can see the kernel makefile
> > > gets simpler ;).
> > > 
> > > Of course the real reason why I'm looking into this is that clang
> > > makes it really hard to build kernels without -ffreestanding.
> > > 
> > > The diff below implements this strategy, and enabled the optimizations
> > > for memcpy() and memset().  We can add others if we think there is a
> > > benefit.  I've tested the diff on amd64.  We may need to put an #undef
> > > memcpy somewhere for platforms that use the generic C code for memcpy.
> > > 
> > > Thoughts?
> > 
> > So those #undefs are necessary.  New diff below.  Tested on armv7,
> > hppa and sparc64 now as well.

macppc tested now as well

> I agree this is the way we want to go.  It also avoids having
> to expand the list to -fno-builtin-free etc for newer versions of gcc.
> 
> Why build the memcpy/memset in libkern at all if we go this route?

__builtin_memcpy() may still expand to an explicit memset() call if
the compiler decides not to inline it.

> > Index: sys/systm.h
> > ===
> > RCS file: /cvs/src/sys/sys/systm.h,v
> > retrieving revision 1.119
> > diff -u -p -r1.119 systm.h
> > --- sys/systm.h 24 Sep 2016 18:35:52 -  1.119
> > +++ sys/systm.h 24 Dec 2016 16:05:48 -
> > @@ -306,6 +306,9 @@ extern int (*mountroot)(void);
> >  
> >  #include 
> >  
> > +#define memcpy(d, s, n) __builtin_memcpy((d), (s), (n))
> > +#define memset(b, c, n) __builtin_memset((b), (c), (n))
> > +
> >  #if defined(DDB) || defined(KGDB)
> >  /* debugger entry points */
> >  void   Debugger(void); /* in DDB only */
> > Index: lib/libkern/memcpy.c
> > ===
> > RCS file: /cvs/src/sys/lib/libkern/memcpy.c,v
> > retrieving revision 1.3
> > diff -u -p -r1.3 memcpy.c
> > --- lib/libkern/memcpy.c12 Jun 2013 16:44:22 -  1.3
> > +++ lib/libkern/memcpy.c24 Dec 2016 16:05:48 -
> > @@ -32,6 +32,8 @@
> >  #include 
> >  #include 
> >  
> > +#undef memcpy
> > +
> >  /*
> >   * This is designed to be small, not fast.
> >   */
> > Index: lib/libkern/memset.c
> > ===
> > RCS file: /cvs/src/sys/lib/libkern/memset.c,v
> > retrieving revision 1.7
> > diff -u -p -r1.7 memset.c
> > --- lib/libkern/memset.c10 Jun 2014 04:16:57 -  1.7
> > +++ lib/libkern/memset.c24 Dec 2016 16:05:48 -
> > @@ -39,6 +39,8 @@
> >  #include 
> >  #include 
> >  
> > +#undef memset
> > +
> >  #definewsize   sizeof(u_int)
> >  #definewmask   (wsize - 1)
> >  
> > Index: arch/amd64/conf/Makefile.amd64
> > ===
> > RCS file: /cvs/src/sys/arch/amd64/conf/Makefile.amd64,v
> > retrieving revision 1.74
> > diff -u -p -r1.74 Makefile.amd64
> > --- arch/amd64/conf/Makefile.amd64  29 Nov 2016 09:08:34 -  1.74
> > +++ arch/amd64/conf/Makefile.amd64  24 Dec 2016 16:05:49 -
> > @@ -29,9 +29,7 @@ CWARNFLAGS=   -Werror -Wall -Wimplicit-fun
> >  
> >  CMACHFLAGS=-mcmodel=kernel -mno-red-zone -mno-sse2 -mno-sse 
> > -mno-3dnow \
> > -mno-mmx -msoft-float -fno-omit-frame-pointer
> > -CMACHFLAGS+=   -fno-builtin-printf -fno-builtin-snprintf \
> > -   -fno-builtin-vsnprintf -fno-builtin-log \
> > -   -fno-builtin-log2 -fno-builtin-malloc ${NOPIE_FLAGS}
> > +CMACHFLAGS+=   -ffreestanding ${NOPIE_FLAGS}
> >  .if ${IDENT:M-DNO_PROPOLICE}
> >  CMACHFLAGS+=   -fno-stack-protector
> >  .endif
> > 
> 



Re: Build kernels with -ffreestanding?

2016-12-24 Thread Jonathan Gray
On Sat, Dec 24, 2016 at 05:07:11PM +0100, Mark Kettenis wrote:
> > Date: Sat, 24 Dec 2016 00:08:35 +0100 (CET)
> > From: Mark Kettenis 
> > 
> > We already do this on some architectures, but not on amd64 for
> > example.  The main reason is that this disables memcpy() optimizations
> > that have a measurable impact on the network stack performance.
> > 
> > We can get those optimizations back by doing:
> > 
> > #define memcpy(d, s, n) __builtin_memcpy((d), (s), (n))
> > 
> > I verified that gcc still does proper bounds checking on
> > __builtin_memcpy(), so we don't lose that.
> > 
> > The nice thing about this solution is that we can choose explicitly
> > which optimizations we want.  And as you can see the kernel makefile
> > gets simpler ;).
> > 
> > Of course the real reason why I'm looking into this is that clang
> > makes it really hard to build kernels without -ffreestanding.
> > 
> > The diff below implements this strategy, and enabled the optimizations
> > for memcpy() and memset().  We can add others if we think there is a
> > benefit.  I've tested the diff on amd64.  We may need to put an #undef
> > memcpy somewhere for platforms that use the generic C code for memcpy.
> > 
> > Thoughts?
> 
> So those #undefs are necessary.  New diff below.  Tested on armv7,
> hppa and sparc64 now as well.

I agree this is the way we want to go.  It also avoids having
to expand the list to -fno-builtin-free etc for newer versions of gcc.

Why build the memcpy/memset in libkern at all if we go this route?

> 
> Index: sys/systm.h
> ===
> RCS file: /cvs/src/sys/sys/systm.h,v
> retrieving revision 1.119
> diff -u -p -r1.119 systm.h
> --- sys/systm.h   24 Sep 2016 18:35:52 -  1.119
> +++ sys/systm.h   24 Dec 2016 16:05:48 -
> @@ -306,6 +306,9 @@ extern int (*mountroot)(void);
>  
>  #include 
>  
> +#define memcpy(d, s, n) __builtin_memcpy((d), (s), (n))
> +#define memset(b, c, n) __builtin_memset((b), (c), (n))
> +
>  #if defined(DDB) || defined(KGDB)
>  /* debugger entry points */
>  void Debugger(void); /* in DDB only */
> Index: lib/libkern/memcpy.c
> ===
> RCS file: /cvs/src/sys/lib/libkern/memcpy.c,v
> retrieving revision 1.3
> diff -u -p -r1.3 memcpy.c
> --- lib/libkern/memcpy.c  12 Jun 2013 16:44:22 -  1.3
> +++ lib/libkern/memcpy.c  24 Dec 2016 16:05:48 -
> @@ -32,6 +32,8 @@
>  #include 
>  #include 
>  
> +#undef memcpy
> +
>  /*
>   * This is designed to be small, not fast.
>   */
> Index: lib/libkern/memset.c
> ===
> RCS file: /cvs/src/sys/lib/libkern/memset.c,v
> retrieving revision 1.7
> diff -u -p -r1.7 memset.c
> --- lib/libkern/memset.c  10 Jun 2014 04:16:57 -  1.7
> +++ lib/libkern/memset.c  24 Dec 2016 16:05:48 -
> @@ -39,6 +39,8 @@
>  #include 
>  #include 
>  
> +#undef memset
> +
>  #define  wsize   sizeof(u_int)
>  #define  wmask   (wsize - 1)
>  
> Index: arch/amd64/conf/Makefile.amd64
> ===
> RCS file: /cvs/src/sys/arch/amd64/conf/Makefile.amd64,v
> retrieving revision 1.74
> diff -u -p -r1.74 Makefile.amd64
> --- arch/amd64/conf/Makefile.amd6429 Nov 2016 09:08:34 -  1.74
> +++ arch/amd64/conf/Makefile.amd6424 Dec 2016 16:05:49 -
> @@ -29,9 +29,7 @@ CWARNFLAGS= -Werror -Wall -Wimplicit-fun
>  
>  CMACHFLAGS=  -mcmodel=kernel -mno-red-zone -mno-sse2 -mno-sse -mno-3dnow \
>   -mno-mmx -msoft-float -fno-omit-frame-pointer
> -CMACHFLAGS+= -fno-builtin-printf -fno-builtin-snprintf \
> - -fno-builtin-vsnprintf -fno-builtin-log \
> - -fno-builtin-log2 -fno-builtin-malloc ${NOPIE_FLAGS}
> +CMACHFLAGS+= -ffreestanding ${NOPIE_FLAGS}
>  .if ${IDENT:M-DNO_PROPOLICE}
>  CMACHFLAGS+= -fno-stack-protector
>  .endif
> 



Re: ed(1) doesn't support adress ranges which begin with comma or semicolon

2016-12-24 Thread Theo Buehler
On Sat, Dec 24, 2016 at 05:44:07PM +0100, Jérôme FRGACIC wrote:
> Hi @tech,
> 
> I remark that ed(1) do not support adress ranges which begin with
> comma or semicolon, for example ",10p" which is equivalent to "1,10p" or
> "; +10p" which is equivalent to ".;+10p". These adress ranges are
> specified by Open Group Base Specifications Issue 6 (IEEE Std 1003.1,
> 2004 Edition) (in fact, there are also adress ranges like "10," which
> is equivalent to "10,10" but they seem useless to me...).
> 
> I would suggest this diff to add support for these adress ranges.

ok tb@

> Index: main.c
> ===
> RCS file: /cvs/src/bin/ed/main.c,v
> retrieving revision 1.58
> diff -u -r1.58 main.c
> --- main.c16 Aug 2016 20:04:46 -  1.58
> +++ main.c24 Dec 2016 15:26:41 -
> @@ -383,7 +383,9 @@
>   ibufp++;
>   addr_cnt++;
>   second_addr = (c == ';') ?
> current_addr : 1;
> - addr = addr_last;
> + addr = next_addr();
> + if (addr < 0)
> + addr = addr_last;
>   break;
>   }
>   /* FALLTHROUGH */
> 
> PS : I haven't subcribe to the tech mailing list, so please add me as
> recipient if you reply.
> PPS : Merry Christmas.
> 
> 
> Kind regards,
> 
> 
> Jérôme FRGACIC
> 



ed(1) doesn't support adress ranges which begin with comma or semicolon

2016-12-24 Thread Jérôme FRGACIC
Hi @tech,

I remark that ed(1) do not support adress ranges which begin with
comma or semicolon, for example ",10p" which is equivalent to "1,10p" or
"; +10p" which is equivalent to ".;+10p". These adress ranges are
specified by Open Group Base Specifications Issue 6 (IEEE Std 1003.1,
2004 Edition) (in fact, there are also adress ranges like "10," which
is equivalent to "10,10" but they seem useless to me...).

I would suggest this diff to add support for these adress ranges.

Index: main.c
===
RCS file: /cvs/src/bin/ed/main.c,v
retrieving revision 1.58
diff -u -r1.58 main.c
--- main.c  16 Aug 2016 20:04:46 -  1.58
+++ main.c  24 Dec 2016 15:26:41 -
@@ -383,7 +383,9 @@
ibufp++;
addr_cnt++;
second_addr = (c == ';') ?
current_addr : 1;
-   addr = addr_last;
+   addr = next_addr();
+   if (addr < 0)
+   addr = addr_last;
break;
}
/* FALLTHROUGH */

PS : I haven't subcribe to the tech mailing list, so please add me as
recipient if you reply.
PPS : Merry Christmas.


Kind regards,


Jérôme FRGACIC



Re: Build kernels with -ffreestanding?

2016-12-24 Thread Mark Kettenis
> Date: Sat, 24 Dec 2016 00:08:35 +0100 (CET)
> From: Mark Kettenis 
> 
> We already do this on some architectures, but not on amd64 for
> example.  The main reason is that this disables memcpy() optimizations
> that have a measurable impact on the network stack performance.
> 
> We can get those optimizations back by doing:
> 
> #define memcpy(d, s, n) __builtin_memcpy((d), (s), (n))
> 
> I verified that gcc still does proper bounds checking on
> __builtin_memcpy(), so we don't lose that.
> 
> The nice thing about this solution is that we can choose explicitly
> which optimizations we want.  And as you can see the kernel makefile
> gets simpler ;).
> 
> Of course the real reason why I'm looking into this is that clang
> makes it really hard to build kernels without -ffreestanding.
> 
> The diff below implements this strategy, and enabled the optimizations
> for memcpy() and memset().  We can add others if we think there is a
> benefit.  I've tested the diff on amd64.  We may need to put an #undef
> memcpy somewhere for platforms that use the generic C code for memcpy.
> 
> Thoughts?

So those #undefs are necessary.  New diff below.  Tested on armv7,
hppa and sparc64 now as well.

Index: sys/systm.h
===
RCS file: /cvs/src/sys/sys/systm.h,v
retrieving revision 1.119
diff -u -p -r1.119 systm.h
--- sys/systm.h 24 Sep 2016 18:35:52 -  1.119
+++ sys/systm.h 24 Dec 2016 16:05:48 -
@@ -306,6 +306,9 @@ extern int (*mountroot)(void);
 
 #include 
 
+#define memcpy(d, s, n) __builtin_memcpy((d), (s), (n))
+#define memset(b, c, n) __builtin_memset((b), (c), (n))
+
 #if defined(DDB) || defined(KGDB)
 /* debugger entry points */
 void   Debugger(void); /* in DDB only */
Index: lib/libkern/memcpy.c
===
RCS file: /cvs/src/sys/lib/libkern/memcpy.c,v
retrieving revision 1.3
diff -u -p -r1.3 memcpy.c
--- lib/libkern/memcpy.c12 Jun 2013 16:44:22 -  1.3
+++ lib/libkern/memcpy.c24 Dec 2016 16:05:48 -
@@ -32,6 +32,8 @@
 #include 
 #include 
 
+#undef memcpy
+
 /*
  * This is designed to be small, not fast.
  */
Index: lib/libkern/memset.c
===
RCS file: /cvs/src/sys/lib/libkern/memset.c,v
retrieving revision 1.7
diff -u -p -r1.7 memset.c
--- lib/libkern/memset.c10 Jun 2014 04:16:57 -  1.7
+++ lib/libkern/memset.c24 Dec 2016 16:05:48 -
@@ -39,6 +39,8 @@
 #include 
 #include 
 
+#undef memset
+
 #definewsize   sizeof(u_int)
 #definewmask   (wsize - 1)
 
Index: arch/amd64/conf/Makefile.amd64
===
RCS file: /cvs/src/sys/arch/amd64/conf/Makefile.amd64,v
retrieving revision 1.74
diff -u -p -r1.74 Makefile.amd64
--- arch/amd64/conf/Makefile.amd64  29 Nov 2016 09:08:34 -  1.74
+++ arch/amd64/conf/Makefile.amd64  24 Dec 2016 16:05:49 -
@@ -29,9 +29,7 @@ CWARNFLAGS=   -Werror -Wall -Wimplicit-fun
 
 CMACHFLAGS=-mcmodel=kernel -mno-red-zone -mno-sse2 -mno-sse -mno-3dnow \
-mno-mmx -msoft-float -fno-omit-frame-pointer
-CMACHFLAGS+=   -fno-builtin-printf -fno-builtin-snprintf \
-   -fno-builtin-vsnprintf -fno-builtin-log \
-   -fno-builtin-log2 -fno-builtin-malloc ${NOPIE_FLAGS}
+CMACHFLAGS+=   -ffreestanding ${NOPIE_FLAGS}
 .if ${IDENT:M-DNO_PROPOLICE}
 CMACHFLAGS+=   -fno-stack-protector
 .endif



Re: ospfd - add metric and type to print_redistribute

2016-12-24 Thread Stefan Sperling
On Fri, Dec 23, 2016 at 11:06:34PM +0100, Jeremie Courreges-Anglas wrote:
> Same diff for ospf6d, ok?

Yes. OK.

> Index: printconf.c
> ===
> RCS file: /d/cvs/src/usr.sbin/ospf6d/printconf.c,v
> retrieving revision 1.4
> diff -u -p -r1.4 printconf.c
> --- printconf.c   22 Aug 2010 21:15:25 -  1.4
> +++ printconf.c   23 Dec 2016 22:04:31 -
> @@ -72,24 +72,27 @@ print_redistribute(struct ospfd_conf *co
>   SIMPLEQ_FOREACH(r, >redist_list, entry) {
>   switch (r->type & ~REDIST_NO) {
>   case REDIST_STATIC:
> - printf("%sredistribute static\n", print_no(r->type));
> + printf("%sredistribute static ", print_no(r->type));
>   break;
>   case REDIST_CONNECTED:
> - printf("%sredistribute connected\n", print_no(r->type));
> + printf("%sredistribute connected ", print_no(r->type));
>   break;
>   case REDIST_LABEL:
> - printf("%sredistribute rtlabel %s\n",
> + printf("%sredistribute rtlabel %s ",
>   print_no(r->type), rtlabel_id2name(r->label));
>   break;
>   case REDIST_ADDR:
> - printf("%sredistribute %s/%d\n",
> + printf("%sredistribute %s/%d ",
>   print_no(r->type), log_in6addr(>addr),
>   r->prefixlen);
>   break;
>   case REDIST_DEFAULT:
> - printf("%sredistribute default\n", print_no(r->type));
> + printf("%sredistribute default ", print_no(r->type));
>   break;
>   }
> + printf("set { metric %d type %d }\n",
> + (r->metric & LSA_METRIC_MASK),
> + ((r->metric & LSA_ASEXT_E_FLAG) == 0 ? 1 : 2));
>   }
>  }
>  
> 
> 
> -- 
> jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE
>