Am 11/09/13 05:44, schrieb Philip Guenther:
> On Fri, Nov 8, 2013 at 7:30 PM, Christian Schulte <[email protected]> wrote:
>> are the i386 GENERIC and GENERIC.MP kernels built using '-O2' as is
>> setup in '/usr/src/sys/arch/i386/conf/Makefile.i386' or is COPTS set to
>> something else in '/etc/mk.conf' during 'make release' ?
>
> COPTS is overridden when building the ramdisk kernels, but it's left
> alone for the normal GENERIC/GENERIC.* kernels.
>
> So yes, if your /etc/mk.conf sets COPTS, it'll affect them.
>
>
> Philip Guenther
>
Ok. Reason I am asking is this:
$ cc bcmp.c
$ time ./a.out
0m17.83s real 0m16.92s user 0m0.87s system
$ cc -O2 bcmp.c
$ time ./a.out
1m0.98s real 1m0.17s user 0m0.87s system
$ cc memcmp.c
$ time ./a.out
0m17.41s real 0m16.56s user 0m0.87s system
$ cc -O2 memcmp.c
$ time ./a.out
1m1.03s real 1m0.18s user 0m0.88s system
The difference comes from GCC optimizing away calls to the libc assembly
versions of bcmp/memcmp. For 'len' values greater than or equal to 8
(change BSIZ below), those assembly versions perform way better than
'cmpsb' inlined by GCC so that the following may be useful as most of
the bcmp/memcmp calls are using 'len' values greater than 8 and the
added function call overhead due to GCC no longer inlining these
functions should not be an issue.
Index: sys/arch/i386/conf/Makefile.i386
===================================================================
RCS file: /cvs/src/sys/arch/i386/conf/Makefile.i386,v
retrieving revision 1.88
diff -u -p -r1.88 Makefile.i386
--- sys/arch/i386/conf/Makefile.i386 15 Oct 2013 19:23:27 -0000 1.88
+++ sys/arch/i386/conf/Makefile.i386 9 Nov 2013 04:55:54 -0000
@@ -30,7 +30,10 @@ CWARNFLAGS= -Werror -Wall -Wstrict-proto
CMACHFLAGS=
CMACHFLAGS+= -fno-builtin-printf -fno-builtin-snprintf \
-fno-builtin-vsnprintf -fno-builtin-log \
- -fno-builtin-log2 -fno-builtin-malloc ${NOPIE_FLAGS}
+ -fno-builtin-log2 -fno-builtin-malloc \
+ -fno-builtin-bcmp -fno-builtin-memcmp \
+ ${NOPIE_FLAGS}
+
.if ${IDENT:M-DNO_PROPOLICE}
CMACHFLAGS+= -fno-stack-protector
.endif
--
bcmp.c:
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/mman.h>
#define BSIZ (256 * 1024 * 1024)
#define VALUE (0xff)
#define ITERATIONS (100)
int
main(int argc, char *argv[])
{
void *b1, *b2;
int i;
b1 = malloc(BSIZ);
if (b1 == NULL) {
fprintf(stderr, "unable to allocate memory: %s\n",
strerror(errno));
return errno;
}
if (mlock(b1, BSIZ)) {
fprintf(stderr, "unable to lock memory: %s\n",
strerror(errno));
return errno;
}
memset(b1, VALUE, BSIZ);
b2 = malloc(BSIZ);
if (b2 == NULL) {
fprintf(stderr, "unable to allocate memory: %s\n",
strerror(errno));
return errno;
}
if (mlock(b2, BSIZ)) {
fprintf(stderr, "unable to lock memory: %s\n",
strerror(errno));
return errno;
}
memset(b2, VALUE, BSIZ);
for (i = 0; i < ITERATIONS; i++) {
fprintf(stdout, "bcmp(b1,b2,%d)\t%d\t%d\n", BSIZ, i,
bcmp(b1, b2, BSIZ));
}
if (munlock(b1, BSIZ)) {
fprintf(stderr, "unable to unlock memory: %s\n",
strerror(errno));
}
if (munlock(b2, BSIZ)) {
fprintf(stderr, "unable to unlock memory: %s\n",
strerror(errno));
}
free(b1);
free(b2);
return 0;
}
--
memcmp.c:
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/mman.h>
#define BSIZ (256 * 1024 * 1024)
#define VALUE (0xff)
#define ITERATIONS (100)
int
main(int argc, char *argv[])
{
void *b1, *b2;
int i;
b1 = malloc(BSIZ);
if (b1 == NULL) {
fprintf(stderr, "unable to allocate memory: %s\n",
strerror(errno));
return errno;
}
if (mlock(b1, BSIZ)) {
fprintf(stderr, "unable to lock memory: %s\n",
strerror(errno));
return errno;
}
memset(b1, VALUE, BSIZ);
b2 = malloc(BSIZ);
if (b2 == NULL) {
fprintf(stderr, "unable to allocate memory: %s\n",
strerror(errno));
return errno;
}
if (mlock(b2, BSIZ)) {
fprintf(stderr, "unable to lock memory: %s\n",
strerror(errno));
return errno;
}
memset(b2, VALUE, BSIZ);
for (i = 0; i < ITERATIONS; i++) {
fprintf(stdout, "memcmp(b1,b2,%d)\t%d\t%d\n", BSIZ, i,
memcmp(b1, b2, BSIZ));
}
if (munlock(b1, BSIZ)) {
fprintf(stderr, "unable to unlock memory: %s\n",
strerror(errno));
}
if (munlock(b2, BSIZ)) {
fprintf(stderr, "unable to unlock memory: %s\n",
strerror(errno));
}
free(b1);
free(b2);
return 0;
}