Go to main content

Memory and Thread Placement Optimization Developer's Guide

Exit Print View

Updated: November 2020
 
 

The Solaris::lgrp Module

This Perl module provides a Perl interface to the lgroup APIs that are in liblgrp. This interface provides a way to traverse the lgroup hierarchy, discover its contents and characteristics, and set a thread's affinity for an lgroup. The module gives access to various constants and functions defined in the lgrp_user.h header file. The module provides the procedural interface and the object interface to the library.

The default behavior of this module does not export anything. You can use the following tags to selectively import the constants and functions that are defined in this module:

:LGRP_CONSTANTS

LGRP_AFF_NONE, LGRP_AFF_STRONG, LGRP_AFF_WEAK, LGRP_CONTENT_DIRECT, LGRP_CONTENT_HIERARCHY, LGRP_MEM_SZ_FREE, LGRP_MEM_SZ_INSTALLED, LGRP_VER_CURRENT, LGRP_VER_NONE, LGRP_VIEW_CALLER, LGRP_VIEW_OS, LGRP_NONE, LGRP_RSRC_CPU, LGRP_RSRC_MEM, LGRP_CONTENT_ALL, LGRP_LAT_CPU_TO_MEM

:PROC_CONSTANTS

P_PID, P_LWPID, P_MYID

:CONSTANTS

:LGRP_CONSTANTS, :PROC_CONSTANTS

:FUNCTIONS

lgrp_affinity_get(), lgrp_affinity_set(), lgrp_children(), lgrp_cookie_stale(), lgrp_cpus(), lgrp_fini(), lgrp_home(), lgrp_init(), lgrp_latency(), lgrp_latency_cookie(), lgrp_mem_size(), lgrp_nlgrps(), lgrp_parents(), lgrp_root(), lgrp_version(), lgrp_view(), lgrp_resources(), lgrp_lgrps(), lgrp_leaves(), lgrp_isleaf(), lgrp_lgrps(), lgrp_leaves().

:ALL()

:CONSTANTS(), :FUNCTIONS()

The Perl module has the following methods:

  • new()

  • cookie()

  • stale()

  • view()

  • root()

  • children()

  • parents()

  • nlgrps()

  • mem_size()

  • cpus()

  • isleaf()

  • resources()

  • version()

  • home()

  • affinity_get()

  • affinity_set()

  • lgrps()

  • leaves()

  • latency()

You can export constants with the :CONSTANTS or :ALL tags. You can use any of the constants in the following list in Perl programs.

  • LGRP_NONE

  • LGRP_VER_CURRENT

  • LGRP_VER_NONE

  • LGRP_VIEW_CALLER

  • LGRP_VIEW_OS

  • LGRP_AFF_NONE

  • LGRP_AFF_STRONG

  • LGRP_AFF_WEAK

  • LGRP_CONTENT_DIRECT

  • LGRP_CONTENT_HIERARCHY

  • LGRP_MEM_SZ_FREE

  • LGRP_MEM_SZ_INSTALLED

  • LGRP_RSRC_CPU

  • LGRP_RSRC_MEM

  • LGRP_CONTENT_ALL

  • LGRP_LAT_CPU_TO_MEM

  • P_PID

  • P_LWPID

  • P_MYID

When an underlying library function fails, the functions in this module return either undef or an empty list. The module can use the following error codes:

EINVAL

The value supplied is not valid.

ENOMEM

There was not enough system memory to complete an operation.

ESRCH

The specified process or thread was not found.

EPERM

The effective user of the calling process does not have the appropriate privileges, and its real or effective user ID does not match the real or effective user ID of one of the threads.

Functions in the Solaris::lgrp Module

lgrp_init([LGRP_VIEW_CALLER | LGRP_VIEW_OS])

This function initializes the lgroup interface and takes a snapshot of the lgroup hierarchy with the given view. Given the view, the lgrp_init() function returns a cookie that represents this snapshot of the lgroup hierarchy. Use this cookie with the other routines in the lgroup interface that require the lgroup hierarchy. Call the lgrp_fini() function with this cookie when the system no longer needs the hierarchy snapshot. Unlike the lgrp_init(3LGRP) function, this function assumes a value of LGRP_VIEW_OS as the default if the system provides no view. This function returns a cookie upon successful completion. If the lgrp_init function does not complete successfully, it returns a value of undef and sets $! to indicate the error. See the man page for the lgrp_init(3LGRP) function for more information.

lgrp_fini($cookie)

This function takes a cookie, frees the snapshot of the lgroup hierarchy that the lgrp_init() function created, and cleans up anything else that the lgrp_init() function set up. After calling this function, do not use the cookie that the lgroup interface returns. This function returns 1 upon successful completion. If the lgrp_fini function does not complete successfully, it returns a value of undef and sets $! to indicate the error. See the man page for the lgrp_fini(3LGRP) function for more information.

