Skip to content

Conversation

hebasto
Copy link
Member

@hebasto hebasto commented Sep 29, 2019

Thread names at the process level are limited by 15 characters:

// Only the first 15 characters are used (16 - NUL terminator)
::prctl(PR_SET_NAME, name, 0, 0, 0);

This commit ensures that name b-httpworker.42 will not be truncated.

On master (6b2210f):

hebasto@redcat:~$ ps -T -p $(cat /home/hebasto/.bitcoin/testnet3/bitcoind.pid)
  PID  SPID TTY          TIME CMD
32647 32647 pts/6    00:00:00 bitcoin-main
32647 32648 pts/6    00:00:00 QXcbEventReader
32647 32649 pts/6    00:00:00 bitcoin:disk$0
32647 32650 pts/6    00:00:00 QDBusConnection
32647 32651 pts/6    00:00:00 gmain
32647 32652 pts/6    00:00:00 gdbus
32647 32653 pts/6    00:00:07 bitcoin-qt-init
32647 32656 pts/6    00:00:00 bitcoin-scriptc
32647 32657 pts/6    00:00:00 bitcoin-scriptc
32647 32658 pts/6    00:00:00 bitcoin-scriptc
32647 32659 pts/6    00:00:00 bitcoin-schedul
32647 32660 pts/6    00:00:00 bitcoin-http
32647 32661 pts/6    00:00:00 bitcoin-httpwor
32647 32662 pts/6    00:00:00 bitcoin-httpwor
32647 32663 pts/6    00:00:00 bitcoin-httpwor
32647 32664 pts/6    00:00:00 bitcoin-httpwor
32647 32665 pts/6    00:00:00 bitcoin-qt-init
32647 32668 pts/6    00:00:00 bitcoin-torcont
32647 32669 pts/6    00:00:00 bitcoin-upnp
32647 32670 pts/6    00:00:00 bitcoin-net
32647 32671 pts/6    00:00:00 bitcoin-dnsseed
32647 32672 pts/6    00:00:00 bitcoin-addcon
32647 32673 pts/6    00:00:00 bitcoin-opencon
32647 32674 pts/6    00:00:00 bitcoin-msghand
32647 32675 pts/6    00:00:00 QThread
32647 32676 pts/6    00:00:00 QThread

With this PR:

hebasto@redcat:~$ ps -T -p $(cat /home/hebasto/.bitcoin/testnet3/bitcoind.pid)
  PID  SPID TTY          TIME CMD
25664 25664 pts/0    00:00:00 b-main
25664 25665 pts/0    00:00:00 QXcbEventReader
25664 25666 pts/0    00:00:00 bitcoin:disk$0
25664 25667 pts/0    00:00:00 QDBusConnection
25664 25668 pts/0    00:00:00 gmain
25664 25669 pts/0    00:00:00 gdbus
25664 25670 pts/0    00:00:07 b-qt-init
25664 25671 pts/0    00:00:00 b-scriptch.0
25664 25672 pts/0    00:00:00 b-scriptch.1
25664 25673 pts/0    00:00:00 b-scriptch.2
25664 25674 pts/0    00:00:00 b-scheduler
25664 25675 pts/0    00:00:00 b-http
25664 25676 pts/0    00:00:00 b-httpworker.0
25664 25677 pts/0    00:00:00 b-httpworker.1
25664 25678 pts/0    00:00:00 b-httpworker.2
25664 25679 pts/0    00:00:00 b-httpworker.3
25664 25680 pts/0    00:00:00 b-qt-init
25664 25682 pts/0    00:00:00 b-torcontrol
25664 25683 pts/0    00:00:00 b-upnp
25664 25684 pts/0    00:00:00 b-net
25664 25685 pts/0    00:00:00 b-dnsseed
25664 25686 pts/0    00:00:00 b-addcon
25664 25687 pts/0    00:00:00 b-opencon
25664 25688 pts/0    00:00:01 b-msghand
25664 25689 pts/0    00:00:00 QThread
25664 25690 pts/0    00:00:00 QThread

@promag
Copy link
Contributor

promag commented Sep 29, 2019

Concept ACK, b1?

@fanquake fanquake requested a review from jamesob September 29, 2019 23:41
@hebasto
Copy link
Member Author

hebasto commented Sep 30, 2019

b1?

