-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
metrics: add MetricAtomicU64 and use in metrics #6574
Conversation
Is this intended to be merged before or after #6556? |
Before — can't build the other cr without it
…On Tue, May 21, 2024, 2:03 AM Alice Ryhl ***@***.***> wrote:
Is this intended to be merged before or after #6556
<#6556>?
—
Reply to this email directly, view it on GitHub
<#6574 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AADYKZ34ZQ4DVZOPIIGBWILZDLPTRAVCNFSM6AAAAABIAKT7ASVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMRRHAYTEOJXGE>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall lgtm.
spellcheck.dic
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also update the counter on the first line.
tokio/src/macros/cfg.rs
Outdated
macro_rules! cfg_64bit_metrics { | ||
($($item:item)*) => { | ||
$( | ||
#[cfg(all(target_has_atomic = "64"))] | ||
#[cfg_attr(docsrs, doc(cfg(target_has_atomic = "64")))] | ||
$item | ||
)* | ||
} | ||
|
||
} | ||
|
||
macro_rules! cfg_no_64bit_metrics { | ||
($($item:item)*) => { | ||
$( | ||
// For now, metrics is only disabled in loom tests. | ||
// When stabilized, it might have a dedicated feature flag. | ||
#[cfg(not(target_has_atomic = "64"))] | ||
$item | ||
)* | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are some empty lines here (line 238 and 250).
tokio/src/macros/cfg.rs
Outdated
macro_rules! cfg_no_64bit_metrics { | ||
($($item:item)*) => { | ||
$( | ||
// For now, metrics is only disabled in loom tests. | ||
// When stabilized, it might have a dedicated feature flag. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment seems out of date.
tokio/src/runtime/metrics/runtime.rs
Outdated
cfg_64bit_metrics! { | ||
|
||
/// Returns the number of times that tasks have been forced to yield back to the scheduler | ||
/// after exhausting their task budgets. | ||
/// | ||
/// This count starts at zero when the runtime is created and increases by one each time a task yields due to exhausting its budget. | ||
/// | ||
/// The counter is monotonically increasing. It is never decremented or | ||
/// reset to zero. | ||
pub fn budget_forced_yield_count(&self) -> u64 { | ||
self.handle | ||
.inner | ||
.scheduler_metrics() | ||
.budget_forced_yield_count | ||
.load(Relaxed) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra empty lines.
@@ -1,4 +1,4 @@ | |||
use crate::loom::sync::atomic::{AtomicU64, Ordering::Relaxed}; | |||
use crate::{loom::sync::atomic::Ordering::Relaxed, util::metric_atomics::MetricAtomicU64}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use crate::{loom::sync::atomic::Ordering::Relaxed, util::metric_atomics::MetricAtomicU64}; | |
use crate::loom::sync::atomic::Ordering::Relaxed; | |
use crate::util::metric_atomics::MetricAtomicU64; |
tokio/src/util/metric_atomics.rs
Outdated
// on platforms without 64-bit atomics, fetch-add returns unit | ||
pub(crate) fn fetch_add(&self, _value: u64, _ordering: Ordering) { } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then I would probably just return unit from both. (And perhaps rename to add
.)
tokio/src/macros/cfg.rs
Outdated
// For now, metrics is only disabled in loom tests. | ||
// When stabilized, it might have a dedicated feature flag. | ||
#[cfg(all(tokio_unstable, not(loom)))] | ||
#[cfg(tokio_unstable)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps this comment is also out of date?
tokio/src/macros/cfg.rs
Outdated
macro_rules! cfg_64bit_metrics { | ||
($($item:item)*) => { | ||
$( | ||
#[cfg(all(target_has_atomic = "64"))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we could simplify this condition:
#[cfg(all(target_has_atomic = "64"))] | |
#[cfg(target_has_atomic = "64")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
As we move to stabilize metrics, we need a graceful way to support U64 on platforms without 64-bit atomics. This commit adds MetricAtomicU64 which is empty on platforms that do not support 64-bit atomics. Write operations are no-ops and read operations are not defined.
Motivation
As we move to stabilize metrics, we need a graceful way to support U64 on platforms without 64-bit atomics.
Note: this is a breaking change on platforms without 32-bit atomics. Previously, they would have used a lock fallback provided by loom. Now, they simply do not have read access to these metrics.
Solution
This commit adds MetricAtomicU64 which is empty on platforms that do not support 64-bit atomics. Write operations are no-ops and read operations are not defined. This also allows us to remove the loom gating on
cfg_metrics
. This will allow #6556 to avoid the need for a separatecfg_metrics
gate.