Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 23 Sep 2014 14:02:01 +0400
From:      Sergey Kandaurov <pluknet@gmail.com>
To:        Konstantin Belousov <kostikbel@gmail.com>
Cc:        Daniel Eischen <deischen@freebsd.org>, "Ivan A. Kosarev" <ivan@ivan-labs.com>, FreeBSD Current <freebsd-current@freebsd.org>
Subject:   Re: libthr and main thread stack size
Message-ID:  <CAE-mSO%2BMWYUT5EC95TCn8YyHoFnz0Jpqzqfy_MOqm2wc5g5-vA@mail.gmail.com>
In-Reply-To: <20140923092449.GB8334@kib.kiev.ua>
References:  <53E36E84.4060806@ivan-labs.com> <FEB60EB5-546D-454D-AE62-B2483246E42C@scsiguy.com> <20140916081324.GQ2737@kib.kiev.ua> <5242716.s4iaScq0Bu@ralph.baldwin.cx> <541E31E0.8020108@freebsd.org> <Pine.GSO.4.64.1409220917100.26756@sea.ntplx.net> <20140923092449.GB8334@kib.kiev.ua>

next in thread | previous in thread | raw e-mail | index | archive | help
On 23 September 2014 13:24, Konstantin Belousov <kostikbel@gmail.com> wrote:
> In the patch, default behaviour is to provide RLIMIT_STACK sized stack
> for the main thread.  The knobs are there to restore the old AS layout
> if my fears of the binary compatibility become real one day, and to
> keep the interface compat with the stable/10, which already got a knob
> merged.
>
> That said, below the patch with libthr.7 man page merged to libthr.3,
> and with the editing applied.
>
> diff --git a/lib/libthr/libthr.3 b/lib/libthr/libthr.3
> index bfbebec..aa4572c 100644
> --- a/lib/libthr/libthr.3
> +++ b/lib/libthr/libthr.3
> @@ -1,6 +1,11 @@
>  .\" Copyright (c) 2005 Robert N. M. Watson
> +.\" Copyright (c) 2014 The FreeBSD Foundation, Inc.
>  .\" All rights reserved.
>  .\"
> +.\" Part of this documentation was written by
> +.\" Konstantin Belousov <kib@FreeBSD.org> under sponsorship
> +.\" from the FreeBSD Foundation.
> +.\"
>  .\" Redistribution and use in source and binary forms, with or without
>  .\" modification, are permitted provided that the following conditions
>  .\" are met:
> @@ -24,7 +29,7 @@
>  .\"
>  .\" $FreeBSD$
>  .\"
> -.Dd October 19, 2007
> +.Dd September 20, 2014
>  .Dt LIBTHR 3
>  .Os
>  .Sh NAME
> @@ -45,8 +50,216 @@ has been optimized for use by applications expecting system scope thread
>  semantics, and can provide significant performance improvements
>  compared to
>  .Lb libkse .
> +.Pp
> +The library is tightly integrated with the run-time link editor
> +.Xr ld-elf.so.1 1
> +and
> +.Lb libc ;
> +all three components must be built from the same source tree.
> +Mixing
> +.Li libc
> +and
> +.Nm
> +libraries from different versions of
> +.Fx
> +is not supported.
> +The run-time linker
> +.Xr ld-elf.so.1 1
> +has some code to ensure backward-compatibility with older versions of
> +.Nm .
> +.Pp
> +The man page documents the quirks and tunables of the
> +.Nm .
> +When linking with
> +.Li -lpthread ,
> +the run-time dependency
> +.Li libthr.so.3
> +is recorded in the produced object.
> +.Sh MUTEX ACQUISITION
> +A locked mutex (see
> +.Xr pthread_mutex_lock 3 )
> +is represented by a volatile variable of type
> +.Dv lwpid_t ,
> +which records the global system identifier of the thread
> +owning the lock.
> +.Nm
> +performs a contested mutex acquisition in three stages, each of which
> +is more resource-consuming than the previous.
> +.Pp
> +First, a spin loop
> +is performed, where the library attempts to acquire the lock by
> +.Xr atomic 9
> +operations.
> +The loop count is controlled by the
> +.Ev LIBPTHREAD_SPINLOOPS
> +environment variable, with a default value of 2000.
> +.Pp
> +If the spin loop
> +was unable to acquire the mutex, a yeild loop
typo: yield

[...]
>  .Sh SEE ALSO
> -.Xr pthread 3
> +.Xr ktrace 1 ,
> +.Xr ld-elf.so.1 1 ,
> +.Xr getrlimit 2 ,
> +.Xr umtx 2 ,
> +.Xr dlclose 3 ,
> +.Xr dlopen 3 ,
> +.Xr errno 3 ,
> +.Xr getenv 3 ,
> +.Xr libc 3 ,
> +.Xr pthread_attr 3 ,
> +.Xr pthread_attr_setstacksize 3 ,
> +.Xr pthread_create 3 ,
> +.Xr signal 3 ,
> +.Xr atomic 9 .
no pediod there per mdoc

>  .Sh AUTHORS
>  .An -nosplit
>  The
> diff --git a/lib/libthr/thread/thr_init.c b/lib/libthr/thread/thr_init.c
> index 9bf0e29..72a067a 100644
> --- a/lib/libthr/thread/thr_init.c
> +++ b/lib/libthr/thread/thr_init.c
> @@ -445,7 +445,7 @@ init_private(void)
>         struct rlimit rlim;
>         size_t len;
>         int mib[2];
> -       char *env;
> +       char *env, *env_bigstack, *env_splitstack;
>
>         _thr_umutex_init(&_mutex_static_lock);
>         _thr_umutex_init(&_cond_static_lock);
> @@ -473,8 +473,9 @@ init_private(void)
>                 len = sizeof (_usrstack);
>                 if (sysctl(mib, 2, &_usrstack, &len, NULL, 0) == -1)
>                         PANIC("Cannot get kern.usrstack from sysctl");
> -               env = getenv("LIBPTHREAD_BIGSTACK_MAIN");
> -               if (env != NULL) {
> +               env_bigstack = getenv("LIBPTHREAD_BIGSTACK_MAIN");
> +               env_splitstack = getenv("LIBPTHREAD_SPLITSTACK_MAIN");
> +               if (bigstack != NULL || env_splitstack == NULL) {
looks like a typo: s/bigstack/env_bigstack/

>                         if (getrlimit(RLIMIT_STACK, &rlim) == -1)
>                                 PANIC("Cannot get stack rlimit");
>                         _thr_stack_initial = rlim.rlim_cur;

-- 
wbr,
pluknet



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAE-mSO%2BMWYUT5EC95TCn8YyHoFnz0Jpqzqfy_MOqm2wc5g5-vA>