Re: tap(4) performance tuning on (amd64)

2020-01-20 Thread Claudio Jeker
On Tue, Jan 21, 2020 at 02:44:35AM +, Tom Smyth wrote:
> Claudio,
> Thanks for this,
> I compiled  it on Openbsd 6.6 (stable) amd64
> 
> it compiled without error
> 
> the binary seems to run  fine but,
> ./tbridge -k /dev/tap0 /dev/tap1
> 
> runs and displays the usage message and  gives an errorlevel of 1
> every time  use the -k or -t or -s or -p arguments   see  terminal
> conversation below
> 

Shit, I added a last minute check and as usual introduced a bug.
Line 189 change if (ch != 0) to if (mode != 0)

-- 
:wq Claudio

/*
 * Copyright (c) 2020 Claudio Jeker 
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */
#include 
#include 
#include 

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

volatile sig_atomic_tquit;

static void
do_read(int in, int out)
{
char buf[2048];
ssize_t n, o;

n = read(in, buf, sizeof(buf));
if (n == -1)
err(1, "read");
o = write(out, buf, n);
if (o == -1)
err(1, "read");
if (o != n)
errx(1, "short write");
}

static void
do_poll(int fd[2])
{
struct pollfd pfd[2];
int n, i;

while (quit == 0) {
memset(pfd, 0, sizeof(pfd));
pfd[0].fd = fd[0];
pfd[0].events = POLLIN;

pfd[1].fd = fd[1];
pfd[1].events = POLLIN;

n = poll(pfd, 2, INFTIM);
if (n == -1)
err(1, "poll");
if (n == 0)
errx(1, "poll: timeout");
for (i = 0; i < 2; i++) {
if (pfd[i].revents & POLLIN)
do_read(fd[i], fd[(i + 1) & 0x1]);
else if (pfd[i].revents & (POLLHUP | POLLERR))
errx(1, "fd %d revents %x", i, pfd[i].revents);
}
}

}

static void
do_select(int fd[2])
{
fd_set readfds;
int n, i, maxfd = -1;

while (quit == 0) {
FD_ZERO();
for (i = 0; i < 2; i++) {
if (fd[i] > maxfd)
maxfd = fd[i];
FD_SET(fd[i], );
}
n = select(maxfd + 1, , NULL, NULL, NULL);
if (n == -1)
err(1, "select");
if (n == 0)
errx(1, "select: timeout");
for (i = 0; i < 2; i++) {
if (FD_ISSET(fd[i], ))
do_read(fd[i], fd[(i + 1) & 0x1]);
}
}
}

static void
do_kqueue(int fd[2])
{
struct kevent kev[2];
int kq, i, n;

if ((kq = kqueue()) == -1)
err(1, "kqueue");

memset(kev, 0, sizeof(kev));
for (i = 0; i < 2; i++) {
EV_SET([i], fd[i], EVFILT_READ, EV_ADD | EV_ENABLE,
0, 0, (void *)(intptr_t)i);
}
if (kevent(kq, kev, 2, NULL, 0, NULL) == -1)
err(1, "kevent register");

while (quit == 0) {
n = kevent(kq, NULL, 0, kev, 2, NULL);
if (n == -1)
err(1, "kevent");
if (n == 0)
errx(1, "kevent: timeout");
for (i = 0; i < n; i++) {
if (kev[i].flags & EV_ERROR)
errc(1, kev[i].data, "kevent EV_ERROR");
if (kev[i].filter == EVFILT_READ) {
int r = (int)kev[i].udata;
do_read(fd[r], fd[(r + 1) & 0x1]);
}
}
}
}

static void *
run_thread(void *arg)
{
int *fd = arg;

while (quit == 0)
do_read(fd[0], fd[1]);

return NULL;
}

static void
do_thread(int fd[2])
{
pthread_t tid;
int ret;

ret = pthread_create(, NULL, run_thread, fd);
if (ret)  {
errc(1, ret, "pthread_create");
}

while (quit == 0)
do_read(fd[1], fd[0]);
}

static void
sighdlr(int sig)
{
quit = 1;
}

