From thomas.schatzl at oracle.com Fri Jun 13 13:06:23 2025 From: thomas.schatzl at oracle.com (Thomas Schatzl) Date: Fri, 13 Jun 2025 15:06:23 +0200 Subject: Getting per-thread CPU time on *BSD Message-ID: Hi all, I am currently looking into making os::get_thread_cpu_time() usable on *BSD because we in the gc team would like to use this functionality in the future. The idea is to get an accurate measurement of how much CPU time the GC threads take to do heap sizing. For this reason, for some time there is that os::get_thread_cpu_time(Thread*) that returns the user+sys time the given thread (id) took since creation API that is unimplemented on *BSD except OSX. Is there something on *BSD that would satisfy the requirements? I only could find getrusage(RUSAGE_THREAD), that only gets this information for the calling thread, which is not enough and too complicated/expensive to start the threads themselves. Also it only seems to be supported on OpenBSD and FreeBSD. The method seems also required for JVMTI, JFR, some management API and some collectors (Shenandoah uses it), so these are already not working optimally or not at all on *BSD. This would add G1, the default collector, not working as well (or not optimally). Thanks, Thomas (I'm aware that this mailing list might be dead, the last message was from 2019, but maybe....) From harald+jdklists at volse.no Mon Jun 16 07:51:00 2025 From: harald+jdklists at volse.no (Harald Eilertsen) Date: Mon, 16 Jun 2025 09:51:00 +0200 Subject: Getting per-thread CPU time on *BSD In-Reply-To: References: Message-ID: Hi Thomas, On Fri, Jun 13, 2025 at 03:06:23PM +0200, Thomas Schatzl wrote: > For this reason, for some time there is that > os::get_thread_cpu_time(Thread*) that returns the user+sys time the given > thread (id) took since creation API that is unimplemented on *BSD except > OSX. > > Is there something on *BSD that would satisfy the requirements? I'll have to research that a bit before giving you an answer, unless there's someone else slumbering on the list who can help. Take care! Harald From harald+jdklists at volse.no Mon Jun 16 14:21:15 2025 From: harald+jdklists at volse.no (Harald Eilertsen) Date: Mon, 16 Jun 2025 16:21:15 +0200 Subject: Getting per-thread CPU time on *BSD In-Reply-To: References: Message-ID: Hi again, I think it should be possible to get what you need via the clock_gettime() call with the clock id returned by pthread_getcpuclockid() for the target thread. https://man.freebsd.org/cgi/man.cgi?query=clock_gettime https://man.freebsd.org/cgi/man.cgi?query=pthread_getcpuclockid >From what I can see these calls are also supported on OpenBSD and NetBSD. One note, though: These calls return (afaict) the acumulated sys+user time of the thread in one timespec struct, not as separate sys+user times. If that's ok, I'm happy to try to implement it. Is there a test that can be used to check the implementation? Take Care! Harald From thomas.schatzl at oracle.com Mon Jun 16 16:04:14 2025 From: thomas.schatzl at oracle.com (Thomas Schatzl) Date: Mon, 16 Jun 2025 18:04:14 +0200 Subject: Getting per-thread CPU time on *BSD In-Reply-To: References: Message-ID: <97c3f636-5fed-4fd3-a104-afeda353ec22@oracle.com> Hi, thanks for looking into this. On 16.06.25 16:21, Harald Eilertsen wrote: > Hi again, > > I think it should be possible to get what you need via the > clock_gettime() call with the clock id returned by > pthread_getcpuclockid() for the target thread. > > https://urldefense.com/v3/__https://man.freebsd.org/cgi/man.cgi?query=clock_gettime__;!!ACWV5N9M2RV99hQ!Igm6XiYuRHoGdLiINNmnGjMmnpJb1YT9uiq9qJr4MmKjsNFtl7OTvu9ogF6zQHLj4oR_fedP1I3oOQDabcPm4dNT7XdIry9c$ > https://urldefense.com/v3/__https://man.freebsd.org/cgi/man.cgi?query=pthread_getcpuclockid__;!!ACWV5N9M2RV99hQ!Igm6XiYuRHoGdLiINNmnGjMmnpJb1YT9uiq9qJr4MmKjsNFtl7OTvu9ogF6zQHLj4oR_fedP1I3oOQDabcPm4dNT7dKHsMci$ > > From what I can see these calls are also supported on OpenBSD and > NetBSD. > So this is somewhat similar to what linux does if both user and sys time are requested, getting a clock and then using that method? (I did not look into the linux code in detail). When getting user time only, Linux seems to parse /proc/self/task//stats or so file, not sure if that is possible on BSD too. > One note, though: These calls return (afaict) the acumulated sys+user > time of the thread in one timespec struct, not as separate sys+user > times. > That's fine for many cases, at least for GC we want both. Some users (JFR) seem to make the distinction, but I guess just returning the same value is better than the current implementation (crashing). > If that's ok, I'm happy to try to implement it. Is there a test that can > be used to check the implementation? > jcmd Thread.print on a java process should print lines like: "G1 Refine#3" os_prio=0 cpu=22.28ms elapsed=90.86s tid=0x0000f56fbc21f000 nid=0x75f4 runnable The value after "cpu=" is derived from os::thread_cpu_time() (see Thread::print_on in thread.cpp) which seems to be unimplemented (just fail the VM) on *BSD. I.e. os_bsd.cpp, search for "Unimplemented()" to find that above method. Would be great to have support for that on non-OSX too so that we can rely on that. Thanks, Thomas From harald+jdklists at volse.no Mon Jun 16 17:53:54 2025 From: harald+jdklists at volse.no (Harald Eilertsen) Date: Mon, 16 Jun 2025 19:53:54 +0200 Subject: Getting per-thread CPU time on *BSD In-Reply-To: <97c3f636-5fed-4fd3-a104-afeda353ec22@oracle.com> References: <97c3f636-5fed-4fd3-a104-afeda353ec22@oracle.com> Message-ID: Hi, On Mon, Jun 16, 2025 at 06:04:14PM +0200, Thomas Schatzl wrote: > On 16.06.25 16:21, Harald Eilertsen wrote: > > Hi again, > > > > I think it should be possible to get what you need via the > > clock_gettime() call with the clock id returned by > > pthread_getcpuclockid() for the target thread. > > > > https://urldefense.com/v3/__https://man.freebsd.org/cgi/man.cgi?query=clock_gettime__;!!ACWV5N9M2RV99hQ!Igm6XiYuRHoGdLiINNmnGjMmnpJb1YT9uiq9qJr4MmKjsNFtl7OTvu9ogF6zQHLj4oR_fedP1I3oOQDabcPm4dNT7XdIry9c$ > > https://urldefense.com/v3/__https://man.freebsd.org/cgi/man.cgi?query=pthread_getcpuclockid__;!!ACWV5N9M2RV99hQ!Igm6XiYuRHoGdLiINNmnGjMmnpJb1YT9uiq9qJr4MmKjsNFtl7OTvu9ogF6zQHLj4oR_fedP1I3oOQDabcPm4dNT7dKHsMci$ > > > > From what I can see these calls are also supported on OpenBSD and > > NetBSD. > > > > So this is somewhat similar to what linux does if both user and sys time are > requested, getting a clock and then using that method? Yes, it seems we could in practice use mostly the same code. It is tempting to try to move it to os_posix.cpp, except that AIX does it in a completely different way :) > When getting user time only, Linux seems to parse > /proc/self/task//stats or so file, not sure if that is possible on BSD > too. It requires that procfs is mounted, which it may not be. (Currently the BSD port relies on procfs for some other stuff as well, but we're hoping to get away from it.) > > If that's ok, I'm happy to try to implement it. Is there a test that can > > be used to check the implementation? > > > jcmd Thread.print on a java process should print lines like: > > "G1 Refine#3" os_prio=0 cpu=22.28ms elapsed=90.86s tid=0x0000f56fbc21f000 > nid=0x75f4 runnable Thanks, I'll look into it. Take care! Harald From harald+jdklists at volse.no Sat Jun 21 12:03:02 2025 From: harald+jdklists at volse.no (Harald Eilertsen) Date: Sat, 21 Jun 2025 14:03:02 +0200 Subject: Getting per-thread CPU time on *BSD In-Reply-To: References: <97c3f636-5fed-4fd3-a104-afeda353ec22@oracle.com> Message-ID: Hi, A quick update on my part. I have figured out how to get both user time and user+sys time on FreeBSD. https://git.anduin.net/haraldei/bsd-thread-time-example This is quite similar to the OpenBSD code by Kurt Miller that was already in the BSD port tree. I have a local patch based on that which replace the existing FreeBSD code with combined code for OpenBSD and FreeBSD. I will need help from someone to add support for NetBSD, though. I'm a bit unsure about what to do next however. Do you want me to submit the changes to the OpenJDK mainline repo? It won't in itself fix BSD support for OpenJDK, but could be one of the many steps on the way. In any case, it should be safe to go on with whatever needs you have for this information, we are able to provide it on the BSD's as well. H! From thomas.schatzl at oracle.com Mon Jun 23 07:46:49 2025 From: thomas.schatzl at oracle.com (Thomas Schatzl) Date: Mon, 23 Jun 2025 09:46:49 +0200 Subject: Getting per-thread CPU time on *BSD In-Reply-To: References: <97c3f636-5fed-4fd3-a104-afeda353ec22@oracle.com> Message-ID: Hi Harald, thanks for your effort! On 21.06.25 14:03, Harald Eilertsen wrote: > Hi, > > A quick update on my part. > > I have figured out how to get both user time and user+sys time on > FreeBSD. > > https://urldefense.com/v3/__https://git.anduin.net/haraldei/bsd-thread-time-example__;!!ACWV5N9M2RV99hQ!KBbaClb29ZBzy6EdTYhJCvZr14QJva2hOK77xk4iHj9UsZiM0q2WpJzM2-Yy0rIrpBA6ueo4LvMJJ90zr-K7IDN-PeWZ-p-s$ > > This is quite similar to the OpenBSD code by Kurt Miller that was > already in the BSD port tree. I have a local patch based on that I did not know somebody maintained the BSD port outside of mainline. That may make the issue more complicated. > which replace the existing FreeBSD code with combined code for OpenBSD > and FreeBSD. I will need help from someone to add support for NetBSD, > though. > > I'm a bit unsure about what to do next however. Do you want me to submit > the changes to the OpenJDK mainline repo? It won't in itself fix BSD > support for OpenJDK, but could be one of the many steps on the way. I would go that way if possible and try to keep mainline up to date. However if mainline does not build/work at all, then this effort would probably just contribute to more untested code. Unfortunately I do not know the exact state of the BSD ports. > > In any case, it should be safe to go on with whatever needs you have for > this information, we are able to provide it on the BSD's as well. > Thanks again. Thomas From thomas.schatzl at oracle.com Wed Jun 25 11:48:58 2025 From: thomas.schatzl at oracle.com (Thomas Schatzl) Date: Wed, 25 Jun 2025 13:48:58 +0200 Subject: Getting per-thread CPU time on *BSD In-Reply-To: References: <97c3f636-5fed-4fd3-a104-afeda353ec22@oracle.com> Message-ID: <6cba220f-f33b-4b37-a425-bffdda7e5e96@oracle.com> Hi Harald, On 23.06.25 09:46, Thomas Schatzl wrote: > Hi Harald, > > ? thanks for your effort! > > On 21.06.25 14:03, Harald Eilertsen wrote: >> Hi, >> >> A quick update on my part. >> >> I have figured out how to get both user time and user+sys time on >> FreeBSD. >> >> https://urldefense.com/v3/__https://git.anduin.net/haraldei/bsd- >> thread-time-example__;!!ACWV5N9M2RV99hQ! >> KBbaClb29ZBzy6EdTYhJCvZr14QJva2hOK77xk4iHj9UsZiM0q2WpJzM2- >> Yy0rIrpBA6ueo4LvMJJ90zr-K7IDN-PeWZ-p-s$ >> >> This is quite similar to the OpenBSD code by Kurt Miller that was >> already in the BSD port tree. I have a local patch based on that > > I did not know somebody maintained the BSD port outside of mainline. > That may make the issue more complicated. actually it looks like there is at least a JDK 21 port which has the necessary infrastructure implemented. I did not notice because it is maintained out of tree (link shows the changes for os::thread_cpu_time() here: https://github.com/battleblow/jdk21u/blob/bsd-port/src/hotspot/os/bsd/os_bsd.cpp). Not sure how to proceed here for adding the suggested changes to mainline. However it seems that these are the "official" changes, and probably we in the gc team will actually assume that the functionality is there and we may not provide workarounds in the future when depending on this, even if it's not in mainline. Just out of curiosity, do you happen to know why the changes for *BSD are not upstreamed? Thanks, Thomas From harald+jdklists at volse.no Wed Jun 25 14:23:50 2025 From: harald+jdklists at volse.no (Harald Eilertsen) Date: Wed, 25 Jun 2025 16:23:50 +0200 Subject: Getting per-thread CPU time on *BSD In-Reply-To: <6cba220f-f33b-4b37-a425-bffdda7e5e96@oracle.com> References: <97c3f636-5fed-4fd3-a104-afeda353ec22@oracle.com> <6cba220f-f33b-4b37-a425-bffdda7e5e96@oracle.com> Message-ID: Hi Thomas, On Wed, Jun 25, 2025 at 01:48:58PM +0200, Thomas Schatzl wrote: > actually it looks like there is at least a JDK 21 port which has the > necessary infrastructure implemented. Yes, you'll also find the same in the latest update repo for FreeBSD: https://github.com/freebsd/openjdk/blob/jdk24u-freebsd/src/hotspot/os/bsd/os_bsd.cpp#L2609 However, this implementation does not provide for getting only user time except for OpenBSD (and presumably OS X), unless it's a request for the timing of the current thread. I have improved on that, so it should also fully work on FreeBSD. I'll include that in the JDK 24.0.2 release and in my fork of the mainline repo. > Not sure how to proceed here for adding the suggested changes to mainline. Me neither, I hope to be able to upstream the full port some time, but it will have to happen in increments. > Just out of curiosity, do you happen to know why the changes for *BSD are > not upstreamed? No, I don't know why, only that's where we are. I am contracted by The FreeBSD Foundation to try to get the port(s) upstreamed. So far it's been a lot of cleanup, and catch up to get everything ported on top of the mainline repo. :) Best regards, Harald From thomas.schatzl at oracle.com Thu Jun 26 11:55:48 2025 From: thomas.schatzl at oracle.com (Thomas Schatzl) Date: Thu, 26 Jun 2025 13:55:48 +0200 Subject: Getting per-thread CPU time on *BSD In-Reply-To: References: <97c3f636-5fed-4fd3-a104-afeda353ec22@oracle.com> <6cba220f-f33b-4b37-a425-bffdda7e5e96@oracle.com> Message-ID: Hi Harald, On 25.06.25 16:23, Harald Eilertsen wrote: > Hi Thomas, > > On Wed, Jun 25, 2025 at 01:48:58PM +0200, Thomas Schatzl wrote: >> actually it looks like there is at least a JDK 21 port which has the >> necessary infrastructure implemented. > > Yes, you'll also find the same in the latest update repo for FreeBSD: > https://urldefense.com/v3/__https://github.com/freebsd/openjdk/blob/jdk24u-freebsd/src/hotspot/os/bsd/os_bsd.cpp*L2609__;Iw!!ACWV5N9M2RV99hQ!NOYYAR0rODCedfhq33DuAWwlenmBRQUMpw2ViZNgd34uafcKc0KBA_77dZc1wwPk6In2YGb7X_pe0ABnhHROAzR-U_4CueGo$ > > However, this implementation does not provide for getting only user time > except for OpenBSD (and presumably OS X), unless it's a request for the > timing of the current thread. > > I have improved on that, so it should also fully work on FreeBSD. I'll > include that in the JDK 24.0.2 release and in my fork of the mainline > repo. For GC we only need user+sys time, so that would be sufficient. The only user of user-only time seems to be Java's ThreadMXBean. However an implementation may not support getting another thread's user time afaict (https://docs.oracle.com/en/java/javase/24/docs/api/java.management/java/lang/management/ThreadMXBean.html#getThreadUserTime(long), see the remark in the UnsupportedException description). > >> Not sure how to proceed here for adding the suggested changes to mainline. > > Me neither, I hope to be able to upstream the full port some time, but > it will have to happen in increments. > That would be great, and doing this incrementally is understandable (and favorable to reviewers :)). Thomas From glewis at eyesbeyond.com Sun Jun 29 21:26:38 2025 From: glewis at eyesbeyond.com (Greg Lewis) Date: Sun, 29 Jun 2025 21:26:38 +0000 Subject: CFV: New bsd-port Group Member: Harald Eilertsen Message-ID: <01010197bd95c584-3c9dbff5-4d50-4fc3-8b5a-6df47f58dbdd-000000@us-west-2.amazonses.com> |I hereby nominate Harald Eilertsen to Membership in the bsd-port Group. Harald has been working on both improving the BSD port of OpenJDK and preparing it for upstreaming. His membership of the group will help him drive upstream changes. Votes are due by July 13th, 2025. Only current Members of the bsd-port Group [1] are eligible to vote on this nomination. Votes must be cast in the open by replying to this mailing list For Lazy Consensus voting instructions, see [2]. Greg Lewis [1] https://openjdk.org/census#bsd-port [2] https://openjdk.org/groups/#member-vote| -------------- next part -------------- An HTML attachment was scrubbed... URL: From harald+jdklists at volse.no Mon Jun 30 14:19:23 2025 From: harald+jdklists at volse.no (Harald Eilertsen) Date: Mon, 30 Jun 2025 16:19:23 +0200 Subject: Support for -XX:AllocateHeapAt on ZFS? Message-ID: Hi everyone, I tried asking this on the freebsd-java list too, but did not get a response, so trying here instead: The code backing the `-XX:AllocateHeapAt=path` option to java calls the function posix_fallocate on most systems to reserve the space for the file in the file system. This will fail and return `EINVAL` if the underlying file system does not support the operation. On FreeBSD this is particularly relevant because the commonly used ZFS file system does not support this operation. For rationale see: https://freebsd-current.freebsd.narkive.com/5pbDPeIT/heads-up-posix-fallocate-support-removed-from-zfs-lld-affected https://lists.freebsd.org/pipermail/freebsd-current/2018-February/068447.html On OpenBSD the ftruncate function is used instead, and MacOSX will attempt to set the size via fcntl, but falls back to ftruncate if that does not work. To make things even more interesting, the glibc implementation of posix_fallocate used on most Linux based systems deviates from the posix standard by 'emulating' the feature if not supported by the underlying file system. https://www.man7.org/linux/man-pages/man3/posix_fallocate.3.html#CAVEATS My question is: Do we want to keep the strict posix compliance on FreeBSD, which in practice means this feature is not supported on ZFS, or do we want to be less strict like the other platforms mentioned above? Also, if someone can comment on the rationale for OpenBSD implementation, that would also be helpful. Thanks in advance, Harald Eilertsen From glewis at eyesbeyond.com Mon Jun 30 14:38:44 2025 From: glewis at eyesbeyond.com (Greg Lewis) Date: Mon, 30 Jun 2025 14:38:44 +0000 Subject: CFV: New bsd-port Group Member: Harald Eilertsen In-Reply-To: <01010197bd95c584-3c9dbff5-4d50-4fc3-8b5a-6df47f58dbdd-000000@us-west-2.amazonses.com> References: <01010197bd95c584-3c9dbff5-4d50-4fc3-8b5a-6df47f58dbdd-000000@us-west-2.amazonses.com> Message-ID: <01010197c146ae0e-8a1cefea-0645-465c-a41a-74694d0edfa0-000000@us-west-2.amazonses.com> I'll post a new CFV shortly with Group corrected to Project. Sorry for the noise regards, Greg On 6/29/25 2:26 PM, Greg Lewis wrote: > I hereby nominate Harald Eilertsen to Membership in the bsd-port > Group. Harald has been working on both improving the BSD port of > OpenJDK and preparing it for upstreaming. His membership of the group > will help him drive upstream changes. Votes are due by July 13th, > 2025. Only current Members of the bsd-port Group [1] are eligible to > vote on this nomination. Votes must be cast in the open by replying to > this mailing list For Lazy Consensus voting instructions, see [2]. > Greg Lewis [1] https://openjdk.org/census#bsd-port [2] > https://openjdk.org/groups/#member-vote From glewis at eyesbeyond.com Mon Jun 30 14:39:11 2025 From: glewis at eyesbeyond.com (Greg Lewis) Date: Mon, 30 Jun 2025 14:39:11 +0000 Subject: CFV: New bsd-port Project Member: Harald Eilertsen Message-ID: <01010197c14718db-a2a99d21-f7df-4b8a-86ec-079b8866279c-000000@us-west-2.amazonses.com> |I hereby nominate Harald Eilertsen to Membership in the bsd-port Project. Harald has been working on both improving the BSD port of OpenJDK and preparing it for upstreaming. His membership of the project will help him drive upstream changes. Votes are due by July 14th, 2025. Only current Members of the bsd-port Project [1] are eligible to vote on this nomination. Votes must be cast in the open by replying to this mailing list For Lazy Consensus voting instructions, see [2]. Greg Lewis [1] https://openjdk.org/census#bsd-port [2] https://openjdk.org/groups/#member-vote| -------------- next part -------------- An HTML attachment was scrubbed... URL: