Modify affinity range config format for Windows
[platform/upstream/coreclr.git] / src / gc / gcconfig.h
1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
4
5 #ifndef __GCCONFIG_H__
6 #define __GCCONFIG_H__
7
8 // gcconfig.h - GC configuration management and retrieval.
9 //
10 // This file and the GCConfig class are designed to be the primary entry point
11 // for querying configuration information from within the GC.
12
13 // GCConfigStringHolder is a wrapper around a configuration string obtained
14 // from the EE. Such strings must be disposed using GCToEEInterface::FreeStringConfigValue,
15 // so this class ensures that is done correctly.
16 //
17 // The name is unfortunately a little long, but "ConfigStringHolder" is already taken by the
18 // EE's config mechanism.
19 class GCConfigStringHolder
20 {
21 private:
22     const char* m_str;
23
24 public:
25     // Constructs a new GCConfigStringHolder around a string obtained from
26     // GCToEEInterface::GetStringConfigValue.
27     explicit GCConfigStringHolder(const char* str)
28       : m_str(str) {}
29
30     // No copy operators - this type cannot be copied.
31     GCConfigStringHolder(const GCConfigStringHolder&) = delete;
32     GCConfigStringHolder& operator=(const GCConfigStringHolder&) = delete;
33
34     // This type is returned by-value by string config functions, so it
35     // requires a move constructor.
36     GCConfigStringHolder(GCConfigStringHolder&&) = default;
37
38     // Frees a string config value by delegating to GCToEEInterface::FreeStringConfigValue.
39     ~GCConfigStringHolder()
40     {
41         if (m_str)
42         {
43             GCToEEInterface::FreeStringConfigValue(m_str);
44         }
45
46         m_str = nullptr;
47     }
48
49     // Retrieves the wrapped config string.
50     const char* Get() const { return m_str; }
51 };
52
53 // Each one of these keys produces a method on GCConfig with the name "Get{name}", where {name}
54 // is the first parameter of the *_CONFIG macros below.
55 #define GC_CONFIGURATION_KEYS \
56   BOOL_CONFIG(ServerGC,     "gcServer",     false, "Whether we should be using Server GC")     \
57   BOOL_CONFIG(ConcurrentGC, "gcConcurrent", true,  "Whether we should be using Concurrent GC") \
58   BOOL_CONFIG(ConservativeGC, "gcConservative", false, "Enables/Disables conservative GC")     \
59   BOOL_CONFIG(ForceCompact, "gcForceCompact", false,                                           \
60       "When set to true, always do compacting GC")                                             \
61   BOOL_CONFIG(RetainVM,     "GCRetainVM",   false,                                             \
62       "When set we put the segments that should be deleted on a standby list (instead of "     \
63       "releasing them back to the OS) which will be considered to satisfy new segment requests"\
64      " (note that the same thing can be specified via API which is the supported way)")        \
65   BOOL_CONFIG(StressMix,    "GCStressMix",  false,                                             \
66       "Specifies whether the GC mix mode is enabled or not")                                   \
67   BOOL_CONFIG(BreakOnOOM,   "GCBreakOnOOM", false,                                             \
68       "Does a DebugBreak at the soonest time we detect an OOM")                                \
69   BOOL_CONFIG(NoAffinitize, "GCNoAffinitize", false,                                           \
70       "If set, do not affinitize server GC threads")                                           \
71   BOOL_CONFIG(LogEnabled,   "GCLogEnabled", false,                                             \
72       "Specifies if you want to turn on logging in GC")                                        \
73   BOOL_CONFIG(ConfigLogEnabled, "GCConfigLogEnabled", false,                                   \
74       "Specifies the name of the GC config log file")                                          \
75   BOOL_CONFIG(GCNumaAware,   "GCNumaAware", true, "Enables numa allocations in the GC")        \
76   BOOL_CONFIG(GCCpuGroup,    "GCCpuGroup", false, "Enables CPU groups in the GC")              \
77   INT_CONFIG(HeapVerifyLevel, "HeapVerify", HEAPVERIFY_NONE,                                   \
78       "When set verifies the integrity of the managed heap on entry and exit of each GC")      \
79   INT_CONFIG(LOHCompactionMode, "GCLOHCompact", 0, "Specifies the LOH compaction mode")        \
80   INT_CONFIG(LOHThreshold, "GCLOHThreshold", LARGE_OBJECT_SIZE,                                \
81       "Specifies the size that will make objects go on LOH")                                   \
82   INT_CONFIG(BGCSpinCount,  "BGCSpinCount", 140, "Specifies the bgc spin count")               \
83   INT_CONFIG(BGCSpin,       "BGCSpin",      2,   "Specifies the bgc spin time")                \
84   INT_CONFIG(HeapCount,     "GCHeapCount",  0,   "Specifies the number of server GC heaps")    \
85   INT_CONFIG(Gen0Size,      "GCgen0size",   0, "Specifies the smallest gen0 size")             \
86   INT_CONFIG(SegmentSize,   "GCSegmentSize", 0, "Specifies the managed heap segment size")     \
87   INT_CONFIG(LatencyMode,   "GCLatencyMode", -1,                                               \
88       "Specifies the GC latency mode - batch, interactive or low latency (note that the same " \
89       "thing can be specified via API which is the supported way")                             \
90   INT_CONFIG(LatencyLevel,  "GCLatencyLevel", 1,                                               \
91       "Specifies the GC latency level that you want to optimize for. Must be a number from 0"  \
92       "3. See documentation for more details on each level.")                                  \
93   INT_CONFIG(LogFileSize,   "GCLogFileSize", 0, "Specifies the GC log file size")              \
94   INT_CONFIG(CompactRatio,  "GCCompactRatio", 0,                                               \
95       "Specifies the ratio compacting GCs vs sweeping")                                        \
96   INT_CONFIG(GCHeapAffinitizeMask, "GCHeapAffinitizeMask", 0,                                  \
97       "Specifies processor mask for Server GC threads")                                        \
98   STRING_CONFIG(GCHeapAffinitizeRanges, "GCHeapAffinitizeRanges",                              \
99       "Specifies list of processors for Server GC threads. The format is a comma separated "   \
100       "list of processor numbers or ranges of processor numbers. On Windows, each entry is "   \
101       "prefixed by the CPU group number. Example: Unix - 1,3,5,7-9,12, Windows - 0:1,1:7-9")   \
102   INT_CONFIG(GCHighMemPercent, "GCHighMemPercent", 0,                                          \
103       "The percent for GC to consider as high memory")                                         \
104   INT_CONFIG(GCProvModeStress, "GCProvModeStress", 0,                                          \
105       "Stress the provisional modes")                                                          \
106   INT_CONFIG(GCGen0MaxBudget, "GCGen0MaxBudget", 0,                                            \
107       "Specifies the largest gen0 allocation budget")                                          \
108   INT_CONFIG(GCHeapHardLimit, "GCHeapHardLimit", 0,                                            \
109       "Specifies a hard limit for the GC heap")                                                \
110   INT_CONFIG(GCHeapHardLimitPercent, "GCHeapHardLimitPercent", 0,                              \
111       "Specifies the GC heap usage as a percentage of the total memory")                       \
112   STRING_CONFIG(LogFile,    "GCLogFile",    "Specifies the name of the GC log file")           \
113   STRING_CONFIG(ConfigLogFile, "GCConfigLogFile",                                              \
114       "Specifies the name of the GC config log file")                                          \
115   STRING_CONFIG(MixLogFile, "GCMixLog",                                                        \
116       "Specifies the name of the log file for GC mix statistics")
117
118 // This class is responsible for retreiving configuration information
119 // for how the GC should operate.
120 class GCConfig
121 {
122 #define BOOL_CONFIG(name, unused_key, unused_default, unused_doc) \
123   public: static bool Get##name();                                \
124   private: static bool s_##name;
125 #define INT_CONFIG(name, unused_key, unused_default, unused_doc) \
126   public: static int64_t Get##name();                            \
127   private: static int64_t s_##name;
128 #define STRING_CONFIG(name, unused_key, unused_doc) \
129   public: static GCConfigStringHolder Get##name();
130 GC_CONFIGURATION_KEYS
131 #undef BOOL_CONFIG
132 #undef INT_CONFIG
133 #undef STRING_CONFIG
134
135 public:
136 // Flags that may inhabit the number returned for the HeapVerifyLevel config option.
137 // Keep this in sync with vm\eeconfig.h if this ever changes.
138 enum HeapVerifyFlags {
139     HEAPVERIFY_NONE             = 0,
140     HEAPVERIFY_GC               = 1,   // Verify the heap at beginning and end of GC
141     HEAPVERIFY_BARRIERCHECK     = 2,   // Verify the brick table
142     HEAPVERIFY_SYNCBLK          = 4,   // Verify sync block scanning
143
144     // the following options can be used to mitigate some of the overhead introduced
145     // by heap verification.  some options might cause heap verifiction to be less
146     // effective depending on the scenario.
147
148     HEAPVERIFY_NO_RANGE_CHECKS  = 0x10,   // Excludes checking if an OBJECTREF is within the bounds of the managed heap
149     HEAPVERIFY_NO_MEM_FILL      = 0x20,   // Excludes filling unused segment portions with fill pattern
150     HEAPVERIFY_POST_GC_ONLY     = 0x40,   // Performs heap verification post-GCs only (instead of before and after each GC)
151     HEAPVERIFY_DEEP_ON_COMPACT  = 0x80    // Performs deep object verfication only on compacting GCs.
152 };
153
154 // Initializes the GCConfig subsystem. Must be called before accessing any
155 // configuration information.
156 static void Initialize();
157
158 };
159
160 bool ParseGCHeapAffinitizeRanges(const char* cpu_index_ranges, AffinitySet* config_affinity_set);
161
162 #endif // __GCCONFIG_H__