static __dead void
usage(void)
{

Re: less --no-init and multiline $PS1

2020-01-20 Thread Theo de Raadt
The diff is clearly a layer violation, trying to interpret and dance
for an event which happens after less terminates.

What comes next, someone wanting ANSI control characters to be parsed
and evaluated to avoid screen damage?

Richard Ulmer  wrote:

> Hi,
> when using a $PS1, which has more than one line, `less --no-init` cuts
> of some lines at the top, when it quits. This is especially annyoing
> when using `git diff` and `git show`. For example,
> `echo "foo\nbar" | less --no-init --quit-if-one-screen` with a two-line
> $PS1 leads to terminal content like this:
> 
> .---.
> | bar   |
> | ~ |
> | ~ |
> | PS1 line 1|
> | PS1 line 2$   |
> `---'
> 
> I think, that using an environment variable like $PS1_LINES to inform
> less about a multiline $PS1, would be a solution for the problem. This
> is what I came up with:
> 
> Index: usr.bin/less/funcs.h
> ===
> RCS file: /cvs/src/usr.bin/less/funcs.h,v
> retrieving revision 1.25
> diff -u -p -u -r1.25 funcs.h
> --- usr.bin/less/funcs.h  2 Sep 2019 14:07:45 -   1.25
> +++ usr.bin/less/funcs.h  19 Jan 2020 11:23:56 -
> @@ -30,6 +30,7 @@ void ring_bell(void);
>  void do_clear(void);
>  void clear_eol(void);
>  void clear_bot(void);
> +void clear_above_bot(int);
>  void at_enter(int);
>  void at_exit(void);
>  void at_switch(int);
> Index: usr.bin/less/main.c
> ===
> RCS file: /cvs/src/usr.bin/less/main.c,v
> retrieving revision 1.37
> diff -u -p -u -r1.37 main.c
> --- usr.bin/less/main.c   28 Jun 2019 05:44:09 -  1.37
> +++ usr.bin/less/main.c   19 Jan 2020 11:23:56 -
> @@ -47,6 +47,7 @@ extern char *tags;
>  extern char  *tagoption;
>  extern int   jump_sline;
>  extern int   less_is_more;
> +extern int   ps1_lines;
>  extern int   missing_cap;
>  extern int   know_dumb;
>  extern int   quit_if_one_screen;
> @@ -102,6 +103,9 @@ main(int argc, char *argv[])
>   }
>   }
>  
> + if ((s = lgetenv("PS1_LINES")) != NULL)
> + ps1_lines = atoi(s);
> +
>   /*
>* Process command line arguments and LESS environment arguments.
>* Command line arguments override environment arguments.
> @@ -383,8 +387,10 @@ quit(int status)
>   edit(NULL);
>   if (!secure)
>   save_cmdhist();
> - if (any_display && is_tty)
> + if (any_display && is_tty) {
>   clear_bot();
> + clear_above_bot(ps1_lines - 1);
> + }
>   deinit();
>   flush(1);
>   raw_mode(0);
> Index: usr.bin/less/opttbl.c
> ===
> RCS file: /cvs/src/usr.bin/less/opttbl.c,v
> retrieving revision 1.19
> diff -u -p -u -r1.19 opttbl.c
> --- usr.bin/less/opttbl.c 17 Sep 2016 15:06:41 -  1.19
> +++ usr.bin/less/opttbl.c 19 Jan 2020 11:23:56 -
> @@ -53,6 +53,7 @@ int opt_use_backslash;  /* Use backslash 
>  int hilite_search;   /* Highlight matched search patterns? */
>  
>  int less_is_more = 0;/* Make compatible with POSIX more */
> +int ps1_lines = 1;   /* Height of the primary prompt */
>  
>  /*
>   * Long option names.
> Index: usr.bin/less/screen.c
> ===
> RCS file: /cvs/src/usr.bin/less/screen.c,v
> retrieving revision 1.25
> diff -u -p -u -r1.25 screen.c
> --- usr.bin/less/screen.c 3 Sep 2019 23:08:42 -   1.25
> +++ usr.bin/less/screen.c 19 Jan 2020 11:23:56 -
> @@ -34,6 +34,7 @@ static char
>   *sc_lower_left, /* Cursor to last line, first column */
>   *sc_return, /* Cursor to beginning of current line */
>   *sc_move,   /* General cursor positioning */
> + *sc_up, /* Cursor up one line */
>   *sc_clear,  /* Clear screen */
>   *sc_eol_clear,  /* Clear to end of line */
>   *sc_eos_clear,  /* Clear to end of screen */
> @@ -87,6 +88,7 @@ extern int tty;
>  extern int top_scroll;
>  extern int oldbot;
>  extern int hilite_search;
> +extern int ps1_lines;
>  
>  /*
>   * Change terminal to "raw mode", or restore to "normal" mode.
> @@ -414,6 +416,10 @@ get_term(void)
>   }
>   sc_lower_left = cheaper(t1, t2, "\r");
>  
> + sc_up = cursor_up;
> + if (ps1_lines > 1 && sc_up == NULL)
> + missing_cap = 1;
> +
>   /*
>* Get carriage return string.
>*/
> @@ -699,6 +705,20 @@ clear_bot(void)
>   at_exit();
>   clear_eol_bot();
>   at_enter(saved_attrmode);
> + }
> +}
> +
> +/*
> + * Clear n lines above the bottom line of the display.
> + * The cursor must be set to the beginning of the bottom line before.
> + */
> +void
> +clear_above_bot(int n)
> +{
> + int i;
> + for (i = 0; i < n; i++) 

Re: tap(4) performance tuning on (amd64)

2020-01-20 Thread Tom Smyth
Claudio,
Thanks for this,
I compiled  it on Openbsd 6.6 (stable) amd64

it compiled without error

the binary seems to run  fine but,
./tbridge -k /dev/tap0 /dev/tap1

runs and displays the usage message and  gives an errorlevel of 1
every time  use the -k or -t or -s or -p arguments   see  terminal
conversation below


test3b# ./tbridge -k /dev/tap0 /dev/tap1
tbridge -k | -p | -s | -t tapA tapB
persistentg3b# ./tbridge -p /dev/tap0 /dev/tap1
tbridge -k | -p | -s | -t tapA tapB
test3b# echo $?
1
test3b# ./tbridge -s /dev/tap0 /dev/tap1
tbridge -k | -p | -s | -t tapA tapB
test3b# echo $?
1
test3b# ./tbridge -t /dev/tap0 /dev/tap1
tbridge -k | -p | -s | -t tapA tapB
test3b# echo $?
1
test3b# ./tbridge /dev/tap0 /dev/tap1
test3b# echo $?
0

I tried with and without creating the tunnel interfaces first,  with
ifconfig tap create
i tried with our without running ifconfig tap1 up
i tried with and without adding each tap to a separate  bridge(4)
I ran  the binary as root  for all tests
I tried running tbridge with interface name "tap1" / "tap0"  as opposed
to the device name /dev/tap1 /dev/tap2 (just in case)

 will try with current  after I get some sleep
( was just trying to do a benchmark of release /stable vs  current  also )


Thanks for this it is a help
 as I was trying and (losing with socat)  I think socat port on
OpenBSD6.6 amd64
is compiled without tap / tun support

cheers,
Tom Smyth






On Mon, 20 Jan 2020 at 10:38, Claudio Jeker  wrote:
>
> On Fri, Jan 10, 2020 at 01:00:49PM +, Tom Smyth wrote:
> > Hi lads,
> >
> > I have been doing some testing with tap(4) and openvpn (standard ssl )
> > I have been using openvpn with tap and I have been trying with null
> > encryption. null authentication,
> > the performance of the tap interface  seems to be about 100-150Mb/s  on a 
> > system
> > which can give  3Gb/s-5Gb/s on ix(4) interfaces  in Bridge mode and
> > 4-8Gb/s on tpmr mode
> > I was wondering is there a sysctl setting that if modified would
> > improve the tap interface performance.
> > I have tried with tpmr(4) and  bridge(4)
> >
> > is there a simple way  testing a tap(4) interface throughput /
> > performance without Openvpn process
> >
> > I can try mlvpn and wireguard
> > but I would love if there was a trick where I can just test the tap(4)
> > interface  with something like pair(4)...
> >
> > ix0---bridge0--tap0---someprocess--tap1-bridge1--ix1
> > or
> > ix0--tpmr0--tap0--someprocess--tap1-tpmr1-ix1
> >
> > is there a simple "someprocess" that would provide forwarding packets
> > between tap0 and tap1 in userland
> > so that any performance testing on tap(4) interfaces does not have the
> > distractions of complex userland programs with encryption /
> > encapsulation overheads
> >
>
> I just wrote a simple tun/tap bridge for testing so here you go.
> Compile it with 'cc -Wall -o tbridge tbridge.c -lpthread' and run it
> with 'tbridge -k /dev/tun0 /dev/tun1' to wire tun0 and tun1 together.
> You can select between, select(2), poll(2), kqueue(2) and pthreads as the
> way on how to multiplex the reads.
>
> For me the code triggers scheduler inefficencies and causes packets drops
> on the output queue when there are multiple packet producers.
> --
> :wq Claudio
>
> /*
>  * Copyright (c) 2020 Claudio Jeker 
>  *
>  * Permission to use, copy, modify, and distribute this software for any
>  * purpose with or without fee is hereby granted, provided that the above
>  * copyright notice and this permission notice appear in all copies.
>  *
>  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
>  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
>  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
>  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
>  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
>  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
>  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
>  */
> #include 
> #include 
> #include 
>
> #include 
> #include 
> #include 
> #include 
> #include 
> #include 
> #include 
> #include 
> #include 
> #include 
>
> volatile sig_atomic_tquit;
>
> static void
> do_read(int in, int out)
> {
> char buf[2048];
> ssize_t n, o;
>
> n = read(in, buf, sizeof(buf));
> if (n == -1)
> err(1, "read");
> o = write(out, buf, n);
> if (o == -1)
> err(1, "read");
> if (o != n)
> errx(1, "short write");
> }
>
> static void
> do_poll(int fd[2])
> {
> struct pollfd pfd[2];
> int n, i;
>
> while (quit == 0) {
> memset(pfd, 0, sizeof(pfd));
> pfd[0].fd = fd[0];
> pfd[0].events = POLLIN;
>
> pfd[1].fd = fd[1];
> pfd[1].events = POLLIN;
>
> n = poll(pfd, 2, INFTIM);
> if (n == 

Re: Display flickers after upgrade to 6.6

2020-01-20 Thread Stanislav Gilmulin

Yes, I have customized xorg.conf via /etc/X11/xorg.conf.d/intel.conf :

Section "Device"
  Identifier "drm0"
  Driver "intel"
  Option "TearFree" "true"
EndSection

I checked /var/log/Xorg.0.log, "intel" driver works without errors.

Unfortunately I did not solve the problem modifying this configuration 
file.


P.S. The https://man.openbsd.org/intel page mentions 
"XV_SYNC_TO_VBLANK". Even if it might be solution, actually I m not sure 
I can set this attribute.


On 10-01-2020 20:58, Dumitru Moldovan wrote:

On Fri, Jan 10, 2020 at 10:18:51AM -0700, Stanislav wrote:

I have got weak flickering of XFCE too (after upgrade to 6.6).
Mentioned setting the method for vblank does not fix it. Turning 
on/off

compositor does not help too.
Any ideas?



Have you tried customizing xorg.conf?  This /etc/X11/xorg.conf works 
for

me in 6.6 with the Radeon HD 4200 video chipset from my old desktop:

Section "Device"
   Identifier "drm0"
   Driver "radeon"
   Option "AccelMethod" "glamor"
   Option "DRI" "3"
   Option "TearFree" "On"
   Option "SWCursor" "true"
EndSection

Still getting a bit of glitches when resuming, but mostly just for the
current window (the terminal) and it's usually enough to change the
active "window" in tmux to get rid of it.  Rarely do I have to change
to console and back with CTRL-ALT-F1 and CTRL-ALT-F5.  Had more issues
with the older driver (and default settings), so I'm actually happy
with the upgrade in this regard.




Re: glib2: File not found (Ruby on Rails: replacing ImageMagick with the much faster Vips)

2020-01-20 Thread 1234dev
Update: Figured it'd be best to just open up an issue over at ruby-vips: 
https://github.com/libvips/ruby-vips/issues/221

Thanks!

Sent with [ProtonMail](https://protonmail.com) Secure Email.

‐‐‐ Original Message ‐‐‐
On Monday, January 20, 2020 9:47 AM, 1234dev <1234...@protonmail.com> wrote:

> Hi!
>
> I'm trying to switch from ImageMagick over to the newer and much faster Vips 
> (https://libvips.github.io/libvips/) in my Rails app. However, despite having 
> glib2-2.60.7 installed on OpenBSD 6.6, I'm getting LoadError (Could not open 
> library 'glib-2.0.so.0': File not found).
>
> Any chance anybody here knows how to fix this?
>
> Thanks,
> Jonathan
>
> Ref. https://bloggie.io/@kinopyo/upgrade-guide-active-storage-in-rails-6
>
> Sent with [ProtonMail](https://protonmail.com) Secure Email.


Re: tap(4) performance tuning on (amd64)

2020-01-20 Thread Claudio Jeker
On Fri, Jan 10, 2020 at 01:00:49PM +, Tom Smyth wrote:
> Hi lads,
> 
> I have been doing some testing with tap(4) and openvpn (standard ssl )
> I have been using openvpn with tap and I have been trying with null
> encryption. null authentication,
> the performance of the tap interface  seems to be about 100-150Mb/s  on a 
> system
> which can give  3Gb/s-5Gb/s on ix(4) interfaces  in Bridge mode and
> 4-8Gb/s on tpmr mode
> I was wondering is there a sysctl setting that if modified would
> improve the tap interface performance.
> I have tried with tpmr(4) and  bridge(4)
> 
> is there a simple way  testing a tap(4) interface throughput /
> performance without Openvpn process
> 
> I can try mlvpn and wireguard
> but I would love if there was a trick where I can just test the tap(4)
> interface  with something like pair(4)...
> 
> ix0---bridge0--tap0---someprocess--tap1-bridge1--ix1
> or
> ix0--tpmr0--tap0--someprocess--tap1-tpmr1-ix1
> 
> is there a simple "someprocess" that would provide forwarding packets
> between tap0 and tap1 in userland
> so that any performance testing on tap(4) interfaces does not have the
> distractions of complex userland programs with encryption /
> encapsulation overheads
> 

I just wrote a simple tun/tap bridge for testing so here you go.
Compile it with 'cc -Wall -o tbridge tbridge.c -lpthread' and run it
with 'tbridge -k /dev/tun0 /dev/tun1' to wire tun0 and tun1 together.
You can select between, select(2), poll(2), kqueue(2) and pthreads as the
way on how to multiplex the reads.

For me the code triggers scheduler inefficencies and causes packets drops
on the output queue when there are multiple packet producers.
-- 
:wq Claudio

/*
 * Copyright (c) 2020 Claudio Jeker 
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */
#include 
#include 
#include 

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

volatile sig_atomic_tquit;

static void
do_read(int in, int out)
{
char buf[2048];
ssize_t n, o;

n = read(in, buf, sizeof(buf));
if (n == -1)
err(1, "read");
o = write(out, buf, n);
if (o == -1)
err(1, "read");
if (o != n)
errx(1, "short write");
}

static void
do_poll(int fd[2])
{
struct pollfd pfd[2];
int n, i;

while (quit == 0) {
memset(pfd, 0, sizeof(pfd));
pfd[0].fd = fd[0];
pfd[0].events = POLLIN;

pfd[1].fd = fd[1];
pfd[1].events = POLLIN;

n = poll(pfd, 2, INFTIM);
if (n == -1)
err(1, "poll");
if (n == 0)
errx(1, "poll: timeout");
for (i = 0; i < 2; i++) {
if (pfd[i].revents & POLLIN)
do_read(fd[i], fd[(i + 1) & 0x1]);
else if (pfd[i].revents & (POLLHUP | POLLERR))
errx(1, "fd %d revents %x", i, pfd[i].revents);
}
}

}

static void
do_select(int fd[2])
{
fd_set readfds;
int n, i, maxfd = -1;

while (quit == 0) {
FD_ZERO();
for (i = 0; i < 2; i++) {
if (fd[i] > maxfd)
maxfd = fd[i];
FD_SET(fd[i], );
}
n = select(maxfd + 1, , NULL, NULL, NULL);
if (n == -1)
err(1, "select");
if (n == 0)
errx(1, "select: timeout");
for (i = 0; i < 2; i++) {
if (FD_ISSET(fd[i], ))
do_read(fd[i], fd[(i + 1) & 0x1]);
}
}
}

static void
do_kqueue(int fd[2])
{
struct kevent kev[2];
int kq, i, n;

if ((kq = kqueue()) == -1)
err(1, "kqueue");

memset(kev, 0, sizeof(kev));
for (i = 0; i < 2; i++) {
EV_SET([i], fd[i], EVFILT_READ, EV_ADD | EV_ENABLE,
0, 0, (void *)(intptr_t)i);
}
if (kevent(kq, kev, 2, NULL, 0, NULL) == -1)
err(1, "kevent register");

while 

glib2: File not found (Ruby on Rails: replacing ImageMagick with the much faster Vips)

2020-01-20 Thread 1234dev
Hi!

I'm trying to switch from ImageMagick over to the newer and much faster Vips 
(https://libvips.github.io/libvips/) in my Rails app. However, despite having 
glib2-2.60.7 installed on OpenBSD 6.6, I'm getting LoadError (Could not open 
library 'glib-2.0.so.0': File not found).

Any chance anybody here knows how to fix this?

Thanks,
Jonathan

Ref. https://bloggie.io/@kinopyo/upgrade-guide-active-storage-in-rails-6

Sent with [ProtonMail](https://protonmail.com) Secure Email.