When the userlevel package is initialized and started, default
configuration values for various parts of the package are used. These
values ensure correct behaviour of all the package's parts. Nevertheless,
it may be necessary and/or advantageous to manually adjust some of these
values to ensure better performance. Improvements can be possible due
to recent changes in the machine configuration or to special requirements
of the application.
There are two different possibilities to change the configuration
parameters. mthr_config directly changes one parameter to an
application specific value, whereas with mthr_configv it is
possible to change values of a compiled program by specifying commandline
Both possibilities may only be used before the call to
mthr_startup(3) as the parameters are
needed by this function. Changing the configuration values after starting
the package may confuse certain functions and crash the application!
mthr_config changes the value of the parameter what to the
new value offered by value. Usually macros out of
mthr_config.h should be used for what to avoid problems due
to changes in the mthreads library. The following parameters
are currently supported:
- CPU_MBLOCKPOOL_SIZE: For efficient allocation and alignment of
the various structures of the package, like thread structures,
synchronization mechanisms etc. there are pools for each processor. Freed
structures are pushed into these pools and new allocations are satisfied
out of these pools. The value changed by CPU_MBLOCKPOOL_SIZE restricts the
maximum number of elements in each of these pools. If the pool exceeds this
limit, half of its elements will be pushed to a global node pool. If there
are no elements when trying to allocate a new structure, value/2
elements are retrieved from the node's pool or allocated via
- CPU_STACKPOOL_SIZE: As with memory blocks, stacks are held
in pools, to ensure reuse. Again, value is the maximum number of
stacks that can be held by the cpu's local stackpool. If it exceeds
the limit the oldest stack in the pool is pushed to the node's stackpool.
- NODE_STACKPOOL_SIZE: The node's stackpool has its own upper
limit for the number of stacks it will hold. If the pool exceeds this limit
the oldest stack in the pool will be freed using free(3).
- MIN_STACKSIZE: Depending on the machine, the compiler and the
application, threads need a minimum stack to run correctly. This lower
limit can be adjusted by this option. All threads created with a stacksize
smaller than this minimum will get a stack with the minimum stacksize.
- DEF_STACKSIZE: When creating a thread with a stacksize==0,
it will get a stack with this default stacksize.
- STACK_GRANULARITY: Stacksizes will be rounded up to a multiple
of this size.
- SPINS_BEFORE_BLOCK: This option controls how long a thread
stays spinning when waiting for a lock, before it blocks. Spinning
eventually reduces the necessary number of scheduling decisions and so
may improve the overall performance.
- KTHR_SPINS_BEFORE_BLOCK: Like the option above this option
controls how long a kernel thread spins before it blocks. As blocking
a kernel thread is expensive, a huge number of spins may be better than
- NO_OF_NODES: Generally the whole subcomplex will be used by
the mthreads package, i.e. one kernelthread will be started for
each cpu in each node of the subcomplex. This option allows the user
to reduce the number of nodes that will be used.
- NO_OF_CPUS: As with the number of nodes, the number of cpus
used for the application can be reduced. mthreads tries to allocate
the required number of cpus on as few nodes as possible, but always
includes the node on which the start thread has been allocated by the
The second possibility to change the configuration parameter is to use
the mthr_configv call. This function gets the argument counter and
argument vector from main(), eliminates all options known to him
from the argument vector and adjusts the value of the argument counter.
Each known option starts with the prefix -m_ followed by a
short abbreviation and a numerical value. The program can be started with
the mthreads options and its own options in arbitrary order. The
example below starts the program check_opt with two mthreads
options and one application specific option:
check_opt -m_sbb 40 -my_opt1 -m_cpus 4
There are the same configurable parameters as with the mthr_config
- -m_c_mp: The size of the cpu's mblockpool.
- -m_c_sp: The size of the cpu's stackpool.
- -m_n_sp: The size of the node's stackpool.
- -m_min_ss: The minimum stacksize.
- -m_def_ss: The default stacksize.
- -m_gran: The stack granularity.
- -m_sbb: The number of spins before a thread blocks.
- -m_k_sbb: The number of spins before a kernelthread blocks.
- -m_nodes: The number of nodes that should be used.
- -m_cpus: The number of cpus the application should use.