lgrp_view($cookie)

This function takes a cookie that represents the snapshot of the lgroup hierarchy and returns the snapshot's view of the lgroup hierarchy. If the given view is LGRP_VIEW_CALLER, the snapshot contains only the resources that are available to the caller. When the view is LGRP_VIEW_OS, the snapshot contains the resources that are available to the operating system. This function returns the view for the snapshot of the lgroup hierarchy that is represented by the given cookie upon successful completion. If the lgrp_view function does not complete successfully, it returns a value of undef and sets $! to indicate the error. See the man page for the lgrp_view(3LGRP) function for more information.

lgrp_home($idtype, $id)

This function returns the home lgroup for the given process or thread. To specify a process, give the $idtype argument the value P_PID and give the $id argument the value of the process id. To specify a thread, give the $idtype argument the value P_LWPID and give the $id argument the value of the thread's LWP id. To specify the current process or thread, give the $id argument the value P_MYID. This function returns the id of the home lgroup of the specified process or thread upon successful completion. If the lgrp_home function does not complete successfully, it returns a value of undef and sets $! to indicate the error. See the man page for the lgrp_home(3LGRP) function for more information.

lgrp_cookie_stale($cookie)

This function returns the staleness status of the specified cookie upon successful completion. If the lgrp_cookie_stale function does not complete successfully, it returns a value of undef and sets $! to indicate the error. This function fails and returns EINVAL if the cookie is not valid. See the man page for the lgrp_cookie_stale(3LGRP) function for more information.

lgrp_cpus($cookie, $lgrp, $context)

This function takes a cookie that represents a snapshot of the lgroup hierarchy and returns the list of CPUs that are in the lgroup that is specified by the $lgrp argument. Give the $context argument the value LGRP_CONTENT_HIERARCHY to make the lgrp_cpus() function return the list of all the CPUs that are in the specified lgroup, including child lgroups. Give the $context() argument the value LGRP_CONTENT_DIRECT to make the lgrp_cpus() function return the list of CPUs that are directly contained in the specified lgroup. This function returns the number of CPUs that are in the specified lgroup when you call it in a scalar context. If the lgrp_cpus function does not complete successfully when you call it in a scalar context, it returns a value of undef and sets $! to indicate the error. If the lgrp_cpus function does not complete successfully when you call it in a list context, it returns the empty list and sets $! to indicate the error. See the man page for the lgrp_cpus(3LGRP) function for more information.

lgrp_children($cookie, $lgrp)

This function takes a cookie that represents a snapshot of the lgroup hierarchy and returns the list of lgroups that are children of the specified lgroup. When called in scalar context, the lgrp_children() function returns the number of children lgroups for the specified lgroup when you call it in a scalar context. If the lgrp_children function does not complete successfully when you call it in a scalar context, it returns a value of undef and sets $! to indicate the error. If the lgrp_children function does not complete successfully when you call it in a list context, it returns the empty list and sets $! to indicate the error. See the man page for the lgrp_children(3LGRP) function for more information.

lgrp_parents($cookie, $lgrp)

This function takes a cookie that represents a snapshot of the lgroup hierarchy and returns the list of parent groups of the specified lgroup. When called in scalar context, the lgrp_parents() function returns the number of parent lgroups for the specified lgroup when you call it in a scalar context. If the lgrp_parents function does not complete successfully when you call it in a scalar context, it returns a value of undef and sets $! to indicate the error. If the lgrp_parents function does not complete successfully when you call it in a list context, it returns the empty list and sets $! to indicate the error. See the man page for the lgrp_parents(3LGRP) function for more information.

lgrp_nlgrps($cookie)

This function takes a cookie that represents a snapshot of the lgroup hierarchy. It returns the number of lgroups in the hierarchy. This number is always at least one. If the lgrp_nlgrps function does not complete successfully, it returns a value of undef and sets the value of $! to EINVAL to indicate that the cookie is invalid. See the man page for the lgrp_nlgrps(3LGRP) function for more information.

lgrp_root($cookie)

This function returns the ID of the root lgroup. If the lgrp_root function does not complete successfully, it returns a value of undef and sets the value of $! to EINVAL to indicate that the cookie is invalid. See the man page for the lgrp_root(3LGRP) function for more information.

lgrp_mem_size($cookie, $lgrp, $type, $content)

