<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
Cool! Thanks for the sharing the sample with us.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
-Sundar</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> panama-dev <panama-dev-retn@openjdk.org> on behalf of Gavin Ray <ray.gavin97@gmail.com><br>
<b>Sent:</b> 02 October 2022 09:07<br>
<b>To:</b> Jorn Vernee <jorn.vernee@oracle.com><br>
<b>Cc:</b> Maurizio Cimadamore <maurizio.cimadamore@oracle.com>; panama-dev@openjdk.org <panama-dev@openjdk.org><br>
<b>Subject:</b> Re: Getting "UnsatisfiedLinkError" in io_uring for methods that were defined as "static inline" in the header</font>
<div> </div>
</div>
<div>
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">Just wanted to update anyone interested/following here
<div><br>
</div>
<div>I've been on a work trip the past week so had very little free time</div>
<div>Tonight, I managed to get a "cat" like program working, that reads a file using io_uring</div>
<div><br>
</div>
<div>The code is here:</div>
<div><a href="https://github.com/GavinRay97/panama-liburing/blob/6a80673e73cfcf773212ee068b808f2b9d628df6/lib/src/test/java/panama/liburing/LibraryTest.java#L40-L137">https://github.com/GavinRay97/panama-liburing/blob/6a80673e73cfcf773212ee068b808f2b9d628df6/lib/src/test/java/panama/liburing/LibraryTest.java#L40-L137</a><br>
</div>
<div><br>
</div>
<div>It's not much, but it's a great start IMO</div>
<div>The test tries to read the file here:</div>
<div><br>
</div>
<div><a href="https://github.com/GavinRay97/panama-liburing/blob/master/lib/src/test/resources/test.txt#L1">https://github.com/GavinRay97/panama-liburing/blob/master/lib/src/test/resources/test.txt#L1</a><br>
</div>
<div><br>
</div>
<div><img alt="image.png" width="553" height="190" data-outlook-trace="F:1|T:1" src="cid:ii_l8qskci21"><br>
</div>
</div>
</div>
</div>
<br>
<div class="x_gmail_quote">
<div dir="ltr" class="x_gmail_attr">On Sat, Sep 24, 2022 at 8:37 AM Gavin Ray <<a href="mailto:ray.gavin97@gmail.com">ray.gavin97@gmail.com</a>> wrote:<br>
</div>
<blockquote class="x_gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left:1px solid rgb(204,204,204); padding-left:1ex">
<div dir="ltr">Jorn, thank you so much, a small oversight but it broke everything
<div>Your suggestion worked, I wish I could kiss you!</div>
<div><br>
</div>
<div>How cool is this?!</div>
<div>Now, to polish it up, write tests + examples, and document it so it can be published for public use as Maven library:</div>
<div><img alt="image.png" width="563" height="467" data-outlook-trace="F:1|T:1" src="cid:ii_l8g2r7vk0"><br>
</div>
</div>
<br>
<div class="x_gmail_quote">
<div dir="ltr" class="x_gmail_attr">On Sat, Sep 24, 2022 at 8:26 AM Jorn Vernee <<a href="mailto:jorn.vernee@oracle.com" target="_blank">jorn.vernee@oracle.com</a>> wrote:<br>
</div>
<blockquote class="x_gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left:1px solid rgb(204,204,204); padding-left:1ex">
<div>
<p>It looks like <span>io_uring_wait_cqe [1] takes as second argument a pointer to a pointer, but you pass it an pointer to a struct.</span></p>
<div>I think it s<span>hould be:</span><br>
</div>
<p>    // struct io_uring_cqe **<span>cqeRef = malloc(sizeof *cqeRef);</span><br>
<span><span>    MemorySegment</span> cqeRef = <span>MemorySegment</span>.<span>allocateNative</span>(C_POINTER,
<span>session</span>);<br>
</span>    io_uring_wait_cqe(ring, <span>cqeRef</span>);<br>
    // struct io_uring_cqe *cqe = *cqeRef;<br>
    MemoryAddress cqe = <span>cqeRef.get(C_POINTER, 0)</span><span>;</span><br>
</p>
<p>    MemoryAddress user_data = io_uring_cqe_get_data(cqe);<br>
    MemorySegment user_data_segment = MemorySegment.ofAddress(user_data, myStructLayout.byteSize(), session);</p>
<div>Note that MemorySegment::asSlice doesn't perform any dereference, so it is not equivalent to `cqes[0]`.<br>
</div>
<div><br>
</div>
<div>Jorn<br>
</div>
<div><br>
</div>
<div>[1]: <a href="https://man.archlinux.org/man/extra/liburing/io_uring_wait_cqe.3.en" target="_blank">
https://man.archlinux.org/man/extra/liburing/io_uring_wait_cqe.3.en</a><br>
</div>
<div><br>
</div>
<div>On 23/09/2022 22:15, Gavin Ray wrote:<br>
</div>
<blockquote type="cite">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">Okay, it seems I've gotten the "hello world" almost working
<div><br>
</div>
<div>The only problem left is that trying to read the "user_data" pointer returned gives garbage.</div>
<div>When I submit the event, I attach a struct to it, like this:</div>
<div><br>
</div>
<div>
<div>        MemorySegment myStruct = MemorySegment.allocateNative(myStructLayout, session);</div>
<div>        myStruct$foo.set(myStruct, 1);</div>
<div>        myStruct$bar.set(myStruct, 2);</div>
<div>        io_uring_sqe_set_data(sqePtr, myStruct);</div>
</div>
<div><br>
</div>
<div>Then when the results come back, I am doing this to read the userdata pointer:</div>
<div><br>
</div>
<div>
<div>        MemorySegment cqes = io_uring_cqe.allocateArray(1, allocator);</div>
<div>        io_uring_wait_cqe(ring, cqes);</div>
<div>        // cqes[0]</div>
<div>        MemorySegment cqe = cqes.asSlice(0, io_uring_cqe.$LAYOUT().byteSize());</div>
<div>        // cqes[0]->user_data</div>
<div>        MemoryAddress user_data = MemoryAddress.ofLong(io_uring_cqe.user_data$get(cqe));</div>
<div>        MemorySegment user_data_segment = MemorySegment.ofAddress(user_data, myStructLayout.byteSize(), session);</div>
</div>
<div><br>
</div>
<div>I try to print it out, comparing the "foo" and "bar" field against the original values of "1" and "2"</div>
<div><br>
</div>
<div>
<div>        user_data->foo=1480561120</div>
<div>        user_data->bar=32545</div>
</div>
<div><br>
</div>
<div>Does anyone know/see what I am doing wrong here? 🤔</div>
<div>
<div><a href="https://gist.github.com/GavinRay97/8ea0997693c00f8df61968a98ba30135#file-io_uring-java-L48-L55" target="_blank">https://gist.github.com/GavinRay97/8ea0997693c00f8df61968a98ba30135#file-io_uring-java-L48-L55</a></div>
</div>
</div>
</div>
</div>
</div>
</div>
<br>
<div class="x_gmail_quote">
<div dir="ltr" class="x_gmail_attr">On Wed, Sep 21, 2022 at 8:18 PM Gavin Ray <<a href="mailto:ray.gavin97@gmail.com" target="_blank">ray.gavin97@gmail.com</a>> wrote:<br>
</div>
<blockquote class="x_gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left:1px solid rgb(204,204,204); padding-left:1ex">
<div dir="ltr">
<div dir="ltr">@Daniel, I didn't know the lwjgl folks were looking into this area, I've had a brief look but it's definitely something I want to check out more!
<div><br>
</div>
<div>@Maurizio, the idea about defining a second library that depends on it is pretty clever.</div>
<div><br>
</div>
<div>It turns out that you can pull liburing in with CMake without so much effort</div>
<div>To set that scenario up was just the below code, this should work decently 👍</div>
<div><br>
</div>
<div>=============================</div>
<div>
<div>ExternalProject_Add(</div>
<div>        liburing_git</div>
<div>        GIT_REPOSITORY <a href="http://github.com/axboe/liburing.git" target="_blank">
http://github.com/axboe/liburing.git</a></div>
<div>        GIT_TAG liburing-2.2</div>
<div>        BUILD_IN_SOURCE 1</div>
<div>        BUILD_BYPRODUCTS "<SOURCE_DIR>/src/liburing.a"</div>
<div>        BUILD_COMMAND make</div>
<div>)</div>
<div>ExternalProject_Get_Property(liburing_git SOURCE_DIR)</div>
<div>add_library(liburing INTERFACE)</div>
<div>add_dependencies(liburing liburing_git)</div>
<div>target_include_directories(liburing INTERFACE ${SOURCE_DIR}/src/include)</div>
<div>target_link_libraries(liburing INTERFACE ${SOURCE_DIR}/src/liburing.a)</div>
<div><br>
</div>
<div># NOW LINK IT TO SECOND LIBRARY</div>
<div>add_library(liburing_extras SHARED liburing_extras/main.c)</div>
<div>target_link_libraries(liburing_extras liburing)</div>
<div>add_dependencies(liburing_extras liburing)</div>
</div>
<div><br>
</div>
</div>
</div>
<br>
<div class="x_gmail_quote">
<div dir="ltr" class="x_gmail_attr">On Wed, Sep 21, 2022 at 7:24 PM Maurizio Cimadamore <<a href="mailto:maurizio.cimadamore@oracle.com" target="_blank">maurizio.cimadamore@oracle.com</a>> wrote:<br>
</div>
<blockquote class="x_gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left:1px solid rgb(204,204,204); padding-left:1ex">
<br>
On 21/09/2022 23:39, Gavin Ray wrote:<br>
> That makes sense -- I will look at patching liburing with a dirty <br>
> one-liner that strips "static inline" from the definitions that have <br>
> them then, ty =)<br>
<br>
Sorry, hit send too fast, and forgot to reply to this.<br>
<br>
There are few approaches that can be tried.<br>
<br>
First, you could define another shared library that depends on io_uring <br>
- e.g. a C file which includes the io_uring header. This new file would <br>
contain _new_ exported symbols for all the static inline functions, <br>
whose implementation just delegates to the underlying static inline <br>
functions (in the included io_uring header). Then you load up the <br>
library with Panama and, if you have set up things correctly, you will <br>
see both the static inlines and the exported symbols in IO uring. (in <br>
fact, we do a similar trick to expose system library symbols like <br>
"printf" on Windows, which implements them as macros).<br>
<br>
Another (more fun?) option would be to just keep the original library, <br>
and implement the static inline functions in Java directly, using the <br>
FFM API. Most of the functions I see have only 2-3 lines in them, so it <br>
shouldn't be hard.<br>
<br>
Maurizio<br>
<br>
</blockquote>
</div>
</blockquote>
</div>
</blockquote>
</div>
</blockquote>
</div>
</blockquote>
</div>
</div>
</body>
</html>