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

Custom setproctitle #32667

Merged
merged 16 commits into from
Jun 11, 2024
Merged

Custom setproctitle #32667

merged 16 commits into from
Jun 11, 2024

Conversation

schlimeszn
Copy link
Contributor

@schlimeszn schlimeszn commented Jun 8, 2024

Resolves: #32660

It's a simple refactor with a test to confirm correctness.

Copy link
Contributor

github-actions bot commented Jun 8, 2024

Thanks for contributing to openpilot! In order for us to review your PR as quickly as possible, check the following:

  • Convert your PR to a draft unless it's ready to review
  • Read the contributing docs
  • Before marking as "ready for review", ensure:
    • the goal is clearly stated in the description
    • all the tests are passing
    • the change is something we merge
    • include a route or your device' dongle ID if relevant

@schlimeszn schlimeszn marked this pull request as draft June 8, 2024 21:27
@schlimeszn schlimeszn marked this pull request as ready for review June 8, 2024 21:51
@adeebshihadeh
Copy link
Contributor

Doesn't seem to completely work. Name change isn't reflected in htop anymore. Just run selfdrive/modeld/modeld to check.

@adeebshihadeh adeebshihadeh marked this pull request as draft June 8, 2024 22:33
@schlimeszn
Copy link
Contributor Author

Doesn't seem to completely work. Name change isn't reflected in htop anymore. Just run selfdrive/modeld/modeld to check.

In $HOME/.config/htop/htoprc set show_thread_names=1

Is this a valid fix? Spent an hour trying to modify the process names in memory with ctypes and no success. Looked at setproctitle source code and would rather flip a bool than steal that

@schlimeszn
Copy link
Contributor Author

You can also F2 in htop go to Display Options and select Show custom thread names. If you want this change to persist, https://unix.stackexchange.com/a/181370. Or change the config file like I mentioned

@schlimeszn schlimeszn marked this pull request as ready for review June 9, 2024 20:38
@jyoung8607
Copy link
Collaborator

jyoung8607 commented Jun 10, 2024

The prctl method sets thread names, not the process name. I glanced at the Python setproctitle source, and I agree the method necessary to change the actual process title on Linux seems pretty ugly. If you truly want to change the process title, I don't think it makes much sense for openpilot to roll its own method, just keep using the module.

I think @schlimeszn has proposed a reasonable solution, it's just that AGNOS ships an .htoprc that isn't helping us here. It's configured to show individual threads within processes:

hide_threads=0
hide_kernel_threads=0
hide_userland_threads=0

But with the process name and not the thread name:

show_thread_names=0

I think it may be good to change that regardless. Additionally, it would be nice to be able to name threads within a multithreaded process and then be able to see which threads are consuming CPU in htop.

If we proceed with a thread naming approach, I have some notes:

  • An agnos-builder PR should be filed to update the shipping .htoprc
  • Rename the functions to reflect setting the thread name as opposed to process name
  • When setting, PR_SET_NAME has length and null termination constraints that should be checked
  • When reading, use PR_GET_NAME or /proc/PID/task/TID/comm instead of /proc/PID/comm

@adeebshihadeh
Copy link
Contributor

Let's go with what @jyoung8607's outlined. I think this is a reasonable compromise to get rid of a dependency for something that provides minimal value.

@schlimeszn schlimeszn marked this pull request as draft June 11, 2024 00:51
@schlimeszn schlimeszn marked this pull request as ready for review June 11, 2024 01:54
common/threadname.py Outdated Show resolved Hide resolved
@adeebshihadeh adeebshihadeh merged commit 3365ed5 into commaai:master Jun 11, 2024
12 of 13 checks passed
adeebshihadeh added a commit that referenced this pull request Jun 11, 2024
@adeebshihadeh
Copy link
Contributor

Reverted on master since test_onroad needs some updates after this. I'll look into this more soon

adeebshihadeh added a commit that referenced this pull request Jun 12, 2024
* add custom setproctitle

* add test

* Update poetry.lock

* fix lint

* support only Linux

* test only Linux

* final lint

* Update test_setproctitle.py

* Update setproctitle.py

* convert to threadnames

* delete proctitles

* Check str len and use PR_GET_NAME

* fix poetry.lock

* lint fix

* Update common/threadname.py

---------

Co-authored-by: reddyn12 <[email protected]>
Co-authored-by: Adeeb Shihadeh <[email protected]>
adeebshihadeh added a commit that referenced this pull request Jun 12, 2024
* Custom setproctitle (#32667)

* add custom setproctitle

* add test

* Update poetry.lock

* fix lint

* support only Linux

* test only Linux

* final lint

* Update test_setproctitle.py

* Update setproctitle.py

* convert to threadnames

* delete proctitles

* Check str len and use PR_GET_NAME

* fix poetry.lock

* lint fix

* Update common/threadname.py

---------

Co-authored-by: reddyn12 <[email protected]>
Co-authored-by: Adeeb Shihadeh <[email protected]>

* revert that for now

* use last 15

* fix

* use name

* update those

* and modeld

* rm

---------

Co-authored-by: schlimeszn <[email protected]>
Co-authored-by: reddyn12 <[email protected]>
Co-authored-by: Comma Device <[email protected]>
Edison-CBS pushed a commit to Edison-CBS/openpilot that referenced this pull request Sep 15, 2024
* add custom setproctitle

* add test

* Update poetry.lock

* fix lint

* support only Linux

* test only Linux

* final lint

* Update test_setproctitle.py

* Update setproctitle.py

* convert to threadnames

* delete proctitles

* Check str len and use PR_GET_NAME

* fix poetry.lock

* lint fix

* Update common/threadname.py

---------

Co-authored-by: reddyn12 <[email protected]>
Co-authored-by: Adeeb Shihadeh <[email protected]>
old-commit-hash: 3365ed5
Edison-CBS pushed a commit to Edison-CBS/openpilot that referenced this pull request Sep 15, 2024
This reverts commit 1f45e163559baa2a6127d5a5e8deb7067e32f813.

old-commit-hash: 5b51f03
Edison-CBS pushed a commit to Edison-CBS/openpilot that referenced this pull request Sep 15, 2024
* Custom setproctitle (commaai#32667)

* add custom setproctitle

* add test

* Update poetry.lock

* fix lint

* support only Linux

* test only Linux

* final lint

* Update test_setproctitle.py

* Update setproctitle.py

* convert to threadnames

* delete proctitles

* Check str len and use PR_GET_NAME

* fix poetry.lock

* lint fix

* Update common/threadname.py

---------

Co-authored-by: reddyn12 <[email protected]>
Co-authored-by: Adeeb Shihadeh <[email protected]>

* revert that for now

* use last 15

* fix

* use name

* update those

* and modeld

* rm

---------

Co-authored-by: schlimeszn <[email protected]>
Co-authored-by: reddyn12 <[email protected]>
Co-authored-by: Comma Device <[email protected]>
old-commit-hash: 83ac80c
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.

[$100 bounty] Remove setproctitle dependency
4 participants