Sys::Info::Driver::BSD::Device::CPU - BSD CPU Device Driver


Sys-Info-Driver-BSD documentation Contained in the Sys-Info-Driver-BSD distribution.

Index


Code Index:

NAME

Top

Sys::Info::Driver::BSD::Device::CPU - BSD CPU Device Driver

SYNOPSIS

Top

-

DESCRIPTION

Top

This document describes version 0.73 of Sys::Info::Driver::BSD::Device::CPU released on 14 January 2010.

Identifies the CPU with Unix::Processors, POSIX.

METHODS

Top

identify

See identify in Sys::Info::Device::CPU.

load

See load in Sys::Info::Device::CPU.

bitness

See bitness in Sys::Info::Device::CPU.

SEE ALSO

Top

Sys::Info, Sys::Info::Device::CPU, Unix::Processors, POSIX.

AUTHOR

Top

Burak Gursoy <burak@cpan.org>.

COPYRIGHT

Top

LICENSE

Top

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.


Sys-Info-Driver-BSD documentation Contained in the Sys-Info-Driver-BSD distribution.

package Sys::Info::Driver::BSD::Device::CPU;
use strict;
use warnings;
use vars qw($VERSION);
use base qw(Sys::Info::Base);
use Unix::Processors;
use POSIX ();
use Carp qw( croak );
use Sys::Info::Driver::BSD;

$VERSION = '0.73';

sub identify {
    my $self = shift;

    if ( ! $self->{META_DATA} ) {
        my $up   = Unix::Processors->new;
        my $mach = $self->uname->{machine} || fsysctl('hw.machine_arch'); # hw.machine?
        my $arch = $mach =~ m{ i [0-9] 86 }xmsi ? 'x86'
                 : $mach =~ m{ ia64       }xmsi ? 'IA64'
                 : $mach =~ m{ x86_64     }xmsi ? 'AMD-64'
                 :                                 $mach
                 ;
        my $name = fsysctl('hw.model');
        $name =~ s{\s+}{ }xms;
        my $byteorder = nsysctl('hw.byteorder');
        my @flags;
        push @flags, 'FPU' if nsysctl('hw.floatingpoint');

        $self->{META_DATA} = [];

        my %d = dmesg();
        if ( $d{CPU} ) {
            my %cpu = %{ $d{CPU} };
            for my $slot ( @cpu{ qw/ flags AMD_flags / } ) {
                next if ! $slot;
                push @flags, @{ $slot };
            }
        }

        push @{ $self->{META_DATA} }, {
            architecture                 => $arch,
            processor_id                 => 1,
            data_width                   => undef,
            address_width                => undef,
            bus_speed                    => undef,
            speed                        => $up->max_clock,
            name                         => $name,
            family                       => undef,
            manufacturer                 => undef,
            model                        => undef,
            stepping                     => undef,
            number_of_cores              => $up->max_physical,
            number_of_logical_processors => $up->max_online,
            L2_cache                     => {max_cache_size => undef},
            flags                        => @flags ? [ @flags ] : undef,
            ( $byteorder ? (byteorder    => $byteorder):()),
        } for 1..fsysctl('hw.ncpu');
    }
    #$VAR1 = 'Intel(R) Core(TM)2 Duo CPU     P8600  @ 2.40GHz';
    return $self->_serve_from_cache(wantarray);
}

sub load {
    my $self  = shift;
    my $level = shift;
    my $loads = fsysctl('vm.loadavg') || 0;
    return $loads->[$level];
}

sub bitness {
    my $self = shift;
    my %i    = dmesg();
    my $cpu  = $i{CPU} || return;
    my %flags;
    foreach my $slot ( $cpu->{flags}, $cpu->{AMD_flags} ) {
        next if ! $slot;
        $flags{ $_ } = 1 for @{ $slot };
    }
    return $flags{LM} ? '64' : '32';
}

1;

__END__