Lgrp - Perl interface to Solalris liblgrp library
use Sun::Solaris::Lgrp qw(:ALL); # initialize lgroup interface my $cookie = lgrp_init(LGRP_VIEW_OS | LGRP_VIEW_CALLER); my $l = Sun::Solaris::Lgrp->new(LGRP_VIEW_OS | LGRP_VIEW_CALLER); my $version = lgrp_version(LGRP_VER_CURRENT | LGRP_VER_NONE); $version = $l->version(LGRP_VER_CURRENT | LGRP_VER_NONE); $home = lgrp_home(P_PID, P_MYID); $home = l->home(P_PID, P_MYID); lgrp_affinity_set(P_PID, $pid, $lgrp, LGRP_AFF_STRONG | LGRP_AFF_WEAK | LGRP_AFF_NONE); $l->affinity_set(P_PID, $pid, $lgrp, LGRP_AFF_STRONG | LGRP_AFF_WEAK | LGRP_AFF_NONE); my $affinity = lgrp_affinity_get(P_PID, $pid, $lgrp); $affinity = $l->affinity_get(P_PID, $pid, $lgrp); my $nlgrps = lgrp_nlgrps($cookie); $nlgrps = $l->nlgrps(); my $root = lgrp_root($cookie); $root = l->root(); $latency = lgrp_latency($lgrp1, $lgrp2); $latency = $l->latency($lgrp1, $lgrp2); my @children = lgrp_children($cookie, $lgrp); @children = l->children($lgrp); my @parents = lgrp_parents($cookie, $lgrp); @parents = l->parents($lgrp); my @lgrps = lgrp_lgrps($cookie); @lgrps = l->lgrps(); @lgrps = lgrp_lgrps($cookie, $lgrp); @lgrps = l->lgrps($lgrp); my @leaves = lgrp_leaves($cookie); @leaves = l->leaves(); my $is_leaf = lgrp_isleaf($cookie, $lgrp); $is_leaf = $l->is_leaf($lgrp); my @cpus = lgrp_cpus($cookie, $lgrp, LGRP_CONTENT_HIERARCHY | LGRP_CONTENT_DIRECT); @cpus = l->cpus($lgrp, LGRP_CONTENT_HIERARCHY | LGRP_CONTENT_DIRECT); my $memsize = lgrp_mem_size($cookie, $lgrp, LGRP_MEM_SZ_INSTALLED | LGRP_MEM_SZ_FREE, LGRP_CONTENT_HIERARCHY | LGRP_CONTENT_DIRECT); $memsize = l->mem_size($lgrp, LGRP_MEM_SZ_INSTALLED | LGRP_MEM_SZ_FREE, LGRP_CONTENT_HIERARCHY | LGRP_CONTENT_DIRECT); my $is_stale = lgrp_cookie_stale($cookie); $stale = l->stale(); lgrp_fini($cookie); # The following is available for API version greater than 1: my @lgrps = lgrp_resources($cookie, $lgrp, LGRP_RSRC_CPU); # Get latencies from cookie $latency = lgrp_latency_cookie($cookie, $from, $to);
This module provides access to the liblgrp(3LIB) library and to various constants and functions defined in <sys/lgrp_sys.h>. It provides both the procedural and object interface to the library. The procedural interface requires (in most cases) passing around a transparent cookie. The object interface hides all the cookie manipulations from the user.
Functions returning a scalar value indicate an error by returning undef. The caller can examine the $! variable to get the error value.
Functions returning a list value return the number of elements in the list when called in scalar context. In the event of error, the empty list is returned in the array context and undef is returned in the scalar context.
The constants are exported with :CONSTANTS or :ALL tags:
use Sun::Solaris::Lgrp ':ALL';
or
use Sun::Solaris::Lgrp ':CONSTANTS';
The following constants are available for use 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_FREE
LGRP_RSRC_CPU (1)
LGRP_RSRC_MEM (1)
LGRP_CONTENT_ALL (1)
LGRP_LAT_CPU_TO_MEM (1)
P_PID
P_LWPID
P_MYID
(1) Available for versions of the liblgrp(3LIB) API greater than 1.
A detailed description of each function follows. Since this module is intended to provide a Perl interface to the functions in liblgrp(3LIB), a very short description is given for the corresponding functions in this module and a reference is given to the complete description in the liblgrp manual pages. Any differences or additional functionality in the Perl module are highlighted and fully documented here.
lgrp_init([LGRP_VIEW_CALLER | LGRP_VIEW_OS])
Upon successful completion, lgrp_init() returns a cookie. Otherwise it returns undef and sets $! to indicate the error.
See lgrp_init(3LGRP) for more information.
lgrp_fini($cookie)
Upon successful completion, 1 is returned. Otherwise, undef is returned and $! is set to indicate the error.
See lgrp_fini(3LGRP) for more information.
lgrp_view($cookie)
If the given view is LGRP_VIEW_CALLER, the snapshot contains only the resources that are available to the caller (such as those with respect to processor sets). When the view is LGRP_VIEW_OS, the snapshot contains what is available to the operating system.
Upon succesful completion, the function returns the view for the snapshot of the lgroup hierarchy represented by the given cookie. Otherwise, undef is returned and $! is set to indicate the error.
See lgrp_view(3LGRP) for more information.
lgrp_home($idtype, $id)
Upon successful completion, lgrp_home() returns the ID of the home lgroup of the specified process or thread. Otherwise, undef is returned and $! is set to indicate the error.
See lgrp_home(3LGRP) for more information.
lgrp_cookie_stale($cookie)
The lgrp_cookie_stale() function will fail with EINVAL if the cookie is not valid.
See lgrp_cookie_stale(3LGRP) for more information.
lgrp_cpus($cookie, $lgrp, $context)
LGRP_CONTENT_HIERARCHY
LGRP_CONTENT_DIRECT
When called in scalar context, lgrp_cpus() function returns the number of CPUs contained in the specified lgroup.
In the event of error, undef is returned in scalar context and $! is set to indicate the error. In list context, the empty list is returned and $! is set.
See lgrp_cpus(3LGRP) for more information.
lgrp_children($cookie, $lgrp)
When called in scalar context, lgrp_children() returns the number of children lgroups for the specified lgroup.
In the event of error, undef or empty list is returned and $! is set to indicate the error.
See lgrp_children(3LGRP) for more information.
lgrp_parents($cookie, $lgrp)
When called in scalar context, lgrp_parents() returns the number of parent lgroups for the specified lgroup.
In the event of error, undef or an empty list is returned and $! is set to indicate the error.
See lgrp_parents(3LGRP) for more information.
lgrp_nlgrps($cookie)
In the event of error, undef is returned and $! is set to EINVAL, indicating that the cookie is not valid.
See lgrp_nlgrps(3LGRP) for more information.
lgrp_root($cookie)
In the event of error, undef is returned and $! is set to EINVAL, indicatng that the cookie is not valid.
See lgrp_root(3LGRP) for more information.
lgrp_mem_size($cookie, $lgrp, $type, $content)
LGRP_MEM_SZ_FREE
LGRP_MEM_SZ_INSTALLED
The $content argument should be set to one of the following values to specify whether the direct contents or everything in this lgroup including its children should be returned:
LGRP_CONTENT_HIERARCHY
LGRP_CONTENT_DIRECT
The total sizes include all the memory in the lgroup including its children, while the others reflect only the memory contained directly in the given lgroup.
Upon successful completion, the size in bytes is returned. Otherwise, undef is returned and $! is set to indicate the error.
See lgrp_mem_size(3LGRP) for more information.
lgrp_version([$version])
If $version is still supported by the implementation, then lgrp_version() returns the requested version. If LGRP_VER_NONE is returned, the implementation cannot support the requested version.
If $version is LGRP_VER_NONE, lgrp_version() returns the current version of the library.
The following example 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 lgrp_version(3LGRP) for more information.
lgrp_affinity_set($idtype, $id, $lgrp, $affinity)
If the $idtype is P_PID, the affinity is retrieved for one of the LWPs in the process or set for all the LWPs of the process with process ID (PID) $id. The affinity is retrieved or set for the LWP of the current process with LWP ID $id if $idtype is P_LWPID. If $id is P_MYID, then the current LWP or process is specified.
There are different levels of affinity that can be specified by a thread for a particuliar lgroup. The levels of affinity are the following from strongest to weakest:
LGRP_AFF_STRONG
LGRP_AFF_WEAK
LGRP_AFF_NONE
Upon successful completion, lgrp_affinity_set() returns 1. Otherwise, it returns undef and set $! to indicate the error.
See lgrp_affinity_set(3LGRP) for more information.
lgrp_affinity_get($idtype, $id, $lgrp)
See lgrp_affinity_get(3LGRP) for more information.
lgrp_latency_cookie($cookie, $from, $to, [$between=LGRP_LAT_CPU_TO_MEM])
The optional $between argument should be set to LGRP_LAT_CPU_TO_MEM to specify between which hardware resources the latency should be measured. The only valid value is LGRP_LAT_CPU_TO_MEM, which represents latency from CPU to memory.
Upon successful completion, lgrp_latency_cookie() return 1. Otherwise, it returns undef and set $! to indicate the error. For LGRP API version 1, the lgrp_latency_cookie() is an alias for lgrp_latency.()
See lgrp_latency_cookie(3LGRP) for more information.
lgrp_latency($from, $to)
See lgrp_latency(3LGRP) for more information.
lgrp_resources($cookie, $lgrp, $type)
The type can be specified as:
LGRP_RSRC_CPU
LGRP_RSRC_MEM
In the event of error, undef or an empty list is returned and $! is set to indicate the error.
This function is available only for API version 2 and returns undef or an empty list for API version 1 and sets $! to EINVAL.
See lgrp_resources(3LGRP) for more information.
lgrp_lgrps($cookie, [$lgrp])
When called in scalar context, this function returns the total number of lgroups in the system.
lgrp_leaves($cookie, [$lgrp])
When called in scalar context, this function returns the total number of leaf lgroups in the system.
lgrp_isleaf($cookie, $lgrp)
new([$view])
cookie()
version([$version])
stale()
view()
root()
children($lgrp)
parents($lgrp)
nlgrps()
mem_size($lgrp, $type, $content)
cpus($lgrp, $context)
resources($lgrp, $type)
home($idtype, $id)
affinity_get($idtype, $id, $lgrp)
affinity_set($idtype, $id, $lgrp, $affinity)
lgrps([$lgrp])
leaves([$lgrp])
isleaf($lgrp)
latency($from, $to)
By default nothing is exported from this module. The following tags can be used to selectively import constants and functions defined in this module:
:LGRP_CONSTANTS
:PROC_CONSTANTS
:CONSTANTS
:FUNCTIONS
:ALL
The functions in this module return undef or an empty list when an underlying library function fails. The $! is set to provide more information values for the error. The following error codes are possible:
EINVAL
ENOMEM
EPERM
ESRCH
The liblgrp(3LIB) library is versioned. The exact version that was used to compile a module is available through the lgrp_version() function.
Version 2 of the lgrp_user API introduced the following constants and functions not present in version 1:
LGRP_RSRC_CPU constant
LGRP_RSRC_MEM constant
LGRP_CONTENT_ALL constant
LGRP_LAT_CPU_TO_MEM constant
lgrp_resources() function
lgrp_latency_cookie() function
The LGRP_RSRC_CPU and LGRP_RSRC_MEM constants are not defined for version 1. The lgrp_resources() function is defined for version 1 but always returns an empty list. The lgrp_latency_cookie() function is an alias for lgrp_latency() for version 1.
See attributes(5) for descriptions of the following attributes:
|
lgrp_affinity_get(3LGRP), lgrp_affinity_set(3LGRP), lgrp_children(3LGRP), lgrp_cookie_stale(3LGRP), lgrp_cpus(3LGRP), lgrp_fini(3LGRP), lgrp_home(3LGRP), lgrp_init(3LGRP), lgrp_latency(3LGRP), lgrp_latency_cookie(3LGRP), lgrp_mem_size(3LGRP), lgrp_nlgrps(3LGRP), lgrp_parents(3LGRP), lgrp_resources(3LGRP), lgrp_root(3LGRP), lgrp_version(3LGRP), lgrp_view(3LGRP), liblgrp(3LIB), attributes(5)
Закладки на сайте Проследить за страницей |
Created 1996-2024 by Maxim Chirkov Добавить, Поддержать, Вебмастеру |