Skip to content

Commit e5227db

Browse files
committed
Set efficiency mode by default
Set the lowest priority and EcoQoS to SimpleCom process. Please specify --disable-efficiency-mode if you face performance issue. See following URL for more details of efficiency mode: https://devblogs.microsoft.com/performance-diagnostics/reduce-process-interference-with-task-manager-efficiency-mode/
1 parent 4fe771a commit e5227db

File tree

6 files changed

+36
-7
lines changed

6 files changed

+36
-7
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Console app for serial connection.
4343
| `--log-file [logfile]` | <none> | Log serial communication to file |
4444
| `--stdin-logging` | false | Enable stdin logging<br><br>⚠️Possible to be logged each chars duplicately due to echo back from the console when this option is set, and also secrets (e.g. passphrase) typed into the console will be logged even if it is not shown on the console. |
4545
| `--batch` | false | Perform in batch mode<br><br>⚠️You have to set serial port in command line arguments, and you cannot set with `--show-dialog`, `--tty-resizer`, `--auto-reconnect`, `--log-file`. |
46+
| `--disable-efficiency-mode` | false | Disable [Efficiency Mode](https://devblogs.microsoft.com/performance-diagnostics/reduce-process-interference-with-task-manager-efficiency-mode/). Specify this option if you have performance issue in SimpleCom. This option cannot be set on setup dialog. |
4647
| `--help` | - | Show help message |
4748

4849
# How to build

SimpleCom/SerialSetup.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ SimpleCom::SerialSetup::SerialSetup() :
150150
_options[_T("--log-file")] = new CommandlineOption<LPTSTR>(_T("[logfile]"), _T("Log serial communication to file"), nullptr);
151151
_options[_T("--stdin-logging")] = new CommandlineOption<bool>(_T(""), _T("Enable stdin logging"), false);
152152
_options[_T("--batch")] = new CommandlineOption<bool>(_T(""), _T("Perform in batch mode"), false);
153+
_options[_T("--disable-efficiency-mode")] = new CommandlineOption<bool>(_T(""), _T("Disable efficiency mode"), false);
153154
_options[_T("--help")] = new CommandlineHelpOption(&_options);
154155
}
155156

SimpleCom/SerialSetup.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,14 @@ namespace SimpleCom {
211211
return static_cast<CommandlineOption<bool>*>(_options[_T("--batch")])->get();
212212
}
213213

214+
inline void DisableEfficiencyMode(bool disable) {
215+
static_cast<CommandlineOption<bool>*>(_options[_T("--disable-efficiency-mode")])->set(disable);
216+
}
217+
218+
inline bool IsEfficiencyMode() {
219+
return !static_cast<CommandlineOption<bool>*>(_options[_T("--disable-efficiency-mode")])->get();
220+
}
221+
214222
inline SerialDeviceScanner& GetDeviceScanner() {
215223
return _scanner;
216224
}

SimpleCom/SimpleCom.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,31 @@ static int DoBatchMode(TString& device, DCB* dcb) {
9090
return 0;
9191
}
9292

93+
// https://devblogs.microsoft.com/performance-diagnostics/reduce-process-interference-with-task-manager-efficiency-mode/
94+
static void SetEfficiencyMode() {
95+
HANDLE hProc = GetCurrentProcess();
96+
97+
// a) reduces process base priority to low
98+
SetPriorityClass(hProc, IDLE_PRIORITY_CLASS);
99+
100+
// b) sets QoS mode to EcoQoS.
101+
PROCESS_POWER_THROTTLING_STATE PowerThrottling = {
102+
.Version = PROCESS_POWER_THROTTLING_CURRENT_VERSION,
103+
.ControlMask = PROCESS_POWER_THROTTLING_EXECUTION_SPEED,
104+
.StateMask = PROCESS_POWER_THROTTLING_EXECUTION_SPEED
105+
};
106+
CALL_WINAPI_WITH_DEBUGLOG(SetProcessInformation(hProc, ProcessPowerThrottling, &PowerThrottling, sizeof(PowerThrottling)), TRUE, __FILE__, __LINE__);
107+
}
108+
93109
int _tmain(int argc, LPCTSTR argv[])
94110
{
95111
DCB dcb;
96112
TString device;
97113
HWND parent_hwnd = GetParentWindow();
98114
SimpleCom::SerialSetup setup;
99115

100-
// Serial port configuration
101116
try {
117+
// Serial port configuration
102118
if (argc > 1) {
103119
// command line mode
104120
setup.ParseArguments(argc, argv);
@@ -108,6 +124,10 @@ int _tmain(int argc, LPCTSTR argv[])
108124
setup.SetShowDialog(true);
109125
}
110126

127+
if (setup.IsEfficiencyMode()) {
128+
SetEfficiencyMode();
129+
}
130+
111131
if (setup.GetWaitDevicePeriod() > 0) {
112132
setup.GetDeviceScanner().SetTargetPort(setup.GetPort());
113133
setup.GetDeviceScanner().WaitSerialDevices(parent_hwnd, setup.GetWaitDevicePeriod());

SimpleCom/app.manifest

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,12 @@
33
<assemblyIdentity version="1.2.6.0" name="SimpleCom.exe" />
44
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
55
<application>
6-
<!-- Windows 10 -->
6+
<!-- Windows 10, 11 -->
77
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" maxversiontested="10.0.19042.868" />
88
<!-- Windows 8.1 -->
99
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />
1010
<!-- Windows 8 -->
1111
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />
12-
<!-- Windows 7 -->
13-
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />
14-
<!-- Windows Vista -->
15-
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />
1612
</application>
1713
</compatibility>
1814
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
@@ -27,4 +23,4 @@
2723
<assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*" />
2824
</dependentAssembly>
2925
</dependency>
30-
</assembly>
26+
</assembly>

SimpleComTest/SerialSetupTest.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ namespace SimpleComTest
230230
Assert::IsNull(setup.GetLogFile());
231231
Assert::AreEqual(false, setup.IsEnableStdinLogging());
232232
Assert::AreEqual(false, setup.IsBatchMode());
233+
Assert::AreEqual(true, setup.IsEfficiencyMode());
233234
}
234235

235236
TEST_METHOD(ArgParserTest)
@@ -250,6 +251,7 @@ namespace SimpleComTest
250251
_T("--auto-reconnect-timeout"), _T("20"),
251252
_T("--log-file"), _T(R"(A:\test.log)"),
252253
_T("--stdin-logging"),
254+
_T("--disable-efficiency-mode"),
253255
_T("COM100")
254256
};
255257

@@ -269,6 +271,7 @@ namespace SimpleComTest
269271
Assert::AreEqual(20, setup.GetAutoReconnectTimeoutInSec());
270272
Assert::AreEqual(_T(R"(A:\test.log)"), setup.GetLogFile());
271273
Assert::AreEqual(true, setup.IsEnableStdinLogging());
274+
Assert::AreEqual(false, setup.IsEfficiencyMode());
272275
Assert::AreEqual(_T("COM100"), setup.GetPort().c_str());
273276
}
274277

0 commit comments

Comments
 (0)