remove cpuset dead code

2017-01-31 Thread Amit Kulkarni
Unused under /sys, survived a kernel build without problems.



Index: kern/kern_sched.c
===
RCS file: /cvs/src/sys/kern/kern_sched.c,v
retrieving revision 1.44
diff -u -p -u -p -r1.44 kern_sched.c
--- kern/kern_sched.c   21 Jan 2017 05:42:03 -  1.44
+++ kern/kern_sched.c   1 Feb 2017 04:04:37 -
@@ -721,12 +721,6 @@ cpuset_init_cpu(struct cpu_info *ci)
 }
 
 void
-cpuset_clear(struct cpuset *cs)
-{
-   memset(cs, 0, sizeof(*cs));
-}
-
-void
 cpuset_add(struct cpuset *cs, struct cpu_info *ci)
 {
unsigned int num = CPU_INFO_UNIT(ci);
@@ -748,12 +742,6 @@ cpuset_isset(struct cpuset *cs, struct c
 }
 
 void
-cpuset_add_all(struct cpuset *cs)
-{
-   cpuset_copy(cs, _all);
-}
-
-void
 cpuset_copy(struct cpuset *to, struct cpuset *from)
 {
memcpy(to, from, sizeof(*to));
@@ -769,15 +757,6 @@ cpuset_first(struct cpuset *cs)
return (cpuset_infos[i * 32 + ffs(cs->cs_set[i]) - 1]);
 
return (NULL);
-}
-
-void
-cpuset_union(struct cpuset *to, struct cpuset *a, struct cpuset *b)
-{
-   int i;
-
-   for (i = 0; i < CPUSET_ASIZE(ncpus); i++)
-   to->cs_set[i] = a->cs_set[i] | b->cs_set[i];
 }
 
 void
Index: sys/proc.h
===
RCS file: /cvs/src/sys/sys/proc.h,v
retrieving revision 1.232
diff -u -p -u -p -r1.232 proc.h
--- sys/proc.h  31 Jan 2017 07:44:55 -  1.232
+++ sys/proc.h  1 Feb 2017 04:04:37 -
@@ -581,13 +581,10 @@ struct cpuset {
 
 void cpuset_init_cpu(struct cpu_info *);
 
-void cpuset_clear(struct cpuset *);
 void cpuset_add(struct cpuset *, struct cpu_info *);
 void cpuset_del(struct cpuset *, struct cpu_info *);
 int cpuset_isset(struct cpuset *, struct cpu_info *);
-void cpuset_add_all(struct cpuset *);
 void cpuset_copy(struct cpuset *, struct cpuset *);
-void cpuset_union(struct cpuset *, struct cpuset *, struct cpuset *);
 void cpuset_intersection(struct cpuset *t, struct cpuset *, struct cpuset *);
 void cpuset_complement(struct cpuset *, struct cpuset *, struct cpuset *);
 struct cpu_info *cpuset_first(struct cpuset *);


cpuset.diff
Description: Binary data


Re: Help with the NET_LOCK()

2017-01-31 Thread James Hastings
boot to console:
/etc/hostname.re0:
inet n.n.n.n 0xff00

/etc/hostname.ral0:
nwid xyz
wpakey ""
mode 11g
dhcp

dmesg:
OpenBSD 6.0-current (GENERIC.MP) #4: Tue Jan 31 19:42:25 EST 2017
r...@cq58-b.test:/usr/src/sys/arch/amd64/compile/GENERIC.MP
RTC BIOS diagnostic error 80
real mem = 1690714112 (1612MB)
avail mem = 1634873344 (1559MB)
mpath0 at root
scsibus0 at mpath0: 256 targets
mainbus0 at root
bios0 at mainbus0: SMBIOS rev. 2.7 @ 0x66abc000 (45 entries)
bios0: Hewlett-Packard Compaq CQ58 Notebook PC
acpi0 at bios0: rev 2
acpi0: sleep states S0 S3 S4 S5
acpi0: tables DSDT FACP UEFI HPET APIC MCFG ASF! BOOT SPCR WDRT WDAT
FPDT MSDM SSDT SSDT VFCT BGRT
acpi0: wakeup devices PB6_(S4) SPB0(S4) XPDV(S4) SPB1(S4) SPB3(S4)
GEC_(S4) OHC1(S3) OHC2(S3) OHC3(S3) OHC4(S3) EHC1(S3) EHC2(S3)
EHC3(S3) P2P_(S5)
acpitimer0 at acpi0: 3579545 Hz, 32 bits
acpihpet0 at acpi0: 14318180 Hz
acpimadt0 at acpi0 addr 0xfee0: PC-AT compat
cpu0 at mainbus0: apid 0 (boot processor)
cpu0: AMD C-60 APU with Radeon(tm) HD Graphics, 998.70 MHz
cpu0: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,MMX,FXSR,SSE,SSE2,HTT,SSE3,MWAIT,SSSE3,CX16,POPCNT,NXE,MMXX,FFXSR,PAGE1GB,LONG,LAHF,CMPLEG,SVM,EAPICSP,AMCR8,ABM,SSE4A,MASSE,3DNOWP,IBS,SKINIT,ITSC
cpu0: 32KB 64b/line 2-way I-cache, 32KB 64b/line 8-way D-cache, 512KB
64b/line 16-way L2 cache
cpu0: 8 4MB entries fully associative
cpu0: DTLB 40 4KB entries fully associative, 8 4MB entries fully associative
cpu0: TSC frequency 998698210 Hz
cpu0: smt 0, core 0, package 0
mtrr: Pentium Pro MTRR support, 8 var ranges, 88 fixed ranges
cpu0: apic clock running at 199MHz
cpu0: mwait min=64, max=64, IBE
cpu1 at mainbus0: apid 1 (application processor)
cpu1: AMD C-60 APU with Radeon(tm) HD Graphics, 997.88 MHz
cpu1: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,MMX,FXSR,SSE,SSE2,HTT,SSE3,MWAIT,SSSE3,CX16,POPCNT,NXE,MMXX,FFXSR,PAGE1GB,LONG,LAHF,CMPLEG,SVM,EAPICSP,AMCR8,ABM,SSE4A,MASSE,3DNOWP,IBS,SKINIT,ITSC
cpu1: 32KB 64b/line 2-way I-cache, 32KB 64b/line 8-way D-cache, 512KB
64b/line 16-way L2 cache
cpu1: 8 4MB entries fully associative
cpu1: DTLB 40 4KB entries fully associative, 8 4MB entries fully associative
cpu1: smt 0, core 1, package 0
ioapic0 at mainbus0: apid 4 pa 0xfec0, version 21, 24 pins
acpimcfg0 at acpi0 addr 0xf800, bus 0-63
acpiprt0 at acpi0: bus 0 (PCI0)
acpiprt1 at acpi0: bus -1 (PB4_)
acpiprt2 at acpi0: bus -1 (PB5_)
acpiprt3 at acpi0: bus -1 (PB6_)
acpiprt4 at acpi0: bus -1 (PB7_)
acpiprt5 at acpi0: bus 2 (SPB0)
acpiprt6 at acpi0: bus 6 (SPB1)
acpiprt7 at acpi0: bus 7 (SPB2)
acpiprt8 at acpi0: bus -1 (SPB3)
acpiprt9 at acpi0: bus 1 (P2P_)
acpiec0 at acpi0
acpicpu0 at acpi0: C2(0@100 io@0xf800), C1(@1 halt!), PSS
acpicpu1 at acpi0: C2(0@100 io@0xf800), C1(@1 halt!), PSS
acpipwrres0 at acpi0: FN00, resource for FAN0
acpitz0 at acpi0: critical temperature is 125 degC
acpibtn0 at acpi0: PWRB
"HPQ8001" at acpi0 not configured
"SYN1E49" at acpi0 not configured
acpiac0 at acpi0: AC unit online
acpibtn1 at acpi0: LID_
"PNP0C14" at acpi0 not configured
"PNP0C0B" at acpi0 not configured
acpivideo0 at acpi0: VGA_
acpivideo1 at acpi0: VGA_
cpu0: 998 MHz: speeds: 1000 800 MHz
pci0 at mainbus0 bus 0
pchb0 at pci0 dev 0 function 0 "AMD AMD64 14h Host" rev 0x00
radeondrm0 at pci0 dev 1 function 0 "ATI Radeon HD 6290" rev 0x00
drm0 at radeondrm0
radeondrm0: msi
ahci0 at pci0 dev 17 function 0 "ATI SBx00 SATA" rev 0x00: apic 4 int
19, AHCI 1.2
ahci0: port 0: 6.0Gb/s
ahci0: port 2: 1.5Gb/s
scsibus1 at ahci0: 32 targets
sd0 at scsibus1 targ 0 lun 0: <> SCSI3 0/direct fixed
cd0 at scsibus1 targ 2 lun 0: <> ATAPI 5/cdrom removable
ohci0 at pci0 dev 18 function 0 "ATI SB700 USB" rev 0x00: apic 4 int
18, version 1.0, legacy support
ehci0 at pci0 dev 18 function 2 "ATI SB700 USB2" rev 0x00: apic 4 int 17
usb0 at ehci0: USB revision 2.0
uhub0 at usb0 configuration 1 interface 0 "ATI EHCI root hub" rev
2.00/1.00 addr 1
ohci1 at pci0 dev 19 function 0 "ATI SB700 USB" rev 0x00: apic 4 int
18, version 1.0, legacy support
ehci1 at pci0 dev 19 function 2 "ATI SB700 USB2" rev 0x00: apic 4 int 17
usb1 at ehci1: USB revision 2.0
uhub1 at usb1 configuration 1 interface 0 "ATI EHCI root hub" rev
2.00/1.00 addr 1
piixpm0 at pci0 dev 20 function 0 "ATI SBx00 SMBus" rev 0x42: polling
iic0 at piixpm0
spdmem0 at iic0 addr 0x51: 2GB DDR3 SDRAM PC3-12800 SO-DIMM
azalia0 at pci0 dev 20 function 2 "ATI SBx00 HD Audio" rev 0x40: apic 4 int 16
azalia0: codecs: IDT 92HD81B1X
audio0 at azalia0
pcib0 at pci0 dev 20 function 3 "ATI SB700 ISA" rev 0x40
ppb0 at pci0 dev 20 function 4 "ATI SB600 PCI" rev 0x40
pci1 at ppb0 bus 1
ppb1 at pci0 dev 21 function 0 "ATI SB800 PCIE" rev 0x00
pci2 at ppb1 bus 2
re0 at pci2 dev 0 function 0 "Realtek 8101E" rev 0x05: RTL8105E
(0x4080), msi, address
rlphy0 at re0 phy 7: RTL8201E 10/100 PHY, rev. 2
ppb2 at pci0 dev 21 function 1 "ATI SB800 PCIE" rev 0x00
pci3 at ppb2 bus 6
ral0 at pci3 dev 0 function 0 "Ralink 

Re: Help with the NET_LOCK()

2017-01-31 Thread David Hill
On Tue, Jan 31, 2017 at 09:11:37PM +0100, Alexander Bluhm wrote:
> On Tue, Jan 31, 2017 at 12:14:35PM -0500, David Hill wrote:
> > with mpi@'s suggestion to pass a struct mbuf * 
> 
> We call mbuf variables m and mbuf pointer mp.  So you should rename
> *mp to m.
> 
> The different policy who has to free the mbuf with
> if (op == PRCO_SETOPT)
> m_free(*mp);
> is not nice.  I think it would be better if all the freeing is
> done in sosetopt and sogetopt.  But this requires more thought
> and should not be in this diff.  A possible next step.
> 
> bluhm
> 

I was thinking sosetopt in a separate diff..

Updated diff.

Index: kern/uipc_socket.c
===
RCS file: /cvs/src/sys/kern/uipc_socket.c,v
retrieving revision 1.175
diff -u -p -r1.175 uipc_socket.c
--- kern/uipc_socket.c  27 Jan 2017 20:31:42 -  1.175
+++ kern/uipc_socket.c  31 Jan 2017 20:29:37 -
@@ -1560,7 +1560,7 @@ sosetopt(struct socket *so, int level, i
if (so->so_proto && so->so_proto->pr_ctloutput) {
NET_LOCK(s);
error = (*so->so_proto->pr_ctloutput)(PRCO_SETOPT, so,
-   level, optname, );
+   level, optname, m0);
NET_UNLOCK(s);
return (error);
}
@@ -1707,7 +1707,7 @@ sosetopt(struct socket *so, int level, i
level = dom->dom_protosw->pr_protocol;
NET_LOCK(s);
error = (*so->so_proto->pr_ctloutput)
-   (PRCO_SETOPT, so, level, optname, );
+   (PRCO_SETOPT, so, level, optname, m0);
NET_UNLOCK(s);
return (error);
}
@@ -1739,7 +1739,7 @@ sosetopt(struct socket *so, int level, i
if (error == 0 && so->so_proto && so->so_proto->pr_ctloutput) {
NET_LOCK(s);
(*so->so_proto->pr_ctloutput)(PRCO_SETOPT, so,
-   level, optname, );
+   level, optname, m0);
NET_UNLOCK(s);
m = NULL;   /* freed by protocol */
}
@@ -1758,11 +1758,19 @@ sogetopt(struct socket *so, int level, i
 
if (level != SOL_SOCKET) {
if (so->so_proto && so->so_proto->pr_ctloutput) {
+   m = m_get(M_WAIT, MT_SOOPTS);
+   m->m_len = 0;
+
NET_LOCK(s);
error = (*so->so_proto->pr_ctloutput)(PRCO_GETOPT, so,
-   level, optname, mp);
+   level, optname, m);
NET_UNLOCK(s);
-   return (error);
+   if (error) {
+   m_free(m);
+   return (error);
+   }
+   *mp = m;
+   return (0);
} else
return (ENOPROTOOPT);
} else {
@@ -1835,7 +1843,6 @@ sogetopt(struct socket *so, int level, i
}
 
case SO_RTABLE:
-   (void)m_free(m);
if (so->so_proto && so->so_proto->pr_domain &&
so->so_proto->pr_domain->dom_protosw &&
so->so_proto->pr_ctloutput) {
@@ -1844,12 +1851,16 @@ sogetopt(struct socket *so, int level, i
level = dom->dom_protosw->pr_protocol;
NET_LOCK(s);
error = (*so->so_proto->pr_ctloutput)
-   (PRCO_GETOPT, so, level, optname, mp);
+   (PRCO_GETOPT, so, level, optname, m);
NET_UNLOCK(s);
-   return (error);
+   if (error) {
+   (void)m_free(m);
+   return (error);
+   }
+   break;
}
+   (void)m_free(m);
return (ENOPROTOOPT);
-   break;
 
 #ifdef SOCKET_SPLICE
case SO_SPLICE:
@@ -1880,7 +1891,6 @@ sogetopt(struct socket *so, int level, i
}
(void)m_free(m);
return (EOPNOTSUPP);
-   break;
 
default:
(void)m_free(m);
Index: net/rtsock.c
===
RCS file: /cvs/src/sys/net/rtsock.c,v
retrieving revision 1.221
diff -u -p -r1.221 rtsock.c

Re: Help with the NET_LOCK()

2017-01-31 Thread Alexander Bluhm
On Tue, Jan 31, 2017 at 12:14:35PM -0500, David Hill wrote:
> with mpi@'s suggestion to pass a struct mbuf * 

We call mbuf variables m and mbuf pointer mp.  So you should rename
*mp to m.

The different policy who has to free the mbuf with
if (op == PRCO_SETOPT)
m_free(*mp);
is not nice.  I think it would be better if all the freeing is
done in sosetopt and sogetopt.  But this requires more thought
and should not be in this diff.  A possible next step.

bluhm

> 
> Index: kern/uipc_socket.c
> ===
> RCS file: /cvs/src/sys/kern/uipc_socket.c,v
> retrieving revision 1.175
> diff -u -p -r1.175 uipc_socket.c
> --- kern/uipc_socket.c27 Jan 2017 20:31:42 -  1.175
> +++ kern/uipc_socket.c31 Jan 2017 17:09:42 -
> @@ -1560,7 +1560,7 @@ sosetopt(struct socket *so, int level, i
>   if (so->so_proto && so->so_proto->pr_ctloutput) {
>   NET_LOCK(s);
>   error = (*so->so_proto->pr_ctloutput)(PRCO_SETOPT, so,
> - level, optname, );
> + level, optname, m0);
>   NET_UNLOCK(s);
>   return (error);
>   }
> @@ -1707,7 +1707,7 @@ sosetopt(struct socket *so, int level, i
>   level = dom->dom_protosw->pr_protocol;
>   NET_LOCK(s);
>   error = (*so->so_proto->pr_ctloutput)
> - (PRCO_SETOPT, so, level, optname, );
> + (PRCO_SETOPT, so, level, optname, m0);
>   NET_UNLOCK(s);
>   return (error);
>   }
> @@ -1739,7 +1739,7 @@ sosetopt(struct socket *so, int level, i
>   if (error == 0 && so->so_proto && so->so_proto->pr_ctloutput) {
>   NET_LOCK(s);
>   (*so->so_proto->pr_ctloutput)(PRCO_SETOPT, so,
> - level, optname, );
> + level, optname, m0);
>   NET_UNLOCK(s);
>   m = NULL;   /* freed by protocol */
>   }
> @@ -1758,11 +1758,19 @@ sogetopt(struct socket *so, int level, i
>  
>   if (level != SOL_SOCKET) {
>   if (so->so_proto && so->so_proto->pr_ctloutput) {
> + m = m_get(M_WAIT, MT_SOOPTS);
> + m->m_len = 0;
> +
>   NET_LOCK(s);
>   error = (*so->so_proto->pr_ctloutput)(PRCO_GETOPT, so,
> - level, optname, mp);
> + level, optname, m);
>   NET_UNLOCK(s);
> - return (error);
> + if (error) {
> + m_free(m);
> + return (error);
> + }
> + *mp = m;
> + return (0);
>   } else
>   return (ENOPROTOOPT);
>   } else {
> @@ -1835,7 +1843,6 @@ sogetopt(struct socket *so, int level, i
>   }
>  
>   case SO_RTABLE:
> - (void)m_free(m);
>   if (so->so_proto && so->so_proto->pr_domain &&
>   so->so_proto->pr_domain->dom_protosw &&
>   so->so_proto->pr_ctloutput) {
> @@ -1844,12 +1851,16 @@ sogetopt(struct socket *so, int level, i
>   level = dom->dom_protosw->pr_protocol;
>   NET_LOCK(s);
>   error = (*so->so_proto->pr_ctloutput)
> - (PRCO_GETOPT, so, level, optname, mp);
> + (PRCO_GETOPT, so, level, optname, m);
>   NET_UNLOCK(s);
> - return (error);
> + if (error) {
> + (void)m_free(m);
> + return (error);
> + }
> + break;
>   }
> + (void)m_free(m);
>   return (ENOPROTOOPT);
> - break;
>  
>  #ifdef SOCKET_SPLICE
>   case SO_SPLICE:
> @@ -1880,7 +1891,6 @@ sogetopt(struct socket *so, int level, i
>   }
>   (void)m_free(m);
>   return (EOPNOTSUPP);
> - break;
>  
>   default:
>   (void)m_free(m);
> Index: net/rtsock.c
> ===
> RCS file: /cvs/src/sys/net/rtsock.c,v
> retrieving revision 1.221
> diff -u -p -r1.221 rtsock.c
> --- net/rtsock.c  31 Jan 2017 10:24:41 -  1.221
> +++ net/rtsock.c  31 Jan 

httpd: HTTP pipelining

2017-01-31 Thread Reyk Floeter
Hi,

the following diff adds support for HTTP pipelining.

With pipelining, the client sends multiple requests before receiving
the responses in the same order.  It was long dead and disabled in
most browsers before Apple decided to turn it on in iOS Safari.

btw. There is no need to enable EV_READ in server_write() - and it can
cause a problem with pipelining - so I removed this line below.

OK?  Testers?

Reyk

Index: usr.sbin/httpd/httpd.h
===
RCS file: /cvs/src/usr.sbin/httpd/httpd.h,v
retrieving revision 1.127
diff -u -p -u -p -r1.127 httpd.h
--- usr.sbin/httpd/httpd.h  31 Jan 2017 14:39:47 -  1.127
+++ usr.sbin/httpd/httpd.h  31 Jan 2017 19:59:11 -
@@ -342,6 +342,7 @@ struct client {
size_t   clt_headerlen;
int  clt_headersdone;
unsigned int clt_persist;
+   unsigned int clt_pipelining;
int  clt_line;
int  clt_done;
int  clt_chunk;
Index: usr.sbin/httpd/server.c
===
RCS file: /cvs/src/usr.sbin/httpd/server.c,v
retrieving revision 1.104
diff -u -p -u -p -r1.104 server.c
--- usr.sbin/httpd/server.c 31 Jan 2017 17:25:05 -  1.104
+++ usr.sbin/httpd/server.c 31 Jan 2017 19:59:11 -
@@ -846,8 +846,6 @@ server_write(struct bufferevent *bev, vo
if (clt->clt_done)
goto done;
 
-   bufferevent_enable(bev, EV_READ);
-
if (clt->clt_srvbev && clt->clt_srvbev_throttled) {
bufferevent_enable(clt->clt_srvbev, EV_READ);
clt->clt_srvbev_throttled = 0;
Index: usr.sbin/httpd/server_file.c
===
RCS file: /cvs/src/usr.sbin/httpd/server_file.c,v
retrieving revision 1.64
diff -u -p -u -p -r1.64 server_file.c
--- usr.sbin/httpd/server_file.c31 Jan 2017 14:39:47 -  1.64
+++ usr.sbin/httpd/server_file.c31 Jan 2017 19:59:11 -
@@ -589,7 +589,7 @@ void
 server_file_error(struct bufferevent *bev, short error, void *arg)
 {
struct client   *clt = arg;
-   struct evbuffer *dst;
+   struct evbuffer *src, *dst;
 
if (error & EVBUFFER_TIMEOUT) {
server_close(clt, "buffer event timeout");
@@ -608,6 +608,12 @@ server_file_error(struct bufferevent *be
 
clt->clt_done = 1;
 
+   src = EVBUFFER_INPUT(clt->clt_bev);
+
+   /* Close the connection if a previous pipeline is empty */
+   if (clt->clt_pipelining && EVBUFFER_LENGTH(src) == 0)
+   clt->clt_persist = 0;
+
if (clt->clt_persist) {
/* Close input file and wait for next HTTP request */
if (clt->clt_fd != -1)
@@ -616,6 +622,12 @@ server_file_error(struct bufferevent *be
clt->clt_toread = TOREAD_HTTP_HEADER;
server_reset_http(clt);
bufferevent_enable(clt->clt_bev, EV_READ|EV_WRITE);
+
+   /* Start pipelining if the buffer is not empty */
+   if (EVBUFFER_LENGTH(src)) {
+   clt->clt_pipelining++;
+   server_read_http(clt->clt_bev, arg);
+   }
return;
}
 
Index: usr.sbin/httpd/server_http.c
===
RCS file: /cvs/src/usr.sbin/httpd/server_http.c,v
retrieving revision 1.112
diff -u -p -u -p -r1.112 server_http.c
--- usr.sbin/httpd/server_http.c31 Jan 2017 14:39:47 -  1.112
+++ usr.sbin/httpd/server_http.c31 Jan 2017 19:59:11 -
@@ -1186,6 +1186,10 @@ server_response(struct httpd *httpd, str
if (clt->clt_persist >= srv_conf->maxrequests)
clt->clt_persist = 0;
 
+   /* pipelining should end after the first "idempotent" method */
+   if (clt->clt_pipelining && clt->clt_toread > 0)
+   clt->clt_persist = 0;
+
/*
 * Do we have a Host header and matching configuration?
 * XXX the Host can also appear in the URL path.



Re: Help with the NET_LOCK()

2017-01-31 Thread Hrvoje Popovski
On 31.1.2017. 18:14, David Hill wrote:
> On Tue, Jan 31, 2017 at 10:43:26AM +0100, Martin Pieuchot wrote:
>> On 27/01/17(Fri) 14:33, David Hill wrote:
>>> [...] 
>>> Forgot a file...   Try this:
>> Is it now possible to pass a 'struct mbuf *' instead of a 'struct mbuf **'
>> to the pr_ctloutput() functions?
>>
>> Changing the signature would ensure we do not miss a call.  This would
>> also simplify the SETOPT case.
>>
> with mpi@'s suggestion to pass a struct mbuf * 


one trace less :)

tnx ..



athn: rate scaling tweak

2017-01-31 Thread Stefan Sperling
The athn driver disables multi-rate retries if RTS is used.
This is done because of a hardware limitation (see comment in ar5008_tx()).
So all attemps to send the frame will use the same data rate.

If RTS is not used, the driver will configure the hardware to switch
to a lower rate after 2 failed attempts, and to a lower rate again after
another 2 failures, and so, until this "rate series" is over.

With RTS enabled a transmit failure is equivally likely with each attempt.
A failure of an earlier attempt followed by successful transmission with
the same transmit rate does not necessarily imply that the rate is bad.
The code which counts transmit failures assumes otherwise and treats
transmit failures with RTS the same way as without RTS.

The diff below fixes this problem.

Index: ar5008.c
===
RCS file: /cvs/src/sys/dev/ic/ar5008.c,v
retrieving revision 1.41
diff -u -p -r1.41 ar5008.c
--- ar5008.c30 Jan 2017 10:57:00 -  1.41
+++ ar5008.c31 Jan 2017 16:59:32 -
@@ -997,11 +997,17 @@ ar5008_tx_process(struct athn_softc *sc,
/*
 * NB: the data fail count contains the number of un-acked tries
 * for the final series used.  We must add the number of tries for
-* each series that was fully processed.
+* each series that was fully processed to punish transmit rates in
+* the earlier series which did not perform well.
+* If RTS/CTS was used, each series used the same transmit rate.
+* Ignore the series count in this case, since each series had
+* the same chance of success.
 */
failcnt  = MS(ds->ds_status1, AR_TXS1_DATA_FAIL_CNT);
-   /* NB: Assume two tries per series. */
-   failcnt += MS(ds->ds_status9, AR_TXS9_FINAL_IDX) * 2;
+   if (!(ds->ds_ctl0 & (AR_TXC0_RTS_ENABLE | AR_TXC0_CTS_ENABLE))) {
+   /* NB: Assume two tries per series. */
+   failcnt += MS(ds->ds_status9, AR_TXS9_FINAL_IDX) * 2;
+   }
 
/* Update rate control statistics. */
if (ni->ni_flags & IEEE80211_NODE_HT) {



Re: Help with the NET_LOCK()

2017-01-31 Thread David Hill
On Tue, Jan 31, 2017 at 10:43:26AM +0100, Martin Pieuchot wrote:
> On 27/01/17(Fri) 14:33, David Hill wrote:
> > [...] 
> > Forgot a file...   Try this:
> 
> Is it now possible to pass a 'struct mbuf *' instead of a 'struct mbuf **'
> to the pr_ctloutput() functions?
> 
> Changing the signature would ensure we do not miss a call.  This would
> also simplify the SETOPT case.
>

with mpi@'s suggestion to pass a struct mbuf * 

Index: kern/uipc_socket.c
===
RCS file: /cvs/src/sys/kern/uipc_socket.c,v
retrieving revision 1.175
diff -u -p -r1.175 uipc_socket.c
--- kern/uipc_socket.c  27 Jan 2017 20:31:42 -  1.175
+++ kern/uipc_socket.c  31 Jan 2017 17:09:42 -
@@ -1560,7 +1560,7 @@ sosetopt(struct socket *so, int level, i
if (so->so_proto && so->so_proto->pr_ctloutput) {
NET_LOCK(s);
error = (*so->so_proto->pr_ctloutput)(PRCO_SETOPT, so,
-   level, optname, );
+   level, optname, m0);
NET_UNLOCK(s);
return (error);
}
@@ -1707,7 +1707,7 @@ sosetopt(struct socket *so, int level, i
level = dom->dom_protosw->pr_protocol;
NET_LOCK(s);
error = (*so->so_proto->pr_ctloutput)
-   (PRCO_SETOPT, so, level, optname, );
+   (PRCO_SETOPT, so, level, optname, m0);
NET_UNLOCK(s);
return (error);
}
@@ -1739,7 +1739,7 @@ sosetopt(struct socket *so, int level, i
if (error == 0 && so->so_proto && so->so_proto->pr_ctloutput) {
NET_LOCK(s);
(*so->so_proto->pr_ctloutput)(PRCO_SETOPT, so,
-   level, optname, );
+   level, optname, m0);
NET_UNLOCK(s);
m = NULL;   /* freed by protocol */
}
@@ -1758,11 +1758,19 @@ sogetopt(struct socket *so, int level, i
 
if (level != SOL_SOCKET) {
if (so->so_proto && so->so_proto->pr_ctloutput) {
+   m = m_get(M_WAIT, MT_SOOPTS);
+   m->m_len = 0;
+
NET_LOCK(s);
error = (*so->so_proto->pr_ctloutput)(PRCO_GETOPT, so,
-   level, optname, mp);
+   level, optname, m);
NET_UNLOCK(s);
-   return (error);
+   if (error) {
+   m_free(m);
+   return (error);
+   }
+   *mp = m;
+   return (0);
} else
return (ENOPROTOOPT);
} else {
@@ -1835,7 +1843,6 @@ sogetopt(struct socket *so, int level, i
}
 
case SO_RTABLE:
-   (void)m_free(m);
if (so->so_proto && so->so_proto->pr_domain &&
so->so_proto->pr_domain->dom_protosw &&
so->so_proto->pr_ctloutput) {
@@ -1844,12 +1851,16 @@ sogetopt(struct socket *so, int level, i
level = dom->dom_protosw->pr_protocol;
NET_LOCK(s);
error = (*so->so_proto->pr_ctloutput)
-   (PRCO_GETOPT, so, level, optname, mp);
+   (PRCO_GETOPT, so, level, optname, m);
NET_UNLOCK(s);
-   return (error);
+   if (error) {
+   (void)m_free(m);
+   return (error);
+   }
+   break;
}
+   (void)m_free(m);
return (ENOPROTOOPT);
-   break;
 
 #ifdef SOCKET_SPLICE
case SO_SPLICE:
@@ -1880,7 +1891,6 @@ sogetopt(struct socket *so, int level, i
}
(void)m_free(m);
return (EOPNOTSUPP);
-   break;
 
default:
(void)m_free(m);
Index: net/rtsock.c
===
RCS file: /cvs/src/sys/net/rtsock.c,v
retrieving revision 1.221
diff -u -p -r1.221 rtsock.c
--- net/rtsock.c31 Jan 2017 10:24:41 -  1.221
+++ net/rtsock.c31 Jan 2017 17:09:42 -
@@ -98,7 +98,7 @@ struct walkarg {
caddr_t w_where, w_tmem;
 };
 
-introute_ctloutput(int, struct socket *, 

Re: uvm: free sizes diff

2017-01-31 Thread Stefan Kempf
David Hill wrote:
> Hello -
> 
> The following diff adds free sizes to free() calls in uvm/.  Only one
> remaining in uvm/.
 
ok stefan@

> Index: uvm/uvm_amap.c
> ===
> RCS file: /cvs/src/sys/uvm/uvm_amap.c,v
> retrieving revision 1.78
> diff -u -p -r1.78 uvm_amap.c
> --- uvm/uvm_amap.c8 Oct 2016 16:19:44 -   1.78
> +++ uvm/uvm_amap.c30 Jan 2017 21:17:22 -
> @@ -368,7 +368,7 @@ amap_alloc1(int slots, int waitf, int la
>   return(amap);
>  
>  fail1:
> - free(amap->am_buckets, M_UVMAMAP, 0);
> + free(amap->am_buckets, M_UVMAMAP, buckets * sizeof(*amap->am_buckets));
>   TAILQ_FOREACH_SAFE(chunk, >am_chunks, ac_list, tmp)
>   pool_put(_amap_chunk_pool, chunk);
>   pool_put(_amap_pool, amap);
> @@ -414,7 +414,7 @@ amap_free(struct vm_amap *amap)
>  
>  #ifdef UVM_AMAP_PPREF
>   if (amap->am_ppref && amap->am_ppref != PPREF_NONE)
> - free(amap->am_ppref, M_UVMAMAP, 0);
> + free(amap->am_ppref, M_UVMAMAP, amap->am_nslot * sizeof(int));
>  #endif
>  
>   if (UVM_AMAP_SMALL(amap))
> Index: uvm/uvm_aobj.c
> ===
> RCS file: /cvs/src/sys/uvm/uvm_aobj.c,v
> retrieving revision 1.84
> diff -u -p -r1.84 uvm_aobj.c
> --- uvm/uvm_aobj.c24 Sep 2016 18:40:29 -  1.84
> +++ uvm/uvm_aobj.c30 Jan 2017 21:17:22 -
> @@ -403,7 +403,7 @@ uao_free(struct uvm_aobj *aobj)
>   uvmexp.swpgonly--;
>   }
>   }
> - free(aobj->u_swslots, M_UVMAOBJ, 0);
> + free(aobj->u_swslots, M_UVMAOBJ, aobj->u_pages * sizeof(int));
>   }
>  
>   /* finally free the aobj itself */
> @@ -532,7 +532,7 @@ uao_shrink_array(struct uvm_object *uobj
>   for (i = 0; i < pages; i++)
>   new_swslots[i] = aobj->u_swslots[i];
>  
> - free(aobj->u_swslots, M_UVMAOBJ, 0);
> + free(aobj->u_swslots, M_UVMAOBJ, aobj->u_pages * sizeof(int));
>  
>   aobj->u_swslots = new_swslots;
>   aobj->u_pages = pages;
> @@ -585,7 +585,7 @@ uao_grow_array(struct uvm_object *uobj, 
>   for (i = 0; i < aobj->u_pages; i++)
>   new_swslots[i] = aobj->u_swslots[i];
>  
> - free(aobj->u_swslots, M_UVMAOBJ, 0);
> + free(aobj->u_swslots, M_UVMAOBJ, aobj->u_pages * sizeof(int));
>  
>   aobj->u_swslots = new_swslots;
>   aobj->u_pages = pages;
> @@ -664,7 +664,7 @@ uao_grow_convert(struct uvm_object *uobj
>   }
>   }
>  
> - free(old_swslots, M_UVMAOBJ, 0);
> + free(old_swslots, M_UVMAOBJ, aobj->u_pages * sizeof(int));
>   aobj->u_pages = pages;
>  
>   return 0;
> 



Re: per cpu counters for icmp

2017-01-31 Thread Jeremie Courreges-Anglas
Jonathan Matthew  writes:

> This is much like the other per cpu counter conversions, except the counter
> enum has gaps in it to match the arrays in struct icmpstat.

I missed this mail and implemented basically the same diff. :-/

So your diff looks fine to me, the difference that I could spot are:
- icmp_sysctl_icmpstat before icmp_sysctl to remove the need for a decl
- I removed the 'if (newp != NULL)' in the ICMPCTL_STATS case,
  sysctl_rdstruct shoudl take care of that
- declare icmpcounters before the definition of icmpstat_inc in
  icmp_var.h, that removes the need for the extern decl within said function
- s/KASSERT/CTASSERT/ in icmp_sysctl_icmpstat

I'd say that CTASSERT is a real improvement, the rest is cosmetic.

-- 
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE



rtwn: amrr support

2017-01-31 Thread Stefan Sperling
This diff adds AMRR support to rtwn(4) (not urtwn(4) yet! PCI devices only).

This improves Tx performance with 8188CE hardware a lot. The firmware's
builtin rate scaling rarely selects rates above 1Mbit/s in my environment.
With this diff and tcpbench I've seen the driver crank it up to 54mbit/s.

Getting feedback on Tx status on this hardware is quirky.
The driver has to set a special bit to request Tx status reports, and then
the firmware will provide this information in "cpu to host" events.
This approach is based on how FreeBSD's rtwn driver does it, except we
poll "cpu to host" events directly from the tx_done interrupt handler.

Index: ic/r92creg.h
===
RCS file: /cvs/src/sys/dev/ic/r92creg.h,v
retrieving revision 1.5
diff -u -p -r1.5 r92creg.h
--- ic/r92creg.h31 Jan 2017 09:21:46 -  1.5
+++ ic/r92creg.h31 Jan 2017 10:43:28 -
@@ -95,9 +95,9 @@
 #define R92C_MBIST_START   0x174
 #define R92C_MBIST_DONE0x178
 #define R92C_MBIST_FAIL0x17c
-#define R92C_C2HEVT_MSG_NORMAL 0x1a0
+#define R92C_C2HEVT_MSG0x1a0
+#define R92C_C2HEVT_CLEAR  0x1af
 #define R92C_C2HEVT_MSG_TEST   0x1b8
-#define R92C_C2HEVT_CLEAR  0x1bf
 #define R92C_MCUTST_1  0x1c0
 #define R92C_FMETHR0x1c8
 #define R92C_HMETFR0x1cc
@@ -1268,6 +1268,71 @@ struct r92c_tx_desc_usb {
 #define R92C_TXDW5_DATA_RETRY_LIMIT_S  18
 #define R92C_TXDW5_AGGNUM_M0xff00
 #define R92C_TXDW5_AGGNUM_S24
+
+/*
+ * C2H event structure.
+ */
+#define R92C_C2H_MSG_MAX_LEN   16
+
+struct r92c_c2h_evt {
+   uint8_t evtb0;
+#define R92C_C2H_EVTB0_ID_M0x0f
+#define R92C_C2H_EVTB0_ID_S0
+#define R92C_C2H_EVTB0_LEN_M   0xf0
+#define R92C_C2H_EVTB0_LEN_S   4
+
+   uint8_t seq;
+
+   /* Followed by payload (see below). */
+} __packed;
+
+/* Bits for R92C_C2HEVT_CLEAR. */
+#define R92C_C2HEVT_HOST_CLOSE 0x00
+#define R92C_C2HEVT_FW_CLOSE   0xff
+
+/*
+ * C2H event types.
+ */
+#define R92C_C2HEVT_DEBUG  0
+#define R92C_C2HEVT_TX_REPORT  3
+#define R92C_C2HEVT_EXT_RA_RPT 6
+
+/* Structure for R92C_C2H_EVT_TX_REPORT event. */
+struct r92c_c2h_tx_rpt {
+   uint8_t rptb0;
+#define R92C_RPTB0_RETRY_CNT_M 0x3f
+#define R92C_RPTB0_RETRY_CNT_S 0
+
+   uint8_t rptb1;  /* XXX junk */
+#define R92C_RPTB1_RTS_RETRY_CNT_M 0x3f
+#define R92C_RPTB1_RTS_RETRY_CNT_S 0
+
+   uint8_t queue_time_low;
+   uint8_t queue_time_high;
+   uint8_t rptb4;
+#define R92C_RPTB4_MISSED_PKT_NUM_M0x1f
+#define R92C_RPTB4_MISSED_PKT_NUM_S0
+
+   uint8_t rptb5;
+#define R92C_RPTB5_MACID_M 0x1f
+#define R92C_RPTB5_MACID_S 0
+#define R92C_RPTB5_DES1_FRAGSSN_M  0xe0
+#define R92C_RPTB5_DES1_FRAGSSN_S  5
+
+   uint8_t rptb6;
+#define R92C_RPTB6_RPT_PKT_NUM_M   0x1f
+#define R92C_RPTB6_RPT_PKT_NUM_S   0
+#define R92C_RPTB6_PKT_DROP0x20
+#define R92C_RPTB6_LIFE_EXPIRE 0x40
+#define R92C_RPTB6_RETRY_OVER  0x80
+
+   uint8_t rptb7;
+#define R92C_RPTB7_EDCA_M  0x0f
+#define R92C_RPTB7_EDCA_S  0
+#define R92C_RPTB7_BMC 0x20
+#define R92C_RPTB7_PKT_OK  0x40
+#define R92C_RPTB7_INT_CCX 0x80
+} __packed;
 
 /*
  * MAC initialization values.
Index: ic/rtwn.c
===
RCS file: /cvs/src/sys/dev/ic/rtwn.c,v
retrieving revision 1.17
diff -u -p -r1.17 rtwn.c
--- ic/rtwn.c   31 Jan 2017 15:15:13 -  1.17
+++ ic/rtwn.c   31 Jan 2017 15:32:05 -
@@ -642,7 +642,7 @@ rtwn_media_change(struct ifnet *ifp)
 }
 
 /*
- * Initialize rate adaptation in firmware.
+ * Initialize rate adaptation.
  */
 int
 rtwn_ra_init(struct rtwn_softc *sc)
@@ -686,11 +686,11 @@ rtwn_ra_init(struct rtwn_softc *sc)
/* Configure Automatic Rate Fallback Register. */
if (ic->ic_curmode == IEEE80211_MODE_11B) {
if (rates & 0x0c)
-   rtwn_write_4(sc, R92C_ARFR(0), rates & 0x0d);
+   rtwn_write_4(sc, R92C_ARFR(0), rates & 0x05);
else
-   rtwn_write_4(sc, R92C_ARFR(0), rates & 0x0f);
+   rtwn_write_4(sc, R92C_ARFR(0), rates & 0x07);
} else
-   rtwn_write_4(sc, R92C_ARFR(0), rates & 0x0ff5);
+   rtwn_write_4(sc, R92C_ARFR(0), rates & 0x07f5);
}
 
if (sc->chip & RTWN_CHIP_88E) {
@@ -699,14 +699,26 @@ rtwn_ra_init(struct rtwn_softc *sc)
/* We use 

tcpstat percpu counters (and kernel size growth)

2017-01-31 Thread Jeremie Courreges-Anglas

Maybe I'm comparing apples and oranges, but I got curious and compared
the size of various kernels on amd64:

* -current GENERIC:
  textdatabss dec hex
  9197408 269192  684032  101506329ae2e8

* percpu tcpstat, not inlined, GENERIC:
  textdatabss dec hex
  9199200 269192  684032  101524249ae9e8
  overhead: 1792 bytes

* percpu tcpstat, GENERIC:
  textdatabss dec hex
  9199536 269192  684032  101527609aeb38
  overhead: 2128 bytes


* -current GENERIC.MP:
  textdatabss dec hex
  9248800 270792  688128  102077209bc1e8

* percpu tcpstat, not inlined, GENERIC.MP:
  textdatabss dec hex
  9250768 270792  688128  102096889bc998
  overhead: 1968 bytes

* percpu tcpstat, GENERIC.MP:
  textdatabss dec hex
  9254320 270792  688128  102132409bd778
  overhead: 5520 bytes

So the counters api is not free.  I don't think that size is a problem
for regular kernels, but we'd better test constrained install media.
I haven't done so for ip6stat yet, I can handle amd64.


Anyway, tcpstat diff below, a bit ugly because that struct is a mix of
uint32_t and uint64_t.  Comments / reviews welcome.


Index: net/pf.c
===
RCS file: /d/cvs/src/sys/net/pf.c,v
retrieving revision 1.1013
diff -u -p -r1.1013 pf.c
--- net/pf.c30 Jan 2017 17:52:24 -  1.1013
+++ net/pf.c31 Jan 2017 00:10:40 -
@@ -6026,7 +6026,7 @@ pf_check_tcp_cksum(struct mbuf *m, int o
}
 
/* need to do it in software */
-   tcpstat.tcps_inswcsum++;
+   tcpstat_inc(tcps_inswcsum);
 
switch (af) {
case AF_INET:
@@ -6047,7 +6047,7 @@ pf_check_tcp_cksum(struct mbuf *m, int o
unhandled_af(af);
}
if (sum) {
-   tcpstat.tcps_rcvbadsum++;
+   tcpstat_inc(tcps_rcvbadsum);
m->m_pkthdr.csum_flags |= M_TCP_CSUM_IN_BAD;
return (1);
}
Index: netinet/ip_output.c
===
RCS file: /d/cvs/src/sys/netinet/ip_output.c,v
retrieving revision 1.334
diff -u -p -r1.334 ip_output.c
--- netinet/ip_output.c 10 Jan 2017 09:01:18 -  1.334
+++ netinet/ip_output.c 31 Jan 2017 01:31:13 -
@@ -1798,7 +1798,7 @@ in_proto_cksum_out(struct mbuf *m, struc
if (m->m_pkthdr.csum_flags & M_TCP_CSUM_OUT) {
if (!ifp || !(ifp->if_capabilities & IFCAP_CSUM_TCPv4) ||
ip->ip_hl != 5 || ifp->if_bridgeport != NULL) {
-   tcpstat.tcps_outswcsum++;
+   tcpstat_inc(tcps_outswcsum);
in_delayed_cksum(m);
m->m_pkthdr.csum_flags &= ~M_TCP_CSUM_OUT; /* Clear */
}
Index: netinet/tcp_input.c
===
RCS file: /d/cvs/src/sys/netinet/tcp_input.c,v
retrieving revision 1.337
diff -u -p -r1.337 tcp_input.c
--- netinet/tcp_input.c 29 Jan 2017 19:58:47 -  1.337
+++ netinet/tcp_input.c 31 Jan 2017 13:33:00 -
@@ -234,7 +234,7 @@ tcp_reass(struct tcpcb *tp, struct tcphd
if (tiqe == NULL || th->th_seq != tp->rcv_nxt) {
/* Flush segment queue for this connection */
tcp_freeq(tp);
-   tcpstat.tcps_rcvmemdrop++;
+   tcpstat_inc(tcps_rcvmemdrop);
m_freem(m);
return (0);
}
@@ -261,8 +261,8 @@ tcp_reass(struct tcpcb *tp, struct tcphd
i = phdr->th_seq + phdr->th_reseqlen - th->th_seq;
if (i > 0) {
if (i >= *tlen) {
-   tcpstat.tcps_rcvduppack++;
-   tcpstat.tcps_rcvdupbyte += *tlen;
+   tcpstat_pkt(tcps_rcvduppack, tcps_rcvdupbyte,
+   *tlen);
m_freem(m);
pool_put(_pool, tiqe);
return (0);
@@ -272,8 +272,7 @@ tcp_reass(struct tcpcb *tp, struct tcphd
th->th_seq += i;
}
}
-   tcpstat.tcps_rcvoopack++;
-   tcpstat.tcps_rcvoobyte += *tlen;
+   tcpstat_pkt(tcps_rcvoopack, tcps_rcvoobyte, *tlen);
 
/*
 * While we overlap succeeding segments trim them or,
@@ -389,7 +388,7 @@ tcp_input(struct mbuf **mp, int *offp, i
u_char iptos;
 #endif
 
-   tcpstat.tcps_rcvtotal++;
+   tcpstat_inc(tcps_rcvtotal);
 
opti.ts_present = 0;
opti.maxseg = 0;
@@ -448,7 +447,7 @@ tcp_input(struct mbuf **mp, int *offp, i
 
IP6_EXTHDR_GET(th, struct tcphdr *, m, iphlen, sizeof(*th));
if (!th) {
-   tcpstat.tcps_rcvshort++;
+   tcpstat_inc(tcps_rcvshort);

Re: [wscons] User-space access to terminal emulation data

2017-01-31 Thread Enrico Mioso

Hello to everyone.
First of all, thank you again for your attention, and to who read this message.
I am unsubscribing from the list now, to manage easily my mailbox. Still, I am 
interested in hearing your opinions and comments. So feel free to contact me 
directly.
Thank you again,
Enrico



Re: sys/dev/uaudio.c: Fix broken links

2017-01-31 Thread Jeremie Courreges-Anglas
Michael Reed  writes:

I'm not sure how, but the patch got corrupted (it didn't apply with just
''patch < uaudio.diff'', there are missing newlines).

Anyway, committed.

Thanks,
-- 
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE



Re: ip6stat percpu counters

2017-01-31 Thread Jeremie Courreges-Anglas

Updated diff that addresses Martin's points:
- kill IPv6 mbuf stats; don't change the ip6stat structure yet - there
  are already other fields that are useless
- add ip6stat_add()

Keep the M_COUNTERS change separate for now, I can send an updated diff
later if needed.

Additionally,
- stop testing for (newp != NULL) in ip6_sysctl/IPV6CTL_STATS,
  sysctl_rdstruct in ip6_sysctl_ip6stat already does so for us.
  I see no harm in returning an error late here.
- move ip6_sysctl_ip6stat above ip6_sysctl to get rid of an unneeded decl


Index: net/if_bridge.c
===
RCS file: /d/cvs/src/sys/net/if_bridge.c,v
retrieving revision 1.293
diff -u -p -r1.293 if_bridge.c
--- net/if_bridge.c 24 Jan 2017 10:08:30 -  1.293
+++ net/if_bridge.c 31 Jan 2017 10:53:00 -
@@ -1692,7 +1692,7 @@ bridge_ip(struct bridge_softc *sc, int d
if (m->m_len < sizeof(struct ip6_hdr)) {
if ((m = m_pullup(m, sizeof(struct ip6_hdr)))
== NULL) {
-   ip6stat.ip6s_toosmall++;
+   ip6stat_inc(ip6s_toosmall);
return (NULL);
}
}
@@ -1700,7 +1700,7 @@ bridge_ip(struct bridge_softc *sc, int d
ip6 = mtod(m, struct ip6_hdr *);
 
if ((ip6->ip6_vfc & IPV6_VERSION_MASK) != IPV6_VERSION) {
-   ip6stat.ip6s_badvers++;
+   ip6stat_inc(ip6s_badvers);
goto dropit;
}
 
Index: net/pf.c
===
RCS file: /d/cvs/src/sys/net/pf.c,v
retrieving revision 1.1013
diff -u -p -r1.1013 pf.c
--- net/pf.c30 Jan 2017 17:52:24 -  1.1013
+++ net/pf.c31 Jan 2017 10:53:00 -
@@ -5974,7 +5974,7 @@ pf_route6(struct pf_pdesc *pd, struct pf
 
rt = rtalloc(sin6tosa(dst), RT_RESOLVE, rtableid);
if (!rtisvalid(rt)) {
-   ip6stat.ip6s_noroute++;
+   ip6stat_inc(ip6s_noroute);
goto bad;
}
 
Index: netinet/ipsec_input.c
===
RCS file: /d/cvs/src/sys/netinet/ipsec_input.c,v
retrieving revision 1.141
diff -u -p -r1.141 ipsec_input.c
--- netinet/ipsec_input.c   29 Jan 2017 19:58:47 -  1.141
+++ netinet/ipsec_input.c   31 Jan 2017 10:53:00 -
@@ -985,7 +985,7 @@ ah6_input_cb(struct mbuf *m, int off, in
 */
while (nxt != IPPROTO_DONE) {
if (ip6_hdrnestlimit && (++nest > ip6_hdrnestlimit)) {
-   ip6stat.ip6s_toomanyhdr++;
+   ip6stat_inc(ip6s_toomanyhdr);
goto bad;
}
 
@@ -994,7 +994,7 @@ ah6_input_cb(struct mbuf *m, int off, in
 * more sanity checks in header chain processing.
 */
if (m->m_pkthdr.len < off) {
-   ip6stat.ip6s_tooshort++;
+   ip6stat_inc(ip6s_tooshort);
goto bad;
}
nxt = (*inet6sw[ip6_protox[nxt]].pr_input)(, , nxt);
Index: netinet6/dest6.c
===
RCS file: /d/cvs/src/sys/netinet6/dest6.c,v
retrieving revision 1.15
diff -u -p -r1.15 dest6.c
--- netinet6/dest6.c14 Mar 2015 03:38:52 -  1.15
+++ netinet6/dest6.c31 Jan 2017 10:53:00 -
@@ -73,7 +73,7 @@ dest6_input(struct mbuf **mp, int *offp,
for (optlen = 0; dstoptlen > 0; dstoptlen -= optlen, opt += optlen) {
if (*opt != IP6OPT_PAD1 &&
(dstoptlen < IP6OPT_MINLEN || *(opt + 1) + 2 > dstoptlen)) {
-   ip6stat.ip6s_toosmall++;
+   ip6stat_inc(ip6s_toosmall);
goto bad;
}
 
Index: netinet6/frag6.c
===
RCS file: /d/cvs/src/sys/netinet6/frag6.c,v
retrieving revision 1.71
diff -u -p -r1.71 frag6.c
--- netinet6/frag6.c28 Nov 2016 11:12:45 -  1.71
+++ netinet6/frag6.c31 Jan 2017 13:00:14 -
@@ -190,7 +190,7 @@ frag6_input(struct mbuf **mp, int *offp,
return IPPROTO_DONE;
}
 
-   ip6stat.ip6s_fragments++;
+   ip6stat_inc(ip6s_fragments);
 
/* offset now points to data portion */
offset += sizeof(struct ip6_frag);
@@ -203,7 +203,7 @@ frag6_input(struct mbuf **mp, int *offp,
 */
fragoff = ntohs(ip6f->ip6f_offlg & IP6F_OFF_MASK);
if (fragoff == 0 && !(ip6f->ip6f_offlg & IP6F_MORE_FRAG)) {
-   ip6stat.ip6s_reassembled++;
+   ip6stat_inc(ip6s_reassembled);
*offp = offset;
return ip6f->ip6f_nxt;
}
@@ -496,7 +496,7 @@ frag6_input(struct mbuf **mp, int *offp,

Re: Add quirks to support M-Audio FastTrack Pro (uaudio)

2017-01-31 Thread Christopher Zimmermann
Hi,

below you find an updated diff. OK?


On 2017-01-29 Martin Pieuchot  wrote:
> On 29/01/17(Sun) 19:33, Christopher Zimmermann wrote:
> > [...]
> > @@ -444,6 +447,11 @@ uaudio_match(struct device *parent, void
> > if (uaa->iface == NULL || uaa->device == NULL)
> > return (UMATCH_NONE);
> >  
> > +   if (uaa->vendor == USB_VENDOR_MAUDIO &&
> > +   uaa->product == USB_PRODUCT_MAUDIO_FASTTRACKPRO &&
> > +   uaa->configno != 2)
> > +   return UMATCH_NONE;  
> 
> Why to you need this?

This device exposes only a very limited set of features in
configuration 1.
To force usb_subr.c:usbd_probe_and_attach() to try configuration 2
both uaudio and umidi must attach to the device only configuration 2.
Otherwise one will claim the device and other configurations won't be
tried.

> > @@ -531,8 +539,21 @@ uaudio_attach(struct device *parent, str
> > found = 1;
> > }
> > }
> > -   if (found)
> > +   if (found) {
> > usbd_claim_iface(sc->sc_udev, i);
> > +   if (uaa->vendor == USB_VENDOR_MAUDIO &&
> > +   uaa->product == USB_PRODUCT_MAUDIO_FASTTRACKPRO) {
> > +   /*
> > +* temporarily switch every iface to 24bit.
> > +* Causes the device to be big endian even
> > +* for 16bit samples.
> > +* using 16bits first will cause the device
> > +* to break when we later switch to 24bit.
> > +*/
> > +   usbd_set_interface(sc->sc_alts[i].ifaceh, 2);
> > +   usbd_set_interface(sc->sc_alts[i].ifaceh, 0);  
> 
> How did you figure that out?  Is this behavior documented somehwere?

It's not documented. I did not find a similar hack in the linux driver.
Still its a reproducable behaviour.

> > @@ -3312,6 +3340,9 @@ uaudio_set_params(void *addr, int setmod
> > }
> > break;
> > }
> > +
> > +   if (sc->sc_quirks & UAUDIO_FLAG_BE)
> > +   p->encoding = AUDIO_ENCODING_SLINEAR_BE;  
> 
> Why do you need this chunk and we don't need to set
> AUDIO_ENCODING_SLINEAR_LE in the other case?

We probably should set it to _LE in the other case. I moved this piece
of code into uaudio_match_alt() and made it agnostic about the specific 
endianness.

> > @@ -152,6 +153,11 @@ umidi_match(struct device *parent, void 
> > DPRINTFN(1,("umidi_match\n"));
> >  
> > if (uaa->iface == NULL)
> > +   return UMATCH_NONE;
> > +
> > +   if (uaa->vendor == USB_VENDOR_MAUDIO &&
> > +   uaa->product == USB_PRODUCT_MAUDIO_FASTTRACKPRO &&
> > +   uaa->configno != 2)
> > return UMATCH_NONE;  
> 
> I'd leave the configno check out and add a comment explaining why we
> want to force this driver to attach to uaudio(4).

See my comment above about the same piece of code in uaudio.c.
If I don't add this condition umidi will attach to configuration 1 and
configuration 2 wouldn't be tried, uaudio wouldn't attach.


Here's the updated diff:



Index: uaudio.c
===
RCS file: /cvs/src/sys/dev/usb/uaudio.c,v
retrieving revision 1.122
diff -u -p -r1.122 uaudio.c
--- uaudio.c3 Jan 2017 06:45:58 -   1.122
+++ uaudio.c31 Jan 2017 12:37:46 -
@@ -172,6 +172,7 @@ struct chan {
 #define UAUDIO_FLAG_VENDOR_CLASS 0x0010/* claims vendor class but 
works */
 #define UAUDIO_FLAG_DEPENDENT   0x0020 /* play and record params must equal */
 #define UAUDIO_FLAG_EMU0202 0x0040
+#define UAUDIO_FLAG_BE  0x0080
 
 struct uaudio_devs {
struct usb_devno uv_dev;
@@ -223,7 +224,9 @@ struct uaudio_devs {
{ { USB_VENDOR_LOGITECH, USB_PRODUCT_LOGITECH_QUICKCAMZOOM },
UAUDIO_FLAG_BAD_AUDIO },
{ { USB_VENDOR_TELEX, USB_PRODUCT_TELEX_MIC1 },
-   UAUDIO_FLAG_NO_FRAC }
+   UAUDIO_FLAG_NO_FRAC },
+   { { USB_VENDOR_MIDIMAN, USB_PRODUCT_MIDIMAN_FASTTRACKPRO },
+   UAUDIO_FLAG_BE | UAUDIO_FLAG_DEPENDENT }
 };
 #define uaudio_lookup(v, p) \
((struct uaudio_devs *)usb_lookup(uaudio_devs, v, p))
@@ -444,6 +447,11 @@ uaudio_match(struct device *parent, void
if (uaa->iface == NULL || uaa->device == NULL)
return (UMATCH_NONE);
 
+   if (uaa->vendor == USB_VENDOR_MIDIMAN &&
+   uaa->product == USB_PRODUCT_MIDIMAN_FASTTRACKPRO &&
+   uaa->configno != 2)
+   return UMATCH_NONE;
+
quirk = uaudio_lookup(uaa->vendor, uaa->product);
if (quirk)
flags = quirk->flags;
@@ -531,8 +539,21 @@ uaudio_attach(struct device *parent, str
found = 1;
}
}
-

Re: counters api: always use M_COUNTERS

2017-01-31 Thread Stefan Sperling
On Tue, Jan 31, 2017 at 01:18:05PM +0100, Jeremie Courreges-Anglas wrote:
> 
> As proposed by mpi@ in
> 
>   http://marc.info/?l=openbsd-tech=148585429014645=2
> 
> I think that choosing a "proper" type doesn't bring much information,
> and having one parameter less makes things simpler.  mbuf counters move
> from M_DEVBUF to M_COUNTERS as a result, but I can't see a reason for
> those to be special.
> 
> Comments / oks?

Yes, makes sense. OK.

> Index: kern/subr_percpu.c
> ===
> RCS file: /d/cvs/src/sys/kern/subr_percpu.c,v
> retrieving revision 1.6
> diff -u -p -r1.6 subr_percpu.c
> --- kern/subr_percpu.c11 Jan 2017 17:46:28 -  1.6
> +++ kern/subr_percpu.c31 Jan 2017 11:19:51 -
> @@ -125,7 +125,7 @@ cpumem_next(struct cpumem_iter *i, struc
>  }
>  
>  struct cpumem *
> -counters_alloc(unsigned int n, int type)
> +counters_alloc(unsigned int n)
>  {
>   struct cpumem *cm;
>   struct cpumem_iter cmi;
> @@ -135,7 +135,7 @@ counters_alloc(unsigned int n, int type)
>   KASSERT(n > 0);
>  
>   n++; /* add space for a generation number */
> - cm = cpumem_malloc(n * sizeof(uint64_t), type);
> + cm = cpumem_malloc(n * sizeof(uint64_t), M_COUNTERS);
>  
>   CPUMEM_FOREACH(counters, , cm) {
>   for (i = 0; i < n; i++)
> @@ -146,17 +146,17 @@ counters_alloc(unsigned int n, int type)
>  }
>  
>  struct cpumem *
> -counters_alloc_ncpus(struct cpumem *cm, unsigned int n, int type)
> +counters_alloc_ncpus(struct cpumem *cm, unsigned int n)
>  {
>   n++; /* the generation number */
> - return (cpumem_malloc_ncpus(cm, n * sizeof(uint64_t), type));
> + return (cpumem_malloc_ncpus(cm, n * sizeof(uint64_t), M_COUNTERS));
>  }
>  
>  void
> -counters_free(struct cpumem *cm, int type, unsigned int n)
> +counters_free(struct cpumem *cm, unsigned int n)
>  {
>   n++; /* generation number */
> - cpumem_free(cm, type, n * sizeof(uint64_t));
> + cpumem_free(cm, M_COUNTERS, n * sizeof(uint64_t));
>  }
>  
>  void
> @@ -284,24 +284,24 @@ cpumem_next(struct cpumem_iter *i, struc
>  }
>  
>  struct cpumem *
> -counters_alloc(unsigned int n, int type)
> +counters_alloc(unsigned int n)
>  {
>   KASSERT(n > 0);
>  
> - return (cpumem_malloc(n * sizeof(uint64_t), type));
> + return (cpumem_malloc(n * sizeof(uint64_t), M_COUNTERS));
>  }
>  
>  struct cpumem *
> -counters_alloc_ncpus(struct cpumem *cm, unsigned int n, int type)
> +counters_alloc_ncpus(struct cpumem *cm, unsigned int n)
>  {
>   /* this is unecessary, but symmetrical */
> - return (cpumem_malloc_ncpus(cm, n * sizeof(uint64_t), type));
> + return (cpumem_malloc_ncpus(cm, n * sizeof(uint64_t), M_COUNTERS));
>  }
>  
>  void
> -counters_free(struct cpumem *cm, int type, unsigned int n)
> +counters_free(struct cpumem *cm, unsigned int n)
>  {
> - cpumem_free(cm, type, n * sizeof(uint64_t));
> + cpumem_free(cm, M_COUNTERS, n * sizeof(uint64_t));
>  }
>  
>  void
> Index: kern/uipc_mbuf.c
> ===
> RCS file: /d/cvs/src/sys/kern/uipc_mbuf.c,v
> retrieving revision 1.240
> diff -u -p -r1.240 uipc_mbuf.c
> --- kern/uipc_mbuf.c  25 Jan 2017 09:41:45 -  1.240
> +++ kern/uipc_mbuf.c  31 Jan 2017 11:22:42 -
> @@ -186,7 +186,7 @@ mbinit(void)
>  void
>  mbcpuinit()
>  {
> - mbstat = counters_alloc_ncpus(mbstat, MBSTAT_COUNT, M_DEVBUF);
> + mbstat = counters_alloc_ncpus(mbstat, MBSTAT_COUNT);
>  }
>  
>  void
> Index: net/route.c
> ===
> RCS file: /d/cvs/src/sys/net/route.c,v
> retrieving revision 1.349
> diff -u -p -r1.349 route.c
> --- net/route.c   24 Jan 2017 10:08:30 -  1.349
> +++ net/route.c   31 Jan 2017 11:22:55 -
> @@ -191,7 +191,7 @@ TAILQ_HEAD(rt_labels, rt_label)   rt_label
>  void
>  route_init(void)
>  {
> - rtcounters = counters_alloc(rts_ncounters, M_COUNTERS);
> + rtcounters = counters_alloc(rts_ncounters);
>  
>   pool_init(_pool, sizeof(struct rtentry), 0, IPL_SOFTNET, 0,
>   "rtentry", NULL);
> Index: netinet/igmp.c
> ===
> RCS file: /d/cvs/src/sys/netinet/igmp.c,v
> retrieving revision 1.62
> diff -u -p -r1.62 igmp.c
> --- netinet/igmp.c29 Jan 2017 19:58:47 -  1.62
> +++ netinet/igmp.c31 Jan 2017 11:23:07 -
> @@ -118,7 +118,7 @@ igmp_init(void)
>   igmp_timers_are_running = 0;
>   rti_head = 0;
>  
> - igmpcounters = counters_alloc(igps_ncounters, M_COUNTERS);
> + igmpcounters = counters_alloc(igps_ncounters);
>   router_alert = m_get(M_DONTWAIT, MT_DATA);
>   if (router_alert == NULL) {
>   printf("%s: no mbuf\n", __func__);
> Index: netinet/ip_input.c
> ===
> RCS file: /d/cvs/src/sys/netinet/ip_input.c,v
> retrieving 

Re: counters api: always use M_COUNTERS

2017-01-31 Thread Jeremie Courreges-Anglas
Jeremie Courreges-Anglas  writes:

> As proposed by mpi@ in
>
>   http://marc.info/?l=openbsd-tech=148585429014645=2
>
> I think that choosing a "proper" type doesn't bring much information,
> and having one parameter less makes things simpler.  mbuf counters move
> from M_DEVBUF to M_COUNTERS as a result, but I can't see a reason for
> those to be special.
>
> Comments / oks?

Manpage diff,


Index: counters_alloc.9
===
RCS file: /d/cvs/src/share/man/man9/counters_alloc.9,v
retrieving revision 1.9
diff -u -p -r1.9 counters_alloc.9
--- counters_alloc.914 Nov 2016 06:57:39 -  1.9
+++ counters_alloc.931 Jan 2017 12:26:29 -
@@ -34,16 +34,15 @@
 .Sh SYNOPSIS
 .In sys/percpu.h
 .Ft struct cpumem *
-.Fn counters_alloc "unsigned int ncounters" "int type"
+.Fn counters_alloc "unsigned int ncounters"
 .Ft void
-.Fn counters_free "struct cpumem *cm" "unsigned int ncounters" "int type"
+.Fn counters_free "struct cpumem *cm" "unsigned int ncounters"
 .Fn COUNTERS_BOOT_MEMORY "NAME" "unsigned int ncounters"
 .Fn COUNTERS_BOOT_INITIALIZER "NAME"
 .Ft struct cpumemt *
 .Fo counters_alloc_ncpus
 .Fa "struct cpumem *cm"
 .Fa "unsigned int ncounters"
-.Fa "int type"
 .Fc
 .Ft uint64_t *
 .Fn counters_enter "struct counters_ref *ref" "struct cpumem *cm"
@@ -91,20 +90,13 @@ uni-processor systems.
 allocates memory for a series of uint64_t values on each CPU.
 .Fa ncounters
 specifies the number of counters to be allocated.
-The
-.Fa type
-argument specifies the type of memory that the counters will be
-allocated as via
-.Xr malloc 9 .
 The counters will be zeroed on allocation.
 .Pp
 .Fn counters_free
 deallocates each CPU's counters.
 The same
 .Fa ncounters
-and
-.Fa type
-arguments type originally provided to
+argument originally provided to
 .Fn counters_alloc
 must be passed to
 .Fn counters_free .
@@ -142,11 +134,6 @@ The same number of counters originally p
 .Fa COUNTERS_BOOT_MEMORY
 must be specified by
 .Fa ncounters .
-The
-.Fa type
-argument specifies the type of memory that the counters will be
-allocated as via
-.Xr malloc 9 .
 The counters on the boot CPU will be preserved, while the counters
 for the additional CPUs will be zeroed on allocation.
 .Pp
@@ -264,8 +251,7 @@ struct cpumem *mbstat = COUNTERS_BOOT_IN
 void
 mbcpuinit()
 {
-   mbstat = counters_alloc_ncpus(mbstat, MBSTAT_COUNT,
-   M_DEVBUF);
+   mbstat = counters_alloc_ncpus(mbstat, MBSTAT_COUNT);
 }
 
 struct mbuf *


-- 
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE



Re: ip6stat percpu counters

2017-01-31 Thread Martin Pieuchot
On 31/01/17(Tue) 12:16, Jeremie Courreges-Anglas wrote:
> Martin Pieuchot  writes:
> [...] 
> Yes, but I don't know which threshold warrants introducing a new
> function.  So far those are the first cases for counters_dec(); that
> includes wip rip6stat, icmp6stat, icmpstat and tcpstat.  And I'm not
> even sure those decrements make sense.  I guess we can add counters_dec()
> and then later remove it if it is deemed useless.

Let's convert all the counters first.  If some people think it doesn't
make sense they can change the code afterward.

> >> @@ -222,7 +225,9 @@ rip6_input(struct mbuf **mp, int *offp, 
> >>ICMP6_PARAMPROB_NEXTHEADER,
> >>prvnxtp - mtod(m, u_int8_t *));
> >>}
> >> -  ip6stat.ip6s_delivered--;
> >> +  counters = counters_enter(, ip6counters);
> >> +  counters[ip6s_delivered]--;
> >> +  counters_leave(, ip6counters);
> >
> > Should we also use your counters_dec() here or do you think it's better
> > to merge icmp6_rip6_input() and rip6_input()?
> 
> I'm fine with using counters_dec(), I can see that those functions are
> almost twins but I don't want to open a can of worms...

Why not?  Fewer code is always good!  Anyway, this is something for
later.



Re: ip6stat percpu counters

2017-01-31 Thread Jeremie Courreges-Anglas
Martin Pieuchot  writes:

> On 30/01/17(Mon) 22:14, Jeremie Courreges-Anglas wrote:
>> Very lightly tested.  I used the existing percpu counters as examples.
>
> I like it.
>
>> I don't like the hardcoding of "32" in ip6_input() but I am not sure how
>> to solve it nicely; the easiest way would be to just kill those
>> ipv6-specific mbuf stats.  Would anyone miss them?
>
> I believe it's fine to kill it.

Let's do that.

>> Thoughts?
>
> Some comments below.
>
>> Other netinet6/* counters will follow.
>
> \o/
>
>> @@ -514,14 +514,14 @@ frag6_input(struct mbuf **mp, int *offp,
>>  m_freem(IP6_REASS_MBUF(af6));
>>  free(af6, M_FTABLE, sizeof(*af6));
>>  }
>> -ip6stat.ip6s_fragdropped += q6->ip6q_nfrag;
>> +counters_add(ip6counters, ip6s_fragdropped, q6->ip6q_nfrag);
>
> What about adding & using ip6stat_add()?

Alright.

>> Index: netinet6/icmp6.c
>> ===
>> RCS file: /d/cvs/src/sys/netinet6/icmp6.c,v
>> retrieving revision 1.197
>> diff -u -p -r1.197 icmp6.c
>> --- netinet6/icmp6.c 19 Jan 2017 14:49:19 -  1.197
>> +++ netinet6/icmp6.c 30 Jan 2017 21:02:30 -
>> @@ -1124,8 +1124,13 @@ icmp6_rip6_input(struct mbuf **mp, int o
>>  } else
>>  sorwakeup(last->inp_socket);
>>  } else {
>> +struct counters_ref ref;
>> +uint64_t *counters;
>> +
>>  m_freem(m);
>> -ip6stat.ip6s_delivered--;
>> +counters = counters_enter(, ip6counters);
>> +counters[ip6s_delivered]--;
>> +counters_leave(, ip6counters);
>
> Looks like you found a use case for introducing counters_dec().

Yes, but I don't know which threshold warrants introducing a new
function.  So far those are the first cases for counters_dec(); that
includes wip rip6stat, icmp6stat, icmpstat and tcpstat.  And I'm not
even sure those decrements make sense.  I guess we can add counters_dec()
and then later remove it if it is deemed useless.

>> Index: netinet6/ip6_input.c
>> ===
>> RCS file: /d/cvs/src/sys/netinet6/ip6_input.c,v
>> retrieving revision 1.175
>> diff -u -p -r1.175 ip6_input.c
>> --- netinet6/ip6_input.c 29 Jan 2017 19:58:47 -  1.175
>> +++ netinet6/ip6_input.c 30 Jan 2017 21:02:30 -
>> @@ -117,7 +117,9 @@
>>  struct in6_ifaddrhead in6_ifaddr;
>>  struct niqueue ip6intrq = NIQUEUE_INITIALIZER(IFQ_MAXLEN, NETISR_IPV6);
>>  
>> -struct ip6stat ip6stat;
>> +struct cpumem *ip6counters;
>> +
>> +int ip6_sysctl_ip6stat(void *, size_t *, void *);
>>  
>>  int ip6_check_rh0hdr(struct mbuf *, int *);
>>  
>> @@ -158,6 +160,8 @@ ip6_init(void)
>>  frag6_init();
>>  
>>  mq_init(_mq, 64, IPL_SOFTNET);
>> +
>> +ip6counters = counters_alloc(ip6s_ncounters, M_COUNTERS);
>
> Could you do me a favor and kill the last argument of counters_alloc(9)?

Agreed.

>> Index: netinet6/raw_ip6.c
>> ===
>> RCS file: /d/cvs/src/sys/netinet6/raw_ip6.c,v
>> retrieving revision 1.103
>> diff -u -p -r1.103 raw_ip6.c
>> --- netinet6/raw_ip6.c   23 Jan 2017 16:31:24 -  1.103
>> +++ netinet6/raw_ip6.c   30 Jan 2017 21:02:30 -
>> @@ -211,6 +211,9 @@ rip6_input(struct mbuf **mp, int *offp, 
>>  } else
>>  sorwakeup(last->inp_socket);
>>  } else {
>> +struct counters_ref ref;
>> +uint64_t *counters;
>> +
>>  rip6stat.rip6s_nosock++;
>>  if (m->m_flags & M_MCAST)
>>  rip6stat.rip6s_nosockmcast++;
>> @@ -222,7 +225,9 @@ rip6_input(struct mbuf **mp, int *offp, 
>>  ICMP6_PARAMPROB_NEXTHEADER,
>>  prvnxtp - mtod(m, u_int8_t *));
>>  }
>> -ip6stat.ip6s_delivered--;
>> +counters = counters_enter(, ip6counters);
>> +counters[ip6s_delivered]--;
>> +counters_leave(, ip6counters);
>
> Should we also use your counters_dec() here or do you think it's better
> to merge icmp6_rip6_input() and rip6_input()?

I'm fine with using counters_dec(), I can see that those functions are
almost twins but I don't want to open a can of worms...

-- 
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE



Re: iwm(4): Update struct iwm_scan_results_notif. Remove a few old defines.

2017-01-31 Thread Stefan Sperling
On Mon, Jan 30, 2017 at 12:07:46PM +0100, Imre Vadász wrote:
> Thanks, this patch was trying to remove the struct iwm_scan_complete_notif
> definition that was already removed in one of the previous diffs.
> fixed patch:

Committed. Thank you!



rtwn: fix hardware admission control config

2017-01-31 Thread Stefan Sperling
In my latest commit I enabled "hardware AC queue management" in rtwn.

Upon closer investigation, this register works differently. It needs to
reflect "ACM" (admission control mandatory) flags which the AP sends to
clients in EDCA parameters.

There is one such flag per traffic class, and the lowest class never sets it.
If the flag is set for a traffic class, clients can ask the AP for some
exlusively reserved bandwidth (actually, air time) within this traffic class.
Which is why all this stuff falls into the area of quality of service (QOS).
The basic idea is that, during periods of contention for the medium, frames
in higher traffic classes are sent before frames in lower classes.

ieee80211_parse_edca_params_body() stores this flag in ac->ac_acm.
Our sets of default EDCA parameters do not set these flags, so with
an OpenBSD AP the flags will never be set.

See also ieee80211_up_to_ac() in ieee80211_output.c which looks at this
bit in a different context. It avoids sending in a traffic class which
requires admission and falls back to one that does not.

Anyway, it is better to actually tell the hardware what's going on
rather than always setting these bits.

Index: rtwn.c
===
RCS file: /cvs/src/sys/dev/ic/rtwn.c,v
retrieving revision 1.16
diff -u -p -r1.16 rtwn.c
--- rtwn.c  31 Jan 2017 09:21:46 -  1.16
+++ rtwn.c  31 Jan 2017 09:47:38 -
@@ -1068,6 +1068,7 @@ rtwn_updateedca(struct ieee80211com *ic)
};
struct ieee80211_edca_ac_params *ac;
int s, aci, aifs, slottime;
+   uint8_t acm = 0;
 
if (ic->ic_flags & IEEE80211_F_SHSLOT)
slottime = 9; /* XXX needs a macro in ieee80211.h */
@@ -1083,8 +1084,28 @@ rtwn_updateedca(struct ieee80211com *ic)
SM(R92C_EDCA_PARAM_ECWMIN, ac->ac_ecwmin) |
SM(R92C_EDCA_PARAM_ECWMAX, ac->ac_ecwmax) |
SM(R92C_EDCA_PARAM_AIFS, aifs));
+
+   /* Is admission control mandatory for this queue? */
+   if (ac->ac_acm) {
+   switch (aci) {
+   case EDCA_AC_BE:
+   acm |= R92C_ACMHW_BEQEN;
+   break;
+   case EDCA_AC_VI:
+   acm |= R92C_ACMHW_VIQEN;
+   break;
+   case EDCA_AC_VO:
+   acm |= R92C_ACMHW_VOQEN;
+   break;
+   default:
+   break;
+   }
+   }
}
splx(s);
+
+   /* Enable hardware admission control. */
+   rtwn_write_1(sc, R92C_ACMHWCTRL, R92C_ACMHW_HWEN | acm);
 }
 
 int
@@ -1725,10 +1746,6 @@ rtwn_edca_init(struct rtwn_softc *sc)
rtwn_write_4(sc, R92C_FAST_EDCA_CTRL, 0x08); /* linux magic */
 
rtwn_write_4(sc, R92C_EDCA_RANDOM_GEN, arc4random());
-
-   /* Enable hardware AC queue management. */
-   rtwn_write_1(sc, R92C_ACMHWCTRL, R92C_ACMHW_HWEN | R92C_ACMHW_BEQEN |
-   R92C_ACMHW_VIQEN | R92C_ACMHW_VOQEN);
 }
 
 void



Re: Help with the NET_LOCK()

2017-01-31 Thread Martin Pieuchot
On 27/01/17(Fri) 14:33, David Hill wrote:
> [...] 
> Forgot a file...   Try this:

Is it now possible to pass a 'struct mbuf *' instead of a 'struct mbuf **'
to the pr_ctloutput() functions?

Changing the signature would ensure we do not miss a call.  This would
also simplify the SETOPT case.

> Index: kern/uipc_socket.c
> ===
> RCS file: /cvs/src/sys/kern/uipc_socket.c,v
> retrieving revision 1.174
> diff -u -p -r1.174 uipc_socket.c
> --- kern/uipc_socket.c26 Jan 2017 00:08:50 -  1.174
> +++ kern/uipc_socket.c27 Jan 2017 19:30:31 -
> @@ -1758,11 +1758,19 @@ sogetopt(struct socket *so, int level, i
>  
>   if (level != SOL_SOCKET) {
>   if (so->so_proto && so->so_proto->pr_ctloutput) {
> + m = m_get(M_WAIT, MT_SOOPTS);
> + m->m_len = 0;
> +
>   NET_LOCK(s);
>   error = (*so->so_proto->pr_ctloutput)(PRCO_GETOPT, so,
> - level, optname, mp);
> + level, optname, );
>   NET_UNLOCK(s);
> - return (error);
> + if (error) {
> + m_free(m);
> + return (error);
> + }
> + *mp = m;
> + return (0);
>   } else
>   return (ENOPROTOOPT);
>   } else {
> @@ -1835,21 +1843,25 @@ sogetopt(struct socket *so, int level, i
>   }
>  
>   case SO_RTABLE:
> - (void)m_free(m);
>   if (so->so_proto && so->so_proto->pr_domain &&
>   so->so_proto->pr_domain->dom_protosw &&
>   so->so_proto->pr_ctloutput) {
>   struct domain *dom = so->so_proto->pr_domain;
>  
>   level = dom->dom_protosw->pr_protocol;
> + 
>   NET_LOCK(s);
>   error = (*so->so_proto->pr_ctloutput)
> - (PRCO_GETOPT, so, level, optname, mp);
> + (PRCO_GETOPT, so, level, optname, );
>   NET_UNLOCK(s);
> - return (error);
> + if (error) {
> + (void)m_free(m);
> + return (error);
> + }
> + break;
>   }
> + (void)m_free(m);
>   return (ENOPROTOOPT);
> - break;
>  
>  #ifdef SOCKET_SPLICE
>   case SO_SPLICE:
> @@ -1880,7 +1892,6 @@ sogetopt(struct socket *so, int level, i
>   }
>   (void)m_free(m);
>   return (EOPNOTSUPP);
> - break;
>  
>   default:
>   (void)m_free(m);
> Index: net/rtsock.c
> ===
> RCS file: /cvs/src/sys/net/rtsock.c,v
> retrieving revision 1.220
> diff -u -p -r1.220 rtsock.c
> --- net/rtsock.c  24 Jan 2017 00:17:14 -  1.220
> +++ net/rtsock.c  27 Jan 2017 19:30:31 -
> @@ -277,12 +277,12 @@ route_ctloutput(int op, struct socket *s
>   case PRCO_GETOPT:
>   switch (optname) {
>   case ROUTE_MSGFILTER:
> - *mp = m = m_get(M_WAIT, MT_SOOPTS);
> + m = *mp;
>   m->m_len = sizeof(unsigned int);
>   *mtod(m, unsigned int *) = rop->msgfilter;
>   break;
>   case ROUTE_TABLEFILTER:
> - *mp = m = m_get(M_WAIT, MT_SOOPTS);
> + m = *mp;
>   m->m_len = sizeof(unsigned int);
>   *mtod(m, unsigned int *) = rop->rtableid;
>   break;
> Index: netinet/ip_mroute.c
> ===
> RCS file: /cvs/src/sys/netinet/ip_mroute.c,v
> retrieving revision 1.107
> diff -u -p -r1.107 ip_mroute.c
> --- netinet/ip_mroute.c   12 Jan 2017 08:22:42 -  1.107
> +++ netinet/ip_mroute.c   27 Jan 2017 19:30:31 -
> @@ -225,8 +225,6 @@ ip_mrouter_get(struct socket *so, int op
>   if (so != ip_mrouter[inp->inp_rtableid])
>   error = ENOPROTOOPT;
>   else {
> - *mp = m_get(M_WAIT, MT_SOOPTS);
> -
>   switch (optname) {
>   case MRT_VERSION:
>   error = get_version(*mp);
> @@ -241,9 +239,6 @@ ip_mrouter_get(struct socket *so, int op
>   error = ENOPROTOOPT;
>   break;
>   }
> -
> - if (error)
> - 

Re: [wscons] User-space access to terminal emulation data

2017-01-31 Thread Martin Pieuchot
Hello Enrico,

On 26/01/17(Thu) 14:41, Enrico Mioso wrote:
> Hello to everyone reading this message, and thank you.

Welcome to OpenBSD hacking!

> I am a blind user, using a braille display to read the output of my
> computer. Each braille display has it's own protocol, so there is the need
> of a software package (specifically a daemon process), that reads the output
> of the system and sends it to the braille device using the appropriate
> protocol. The BRLTTY software does exactly that (
> http://dave.mielke.cc/brltty ). My goal was to make it possible for a blind
> user to use OpenBSD on a standalone system, without serial consoles, a setup
> that may not confortable, on laptops for example.

Nice goal.

> To this end, I was playing with the wscons subsystem, to allow for
> user-space to access terminal emulation (wsemul) data.
> This would enable access to the system even before login, and may also be
> useful to access a shell in early boot stages if something goes wrong...
> 
> The idea was to allocate a memory zone for each wscreen, where an emulation
> module (for example wsemul_vt100) could copy the data (characters and color
> attributes). In addition, some auxiliary informations are saved (the
> position of the cursor and the number of rows and columns).
> This data would then be exported to user-space via some interfaces like
> mmap, or by other means.

I think that the kernel/userland interface is the first thing that need
to be though.  Letting userland programs access kernel memory is
something that we try to avoid.

I see that brltty already has some support from OpenBSD.  So there's no
support for getting the wscreen information?  Do you know which interface
other OSes provide for that?

>  My goal is to make OpenBSD more "accessible2, or
> braille friendly in other words: making it more confortable to administer a
> system even for a braille user. I am posting now some hackish code I came up
> with so far, to hear from you. I am absolutely open (and hoping) for any
> suggestions and comments / ideas: and doing things in a completely different
> ways. Consider the code like a kind of proof-of-concept. I would clearly
> avoid using printfs like this, and I clearly would use something like
> #ifdef HAVE_UWSEMUL
> and not
> #if 11
> around. I know that, especially in the case of kernel code, security and
> quality are very important: and I will do my best.
> Regarding my choice to work in the emulation framework: I tried to find a
> solution that would work across different platforms. For that matter, I
> avoided the VGA driver for example, and the VGA memory region. I can also
> consider this altenrative if you let me know. For now I worked only on the
> vt100 emulation, but the idea was to put all uwsemul code in
> wsdisplay_subr.c or in some other file, and call needed functions in all
> emulation modules. This code may show signs of inexperience, but I am
> willing to learn, and at least try.

Having an #ifdef I guess is ok.  Regarding your contribution I'd suggest
you read the style(9) manual.  We try to all apply to these rules.

Cheers,
Martin

> diff --git a/sys/dev/wscons/wsdisplay.c b/sys/dev/wscons/wsdisplay.c
> index cb7bde50593..2980e738ce4 100644
> --- a/sys/dev/wscons/wsdisplay.c
> +++ b/sys/dev/wscons/wsdisplay.c
> @@ -130,6 +130,9 @@ struct wsscreen {
>  #define IS_SEL_BY_WORD(scr)  ((scr)->mouse_flags & SEL_BY_WORD)
>  #define IS_SEL_BY_LINE(scr)  ((scr)->mouse_flags & SEL_BY_LINE)
>  #endif   /* HAVE_WSMOUSED_SUPPORT */
> +#if 11
> + void *uwsmem;
> +#endif
>  };
> 
>  struct wsscreen *wsscreen_attach(struct wsdisplay_softc *, int, const char *,
> @@ -263,6 +266,9 @@ wsscreen_attach(struct wsdisplay_softc *sc, int console, 
> const char *emul,
>  {
>   struct wsscreen_internal *dconf;
>   struct wsscreen *scr;
> +#if 11
> + struct uwsemul_info *u_info;
> +#endif
> 
>   scr = malloc(sizeof(*scr), M_DEVBUF, M_ZERO | M_NOWAIT);
>   if (!scr)
> @@ -294,6 +300,16 @@ wsscreen_attach(struct wsdisplay_softc *sc, int console, 
> const char *emul,
>   scr->scr_dconf = dconf;
>   scr->scr_tty = ttymalloc(0);
>   scr->sc = sc;
> +#if 11
> + printf("uwsemul_access: %d rows and %d 
> columns",scr->scr_dconf->scrdata->nrows,scr->scr_dconf->scrdata->ncols);
> + scr->uwsmem = malloc(sizeof(struct uwsemul_info)+(sizeof(struct 
> wsdisplay_charcell)*(scr->scr_dconf->scrdata->nrows*scr->scr_dconf->scrdata->ncols)),
>  M_DEVBUF, M_ZERO | M_NOWAIT);
> + if (!scr->uwsmem)
> + goto fail;
> + printf(": %ld bytes allocated at address %p\n",sizeof(struct 
> uwsemul_info)+(sizeof(struct 
> wsdisplay_charcell)*(scr->scr_dconf->scrdata->nrows*scr->scr_dconf->scrdata->ncols)),scr->uwsmem);
> + u_info = scr->uwsmem;
> + u_info->nrows = scr->scr_dconf->scrdata->nrows;
> + u_info->ncols = scr->scr_dconf->scrdata->ncols;
> +#endif
>   return (scr);
> 
>  fail:
> @@ -315,6 +331,10 @@ 

11n hostap: send correct edca params to clients

2017-01-31 Thread Stefan Sperling
In hostap mode, when copying EDCA parameters into frames we send to clients,
we copy EDCA parameters from the "QOS AP" table (ieee80211_qap_edca_table).

But values in these frames tell clients what parameters to use themselves.
So copy parameters from the "QOS client" table (ieee80211_edca_table) instead.

Index: ieee80211_output.c
===
RCS file: /cvs/src/sys/net80211/ieee80211_output.c,v
retrieving revision 1.115
diff -u -p -r1.115 ieee80211_output.c
--- ieee80211_output.c  30 Jan 2017 18:21:13 -  1.115
+++ ieee80211_output.c  31 Jan 2017 08:54:48 -
@@ -767,7 +767,7 @@ ieee80211_add_edca_params(u_int8_t *frm,
*frm++ = 0; /* reserved */
 
/* setup AC Parameter Records */
-   edca = ieee80211_qap_edca_table[ic->ic_curmode];
+   edca = ieee80211_edca_table[ic->ic_curmode];
for (aci = 0; aci < EDCA_NUM_AC; aci++) {
const struct ieee80211_edca_ac_params *ac = [aci];
 
@@ -867,7 +867,7 @@ ieee80211_add_wme_param(uint8_t *frm, st
*frm++ = 0; /* reserved */
 
/* setup AC Parameter Records */
-   edca = ieee80211_qap_edca_table[ic->ic_curmode];
+   edca = ieee80211_edca_table[ic->ic_curmode];
for (aci = 0; aci < EDCA_NUM_AC; aci++) {
const struct ieee80211_edca_ac_params *ac = [aci];
 



Re: ip6stat percpu counters

2017-01-31 Thread Martin Pieuchot
On 30/01/17(Mon) 22:14, Jeremie Courreges-Anglas wrote:
> Very lightly tested.  I used the existing percpu counters as examples.

I like it.

> I don't like the hardcoding of "32" in ip6_input() but I am not sure how
> to solve it nicely; the easiest way would be to just kill those
> ipv6-specific mbuf stats.  Would anyone miss them?

I believe it's fine to kill it.

> Thoughts?

Some comments below.

> Other netinet6/* counters will follow.

\o/

> @@ -514,14 +514,14 @@ frag6_input(struct mbuf **mp, int *offp,
>   m_freem(IP6_REASS_MBUF(af6));
>   free(af6, M_FTABLE, sizeof(*af6));
>   }
> - ip6stat.ip6s_fragdropped += q6->ip6q_nfrag;
> + counters_add(ip6counters, ip6s_fragdropped, q6->ip6q_nfrag);

What about adding & using ip6stat_add()?

> Index: netinet6/icmp6.c
> ===
> RCS file: /d/cvs/src/sys/netinet6/icmp6.c,v
> retrieving revision 1.197
> diff -u -p -r1.197 icmp6.c
> --- netinet6/icmp6.c  19 Jan 2017 14:49:19 -  1.197
> +++ netinet6/icmp6.c  30 Jan 2017 21:02:30 -
> @@ -1124,8 +1124,13 @@ icmp6_rip6_input(struct mbuf **mp, int o
>   } else
>   sorwakeup(last->inp_socket);
>   } else {
> + struct counters_ref ref;
> + uint64_t *counters;
> +
>   m_freem(m);
> - ip6stat.ip6s_delivered--;
> + counters = counters_enter(, ip6counters);
> + counters[ip6s_delivered]--;
> + counters_leave(, ip6counters);

Looks like you found a use case for introducing counters_dec().

> Index: netinet6/ip6_input.c
> ===
> RCS file: /d/cvs/src/sys/netinet6/ip6_input.c,v
> retrieving revision 1.175
> diff -u -p -r1.175 ip6_input.c
> --- netinet6/ip6_input.c  29 Jan 2017 19:58:47 -  1.175
> +++ netinet6/ip6_input.c  30 Jan 2017 21:02:30 -
> @@ -117,7 +117,9 @@
>  struct in6_ifaddrhead in6_ifaddr;
>  struct niqueue ip6intrq = NIQUEUE_INITIALIZER(IFQ_MAXLEN, NETISR_IPV6);
>  
> -struct ip6stat ip6stat;
> +struct cpumem *ip6counters;
> +
> +int ip6_sysctl_ip6stat(void *, size_t *, void *);
>  
>  int ip6_check_rh0hdr(struct mbuf *, int *);
>  
> @@ -158,6 +160,8 @@ ip6_init(void)
>   frag6_init();
>  
>   mq_init(_mq, 64, IPL_SOFTNET);
> +
> + ip6counters = counters_alloc(ip6s_ncounters, M_COUNTERS);

Could you do me a favor and kill the last argument of counters_alloc(9)?

> Index: netinet6/raw_ip6.c
> ===
> RCS file: /d/cvs/src/sys/netinet6/raw_ip6.c,v
> retrieving revision 1.103
> diff -u -p -r1.103 raw_ip6.c
> --- netinet6/raw_ip6.c23 Jan 2017 16:31:24 -  1.103
> +++ netinet6/raw_ip6.c30 Jan 2017 21:02:30 -
> @@ -211,6 +211,9 @@ rip6_input(struct mbuf **mp, int *offp, 
>   } else
>   sorwakeup(last->inp_socket);
>   } else {
> + struct counters_ref ref;
> + uint64_t *counters;
> +
>   rip6stat.rip6s_nosock++;
>   if (m->m_flags & M_MCAST)
>   rip6stat.rip6s_nosockmcast++;
> @@ -222,7 +225,9 @@ rip6_input(struct mbuf **mp, int *offp, 
>   ICMP6_PARAMPROB_NEXTHEADER,
>   prvnxtp - mtod(m, u_int8_t *));
>   }
> - ip6stat.ip6s_delivered--;
> + counters = counters_enter(, ip6counters);
> + counters[ip6s_delivered]--;
> + counters_leave(, ip6counters);

Should we also use your counters_dec() here or do you think it's better
to merge icmp6_rip6_input() and rip6_input()?