Bindings to linux perf_event header.#3160
Conversation
|
Thanks for your pull request, @maxhaton! Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + druntime#3160" |
|
I'm seeing the same buildcite/druntime ldc-developers/ldc failure in other PRs. What broke it? |
|
@WalterBright as far as I can see it's a style issue in the comments from the C header. I'll push something to fix it soon - if I can't fix it easily I'll just strip them given that the ddoc for the sys.linux packages isn't generated anyway as far as I can see. |
|
I removed the comments, passes the checks on my machine now. |
Geod24
left a comment
There was a problem hiding this comment.
There's a lot of weird things here, and it doesn't seem so in line with how other C bindings are handled.
src/core/sys/linux/perf_event.d
Outdated
| * | ||
| * Converted/Bodged from linux userspace header | ||
| * | ||
| * Copyright: Max Haughton 2020 |
There was a problem hiding this comment.
It would be better if the copyright was assigned to the foundation instead of yourself.
src/core/sys/linux/perf_event.d
Outdated
| /* | ||
| * D header file for perf_event_open system call. | ||
| * | ||
| * Converted/Bodged from linux userspace header |
There was a problem hiding this comment.
Having "bodged" in official documentation doesn't really inspire confidence.
There was a problem hiding this comment.
Ha. I'll get rid of that tomorrow. Although the docs aren't generated for this folder if I'm not mistaken.
src/core/sys/linux/perf_event.d
Outdated
| * Converted/Bodged from linux userspace header | ||
| * | ||
| * Copyright: Max Haughton 2020 | ||
| * License: <a href="http://www.boost.org/LICENSE_1_0.txt">Boost License 1.0</a>. |
| else version (ARM64) | ||
| { | ||
| enum __NR_perf_event_open = 241; | ||
| } |
There was a problem hiding this comment.
else
static assert(0, "Platform not supported");| { | ||
| enum __NR_perf_event_open = 241; | ||
| } | ||
| extern (C) extern long syscall(long __sysno, ...); |
There was a problem hiding this comment.
I'm pretty sure we have a binding for this
There was a problem hiding this comment.
There is not. There are a few PRs but none of them made it in #2820
src/core/sys/linux/perf_event.d
Outdated
| private ulong _disabled_inherit_pinned_exclusive_exclude_user_exclude_kernel_exclude_hv_exclude_idle_mmap_comm_freq_inherit_stat_enable_on_exec_task_watermark_precise_ip_mmap_data_sample_id_all_exclude_host_exclude_guest_exclude_callchain_kernel_exclude_callchain_user_mmap2_comm_exec_use_clockid_context_switch_write_backward_namespaces___reserved_1; | ||
| @property ulong disabled() @safe pure nothrow @nogc const | ||
| { | ||
| auto result = (_disabled_inherit_pinned_exclusive_exclude_user_exclude_kernel_exclude_hv_exclude_idle_mmap_comm_freq_inherit_stat_enable_on_exec_task_watermark_precise_ip_mmap_data_sample_id_all_exclude_host_exclude_guest_exclude_callchain_kernel_exclude_callchain_user_mmap2_comm_exec_use_clockid_context_switch_write_backward_namespaces___reserved_1 & 1U) >> 0U; | ||
| return cast(ulong) result; | ||
| } |
There was a problem hiding this comment.
It's a mixin from the Phobos bitmanip template. It's not a public interface so I didn't bother renaming it.
|
|
||
| struct perf_event_attr | ||
| { | ||
|
|
src/core/sys/linux/perf_event.d
Outdated
|
|
||
| enum ulong mispred_min = cast(ulong) 0U; | ||
| enum ulong mispred_max = cast(ulong) 1U; | ||
| @property ulong predicted() @safe pure nothrow @nogc const |
There was a problem hiding this comment.
Since the whole thing is already nothrow @nogc you don't need those
|
Removing the comment is not really a solution IMO, they add a lot of value. What was the failure ? |
|
@Geod24 it was a whitespace check in the CI. The comments removal was easier than manually going through several hundred lines of comments - the ABI of perf_event is completely stable at this point so the documentation is in the manpages/online. |
|
I'm sorry, but how is removing trailing whitespace going to take more than ten seconds? |
Open in Emacs, |
src/core/sys/linux/perf_event.d
Outdated
|
|
||
| ulong sample_type; | ||
| ulong read_format; | ||
| private ulong _disabled_inherit_pinned_exclusive_exclude_user_exclude_kernel_exclude_hv_exclude_idle_mmap_comm_freq_inherit_stat_enable_on_exec_task_watermark_precise_ip_mmap_data_sample_id_all_exclude_host_exclude_guest_exclude_callchain_kernel_exclude_callchain_user_mmap2_comm_exec_use_clockid_context_switch_write_backward_namespaces___reserved_1; |
There was a problem hiding this comment.
seriously ? It is private so the mangling does not matter. Reduce the size of this identifier, please.
There was a problem hiding this comment.
eventually you can keep the long stuff in a comment, as it is certainly a very very self documenting name.
|
Fixed it. It wasn't trailing whitespace, it was tabs vs spaces but somehow only in the comments. I was under the impression that it was all spaces, but apparently not - it is now. |
|
@Geod24 everything passes now, feedback is incorporated, anything else? |
|
Except for in the definition of |
|
Damn I thought this was merged a while ago. |
|
@maxhaton Ping me when it's ready. |
…_event_open is not bound by glibc so I have included a helper to call this through syscall (in linux unistd) which is in glibc. The bitfields were done via the phobos library (manual mixin inclusion)
…d), the comments are now back with working indentation
Version specifier was incorrect for 64 bit arm Co-authored-by: Nathan Sashihara <21227491+n8sh@users.noreply.github.com>
c6eafa6 to
e7fccbf
Compare
|
@RazvanN7 Rebased and did a once over documenting everything I could spot. This API should be pretty stable, but I would like to get a test or two in another PR at some point. I have some eBPF bindings somewhere as well, they could go in. |
|
Thanks, @maxhaton ! |
| version (X86_64) | ||
| { | ||
| enum __NR_perf_event_open = 298; | ||
| } | ||
| else version (X86) | ||
| { | ||
| enum __NR_perf_event_open = 336; | ||
| } | ||
| else version (ARM) | ||
| { | ||
| enum __NR_perf_event_open = 364; | ||
| } | ||
| else version (AArch64) | ||
| { | ||
| enum __NR_perf_event_open = 241; | ||
| } | ||
| else | ||
| { | ||
| static assert(0, "Architecture not supported"); | ||
| } |
There was a problem hiding this comment.
We should really be rejecting PRs that don't cover all primary supported linux platforms. It's annoying to be running through some finishing line bootstrap tests, and I can't even build druntime anymore on PPC.
There was a problem hiding this comment.
Well that's why we need to extend the CI here to include you.
| // ulong, "__reserved_1", 35)); | ||
| private ulong perf_event_attr_bitmanip; | ||
| /// | ||
| @property ulong disabled() @safe pure nothrow @nogc const |
There was a problem hiding this comment.
There's functions here and no unittests? How can we vet that this actually works?
|
If you can find a platform with perf_event turned on I can get a testsuite
going but I'm guessing paranoid is set to the NO_WAY_JOSE setting.
…On Fri, 1 Oct 2021, 19:12 Iain Buclaw, ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In src/core/sys/linux/perf_event.d
<#3160 (comment)>:
> + // ulong, "mmap_data", 1,
+ // ulong, "sample_id_all", 1,
+ // ulong, "exclude_host", 1,
+ // ulong, "exclude_guest", 1,
+ // ulong, "exclude_callchain_kernel", 1,
+ // ulong, "exclude_callchain_user", 1,
+ // ulong, "mmap2", 1,
+ // ulong, "comm_exec", 1,
+ // ulong, "use_clockid", 1,
+ // ulong, "context_switch", 1,
+ // ulong, "write_backward", 1,
+ // ulong, "namespaces", 1,
+ // ulong, "__reserved_1", 35));
+ private ulong perf_event_attr_bitmanip;
+ ///
+ @Property ulong disabled() @safe pure nothrow @nogc const
There's functions here and no unittests? How can we vet that this actually
works?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#3160 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABLI75DILDX2F4CQRJYLRPDUEX2XRANCNFSM4OZAS2GQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
|
I completely forgot I did that, my bad, do we have syscall tables I can
rely upon at build time?
…On Fri, 1 Oct 2021, 18:56 Iain Buclaw, ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In src/core/sys/linux/perf_event.d
<#3160 (comment)>:
> +version (X86_64)
+{
+ enum __NR_perf_event_open = 298;
+}
+else version (X86)
+{
+ enum __NR_perf_event_open = 336;
+}
+else version (ARM)
+{
+ enum __NR_perf_event_open = 364;
+}
+else version (AArch64)
+{
+ enum __NR_perf_event_open = 241;
+}
+else
+{
+ static assert(0, "Architecture not supported");
+}
We should really be rejecting PRs that don't cover all primary supported
linux platforms. It's annoying to be running through some finishing line
bootstrap tests, and I can't even build druntime anymore on PPC.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#3160 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABLI75HK7VSXFULIIVPGOADUEXY5XANCNFSM4OZAS2GQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
In the For all others (HPPA, MIPS, PPC, RISCV, S390, SPARC), you can grab them from musl or glibc sources. |
|
|
||
| struct | ||
| { | ||
| import std.bitmanip : bitfields; |
I am working towards a uarch-level benchmarking and tracing library for phobos, so: these are bindings to perf_event.h . eBPF coming soon.
The system call perf_event_open is not included by glibc so I have included a function to call it that includes system call numbers for X86, amd64 and both varieties of ARM. The bitfields were done by including Phobos bitmanips manually - there could potentially be namespace collisions due to the extern(C) but I chose to keep it simple for now.
A simple example (Converted almost verbatim from the manpage) works fine but I am looking for a more thorough test suite (or at least one that covers most of the functions without converting hacky "kernel C" into D by hand).