1N/A#
1N/A# CDDL HEADER START
1N/A#
1N/A# The contents of this file are subject to the terms of the
1N/A# Common Development and Distribution License (the "License").
1N/A# You may not use this file except in compliance with the License.
1N/A#
1N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
1N/A# or http://www.opensolaris.org/os/licensing.
1N/A# See the License for the specific language governing permissions
1N/A# and limitations under the License.
1N/A#
1N/A# When distributing Covered Code, include this CDDL HEADER in each
1N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1N/A# If applicable, add the following below this CDDL HEADER, with the
1N/A# fields enclosed by brackets "[]" replaced with your own identifying
1N/A# information: Portions Copyright [yyyy] [name of copyright owner]
1N/A#
1N/A# CDDL HEADER END
1N/A#
1N/A
1N/A#
2N/A# Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
1N/A#
1N/A
1N/A#
1N/A# Lgrp.pm provides procedural and object-oriented interface to the Solaris
1N/A# liblgrp(3LIB) library.
1N/A#
1N/A
1N/A
1N/Arequire 5.8.4;
1N/Ause strict;
1N/Ause warnings;
1N/Ause Carp;
1N/A
1N/Apackage Sun::Solaris::Lgrp;
1N/A
1N/Aour $VERSION = '1.1';
1N/Ause XSLoader;
1N/AXSLoader::load(__PACKAGE__, $VERSION);
1N/A
1N/Arequire Exporter;
1N/A
1N/Aour @ISA = qw(Exporter);
1N/A
1N/Aour (@EXPORT_OK, %EXPORT_TAGS);
1N/A
1N/A# Things to export
1N/Amy @lgrp_constants = qw(LGRP_AFF_NONE LGRP_AFF_STRONG LGRP_AFF_WEAK
1N/A LGRP_CONTENT_DIRECT LGRP_CONTENT_HIERARCHY
1N/A LGRP_MEM_SZ_FREE LGRP_MEM_SZ_INSTALLED LGRP_VER_CURRENT
1N/A LGRP_VER_NONE LGRP_VIEW_CALLER
1N/A LGRP_VIEW_OS LGRP_NONE
1N/A LGRP_RSRC_CPU LGRP_RSRC_MEM
1N/A LGRP_CONTENT_ALL LGRP_LAT_CPU_TO_MEM
1N/A);
1N/A
1N/Amy @proc_constants = qw(P_PID P_LWPID P_MYID);
1N/A
1N/Amy @constants = (@lgrp_constants, @proc_constants);
1N/A
1N/Amy @functions = qw(lgrp_affinity_get lgrp_affinity_set
1N/A lgrp_children lgrp_cookie_stale lgrp_cpus lgrp_fini
1N/A lgrp_home lgrp_init lgrp_latency lgrp_latency_cookie
1N/A lgrp_mem_size lgrp_nlgrps lgrp_parents
1N/A lgrp_root lgrp_version lgrp_view lgrp_resources
2N/A lgrp_isleaf lgrp_lgrps lgrp_leaves lgrp_device_lgrps);
1N/A
1N/Amy @all = (@constants, @functions);
1N/A
1N/A# Define symbolic names for various subsets of export lists
1N/A%EXPORT_TAGS = ('CONSTANTS' => \@constants,
1N/A 'LGRP_CONSTANTS' => \@lgrp_constants,
1N/A 'PROC_CONSTANTS' => \@proc_constants,
1N/A 'FUNCTIONS' => \@functions,
1N/A 'ALL' => \@all);
1N/A
1N/A# Define things that are ok ot export.
1N/A@EXPORT_OK = ( @{ $EXPORT_TAGS{'ALL'} } );
1N/A
1N/A#
1N/A# _usage(): print error message and terminate the program.
1N/A#
1N/Asub _usage
1N/A{
1N/A my $msg = shift;
1N/A Carp::croak "Usage: Sun::Solaris::Lgrp::$msg";
1N/A}
1N/A
1N/A#
1N/A# lgrp_isleaf($cookie, $lgrp)
1N/A# Returns T if lgrp is leaf, F otherwise.
1N/A#
1N/Asub lgrp_isleaf
1N/A{
1N/A scalar @_ == 2 or _usage "lgrp_isleaf(cookie, lgrp)";
1N/A return (!lgrp_children(shift, shift));
1N/A}
1N/A
1N/A#
1N/A# lgrp_lgrps($cookie, [$lgrp])
1N/A# Returns: list of lgrps in a subtree starting from $lgrp.
1N/A# If $root is not specified, use lgrp_root.
1N/A# undef on failure.
1N/Asub lgrp_lgrps
1N/A{
1N/A scalar @_ > 0 or _usage("lgrp_lgrps(cookie, [lgrp])");
1N/A my $cookie = shift;
1N/A my $root = shift;
1N/A $root = lgrp_root($cookie) unless defined $root;
1N/A return unless defined $root;
1N/A my @children = lgrp_children($cookie, $root);
1N/A my @result;
1N/A
1N/A #
1N/A # Concatenate root with subtrees for every children. Every subtree is
1N/A # obtained by calling lgrp_lgrps recursively with each of the children
1N/A # as the argument.
1N/A #
1N/A @result = @children ?
1N/A ($root, map {lgrp_lgrps($cookie, $_)} @children) :
1N/A ($root);
1N/A return (wantarray ? @result : scalar @result);
1N/A}
1N/A
1N/A#
1N/A# lgrp_leaves($cookie, [$lgrp])
1N/A# Returns: list of leaves in the hierarchy starting from $lgrp.
1N/A# If $lgrp is not specified, use lgrp_root.
1N/A# undef on failure.
1N/A#
1N/Asub lgrp_leaves
1N/A{
1N/A scalar @_ > 0 or _usage("lgrp_leaves(cookie, [lgrp])");
1N/A my $cookie = shift;
1N/A my $root = shift;
1N/A $root = lgrp_root($cookie) unless defined $root;
1N/A return unless defined $root;
1N/A my @result = grep {
1N/A lgrp_isleaf($cookie, $_)
1N/A } lgrp_lgrps($cookie, $root);
1N/A return (wantarray ? @result : scalar @result);
1N/A}
1N/A
1N/A######################################################################
1N/A# Object-Oriented interface.
1N/A######################################################################
1N/A
1N/A#
1N/A# cookie: extract cookie from the argument.
1N/A# If the argument is scalar, it is the cookie itself, otherwise it is the
1N/A# reference to the object and the cookie value is in $self->{COOKIE}.
1N/A#
1N/Asub cookie
1N/A{
1N/A my $self = shift;
1N/A return ((ref $self) ? $self->{COOKIE} : $self);
1N/A}
1N/A
1N/A#
1N/A# new: The object constructor
1N/A#
1N/Asub new
1N/A{
1N/A my $class = shift;
1N/A my ($self, $view);
1N/A $view = shift;
1N/A $self->{COOKIE} = (defined($view) ? lgrp_init($view) : lgrp_init()) or
1N/A croak("lgrp_init: $!\n"), return;
1N/A bless($self, $class) if defined($class);
1N/A bless($self) unless defined($class);
1N/A return ($self);
1N/A}
1N/A
1N/A#
1N/A# DESTROY: the object destructor.
1N/A#
1N/Asub DESTROY
1N/A{
1N/A lgrp_fini(cookie(shift));
1N/A}
1N/A
1N/A############################################################
1N/A# Wrapper methods.
1N/A#
1N/Asub stale
1N/A{
1N/A scalar @_ == 1 or _usage("stale(class)");
1N/A return (lgrp_cookie_stale(cookie(shift)));
1N/A}
1N/A
1N/Asub view
1N/A{
1N/A scalar @_ == 1 or _usage("view(class)");
1N/A return (lgrp_view(cookie(shift)));
1N/A}
1N/A
1N/Asub root
1N/A{
1N/A scalar @_ == 1 or _usage("root(class)");
1N/A return (lgrp_root(cookie(shift)));
1N/A}
1N/A
1N/Asub nlgrps
1N/A{
1N/A scalar @_ == 1 or _usage("nlgrps(class)");
1N/A return (lgrp_nlgrps(cookie(shift)));
1N/A}
1N/A
1N/Asub lgrps
1N/A{
1N/A scalar @_ > 0 or _usage("lgrps(class, [lgrp])");
1N/A return (lgrp_lgrps(cookie(shift), shift));
1N/A}
1N/A
1N/Asub leaves
1N/A{
1N/A scalar @_ > 0 or _usage("leaves(class, [lgrp])");
1N/A return (lgrp_leaves(cookie(shift), shift));
1N/A}
1N/A
1N/Asub version
1N/A{
1N/A scalar @_ > 0 or _usage("leaves(class, [version])");
1N/A shift;
1N/A return (lgrp_version(shift || 0));
1N/A}
1N/A
1N/Asub children
1N/A{
1N/A scalar @_ == 2 or _usage("children(class, lgrp)");
1N/A return (lgrp_children(cookie(shift), shift));
1N/A}
1N/A
1N/Asub parents
1N/A{
1N/A scalar @_ == 2 or _usage("parents(class, lgrp)");
1N/A return (lgrp_parents(cookie(shift), shift));
1N/A}
1N/A
1N/Asub mem_size
1N/A{
1N/A scalar @_ == 4 or _usage("mem_size(class, lgrp, type, content)");
1N/A return (lgrp_mem_size(cookie(shift), shift, shift, shift));
1N/A}
1N/A
1N/Asub cpus
1N/A{
1N/A scalar @_ == 3 or _usage("cpus(class, lgrp, content)");
1N/A return (lgrp_cpus(cookie(shift), shift, shift));
1N/A}
1N/A
1N/Asub isleaf
1N/A{
1N/A scalar @_ == 2 or _usage("isleaf(class, lgrp)");
1N/A lgrp_isleaf(cookie(shift), shift);
1N/A}
1N/A
1N/Asub resources
1N/A{
1N/A scalar @_ == 3 or _usage("resources(class, lgrp, resource)");
1N/A return (lgrp_resources(cookie(shift), shift, shift));
1N/A}
1N/A
1N/Asub latency
1N/A{
1N/A scalar @_ == 3 or _usage("latency(class, from, to)");
1N/A return (lgrp_latency_cookie(cookie(shift), shift, shift));
1N/A}
1N/A
1N/A# Methods that do not require cookie
1N/Asub home
1N/A{
1N/A scalar @_ == 3 or _usage("home(class, idtype, id)");
1N/A shift;
1N/A return (lgrp_home(shift, shift));
1N/A}
1N/A
1N/Asub affinity_get
1N/A{
1N/A scalar @_ == 4 or _usage("affinity_get(class, idtype, id, lgrp)");
1N/A shift;
1N/A return (lgrp_affinity_get(shift, shift, shift));
1N/A}
1N/A
1N/Asub affinity_set
1N/A{
1N/A scalar @_ == 5 or
1N/A _usage("affinity_set(class, idtype, id, lgrp, affinity)");
1N/A shift;
1N/A return (lgrp_affinity_set(shift, shift, shift, shift));
1N/A}
1N/A
2N/Asub device_lgrps
2N/A{
2N/A scalar @_ == 2 or
2N/A _usage("device_lgrps(device_path)");
2N/A shift;
2N/A return (lgrp_device_lgrps(shift));
2N/A}
2N/A
1N/A1;
1N/A
1N/A__END__