I was looking for two-characters string: b points to Bitcoin, and 1 is a distinct separator.

@laanwj
Copy link
Member

laanwj commented Sep 30, 2019

Concept ACK, no opinion on "b1" specifically but having non-cropped thread names would be nice.

@practicalswift
Copy link
Contributor

practicalswift commented Sep 30, 2019

ACK c442646 modulo:

<bikeshedding>
I find say b1scheduler a bit unpleasant to read -- 1 looks a bit like l or I. Perhaps - is better as a separator?

Making it b-scheduler instead of b1scheduler :)
</bikeshedding>

@yusufsahinhamza
Copy link
Contributor

@hebasto, @practicalswift What about btc instead of b1?

@hebasto
Copy link
Member Author

hebasto commented Sep 30, 2019

What about btc instead of b1?

btc length is 3 characters. It will require to make shorter other parts of thread name, e.g., httpworker

Thread names at the process level are limited by 15 characters. This
commit ensures that name 'b-httpworker.42' will not be cropped.
@hebasto hebasto force-pushed the 20190929-short-thread-names branch from c442646 to 386ae0f Compare September 30, 2019 19:35
@hebasto
Copy link
Member Author

hebasto commented Sep 30, 2019

@promag @laanwj @practicalswift Thank you for your reviews.

I find say b1scheduler a bit unpleasant to read -- 1 looks a bit like l or I. Perhaps - is better as a separator?
Making it b-scheduler instead of b1scheduler :)

Done. PR description has been updated.

@maflcko
Copy link
Member

maflcko commented Sep 30, 2019

ACK 386ae0f (skimmed the diff on GitHub)

@practicalswift
Copy link
Contributor

ACK 386ae0f -- diff looks correct

Copy link
Member

@fanquake fanquake left a comment

Choose a reason for hiding this comment

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

ACK 386ae0f - quickly tested on a Debian system.

ps -T -p $(cat /home/test/regtest/bitcoind.pid)
  PID  SPID TTY          TIME CMD
 5909  5909 ?        00:00:00 b-init
 5909  5910 ?        00:00:00 b-scriptch.0
 5909  5911 ?        00:00:00 b-scriptch.1
 5909  5912 ?        00:00:00 b-scriptch.2
 5909  5913 ?        00:00:00 b-scriptch.3
 5909  5914 ?        00:00:00 b-scheduler
 5909  5915 ?        00:00:00 b-http
 5909  5916 ?        00:00:00 b-httpworker.0
 5909  5917 ?        00:00:00 b-httpworker.1
 5909  5918 ?        00:00:00 b-httpworker.2
 5909  5919 ?        00:00:00 b-httpworker.3
 5909  5921 ?        00:00:00 b-torcontrol
 5909  5922 ?        00:00:00 b-net
 5909  5924 ?        00:00:00 b-addcon
 5909  5925 ?        00:00:00 b-opencon
 5909  5926 ?        00:00:00 b-msghand

fanquake added a commit that referenced this pull request Oct 1, 2019
386ae0f util: Make thread names shorter (Hennadii Stepanov)

