Re: reduce the number of missed PCB cache with tcpbench -su

2014-08-31 Thread Mike Belopuhov
Daniel,  don't reply anything to Damien just yet.  Can you please run
a simple test on Monday.  Try tcpbench -u -n 2 ip (as in multi-
connection test) without your patch and then with the patch and see
if behavior is changed.

Thanks

On 29 August 2014 18:01, Damien Miller d...@mindrot.org wrote:
 On Fri, 29 Aug 2014, Daniel Jakots wrote:

 Hi,

 When running tcpbench -su, a lot of them are counted as missed PCB
 cache.
 ...
 + n = recvfrom(fd, ptb-dummybuf, ptb-dummybuf_len, 0,
 + (struct sockaddr *)ss, slen);
 + if (n  0  connect(fd, (const struct sockaddr *)ss, slen))
 + warn(fail to connect);

 What's the benefit of this? I've never seen an application do this;
 wouldn't it be better to improve the PCB cache so it caught this case
 (which seems the usual way UDP applications behave) instead?

 -d




uuid encode breakage

2014-08-31 Thread Jonas 'Sortie' Termansen
Hi,

I was looking at the recently imported uuid interface in libc and
noticed the encode functions are broken. In particular, this pattern:

uint8_t *p = buf;
p[0] = htobe32(uuid-time_low);
p[4] = htobe16(uuid-time_mid);
p[6] = htobe16(uuid-time_hi_and_version);

The intention is obviously that the 32-bit and 16-bit values gets copied
to the buffer, but instead the value gets truncated. The resulting
encoded uuid will then contain unmodified bytes (likely uninitialized).

This appears to be the case in the kernel uuid code as well.

The FreeBSD and NetBSD counterparts for this code is instead using
be32enc and be16enc macros to put the bytes into the buffer and doesn't
suffer from this truncation issue.

Grepping through the tree reveals these encode functions are fortunately
not currently used. The decode functions are used though, but they don't
have this problem.

Jonas



Re: apmd -A induced hangs

2014-08-31 Thread Alexander Bluhm
On Tue, Jul 29, 2014 at 12:19:43AM +0200, Alexander Bluhm wrote:
 Next I will try with this diff and without running apmd.

I was runnig with the diff and without apmd and used sysctl hw.setperf
manually.  In this month my thinkpad never crashed.

So I have added apmd -A again to rc.conf now and will report what
happens.

