CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_8_patch3/src/FWCore/Utilities/interface/MallocOpts.h

Go to the documentation of this file.
00001 #ifndef MallocOpts_h
00002 #define MallocOpts_h
00003 
00004 // -*- C++ -*-
00005 //
00006 // Package:     Utilities
00007 // Class  :     MallocOpts
00008 // 
00009 // Original Author:  Jim Kowalkowski
00010 // $Id: MallocOpts.h,v 1.1 2007/12/20 19:36:47 jbk Exp $
00011 //
00012 // ------------------ malloc option setter -----------------------
00013 //
00014 // There is a global instance of MallocOptionSetter.  Upon construction,
00015 // it gets the CPU type.  If is it AMD or Intel, it sets the mallopt
00016 // parameters to a set that works best for that environment.  The best
00017 // values have been chosen based on running a simple cmsRun job.
00018 //
00019 // The four values that get reset are:
00020 //   M_MMAP_MAX, M_TRIM_THRESHOLD, M_TOP_PAD, M_MMAP_THRESHOLD
00021 //
00022 // Current the best AMD and Intel values were calculated using:
00023 //   AMD Opteron(tm) Processor 248
00024 //   Intel Dual Core something or other
00025 //
00026 // These values will need to be checked when new CPUs are available or
00027 // when we move to 64 bit executables.
00028 
00029 #include <string>
00030 #include <ostream>
00031 
00032 namespace edm
00033 {
00034   struct MallocOpts
00035   {
00036     typedef int opt_type;
00037     
00038     MallocOpts():
00039       mmap_max_(),trim_thr_(),top_pad_(),mmap_thr_()
00040     {}
00041     MallocOpts(opt_type max,opt_type trim,opt_type pad,opt_type mmap_thr):
00042       mmap_max_(max),trim_thr_(trim),top_pad_(pad),mmap_thr_(mmap_thr)
00043     {}
00044     
00045     opt_type mmap_max_;
00046     opt_type trim_thr_;
00047     opt_type top_pad_;
00048     opt_type mmap_thr_;
00049 
00050     bool operator==(const MallocOpts& opts) const 
00051     {
00052       return
00053         mmap_max_ == opts.mmap_max_ && 
00054         trim_thr_ == opts.trim_thr_ && 
00055         top_pad_ == opts.top_pad_ &&
00056         mmap_thr_ == opts.mmap_thr_;
00057     }
00058     bool operator!=(const MallocOpts& opts) const
00059     { return !operator==(opts); }
00060   };
00061 
00062   std::ostream& operator<<(std::ostream& ost,const MallocOpts&);
00063 
00064   class MallocOptionSetter
00065   {
00066   public:
00067     typedef MallocOpts::opt_type opt_type;
00068     MallocOptionSetter();
00069 
00070     bool retrieveFromCpuType(); 
00071     bool retrieveFromEnv();
00072     void adjustMallocParams();
00073     bool hasErrors() const { return !error_message_.empty(); }
00074     std::string error_message() const { return error_message_; }
00075 
00076     void set_mmap_max(opt_type mmap_max)
00077     { values_.mmap_max_=mmap_max; changed_=true; }
00078     void set_trim_thr(opt_type trim_thr)
00079     { values_.trim_thr_=trim_thr; changed_=true; }
00080     void set_top_pad(opt_type top_pad)
00081     { values_.top_pad_=top_pad; changed_=true; }
00082     void set_mmap_thr(opt_type mmap_thr)
00083     { values_.mmap_thr_=mmap_thr; changed_=true; }
00084 
00085     MallocOpts get() const { return values_; }
00086 
00087   private:
00088     bool changed_;
00089     MallocOpts values_;
00090 
00091     std::string error_message_;
00092   };
00093 
00094   MallocOptionSetter& getGlobalOptionSetter();
00095 
00096 }
00097 
00098 
00099 
00100 #endif