Pull request description:

  Thread names at the process level are limited by 15 characters:
  https://github.com/bitcoin/bitcoin/blob/6b2210f1016c9ed96ce470e588e4cb12fa36a900/src/util/threadnames.cpp#L28-L29

  This commit ensures that name `b-httpworker.42` will not be truncated.

  On master (6b2210f):
  ```bash
  hebasto@redcat:~$ ps -T -p $(cat /home/hebasto/.bitcoin/testnet3/bitcoind.pid)
    PID  SPID TTY          TIME CMD
  32647 32647 pts/6    00:00:00 bitcoin-main
  32647 32648 pts/6    00:00:00 QXcbEventReader
  32647 32649 pts/6    00:00:00 bitcoin:disk$0
  32647 32650 pts/6    00:00:00 QDBusConnection
  32647 32651 pts/6    00:00:00 gmain
  32647 32652 pts/6    00:00:00 gdbus
  32647 32653 pts/6    00:00:07 bitcoin-qt-init
  32647 32656 pts/6    00:00:00 bitcoin-scriptc
  32647 32657 pts/6    00:00:00 bitcoin-scriptc
  32647 32658 pts/6    00:00:00 bitcoin-scriptc
  32647 32659 pts/6    00:00:00 bitcoin-schedul
  32647 32660 pts/6    00:00:00 bitcoin-http
  32647 32661 pts/6    00:00:00 bitcoin-httpwor
  32647 32662 pts/6    00:00:00 bitcoin-httpwor
  32647 32663 pts/6    00:00:00 bitcoin-httpwor
  32647 32664 pts/6    00:00:00 bitcoin-httpwor
  32647 32665 pts/6    00:00:00 bitcoin-qt-init
  32647 32668 pts/6    00:00:00 bitcoin-torcont
  32647 32669 pts/6    00:00:00 bitcoin-upnp
  32647 32670 pts/6    00:00:00 bitcoin-net
  32647 32671 pts/6    00:00:00 bitcoin-dnsseed
  32647 32672 pts/6    00:00:00 bitcoin-addcon
  32647 32673 pts/6    00:00:00 bitcoin-opencon
  32647 32674 pts/6    00:00:00 bitcoin-msghand
  32647 32675 pts/6    00:00:00 QThread
  32647 32676 pts/6    00:00:00 QThread
  ```

  With this PR:
  ```bash
  hebasto@redcat:~$ ps -T -p $(cat /home/hebasto/.bitcoin/testnet3/bitcoind.pid)
    PID  SPID TTY          TIME CMD
  25664 25664 pts/0    00:00:00 b-main
  25664 25665 pts/0    00:00:00 QXcbEventReader
  25664 25666 pts/0    00:00:00 bitcoin:disk$0
  25664 25667 pts/0    00:00:00 QDBusConnection
  25664 25668 pts/0    00:00:00 gmain
  25664 25669 pts/0    00:00:00 gdbus
  25664 25670 pts/0    00:00:07 b-qt-init
  25664 25671 pts/0    00:00:00 b-scriptch.0
  25664 25672 pts/0    00:00:00 b-scriptch.1
  25664 25673 pts/0    00:00:00 b-scriptch.2
  25664 25674 pts/0    00:00:00 b-scheduler
  25664 25675 pts/0    00:00:00 b-http
  25664 25676 pts/0    00:00:00 b-httpworker.0
  25664 25677 pts/0    00:00:00 b-httpworker.1
  25664 25678 pts/0    00:00:00 b-httpworker.2
  25664 25679 pts/0    00:00:00 b-httpworker.3
  25664 25680 pts/0    00:00:00 b-qt-init
  25664 25682 pts/0    00:00:00 b-torcontrol
  25664 25683 pts/0    00:00:00 b-upnp
  25664 25684 pts/0    00:00:00 b-net
  25664 25685 pts/0    00:00:00 b-dnsseed
  25664 25686 pts/0    00:00:00 b-addcon
  25664 25687 pts/0    00:00:00 b-opencon
  25664 25688 pts/0    00:00:01 b-msghand
  25664 25689 pts/0    00:00:00 QThread
  25664 25690 pts/0    00:00:00 QThread
  ```

ACKs for top commit:
  MarcoFalke:
    ACK 386ae0f (skimmed the diff on GitHub)
  practicalswift:
    ACK 386ae0f -- diff looks correct
  fanquake:
    ACK 386ae0f - quickly tested on a Debian system.

Tree-SHA512: 8f7f553213a5856943ddba50611814b771e7dc474101a3e1f98259091684c8d0358c541d32011bfe1da7f430225f01a2d6b514a3b7c5aaf671b2ca8fcf155c4a
@fanquake fanquake merged commit 386ae0f into bitcoin:master Oct 1, 2019
@jamesob
Copy link
Contributor

jamesob commented Oct 1, 2019

Post-merge ACK

@hebasto hebasto deleted the 20190929-short-thread-names branch October 1, 2019 15:49
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Mar 24, 2020
Summary:
```
Thread names at the process level are limited by 15 characters. This
commit ensures that name 'b-httpworker.42' will not be cropped.
```

