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

macOS: disable AppNap during sync #12783

Merged
merged 1 commit into from Nov 10, 2018
Merged

Conversation

krab
Copy link
Contributor

@krab krab commented Mar 26, 2018

Code based on pull/5804. Tested only on macOS 10.13.3 and should support 10.9+.

What macOS versions bitcoin core currently supports?

@Empact
Copy link
Member

Empact commented Mar 26, 2018

#5804

@fanquake fanquake added the macOS label Mar 26, 2018
class CAppNapInhibitorInt
{
public:
id<NSObject> activityId;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a difference in using NSObject *activityId?

~(NSActivitySuddenTerminationDisabled |
NSActivityAutomaticTerminationDisabled);

if ([[NSProcessInfo processInfo] respondsToSelector:@selector(beginActivityWithOptions:reason:)])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: code styling, use brackets {}

if ([[NSProcessInfo processInfo] respondsToSelector:@selector(endActivity:)])
[[NSProcessInfo processInfo] endActivity:priv->activityId];
#endif
delete priv;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are only holding a NSObject pointer, is this deallocation really required or could it even be messing with the autorelease pool?

@jonasschnelli
Copy link
Contributor

utACK e41bb4a4568e08fe75ab8af7de7db1a2684cd989

@fanquake fanquake requested a review from theuni March 27, 2018 03:49
@Sjors
Copy link
Member

Sjors commented Mar 27, 2018

Will review later. Good question regarding which macOS version to support. The release notes state 10.8+, but I wonder how true that is. Apple pushes macOS updates quite aggressively and the lack of VM's make downgrades impractical. So unless any of the active devs here still runs an older version, I don't think it's realistic to support anything but the current macOS release and maybe one earlier version .

@jonasschnelli
Copy link
Contributor

We do currently support 10.8+ and I have VMs for all OSX versions from 10.5 upwards. I do test the RC regularly in 10.8 till 10.x VMs.

@Sjors
Copy link
Member

Sjors commented Mar 27, 2018

@jonasschnelli ok, that's great to know. Any hints for setting up a 10.8 VM on an iMac?

@laanwj
Copy link
Member

laanwj commented Mar 27, 2018

Concept ACK.
Should appnap always be disabled, or just during initial sync? It's something that could be done later, but worth thinking about I think.

@theuni
Copy link
Member

theuni commented Mar 28, 2018

I really really don't like the idea of adding a new compiler requirement for bitcoind (which is why we closed #5804).

How about using this for bitcoin-qt only ?

@Sjors
Copy link
Member

Sjors commented Mar 29, 2018

I think it's reasonable* to expect bitcoind users to understand their OS power management.

@krab
Copy link
Contributor Author

krab commented Mar 31, 2018

how to i squash all my commits in PR they contain merging commits from upstream/master 😕

@krab
Copy link
Contributor Author

krab commented Mar 31, 2018

Squashed all my commits into single one.

OS X Mountain Lion 10.8 not supported by Apple anymore. Mozilla/Google don't support 10.8 either in their web browsers.
Qt 5.7 (currently used in bitcoin-qt0.16.0) support expired in June 15, 2017.
Qt 5.8 supports only 10.9+.
Qt 5.9 only 10.10+.
So OS X 10.8 support in bitcoin-qt pretty much pointless since it requires Qt 5.6/5.7 and very old XCode to build.

@laanwj
Copy link
Member

laanwj commented Apr 7, 2018

How about using this for bitcoin-qt only ?

Would make sense to me. Would (for me) be preferable to having objective C in the core code.

I think it's reasonable* to expect bitcoind users to understand their OS power management.

Virtually no one uses bitcoind on MacOSX. For a long time, we didn't even build it, and there was about one person that requested it :)


CAppNapInhibitor::CAppNapInhibitor(const char* strReason) : d(new Private)
{
const NSActivityOptions activityOptions =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this isn't defined for < MAC_OS_X_VERSION_10_9, does it need a runtime check?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No idea, i can't setup 10.8 build vm to test code properly, so pre 10.9 support removed.

@fanquake
Copy link
Member

Started doing some testing.
Using master (979f598) I can make bitcoin-qt and Bitcoin Core (app bundle) enter app nap quite quickly just by starting and then minimising the app window.
You can check App Nap status using Activity Monitor -> Energy.

master - bitcoin-qt - nap
master - bitcoin core - nap

Using c975861, neither process seems to go into App Nap:

pr - bitcoin-qt - no nap
pr - bitcoin core - no nap

@theuni
Copy link
Member

theuni commented Apr 12, 2018

Concept ACK. What's the point of MacOSIdleInhibitor though? In #5804, CIdleInhibitor was introduced as a generic object that could used to be hold any/all platform-specific inhibitors. Here, MacOSIdleInhibitor seems to just be an extra level of indirection.

@krab
Copy link
Contributor Author

krab commented Apr 13, 2018

Well windows and linux can't lower cpu performance per application, on windows user can only change system-wide power plans. This thing pretty much only macos specific, MacOSIdleInhibitor change reverted anyways.

@@ -259,6 +263,21 @@ public Q_SLOTS:
void startThread();
};

#if defined(Q_OS_MACOS)
// A RAII wrapper around calls to forbid and re-allow entering into
// low-priority states, specifically OSX's app-nap. For the scope of
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: macOS instead of OSX

@@ -0,0 +1,19 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2018 The Bitcoin Core developers
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just use:

// Copyright (c) 2018 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

as the copyright header here

@theuni
Copy link
Member

theuni commented Apr 19, 2018

CIdleInhibitor is still there, maybe an issue with the rebase? BitcoinCore::BitcoinCore can just create a CAppNapInhibitor.

@fanquake
Copy link
Member

@krab could you now squash your commits.

@krab krab closed this May 29, 2018
@DrahtBot
Copy link
Contributor

DrahtBot commented Oct 20, 2018

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #14137 (gui: Add Windows taskbar progress by ken2812221)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@Sjors
Copy link
Member

Sjors commented Oct 23, 2018

tACK 2a14df1 on macOS 10.14 (in July I tested on 10.13)

I previously wrote:

it would be nice to disable app nap only during sync,

This works now. With the app in the background, it enters app nap after a minute or so. If however I rewind the chain a bit e.g. with invalidateblock & reconsiderblock and wait for resync, it won't enter app nap.

It does enter app nap during expensive RPC operations (invalidateblock grinds to a halt), but let's improve that some other time. Conversely, we could also make QT (or a future headless node) conserve energy better when the user is on battery.

I also wrote:

The code looks pretty complicated, which generally suggests that Apple doesn't like this.

The current solution looks much cleaner. E.g. it got rid of the undocumented plist option, and instead uses the documented NSActivityOptions. Some relevant Apple docs:

For future reference, I suggest renaming the PR to "macOS: disable AppNap during sync"

@krab krab changed the title macOS: Disable AppNap macOS: disable AppNap during sync Oct 23, 2018
@fanquake
Copy link
Member

Related upstream ticket QTBUG-43861. If we're lucky, one day Qt might expose an API for this functionality, so we don't have to ship the Objective-C ourselves.

Signed-off-by: Alexey Ivanov <alexey.ivanes@gmail.com>
@Sjors
Copy link
Member

Sjors commented Nov 2, 2018

utACK 1e0f3c4 (rebased)

@laanwj laanwj merged commit 1e0f3c4 into bitcoin:master Nov 10, 2018
laanwj added a commit that referenced this pull request Nov 10, 2018
1e0f3c4 macOS: disable AppNap during sync (Alexey Ivanov)

Pull request description:

