/*
solarissystem.h
Copyright 2006 John Poole.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef INC_SOLARISSYSTEM_H
#define INC_SOLARISSYSTEM_H
#include "system.h"
#include <sstream>
#include <unistd.h>
#include <sys/utsname.h>
#include <sys/systeminfo.h>
#include <kstat.h>
#include <set>
#include <iostream>
#include <smbios.h>
static std::string trim( const std::string s )
{
std::string::size_type p;
std::string::size_type q;
p = s.find_first_not_of( ' ' );
if( p == std::string::npos ) {
p = 0;
}
q = s.find_last_not_of( ' ' );
if( q == std::string::npos ) {
q = s.length() - 1;
}
return s.substr( p, q - p + 1 );
}
class SolarisSystem : public BaseSystem {
public:
SolarisSystem() : BaseSystem() {
}
virtual ~SolarisSystem() {
}
virtual std::string os() {
std::ostringstream s;
struct utsname name;
uname( &name );
s << name.sysname << " " << name.release << " " << name.machine;
return s.str();
}
virtual std::string model() {
#if 0
char buffer[ 257 ];
sysinfo( SI_PLATFORM, buffer, 256 );
return buffer;
#endif
std::ostringstream s;
smbios_hdl_t * shp;
smbios_struct_t ss;
smbios_info_t i;
int err;
shp = smbios_open( NULL, SMB_VERSION, 0, &err );
err = smbios_lookup_id( shp, SMB_TYPE_SYSTEM, &ss );
err = smbios_info_common( shp, ss.smbstr_id, &i );
s << trim( i.smbi_manufacturer ) << " " << trim( i.smbi_product );
smbios_close( shp );
return s.str();
}
virtual std::string motherboard() {
std::ostringstream s;
smbios_hdl_t * shp;
smbios_struct_t ss;
smbios_info_t i;
int err;
shp = smbios_open( NULL, SMB_VERSION, 0, &err );
err = smbios_lookup_id( shp, SMB_TYPE_BASEBOARD, &ss );
err = smbios_info_common( shp, ss.smbstr_id, &i );
s << trim( i.smbi_manufacturer ) << " " << trim( i.smbi_product );
smbios_close( shp );
return s.str();
}
virtual std::string cpu() {
kstat_ctl_t *kc;
kstat_t *ksp;
kstat_io_t kio;
kstat_named_t *knp;
kc = kstat_open();
ksp = kstat_lookup( kc, ( char * )"cpu_info", -1, NULL );
kstat_read( kc, ksp, NULL );
knp = ( kstat_named_t *)kstat_data_lookup( ksp, ( char * )"brand" );
return knp->value.string.addr.ptr;
}
virtual std::string cpuid() {
kstat_ctl_t *kc;
kstat_t *ksp;
kstat_io_t kio;
kstat_named_t *knp;
kc = kstat_open();
ksp = kstat_lookup( kc, ( char * )"cpu_info", -1, NULL );
kstat_read( kc, ksp, NULL );
knp = ( kstat_named_t *)kstat_data_lookup( ksp, ( char * )"implementation" );
return knp->value.string.addr.ptr;
}
virtual uint64 cpuLogicalCount() {
kstat_ctl_t *kc;
kstat_t *ksp;
kstat_io_t kio;
int count = 0;
kc = kstat_open();
for( ksp = kc->kc_chain; ksp != NULL; ksp = ksp->ks_next ) {
if( strcmp( ksp->ks_module, "cpu_info" ) == 0 ) {
count += 1;
}
}
return count;
}
virtual uint64 cpuPhysicalCount() {
kstat_ctl_t *kc;
kstat_t *ksp;
kstat_io_t kio;
kstat_named_t *knp;
std::set<int> physicalid;
kc = kstat_open();
for( ksp = kc->kc_chain; ksp != NULL; ksp = ksp->ks_next ) {
if( strcmp( ksp->ks_module, "cpu_info" ) == 0 ) {
kstat_read( kc, ksp, NULL );
knp = ( kstat_named_t *)kstat_data_lookup( ksp, ( char * )"chip_id" );
physicalid.insert( knp->value.i32 );
}
}
return physicalid.size();
}
virtual uint64 cpuFrequency() {
kstat_ctl_t *kc;
kstat_t *ksp;
kstat_io_t kio;
kstat_named_t *knp;
kc = kstat_open();
ksp = kstat_lookup( kc, ( char * )"cpu_info", -1, NULL );
kstat_read( kc, ksp, NULL );
knp = ( kstat_named_t *)kstat_data_lookup( ksp, ( char * )"clock_MHz" );
return knp->value.i32 * 1000000;
}
virtual uint64 busFrequency() {
return 0;
}
virtual uint64 memorySize() {
return sysconf( _SC_PAGESIZE ) * sysconf( _SC_PHYS_PAGES );
}
virtual bool simd() {
return false;
}
};
#endif