Matrix Science header

ms_processors.hpp

00001 /*
00002 ##############################################################################
00003 # file: ms_processors.hpp                                                    #
00004 # 'msparser' toolkit                                                         #
00005 # Use this class to retrieve current CPU configuration                       #
00006 ##############################################################################
00007 # COPYRIGHT NOTICE                                                           #
00008 # Copyright 1998-2003 Matrix Science Limited  All Rights Reserved.           #
00009 #                                                                            #
00010 ##############################################################################
00011 #    $Archive:: /Mowse/ms_mascotresfile/include/ms_processors.hpp          $ #
00012 #     $Author: francoisr $ #
00013 #       $Date: 2016/10/05 11:16:13 $ #
00014 #   $Revision: 1.17 $ #
00015 # $NoKeywords::                                                            $ #
00016 ##############################################################################
00017 */
00018 
00019 #ifndef MS_PROCESSORS_HPP
00020 #define MS_PROCESSORS_HPP
00021 
00022 #ifdef _WIN32
00023 #pragma warning(disable:4251)   // Don't want all classes to be exported
00024 #pragma warning(disable:4786)   // Debug symbols too long
00025 #   ifndef _MATRIX_USE_STATIC_LIB
00026 #       ifdef MS_MASCOTRESFILE_EXPORTS
00027 #           define MS_MASCOTRESFILE_API __declspec(dllexport)
00028 #       else
00029 #           define MS_MASCOTRESFILE_API __declspec(dllimport)
00030 #       endif
00031 #   else
00032 #       define MS_MASCOTRESFILE_API
00033 #   endif
00034 #else
00035 #   define MS_MASCOTRESFILE_API
00036 #endif
00037 
00038 // for the sake of #include <string>
00039 #ifdef __ALPHA_UNIX__
00040 #include <ctype.h>
00041 #endif
00042 #ifdef __SUNOS__
00043 #include <kstat.h>
00044 #endif
00045 #include <string>
00046 #include <vector>
00047 #include <map>
00048 
00049 namespace matrix_science {
00050 
00051 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00052 #ifndef SWIG
00053     class MS_MASCOTRESFILE_API ms_cpuinfo
00054     {
00055     public:
00056         ms_cpuinfo() : cpu_id_(0), 
00057                        core_id_(0),
00058                        ht_id(0),
00059                        processor_speed_MHZ_(0),
00060                        hyperthreaded_(false), 
00061                        availableForMascot_(true), 
00062                        isPrimary_(true) {};
00063         // int logical_id use as the map
00064         int  cpu_id_;
00065         int  core_id_;
00066         int  ht_id;
00067         int  processor_speed_MHZ_;
00068         bool hyperthreaded_;
00069         bool availableForMascot_;  // Should always be true?
00070         bool isPrimary_;
00071     };
00072 #endif  // SWIG
00073 #endif // DOXYGEN_SHOULD_SKIP_THIS
00074 
00075 
00081 
00082 
00087     class MS_MASCOTRESFILE_API ms_processors: public ms_errors
00088     {
00089     public:
00090         typedef std::vector<short> cpu_id_t;
00091 
00093 
00100         enum HYPERTHREADING
00101         {
00102             HT_NOT_CAPABLE           = 0, 
00103             HT_ENABLED               = 1, 
00104             HT_DISABLED              = 2, 
00105             HT_SUPPORTED_NOT_ENABLED = 3, 
00106             HT_CANNOT_DETECT         = 4  
00107         };
00108 
00110 
00116         enum { 
00117             MAX_CORES_PER_LICENSE = 4 
00118         };
00119 
00121         ms_processors(bool checkLinuxHT, int numLicensed);
00122 
00124         ms_processors(const ms_processors& src);
00125 
00127         ~ms_processors();
00128 
00130         void defaultValues();
00131 
00133         void copyFrom(const ms_processors* right);
00134 
00135 #ifndef SWIG
00136 
00137         ms_processors& operator=(const ms_processors& right);
00138 #endif
00139 
00140         int getNumOnSystem() const;
00141 
00143         int getNumAvailableToProcess() const;
00144 
00146         bool isProcessAffinitySupported() const;
00147 
00149         bool isUseProcessesNotThreads() const;
00150 
00152         UINT64 getWhichAvailableForMascot() const;
00153 
00155         std::vector<int> getWhichAvailableForMascot2();
00156 
00158         bool isLogicalCPUAvailableForMascot(const int cpu) const;
00159 
00161         int getNumPhysicalOnSystem() const;
00162 
00164         HYPERTHREADING getHyperThreadingState() const;
00165 
00167         int getNumLogicalPerPhysical() const;
00168 
00170         int getNumCores(const int cpu = -1) const;
00171 
00173         int getPhysicalFromLogical(const int cpu) const;
00174 
00176         std::string getProcessorName() const;
00177 
00179         std::string getMultithreadedName() const;
00180 
00182         UINT64 getHyperThreadedCPUsMask() const; 
00183 
00185         bool isPrimaryLogicalProcessor(const int cpu) const;
00186 
00188         bool isThreadedLogicalProcessor(const int cpu) const;
00189 
00191         int getCoreFromLogical(const int cpu) const;
00192 
00194         int getHT_IDFromLogical(const int cpu) const;
00195 
00197         int getAutoDetectNumThreads(const int numLicensed) const;
00198 
00199         unsigned char GetAPIC_ID(unsigned char & logical_id,
00200                                  unsigned char & physical_id,
00201                                  unsigned char & core_id,
00202                                  unsigned char & ht_id);
00203 
00204 #ifndef _WIN32
00205         static bool getAffinityForCpu(std::vector<unsigned int> & vecCpu, const int pid = 0);
00206         static bool setAffinityForCpu(const std::vector<unsigned int> & vecCpu, const int pid = 0);        
00207 #endif
00208 
00209     private:
00210         void getIntelHyperThreadingInfo();
00211 
00212         typedef std::map<int, ms_cpuinfo> cpuInfo_t;
00213         cpuInfo_t       cpuInfo_;
00214         bool            usingINT64values_;        // Temporary kludge. Remove when always false;
00215         int             numOnSystem_;             // logical number of processors
00216         int             physicalNumOnSystem_;     // phyiscal number of processors
00217         int             numAvailableToProcess_;
00218         bool            processAffinitySupported_;
00219         bool            useProcessesNotThreads_;
00220         UINT64          whichAvailableForMascot_;
00221         HYPERTHREADING  hyperThreading_;
00222         int             numLogicalPerPhysical_;
00223         cpu_id_t        logicalToPhysical_;       // Note that the physical ID 
00224                                                   // stored in this array has 
00225                                                   // no real significance - it
00226                                                   // is just a number. To use
00227                                                   // it, need to see if one or
00228                                                   // more logical ID's have the
00229                                                   // same physical ID.
00230         UINT64          hyperThreadedCPUs_;       // Bit mask for hyperthreaded
00231         int             numLicensed_;
00232         bool            checkLinuxHT_;
00233         std::string     processorName_;           // e.g. "Intel", "AMD Opteron", "Power 5"
00234         std::string     multiThreadName_;         // e.g. "Hyper-threading", "Dual Core", "SMT"
00235         int             coresPerCpu_;
00236         bool            isIntelProcessor_;
00237         bool            multiCoreOrHTcapable_;    // Intel/AMD only. Corresponds to HT bit set.
00238 
00239         void checkProcessorsAvailable();
00240         unsigned findIntelMaskWidth(unsigned Max_Count) const;
00241         unsigned char findIntelIdFromAPIC(const unsigned char apic, 
00242                                           const unsigned char maxSubIdValue,
00243                                           const unsigned char shiftCount) const;
00244 
00245         void SMTOnPower5();
00246         bool setLogicalToPhysicalWithoutAffinity(bool & foundAnyNonZeroLogical);
00247         bool setLogicalToPhysicalUsingAffinity(bool & foundAnyNonZeroLogical);
00248         void getSolarisInfo();
00249 #ifdef __SUNOS__
00250         int ms_processors::getKstatDataAsInt(kstat_named_t *knp) const;
00251 #endif
00252 
00253 #if defined(__LINUX__) || defined(__LINUX64__)
00254     public:
00255         typedef std::vector<unsigned char> cpu_apic_list_t;
00256         cpu_apic_list_t  linuxApic_;
00257         pthread_mutex_t  mutex_;
00258         bool             ht_linux_detected_;
00259 
00260 #endif
00261 
00262            
00263     }; // class ms_processors // end of config_group
00265 } // namespace matrix_science
00266 
00267 #endif // MS_PROCESSORS_HPP
00268 
00269 /*------------------------------- End of File -------------------------------*/
00270 
Copyright © 2016 Matrix Science Ltd.  All Rights Reserved. Generated on Fri Jun 2 2017 01:44:51