This function takes a cookie that represents a snapshot of the lgroup hierarchy. The function returns the memory size of the given lgroup in bytes. Set the value of the $type argument to LGRP_MEM_SZ_FREE to have the lgrp_mem_size() function return the amount of free memory. Set the value of the $type argument to LGRP_MEM_SZ_INSTALLED to have the lgrp_mem_size() function return the amount of installed memory. Set the value of the $content argument to LGRP_CONTENT_HIERARCHY to have the lgrp_mem_size() function return results for the specified lgroup and each of its child lgroups. Set the value of the $content argument to LGRP_CONTENT_DIRECT to have the lgrp_mem_size() function return results for the specified lgroup only. This function returns the memory size in bytes upon successful completion, the size in bytes is returned. If the lgrp_mem_size function does not complete successfully, it returns a value of undef and sets $! to indicate the error. See the man page for the lgrp_mem_size(3LGRP) function for more information.

lgrp_version([VERSION])

This function takes an interface version number as the value of the VERSION argument and returns an lgroup interface version. To discover the current lgroup interface version, pass the value of LGRP_VER_CURRENT or LGRP_VER_NONE in the VERSION argument. The lgrp_version() function returns the requested version if the system supports that version. The lgrp_version() function returns LGRP_VER_NONE if the system does not supports the request version. The lgrp_version() function returns the current version of the library when you call the function with LGRP_VER_NONE as the value of the VERSION argument. This code fragment tests whether the version of the interface used by the caller is supported:

lgrp_version(LGRP_VER_CURRENT) == LGRP_VER_CURRENT or
             die("Built with unsupported lgroup interface");

See the man page for the lgrp_version(3LGRP) function for more information.

lgrp_affinity_set($idtype, $id, $lgrp, $affinity)

This function sets the affinity that the LWPs you specify with the $idtype and $id arguments have for the given lgroup. You can set the lgroup affinity to LGRP_AFF_STRONG, LGRP_AFF_WEAK, or LGRP_AFF_NONE. When the value of the $idtype argument is P_PID, this function sets the affinity for all the LWPs of the process with the process id specified in the $id argument. The lgrp_affinity_set() function sets the affinity for the LWP of the current process with LWP id $id when the value of the $idtype argument is P_LWPID. You can specify the current LWP or process by assigning the $id argument a value of P_MYID. This function returns 1 upon successful completion. If the lgrp_affinity_set function does not complete successfully, it returns a value of undef and sets $! to indicate the error. See the man page for the lgrp_affinity_set(3LGRP) function for more information.

lgrp_affinity_get($idtype, $id, $lgrp)

This function retrieves the affinity that the LWPs you specify with the $idtype and $id arguments have for the given lgroup. When the value of the $idtype argument is P_PID, this function retrieves the affinity for one of the LWPs in the process. The lgrp_affinity_get() function retrieves the affinity for the LWP of the current process with LWP id $id when the value of the $idtype argument is P_LWPID. You can specify the current LWP or process by assigning the $id argument a value of P_MYID. This function returns 1 upon successful completion. If the lgrp_affinity_get function does not complete successfully, it returns a value of undef and sets $! to indicate the error. See the man page for the lgrp_affinity_get(3LGRP) function for more information.

lgrp_latency_cookie($cookie, $from, $to, [$between=LGRP_LAT_CPU_TO_MEM])()

This function takes a cookie that represents a snapshot of the lgroup hierarchy and returns the latency value between a hardware resource in the $from lgroup to a hardware resource in the $to lgroup. This function returns the latency value within a given lgroup when the values of the $from and $to arguments are identical. Set the value of the optional $between argument to LGRP_LAT_CPU_TO_MEM to specify the hardware resources to measure the latency between. LGRP_LAT_CPU_TO_MEM represents the latency from CPU to memory and is the only valid value for this argument in this release. This function returns 1 upon successful completion. If the lgrp_latency_cookie function does not complete successfully, it returns a value of undef and sets $! to indicate the error. See the man page for the lgrp_latency_cookie(3LGRP) function for more information.

lgrp_latency($from, $to)()

The function is similar to the lgrp_latency_cookie() function, but returns the latency between the given lgroups at the given instant in time. Because the system dynamically reallocates and frees lgroups, this function's results are not always consistent across calls. This function is deprecated. Use the lgrp_latency_cookie() function instead. See the man page for the lgrp_latency(3LGRP) function for more information.

lgrp_resources($cookie, $lgrp, $type)()

This function is only available for version 2 of the API. When you call this function with version 1 of the API, the lgrp_resources() function returns undef or the empty list and sets the value of $! to EINVAL. This function returns the list of lgroups that directly contain the specified type of resources. The resources are represented by a set of lgroups in which each lgroup directly contains CPU and/or memory resources. To specify CPU resources, set the value of the $type argument to LGRP_RSRC_CPU. To specify memory resources, set the value of the $type argument to LGRP_RSRC_MEM. If the lgrp_resources function does not complete successfully, it returns a value of undef or the empty list and sets $! to indicate the error. See the man page for the lgrp_resources(3LGRP) function for more information.