  Code based on pull/5804. Tested only on macOS 10.13.3 and should support 10.9+.

  What macOS versions bitcoin core currently supports?

Tree-SHA512: 85809b8d8d8a05169437b4268988da0b7372c29c6da3223ebdc106dc16dcb6d3caa5c52ace3591467005b50a63fd8b2ab1cb071cb4f450032932df25d5063315
@laanwj
Copy link
Member

laanwj commented Nov 10, 2018

utACK 1e0f3c4

UdjinM6 pushed a commit to UdjinM6/dash that referenced this pull request Jul 10, 2019
1e0f3c4 macOS: disable AppNap during sync (Alexey Ivanov)

Pull request description:

  Code based on pull/5804. Tested only on macOS 10.13.3 and should support 10.9+.

  What macOS versions bitcoin core currently supports?

Tree-SHA512: 85809b8d8d8a05169437b4268988da0b7372c29c6da3223ebdc106dc16dcb6d3caa5c52ace3591467005b50a63fd8b2ab1cb071cb4f450032932df25d5063315
UdjinM6 added a commit to dashpay/dash that referenced this pull request Jul 15, 2019
#3024)

* Merge bitcoin#12783: macOS: disable AppNap during sync

1e0f3c4 macOS: disable AppNap during sync (Alexey Ivanov)

Pull request description:

  Code based on pull/5804. Tested only on macOS 10.13.3 and should support 10.9+.

  What macOS versions bitcoin core currently supports?

Tree-SHA512: 85809b8d8d8a05169437b4268988da0b7372c29c6da3223ebdc106dc16dcb6d3caa5c52ace3591467005b50a63fd8b2ab1cb071cb4f450032932df25d5063315

* Refactor

* Drop `#include <memory>` from `src/qt/bitcoingui.h`

Was included by mistake.
codablock pushed a commit to codablock/dash that referenced this pull request Aug 7, 2019
dashpay#3024)

* Merge bitcoin#12783: macOS: disable AppNap during sync

1e0f3c4 macOS: disable AppNap during sync (Alexey Ivanov)

Pull request description:

