rust/library/std/src
Matthias Krüger 2dd2fb728e
Rollup merge of #104493 - adamncasey:cgroupzeroperiod, r=m-ou-se
available_parallelism: Gracefully handle zero value cfs_period_us

There seem to be some scenarios where the cgroup cpu quota field `cpu.cfs_period_us` can contain `0`. This field is used to determine the "amount" of parallelism suggested by the function `std:🧵:available_parallelism`

A zero value of this field cause a panic when `available_parallelism()` is invoked. This issue was detected by the call from binaries built by `cargo test`. I really don't feel like `0` is a good value for `cpu.cfs_period_us`, but I also don't think applications should panic if this value is seen.

This panic started happening with rust 1.64.0.

This case is gracefully handled by other projects which read this information: [num_cpus](e437b9d908/src/linux.rs (L207-L210)), [ninja](https://github.com/ninja-build/ninja/pull/2174/files), [dotnet](c4341d45ac/src/coreclr/pal/src/misc/cgroup.cpp (L481-L483))

Before this change, running `cargo test` in environments configured as described above would trigger this panic:
```
$ RUST_BACKTRACE=1 cargo test
    Finished test [unoptimized + debuginfo] target(s) in 3.55s
     Running unittests src/main.rs (target/debug/deps/x-9a42e145aca2934d)
thread 'main' panicked at 'attempt to divide by zero', library/std/src/sys/unix/thread.rs:546:70
stack backtrace:
   0: rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::panic
   3: std::sys::unix:🧵:cgroups::quota
   4: std::sys::unix:🧵:available_parallelism
   5: std:🧵:available_parallelism
   6: test::helpers::concurrency::get_concurrency
   7: test::console::run_tests_console
   8: test::test_main
   9: test::test_main_static
  10: x::main
             at ./src/main.rs:1:1
  11: core::ops::function::FnOnce::call_once
             at /tmp/rust-1.64-1.64.0-1/library/core/src/ops/function.rs:248:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
error: test failed, to rerun pass '--bin x'
```

I've tested this change in an environment which has the bad (questionable?) setup and rebuilding the test executable against a fixed std library fixes the panic.
2022-12-28 22:22:18 +01:00
..
backtrace Use implicit capture syntax in format_args 2022-03-10 10:23:40 -05:00
collections Added const_hash tracking issue id 2022-11-06 18:01:44 +01:00
env
error remove fn backtrace 2022-08-01 20:10:40 +00:00
f32 Improve accuracy of asinh and acosh 2022-11-17 12:50:33 -08:00
f64 Improve accuracy of asinh and acosh 2022-11-17 12:50:33 -08:00
ffi Guarantee try_reserve preserves the contents on error 2022-08-10 01:51:38 +09:00
fs fs/tests: Fail fast on duplicate errors rather than looping indefinitely 2022-12-14 10:03:46 -05:00
io std: move ReentrantMutex to sync 2022-11-14 14:25:44 +01:00
net Remove unused diagnostic items 2022-11-13 18:49:21 +00:00
num
os enable fuzzy_provenance_casts lint in libstd 2022-11-20 19:23:28 +01:00
panic
path make many std tests work in Miri 2022-08-18 18:07:39 -04:00
personality enable fuzzy_provenance_casts lint in libstd 2022-11-20 19:23:28 +01:00
prelude Gate macros behind #[cfg(not(bootstrap))] 2022-12-01 11:16:18 +01:00
process More verbose Debug implementation of std::process:Command 2022-12-27 09:50:01 +01:00
sync Rollup merge of #104402 - joboet:sync_remutex, r=m-ou-se 2022-12-28 22:22:17 +01:00
sys Rollup merge of #104493 - adamncasey:cgroupzeroperiod, r=m-ou-se 2022-12-28 22:22:18 +01:00
sys_common Rollup merge of #104402 - joboet:sync_remutex, r=m-ou-se 2022-12-28 22:22:17 +01:00
thread fix dupe word typos 2022-12-05 16:42:36 +08:00
time Fix non-associativity of Instant math on aarch64-apple-darwin targets 2022-11-13 12:01:42 -08:00
alloc.rs Forbid mixing System with sytem allocator calls 2022-09-03 16:47:12 -05:00
ascii.rs Remove use of #[rustc_deprecated] 2022-04-14 01:33:13 -04:00
backtrace.rs std: use sync::Mutex for internal statics 2022-10-13 12:55:14 +02:00
env.rs Rollup merge of #101648 - Timmmm:home_dir_docs, r=joshtriplett 2022-12-11 23:36:44 +01:00
error.rs remove cfg(bootstrap) 2022-09-26 10:14:45 +02:00
f32.rs Improve accuracy of asinh and acosh 2022-11-17 12:50:33 -08:00
f64.rs Improve accuracy of asinh and acosh 2022-11-17 12:50:33 -08:00
fs.rs Rollup merge of #105100 - jhpratt:fix-docs, r=JohnTitor 2022-12-03 12:51:28 +09:00
keyword_docs.rs review feedback 2022-10-07 15:21:47 +02:00
lib.rs Rollup merge of #104647 - RalfJung:alloc-strict-provenance, r=thomcc 2022-11-22 22:54:41 -05:00
macros.rs stdio: Document no support for writing to non-blocking stdio/stderr 2022-09-07 14:22:57 +01:00
num.rs
panic.rs Adding backtrace off option for fuchsia targets 2022-09-14 23:54:40 +00:00
panicking.rs Adjust inlining attributes around panic_immediate_abort 2022-11-29 09:24:01 -05:00
path.rs Realistic Path::as_mut_os_str doctest 2022-12-16 16:52:36 -05:00
personality.rs Move personality functions to std 2022-08-23 16:12:58 +08:00
primitive_docs.rs disable strict-provenance-violating doctests in Miri 2022-11-22 11:49:02 +01:00
process.rs More verbose Debug implementation of std::process:Command 2022-12-27 09:50:01 +01:00
rt.rs Change process spawning to inherit the parent's signal mask by default 2022-10-20 14:53:38 -07:00
time.rs Bump version placeholders to release 2022-11-06 17:11:02 -05:00