lgrp_lgrps($cookie, [$lgrp])()

This function returns the list of all of the lgroups in a hierarchy, starting from the lgroup specified in the $lgrp argument. This function uses the value returned by the lgrp_root($cookie) function when the $lgrp argument has no value. The lgrp_lgrps() function returns the empty list on failure. This function returns the total number of lgroups in the system when you call it in a scalar context.

lgrp_leaves($cookie, [$lgrp])()

This function returns the list of all leaf lgroups in a hierarchy that starts from the lgroup specified in the $lgrp argument. This function uses the value returned by the lgrp_root($cookie) function when the $lgrp argument has no value. The lgrp_leaves() function returns undef or the empty list on failure. This function returns the total number of leaf lgroups in the system when you call it in a scalar context.

lgrp_isleaf($cookie, $lgrp)()

This function returns True if the lgroup specified by the value of the $lgrp argument is a leaf lgroup. Leaf lgroups have no children. The lgrp_isleaf() function returns False if the specified lgroup is not a leaf lgroup.

Object Methods in the Solaris::lgrp Module

new([$view])

This method creates a new Sun::Solaris::Lgrp object. An optional argument is passed to the lgrp_init() function. This method uses a value for the $view argument of LGRP_VIEW_OS by default.

cookie()

This function returns a transparent cookie that is passed to functions that accept a cookie.

version([$version])

This method returns the current version of the liblgrp(3LIB) library when you call it without an argument. This is a wrapper for the lgrp_version() function with LGRP_VER_NONE as the default value of the $version argument.

stale()

This method returns T if the lgroup information in the object is stale. This method returns F in all other cases. The stale method is a wrapper for the lgrp_cookie_stale() function.

view()

This method returns the snapshot's view of the lgroup hierarchy. The view() method is a wrapper for the lgrp_view() function.

root()

This method returns the root lgroup. The root() method is a wrapper for the lgrp_root() function.

children($lgrp)

This method returns the list of lgroups that are children of the specified lgroup. The children method is a wrapper for the lgrp_children() function.

parents($lgrp)

This method returns the list of lgroups that are parents of the specified lgroup. The parents method is a wrapper for the lgrp_parents() function.

nlgrps()

This method returns the number of lgroups in the hierarchy. The nlgrps() method is a wrapper for the lgrp_nlgrps() function.

mem_size($lgrp, $type, $content)

This method returns the memory size of the given lgroup in bytes. The mem_size method is a wrapper for the lgrp_mem_size() function.

cpus($lgrp, $context)

This method returns the list of CPUs that are in the lgroup specified by the $lgrp argument. The cpus method is a wrapper for the lgrp_cpus() function.

resources($lgrp, $type)

This method returns the list of lgroups that directly contain resources of the specified type. The resources method is a wrapper for the lgrp_resources() function.

home($idtype, $id)

This method returns the home lgroup for the given process or thread. The home method is a wrapper for the lgrp_home() function.

affinity_get($idtype, $id, $lgrp)

This method returns the affinity that the LWP has to a given lgroup. The affinity_get() method is a wrapper for the lgrp_affinity_get() function.

affinity_set($idtype, $id, $lgrp, $affinity)

This method sets the affinities that the LWPs specified by the $idtype and $id arguments have for the given lgroup. The affinity_set() method is a wrapper for the lgrp_affinity_set() function.

lgrps([$lgrp])

This method returns the list of all of the lgroups in a hierarchy starting from the lgroup specified by the value of the $lgrp argument. The hierarchy starts from the root lgroup when you do not specify a value for the $lgrp argument. The lgrps() method is a wrapper for the lgrp_lgrps() function.

leaves([$lgrp])

This method returns the list of all of the leaf lgroups in a hierarchy starting from the lgroup specified by the value of the $lgrp argument. The hierarchy starts from the root lgroup when you do not specify a value for the $lgrp argument. The leaves() method is a wrapper for the lgrp_leaves() function.

isleaf($lgrp)

This method returns True if the lgroup specified by the value of the $lgrp argument is a leaf lgroup. A leaf lgroup has no children. This method returns False in all other cases. The isleaf method is a wrapper for the lgrp_isleaf function.

latency($from, $to)

This method returns the latency value between a hardware resource in the lgroup specified by the $from argument to a hardware resource in the lgroup specified by the $to argument. The latency method uses the lgrp_latency() function in version 1 of liblgrp. The latency method uses the lgrp_latency_cookie() function in newer versions of liblgrp.