  Code based on pull/5804. Tested only on macOS 10.13.3 and should support 10.9+.

  What macOS versions bitcoin core currently supports?

Tree-SHA512: 85809b8d8d8a05169437b4268988da0b7372c29c6da3223ebdc106dc16dcb6d3caa5c52ace3591467005b50a63fd8b2ab1cb071cb4f450032932df25d5063315

* Refactor

* Drop `#include <memory>` from `src/qt/bitcoingui.h`

Was included by mistake.
codablock pushed a commit to codablock/dash that referenced this pull request Aug 7, 2019
dashpay#3024)

* Merge bitcoin#12783: macOS: disable AppNap during sync

1e0f3c4 macOS: disable AppNap during sync (Alexey Ivanov)

Pull request description:

  Code based on pull/5804. Tested only on macOS 10.13.3 and should support 10.9+.

  What macOS versions bitcoin core currently supports?

Tree-SHA512: 85809b8d8d8a05169437b4268988da0b7372c29c6da3223ebdc106dc16dcb6d3caa5c52ace3591467005b50a63fd8b2ab1cb071cb4f450032932df25d5063315

* Refactor

* Drop `#include <memory>` from `src/qt/bitcoingui.h`

Was included by mistake.
MIPPL pushed a commit to biblepay/biblepay that referenced this pull request Nov 20, 2019
* commit '7d8eab2641023c78a72ccd6efc99fc35fd030a46': (32 commits)
  Add 0.14.0.3 change log to release-notes.md (dashpay#3055)
  Update release-notes.md for 0.14.0.3 (dashpay#3054)
  Bump version to 0.14.0.3 and copy release notes (dashpay#3053)
  Re-verify invalid IS sigs when the active quorum set rotated (dashpay#3052)
  Remove recovered sigs from the LLMQ db when corresponding IS locks get confirmed (dashpay#3048)
  Add "instantsendlocks" to getmempoolinfo RPC (dashpay#3047)
  Use fEnablePrivateSend instead of fPrivateSendRunning
  Show number of InstantSend locks in Debug Console (dashpay#2919)
  Optimize on-disk deterministic masternode storage to reduce size of evodb (dashpay#3017)
  Add "isValidMember" and "memberIndex" to "quorum memberof" and allow to specify quorum scan count (dashpay#3009)
  Implement "quorum memberof" (dashpay#3004)
  Bail out properly on Evo DB consistency check failures in ConnectBlock/DisconnectBlock (dashpay#3044)
  Do not count 0-fee txes for fee estimation (dashpay#3037)
  Fix broken link in PrivateSend info dialog (dashpay#3031)
  Merge pull request dashpay#3028 from PastaPastaPasta/backport-12588
  Add Dash Core Group codesign certificate (dashpay#3027)
  Fix osslsigncode compile issue in gitian-build (dashpay#3026)
  Backport bitcoin#12783: macOS: disable AppNap during sync (and mixing) (dashpay#3024)
  Remove support for InstantSend locked gobject collaterals (dashpay#3019)
  [v0.14.0.x] Update release notes for 0.14.0.2 (dashpay#3012)
  ...

# Conflicts:
#	.gitignore
#	.travis.yml
#	configure.ac
#	doc/man/biblepay-cli.1
#	doc/man/biblepay-qt.1
#	doc/man/biblepay-tx.1
#	doc/man/biblepayd.1
#	doc/release-notes.md
#	src/clientversion.h
#	src/qt/utilitydialog.cpp
barrystyle pushed a commit to PACGlobalOfficial/PAC that referenced this pull request Jan 22, 2020
dashpay#3024)

* Merge bitcoin#12783: macOS: disable AppNap during sync

1e0f3c4 macOS: disable AppNap during sync (Alexey Ivanov)

Pull request description:

  Code based on pull/5804. Tested only on macOS 10.13.3 and should support 10.9+.

  What macOS versions bitcoin core currently supports?

Tree-SHA512: 85809b8d8d8a05169437b4268988da0b7372c29c6da3223ebdc106dc16dcb6d3caa5c52ace3591467005b50a63fd8b2ab1cb071cb4f450032932df25d5063315

* Refactor

* Drop `#include <memory>` from `src/qt/bitcoingui.h`

Was included by mistake.
jonasschnelli added a commit to jonasschnelli/bitcoin that referenced this pull request May 18, 2020
jonasschnelli added a commit to jonasschnelli/bitcoin that referenced this pull request May 18, 2020
jasonbcox pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Nov 9, 2020
Summary: Backport of core [[bitcoin/bitcoin#12783 | PR12783]].

Test Plan:
  ninja all check
On OSX:
  ninja all check check-functional

Reviewers: #bitcoin_abc, PiRK

Reviewed By: #bitcoin_abc, PiRK

Subscribers: PiRK

Differential Revision: https://reviews.bitcoinabc.org/D8334
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet