#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
#
#
# Lgrp.pm provides procedural and object-oriented interface to the Solaris
# liblgrp(3LIB) library.
#
require 5.8.4;
use strict;
use warnings;
use Carp;
our $VERSION = '1.1';
use XSLoader;
require Exporter;
our (@EXPORT_OK, %EXPORT_TAGS);
# Things to export
);
# Define symbolic names for various subsets of export lists
'LGRP_CONSTANTS' => \@lgrp_constants,
'PROC_CONSTANTS' => \@proc_constants,
'FUNCTIONS' => \@functions,
'ALL' => \@all);
# Define things that are ok ot export.
#
# _usage(): print error message and terminate the program.
#
sub _usage
{
my $msg = shift;
Carp::croak "Usage: Sun::Solaris::Lgrp::$msg";
}
#
# lgrp_isleaf($cookie, $lgrp)
# Returns T if lgrp is leaf, F otherwise.
#
sub lgrp_isleaf
{
return (!lgrp_children(shift, shift));
}
#
# lgrp_lgrps($cookie, [$lgrp])
# Returns: list of lgrps in a subtree starting from $lgrp.
# If $root is not specified, use lgrp_root.
# undef on failure.
sub lgrp_lgrps
{
my $cookie = shift;
my $root = shift;
return unless defined $root;
my @result;
#
# Concatenate root with subtrees for every children. Every subtree is
# obtained by calling lgrp_lgrps recursively with each of the children
# as the argument.
#
($root);
}
#
# lgrp_leaves($cookie, [$lgrp])
# Returns: list of leaves in the hierarchy starting from $lgrp.
# If $lgrp is not specified, use lgrp_root.
# undef on failure.
#
sub lgrp_leaves
{
my $cookie = shift;
my $root = shift;
return unless defined $root;
my @result = grep {
lgrp_isleaf($cookie, $_)
}
######################################################################
# Object-Oriented interface.
######################################################################
#
# cookie: extract cookie from the argument.
# If the argument is scalar, it is the cookie itself, otherwise it is the
# reference to the object and the cookie value is in $self->{COOKIE}.
#
sub cookie
{
my $self = shift;
}
#
# new: The object constructor
#
sub new
{
my $class = shift;
$view = shift;
croak("lgrp_init: $!\n"), return;
return ($self);
}
#
# DESTROY: the object destructor.
#
sub DESTROY
{
}
############################################################
# Wrapper methods.
#
sub stale
{
return (lgrp_cookie_stale(cookie(shift)));
}
sub view
{
}
sub root
{
}
sub nlgrps
{
return (lgrp_nlgrps(cookie(shift)));
}
sub lgrps
{
return (lgrp_lgrps(cookie(shift), shift));
}
sub leaves
{
return (lgrp_leaves(cookie(shift), shift));
}
sub version
{
shift;
return (lgrp_version(shift || 0));
}
sub children
{
return (lgrp_children(cookie(shift), shift));
}
sub parents
{
return (lgrp_parents(cookie(shift), shift));
}
sub mem_size
{
return (lgrp_mem_size(cookie(shift), shift, shift, shift));
}
sub cpus
{
}
sub isleaf
{
lgrp_isleaf(cookie(shift), shift);
}
sub resources
{
return (lgrp_resources(cookie(shift), shift, shift));
}
sub latency
{
return (lgrp_latency_cookie(cookie(shift), shift, shift));
}
# Methods that do not require cookie
sub home
{
shift;
return (lgrp_home(shift, shift));
}
sub affinity_get
{
shift;
return (lgrp_affinity_get(shift, shift, shift));
}
sub affinity_set
{
scalar @_ == 5 or
_usage("affinity_set(class, idtype, id, lgrp, affinity)");
shift;
return (lgrp_affinity_set(shift, shift, shift, shift));
}
sub device_lgrps
{
scalar @_ == 2 or
_usage("device_lgrps(device_path)");
shift;
return (lgrp_device_lgrps(shift));
}
1;