mirror of
https://github.com/CalcProgrammer1/OpenRGB.git
synced 2025-12-23 23:37:48 -05:00
Reduce CPU usage when accessing i2c smbus devices on windows (AMD)
This commit is contained in:
@@ -9,9 +9,37 @@
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "i2c_smbus_piix4.h"
|
||||
#include <Windows.h>
|
||||
#include "inpout32.h"
|
||||
#include "LogManager.h"
|
||||
#include "ResourceManager.h"
|
||||
|
||||
i2c_smbus_piix4::i2c_smbus_piix4()
|
||||
{
|
||||
json drivers_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("Drivers");
|
||||
bool amd_smbus_reduce_cpu = false;
|
||||
|
||||
if(drivers_settings.contains("amd_smbus_reduce_cpu"))
|
||||
{
|
||||
amd_smbus_reduce_cpu = drivers_settings["amd_smbus_reduce_cpu"].get<bool>();
|
||||
}
|
||||
|
||||
if(amd_smbus_reduce_cpu)
|
||||
{
|
||||
delay_timer = CreateWaitableTimerExW(NULL, NULL, CREATE_WAITABLE_TIMER_MANUAL_RESET | CREATE_WAITABLE_TIMER_HIGH_RESOLUTION, TIMER_ALL_ACCESS);
|
||||
if(!delay_timer) // high resolution timer not supported
|
||||
{
|
||||
delay_timer = CreateWaitableTimer(NULL, TRUE, NULL); // create regular timer instead
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
i2c_smbus_piix4::~i2c_smbus_piix4()
|
||||
{
|
||||
if(delay_timer)
|
||||
{
|
||||
CloseHandle(delay_timer);
|
||||
}
|
||||
}
|
||||
|
||||
//Logic adapted from piix4_transaction() in i2c-piix4.c
|
||||
int i2c_smbus_piix4::piix4_transaction()
|
||||
@@ -41,11 +69,29 @@ int i2c_smbus_piix4::piix4_transaction()
|
||||
|
||||
/* We will always wait for a fraction of a second! (See PIIX4 docs errata) */
|
||||
temp = 0;
|
||||
while ((++timeout < MAX_TIMEOUT) && temp <= 1)
|
||||
if(delay_timer)
|
||||
{
|
||||
temp = Inp32(SMBHSTSTS);
|
||||
}
|
||||
LARGE_INTEGER retry_delay;
|
||||
retry_delay.QuadPart = -2500;
|
||||
|
||||
SetWaitableTimer(delay_timer, &retry_delay, 0, NULL, NULL, FALSE);
|
||||
WaitForSingleObject(delay_timer, INFINITE);
|
||||
|
||||
|
||||
while ((++timeout < MAX_TIMEOUT) && temp <= 1)
|
||||
{
|
||||
temp = Inp32(SMBHSTSTS);
|
||||
SetWaitableTimer(delay_timer, &retry_delay, 0, NULL, NULL, FALSE);
|
||||
WaitForSingleObject(delay_timer, INFINITE);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while ((++timeout < MAX_TIMEOUT) && temp <= 1)
|
||||
{
|
||||
temp = Inp32(SMBHSTSTS);
|
||||
}
|
||||
}
|
||||
/* If the SMBus is still busy, we give up */
|
||||
if (timeout == MAX_TIMEOUT)
|
||||
{
|
||||
@@ -144,7 +190,7 @@ s32 i2c_smbus_piix4::piix4_access(u16 addr, char read_write, u8 command, int siz
|
||||
if (status)
|
||||
return status;
|
||||
|
||||
if ((read_write == I2C_SMBUS_WRITE) || (size == PIIX4_QUICK))
|
||||
if ((read_write == I2C_SMBUS_WRITE) || (size == PIIX4_QUICK))
|
||||
return 0;
|
||||
|
||||
switch (size)
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "i2c_smbus.h"
|
||||
#include "windows.h"
|
||||
|
||||
#pragma once
|
||||
|
||||
@@ -40,10 +41,13 @@ class i2c_smbus_piix4 : public i2c_smbus_interface
|
||||
{
|
||||
public:
|
||||
u16 piix4_smba = 0x0B00;
|
||||
i2c_smbus_piix4();
|
||||
~i2c_smbus_piix4();
|
||||
|
||||
private:
|
||||
int piix4_transaction();
|
||||
s32 piix4_access(u16 addr, char read_write, u8 command, int size, i2c_smbus_data *data);
|
||||
s32 i2c_smbus_xfer(u8 addr, char read_write, u8 command, int size, i2c_smbus_data* data);
|
||||
s32 i2c_xfer(u8 addr, char read_write, int* size, u8* data);
|
||||
};
|
||||
HANDLE delay_timer;
|
||||
};
|
||||
|
||||
@@ -82,6 +82,21 @@ OpenRGBSettingsPage::OpenRGBSettingsPage(QWidget *parent) :
|
||||
ui->CheckboxLogConsole->setChecked(log_manager_settings["log_console"]);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Load drivers settings (Windows only) |
|
||||
\*---------------------------------------------------------*/
|
||||
#ifdef _WIN32
|
||||
json drivers_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("Drivers");
|
||||
|
||||
if(drivers_settings.contains("amd_smbus_reduce_cpu"))
|
||||
{
|
||||
ui->CheckboxAMDSMBusReduceCPU->setChecked(drivers_settings["amd_smbus_reduce_cpu"]);
|
||||
}
|
||||
#else
|
||||
ui->DriversSettingsLabel->hide();
|
||||
ui->CheckboxAMDSMBusReduceCPU->hide();
|
||||
#endif
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Load AutoStart settings |
|
||||
\*---------------------------------------------------------*/
|
||||
@@ -530,3 +545,11 @@ void Ui::OpenRGBSettingsPage::on_CheckboxLogConsole_clicked()
|
||||
SaveSettings();
|
||||
}
|
||||
|
||||
void Ui::OpenRGBSettingsPage::on_CheckboxAMDSMBusReduceCPU_clicked()
|
||||
{
|
||||
json drivers_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("Drivers");
|
||||
drivers_settings["amd_smbus_reduce_cpu"] = ui->CheckboxAMDSMBusReduceCPU->isChecked();
|
||||
ResourceManager::get()->GetSettingsManager()->SetSettings("Drivers", drivers_settings);
|
||||
SaveSettings();
|
||||
}
|
||||
|
||||
|
||||
@@ -50,6 +50,7 @@ private slots:
|
||||
void on_CheckboxRunZoneChecks_clicked();
|
||||
void on_OpenSettingsFolderButton_clicked();
|
||||
void on_CheckboxLogConsole_clicked();
|
||||
void on_CheckboxAMDSMBusReduceCPU_clicked();
|
||||
};
|
||||
|
||||
#endif // OPENRGBSETTINGSPAGE_H
|
||||
|
||||
@@ -24,41 +24,12 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>398</width>
|
||||
<height>554</height>
|
||||
<width>418</width>
|
||||
<height>464</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<item row="22" column="0">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::MinimumExpanding</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="20" column="1">
|
||||
<widget class="QComboBox" name="ComboBoxAutoStartProfile"/>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<widget class="QCheckBox" name="CheckboxLoadGeometry">
|
||||
<property name="text">
|
||||
<string>Load Window Geometry</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QComboBox" name="ComboBoxTheme"/>
|
||||
</item>
|
||||
<item row="17" column="1">
|
||||
<item row="19" column="1">
|
||||
<widget class="QLineEdit" name="TextServerPort">
|
||||
<property name="inputMask">
|
||||
<string>90000</string>
|
||||
@@ -71,33 +42,40 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="0">
|
||||
<widget class="QCheckBox" name="CheckboxRunZoneChecks">
|
||||
<item row="20" column="0">
|
||||
<widget class="QCheckBox" name="CheckboxAutoStartClient">
|
||||
<property name="text">
|
||||
<string>Run zone checks on rescan</string>
|
||||
<string>Start Client</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="16" column="0">
|
||||
<widget class="QCheckBox" name="CheckboxAutoStartServer">
|
||||
<item row="10" column="0">
|
||||
<widget class="QLabel" name="DriversSettingsLabel">
|
||||
<property name="text">
|
||||
<string>Start Server</string>
|
||||
<string>Drivers Settings</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="18" column="1">
|
||||
<item row="23" column="0">
|
||||
<widget class="QLabel" name="AutoStartStatusLabel">
|
||||
<property name="text">
|
||||
<string>Start at Login Status</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="20" column="1">
|
||||
<widget class="QLineEdit" name="TextClientHost"/>
|
||||
</item>
|
||||
<item row="19" column="1">
|
||||
<widget class="QLineEdit" name="TextCustomArgs"/>
|
||||
</item>
|
||||
<item row="15" column="0">
|
||||
<widget class="QCheckBox" name="CheckboxAutoStartMinimized">
|
||||
<item row="19" column="0">
|
||||
<widget class="QCheckBox" name="CheckboxAutoStartSetServerPort">
|
||||
<property name="text">
|
||||
<string>Start Minimized</string>
|
||||
<string>Set Server Port</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="21" column="1">
|
||||
<widget class="QLineEdit" name="TextCustomArgs"/>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="UserInterfaceSettingsLabel">
|
||||
<property name="text">
|
||||
@@ -105,13 +83,6 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="11" column="0">
|
||||
<widget class="QCheckBox" name="CheckboxAutoStart">
|
||||
<property name="text">
|
||||
<string>Start At Login</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QCheckBox" name="CheckboxMinimizeOnClose">
|
||||
<property name="text">
|
||||
@@ -126,42 +97,35 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="18" column="0">
|
||||
<widget class="QCheckBox" name="CheckboxAutoStartClient">
|
||||
<item row="13" column="0">
|
||||
<widget class="QCheckBox" name="CheckboxAutoStart">
|
||||
<property name="text">
|
||||
<string>Start Client</string>
|
||||
<string>Start At Login</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="20" column="0">
|
||||
<item row="22" column="0">
|
||||
<widget class="QCheckBox" name="CheckboxAutoStartProfile">
|
||||
<property name="text">
|
||||
<string>Load Profile</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="17" column="0">
|
||||
<widget class="QCheckBox" name="CheckboxAutoStartSetServerPort">
|
||||
<item row="18" column="0">
|
||||
<widget class="QCheckBox" name="CheckboxAutoStartServer">
|
||||
<property name="text">
|
||||
<string>Set Server Port</string>
|
||||
<string>Start Server</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="ThemeLabel">
|
||||
<item row="12" column="0">
|
||||
<widget class="QLabel" name="AutoStartLabel">
|
||||
<property name="text">
|
||||
<string>Theme (restart required)</string>
|
||||
<string>Start At Login Settings:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="9" column="0">
|
||||
<widget class="QCheckBox" name="CheckboxLogConsole">
|
||||
<property name="text">
|
||||
<string>Enable Log Console (restart required)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="19" column="0">
|
||||
<item row="21" column="0">
|
||||
<widget class="QCheckBox" name="CheckboxAutoStartCustom">
|
||||
<property name="text">
|
||||
<string>Custom Arguments</string>
|
||||
@@ -175,17 +139,67 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="21" column="0">
|
||||
<widget class="QLabel" name="AutoStartStatusLabel">
|
||||
<item row="17" column="0">
|
||||
<widget class="QCheckBox" name="CheckboxAutoStartMinimized">
|
||||
<property name="text">
|
||||
<string>Start at Login Status</string>
|
||||
<string>Start Minimized</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="10" column="0">
|
||||
<widget class="QLabel" name="AutoStartLabel">
|
||||
<item row="24" column="0">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::MinimumExpanding</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QComboBox" name="ComboBoxTheme"/>
|
||||
</item>
|
||||
<item row="7" column="0">
|
||||
<widget class="QCheckBox" name="CheckboxRunZoneChecks">
|
||||
<property name="text">
|
||||
<string>Start At Login Settings:</string>
|
||||
<string>Run zone checks on rescan</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="9" column="0">
|
||||
<widget class="QCheckBox" name="CheckboxLogConsole">
|
||||
<property name="text">
|
||||
<string>Enable Log Console (restart required)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="ThemeLabel">
|
||||
<property name="text">
|
||||
<string>Theme (restart required)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<widget class="QCheckBox" name="CheckboxLoadGeometry">
|
||||
<property name="text">
|
||||
<string>Load Window Geometry</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="22" column="1">
|
||||
<widget class="QComboBox" name="ComboBoxAutoStartProfile"/>
|
||||
</item>
|
||||
<item row="11" column="0">
|
||||
<widget class="QCheckBox" name="CheckboxAMDSMBusReduceCPU">
|
||||
<property name="text">
|
||||
<string>AMD SMBus: Reduce CPU Usage (restart required)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
Reference in New Issue
Block a user