bluhm

  Index: acpicpu.c
  ===
  RCS file: /home/cvs/src/sys/dev/acpi/acpicpu.c,v
  retrieving revision 1.60
  diff -u -p -r1.60 acpicpu.c
  --- acpicpu.c   12 Jul 2014 18:48:17 -  1.60
  +++ acpicpu.c   13 Jul 2014 14:00:03 -
  @@ -202,9 +202,7 @@ acpicpu_set_pdc(struct acpicpu_softc *sc
  static uint8_t cpu_oscuuid[16] = { 0x16, 0xA6, 0x77, 0x40, 0x0C, 0x29,
 0xBE, 0x47, 0x9E, 0xBD, 0xD8, 0x70,
 0x58, 0x71, 0x39, 0x53 };
  -   cap = ACPI_PDC_C_C1_HALT | ACPI_PDC_P_FFH | ACPI_PDC_C_C1_FFH
  -   | ACPI_PDC_C_C2C3_FFH | ACPI_PDC_SMP_P_SWCOORD | ACPI_PDC_SMP_C2C3
  -   | ACPI_PDC_SMP_C1PT;
  +   cap = ACPI_PDC_P_FFH | ACPI_PDC_C_C1_FFH;
   
  if (aml_searchname(sc-sc_devnode, _OSC)) {
  /* Query _OSC */

OpenBSD 5.6-current (GENERIC.MP) #97: Thu Aug 28 19:25:13 CEST 2014
bluhm@t430s.bluhm.invalid:/usr/src/sys/arch/amd64/compile/GENERIC.MP
real mem = 16845570048 (16065MB)
avail mem = 16388411392 (15629MB)
mpath0 at root
scsibus0 at mpath0: 256 targets
mainbus0 at root
bios0 at mainbus0: SMBIOS rev. 2.7 @ 0xbae9d000 (68 entries)
bios0: vendor LENOVO version G7ET94WW (2.54 ) date 04/30/2013
bios0: LENOVO 2355CTO
acpi0 at bios0: rev 2
acpi0: sleep states S0 S3 S4 S5
acpi0: tables DSDT FACP TCPA SSDT SSDT SSDT HPET APIC MCFG ECDT FPDT ASF! UEFI 
UEFI MSDM SSDT SSDT UEFI DBG2
acpi0: wakeup devices LID_(S4) SLPB(S3) IGBE(S4) EXP3(S4) XHCI(S3) EHC1(S3) 
EHC2(S3) HDEF(S4)
acpitimer0 at acpi0: 3579545 Hz, 24 bits
acpihpet0 at acpi0: 14318179 Hz
acpimadt0 at acpi0 addr 0xfee0: PC-AT compat
cpu0 at mainbus0: apid 0 (boot processor)
cpu0: Intel(R) Core(TM) i7-3520M CPU @ 2.90GHz, 2893.88 MHz
cpu0: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,SMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,LONG,LAHF,PERF,ITSC,FSGSBASE,SMEP,ERMS
cpu0: 256KB 64b/line 8-way L2 cache
cpu0: smt 0, core 0, package 0
mtrr: Pentium Pro MTRR support, 10 var ranges, 88 fixed ranges
cpu0: apic clock running at 99MHz
cpu0: mwait min=64, max=64, C-substates=0.2.1.1.2, IBE
cpu1 at mainbus0: apid 1 (application processor)
cpu1: Intel(R) Core(TM) i7-3520M CPU @ 2.90GHz, 2893.43 MHz
cpu1: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,SMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,LONG,LAHF,PERF,ITSC,FSGSBASE,SMEP,ERMS
cpu1: 256KB 64b/line 8-way L2 cache
cpu1: smt 1, core 0, package 0
cpu2 at mainbus0: apid 2 (application processor)
cpu2: Intel(R) Core(TM) i7-3520M CPU @ 2.90GHz, 2893.43 MHz
cpu2: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,SMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,LONG,LAHF,PERF,ITSC,FSGSBASE,SMEP,ERMS
cpu2: 256KB 64b/line 8-way L2 cache
cpu2: smt 0, core 1, package 0
cpu3 at mainbus0: apid 3 (application processor)
cpu3: Intel(R) Core(TM) i7-3520M CPU @ 2.90GHz, 2893.43 MHz
cpu3: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,SMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,LONG,LAHF,PERF,ITSC,FSGSBASE,SMEP,ERMS
cpu3: 256KB 64b/line 8-way L2 cache
cpu3: smt 1, core 1, package 0
ioapic0 at mainbus0: apid 2 pa 0xfec0, version 20, 24 pins
acpimcfg0 at acpi0 addr 0xf800, bus 0-63
acpiec0 at acpi0
acpiprt0 at acpi0: bus 0 (PCI0)
acpiprt1 at acpi0: bus -1 (PEG_)
acpiprt2 at acpi0: bus 2 (EXP1)
acpiprt3 at acpi0: bus 3 (EXP2)
acpiprt4 at acpi0: bus 4 (EXP3)
acpiprt5 at acpi0: bus 12 (EXP5)
acpiprt6 at acpi0: bus -1 (EXP6)
acpiprt7 at acpi0: bus -1 (EXP7)
acpiprt8 at acpi0: bus -1 (EXP8)
acpicpu0 at acpi0: C3, PSS
acpicpu1 at acpi0: C3
acpicpu2 at acpi0: C3
acpicpu3 at acpi0: C3
acpipwrres0 at acpi0: PUBS, resource for XHCI, EHC1, EHC2
acpitz0 at acpi0: critical temperature is 103 degC
acpibtn0 at acpi0: LID_
acpibtn1 at acpi0: SLPB
acpibat0 at acpi0: BAT0 model 45N1143 serial   663 type LION oem Panasonic
acpibat1 at acpi0: BAT1 not present
acpiac0 at acpi0: AC unit online
acpithinkpad0 at acpi0
cpu0: Enhanced SpeedStep 2893 MHz: speeds: 2901, 2900, 2800, 

Re: uuid encode breakage

2014-08-31 Thread Miod Vallat
 I was looking at the recently imported uuid interface in libc and
 noticed the encode functions are broken. In particular, this pattern:
 
   uint8_t *p = buf;
   p[0] = htobe32(uuid-time_low);
   p[4] = htobe16(uuid-time_mid);
   p[6] = htobe16(uuid-time_hi_and_version);
 
 The intention is obviously that the 32-bit and 16-bit values gets copied
 to the buffer, but instead the value gets truncated. The resulting
 encoded uuid will then contain unmodified bytes (likely uninitialized).
 
 This appears to be the case in the kernel uuid code as well.

Indeed. Thanks for catching this, I'm fixing this issue right now.

Miod



Re: syslogd libevent

2014-08-31 Thread Alexander Bluhm
On Fri, Aug 29, 2014 at 11:25:52PM +0200, Alexander Bluhm wrote:
 I will try to pull parts of the diff into separate changes to make review
 easier.

Let's start with an obvious bug.  Do not call free() on an array
in the data section.  Fortunately the code was not reached.  No
binary change.

ok?

bluhm

Index: usr.sbin/syslogd/syslogd.c
===
RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/syslogd.c,v
retrieving revision 1.119
diff -u -p -r1.119 syslogd.c
--- usr.sbin/syslogd/syslogd.c  25 Aug 2014 18:19:18 -  1.119
+++ usr.sbin/syslogd/syslogd.c  31 Aug 2014 20:00:14 -
@@ -646,7 +646,6 @@ main(int argc, char *argv[])
}
}
/* NOTREACHED */
-   free(pfd);
return (0);
 }
 



