User-Level Native Thread Primitives (GThread) Library White Paper (G06.26+)

User-Level Native Thread Primitives (GThread Library) 03/31/2005
Hewlett-Packard Company--540065-001 Page 42 of 46
The GThread primitives apply a ‘default’ ratio when allocating the mem stack and reg stack during
thread initialization (GTHREAD_INITIATE_). However, since this ratio may not be optimal for all
client implementations, the interface provides clients with the option to change the fraction of allocated
stack space devoted to the reg stack.
The Swaptions argument to GTHREAD_INITIATE_ is changed to provide the client with the ability to
specify the allocation ratio. The ratio is specified as a ‘percentage’ from 10 to 80 percent and provided
using the following new define:
GTS_STATIC_RegPerCent(n)
where n is the percentage of the total allocated space devoted to the reg stack. The remaining space is
devoted to the mem stack. This define replaces the define GTS_STATIC for those clients that wish to
control this ratio. A call to GTHREAD_INITIATE_ utilizing the new define would be as follows:
GTHREAD_INITIATE_(...,length,GTS_STATIC_RegPerCent(30),...);
specifying that 30% of the specified length be devoted to the reg stack and the other 70% to the mem
stack.
GTS_STATIC_RegPerCent(0) is equivalent to GTS_STATIC; GTHREAD_INITIATE_ and uses a
default ratio of reg to mem stack. That ratio is implementation-dependent.
On non-TNS/E native platforms, GTS_STATIC_RegPerCent(n) is equivalent to GTS_STATIC; the
percentage value n is ignored.
On TNS/E native platforms, GTS_STATIC_RegPerCent takes its argument modulo 128.
GTHREAD_INITIATE_ returns the error GT_BAD_SWAPTIONS if the RegPerCent value is outside
the range of 10 to 80.
If GT_BAD_SWAPTIONS is returned, the thread control block specified on the call to
GTHREAD_INITIATE_ has not been properly set up and therefore cannot be activated until successfully
initialized (by calling GTHREAD_INITIATE_ with a valid Swaptions argument).
Some minor adjustments to the percentage value specified are performed for buffer alignment purposes.
If an adjustment is necessary, the percentage value is rounded down to the closest alignment boundary.
The specified RegPerCent (before any adjustment) also determines treatment of the stack_delta
parameter to GTH_STACK_CHECK_ACTIVE_ and GTH_STACK_CHECK_THREAD_:
mem_delta = stack_delta;
reg_delta = stack_delta * RegPerCent / (100 – RegPerCent).
Once again it needs to be emphasized that this feature is optional, if the default ratio proves satisfactory.
Using this interface requires knowledge of how both the mem and reg stacks grow given a specific client
implementation. This knowledge can be obtained by careful code analysis, empirical data, or both.