c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# CDDL HEADER START
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# The contents of this file are subject to the terms of the
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Common Development and Distribution License (the "License").
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# You may not use this file except in compliance with the License.
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# See the License for the specific language governing permissions
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# and limitations under the License.
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# When distributing Covered Code, include this CDDL HEADER in each
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# If applicable, add the following below this CDDL HEADER, with the
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# fields enclosed by brackets "[]" replaced with your own identifying
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# information: Portions Copyright [yyyy] [name of copyright owner]
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# CDDL HEADER END
fbdfbdd80db964f47d48b36c08c747e636fe7b42vm# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Use is subject to license terms.
fbdfbdd80db964f47d48b36c08c747e636fe7b42vm# ident "%Z%%M% %I% %E% SMI"
f52e84dfce89ba2ea0ebb6a191b4466da3012efdvm# Make sure that Lgrp test is not executed on anything less than 5.8.0,
f52e84dfce89ba2ea0ebb6a191b4466da3012efdvm# as Lgrp is not implemented there
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb######################################################################
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Tests for Sun::Solaris::Lgrp API.
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# This is an example script that demonstrates use of Sun::Solaris::Lgrp module.
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# It can be used to test the module itself, the liblgrp library or the in-kernel
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# implementation.
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb######################################################################
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Tests to run
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Verify that we can load the module
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb######################################################################
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Verify that lgrp_init() works.
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb######################################################################
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb######################################################################
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# root should have ID 0.
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb######################################################################
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Verify lgrp_nlgrps()
c64027834c5ffc60c557c2b12555e0cd4d30320cakolbis(scalar @lgrps, $nlgrps, 'lgrp_nlgrps() should match number of lgrps');
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb######################################################################
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# All root children should have root as their one and only one parent
c64027834c5ffc60c557c2b12555e0cd4d30320cakolbcmp_ok(@children, '<=', @leaves, 'Root should have nchildren <= nleaves');
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb######################################################################
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Each lgrp other than root should have a single parent and
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# root should have no parents.
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb next if $l == $root;
c64027834c5ffc60c557c2b12555e0cd4d30320cakolbis($fail, 0, 'All non-leaf lgrps should have single parent');
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb#######################################################################
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb######################################################################
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Lgrp affinity tests.
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb#######################
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb######################################################################
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# lgrp_affinity-set should change home lgrp.
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb skip 'Test only valid on NUMA platform', 1 unless $is_numa;
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb $c->affinity_set(P_PID, P_MYID, $lgrp, LGRP_AFF_STRONG) or
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb is($home, $lgrp, 'Home lgrp should change after strong affinity is set');
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb $c->affinity_set(P_PID, P_MYID, $lgrp, LGRP_AFF_NONE) or
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb######################################################################
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Should be able to set affinity to any legal value
c64027834c5ffc60c557c2b12555e0cd4d30320cakolbmy @affs = (LGRP_AFF_WEAK, LGRP_AFF_STRONG, LGRP_AFF_NONE);
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb######################################################################
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb######################################################################
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Root should have non-zero CPUs and memory size
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Also, its memory size should be consistent with the one reported by
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# sysconfig.
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb######################################################################
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb######################################################################
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# The cookie should not be stale
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb######################################################################
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb######################################################################
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Latency should be non-zero.
c64027834c5ffc60c557c2b12555e0cd4d30320cakolbok(defined $latency1, 'lgrp_latency_cookie() is working') or
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb######################################################################
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb######################################################################
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Verify latency matrix.
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb skip 'Test only valid on NUMA platform', 9 unless $is_numa;
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb cmp_ok($latency, '>', 0, "Latency from root to self should be positive");
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb # There should be at least some lgroups which have latencies.
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb my @d_lgrps = grep { defined $latencies->{$_}{$_} } @leaves;
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb ok(@d_lgrps, 'There should be at least some lgroups which have latencies');
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb my $lat_diag = $latencies->{$lat_diag_lgrp}{$lat_diag_lgrp};
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb my @badlatencies = grep { $latencies->{$_}{$_} != $lat_diag } @d_lgrps;
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb is(scalar @badlatencies, 0, 'All diagonal latencies should be the same') or
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb diag("diagonal latency: $lat_diag; bad latencies: @badlatencies");
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb $l_cpus{$l1} = scalar $c->cpus($l1, LGRP_CONTENT_HIERARCHY);
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb $l_mem{$l1} = $c->mem_size($l1, LGRP_MEM_SZ_INSTALLED,
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb $lgrps_nocpus++ unless $c->cpus($l1, LGRP_CONTENT_HIERARCHY);
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb # Can't get latenciy if destination doesn't have memory
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb # Latencies should be symmetrical but only if they are valid.
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb $diagonalmin++ if $c->isleaf($l1) && $c->isleaf($l2) &&
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb $self_latency && $self_latency > $latencies->{$l1}{$l2};
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb skip 'Symmetry test only valid if all lgroups have memory and CPUs',
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb is($assymetrical, 0, 'Latencies should be symmetrical');
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb is($diagonalmin, 0, 'Latency should be minimal on diagonals');
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb cmp_ok($min_latency, '>', 0, 'Minimum latency should be positive') if
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb 'Minimum latency should be less then maximum') if $nlatencies;
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb######################################################################
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Verify lgrp_resources API
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb ok(scalar @lgrps_c, 'there are CPU resources in the system');
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb is($fail, 0, 'Each lgrp containing CPU resources should be leaf');
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb######################################################################