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

nproc: replace num_cpus crate with thread::available_parallelism #4352

Merged
merged 8 commits into from
Feb 14, 2023
Merged

nproc: replace num_cpus crate with thread::available_parallelism #4352

merged 8 commits into from
Feb 14, 2023

Conversation

souzaguilhermea
Copy link
Contributor

Closes #4351

@souzaguilhermea souzaguilhermea changed the title nproc: replace num_cpus crate with std::thread::available_parallelism nproc: replace num_cpus crate with thread::available_parallelism Feb 12, 2023
@sylvestre
Copy link
Contributor

Looks good
Should we check the error ?
(in which cases can we get any?)

@souzaguilhermea
Copy link
Contributor Author

souzaguilhermea commented Feb 13, 2023

From what i have read here thread::available_parallelism a error will, but it's not limited to, return in the following cases:

  • If the amount of parallelism is not known for the target platform.
  • If the program lacks permission to query the amount of parallelism made available to it.

I'm not sure if at any point we will reach those scenarios, but I'm doing a research to see others pitfall we may find.

@tertsdiepraam
Copy link
Member

I think GNU nproc just returns 1 processor if all methods fail: https://github.com/coreutils/gnulib/blob/f2b8ad906cbc861552a64e3804e5851c323cbac7/lib/nproc.c#L339

Not sure I agree with that, but that's probably what we should do for compatibility.

@sylvestre
Copy link
Contributor

one of the great thing about Rust. it forces us to have conversations about the right error handling :)

@souzaguilhermea
Copy link
Contributor Author

So for compatibility reasons it's better to return 1 in case it falls in an error?

If we agree with that I will do the changes.

@tertsdiepraam
Copy link
Member

Yes I think so, but let's also include a comment on the GNU behaviour for context.

@github-actions
Copy link

GNU testsuite comparison:

Congrats! The gnu test tests/tail-2/inotify-dir-recreate is no longer failing!

@github-actions
Copy link

GNU testsuite comparison:

Congrats! The gnu test tests/tail-2/inotify-dir-recreate is no longer failing!

Copy link
Member

@tertsdiepraam tertsdiepraam left a comment

Choose a reason for hiding this comment

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

Looks good! Just one more nit

src/uu/nproc/src/nproc.rs Outdated Show resolved Hide resolved
@github-actions
Copy link

GNU testsuite comparison:

GNU test failed: tests/tail-2/inotify-dir-recreate. tests/tail-2/inotify-dir-recreate is passing on 'main'. Maybe you have to rebase?

Copy link
Member

@tertsdiepraam tertsdiepraam left a comment

Choose a reason for hiding this comment

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

All good now! Thanks! For future PRs, could you squash the commits a bit more? I squashed them all while merging now.

@tertsdiepraam tertsdiepraam merged commit 04b6d80 into uutils:main Feb 14, 2023
@souzaguilhermea
Copy link
Contributor Author

Of course, I'll pay more attention in the next PRs and sorry for the inconvenience.

@sylvestre
Copy link
Contributor

not a big deal :) it is just best practice :)

@souzaguilhermea souzaguilhermea deleted the nproc_replace_num_cpus branch February 15, 2023 00:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace num_cpus crate with std::thread::available_parallelism
4 participants