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

Add all definitions from linux/ptp-clock.h #3559

Closed
wants to merge 6 commits into from

Conversation

folkertdev
Copy link
Contributor

I've taken over this change from @davidv1992 (who is my colleague). #3353 is the original PR which can now be closed.

I'm also assuming this can/should be merged into the libc-0.2 branch (and main will be rebased on top of that at some point?).

@rustbot
Copy link
Collaborator

rustbot commented Jan 25, 2024

r? @JohnTitor

(rustbot has picked a reviewer for you, use r? to override)

Comment on lines +4331 to +4446
(struct_ == "user_regs" && arm) ||
// `anonymous_1` is an anonymous union
(struct_ == "ptp_perout_request" && field == "anonymous_1") ||
// `anonymous_2` is an anonymous union
(struct_ == "ptp_perout_request" && field == "anonymous_2")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure why but both this and block and the block above excluding these fields seem required for CI to be satisfied?!

@JohnTitor
Copy link
Member

Could you resolve CI failure?
@rustbot author

@folkertdev
Copy link
Contributor Author

well that was more work that expected. A bunch of the constants and one struct are defined only in newer kernel versions (this causes problems on the 0.2 branch on musl, which uses an older kernel version)

and then on powerpc a bunch of the constants have different values.

Comment on lines 3741 to 3803
pub const PTP_CLOCK_GETCAPS: ::c_uint = 0x40503d01;
pub const PTP_EXTTS_REQUEST: ::c_uint = 0x80103d02;
pub const PTP_PEROUT_REQUEST: ::c_uint = 0x80383d03;
pub const PTP_ENABLE_PPS: ::c_uint = 0x80043d04;
pub const PTP_SYS_OFFSET: ::c_uint = 0x83403d05;
pub const PTP_PIN_GETFUNC: ::c_uint = 0xc0603d06;
pub const PTP_PIN_SETFUNC: ::c_uint = 0x80603d07;
pub const PTP_SYS_OFFSET_PRECISE: ::c_uint = 0xc0403d08;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

these are defined with some macros. There are rust versions here https://github.com/torvalds/linux/blob/8a696a29c6905594e4abf78eaafcb62165ac61f1/rust/kernel/ioctl.rs#L13

should those be used instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think duplicating the macros from ioctl.h would be better here - these numbers are kind of difficult to verify by hand as-is.

@folkertdev folkertdev force-pushed the add-ptp-clock branch 3 times, most recently from d9c8b36 to b087c94 Compare January 28, 2024 17:18
@folkertdev
Copy link
Contributor Author

@JohnTitor this is actually waiting for review, but I don't think I can update the label? (not sure how this workflow is supposed to work?)

@folkertdev
Copy link
Contributor Author

ah, rustbot got more helpful in newer PRs

@rustbot review

@@ -3457,6 +3457,8 @@ fn test_linux(target: &str) {
"linux/netlink.h",
// FIXME: requires Linux >= 5.6:
[!musl]: "linux/openat2.h",
"linux/ptp_clock.h",
// FIXME: requires Linux >= 5.6:
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this referring to? uapi ptp_clock.h has been around since at least 4.0, not sure if this is intended for ptrace.h below but that doesn't make sense either.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#3559 (comment) goes into why. it's not that the file doesn't exist before 5.6, but some of the constants are only added in this later version, so for the full functionality, 5.6 is required. I believe the same is true for netlink.h above, a file that is also very old but its api changed over time, so that is why I copied over that comment too

Copy link
Contributor

Choose a reason for hiding this comment

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

I was asking mostly about why the FIXME is below ptp_clock.h rather than above, looks like it is referring to ptrace.h rather than ptp_clock.h - but I guess this didn't show up well on the review UI. That context is probably helpful though, maybe change the comment to some fields require Linux >= 5.6

libc-test/build.rs Outdated Show resolved Hide resolved
libc-test/build.rs Outdated Show resolved Hide resolved
Comment on lines 668 to 675
#[cfg(target_env = "gnu")]
pub adjust_phase: ::c_int,
#[cfg(target_env = "gnu")]
pub max_phase_adj: ::c_int,
#[cfg(target_env = "gnu")]
pub rsv: [::c_int; 11],
#[cfg(any(target_env = "musl", target_env = "ohos"))]
pub rsv: [::c_int; 13],
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add a note about how this is a kernel version difference that happens to be exposed by glibc / musl supported versions?

Also if you have links to relevant sources or docs, please add them in the PR description. I haven't been able to find anything relevant.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm confused by this now. I suspect that I came to the above after some fighting with CI. Here // https://github.com/torvalds/linux/blob/b311c1b497e51a628aa89e7cb954481e5f9dced2/include/uapi/linux/ptp_clock.h#L94
the max_phase_adj field clearly is defined. But then e.g. on godbolt, for both musl and gnu, that field does not exist. adjust_phase does though. I'll change it back and see what CI says

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm confused by this now.

At least that makes two of us :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I just realized this is targeting 0.2 rather than main. I would prefer this target main first since it uses some newer versions, then for the backport we can work around any kind of legacy weirdness.

Don't close this since it is still useful, but if it isn't too much trouble then it would be good if you could reapply this on top of main and open a new PR with that.

(If it's a PITA don't worry about it and I'll figure out how to get things in sync after)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

worked out fine #3865

src/unix/linux_like/linux/mod.rs Outdated Show resolved Hide resolved
src/unix/linux_like/linux/mod.rs Outdated Show resolved Hide resolved
src/unix/linux_like/linux/mod.rs Show resolved Hide resolved
Comment on lines 1492 to 1515
impl PartialEq for ptp_sys_offset {
fn eq(&self, other: &ptp_sys_offset) -> bool {
self.n_samples == other.n_samples &&
self.rsv == other.rsv &&
self.ts[..] == other.ts[..]
}
}
impl Eq for ptp_sys_offset {}
impl ::fmt::Debug for ptp_sys_offset {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("ptp_sys_offset")
.field("n_samples", &self.n_samples)
.field("rsv", &self.rsv)
.field("ts", &&self.ts[..])
.finish()
}
}
impl ::hash::Hash for ptp_sys_offset {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
self.n_samples.hash(state);
self.rsv.hash(state);
self.ts[..].hash(state);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just move this struct from s_no_extra_traits! to s! so it gets these derived? Same for ptp_pin_desc

Comment on lines 3741 to 3803
pub const PTP_CLOCK_GETCAPS: ::c_uint = 0x40503d01;
pub const PTP_EXTTS_REQUEST: ::c_uint = 0x80103d02;
pub const PTP_PEROUT_REQUEST: ::c_uint = 0x80383d03;
pub const PTP_ENABLE_PPS: ::c_uint = 0x80043d04;
pub const PTP_SYS_OFFSET: ::c_uint = 0x83403d05;
pub const PTP_PIN_GETFUNC: ::c_uint = 0xc0603d06;
pub const PTP_PIN_SETFUNC: ::c_uint = 0x80603d07;
pub const PTP_SYS_OFFSET_PRECISE: ::c_uint = 0xc0403d08;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think duplicating the macros from ioctl.h would be better here - these numbers are kind of difficult to verify by hand as-is.

src/unix/linux_like/linux/mod.rs Show resolved Hide resolved
@tgross35
Copy link
Contributor

Left a review above, mostly nits with some follow up questions.

@rustbot author

@rustbot
Copy link
Collaborator

rustbot commented Aug 21, 2024

Some changes occurred in OpenBSD module

cc @semarie

Some changes occurred in solarish module

cc @jclulow, @pfmooney

Some changes occurred in OpenBSD module

cc @semarie

@tgross35
Copy link
Contributor

Considering there are some CI failures here and #3865 exists now, let's figure this out on main first then backport as applicable.

@tgross35 tgross35 closed this Aug 28, 2024
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.

5 participants