Re: syslogd libevent handler

2014-08-31 Thread Alexander Bluhm
On Fri, Aug 29, 2014 at 11:25:52PM +0200, Alexander Bluhm wrote:
 I will try to pull parts of the diff into separate changes to
 make review easier.

Move the handlers for the poll events into separate functions.  They
will become the libevent callbacks later.

ok?

bluhm

Index: usr.sbin/syslogd/syslogd.c
===
RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/syslogd.c,v
retrieving revision 1.119
diff -u -p -r1.119 syslogd.c
--- usr.sbin/syslogd/syslogd.c  25 Aug 2014 18:19:18 -  1.119
+++ usr.sbin/syslogd/syslogd.c  31 Aug 2014 20:34:01 -
@@ -245,6 +245,13 @@ char   *reply_text;/* Start of reply tex
 size_t ctl_reply_size = 0; /* Number of bytes used in reply */
 size_t ctl_reply_offset = 0;   /* Number of bytes of reply written so far */
 
+char   *linebuf;
+int linesize;
+
+voidklog_read_handler(int);
+voidudp_read_handler(int);
+voidunix_read_handler(int);
+
 struct pollfd pfd[N_PFD];
 
 volatile sig_atomic_t MarkSet;
@@ -283,12 +290,8 @@ void   logto_ctlconn(char *);
 int
 main(int argc, char *argv[])
 {
-   int ch, i, linesize, fd;
-   struct sockaddr_un fromunix;
-   struct sockaddr_storage from;
-   socklen_t len;
-   char *p, *line;
-   char resolve[MAXHOSTNAMELEN];
+   int ch, i, fd;
+   char *p;
int lockpipe[2] = { -1, -1}, pair[2], nullfd;
struct addrinfo hints, *res, *res0;
FILE *fp;
@@ -368,7 +371,7 @@ main(int argc, char *argv[])
if (linesize  MAXLINE)
linesize = MAXLINE;
linesize++;
-   if ((line = malloc(linesize)) == NULL) {
+   if ((linebuf = malloc(linesize)) == NULL) {
logerror(Couldn't allocate line buffer);
die(0);
}
@@ -586,41 +589,13 @@ main(int argc, char *argv[])
}
 
if ((pfd[PFD_KLOG].revents  POLLIN) != 0) {
-   i = read(pfd[PFD_KLOG].fd, line, linesize - 1);
-   if (i  0) {
-   line[i] = '\0';
-   printsys(line);
-   } else if (i  0  errno != EINTR) {
-   logerror(klog);
-   pfd[PFD_KLOG].fd = -1;
-   pfd[PFD_KLOG].events = 0;
-   }
+   klog_read_handler(pfd[PFD_KLOG].fd);
}
if ((pfd[PFD_INET].revents  POLLIN) != 0) {
-   len = sizeof(from);
-   i = recvfrom(pfd[PFD_INET].fd, line, MAXLINE, 0,
-   (struct sockaddr *)from, len);
-   if (i  0) {
-   line[i] = '\0';
-   cvthname((struct sockaddr *)from, resolve,
-   sizeof(resolve));
-   dprintf(cvthname res: %s\n, resolve);
-   printline(resolve, line);
-   } else if (i  0  errno != EINTR)
-   logerror(recvfrom inet);
+   udp_read_handler(pfd[PFD_INET].fd);
}
if ((pfd[PFD_INET6].revents  POLLIN) != 0) {
-   len = sizeof(from);
-   i = recvfrom(pfd[PFD_INET6].fd, line, MAXLINE, 0,
-   (struct sockaddr *)from, len);
-   if (i  0) {
-   line[i] = '\0';
-   cvthname((struct sockaddr *)from, resolve,
-   sizeof(resolve));
-   dprintf(cvthname res: %s\n, resolve);
-   printline(resolve, line);
-   } else if (i  0  errno != EINTR)
-   logerror(recvfrom inet6);
+   udp_read_handler(pfd[PFD_INET6].fd);
}
if ((pfd[PFD_CTLSOCK].revents  POLLIN) != 0)
ctlsock_accept_handler();
@@ -631,23 +606,65 @@ main(int argc, char *argv[])
 
for (i = 0; i  nfunix; i++) {
if ((pfd[PFD_UNIX_0 + i].revents  POLLIN) != 0) {
-   ssize_t rlen;
-
-   len = sizeof(fromunix);
-   rlen = recvfrom(pfd[PFD_UNIX_0 + i].fd, line,
-   MAXLINE, 0, (struct sockaddr *)fromunix,
-   len);
-   if (rlen  0) {
-   line[rlen] = '\0';
-   printline(LocalHostName, line);
-   } else if (rlen == -1  errno != EINTR)
-   logerror(recvfrom unix);
+   udp_read_handler(pfd[PFD_UNIX_0 + i].fd);

Re: syslogd libevent

2014-08-31 Thread Alexander Bluhm
On Fri, Aug 29, 2014 at 11:25:52PM +0200, Alexander Bluhm wrote:
 I will try to pull parts of the diff into separate changes to
 make review easier.

The reapchild() signal handler collects all children.  This can be
done easier by ignoring SIGCHLD.

ok?

bluhm

Index: usr.sbin/syslogd/syslogd.c
===
RCS file: /cvs/src/usr.sbin/syslogd/syslogd.c,v
retrieving revision 1.120
diff -u -p -r1.120 syslogd.c
--- usr.sbin/syslogd/syslogd.c  31 Aug 2014 20:51:31 -  1.120
+++ usr.sbin/syslogd/syslogd.c  31 Aug 2014 21:00:04 -
@@ -266,7 +266,6 @@ voidlogmsg(int, char *, char *, int);
 struct filed *find_dup(struct filed *);
 void   printline(char *, char *);
 void   printsys(char *);
-void   reapchild(int);
 char   *ttymsg(struct iovec *, int, char *, int);
 void   usage(void);
 void   wallmsg(struct filed *, struct iovec *);
@@ -553,7 +552,7 @@ main(int argc, char *argv[])
(void)signal(SIGTERM, dodie);
(void)signal(SIGINT, Debug ? dodie : SIG_IGN);
(void)signal(SIGQUIT, Debug ? dodie : SIG_IGN);
-   (void)signal(SIGCHLD, reapchild);
+   (void)signal(SIGCHLD, SIG_IGN);
(void)signal(SIGALRM, domark);
(void)signal(SIGPIPE, SIG_IGN);
(void)alarm(TIMERINTVL);
@@ -1117,18 +1116,6 @@ wallmsg(struct filed *f, struct iovec *i
}
(void)fclose(uf);
reenter = 0;
-}
-
-/* ARGSUSED */
-void
-reapchild(int signo)
-{
-   int save_errno = errno;
-   int status;
-
-   while (waitpid(-1, status, WNOHANG)  0)
-   ;
-   errno = save_errno;
 }
 
 /*



Re: minphys woes

2014-08-31 Thread David Gwynne

On 30 Aug 2014, at 6:39, Stefan Fritsch s...@sfritsch.de wrote:

 On Fri, 29 Aug 2014, Mike Belopuhov wrote:
 
 On 29 August 2014 11:26, Stefan Fritsch s...@sfritsch.de wrote:
 On Fri, 29 Aug 2014, Miod Vallat wrote:
 sc-sc_xfer_max is computed according to the host's capabilities. What I
 want to simulate with this diff is a host adapter that can only cope with
 transfers  64k == MAXPHYS.
 
 Back to your original problem, you might want to print the sc_link
 struct as well the scsi_adapter struct it points to, when you detect a
 transfer larger than MAXPHYS. It has likely been overriden or reset to
 NULL by mistake at some point.
 
 OK, I will try that. Will take a bit until I have time, though.
 
 That's not the problem. I have added an additional
 
 KASSERT(xs-sc_link-adapter-scsi_minphys == vioblk_minphys)
 
 before the other KASSERT and it did not trigger.
 
 But I have also read the code and I could not find a place in the path
 from bread() to the scsi adapter cmd function where the minphys function
 is called.
 
 
 correct me if i'm wrong, but what happens is that bread being a block
 read reads up to MAXBSIZE which is conveniently set to 64k and you can't
 create a filesystem with a larger block size.
 
 physio (raw device io) however doesn't go through bread and need to know
 how split the provided buffer in separate transactions hence minphys.
 
 Yes, that seems to be what happens. But if every adapter needs to support 
 transfers of MAXBSIZE == MAXPHYS anyway, there would be no need for the 
 adapter to be able to override the default minphys function with its own. 
 And adapters that only support smaller transfers would need to have logic 
 in their driver to be able to split the transfer into smaller chunks.
 
 I think it makes more sense to have that logic in one place to be used by 
 all drivers.

this has blown my mind. how do the stupid ata cf card things that only support 
single sector IO work?

dlg



add support for \ and \ word delimiters in regcomp

2014-08-31 Thread Jonathan Gray
This adds support for using the SVR4/glibc word delimeters
in regcomp as an extension to what posix requires.

We already have [[::]] and [[::]] as extensions, apparently
from 'Henry Spencer's Alpha 3.0 regex release' back in 1993.

But now Solaris/Linux/FreeBSD all have the other syntax
and sadly lots of uses of grep and sed in what are supposed
to be portable projects use it.

This diff is from Garrett D'Amore in Illumos via FreeBSD.
https://www.illumos.org/issues/516

Index: re_format.7
===
RCS file: /cvs/src/lib/libc/regex/re_format.7,v
retrieving revision 1.16
diff -u -p -r1.16 re_format.7
--- re_format.7 5 Jun 2013 22:05:29 -   1.16
+++ re_format.7 1 Sep 2014 03:51:27 -
@@ -304,6 +304,12 @@ This is an extension,
 compatible with but not specified by POSIX,
 and should be used with
 caution in software intended to be portable to other systems.
+The additional word delimiters  
+.Ql \e
+and
+.Ql \e 
+are provided to ease compatibility with traditional SVR4
+systems but are not portable and should be avoided.
 .Pp
 In the event that an RE could match more than one substring of a given
 string,
Index: regcomp.c
===
RCS file: /cvs/src/lib/libc/regex/regcomp.c,v
retrieving revision 1.24
diff -u -p -r1.24 regcomp.c
--- regcomp.c   6 May 2014 15:48:38 -   1.24
+++ regcomp.c   1 Sep 2014 03:25:44 -
@@ -349,7 +349,17 @@ p_ere_exp(struct parse *p)
case '\\':
REQUIRE(MORE(), REG_EESCAPE);
c = GETNEXT();
-   ordinary(p, c);
+   switch (c) {
+   case '':
+   EMIT(OBOW, 0);
+   break;
+   case '':
+   EMIT(OEOW, 0);
+   break;
+   default:
+   ordinary(p, c);
+   break;
+   }
break;
case '{':   /* okay as ordinary except if digit follows */
REQUIRE(!MORE() || !isdigit((uch)PEEK()), REG_BADRPT);
@@ -500,6 +510,12 @@ p_simp_re(struct parse *p,
break;
case '[':
p_bracket(p);
+   break;
+   case BACKSL|'':
+   EMIT(OBOW, 0);
+   break;
+   case BACKSL|'':
+   EMIT(OEOW, 0);
break;
case BACKSL|'{':
SETERROR(REG_BADRPT);



Re: add support for \ and \ word delimiters in regcomp

2014-08-31 Thread Ted Unangst
On Mon, Sep 01, 2014 at 14:03, Jonathan Gray wrote:
 This adds support for using the SVR4/glibc word delimeters
 in regcomp as an extension to what posix requires.
 
 We already have [[::]] and [[::]] as extensions, apparently
 from 'Henry Spencer's Alpha 3.0 regex release' back in 1993.
 
 But now Solaris/Linux/FreeBSD all have the other syntax
 and sadly lots of uses of grep and sed in what are supposed
 to be portable projects use it.
 
 This diff is from Garrett D'Amore in Illumos via FreeBSD.
 https://www.illumos.org/issues/516

I have a slight preference for my diff (I think it's clearer than
deeper nested switches), but no matter.

http://marc.info/?l=openbsd-techm=131094975127745w=2