Skip to content

support for 32bit environenments like xtensa, mips ..#533

Open
gb6881 wants to merge 2 commits into
tikv:masterfrom
gb6881:master
Open

support for 32bit environenments like xtensa, mips ..#533
gb6881 wants to merge 2 commits into
tikv:masterfrom
gb6881:master

Conversation

@gb6881

@gb6881 gb6881 commented Dec 14, 2024

Copy link
Copy Markdown

Hi

i wanted to use this together with opentelemetry-prometheus on my esp32s3, but there i don't have Atomic[UI]64,
For Opentelemetry there is a already a patch iin the wild, doing this here,
maybe you're interesseted.

Thanks,
Georg

Summary by CodeRabbit

  • New Features

    • Added support for additional CPU architectures, improving compatibility on PowerPC, MIPS, and Xtensa devices.
    • Expanded low-level atomic handling to work more reliably across more platforms.
  • Bug Fixes

    • Updated generated protobuf code to match newer tooling, helping improve serialization and reflection behavior.
    • Fixed platform-specific atomic usage in time and histogram handling for better runtime stability.

@ti-chi-bot

ti-chi-bot Bot commented Dec 14, 2024

Copy link
Copy Markdown

Welcome @gb6881! It looks like this is your first PR to tikv/rust-prometheus 🎉

Signed-off-by: Georg Buschbeck <gb@viingx.com>
…rdering

- proto/proto_model.rs: regenerate with rust-protobuf 2.28.0 (was 2.2.5), no logic changes
- atomic64.rs, histogram.rs, timer.rs: clean up whitespace and cfg-gated use blocks left over from the 32-bit/xtensa/mips portable_atomic support (12958bb)

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@ti-chi-bot

ti-chi-bot Bot commented Jul 2, 2026

Copy link
Copy Markdown

Thanks for your pull request. Before we can look at it, you'll need to add a 'DCO signoff' to your commits.

📝 Please follow instructions in the contributing guide to update your commits with the DCO

Full details of the Developer Certificate of Origin can be found at developercertificate.org.

The list of commits missing DCO signoff:

  • d80dc20 regenerate protobuf code with newer protobuf-codegen; fix up import ordering
Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds a target-specific portable-atomic dependency for powerpc, mips, and xtensa architectures, and conditionally routes atomic type imports (AtomicI64, AtomicU64, AtomicBool, Ordering) through portable_atomic for those targets in atomic64.rs, histogram.rs, and timer.rs. Separately, proto/proto_model.rs is regenerated with a newer rust-protobuf runtime, updating reflection trait implementations, descriptor initialization, and field visibility.

Changes

Portable-atomic backend selection

Layer / File(s) Summary
Add portable-atomic dependency
Cargo.toml
Adds target-specific dependency table for powerpc/mips/xtensa pulling in portable-atomic = "1.10.0".
Conditional atomic imports
src/atomic64.rs, src/histogram.rs, src/timer.rs
Atomic types are sourced from portable_atomic on mips/powerpc/xtensa targets and from std::sync::atomic otherwise.

Regenerated proto_model.rs

Layer / File(s) Summary
File header and lint updates
proto/proto_model.rs
Updates rust-protobuf version comment, lint attributes, and module doc comment.
LabelPair, Gauge, Counter regeneration
proto/proto_model.rs
Adds Default impls for references, updates getters, migrates reflection to dyn Any and LazyV2, and updates ProtobufValue::as_ref to ReflectValueRef.
Quantile, Summary regeneration
proto/proto_model.rs
Makes Summary.quantile public, adds Default impls, updates getters and reflection to dyn Any/LazyV2.
Untyped, Histogram, Bucket regeneration
proto/proto_model.rs
Makes Histogram.bucket public, adds Default impls, updates getters and reflection to dyn Any/LazyV2.
Metric, MetricFamily regeneration
proto/proto_model.rs
Makes Metric and MetricFamily.metric fields public, updates optional message getters, enum serialization via ProtobufEnum::value, and reflection to dyn Any/LazyV2.
MetricType and file descriptor regeneration
proto/proto_model.rs
Adds Default for MetricType and migrates enum/file descriptor plumbing to LazyV2.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

