Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent precise timers from being used when unnecessary #18555

Merged
merged 1 commit into from Feb 14, 2023

Conversation

glassez
Copy link
Member

@glassez glassez commented Feb 13, 2023

The implementation of QTimer::singleShot() uses Qt::PreciseTimer if interval is less than 2 seconds. This isn't mentioned in the docs.
Qt::PreciseTimer increases the system's timer resolution which negatively affects power consumption.

Closes #18350.
Supercedes #18475.

@glassez glassez added the Core label Feb 13, 2023
@glassez glassez added this to the 4.6.0 milestone Feb 13, 2023
@glassez glassez marked this pull request as ready for review February 13, 2023 06:32
@glassez glassez requested a review from a team February 13, 2023 06:32
@sledgehammer999
Copy link
Member

Maybe add something like this in the commit message?

The implementation of QTimer::singleShot() uses Qt::PreciseTimer if interval is less than 2 seconds. This isn't mentioned in the docs.
Qt::PreciseTimer increases the system's timer resolution which negatively affects power consumption.

Just to have enough context for the future.

@glassez
Copy link
Member Author

glassez commented Feb 13, 2023

Maybe add something like this in the commit message?

The implementation of QTimer::singleShot() uses Qt::PreciseTimer if interval is less than 2 seconds. This isn't mentioned in the docs.
Qt::PreciseTimer increases the system's timer resolution which negatively affects power consumption.

Just to have enough context for the future.

OK.
Added in OP.
Will add it in final commit message while merging.

@glassez glassez merged commit 7600f59 into qbittorrent:master Feb 14, 2023
@glassez glassez deleted the timer-type branch February 14, 2023 05:26
c0re100 pushed a commit to c0re100/qBittorrent-Enhanced-Edition that referenced this pull request Feb 16, 2023
The implementation of QTimer::singleShot() uses Qt::PreciseTimer if interval is less than 2 seconds. This isn't mentioned in the docs.
Qt::PreciseTimer increases the system's timer resolution which negatively affects power consumption.

PR qbittorrent#18555.
Closes qbittorrent#18350.
@andry81
Copy link

andry81 commented Feb 17, 2023

Qt::PreciseTimer increases the system's timer resolution which negatively affects power consumption.

Can you elaborate the power consumption issue and give some links?

@glassez
Copy link
Member Author

glassez commented Feb 17, 2023

Can you elaborate the power consumption issue and give some links?

You can find something in the Issue mentioned in OP.
Also there is some explanation in Qt documentation: https://doc.qt.io/qt-6/qt.html#TimerType-enum.

@andry81
Copy link

andry81 commented Feb 18, 2023

Also there is some explanation in Qt documentation: doc.qt.io/qt-6/qt.html#TimerType-enum.

On UNIX (including Linux, macOS, and iOS), Qt will keep millisecond accuracy for Qt::PreciseTimer. For Qt::CoarseTimer, the interval will be adjusted up to 5% to align the timer with other timers that are expected to fire at or around the same time. The objective is to make most timers wake up at the same time, thereby reducing CPU wakeups and power consumption.

The meaning is to adjust wake up all types of timers at the same moment of time to reduce kernel scheduler switches. It does not much related particularly to Qt::PreciseTimer and power consumption.

@sledgehammer999
Copy link
Member

The meaning is to adjust wake up all types of timers at the same moment of time to reduce kernel scheduler switches. It does not much related particularly to Qt::PreciseTimer and power consumption.

Qt::PreciseTimer forces the OS to use the smallest possible timer resolution. This results in more system wakeups than necessary. eg 1ms vs 14ms. Read the links in #18350 and the discussion thread in #18475

sledgehammer999 pushed a commit to glassez/qBittorrent that referenced this pull request Feb 19, 2023
The implementation of QTimer::singleShot() uses Qt::PreciseTimer if interval is less than 2 seconds. This isn't mentioned in the docs.
Qt::PreciseTimer increases the system's timer resolution which negatively affects power consumption.

PR qbittorrent#18555.
Closes qbittorrent#18350.
divinehawk pushed a commit to divinehawk/qBittorrent that referenced this pull request Apr 12, 2023
The implementation of QTimer::singleShot() uses Qt::PreciseTimer if interval is less than 2 seconds. This isn't mentioned in the docs.
Qt::PreciseTimer increases the system's timer resolution which negatively affects power consumption.

PR qbittorrent#18555.
Closes qbittorrent#18350.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

qBittorrent requests a timer resolution smaller than the platform maximum timer resolution
4 participants