Sys-CPU-0.61/000755 000765 000024 00000000000 12245472676 012772 5ustar00mattstaff000000 000000 Sys-CPU-0.61/Changes000644 000765 000024 00000001514 11432303316 014243 0ustar00mattstaff000000 000000 Revision history for Perl extension Sys::CPU. 0.01 Wed Jun 27 16:43:58 2001 - original version; created by h2xs 1.20 with options -A -n Sys::CPU 0.10 - Added cpu_type and cpu_clock functions - Changed to better win32 suppport (untested) 0.20 - Fixed linux support 0.25 - Fixed dist tar problem 0.30 - Fixed win32 supprot to work with Windows 2000 (thanks Gary) - Changed interface to eliminate cpu numbers 0.35 - Fixed linux support (thanks Peter) 0.40 - Fixed HP-UX support (thanks Brett Gersekowski) 0.45 - Fixed Solaris support 0.50 - Fixed Darwin/Mac Os support (Marc Koderer) 0.51 - Fixed hidden mac os files 0.52 - fixed bug 50933 and 25253 - added licence info (Fedora bug 585336) Sys-CPU-0.61/CPU.pm000644 000765 000024 00000003046 12245472661 013754 0ustar00mattstaff000000 000000 package Sys::CPU; use strict; use vars qw(@ISA %EXPORT_TAGS @EXPORT_OK $VERSION); require Exporter; require DynaLoader; our @ISA = qw(Exporter DynaLoader); # This allows declaration use Sys::CPU ':all'; # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK # will save memory. our %EXPORT_TAGS = ( 'all' => [ qw( cpu_count cpu_clock cpu_type ) ] ); our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); our $VERSION = '0.61'; bootstrap Sys::CPU $VERSION; # Preloaded methods go here. 1; __END__ # Below is stub documentation for your module. You better edit it! =head1 NAME Sys::CPU - Perl extension for getting CPU information. Currently only number of CPU's supported. =head1 SYNOPSIS use Sys::CPU; $number_of_cpus = Sys::CPU::cpu_count(); printf("I have %d CPU's\n",$number_of_cpus); print " Speed : ",Sys::CPU::cpu_clock(),"\n"; print " Type : ",Sys::CPU::cpu_type(),"\n"; =head1 DESCRIPTION In responce to a post on perlmonks.org, a module for counting the number of CPU's on a system. Support has now also been added for type of CPU and clock speed. While much of the code is from UNIX::Processors, win32 support has been added (but not tested). v0.45 - Corrected solaris support (Thanks Cloyce) v0.60 - Added FreeBSD support (Thanks Johan & SREZIC) v0.61 - Fix test numbering issue =head2 EXPORT None by default. =head1 AUTHOR Matt Sanford =head1 MAINTENANCE Marc Koderer =head1 LICENSE =head1 SEE ALSO perl(1), sysconf(3) =cut Sys-CPU-0.61/CPU.xs000644 000765 000024 00000024525 12245472307 013774 0ustar00mattstaff000000 000000 #include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include /************************************************************************************** * some of the code for the CPU information was copied and modilefied from * * the source for Unix::Processors. All code contained herein in free to use and edit * * under the same licence as Perl itself. * * * **************************************************************************************/ #define MAX_IDENT_SIZE 256 #if defined(_WIN32) || defined(WIN32) #define _have_cpu_type #define _have_cpu_clock #define WINDOWS #endif #ifdef WINDOWS /* WINDOWS */ #include #include #include #include #else /* other (try unix) */ #include #include #endif #if defined(__sun) || defined(__sun__) #include #endif #ifdef _HPUX_SOURCE #include #include #define _have_cpu_clock #define _have_cpu_type #endif #ifdef __APPLE__ #include #define _have_cpu_clock #define _have_cpu_type #endif #ifdef __FreeBSD__ #include #define _have_cpu_type #define _have_cpu_clock #endif #ifdef WINDOWS /* Registry Functions */ int GetSysInfoKey(char *key_name,char *output) { // Get values from registry, use REGEDIT to see how data is stored while sample is running int ret; HKEY hTestKey, hSubKey; DWORD dwRegType, dwBuffSize; // Access using preferred 'Ex' functions if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Hardware\\Description\\System\\CentralProcessor", 0, KEY_READ, &hTestKey) == ERROR_SUCCESS) { if (RegOpenKey(hTestKey, "0", &hSubKey) == ERROR_SUCCESS) { dwBuffSize = MAX_IDENT_SIZE; ret = RegQueryValueEx(hSubKey, key_name, NULL, &dwRegType, output, &dwBuffSize); if (ret != ERROR_SUCCESS) { sprintf(output,"Failed to get Value for key : %d\n",GetLastError()); return(1); } RegCloseKey(hSubKey); } else { sprintf(output,"Failed to open sub-key : %d\n",GetLastError()); return(1); } RegCloseKey(hTestKey); } else { sprintf(output,"Failed to open test key : %d\n",GetLastError()); return(1); } return(0); } #endif /* WINDOWS */ #ifdef _HPUX_SOURCE /* * HP specific function to return the clock-speed of a specified CPU in MHz. */ int proc_get_mhz(int id) { struct pst_processor st; int result = 0; if( !(result = pstat_getprocessor(&st, sizeof(st), (size_t)1, id)) ) { /* Maybe the CPU id too high, so try for CPU 0, instead. */ result = pstat_getprocessor(&st, sizeof(st), (size_t)1, 0); } if( result ) { return st.psp_iticksperclktick * sysconf(_SC_CLK_TCK) / 1000000; } /* Call failed - return 0 for unknown clock speed. */ return 0; } /* * Depending on your version of HP-UX, you may or may not already have these * but we need them, so make sure that they are defined. */ #ifndef CPU_PA_RISC1_0 #define CPU_PA_RISC1_0 0x20B /* HP PA-RISC1.0 */ #endif #ifndef CPU_PA_RISC1_1 #define CPU_PA_RISC1_1 0x210 /* HP PA-RISC1.1 */ #endif #ifndef CPU_PA_RISC1_2 #define CPU_PA_RISC1_2 0x211 /* HP PA-RISC1.2 */ #endif #ifndef CPU_PA_RISC2_0 #define CPU_PA_RISC2_0 0x214 /* HP PA-RISC2.0 */ #endif #ifndef CPU_PA_RISC_MAX #define CPU_PA_RISC_MAX 0x2FF /* Maximum for HP PA-RISC systems. */ #endif #ifndef CPU_IA64_ARCHREV_0 #define CPU_IA64_ARCHREV_0 0x300 /* IA-64 archrev 0 */ #endif const char *proc_get_type_name () { long cpuvers = sysconf(_SC_CPU_VERSION); switch(cpuvers) { case CPU_PA_RISC1_0: return "HP PA-RISC1.0"; case CPU_PA_RISC1_1: return "HP PA-RISC1.1"; case CPU_PA_RISC1_2: return "HP PA-RISC1.2"; case CPU_PA_RISC2_0: return "HP PA-RISC2.0"; case CPU_IA64_ARCHREV_0: return "IA-64 archrev 0"; default: if( CPU_IS_PA_RISC(cpuvers) ) { return "HP PA-RISC"; } } return "UNKNOWN HP-UX"; } #endif /* _HPUX_SOURCE */ #ifdef __APPLE__ #ifndef POWERPC_G3 #define POWERPC_G3 0xcee41549 #endif #ifndef POWERPC_G4 #define POWERPC_G4 0x77c184ae #endif #ifndef POWERPC_G5 #define POWERPC_G5 0xed76d8aa #endif #ifndef INTEL_6_13 #define INTEL_6_13 0xaa33392b #endif #ifndef ARM_9 #define ARM_9 0xe73283ae #endif #ifndef ARM_11 #define ARM_11 0x8ff620d8 #endif #ifndef INTEL_PENRYN #define INTEL_PENRYN 0x78ea4fbc #endif #ifndef INTEL_NEHALEM #define INTEL_NEHALEM 0x6b5a4cd2 #endif #ifndef INTEL_CORE #define INTEL_CORE 0x73d67300 #endif #ifndef INTEL_CORE2 #define INTEL_CORE2 0x426f69ef #endif #ifndef INTEL_COREI7 #define INTEL_COREI7 0x5490B78C #endif char *apple_get_type_name() { int mib[2]; size_t len=2; int kp; sysctlnametomib ("hw.cpufamily", mib, &len); sysctl(mib, 2, NULL, &len, NULL, 0); sysctl(mib, 2, &kp, &len, NULL, 0); switch (kp) { case POWERPC_G3: return "POWERPC_G3"; case POWERPC_G4: return "POWERPC_G4"; case POWERPC_G5: return "POWERPC_G5"; case INTEL_6_13: return "INTEL_6_13"; case ARM_9: return "ARM_9"; case ARM_11: return "ARM_11"; case INTEL_PENRYN: return "INTEL_PENRYN"; case INTEL_NEHALEM: return "INTEL_NEHALEM"; case INTEL_CORE: return "INTEL_CORE"; case INTEL_CORE2: return "INTEL_CORE2"; case INTEL_COREI7: return "INTEL_COREI7"; default: return "UNKNOWN"; } } #endif /* __APPLE__ */ /* the following few functions were shamlessly taken from UNIX::Processors * * to make this linux compatable. No linux machine to test on, so had to * * use existing code */ #ifdef __linux__ #define _have_cpu_type #define _have_cpu_clock /* Return string from a field of /proc/cpuinfo, NULL if not found */ /* Comparison is case insensitive */ char *proc_cpuinfo_field (const char *field) { FILE *fp; static char line[1000]; int len = strlen(field); char *result = NULL; if (NULL!=(fp = fopen ("/proc/cpuinfo", "r"))) { while (!feof(fp) && result==NULL) { if (NULL == fgets (line, 990, fp) && !feof(fp)) break; if (0==strncasecmp (field, line, len)) { char *loc = strchr (line, ':'); if (loc) { result = loc+2; loc = strchr (result, '\n'); if (loc) *loc = '\0'; } } } fclose(fp); } return (result); } /* Return clock frequency */ int proc_cpuinfo_clock (void) { char *value; value = proc_cpuinfo_field ("cpu MHz"); if (value) return (atoi(value)); value = proc_cpuinfo_field ("clock"); if (value) return (atoi(value)); value = proc_cpuinfo_field ("bogomips"); if (value) return (atoi(value)); return (0); } #if defined __s390__ || defined __s390x__ /* Return machine value from s390 processor line, NULL if not found */ char *processor_machine_field (char *processor) { char *machine = NULL; if (NULL == processor) { return NULL; } if (NULL != (machine = strstr(processor, "machine = "))) { machine += 10; } return machine; } #endif #endif int get_cpu_count() { int ret; #ifdef WINDOWS /* WINDOWS */ SYSTEM_INFO info; GetSystemInfo(&info); ret = info.dwNumberOfProcessors; #else /*other (try *nix)*/ #ifdef _HPUX_SOURCE /* HP-UX */ ret = pthread_num_processors_np(); #else /*other unix - try sysconf*/ ret = (int )sysconf(_SC_NPROCESSORS_ONLN); #endif /* HP-UX */ #endif /* WINDOWS */ return ret; } MODULE = Sys::CPU PACKAGE = Sys::CPU int cpu_count() CODE: { int i = 0; i = get_cpu_count(); if (i) { ST(0) = sv_newmortal(); sv_setiv (ST(0), i); } else { ST(0) = &PL_sv_undef; } } int cpu_clock() CODE: { int clock = 0; #ifdef __linux__ int value = proc_cpuinfo_clock(); if (value) clock = value; #endif #ifdef __FreeBSD__ size_t len = sizeof(clock); sysctlbyname("hw.clockrate", &clock, &len, NULL, 0); #endif #ifdef WINDOWS char *clock_str = malloc(MAX_IDENT_SIZE); /*!! untested !!*/ if (GetSysInfoKey("~MHz",clock_str)) { clock = 0; } else { clock = atoi(clock_str); } #endif /* not linux, not windows, not hpux */ #ifdef _HPUX_SOURCE /* Try to get the clock speed for processor 0 - assume all the same. */ clock = proc_get_mhz(0); #endif #ifdef __APPLE__ int mib[2]; unsigned int freq; size_t len; mib[0] = CTL_HW; mib[1] = HW_CPU_FREQ; len = sizeof(freq); sysctl(mib, 2, &freq, &len, NULL, 0); clock = freq/1000000; #endif #ifndef _have_cpu_clock processor_info_t info, *infop=&info; if ( processor_info(0, infop) == 0 && infop->pi_state == P_ONLINE) { if (clock < infop->pi_clock) { clock = infop->pi_clock; } } #endif if (clock) { ST(0) = sv_newmortal(); sv_setiv (ST(0), clock); } else { ST(0) = &PL_sv_undef; } } SV * cpu_type() CODE: { char *value = NULL; #ifdef __FreeBSD__ size_t len = MAX_IDENT_SIZE; sysctlbyname("hw.model", value, &len, NULL, 0); #endif #ifdef __linux__ #if defined __s390__ || defined __s390x__ value = processor_machine_field (proc_cpuinfo_field ("processor") ); #endif if (!value) value = proc_cpuinfo_field ("model name"); if (!value) value = proc_cpuinfo_field ("machine"); if (!value) value = proc_cpuinfo_field ("vendor_id"); #endif #ifdef WINDOWS if (GetSysInfoKey("Identifier", value)) { value = NULL; } #endif #ifdef _HPUX_SOURCE value = proc_get_type_name(); #endif #ifdef __APPLE__ value = apple_get_type_name(); #endif #ifndef _have_cpu_type /* not linux, not windows */ processor_info_t info, *infop=&info; if (processor_info (0, infop)==0) { value = infop->pi_processor_type; } #endif if (value) { ST(0) = sv_newmortal(); sv_setpv (ST(0), value); } else { ST(0) = &PL_sv_undef; } } Sys-CPU-0.61/Makefile.PL000644 000765 000024 00000000745 12050346314 014731 0ustar00mattstaff000000 000000 use ExtUtils::MakeMaker; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. if ($^O eq 'darwin'){ $extra_arg = '-framework Carbon'; } WriteMakefile( 'NAME' => 'Sys::CPU', 'VERSION_FROM' => 'CPU.pm', 'LIBS' => [''], # e.g., '-lm' 'DEFINE' => '', # e.g., '-DHAVE_SOMETHING' 'INC' => '', # e.g., '-I/usr/include/other' 'dynamic_lib' => {OTHERLDFLAGS => $extra_arg}, ); Sys-CPU-0.61/MANIFEST000644 000765 000024 00000000341 12245472676 014121 0ustar00mattstaff000000 000000 CPU.pm CPU.xs Changes MANIFEST Makefile.PL t/Sys-CPU.t README META.yml Module meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) Sys-CPU-0.61/META.json000644 000765 000024 00000001423 12245472676 014413 0ustar00mattstaff000000 000000 { "abstract" : "unknown", "author" : [ "unknown" ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 6.6302, CPAN::Meta::Converter version 2.120921", "license" : [ "unknown" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Sys-CPU", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "requires" : {} } }, "release_status" : "stable", "version" : "0.61" } Sys-CPU-0.61/META.yml000644 000765 000024 00000000651 12245472676 014245 0ustar00mattstaff000000 000000 --- abstract: unknown author: - unknown build_requires: ExtUtils::MakeMaker: 0 configure_requires: ExtUtils::MakeMaker: 0 dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 6.6302, CPAN::Meta::Converter version 2.120921' license: unknown meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: Sys-CPU no_index: directory: - t - inc requires: {} version: 0.61 Sys-CPU-0.61/README000644 000765 000024 00000003762 12050350765 013646 0ustar00mattstaff000000 000000 Sys::CPU is Copyright (c) 2001-2010, MZSanford This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. For more details, see the full text of the licenses in the directory LICENSES. NAME Sys::CPU - Perl extension for getting CPU information. Currently only number of CPU's supported. SYNOPSIS use Sys::CPU; $number_of_cpus = Sys::CPU::cpu_count(); printf("I have %d CPU's\n",$number_of_cpus); print " Speed : ",Sys::CPU::cpu_clock(),"\n"; print " Type : ",Sys::CPU::cpu_type(),"\n"; DESCRIPTION In responce to a post on perlmonks.org, a module for counting the number of CPU's on a system. Support has now also been added for type of CPU and clock speed. While much of the code is from UNIX::Processors, win32 support has been added (but not tested). EXPORT None by default. AUTHOR MZSanford MAINTENANCE Marc Koderer SEE ALSO perl(1), sysconf(3) CHANGES Revision history for Perl extension Sys::CPU. 0.01 Wed Jun 27 16:43:58 2001 - original version; created by h2xs 1.20 with options -A -n Sys::CPU 0.10 - Added cpu_type and cpu_clock functions - Changed to better win32 suppport (untested) 0.20 - Fixed linux support 0.25 - Fixed dist tar problem 0.30 - Fixed win32 supprot to work with Windows 2000 (thanks Gary) - Changed interface to eliminate cpu numbers 0.35 - Fixed linux support (thanks Peter) 0.40 - Fixed HP-UX support (thanks Brett Gersekowski) 0.45 - Fixed Solaris support 0.50 - Fixed Darwin/Mac Os support (Marc Koderer) 0.51 - Fixed hidden mac os files 0.52 - Fixed bug 50933 and 25253 - Added license info (Fedora bug 585336) 0.53 - Fixed bug in s390 CPU detection (thanks Petr Pisar) 0.54 - Clean up some compiler warnings introduced in 0.53 (thanks Petr Pisar) - Clean up other compiler warnings (thanks Petr Pisar) Sys-CPU-0.61/t/000755 000765 000024 00000000000 12245472676 013235 5ustar00mattstaff000000 000000 Sys-CPU-0.61/t/Sys-CPU.t000755 000765 000024 00000002353 12245472563 014626 0ustar00mattstaff000000 000000 # Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl test.pl' ######################### We start with some black magic to print on failure. # Change 1..1 below to 1..last_test_to_print . # (It may become useful if the test is moved to ./t subdirectory.) BEGIN { $| = 1; print "1..4\n"; } END {print "not ok 1\n" unless $loaded;} use Sys::CPU; $loaded = 1; print "ok 1\n"; $number = &Sys::CPU::cpu_count(); if (defined($number)) { print "ok 2 (CPU Count : $number)\n"; } else { print "not ok 2 (cpu_count failed)\n"; } $speed = &Sys::CPU::cpu_clock(); if (defined($speed)) { print "ok 3 (CPU Speed : $speed)\n"; } elsif ( $^O eq 'MSWin32'){ print "ok 3 (CPU Speed: test skipped on MSWin32)\n"; } else { print "not ok 3 (cpu_clock undefined (ok if Win9x))\n"; } $type = &Sys::CPU::cpu_type(); if (defined($type)) { print "ok 4 (CPU Type : $type)\n"; } else { print "not ok 4 (cpu_type unavailable)\n"; } ######################### End of black magic. # Insert your test code below (better if it prints "ok 13" # (correspondingly "not ok 13") depending on the success of chunk 13 # of the test code):