Backport of core [[bitcoin/bitcoin#16984 | PR16984]].

Depends on D5540.

Test Plan:
  ninja check

  bitcoind -daemon -testnet
  ps -T -p $(cat ~/.bitcoin/testnet3/bitcoind.pid)
Check no thread name is truncated.

Before:
```
 PID  SPID TTY          TIME CMD
 3749  3749 ?        00:00:07 bitcoind
 3749  3750 ?        00:00:00 bitcoin-scriptc
 3749  3751 ?        00:00:00 bitcoin-scriptc
 3749  3752 ?        00:00:00 bitcoin-scriptc
 3749  3753 ?        00:00:00 bitcoin-scriptc
 3749  3754 ?        00:00:00 bitcoin-scriptc
 3749  3755 ?        00:00:00 bitcoin-schedul
 3749  3756 ?        00:00:00 bitcoin-http
 3749  3757 ?        00:00:00 bitcoin-httpwor
 3749  3758 ?        00:00:00 bitcoin-httpwor
 3749  3759 ?        00:00:00 bitcoin-httpwor
 3749  3760 ?        00:00:00 bitcoin-httpwor
 3749  3761 ?        00:00:01 bitcoind
 3749  3765 ?        00:00:00 bitcoin-torcont
 3749  3766 ?        00:00:00 bitcoin-net
 3749  3768 ?        00:00:00 bitcoin-addcon
 3749  3769 ?        00:00:00 bitcoin-opencon
 3749  3770 ?        00:00:02 bitcoin-msghand
```

After:
```
  PID  SPID TTY          TIME CMD
 5191  5191 ?        00:00:06 b-init
 5191  5192 ?        00:00:00 b-scriptch.0
 5191  5193 ?        00:00:00 b-scriptch.1
 5191  5194 ?        00:00:00 b-scriptch.2
 5191  5195 ?        00:00:00 b-scriptch.3
 5191  5196 ?        00:00:00 b-scriptch.4
 5191  5197 ?        00:00:00 b-scheduler
 5191  5198 ?        00:00:00 b-http
 5191  5199 ?        00:00:00 b-httpworker.0
 5191  5200 ?        00:00:00 b-httpworker.1
 5191  5201 ?        00:00:00 b-httpworker.2
 5191  5202 ?        00:00:00 b-httpworker.3
 5191  5206 ?        00:00:00 b-torcontrol
 5191  5207 ?        00:00:00 b-net
 5191  5208 ?        00:00:00 b-dnsseed
 5191  5209 ?        00:00:00 b-addcon
 5191  5210 ?        00:00:00 b-opencon
 5191  5211 ?        00:00:00 b-msghand
```

Reviewers: #bitcoin_abc, jasonbcox

Reviewed By: #bitcoin_abc, jasonbcox

Differential Revision: https://reviews.bitcoinabc.org/D5543
ftrader added a commit to bitcoin-cash-node/bitcoin-cash-node that referenced this pull request Dec 1, 2020
Thread names in logs and deadlock debug tools

See merge request bitcoin-cash-node/bitcoin-cash-node!834

This is a backport of [PR15849](bitcoin/bitcoin#15849) (Thread names in logs and deadlock debug tools).

See original PR for benchmarks.

Also includes some smaller follow-up PR's:
* [PR15968](bitcoin/bitcoin#15968) - Fix portability issue with pthreads
* [PR16984](bitcoin/bitcoin#16984) - util: Make thread names shorter
* [PR17038](bitcoin/bitcoin#17038) - Don't rename main thread at process level

## Test plan

New tests: `ninja check`

Run with `-logthreadnames`, observe lines are prefixed with thread

```
2020-10-28T11:39:16Z [init] init message: Done loading
2020-10-28T11:39:16Z [opencon] opencon thread start
2020-10-28T11:39:16Z [dnsseed] 0 addresses found from DNS seeds
2020-10-28T11:39:16Z [msghand] msghand thread start
2020-10-28T11:39:16Z [dnsseed] dnsseed thread exit
```

Compile with lockorder debugging enabled: `cmake -GNinja -DCMAKE_BUILD_TYPE=Debug ..`
kwvg added a commit to kwvg/dash that referenced this pull request Nov 6, 2021
kwvg added a commit to kwvg/dash that referenced this pull request Dec 5, 2021
kwvg added a commit to kwvg/dash that referenced this pull request Dec 5, 2021
kwvg added a commit to kwvg/dash that referenced this pull request Dec 12, 2021
kwvg added a commit to kwvg/dash that referenced this pull request Dec 12, 2021
kwvg added a commit to kwvg/dash that referenced this pull request Dec 12, 2021
PastaPastaPasta added a commit to dashpay/dash that referenced this pull request Dec 12, 2021
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Dec 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants