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

Use standard C types for 32 and 64 bit variables. #16

Open
wants to merge 1 commit into
base: amd-staging
Choose a base branch
from

Conversation

petterreinholdtsen
Copy link

This make the code build on 64 bit PowerPC. It also ensure standard user space types are used instead of Linux specific types. This was required to get the code to build on amd64, where __u64 is 'unsigned long long', while uint64_t is 'unsigned long' (both with sizeof() == 8), and PRIx64 expect the latter.

All formatting of 64 bit types are converted to use PRIxN style formatting statements. Some 32 bit use is also converted, but did not try to track down every use as this do not affect PowerPC. Also drop the <linux/ioctl.h> include, as it seem to be unused.

This addresses https://bugs.debian.org/1081303

Fixes #14.

@lancesix
Copy link
Collaborator

Hi,

Thanks for the patch. I really do not think we should change the kfd_ioctl.h file for this as this is a verbotim copy of the kernel interface, and ideally one should be able to build the rest of rocm-dbgapi by relying on the version from /usr/include/linux/kfd_ioctl.h.

I think a more desirable approach could be to use the PRIxN macros in the format as this patch proposes, but be sure to static_cast<uint64_t> () all the __u64 values (similar for the 32 bits values). This is not ideal, but this would allow us to be able to log values from the driver without having to alter the reference header.

@petterreinholdtsen
Copy link
Author

What about dropping the renaming of __u32, __s32 and __u64 and instead only change the #include in kfd_ioctl.h to something like this:

#include <stdint.h>
typedef int32_t __s32;
typedef uint32_t __u32;
typedef uint64_t __u64;

The change would be a lot smaller, while the effect is the same. It seem like a better option than hiding any problems with casting.

@lancesix
Copy link
Collaborator

The main limitation I see for this this approach is that it prevents up from dropping the copy of kfd_ioctl.h once that interface gets stable enough. Ideally, we should not embed it at all, and rely on /usr/include/linux/kfd_ioctl.h instead.

@lancesix
Copy link
Collaborator

cc @lmoriche

@petterreinholdtsen
Copy link
Author

petterreinholdtsen commented Sep 12, 2024 via email

@petterreinholdtsen
Copy link
Author

petterreinholdtsen commented Sep 12, 2024 via email

@lancesix
Copy link
Collaborator

Can you update the patch to use the approach you suggested earlier with:

#include <stdint.h>
typedef int32_t __s32;
typedef uint32_t __u32;
typedef uint64_t __u64;

That seems to be the best compromise at this point. If at some point we end up moving to not using a copy of this file in our repo, we'll revisit this.

I'm going to be away for a few days, I'll follow-up on this PR when I come back late next week.

This make the code build on 64 bit PowerPC.  It also ensure
standard user space types are used instead of Linux specific types.  This
was required to get the code to build on amd64, where __u64 is
'unsigned long long', while uint64_t is 'unsigned long' (both with
sizeof() == 8), and PRIx64 expect the latter.

All formatting of 64 bit types are converted to use PRIxN style formatting
statements.  Some 32 bit use is also converted, but did not try to
track down every use as this do not affect PowerPC.  Also drop the
<linux/ioctl.h> include, as it seem to be unused.

This addresses https://bugs.debian.org/1081303

Fixes ROCm#14.
@petterreinholdtsen
Copy link
Author

petterreinholdtsen commented Sep 12, 2024 via email

@zumbi
Copy link

zumbi commented Sep 16, 2024

I have test built the patch on ppc64le and I confirm this builds fine on that architecture.

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.

[Issue]: fails to build on PowerPC
3 participants