Not applicable — changes are conditional-compilation dependency selection and generated protobuf code updates without new multi-component control flow.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the main change: adding 32-bit target support for xtensa and mips via portable atomic backends.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
⚔️ Resolve merge conflicts
  • Resolve merge conflict in branch master

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@Cargo.toml`:
- Around line 35-37: Document the Xtensa portable-atomic dependency by adding a
short note near the target-specific dependency block in Cargo.toml or in the
README, explaining that Xtensa builds use portable-atomic and require
critical-section or unsafe-assume-single-core for CAS paths. Reference the
existing target dependency stanza for target.'cfg(any(target_arch = "powerpc",
target_arch = "mips", target_arch = "xtensa"))'.dependencies so the guidance is
easy to find for builds like ESP32-S3.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 851f894c-dadf-4d4e-9dd9-cb216ce476aa

📥 Commits

Reviewing files that changed from the base of the PR and between 45c43c9 and d80dc20.

📒 Files selected for processing (5)
  • Cargo.toml
  • proto/proto_model.rs
  • src/atomic64.rs
  • src/histogram.rs
  • src/timer.rs

Comment thread Cargo.toml
Comment on lines +35 to +37
[target.'cfg(any(target_arch = "powerpc", target_arch = "mips", target_arch = "xtensa"))'.dependencies]
portable-atomic = "1.10.0"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🌐 Web query:

Does portable-atomic require the critical-section feature to compile compare_exchange on Xtensa targets, and is unsafe-assume-single-core safe for dual-core ESP32-S3?

💡 Result:

The portable-atomic crate does not strictly require the critical-section feature to compile compare_exchange on Xtensa targets; however, it requires either the critical-section feature or the unsafe-assume-single-core feature (or portable_atomic_unsafe_assume_single_core cfg) to provide atomic CAS functionality where it is not natively available in the standard library [1][2][3]. Regarding your second question, it is unsafe to use unsafe-assume-single-core on a dual-core ESP32-S3 [3]. The unsafe-assume-single-core feature is strictly for single-core targets [3][4]. Enabling this feature on a multi-core system is unsound because the mechanism used to provide atomicity—disabling interrupts—only affects the current core and does not provide atomicity across multiple cores, leading to potential race conditions [3][5]. For multi-core environments like the ESP32-S3, you should use the critical-section feature, which allows you to provide a cross-core-aware implementation (e.g., using a global spinlock) to ensure atomicity across all cores [1][2][3].

Citations:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n== Cargo.toml context ==\n'
nl -ba Cargo.toml | sed -n '1,80p'

printf '\n== portable-atomic references ==\n'
rg -n "portable-atomic|portable_atomic|compare_exchange|unsafe-assume-single-core|critical-section" -S .

printf '\n== target-specific dependency section ==\n'
python3 - <<'PY'
from pathlib import Path
text = Path("Cargo.toml").read_text()
for i, line in enumerate(text.splitlines(), 1):
    if "portable-atomic" in line or "target.'cfg(any(target_arch = \"powerpc\", target_arch = \"mips\", target_arch = \"xtensa\"))'" in line:
        print(f"{i}: {line}")
PY

Repository: tikv/rust-prometheus

Length of output: 224


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n== Cargo.toml excerpt ==\n'
sed -n '1,90p' Cargo.toml | cat -n

printf '\n== searchable references ==\n'
rg -n -S "portable-atomic|portable_atomic|critical-section|unsafe-assume-single-core|xtensa|ESP32-S3" .

printf '\n== target-specific dependency lines ==\n'
python3 - <<'PY'
from pathlib import Path
text = Path("Cargo.toml").read_text().splitlines()
for i, line in enumerate(text, 1):
    if "portable-atomic" in line or "target.'cfg(any(target_arch = \"powerpc\", target_arch = \"mips\", target_arch = \"xtensa\"))'" in line:
        print(f"{i}: {line}")
PY

Repository: tikv/rust-prometheus

Length of output: 3965


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n== src/atomic64.rs ==\n'
sed -n '1,220p' src/atomic64.rs | cat -n

printf '\n== src/histogram.rs ==\n'
sed -n '1,220p' src/histogram.rs | cat -n

printf '\n== src/timer.rs ==\n'
sed -n '1,220p' src/timer.rs | cat -n

printf '\n== compare_exchange / fetch_update usage ==\n'
rg -n -S "compare_exchange|compare_exchange_weak|fetch_update|swap\\(" src

Repository: tikv/rust-prometheus

Length of output: 19623


Document the Xtensa portable-atomic requirement. Xtensa builds use portable_atomic here, and the CAS paths need critical-section (or unsafe-assume-single-core on truly single-core chips). A short note in the manifest or README would avoid confusing build failures for targets like ESP32-S3.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Cargo.toml` around lines 35 - 37, Document the Xtensa portable-atomic
dependency by adding a short note near the target-specific dependency block in
Cargo.toml or in the README, explaining that Xtensa builds use portable-atomic
and require critical-section or unsafe-assume-single-core for CAS paths.
Reference the existing target dependency stanza for target.'cfg(any(target_arch
= "powerpc", target_arch = "mips", target_arch = "xtensa"))'.dependencies so the
guidance is easy to find for builds like ESP32-S3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant