From 98e2ea18afa8c8b5078ff57f44543fc9b7a69337 Mon Sep 17 00:00:00 2001 From: Emma Walker <35726386+EmmaChronicle@users.noreply.github.com> Date: Fri, 1 Jun 2018 14:15:15 +0100 Subject: [PATCH 001/353] Update README.md added image --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 45b93b80d..4b6b3b5ed 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,12 @@ Thread Affinity ============= + +![alt text](https://chronicle.software/wp-content/uploads/2018/02/Thread-Affinity_line.png) + +## Version [![Maven Central](https://maven-badges.herokuapp.com/maven-central/net.openhft/affinity/badge.svg)](https://maven-badges.herokuapp.com/maven-central/net.openhft/affinity) +## Overview Lets you bind a thread to a given core, this can improve performance (this library works best on linux). OpenHFT Java Thread Affinity library From ae54d1bf738ab1ccb6348747fbda2648d4a4becf Mon Sep 17 00:00:00 2001 From: Emma Walker <35726386+EmmaChronicle@users.noreply.github.com> Date: Fri, 1 Jun 2018 14:17:43 +0100 Subject: [PATCH 002/353] Update README.md can't size image need to convert to adoc. --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 4b6b3b5ed..d7273fc9f 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,6 @@ Thread Affinity ============= -![alt text](https://chronicle.software/wp-content/uploads/2018/02/Thread-Affinity_line.png) - ## Version [![Maven Central](https://maven-badges.herokuapp.com/maven-central/net.openhft/affinity/badge.svg)](https://maven-badges.herokuapp.com/maven-central/net.openhft/affinity) From 119cb8023ace92beb5a30d75de02ac440445144e Mon Sep 17 00:00:00 2001 From: Emma Walker <35726386+EmmaChronicle@users.noreply.github.com> Date: Mon, 4 Jun 2018 11:31:39 +0100 Subject: [PATCH 003/353] Rename README.md to README.adoc changed to adoc --- README.md => README.adoc | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename README.md => README.adoc (100%) diff --git a/README.md b/README.adoc similarity index 100% rename from README.md rename to README.adoc From 43561ae115ae85a6396af775bb166881f599852f Mon Sep 17 00:00:00 2001 From: Emma Walker <35726386+EmmaChronicle@users.noreply.github.com> Date: Mon, 4 Jun 2018 11:51:19 +0100 Subject: [PATCH 004/353] Update README.adoc updated to adoc format --- README.adoc | 93 +++++++++++++++++++++++++++++------------------------ 1 file changed, 51 insertions(+), 42 deletions(-) diff --git a/README.adoc b/README.adoc index d7273fc9f..529566597 100644 --- a/README.adoc +++ b/README.adoc @@ -1,32 +1,34 @@ -Thread Affinity -============= += Thread Affinity -## Version -[![Maven Central](https://maven-badges.herokuapp.com/maven-central/net.openhft/affinity/badge.svg)](https://maven-badges.herokuapp.com/maven-central/net.openhft/affinity) +=== Version -## Overview +[#image-maven] +[caption="", link=https://maven-badges.herokuapp.com/maven-central/net.openhft/affinity] +image::https://maven-badges.herokuapp.com/maven-central/net.openhft/affinity/badge.svg[] + +=== Overview Lets you bind a thread to a given core, this can improve performance (this library works best on linux). OpenHFT Java Thread Affinity library -See [affinity/src/test/java](https://github.com/OpenHFT/Java-Thread-Affinity/tree/master/affinity/src/test/java) +See https://github.com/OpenHFT/Java-Thread-Affinity/tree/master/affinity/src/test/java[affinity/src/test/java] for working examples of how to use this library. -## Wold Wide Usage -[Thread Affinity usage Heatmap](http://jrvis.com/red-dwarf/?user=openhft&repo=Java-Thread-Affinity) +==== Wold Wide Usage +http://jrvis.com/red-dwarf/?user=openhft&repo=Java-Thread-Affinity[Thread Affinity usage Heatmap] -## Changes +==== Changes - - V3.1.1 - Upgraded JNA dependency to 4.4.0 - - V2.0.1 - Added getThreadId for the process if of the thread. +* V3.1.1 - Upgraded JNA dependency to 4.4.0 +* V2.0.1 - Added getThreadId for the process if of the thread. -## Dependencies +=== Dependencies -Java-Thread-Affinity will try to use [JNA](https://github.com/java-native-access/jna) +Java-Thread-Affinity will try to use https://github.com/java-native-access/jna[JNA] to provide access to native thread-handling functions. JNA should be installed on your system to get the most from this library. -### JNA version +==== JNA version Java-Thread-Affinity currently depends on JNA version 4.4.0, which in turn depends on a version of GLIBC >= 2.14. If your operating system is an old one, @@ -36,15 +38,15 @@ invoke native functions. To work around this problem, fork the repository, and override the `` tag for the artifacts `jna` and `jna-platform` in the project's `pom` file. -### Installing JNA on Ubuntu +==== Installing JNA on Ubuntu sudo apt-get install libjna-java -### Installing JNA on CentOS +==== Installing JNA on CentOS sudo yum install jna -## How does CPU allocation work? +=== How does CPU allocation work? The library will read your `/proc/cpuinfo` if you have one or provide one and it will determine your CPU layout. If you don't have one it will assume every CPU is on one CPU socket. The library looks for isolated CPUs determined by looking at the CPUs you are not running on by default. @@ -55,7 +57,7 @@ To control which CPUs a process can use, add -Daffinity.reserved={cpu-mask-in-he Note: the CPU 0 is reserved for the Operating System, it has to run somewhere. -## References +=== References https://github.com/peter-lawrey/Java-Thread-Affinity/wiki/Getting-started @@ -63,7 +65,7 @@ https://github.com/peter-lawrey/Java-Thread-Affinity/wiki/How-it-works http://vanillajava.blogspot.co.uk/2013/07/micro-jitter-busy-waiting-and-binding.html -## isolcpus +=== isolcpus Java-Thread-Affinity requires that you first isolate some CPU's. @@ -73,36 +75,41 @@ To isolate the 1st and 3rd CPU cores (CPU numbers start from 0) on your system, isolcpus=1,3 -## Acquiring a CPU lock for a thread +==== Acquiring a CPU lock for a thread You can acquire a lock for a CPU in the following matter In Java 6 - +[source, java] +---- AffinityLock al = AffinityLock.acquireLock(); try { // do some work locked to a CPU. } finally { al.release(); } +---- In Java 7 or 8 - +[source, java] +---- try (AffinityLock al = AffinityLock.acquireLock()) { // do some work while locked to a CPU. } - +---- You have further options such as -## Acquiring a CORE lock for a thread +=== Acquiring a CORE lock for a thread You can reserve a whole core. If you have hyper-threading enabled, this will use one CPU and leave it's twin CPU unused. - +[source, java] +---- try (AffinityLock al = AffinityLock.acquireCore()) { // do some work while locked to a CPU. } - -## Controlling layout +---- +=== Controlling layout You can chose a layout relative to an existing lock. - +[source, java] +---- try (final AffinityLock al = AffinityLock.acquireLock()) { System.out.println("Main locked"); Thread t = new Thread(new Runnable() { @@ -116,20 +123,20 @@ You can chose a layout relative to an existing lock. }); t.start(); } - +---- In this example, the library will prefer a free CPU on the same Socket as the first thread, otherwise it will pick any free CPU. -## Getting the thread id. +=== Getting the thread id. You can get the current thread id using int threadId = AffinitySupport.getThreadId(); -## Determining which CPU you are running on. +=== Determining which CPU you are running on. You can get the current CPU being used by int cpuId = AffinitySupport.getCpu(); -## Controlling the affinity more directly. +=== Controlling the affinity more directly. The affinity of the process on start up is long baseAffinity = AffinityLock.BASE_AFFINITY; @@ -143,12 +150,13 @@ If you want to get/set the affinity directly you can do long currentAffinity = AffinitySupport.getAffinity(); AffinitySupport.setAffinity(1L << 5); // lock to CPU 5. -## Debugging affinity state +=== Debugging affinity state For a detailed of view of the current affinity state (as seen by the library), execute the following script on Linux systems: -``` +[source] +---- # change to the affinity lock-file directory (defaults to system property java.io.tmpdir) $ cd /tmp @@ -163,27 +171,28 @@ $ for i in "$(ls cpu-*)"; pid 14584's current affinity list: 3 /opt/jdk1.8.0_141/bin/java ... -``` +---- -# Support Material +== Support Material -[Java Thread Affinity support group](https://groups.google.com/forum/?hl=en-GB#!forum/java-thread-affinity) +https://groups.google.com/forum/?hl=en-GB#!forum/java-thread-affinity[Java Thread Affinity support group] For an article on how much difference affinity can make and how to use it http://vanillajava.blogspot.com/2013/07/micro-jitter-busy-waiting-and-binding.html -# Questions and Answers +== Questions and Answers -## Question +=== Question I am currently working on a project related to deadlock detection in multithreaded programs in java. We are trying to run threads on different processors and thus came across your github posts regarding the same. https://github.com/peter-lawrey/Java-Thread-Affinity/wiki/Getting-started Being a beginner, I have little knowledge and thus need your assistance. We need to know how to run threads on specified cpu number and then switch threads when one is waiting. -## Answer +=== Answer Use : -``` java +[source, java] +---- AffinityLock.setAffinity (1L << n); -``` +---- where n is the cpu you want to run the thread on. From 6f38106bd53ce8d01dcb3786a402082e0276a50c Mon Sep 17 00:00:00 2001 From: Emma Walker <35726386+EmmaChronicle@users.noreply.github.com> Date: Mon, 4 Jun 2018 11:57:58 +0100 Subject: [PATCH 005/353] Update README.adoc adoc corrections --- README.adoc | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/README.adoc b/README.adoc index 529566597..00e899a97 100644 --- a/README.adoc +++ b/README.adoc @@ -128,28 +128,33 @@ In this example, the library will prefer a free CPU on the same Socket as the fi === Getting the thread id. You can get the current thread id using - +[source, java] +---- int threadId = AffinitySupport.getThreadId(); - +---- === Determining which CPU you are running on. You can get the current CPU being used by - +[source, java] +---- int cpuId = AffinitySupport.getCpu(); - +---- === Controlling the affinity more directly. The affinity of the process on start up is - +[source, java] +---- long baseAffinity = AffinityLock.BASE_AFFINITY; - +---- The available CPU for reservation is - +[source, java] +---- long reservedAffinity = AffinityLock.RESERVED_AFFINITY; - +---- If you want to get/set the affinity directly you can do - +[source, java] +---- long currentAffinity = AffinitySupport.getAffinity(); AffinitySupport.setAffinity(1L << 5); // lock to CPU 5. - +---- === Debugging affinity state For a detailed of view of the current affinity state (as seen by the library), From 6cd934db49577f708cc9200bda0c54044458a773 Mon Sep 17 00:00:00 2001 From: Emma Walker <35726386+EmmaChronicle@users.noreply.github.com> Date: Tue, 5 Jun 2018 12:10:17 +0100 Subject: [PATCH 006/353] Update README.adoc added image --- README.adoc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.adoc b/README.adoc index 00e899a97..b28dc3740 100644 --- a/README.adoc +++ b/README.adoc @@ -1,5 +1,7 @@ = Thread Affinity +image::https://chronicle.software/wp-content/uploads/2018/02/Thread-Affinity_line.png[width=20%] + === Version [#image-maven] From 6f03a7f8fe90a81b2abd789678d3bab8a032e544 Mon Sep 17 00:00:00 2001 From: Emma Walker <35726386+EmmaChronicle@users.noreply.github.com> Date: Wed, 6 Jun 2018 10:59:28 +0100 Subject: [PATCH 007/353] Create a.txt --- images/a.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 images/a.txt diff --git a/images/a.txt b/images/a.txt new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/images/a.txt @@ -0,0 +1 @@ + From 1ccf9b66f9f57d4b4664b7a5e27572ba5166d61f Mon Sep 17 00:00:00 2001 From: Emma Walker <35726386+EmmaChronicle@users.noreply.github.com> Date: Wed, 6 Jun 2018 10:59:41 +0100 Subject: [PATCH 008/353] Add files via upload --- images/Thread-Affinity_line.png | Bin 0 -> 18161 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 images/Thread-Affinity_line.png diff --git a/images/Thread-Affinity_line.png b/images/Thread-Affinity_line.png new file mode 100644 index 0000000000000000000000000000000000000000..2f80359d200dabe76c42ea3c5a520d3b5362390f GIT binary patch literal 18161 zcmZU*Wmp@}_dcB9PH=bk;_ks+3zXs%ch?4Yio3hJ7k4NQ1&T{4ZpE$q^Z7p4@741n zn_StM-JO|Z_kGT6l)9=MItnog002N&kOyl50KmfkK1c}AV_&_nHuMCtv%J0=06>8C z-v>BJe$G4bo9@^Qe-E}*JLJFP_B0xS#04ifR+`#w}8 z^!nj#=D6cd2!kUR{cGd|<>%h&p~{ed5P!7Mk6(3-&vIYy-8XvMM4#l}wUMxczwM-S&Oo94+}{&*}I9#*;5le(Z04 zlxnXJ@%U*SX1eg!>Hb<9W;yWa8EO6ybe_vxHH4YZ0YA(2|(zE(zgq|IPyICE#u*>3O0V~5Gaq%86h9o_HzV zJ)!N?`VW)j3HVSoo9d;=b$5&~_3@tW{l(HNxRHYA6$rj{fArBH>%9>_O%$8y^^!%R zTfgIfU0)Hham%r~5WX{wPoDZ)yy_!$>()e)(s{A;eXH+ujv@P0?vCR7Y@r(8%lf7J zhU%JaoyfCB(4Vg#fzSS-%eP3pm%?Q2=~T};IftgNr|P|(nUq!6bz`?j8`G6E_b=D= zTcP9$9NKCt73+d$&Kn;*g&%YY*tPRNVeBoK8`CBJBl~dR`LFI}116vQmcyK*l}WVq zp~ql%4ft)$A#*8xW%(n8s8>tc1X0*GJc&^o>K})F>5sE2x`*{q)^cFA?{|fQJL!W2 z)V^*)jt_;ZO*sP5yAzN3MPmbnU#lxg%#vwCs3t|Cm1R(_0|5YWZ@j53`=L;^^8Nds zdd|l=hViQ%b+P5K?uw97H9C2%~yM7_ulKvjUbM+3ON zO(yWVRSicwIuJK5o0)gAbB&J=%&3@6jiS2Cpu{|ma8qLRjbeP0n|a8t71p=m5?JJP ze);_HE+_>TekwoHWgRORs4n>UZcL?iPf@h<_a<`DJ0foo*_CBM;8%4ggzfz2(6r)gb+QM7DQzQ)%j>Fc#y@O;#+7=; zChz^1;oHUWn~y@FiL!VvDWzRre|zdxRcNAnO!w3pjy{p9_!F#$2qAn^u}L@)Dd+Gt zR*uet{i}KRWN{rW_=c_}-(6YE4gYU1>_<^LM@gNji&bY$I;*gBT zDk#xSgW-50DUQ}9>h4ME?9Uyp_IIjY8nCHv{%Sbj?+Lo~=MEk^6tfC&L6VR|2FHfoiDJ$GQzo8U6vnsZ@3r^wV5#ktsM~cKei8;-&mFx^RtcLoibUSe!J! z;vc$66z;sLT*q_LPdz2zr}`Gt>GQZ$TMJ(Mhz=3f5Gg0k+*a7`HSG7fbxML4 z;jQ2EEO8y(fg@I?3PUIGmJgRXW`HuJ6s*(KMotVm1#NgLs*_b%q@cFRVaTtZ(X`)J z#M}dn5oT@FlkETdEx-X+GGykYx$8m^w#s@>Kd&s@J{`oKs(osroT`4jE_=iuVozjW#*v=ji^WLq!H7NlVNl@MZ5m{#l(-1 zmz~;Ie+$pohhOW;I!(K~auF4Td)ai4gorVzR()1gTj%ss4TB4K8dE`m0+5REO9=ml zg6jdV`|a(~_eRgC`JURAe+!MSRDOGwN3o7e&M2S82t!l0JbH+;ca&2ld}Mt#E1KT( zhm#kd`Hx&{YAxP}t%kWPLY-26Uf^*uRt9z}SSV!w+H^NlZ# z53HT8GE+KZxDuux579)!UlvDNsa`}`=CqaHg?$6rtk5V8`4UNvi2F+4*Yv${8r zbf2<*W)9n^1Yy)s7_-Fw{rX#6Rh>C3le zON7#?&uwM2BiQnj{3_g~D`l0Tl=o=zI(Ctfdm9~CBrF{*v56ZvBA)vQ8#wb;6C)(5 zvkX^V-&!$~zAI>586^JD1Z!79!xVrkP4z@@L==q1m*g-Dr-aE=+~}0J!xDrq4ekA8 ztzkBHrhUS;4n=VVKAL`bv@Rj^x++d;V-5*=@Tu<&YA8u~4gj3`2K_f<@FYwx=5V(L z=c{oS$<3eNF4e*W?#YRS{I-sm55KBe!&V|OHivi)Gpqy?i`YFE_+`WPcC$+N-bqn? zhA8m;BU;rfZncjP+4K%WuqVN&Ray1kG;p8lknrjoqN|?VUR5v2>JI+6hyLp^vg1TU zc=0{vk2u;57onAS!O*$K+jz7V>Ix^}rd{H_(kS80%wDuSmf1oZwu7s&L-V@LPA-ZW zJydc1DcR^W6EDkLH>~*CgpzJGX?nU4#bnU)P{n1i|9D+vL_)C!Fg_1!l`0bTJfkk>azuMR>KE;S9w& z=@0%DI;sRHvwkE`W(l`nXl3?DQi8XLXol@-DliCo9lL79ur~_^s?Rg)K3jD6jUxC? z`J{h1>4`6`7pjE2Gj@pkmGO6U?4L|eFT3A6-saf^$r6WC+Fo^BWFSt93rg|c_9jPx zHJeJv$4v_l4h5Ak^!LqGH0$wx-kStov2iTlRdLS-fiEP@_kCMWwQUin_#}Sk?C$Gp zgjezOD5R&p}^9GizG&$fd=5cS-(|bdEivj;jJ#n_QTSF^3 zRJ%07x}i`T3AXD}L4d4X4Mrv@UbT7F$R!|Och4w<+mCU0k!(#soUA>66iqi3P64|@ zlQOInqrSq(&Ah(jcN)&~aO?(hztO{h-sU;&q*`4Nr?6W`#OaahHKj;MX)ZVN+B9EM zKiXGoS&_ff$3`xK=aHqwv7!L!6eHhFcII@+2rkSdkD?UyH9e&*n*~N+dcH2CO1kZW zGtWuwYv+(?cn67W;Q%WS<6u`mEAfQuSe3E57rA$Y)Mm^fii2^hJ7x2$iI4_X8N@h+ zukm8vn_k8=9n}T@{t|aXr-oDNlr&#zMBEwNb5g%By4-M5kAEJCgnn_QVu@;by+3|C zF_C>0-K13_4_x`GjmTXTFA9+m86FqiC?FMG?NkG}-;$Mgo)(NWkCUVnJJnrMo)>pZ zqF&jjHzJw@aiPmFNG`-BYSPKgzRG$ydxxZfVkA<^;XFhp|9HEHxaLfF9Bu7(aw=bw zD($SnQ^Xm2Li;IckhSbCn>TlC1QY7`mgo6_(yU{gD;(A9N|TjF8f&^~s+6OfNtV7M z{;^g=t1!njiLP`$Ws>&bkrDCWa)Cb|6*1u=H%1aMh~s2!EfUpAj6&JPbS= znultL*=}LRreR7W;)f9lU)djL^2;H%|Af=s*@tt!(=dpGcE;+=e1E z+0PPrK=n9~3ao_LG_VBO{g--^_NqfoUE))Q$@Rz4u+t(X1+u^ylVzBBi2d znq3N*i?*|tC2{h$1mj{uxt(UpZa$;8ObeY9=dzhoVpRbM{5BLf3VF%9qkqMu5gO9l zX$rqyvho(BdnboyzhZ|yk=>!cj@j=?hRFeE>twCZwf8)<|9K<;K%&mV5}ggc z?L?9KIn_Y!JUg#A#TaY;ldB){Mqd1SNxT2Ifs?Rt*UW}O z&r+rzk>YrUt@kvUsK0EB{(96XM#9b0NE6$d2V{fxCxD*88wrLTNs;}T$s?$V>;f8+ z(qInFjKI>F4^a-mB_SUE4FXgPVFoOEZ#=^c2#b66f0;^Hr6QwGuHx68UJ0wSzYGVv z;q=Yl;$Dqli$H#%B&zRQWM8z?YFEafH2qZng`7w!P5rAz?5bglPxseNpt=W}PZNlG z>)4WifmW|g1Svv7x+f7=Jzix&il@+{;i{dIzPmzUy?FvTvC3oyVt+VelEw7kV~acn zMn;|wy|Um}L%4{Y25VxM9l>UT@^oqskUrnV75|aFn<};r&f11r)ifnQbZm|q z;WvNkm+gd4R#>8y*m`NyP%`*XKi z7GhL?U1nFI(pS*sX>VK`z3AdMyJ9B(3iXTP2-zF(yYEt-80R#9oPG{$!Ibc*bEoFg zSVfdKIpNN3L_mQh($f_DJQzwClw%d7gD8po-}qj)>+RL(%zsKWC&gM-%L=!x<7YTV|65Lcp zdCy4$yFvg&$s;YXUZ-=NDNbf~jMHuplMh?vTcOs&J|DhslTVEucl1D!zS?8ZPZ>=x z4kP(WrtB?~{LEq}7J<2IP*KnM_C;mwax;a^_d>qQ1Ho30RikeQOz2ey8LC8q+}6V3 z3zCxV_(YtYhgz2gyh~-YOIi$vd}@y`T@nkw%Kf2uyp{P|C3HfHE+uNK^ODzY9rkK( ztTCk)8UI%15XQ0iy2q7QU>M757IFFXXqXi9=Zw!8A(vO~gp6PxAVyVvN<~QGrQhWi{nl!*8IjUw3|gGYL_=rpsjA z$}RNdigmD>QeX78Gd!nZ^Dkm6=5jVucHDX7;gT<*9IS{ww^wV|drm{Uzw#mbgvqvR z8}ioQuiI*DTTL&|UeEgHKgWCV@EM|XF^3M9W*$+Aqf}<161eh0k7`uT2=q^axkHVs zhM1~cKC~oy#Sf{6EBDS15b?%cD%?H{AJRVhV0L&J2rrV=rJumF)Bv;I`Ya3LXyO)NsH8P$B$Y&&@7Cz*P2%ZcA8uD7 z^o;+`q8R=it^0}8$u5P{L)(7K{wKla6QVMq?(8)!<`ULh3hVt z3_v|@an!_VT(Kd~&c$>^%Yq0E0(eUGw3YSIAh~Qj} z(}mQ((iBMSS1!snWGf%;yj?4uUu`Zd5<+s~E?`SRHrgw;lS?yj-8MEf_fn@k^Xt37 zsm>lPOw3SKMOayXa`L%Nid>LPJw+Rg_Ts+lg(QHNxb!-r%HfJ@P$F(L^|{*8t93{n zLV7UB63WQt{;6CU_+m>=2_{lk<&|iW@|B4ETTDt0S!7@b6}|RL*_la1?rDDVx7znX zlTfV{LZXU}iIX||W#tP6cl{E`<1RT?iV*@%Kb zHF$Jkil{2O9Z73o>4zD`2!k`J3v?FCqeTZXdp*n%=NP}ll<$N-!8 zRrCRbwKz7>zxqM~e#Z_^e-0-fUfUTDo!)7<#;+QE0u%E-r1HbUdM*vYI=e-L)z>p~ z4R~L&RhNjwQ4WYTf%pH2u@ndvT#F}p^q)#vNy5^5s#Ba!>8?zh4bW=A^Xz6eL*V6G z$t`*=YqWejR1-e5-aunNZ5W+d(fEyBrksyJ>c8sdlKib9%>x;YaWNVsn^>OI-r0k9 z*P0a;!@r!5i{De7btQV_1Xn22kiIwSsKQx6`{g$m+StMfn8Jq(z1Ew*}xT^kFD^cP#ocRQD?ugYVMspDrS#aX?9x2L(~ju z*_uvw7fb(&oGq^g<${xn9=p}f7a8Qs$%N2xPsV=7|MC6F(-7tSc57X?`*z$Rs`TMb zW)7vozj>D0^cQ-3#&@@w=pj%J3N_SS>y%GOqkuF_RF_ezhGq@G0>C^ z*{|5N8Em|UXwNrp?|Oe2WE}LKxN z3#_V;M=IJ%NQ`kQpD6n*(zRL_&x?vxFIXitS=8&F+(AV%*rGTM_j1i?zW9b~#5|8U z$8Zs*yrvXlj3SwF;4@#+TLzEX8z8;XI!$NX5O2c~YOSmH(B z)TOank5^}1Gu+DK2b5~AbAKem#NZTBk+QK*g91Vpx)+r@3L{wmWw9GYhF{TJmJWQ} zQbNt3%^5B9fp~7k^cfM8Gc_#A- zCv*}OM2V_rB9`E{r| za7xGOsFZ0WAP52$_4l2n%cB*Wa=%qI$c!}Xic{l1Q_VX9;3CNv(0UVcRov7ZfaCT_ z3mt>=!bt>}L`k0qhSh5fAge^q4%a_rRP0Dk>ALmYinf^H#~a+W#%wk7*%p6&6zutw z3eXpT*EP;w-^;31Owgs02q!*_UlWZ5VK0W1`xq;bd$yoR8ngh2)�o_%zX47mDoC zIW!??C)PNoVQ^07~>Ma zAq9aG-o!Gk;v62 z;Ru!t5`&)?n*yuZuoMy; zB_ZSS$oZGkK36%jqh6o2m!3_+5a#4mKKUnDo&%b^*_iVt9$8G;$4FC-_Z|t%wLKgjduwEhzX zS*n=7pU*+EN0ah4SgD<^!`RlkRSbg|;|g7#e$QB;nhX(2b8eN|b+P2dNJCb^JrJ6z z3tANjziL_JBSXjPp(;v$wGvtkF~zAFG>&i z@JBD>g-)a$VF7uzxfKbsxa%pIO3|=g^}vH!G?t0PyQ=KA*Cz`8@T!dPj})M z8m7E-%4%4^eUpBSbYV#SkkQ?*;oDV~W~8}s%;%Oi8L7NLG)~??ohP+AKVnP7dSGSU zrkg4irm8b=Z#p*xb6T^wGI5aFw);@Y0Bw23 zILz#5Ho2lME6ezSdlF;ZA3Q#>8)CH)*LRF6Q-IVV(`7wv%sf%qdcvsKeK^<$v2+fD~6o5UIoAI2v4D}-1A%Zn#=gs zj^I0i?IPnvg$mXDA7gaeCL*2QU7N+^C@Cg>8IO!w@C_8!uvQIaMrmkA*sWBFsS-zS zE?d=2ElplFC44Q+HxC$bk~%>DL)iNd{%d*6DNEIm+rJvWY9r8m`fA+<2K&}R{r86) zS(K!!ju&`zFaO$D>g->rX-RyVah8W`m8ZC>cL_`J0ls0pQ5S#m518UaAG2oNJ5>pY zXDy0PxA|*)JhQ&dRs}XS9M`2@qwYdk#6|}m{9fJ|hZ0mOH}vEte9Byw4+9&o^XJPi zcoLb7{O859xZ9~YFWXU7Ybt#G<$p=Fy2Or zVsAGESC#!8y9DfdGS(Mmh4|V6NMd*MmX5EM4aOBAviA8$tMD}iwb}J^#@IKQ2)dDzW8rg}7W#fEv(5rb; zK6I%ucUqajjJfE|`9;gBKA9e@BCo4<8rwseC)1Fv^Du8~`cn_WLqbZIOFPDY#MG)) zm$fz>m4CD>^=Rrd;b3RGqLP9+2VKd-*)6yAPqs1O6LOTFg8YN|W>d!UYQ8p6FS z|IURZeI(Cemp@nYrw!hOl(o(z6P|{3y*O$SPu&lqA%;RUU~yNjs>E{_R#CJZk}6b% zbRW9MnpaWJ&m=|N$TP%#$R;91(JBRjv9#e;q{gERBIGs5a$Y!d2P<8FXwVMl8pAte z&4o0SR$!#V>_(ZMD!ZhynVc+mV$jPZf;i;6ou`KnW!Y_v83*&i!Ob3JbHn^;^Z}9Z z^7|sI**R#d$(qi#5tMKYGPT^`g9Y|dW4^{9&mq{#t~zduj)X1-%%FJgg2kMPRUsIo zg{Q7R=*Q^{Udw@2?;{1)e4^3=p5jifCzu*5jv?gln&%IRD5UuC8~ zisCB{_bw4d;RI=R|1QOJKFRfGf)qq&7MM01y#cA7gM%>vUHm>=!koWL9Av#!4n45z z6hNnuOon+m@cCs&7US@7%eXxy^zib@xZ%endc;*W8x|?uVA$NJN6vtlc#B=UjKaT+ zYO>bmDCrCns}f3*`*AGgz5L7)#CZ6;U=c1@3v{eZgYcothB+=b4lyuP=tneg5r!4YO`V<6-wV~9B7dWG6 zaK9gdHD51`MV_O8BAWAiSy2%aY$?p(zvX+Ysw>{g5WYGZASFMK;+}G*dw&!NQAZ~O zx7`_zjbsy%9!6Uj6Bd-{hY=0K$_AEVlE`{`G&YTZA)ULpgRQA3MfV`C&?c2eQqv2J z5d~cJ>j&ZICd)BMSn+c&Di5`SN~vdqHJD;Ff6jqngBtpy5|D^VbOfa#1ngvBRk&$w z7}e0Ll&TO=fhB-JinatMlq3a1zDxK=!UNE8F+Y9BhW<~<^@&pA3CLk6RRLE4#gpj_NX}EN0BcGBDFiT5OinIg z;1wtV0XPF-aKAxmjvODfeymi$&mq_hgU2!Rz|{Ic2>hIcjcK!k!hc{B1CEicVKf<| zD4~)YxKQ(y5+4HO;=|t_@YMvD5FhnP$^nJ=8W92HjC66(r+%!4lPGZVm4~lD6GQ^I z!mEaMGe#hS$_WXOKme|kr%#}QZV5hH5!;`Vxd0{-*h?sL515%3uuJ&?F9g*5i4e}f zE@pWKtO?b0QPw9hVvwjBEnW|RWobalqTgG)QUr2UqNDZ0FqNXKkzL<2VJ#SU zz6X{nSbS|7h+%>LV}XDt?|m2(P%}W^0~?Um@91s9{MkYq!ZV6fM(6?^c>*df#j3;; zqze}~pF#gpd8q(*)U#(n0ly8)RbnSN_iCykx@a}~FF^qaB@(M-O1zS=fLIHyIV$6l zkegHCwttI3Oosl@rr8N0dfZut?XrJAR{|`EV6$>MxO2*!y|sKLd1u)V$%hT*y|;;vA5`GvOT)CQFbOFG7K2PG z@^;e~IAWldC61+Z8&Ot%;qY`WM305uk3Um&cczSF91A7b!ZubLK@JKr7sULM#gyTX z!uD2MO({%>qi}ZfcZ&7Isy6cZ>B$I@6I5FVGC}xYvllsTH?HLqJ|h90(0l%vKnQ7f z!E14rU{o$5*(i*=kRu0PgiFYfD_^NJZJTJxb3_LdLUDQI!9bjsnA=o*oWo7sj>XtEzDl2y$2R}5s z|7LR*H-f+IEojVyAMHJMRV=+NpsS4gf30#&8HhX3TgF43$e|xFJkY73jaVwU%aSx?rGb?S zPIqP$&|;3~<^D#cwCYme`!DZVD1sko7Nt8qy{qoLpS}xB4y{iub|qa(a@Eo7PHTk@ zNO5AB$Ylqs^^X9)HXC7PmrrAWkknF`Rwsh-u~|Yttk4($Zakq#sGH_)NhK9@66ysc zc0s3>GR^to4G{MHR9vO+O;7|;N|-ExQm9cU0)zgt8k-wXvg$v06<86UAOGocErQYB z##kqEIQ%CIVS$hEzbb)n8Etf$AM}!;5sU=@7b4c5)Bm86A7Sd7)~skG>CSk%=JmY8 z_?n+&%#YJ@s%x|zf+luDIqm(mG(k@*bs2lR%~+Epp?d%}_^?TLZBGoD zU84J_e6q6xN=2^B9U2oe(*Mm!Byjogy?mDS1=eLorugv)TD_*8an0ay2K)`z2hq8| z4Xn%BZ+2)XRp_OmUMm#2f{kp#ALKAfO+MIa>8e0&zEJ1qV(5`Y2T)UY#fd^lcS;j- zPnxmDbUtZm~3$-fcx2WYDmCAmJB$B#o&D!WMrGR@~o@XTagm zFgYvk*(x8QB73eWCxcCqJK<3IxG&$zboyO_gm!&)xn%}It-rgw(T(@~+2=*ofTrmx z2eRZy%5dD$`zqEqn%gbvpB`Tn$xu}-)6zzVTh3L^*tm*OK=UP_fX|=g-^XD&v+els zR&_+_MP7&^ifOw5SSl#<>3Fiv`8I{PSBCS2!w+UZIf7yuD1(ffX zp?$xtk2& zS@lR!_F#Qjtoav1f|zDJO6o)^MetH=Npgt9mHRn~ihWv6Q;dPsa>yk}88dQC3a1)% zJQg_Cs3Nn#VV2c{1f<3$sQ{yPx-fBJ{a8&btt~d^gjwQjt=fbQ{*7F?1H$SNBWsUg z&S??=p6ujO@&%V=tm#wd2;sEeRfeRk#*LW4M~+(?$fZn7dfBhK6th?hSX^V|$e^l6 zP%e1Mb0L4K>{p1Jbk#(;sQfH7{zY;rO$SLm!dazAP1<3}3&%{Pa)=|3gBFTCs}201 z^nwS{%D3Y4fvt zk`AhRJ~V|xOTE5F$BPv(BU2#Y@DDb#Pe7;%z2_Po&KjV0*_-e-^s|wnNZj0N+ST`! zf`^P>V1%soe&?jj##{m-yAyGlH5GfrWNX{b*;%|ieX30xLPkSk%TF7q8t8TJSkd~D z#QZxE8$?OPs!TEQnY(m`j86TUn}AXRzu{&V7Fsh@8Pq_pL@7aT667lfcAB_!=YT_R z#lRE*iU5EpaHv1yBLf-wJfo0#TjOH`N^UsFk<@8dAHS;Bjy}g>rVrMyygqC%*{0C9 zwPXGti}e5dhUkQh+XE1sm%5|TCz_HkE7)FmOZ0uCcmT>l*f76_I%8*#%aa~c*IKIC z-<7POJ9lixKau&b{;UqizK@=vnt%59~V zCJm@M4@y~}4#GA7$ar*=EU#TV9G_KwRu5-E*MnkTvM>#0-hqI2q=HbcP*`NK1ml6; zV%^;{(R<{68s9W%oylTeF91z^E;X^U;O|z@~zVrQeAqNP+SQxq^-)8rB|4TKpm|Futq;Z?&7p^3xI*ZxsYUQ@ucjJyLoF-o3-hZK?((-Fhks}cCInD zA?pADtcVZEMdT5$2)bzyHVOc>pTLy`3Hbp4AipX}5QAnY9`eHBd?k>5LW{lY$hsgS zuo4m?a4@_}26E%|H*hHlG~_jTpKJr>^!9-!vfk*&;b$SlA8c*`DG79jLWkjJ%f7^e z_9zewr~?$X4I#FN=H}Bg)u?-uFBCzrHFvJ& zHnqMlYxz;&0w{$r$gvn{(AA|xNsBBKmJs@*o#n?MT*Lr6uxgr`O6^}s?J23x^ zK6-K3O*!XMPplwB@jynXm;|+s9GF(dUQ`BT8)3E8+=Je-jepkuMK5g4p4`+9U$!5?ygza)7w!8qlVk526Dcx6}5ZlmtZ%6 z{8@21NVg2HWLGy{s2g|dy3{za4EXTzpUk#3Vl<`BzP`zRp}({()?5Zd2aq@=ia&+T z*)Z&=Hgqg0mqutR08?9VB0_5>oR?!aSZhJN{K$?uf* zYJ3LFFvEIkJGzqnz(GURR;~B}&eSyKDN1r@kR>m}>H+PGCGs_TB6C5w!6_mNl6TOM ztw-P^D)sZIA_`%DUR+ZJ#-;Nc`Orkw!rkcw5fAcQv?_jDg3RqWo}p7e!z-HNU!l6F zBmLERR@l$uz8Yj*U$-=~r5aCiDxpOUpR^;&X*u3+8Y?jR4mBO9e3T+Lo#+P;ISL>W z0M9{BlBqxCyLLRO+;`EDy*GO==!d|%r2mQ`>|{O;)~7(p?z|yhB?Dxa5xdHlTBvVV z13e+Ym}1xJh7%7*2T4&==b4BXd!oBWquSQ%6S*qa(N>3cT&%0EzA_Um;sCB1t{hpK zt99jjx~Y#tUr@h`CDRJhEur?MjrI<`AxMNn_gG}znB`$7IsoQv@sbMtE~Kj_Y89BM z_(=Ma?cd4^`JT})_yJtuE5cjSRGC9K&XqFyuIM8r^7KM8AKtC-UhEIe@Fvb;pr;0_kId)Cy`#8A3n%q(qSKrjqU_);)mcE9Bso=WXXRmI!6HWQx~p?VN2y@ z@G6c1J(dji*D#noemgqhr!AAy3*>ZCg0j{NyEn{9MLg zxE(RXOaI@Xo#XcS%t%)Un;;sr0<;rv-d-{C22x^&8sm#3HI%u?Cmga2t<`AR<7SB_ z;M*^{7rS71{wga)$GMaC^?^DO&d_--Vw&&nVM+CGOLY9~d+Zs#K)&i&?Q};h)Gux| zlQ<o#vRHHHTW?plM|x-nvF%N?HpQT6rCQA~v?;TssNA9K*R!{#xQ9Szn1~ zeJy%MT?wb5`T)Kqvdjt`++9}l<$`kaM#++Jge*k_uTohCW34FD?E{oKUt@obW}`qY z3e*bp&E5JM6Eq6_NTVH)Zt>IL!%jei3*I5dKW71dT2#G)yOV^}uP=3e z*brJGb5mCU0Z>x6do+yzMsUKRyI!)SkIL)ppoZ*Q`TnxUxl2lcVkGZ{?3_C$0V)6x zZAA{Xcc^t#{H^ylbrl%zp*)~qCaU<*o9G$)|ycA`FDCYhq{1oVscYua8#fe3OUw^WeL-qr6vH1|t)k};Aas*X8m zX-DwWq7uJI1;OA+g;^`D1Q~HudQ%m*{edwwUA<=YA(LNeydV96oX$rA&ersM!p~$SQ(At-ZHje_LAYfgC#q)Ml4Bg?TB#(Pa z(e)1m4fLJlw^!IFM!~-;LRU%Gk+P(KLAVw04u+olIc9C51_0-v-RBiEvQW9{cVQagVz#-2d6nG zcTCPA5GM&U*et2&kKfiDpVF);WeBT8t-U}2=wC>j!Nrn9Ng6P5kT*+VY-|lJVF-nG zD@x?yYA^uk!G1+qGhEfxXwZ>LO5UWtA)%F}u_vI8u1(>Qvh+zHMo?nbT~27k<{D25 zW5ECb(guv?%36@s8yZ6c30gYGVlhg>2e|bS1m3>F-XixK${V_Zn~00PebAJuIZ%{b z>^YVI=m{iwlnLEZ0vduCoRbdlq7wfiX(`EfUEQWb&t@P;QN9uT;{tw|pjS}8Vbb8WcQVeBOOtDp3+026o#&wkA-u_$g0DG~*m8pNPs8`?PK zw>3Zw+#%>am;=yS_OI;{l6!g`Sch@(#$GOyjIV-H~{i3&pdi7Ug-`N(Gu ziZKEBs3{nhZl@$04rQQ-XE0> zm$(A-4FbRid2M)98BJ3o`^^_!spiW87ziDcj6WZD4lKY*O1VZkB>~+0v=IUiNtnXA zW=cf_=LZ|EBCYc-V5p?1v)P0iQY9cm?|bZwk!S_rC6JVTWwxf-EeX~nzD1V6 z{esdq5MO0tBVY5fRwCVq4W<7cLU-UASZN(Uq#yb~r&#zFv)>-7`@t|Jq#5+pTPSNO z;Q=t9m^sG=m7RaUjAYH#I=zGmG!6o-l_5f9KIa#8-y0)F9(adxHh#^mj_Vqp$J<-2SSrs{W=UF{=(O z2^80prt~0|B*`|Ux>N`NfTjMDJK5Lzvd|4%%F;6UM?kp%0hNM4{-9@g6F#VX(ENHX zOT`2KZfmZ(Ez#7%fDp#(_=P8)E2}Q9H;*9F=VB>o`^ZQn!gqSgchaoa82PQbrr}QB2Z#$vK%cO(5gbm zN9-FRFW5k>XexY01D6DamzUNEERo}z(Ao6mut&5*qK%LQs}b#NtjZykME?#5xU_}G z@==#!9ZsSx{a8^1;2Nd9l*3*?hyP#imBBJiSPNW=G!Rw|RRVu&LENPYY{#C2tF!vF z>fG&28TcCthhil6EFG0E2^M zm2F@n1B}D-fuMX>zJHySua?x5ovCnT8@vey7={jckq_yhF6AjiZw^6&&>laVD`(+I&)LFh4^p-%h^4QQ|`F!f_=!)ZA;Y z!qOQbLbYMw?;6zo7e(9^8qBqT3t%Fr`s&E~ThX|rPJ(5EVc2<`z6D27uXCGP@CEuOP@gAqcoasqa*hYP?i%{NQcMM+d%5C}7~du4}x5 zl?Q$FGTgT!1dN-&x8U&fFcew2eL87ohK_H}p^~~QNCxf;7+a{;eGKoXq`}UTAPOdc z2>~UNF&KtAx*#+%77xqN&4k@nfkq`Xr-iHgh!oHTFRigv^qBiT+j+rX)5Rf8fsxf9}WvT4?AVvicM2@=vV<` ze7lr@qNCQpT!E0o56FdxY%@zT002VFfA0nO5xnxFl)Pwt(M8yfd=7Vlk*bI<`4tLS z=$`h@KW<^d0*sfSz;U{7Orn!~2hS+)kXzXHQub8-z-%=WnUG~W;4TTj8?ooQfL3b9&_KZ%!?ivbD4dc-tm zXQ5SJaapjmy9#GO`Q6_vF1pV-Iwk{6J7Gpq`EN|Er;sy!&}V1xSnB^Kks>k=HVrzsS!9x5LH*Dbp_v$}hrS5lcM&9#3o3AWjq>efbhgsi z$uUSk8)yhi5&UJd#CpLNssXd__07@*vu8D}=@XiB^A!~P>3KsYmBrg`ZgNqJm@R4PX^&oHt=RKN6zCBr* z0wP+VCDg|t>9Eg>({YPJlb|b)?;6bV5;fyM2XD-|Gx*9qwa?IE-${#BLPQU-_FqU| zZGmV7Hy+3k<_qcQs=|YnW3lc-)P`MW8}%k-@k*$J^Mt;Tng8{UT4l6|1wdeq#TsLu zPp9KnT7(xY5KHB=s&&NGD4`C^hXTrIrC3B=_JJ#IrC7Rh8)}yWR`s4)of7JRG6GUK zdC+v5kSt5605>e(E30<@uT}|lSS%D0waVztS|6IVVHx1ExKLW4$5Qza!CHnA>abKs ztDeEE3B#Nr6wO@;MRj;bL?11_ib)CsB{aZN84=;3S~LcUg$-{{4;BpG6aIh_(%|rr zp#sB#8F9_sQyWsdpLIZBHh3a(LuTn79Z)_RpoAvi4W-^$eD#iqUZ=jbE&yO0Uhnxx z=D{g&*9(9W65_D%NQ7As09nCF?$<>0%Hrz{wG&V%9|2H8hFB)OcECCUAYnK!?3(Q4 zyQWsYk-}jBl#nGnQ@SDhZ2GI5_JIdrsd$j(Rg~8W1(c8n9Ktk-TEFp|({bygVlx0h zh{Jj>5!QRW0VU)ScGX>zUGxkQl3)P{3Qrh6ke$1Y2+^^R4q?@Oux>j8P(m}p?z$Ut+cLVLRw30Mh6KQ3;6&oLGut?a= z_JQ2I2}Dpl$p9sk7#Htrz!R;v1f(}kO_=Ef_oQ_Y_CXYhtEDR{26%be{b=(orpG0&Et7*A# z!gZ%?Hi1q9OJ_wu39S%z-@T>QedlvcNyQxz{Y9;Eg5{J6Y}x!y?Zjmh_;d}m!34KZ zI_m>U2oTZ3g7F^|)><0UDX1EY%Jae#k&=jhqj?lf$36WFfWf2$KnVdokrY#(JO1+z z5#2#i$>5^7&#Ap{zw+OqEnXF!!ub>T4(Naq0!HxqQnw}$4GmBEc^oi000000000000000000000000W;Qs;5MWHR<`|wu)0000 Date: Wed, 6 Jun 2018 11:00:01 +0100 Subject: [PATCH 009/353] Delete a.txt --- images/a.txt | 1 - 1 file changed, 1 deletion(-) delete mode 100644 images/a.txt diff --git a/images/a.txt b/images/a.txt deleted file mode 100644 index 8b1378917..000000000 --- a/images/a.txt +++ /dev/null @@ -1 +0,0 @@ - From ac662335f1a90cedb96c6d038d7ad49f31974a51 Mon Sep 17 00:00:00 2001 From: Emma Walker <35726386+EmmaChronicle@users.noreply.github.com> Date: Wed, 6 Jun 2018 11:00:42 +0100 Subject: [PATCH 010/353] Update README.adoc local image --- README.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.adoc b/README.adoc index b28dc3740..64f49dd47 100644 --- a/README.adoc +++ b/README.adoc @@ -1,6 +1,6 @@ = Thread Affinity -image::https://chronicle.software/wp-content/uploads/2018/02/Thread-Affinity_line.png[width=20%] +image::/images/Thread-Affinity_line.png[width=20%] === Version From d9c51c3ab76320d7a746d27d1d3f059b9d45eb47 Mon Sep 17 00:00:00 2001 From: Tom Shercliff Date: Wed, 4 Jul 2018 13:30:12 +0100 Subject: [PATCH 011/353] Close #46 - use FileLock on lock files rather than presence/absence of file itself --- .../java/net/openhft/affinity/LockCheck.java | 95 ++++------- .../net/openhft/affinity/LockInventory.java | 12 +- .../lockchecker/FileBasedLockChecker.java | 81 +++++++++ .../lockchecker/FileLockBasedLockChecker.java | 156 ++++++++++++++++++ .../affinity/lockchecker/LockChecker.java | 18 ++ .../affinity/lockchecker/LockReference.java | 23 +++ .../affinity/main/AffinityTestMain.java | 52 ++++++ .../openhft/affinity/AffinityLockTest.java | 10 +- .../affinity/FileLockLockCheckTest.java | 86 ++++++++++ .../net/openhft/affinity/LockCheckTest.java | 8 +- .../testimpl/TestFileBasedLockChecker.java | 12 ++ .../TestFileLockBasedLockChecker.java | 12 ++ 12 files changed, 490 insertions(+), 75 deletions(-) create mode 100644 affinity/src/main/java/net/openhft/affinity/lockchecker/FileBasedLockChecker.java create mode 100644 affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java create mode 100644 affinity/src/main/java/net/openhft/affinity/lockchecker/LockChecker.java create mode 100644 affinity/src/main/java/net/openhft/affinity/lockchecker/LockReference.java create mode 100644 affinity/src/main/java/net/openhft/affinity/main/AffinityTestMain.java create mode 100644 affinity/src/test/java/net/openhft/affinity/FileLockLockCheckTest.java create mode 100644 affinity/src/test/java/net/openhft/affinity/testimpl/TestFileBasedLockChecker.java create mode 100644 affinity/src/test/java/net/openhft/affinity/testimpl/TestFileLockBasedLockChecker.java diff --git a/affinity/src/main/java/net/openhft/affinity/LockCheck.java b/affinity/src/main/java/net/openhft/affinity/LockCheck.java index 01d66e9fa..63e713d2b 100644 --- a/affinity/src/main/java/net/openhft/affinity/LockCheck.java +++ b/affinity/src/main/java/net/openhft/affinity/LockCheck.java @@ -17,13 +17,12 @@ package net.openhft.affinity; -import org.jetbrains.annotations.NotNull; +import net.openhft.affinity.lockchecker.FileLockBasedLockChecker; +import net.openhft.affinity.lockchecker.LockChecker; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.*; -import java.text.SimpleDateFormat; -import java.util.Date; /** * @author Rob Austin. @@ -35,7 +34,9 @@ enum LockCheck { private static final String OS = System.getProperty("os.name").toLowerCase(); static final boolean IS_LINUX = OS.startsWith("linux"); private static final int EMPTY_PID = Integer.MIN_VALUE; - private static SimpleDateFormat df = new SimpleDateFormat("yyyy.MM" + ".dd 'at' HH:mm:ss z"); + + + private static final LockChecker lockChecker = FileLockBasedLockChecker.getInstance(); static long getPID() { String processName = @@ -43,53 +44,39 @@ static long getPID() { return Long.parseLong(processName.split("@")[0]); } - public static boolean isCpuFree(int cpu) { + static boolean canOSSupportOperation() { + return IS_LINUX; + } - if (!IS_LINUX) + public static boolean isCpuFree(int cpu) { + if (!canOSSupportOperation()) return true; - final File file = toFile(cpu); - final boolean exists = file.exists(); - - if (!exists) { + if (isLockFree(cpu)) { return true; } else { int currentProcess = 0; try { - currentProcess = getProcessForCpu(file); + currentProcess = getProcessForCpu(cpu); } catch (RuntimeException | IOException e) { LOGGER.warn("Failed to determine process on cpu " + cpu, e); e.printStackTrace(); return true; } - if (currentProcess == EMPTY_PID) { - file.delete(); - return true; - } if (!isProcessRunning(currentProcess)) { - file.delete(); + lockChecker.releaseLock(cpu); return true; } return false; } } - @NotNull - static File toFile(int core) { - return new File(tmpDir(), "cpu-" + core + ".lock"); - } - - static void replacePid(int core, long processID) throws IOException { - replacePid(toFile(core), processID); - } - - private static void replacePid(File file, long processID) throws IOException { - file.delete(); - storePid(processID, file); + static void replacePid(int cpu, long processID) throws IOException { + storePid(processID, cpu); } static boolean isProcessRunning(long pid) { - if (IS_LINUX) + if (canOSSupportOperation()) return new File("/proc/" + pid).exists(); else throw new UnsupportedOperationException("this is only supported on LINUX"); @@ -99,55 +86,41 @@ static boolean isProcessRunning(long pid) { * stores the pid in a file, named by the core, the pid is written to the file with the date * below */ - private synchronized static void storePid(long processID, File coreFile) throws IOException { - try (Writer writer = new BufferedWriter(new OutputStreamWriter( - new FileOutputStream(coreFile, false), "utf-8"))) { - String processIDStr = Long.toString(processID); - writer.write(processIDStr + "\n" + df.format(new Date())); + private synchronized static void storePid(long processID, int cpu) throws IOException { + if(!lockChecker.obtainLock(cpu, Long.toString(processID))) { + throw new IOException(String.format("Cannot obtain file lock for cpu %d", cpu)); } } - static int getProcessForCpu(int core) throws IOException { - return getProcessForCpu(toFile(core)); + private synchronized static boolean isLockFree(int id) { + return lockChecker.isLockFree(id); } - private static int getProcessForCpu(@NotNull File coreFile) throws IOException { - try (BufferedReader reader = new BufferedReader(new InputStreamReader( - new FileInputStream(coreFile), "utf-8"))) { + static int getProcessForCpu(int core) throws IOException { + String meta = lockChecker.getMetaInfo(core); - final String firstLine = reader.readLine(); - if (firstLine == null) { - LOGGER.warn("Empty lock file {}", coreFile.getAbsolutePath()); - return EMPTY_PID; - } - String s = firstLine.trim(); + if(meta != null && !meta.isEmpty()) { try { - return Integer.parseInt(s); - } catch (RuntimeException e) { - LOGGER.warn("Corrupt lock file {}: first line = '{}'", coreFile.getAbsolutePath(), firstLine); - e.printStackTrace(); - return EMPTY_PID; + return Integer.parseInt(meta); + } catch(NumberFormatException e) { + //nothing } } - } - - private static File tmpDir() { - final File tempDir = new File(System.getProperty("java.io.tmpdir")); - - if (!tempDir.exists()) - tempDir.mkdirs(); - - return tempDir; + return EMPTY_PID; } static void updateCpu(int cpu) { - if (!IS_LINUX) + if (!canOSSupportOperation()) return; try { - replacePid(toFile(cpu), getPID()); + replacePid(cpu, getPID()); } catch (IOException e) { LOGGER.warn("Failed to update lock file for cpu " + cpu, e); e.printStackTrace(); } } + + public static void releaseLock(int cpu) { + lockChecker.releaseLock(cpu); + } } \ No newline at end of file diff --git a/affinity/src/main/java/net/openhft/affinity/LockInventory.java b/affinity/src/main/java/net/openhft/affinity/LockInventory.java index 6e04d2f51..892fcc83f 100644 --- a/affinity/src/main/java/net/openhft/affinity/LockInventory.java +++ b/affinity/src/main/java/net/openhft/affinity/LockInventory.java @@ -108,11 +108,10 @@ public final synchronized AffinityLock acquireLock(boolean bind, int cpuId, Affi updateLockForCurrentThread(bind, required, false); return required; } + LOGGER.warn("Unable to acquire lock on CPU {} for thread {}, trying to find another CPU", + cpuId, Thread.currentThread()); } - LOGGER.warn("Unable to acquire lock on CPU {} for thread {}, trying to find another CPU", - cpuId, Thread.currentThread()); - for (AffinityStrategy strategy : strategies) { // consider all processors except cpu 0 which is usually used by the OS. // if you have only one core, this library is not appropriate in any case. @@ -215,11 +214,6 @@ private void releaseAffinityLock(final Thread t, final AffinityLock al, final St al.bound = false; al.boundHere = null; - final String lockFilePath = LockCheck.toFile(al.cpuId()).getAbsolutePath(); - try { - Files.delete(Paths.get(lockFilePath)); - } catch (IOException e) { - LOGGER.warn("Failed to delete lock file at " + lockFilePath); - } + LockCheck.releaseLock(al.cpuId()); } } \ No newline at end of file diff --git a/affinity/src/main/java/net/openhft/affinity/lockchecker/FileBasedLockChecker.java b/affinity/src/main/java/net/openhft/affinity/lockchecker/FileBasedLockChecker.java new file mode 100644 index 000000000..8cfd8a127 --- /dev/null +++ b/affinity/src/main/java/net/openhft/affinity/lockchecker/FileBasedLockChecker.java @@ -0,0 +1,81 @@ +package net.openhft.affinity.lockchecker; + +import org.jetbrains.annotations.NotNull; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.*; +import java.text.SimpleDateFormat; +import java.util.Date; + +/** + * @author Tom Shercliff + */ +public class FileBasedLockChecker implements LockChecker { + + private static final Logger LOGGER = LoggerFactory.getLogger(FileBasedLockChecker.class); + protected static final SimpleDateFormat df = new SimpleDateFormat("yyyy.MM" + ".dd 'at' HH:mm:ss z"); + + private static final LockChecker instance = new FileBasedLockChecker(); + public static LockChecker getInstance() { + return instance; + } + + protected FileBasedLockChecker() { + //nothing + } + + @Override + public boolean isLockFree(int id) { + return !toFile(id).exists(); + } + + @Override + public boolean obtainLock(int id, String metaInfo) throws IOException { + File file = toFile(id); + file.delete(); + + try (Writer writer = new BufferedWriter(new OutputStreamWriter( + new FileOutputStream(file, false), "utf-8"))) { + writer.write(metaInfo + "\n" + df.format(new Date())); + return true; + } + } + + @Override + public boolean releaseLock(int id) { + return toFile(id).delete(); + } + + @Override + public String getMetaInfo(int id) throws IOException { + File file = toFile(id); + + if(!file.exists()) { + return null; + } + + try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "utf-8"))) { + final String firstLine = reader.readLine(); + if (firstLine == null) { + LOGGER.error(String.format("Empty lock file %s%n", file.getAbsolutePath())); + return null; + } + return firstLine.trim(); + } + } + + @NotNull + protected File toFile(int id) { + return new File(tmpDir(), "cpu-" + id + ".lock"); + } + + static File tmpDir() { + final File tempDir = new File(System.getProperty("java.io.tmpdir")); + + if (!tempDir.exists()) + tempDir.mkdirs(); + + return tempDir; + } +} diff --git a/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java b/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java new file mode 100644 index 000000000..f2711498a --- /dev/null +++ b/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java @@ -0,0 +1,156 @@ +package net.openhft.affinity.lockchecker; + +import org.jetbrains.annotations.NotNull; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.*; +import java.nio.ByteBuffer; +import java.nio.channels.FileChannel; +import java.nio.channels.FileLock; +import java.nio.channels.OverlappingFileLockException; +import java.nio.file.Files; +import java.nio.file.StandardOpenOption; +import java.nio.file.attribute.PosixFilePermissions; +import java.util.Date; + +import static net.openhft.affinity.impl.VanillaCpuLayout.MAX_CPUS_SUPPORTED; + +/** + * @author Tom Shercliff + */ +public class FileLockBasedLockChecker extends FileBasedLockChecker { + + private static final Logger LOGGER = LoggerFactory.getLogger(FileLockBasedLockChecker.class); + private static final String OS = System.getProperty("os.name").toLowerCase(); + + private static final LockChecker instance = new FileLockBasedLockChecker(); + public static LockChecker getInstance() { + return instance; + } + + private final LockReference[] locks = new LockReference[MAX_CPUS_SUPPORTED]; + + protected FileLockBasedLockChecker() { + //nothing + } + + @Override + public boolean isLockFree(int id) { + return isLockFree(toFile(id), id); + } + + private boolean isLockFree(File file, int id) { + //if no file exists - nobody has the lock for sure + if(!file.exists()) { + return true; + } + + //do we have the lock already? + LockReference existingLock = locks[id]; + if(existingLock != null) { + return false; + } + + //does another process have the lock? + try { + FileChannel fc = FileChannel.open(file.toPath(), StandardOpenOption.WRITE); + FileLock fileLock = fc.tryLock(); + if (fileLock == null) { + return false; + } + } catch (IOException | OverlappingFileLockException e) { + LOGGER.error(String.format("Exception occurred whilst trying to check lock on file %s : %s%n", file.getAbsolutePath(), e)); + } + + //file is present but nobody has it locked - delete it + LOGGER.info(String.format("Deleting %s as nobody has the lock", file.getAbsolutePath())); + file.delete(); + + return true; + } + + @Override + public boolean obtainLock(int id, String metaInfo) throws IOException { + final File file = toFile(id); + if(!isLockFree(file, id)) { + return false; + } + + FileChannel fc = FileChannel.open(file.toPath(), StandardOpenOption.CREATE_NEW, + StandardOpenOption.WRITE, StandardOpenOption.READ, StandardOpenOption.SYNC); + FileLock fl = fc.tryLock(); + + if(fl == null) { + LOGGER.error(String.format("Could not obtain lock on file %s%n", file.getAbsolutePath())); + return false; + } else { + LOGGER.debug(String.format("Obtained lock on file %s (%s)%n", file.getAbsolutePath(), metaInfo)); + locks[id] = new LockReference(fc, fl); + + byte[] content = String.format("%s%n%s", metaInfo, df.format(new Date())).getBytes(); + ByteBuffer buffer = ByteBuffer.wrap(content); + while(buffer.hasRemaining()) { + fc.write(buffer); + } + return true; + } + } + + @Override + public boolean releaseLock(int id) { + LockReference lock = locks[id]; + if(lock == null) { + LOGGER.error(String.format("Cannot release lock for id %d as don't have it!", id)); + return false; + } + + try { + locks[id] = null; + lock.lock.release(); + lock.channel.close(); + toFile(id).delete(); + return true; + } catch (IOException e) { + LOGGER.error(String.format("Couldn't release lock for id %d due to exception: %s%n", id, e.getMessage())); + return false; + } + } + + @Override + public String getMetaInfo(int id) throws IOException { + final File file = toFile(id); + if(isLockFree(file, id)) { + LOGGER.warn("Cannot obtain lock on lock file {}", file.getAbsolutePath()); + return null; + } + + LockReference lr = locks[id]; + if(lr == null) { + return null; + } + FileChannel fc = lr.channel; + ByteBuffer buffer = ByteBuffer.allocate(64); + int len = fc.read(buffer, 0); + String content = new String(buffer.array(), 0, len); + if (content == null || content.isEmpty()) { + LOGGER.warn("Empty lock file {}", file.getAbsolutePath()); + return null; + } + return content.substring(0, content.indexOf("\n")); + } + + @NotNull + @Override + protected File toFile(int id) { + File file = super.toFile(id); + try { + if(file.exists() && OS.startsWith("linux")) { + Files.setPosixFilePermissions(file.toPath(), PosixFilePermissions.fromString("rwxrwxrwx")); + } + } catch (IOException e) { + LOGGER.warn("Unable to set file permissions \"rwxrwxrwx\" for {} due to {}", file.toString(), e); + } + return file; + } +} diff --git a/affinity/src/main/java/net/openhft/affinity/lockchecker/LockChecker.java b/affinity/src/main/java/net/openhft/affinity/lockchecker/LockChecker.java new file mode 100644 index 000000000..0c95c335f --- /dev/null +++ b/affinity/src/main/java/net/openhft/affinity/lockchecker/LockChecker.java @@ -0,0 +1,18 @@ +package net.openhft.affinity.lockchecker; + +import java.io.IOException; + +/** + * @author Tom Shercliff + */ + +public interface LockChecker { + + boolean isLockFree(int id); + + boolean obtainLock(int id, String metaInfo) throws IOException; + + boolean releaseLock(int id); + + String getMetaInfo(int id) throws IOException; +} diff --git a/affinity/src/main/java/net/openhft/affinity/lockchecker/LockReference.java b/affinity/src/main/java/net/openhft/affinity/lockchecker/LockReference.java new file mode 100644 index 000000000..ec740ca18 --- /dev/null +++ b/affinity/src/main/java/net/openhft/affinity/lockchecker/LockReference.java @@ -0,0 +1,23 @@ +package net.openhft.affinity.lockchecker; + + +import java.nio.channels.FileChannel; +import java.nio.channels.FileLock; + +/** + * @author Tom Shercliff + */ + +public class LockReference { + protected final FileChannel channel; + protected final FileLock lock; + + public LockReference(final FileChannel channel, final FileLock lock) { + this.channel = channel; + this.lock = lock; + } + + public FileChannel getChannel() { + return channel; + } +} diff --git a/affinity/src/main/java/net/openhft/affinity/main/AffinityTestMain.java b/affinity/src/main/java/net/openhft/affinity/main/AffinityTestMain.java new file mode 100644 index 000000000..9f556ed8f --- /dev/null +++ b/affinity/src/main/java/net/openhft/affinity/main/AffinityTestMain.java @@ -0,0 +1,52 @@ +package net.openhft.affinity.main; + +import net.openhft.affinity.Affinity; +import net.openhft.affinity.AffinityLock; + +import java.text.SimpleDateFormat; +import java.util.Date; + +/** + * @author Tom Shercliff + */ +public class AffinityTestMain { + private static final SimpleDateFormat df = new SimpleDateFormat("yyyy.MM" + ".dd 'at' HH:mm:ss z"); + + public static void main(String[] args) { + + int cpus = 1; + if(args.length == 0) { + cpus = AffinityLock.cpuLayout().cpus() / 12; + } else { + cpus = Integer.valueOf(args[0]); + } + + for(int i=0; i Date: Wed, 4 Jul 2018 16:50:18 +0100 Subject: [PATCH 012/353] add scm info to pom --- pom.xml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pom.xml b/pom.xml index b3bd45754..8d50550b9 100755 --- a/pom.xml +++ b/pom.xml @@ -39,4 +39,12 @@ affinity-test + + scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git + scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git + scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git + + master + + From f62b6fd48fda5cb65c6bf780a7b22ad077ad476d Mon Sep 17 00:00:00 2001 From: Tom Shercliff Date: Wed, 4 Jul 2018 17:03:01 +0100 Subject: [PATCH 013/353] align parent and module versions --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 8d50550b9..5d8c9de5c 100755 --- a/pom.xml +++ b/pom.xml @@ -28,7 +28,7 @@ 4.0.0 Java-Thread-Affinity - 3.1.1-SNAPSHOT + 3.1.8-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent From 18cf0982e7df403497858da64d1ff4ba9123ef8a Mon Sep 17 00:00:00 2001 From: Tom Shercliff Date: Wed, 4 Jul 2018 17:12:13 +0100 Subject: [PATCH 014/353] update root/java parent pom and bring affinity-test version in line --- affinity-test/pom.xml | 4 ++-- pom.xml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index b26aab2dc..85489428c 100755 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -22,13 +22,13 @@ net.openhft java-parent-pom - 1.1.15 + 1.1.16 4.0.0 affinity-test - 3.1.1-SNAPSHOT + 3.1.8-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test diff --git a/pom.xml b/pom.xml index 5d8c9de5c..b6932f46d 100755 --- a/pom.xml +++ b/pom.xml @@ -22,7 +22,7 @@ net.openhft root-parent-pom - 1.1.11 + 1.1.12 From 0e486c2325a30c316430344361ab113126cc884a Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Wed, 4 Jul 2018 17:15:31 +0100 Subject: [PATCH 015/353] [maven-release-plugin] prepare release Java-Thread-Affinity-3.1.8 --- affinity-test/pom.xml | 11 +++++------ affinity/pom.xml | 13 ++++++------- pom.xml | 10 ++++------ 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 85489428c..70a64e24c 100755 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -15,20 +15,18 @@ ~ limitations under the License. --> - + net.openhft java-parent-pom 1.1.16 - + 4.0.0 affinity-test - 3.1.8-SNAPSHOT + 3.1.8 bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -190,7 +188,8 @@ scm:git:https://github.com/OpenHFT/Java-Thread-Affinity.git - + Java-Thread-Affinity-3.1.8 + diff --git a/affinity/pom.xml b/affinity/pom.xml index 7ebae76d5..48c1ffa45 100755 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -15,19 +15,18 @@ ~ limitations under the License. --> - + net.openhft java-parent-pom 1.1.16 - + 4.0.0 affinity - 3.1.8-SNAPSHOT + 3.1.8 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -113,9 +112,9 @@ - + - + @@ -225,7 +224,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - master + Java-Thread-Affinity-3.1.8 diff --git a/pom.xml b/pom.xml index b6932f46d..9e501e2ed 100755 --- a/pom.xml +++ b/pom.xml @@ -15,20 +15,18 @@ ~ limitations under the License. --> - + net.openhft root-parent-pom 1.1.12 - + 4.0.0 Java-Thread-Affinity - 3.1.8-SNAPSHOT + 3.1.8 pom OpenHFT/Java-Thread-Affinity Parent @@ -44,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - master + Java-Thread-Affinity-3.1.8 From bea781c827514bda5a7ebb64e2942ea3cfd39864 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Wed, 4 Jul 2018 17:15:39 +0100 Subject: [PATCH 016/353] [maven-release-plugin] prepare for next development iteration --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 70a64e24c..68422727e 100755 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ 4.0.0 affinity-test - 3.1.8 + 3.1.9-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -188,7 +188,7 @@ scm:git:https://github.com/OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.1.8 + HEAD diff --git a/affinity/pom.xml b/affinity/pom.xml index 48c1ffa45..dbc845720 100755 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ 4.0.0 affinity - 3.1.8 + 3.1.9-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity @@ -224,7 +224,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.1.8 + master diff --git a/pom.xml b/pom.xml index 9e501e2ed..6cbdded9b 100755 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ 4.0.0 Java-Thread-Affinity - 3.1.8 + 3.1.9-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.1.8 + master From e51e9b653e4b257c6357ecd52bb7f9fc391e7856 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Wed, 4 Jul 2018 17:29:39 +0100 Subject: [PATCH 017/353] [maven-release-plugin] prepare release Java-Thread-Affinity-3.1.9 --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 68422727e..c2faa5b0a 100755 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ 4.0.0 affinity-test - 3.1.9-SNAPSHOT + 3.1.9 bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -188,7 +188,7 @@ scm:git:https://github.com/OpenHFT/Java-Thread-Affinity.git - HEAD + Java-Thread-Affinity-3.1.9 diff --git a/affinity/pom.xml b/affinity/pom.xml index dbc845720..1f7b3ac98 100755 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ 4.0.0 affinity - 3.1.9-SNAPSHOT + 3.1.9 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -224,7 +224,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - master + Java-Thread-Affinity-3.1.9 diff --git a/pom.xml b/pom.xml index 6cbdded9b..809ff0bc2 100755 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ 4.0.0 Java-Thread-Affinity - 3.1.9-SNAPSHOT + 3.1.9 pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - master + Java-Thread-Affinity-3.1.9 From 6a7a9a0b7031a2f98929179cfb424b640aac7138 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Wed, 4 Jul 2018 17:29:45 +0100 Subject: [PATCH 018/353] [maven-release-plugin] prepare for next development iteration --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index c2faa5b0a..de36e1052 100755 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ 4.0.0 affinity-test - 3.1.9 + 3.1.10-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -188,7 +188,7 @@ scm:git:https://github.com/OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.1.9 + HEAD diff --git a/affinity/pom.xml b/affinity/pom.xml index 1f7b3ac98..a7bbd1494 100755 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ 4.0.0 affinity - 3.1.9 + 3.1.10-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity @@ -224,7 +224,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.1.9 + master diff --git a/pom.xml b/pom.xml index 809ff0bc2..6bb054862 100755 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ 4.0.0 Java-Thread-Affinity - 3.1.9 + 3.1.10-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.1.9 + master From 8e1cee8b8903a773541cd63dda4547d314982ac9 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Wed, 4 Jul 2018 17:32:06 +0100 Subject: [PATCH 019/353] Updating to bom version 1.16.100 From cd281d0137bd5264007deaf48dcd92734cfbdad6 Mon Sep 17 00:00:00 2001 From: Rob Austin <6506056+RobAustin@users.noreply.github.com> Date: Wed, 1 Aug 2018 11:35:06 +0100 Subject: [PATCH 020/353] Update README.adoc --- README.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.adoc b/README.adoc index 64f49dd47..79a6fb49c 100644 --- a/README.adoc +++ b/README.adoc @@ -78,7 +78,7 @@ To isolate the 1st and 3rd CPU cores (CPU numbers start from 0) on your system, isolcpus=1,3 ==== Acquiring a CPU lock for a thread -You can acquire a lock for a CPU in the following matter +You can acquire a lock for a CPU in the following way: In Java 6 [source, java] From 43fede7b9f7d3202ad090c8646238870868825f1 Mon Sep 17 00:00:00 2001 From: Jeffrey Griffin Date: Thu, 30 Aug 2018 21:48:31 -0700 Subject: [PATCH 021/353] fix last cpu not being marked reservable --- affinity/src/main/java/net/openhft/affinity/AffinityLock.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java index c9e62d6be..e85aac88e 100644 --- a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java +++ b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java @@ -123,7 +123,7 @@ private static BitSet getReservedAffinity0() { LoggerFactory.getLogger(AffinityLock.class).info("No isolated CPUs found, so assuming CPUs 1 to {} available.", (PROCESSORS - 1)); reserverable = new BitSet(PROCESSORS); // make the first CPU unavailable - reserverable.set(1, PROCESSORS - 1, true); + reserverable.set(1, PROCESSORS, true); reserverable.set(0, false); return reserverable; } From bb4df0c35ca3ba3668ddc4a53bcd40d3c7ac84ad Mon Sep 17 00:00:00 2001 From: Dmitry Pisklov Date: Tue, 11 Sep 2018 11:50:50 +0100 Subject: [PATCH 022/353] Fixes #48 --- .../affinity/lockchecker/FileBasedLockChecker.java | 2 ++ .../lockchecker/FileLockBasedLockChecker.java | 11 ++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/affinity/src/main/java/net/openhft/affinity/lockchecker/FileBasedLockChecker.java b/affinity/src/main/java/net/openhft/affinity/lockchecker/FileBasedLockChecker.java index 8cfd8a127..8dfec04b8 100644 --- a/affinity/src/main/java/net/openhft/affinity/lockchecker/FileBasedLockChecker.java +++ b/affinity/src/main/java/net/openhft/affinity/lockchecker/FileBasedLockChecker.java @@ -38,6 +38,8 @@ public boolean obtainLock(int id, String metaInfo) throws IOException { try (Writer writer = new BufferedWriter(new OutputStreamWriter( new FileOutputStream(file, false), "utf-8"))) { writer.write(metaInfo + "\n" + df.format(new Date())); + file.setWritable(true, false); + file.setExecutable(false, false); return true; } } diff --git a/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java b/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java index f2711498a..ae80600fe 100644 --- a/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java +++ b/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java @@ -11,9 +11,13 @@ import java.nio.channels.OverlappingFileLockException; import java.nio.file.Files; import java.nio.file.StandardOpenOption; +import java.nio.file.attribute.PosixFilePermission; import java.nio.file.attribute.PosixFilePermissions; +import java.util.Arrays; import java.util.Date; +import java.util.HashSet; +import static java.nio.file.StandardOpenOption.*; import static net.openhft.affinity.impl.VanillaCpuLayout.MAX_CPUS_SUPPORTED; /** @@ -54,7 +58,7 @@ private boolean isLockFree(File file, int id) { //does another process have the lock? try { - FileChannel fc = FileChannel.open(file.toPath(), StandardOpenOption.WRITE); + FileChannel fc = FileChannel.open(file.toPath(), WRITE); FileLock fileLock = fc.tryLock(); if (fileLock == null) { return false; @@ -77,8 +81,9 @@ public boolean obtainLock(int id, String metaInfo) throws IOException { return false; } - FileChannel fc = FileChannel.open(file.toPath(), StandardOpenOption.CREATE_NEW, - StandardOpenOption.WRITE, StandardOpenOption.READ, StandardOpenOption.SYNC); + FileChannel fc = FileChannel.open(file.toPath(), + new HashSet<>(Arrays.asList(CREATE_NEW, WRITE, READ, SYNC)), + PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("rw-rw-rw-"))); FileLock fl = fc.tryLock(); if(fl == null) { From 059942e6af04a7c425c6385894333571caddb306 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Fri, 14 Sep 2018 15:50:06 +0100 Subject: [PATCH 023/353] Third party bom 3.6.5 --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index de36e1052..b5363e2c3 100755 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -42,7 +42,7 @@ net.openhft third-party-bom pom - 3.6.2 + 3.6.5 import diff --git a/affinity/pom.xml b/affinity/pom.xml index a7bbd1494..4e64f67de 100755 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -43,7 +43,7 @@ net.openhft third-party-bom pom - 3.6.2 + 3.6.5 import From 13c69761460a7d54d79b503e916d2ecc6f91e639 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Wed, 26 Sep 2018 15:38:30 +0100 Subject: [PATCH 024/353] Updating to bom version 1.16.196 From eb446752c9ff53a13f0af7a8dc1a7a74a54b3981 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Wed, 26 Sep 2018 15:39:08 +0100 Subject: [PATCH 025/353] [maven-release-plugin] prepare release Java-Thread-Affinity-3.1.10 --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index b5363e2c3..3dfe4fa00 100755 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ 4.0.0 affinity-test - 3.1.10-SNAPSHOT + 3.1.10 bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -188,7 +188,7 @@ scm:git:https://github.com/OpenHFT/Java-Thread-Affinity.git - HEAD + Java-Thread-Affinity-3.1.10 diff --git a/affinity/pom.xml b/affinity/pom.xml index 4e64f67de..cf9e65bf0 100755 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ 4.0.0 affinity - 3.1.10-SNAPSHOT + 3.1.10 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -224,7 +224,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - master + Java-Thread-Affinity-3.1.10 diff --git a/pom.xml b/pom.xml index 6bb054862..e841b37a8 100755 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ 4.0.0 Java-Thread-Affinity - 3.1.10-SNAPSHOT + 3.1.10 pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - master + Java-Thread-Affinity-3.1.10 From 756d883d70c7c056449b2b1e68ed940b25335246 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Wed, 26 Sep 2018 15:39:17 +0100 Subject: [PATCH 026/353] [maven-release-plugin] prepare for next development iteration --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 3dfe4fa00..d8252dcdd 100755 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ 4.0.0 affinity-test - 3.1.10 + 3.1.11-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -188,7 +188,7 @@ scm:git:https://github.com/OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.1.10 + HEAD diff --git a/affinity/pom.xml b/affinity/pom.xml index cf9e65bf0..9bf8acdeb 100755 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ 4.0.0 affinity - 3.1.10 + 3.1.11-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity @@ -224,7 +224,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.1.10 + master diff --git a/pom.xml b/pom.xml index e841b37a8..7d63866e2 100755 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ 4.0.0 Java-Thread-Affinity - 3.1.10 + 3.1.11-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.1.10 + master From 8887987556869a1ad23cabfae2376e35449fd8ac Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Wed, 26 Sep 2018 15:41:01 +0100 Subject: [PATCH 027/353] Reverting back to bom version 1.16-SNAPSHOT From 83bd27b34b81f5b1fbc5c34d3bd9b03350f0f87e Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Wed, 26 Sep 2018 15:44:34 +0100 Subject: [PATCH 028/353] Reverting back to bom version 1.16-SNAPSHOT From b9248a132be7142de6def4d6c17bb22b60f7efa1 Mon Sep 17 00:00:00 2001 From: Dmitry Pisklov Date: Tue, 27 Nov 2018 11:01:43 +0000 Subject: [PATCH 029/353] Small enhancements --- .../net/openhft/affinity/AffinityLock.java | 6 ++-- .../lockchecker/FileBasedLockChecker.java | 17 ++++----- .../lockchecker/FileLockBasedLockChecker.java | 35 ++++++++++--------- 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java index e85aac88e..c9c714115 100644 --- a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java +++ b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java @@ -121,10 +121,8 @@ private static BitSet getReservedAffinity0() { reserverable.andNot(BASE_AFFINITY); if (reserverable.isEmpty() && PROCESSORS > 1) { LoggerFactory.getLogger(AffinityLock.class).info("No isolated CPUs found, so assuming CPUs 1 to {} available.", (PROCESSORS - 1)); - reserverable = new BitSet(PROCESSORS); - // make the first CPU unavailable - reserverable.set(1, PROCESSORS, true); - reserverable.set(0, false); + // make all but first CPUs available + reserverable.set(1, PROCESSORS); return reserverable; } return reserverable; diff --git a/affinity/src/main/java/net/openhft/affinity/lockchecker/FileBasedLockChecker.java b/affinity/src/main/java/net/openhft/affinity/lockchecker/FileBasedLockChecker.java index 8dfec04b8..72c039bc0 100644 --- a/affinity/src/main/java/net/openhft/affinity/lockchecker/FileBasedLockChecker.java +++ b/affinity/src/main/java/net/openhft/affinity/lockchecker/FileBasedLockChecker.java @@ -8,15 +8,16 @@ import java.text.SimpleDateFormat; import java.util.Date; -/** - * @author Tom Shercliff - */ +import static java.nio.charset.StandardCharsets.UTF_8; + +@SuppressWarnings("ResultOfMethodCallIgnored") public class FileBasedLockChecker implements LockChecker { private static final Logger LOGGER = LoggerFactory.getLogger(FileBasedLockChecker.class); - protected static final SimpleDateFormat df = new SimpleDateFormat("yyyy.MM" + ".dd 'at' HH:mm:ss z"); + static final SimpleDateFormat df = new SimpleDateFormat("yyyy.MM" + ".dd 'at' HH:mm:ss z"); private static final LockChecker instance = new FileBasedLockChecker(); + public static LockChecker getInstance() { return instance; } @@ -36,7 +37,7 @@ public boolean obtainLock(int id, String metaInfo) throws IOException { file.delete(); try (Writer writer = new BufferedWriter(new OutputStreamWriter( - new FileOutputStream(file, false), "utf-8"))) { + new FileOutputStream(file, false), UTF_8))) { writer.write(metaInfo + "\n" + df.format(new Date())); file.setWritable(true, false); file.setExecutable(false, false); @@ -53,11 +54,11 @@ public boolean releaseLock(int id) { public String getMetaInfo(int id) throws IOException { File file = toFile(id); - if(!file.exists()) { + if (!file.exists()) { return null; } - try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "utf-8"))) { + try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), UTF_8))) { final String firstLine = reader.readLine(); if (firstLine == null) { LOGGER.error(String.format("Empty lock file %s%n", file.getAbsolutePath())); @@ -72,7 +73,7 @@ protected File toFile(int id) { return new File(tmpDir(), "cpu-" + id + ".lock"); } - static File tmpDir() { + private static File tmpDir() { final File tempDir = new File(System.getProperty("java.io.tmpdir")); if (!tempDir.exists()) diff --git a/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java b/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java index ae80600fe..3e62380f4 100644 --- a/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java +++ b/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java @@ -4,31 +4,34 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.*; +import java.io.File; +import java.io.IOException; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import java.nio.channels.FileLock; import java.nio.channels.OverlappingFileLockException; import java.nio.file.Files; import java.nio.file.StandardOpenOption; +import java.nio.file.attribute.FileAttribute; import java.nio.file.attribute.PosixFilePermission; import java.nio.file.attribute.PosixFilePermissions; import java.util.Arrays; import java.util.Date; import java.util.HashSet; +import java.util.Set; import static java.nio.file.StandardOpenOption.*; import static net.openhft.affinity.impl.VanillaCpuLayout.MAX_CPUS_SUPPORTED; -/** - * @author Tom Shercliff - */ public class FileLockBasedLockChecker extends FileBasedLockChecker { private static final Logger LOGGER = LoggerFactory.getLogger(FileLockBasedLockChecker.class); private static final String OS = System.getProperty("os.name").toLowerCase(); private static final LockChecker instance = new FileLockBasedLockChecker(); + private static final HashSet openOptions = new HashSet<>(Arrays.asList(CREATE_NEW, WRITE, READ, SYNC)); + private static final FileAttribute> fileAttr = PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("rw-rw-rw-")); + public static LockChecker getInstance() { return instance; } @@ -46,13 +49,13 @@ public boolean isLockFree(int id) { private boolean isLockFree(File file, int id) { //if no file exists - nobody has the lock for sure - if(!file.exists()) { + if (!file.exists()) { return true; } //do we have the lock already? LockReference existingLock = locks[id]; - if(existingLock != null) { + if (existingLock != null) { return false; } @@ -77,16 +80,14 @@ private boolean isLockFree(File file, int id) { @Override public boolean obtainLock(int id, String metaInfo) throws IOException { final File file = toFile(id); - if(!isLockFree(file, id)) { + if (!isLockFree(file, id)) { return false; } - FileChannel fc = FileChannel.open(file.toPath(), - new HashSet<>(Arrays.asList(CREATE_NEW, WRITE, READ, SYNC)), - PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("rw-rw-rw-"))); + FileChannel fc = FileChannel.open(file.toPath(), openOptions, fileAttr); FileLock fl = fc.tryLock(); - if(fl == null) { + if (fl == null) { LOGGER.error(String.format("Could not obtain lock on file %s%n", file.getAbsolutePath())); return false; } else { @@ -95,7 +96,7 @@ public boolean obtainLock(int id, String metaInfo) throws IOException { byte[] content = String.format("%s%n%s", metaInfo, df.format(new Date())).getBytes(); ByteBuffer buffer = ByteBuffer.wrap(content); - while(buffer.hasRemaining()) { + while (buffer.hasRemaining()) { fc.write(buffer); } return true; @@ -105,7 +106,7 @@ public boolean obtainLock(int id, String metaInfo) throws IOException { @Override public boolean releaseLock(int id) { LockReference lock = locks[id]; - if(lock == null) { + if (lock == null) { LOGGER.error(String.format("Cannot release lock for id %d as don't have it!", id)); return false; } @@ -125,20 +126,20 @@ public boolean releaseLock(int id) { @Override public String getMetaInfo(int id) throws IOException { final File file = toFile(id); - if(isLockFree(file, id)) { + if (isLockFree(file, id)) { LOGGER.warn("Cannot obtain lock on lock file {}", file.getAbsolutePath()); return null; } LockReference lr = locks[id]; - if(lr == null) { + if (lr == null) { return null; } FileChannel fc = lr.channel; ByteBuffer buffer = ByteBuffer.allocate(64); int len = fc.read(buffer, 0); String content = new String(buffer.array(), 0, len); - if (content == null || content.isEmpty()) { + if (content.isEmpty()) { LOGGER.warn("Empty lock file {}", file.getAbsolutePath()); return null; } @@ -150,7 +151,7 @@ public String getMetaInfo(int id) throws IOException { protected File toFile(int id) { File file = super.toFile(id); try { - if(file.exists() && OS.startsWith("linux")) { + if (file.exists() && OS.startsWith("linux")) { Files.setPosixFilePermissions(file.toPath(), PosixFilePermissions.fromString("rwxrwxrwx")); } } catch (IOException e) { From d19668b7370fac40d76d9a8d7005c650acba2308 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Tue, 27 Nov 2018 19:42:01 +0000 Subject: [PATCH 030/353] Updating to bom version 2.17.70 From 7cfb6ec95dc38442b54f5412a242c458f035a191 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Tue, 27 Nov 2018 19:42:38 +0000 Subject: [PATCH 031/353] [maven-release-plugin] prepare release Java-Thread-Affinity-3.1.11 --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index d8252dcdd..4068bdc03 100755 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ 4.0.0 affinity-test - 3.1.11-SNAPSHOT + 3.1.11 bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -188,7 +188,7 @@ scm:git:https://github.com/OpenHFT/Java-Thread-Affinity.git - HEAD + Java-Thread-Affinity-3.1.11 diff --git a/affinity/pom.xml b/affinity/pom.xml index 9bf8acdeb..6c41fbd24 100755 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ 4.0.0 affinity - 3.1.11-SNAPSHOT + 3.1.11 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -224,7 +224,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - master + Java-Thread-Affinity-3.1.11 diff --git a/pom.xml b/pom.xml index 7d63866e2..a3e05b52f 100755 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ 4.0.0 Java-Thread-Affinity - 3.1.11-SNAPSHOT + 3.1.11 pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - master + Java-Thread-Affinity-3.1.11 From c2e300dd69bcb220e65ff47fa22f4e7f70b8a292 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Tue, 27 Nov 2018 19:42:45 +0000 Subject: [PATCH 032/353] [maven-release-plugin] prepare for next development iteration --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 4068bdc03..b3b86506e 100755 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ 4.0.0 affinity-test - 3.1.11 + 3.1.12-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -188,7 +188,7 @@ scm:git:https://github.com/OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.1.11 + HEAD diff --git a/affinity/pom.xml b/affinity/pom.xml index 6c41fbd24..0864a096f 100755 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ 4.0.0 affinity - 3.1.11 + 3.1.12-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity @@ -224,7 +224,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.1.11 + master diff --git a/pom.xml b/pom.xml index a3e05b52f..2206c1a4e 100755 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ 4.0.0 Java-Thread-Affinity - 3.1.11 + 3.1.12-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.1.11 + master From 0a254079c78f90fcf21673f8aa00a038c1311517 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Tue, 27 Nov 2018 19:44:02 +0000 Subject: [PATCH 033/353] Reverting back to bom version 2.17-SNAPSHOT From 5b3a614a608fd8b5021bce294d8883557edf5af0 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Tue, 27 Nov 2018 19:45:13 +0000 Subject: [PATCH 034/353] Reverting back to bom version 2.17-SNAPSHOT From 146846a84d263ef404df57bf065be60d265c1d28 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Thu, 3 Jan 2019 17:36:05 +0000 Subject: [PATCH 035/353] Format code using IDEA default. --- .../java/net/openhft/affinity/Affinity.java | 8 +++--- .../java/net/openhft/affinity/LockCheck.java | 10 ++++---- .../net/openhft/affinity/LockInventory.java | 3 --- .../lockchecker/FileBasedLockChecker.java | 25 +++++++++---------- .../lockchecker/FileLockBasedLockChecker.java | 9 +++---- .../affinity/lockchecker/LockReference.java | 1 - .../affinity/main/AffinityTestMain.java | 6 ++--- .../openhft/affinity/AffinityLockTest.java | 2 +- .../affinity/FileLockLockCheckTest.java | 2 +- .../net/openhft/affinity/LockCheckTest.java | 2 +- .../TestFileLockBasedLockChecker.java | 2 +- affinity/src/test/resources/i7.properties | 1 - 12 files changed, 32 insertions(+), 39 deletions(-) diff --git a/affinity/src/main/java/net/openhft/affinity/Affinity.java b/affinity/src/main/java/net/openhft/affinity/Affinity.java index c2c7f308d..3253f817f 100644 --- a/affinity/src/main/java/net/openhft/affinity/Affinity.java +++ b/affinity/src/main/java/net/openhft/affinity/Affinity.java @@ -155,16 +155,16 @@ public static BitSet getAffinity() { return AFFINITY_IMPL.getAffinity(); } + public static void setAffinity(final BitSet affinity) { + AFFINITY_IMPL.setAffinity(affinity); + } + public static void setAffinity(int cpu) { BitSet affinity = new BitSet(Runtime.getRuntime().availableProcessors()); affinity.set(cpu); setAffinity(affinity); } - public static void setAffinity(final BitSet affinity) { - AFFINITY_IMPL.setAffinity(affinity); - } - public static int getCpu() { return AFFINITY_IMPL.getCpu(); } diff --git a/affinity/src/main/java/net/openhft/affinity/LockCheck.java b/affinity/src/main/java/net/openhft/affinity/LockCheck.java index 63e713d2b..1ab24fb8b 100644 --- a/affinity/src/main/java/net/openhft/affinity/LockCheck.java +++ b/affinity/src/main/java/net/openhft/affinity/LockCheck.java @@ -22,7 +22,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.*; +import java.io.File; +import java.io.IOException; /** * @author Rob Austin. @@ -35,7 +36,6 @@ enum LockCheck { static final boolean IS_LINUX = OS.startsWith("linux"); private static final int EMPTY_PID = Integer.MIN_VALUE; - private static final LockChecker lockChecker = FileLockBasedLockChecker.getInstance(); static long getPID() { @@ -87,7 +87,7 @@ static boolean isProcessRunning(long pid) { * below */ private synchronized static void storePid(long processID, int cpu) throws IOException { - if(!lockChecker.obtainLock(cpu, Long.toString(processID))) { + if (!lockChecker.obtainLock(cpu, Long.toString(processID))) { throw new IOException(String.format("Cannot obtain file lock for cpu %d", cpu)); } } @@ -99,10 +99,10 @@ private synchronized static boolean isLockFree(int id) { static int getProcessForCpu(int core) throws IOException { String meta = lockChecker.getMetaInfo(core); - if(meta != null && !meta.isEmpty()) { + if (meta != null && !meta.isEmpty()) { try { return Integer.parseInt(meta); - } catch(NumberFormatException e) { + } catch (NumberFormatException e) { //nothing } } diff --git a/affinity/src/main/java/net/openhft/affinity/LockInventory.java b/affinity/src/main/java/net/openhft/affinity/LockInventory.java index 892fcc83f..9291e9837 100644 --- a/affinity/src/main/java/net/openhft/affinity/LockInventory.java +++ b/affinity/src/main/java/net/openhft/affinity/LockInventory.java @@ -21,9 +21,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; import java.util.NavigableMap; import java.util.TreeMap; diff --git a/affinity/src/main/java/net/openhft/affinity/lockchecker/FileBasedLockChecker.java b/affinity/src/main/java/net/openhft/affinity/lockchecker/FileBasedLockChecker.java index 72c039bc0..37224e104 100644 --- a/affinity/src/main/java/net/openhft/affinity/lockchecker/FileBasedLockChecker.java +++ b/affinity/src/main/java/net/openhft/affinity/lockchecker/FileBasedLockChecker.java @@ -13,17 +13,25 @@ @SuppressWarnings("ResultOfMethodCallIgnored") public class FileBasedLockChecker implements LockChecker { - private static final Logger LOGGER = LoggerFactory.getLogger(FileBasedLockChecker.class); static final SimpleDateFormat df = new SimpleDateFormat("yyyy.MM" + ".dd 'at' HH:mm:ss z"); - + private static final Logger LOGGER = LoggerFactory.getLogger(FileBasedLockChecker.class); private static final LockChecker instance = new FileBasedLockChecker(); + protected FileBasedLockChecker() { + //nothing + } + public static LockChecker getInstance() { return instance; } - protected FileBasedLockChecker() { - //nothing + private static File tmpDir() { + final File tempDir = new File(System.getProperty("java.io.tmpdir")); + + if (!tempDir.exists()) + tempDir.mkdirs(); + + return tempDir; } @Override @@ -72,13 +80,4 @@ public String getMetaInfo(int id) throws IOException { protected File toFile(int id) { return new File(tmpDir(), "cpu-" + id + ".lock"); } - - private static File tmpDir() { - final File tempDir = new File(System.getProperty("java.io.tmpdir")); - - if (!tempDir.exists()) - tempDir.mkdirs(); - - return tempDir; - } } diff --git a/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java b/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java index 3e62380f4..30b924a3a 100644 --- a/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java +++ b/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java @@ -31,17 +31,16 @@ public class FileLockBasedLockChecker extends FileBasedLockChecker { private static final LockChecker instance = new FileLockBasedLockChecker(); private static final HashSet openOptions = new HashSet<>(Arrays.asList(CREATE_NEW, WRITE, READ, SYNC)); private static final FileAttribute> fileAttr = PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("rw-rw-rw-")); - - public static LockChecker getInstance() { - return instance; - } - private final LockReference[] locks = new LockReference[MAX_CPUS_SUPPORTED]; protected FileLockBasedLockChecker() { //nothing } + public static LockChecker getInstance() { + return instance; + } + @Override public boolean isLockFree(int id) { return isLockFree(toFile(id), id); diff --git a/affinity/src/main/java/net/openhft/affinity/lockchecker/LockReference.java b/affinity/src/main/java/net/openhft/affinity/lockchecker/LockReference.java index ec740ca18..d5ed1c707 100644 --- a/affinity/src/main/java/net/openhft/affinity/lockchecker/LockReference.java +++ b/affinity/src/main/java/net/openhft/affinity/lockchecker/LockReference.java @@ -1,6 +1,5 @@ package net.openhft.affinity.lockchecker; - import java.nio.channels.FileChannel; import java.nio.channels.FileLock; diff --git a/affinity/src/main/java/net/openhft/affinity/main/AffinityTestMain.java b/affinity/src/main/java/net/openhft/affinity/main/AffinityTestMain.java index 9f556ed8f..ef9070316 100644 --- a/affinity/src/main/java/net/openhft/affinity/main/AffinityTestMain.java +++ b/affinity/src/main/java/net/openhft/affinity/main/AffinityTestMain.java @@ -15,13 +15,13 @@ public class AffinityTestMain { public static void main(String[] args) { int cpus = 1; - if(args.length == 0) { + if (args.length == 0) { cpus = AffinityLock.cpuLayout().cpus() / 12; } else { cpus = Integer.valueOf(args[0]); } - for(int i=0; i Date: Thu, 3 Jan 2019 17:39:48 +0000 Subject: [PATCH 036/353] Pass tests on Centos 7 desktop --- .../src/test/java/net/openhft/affinity/AffinityLockTest.java | 4 ++-- .../java/net/openhft/affinity/impl/PosixJNAAffinityTest.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java index c54f399cf..820453b50 100644 --- a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java +++ b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java @@ -224,8 +224,8 @@ public void run() { public void shouldReturnLockForSpecifiedCpu() { assumeTrue(Runtime.getRuntime().availableProcessors() > 3); - try (final AffinityLock affinityLock = AffinityLock.acquireLock(2)) { - assertThat(affinityLock.cpuId(), is(2)); + try (final AffinityLock affinityLock = AffinityLock.acquireLock(3)) { + assertThat(affinityLock.cpuId(), is(3)); } } diff --git a/affinity/src/test/java/net/openhft/affinity/impl/PosixJNAAffinityTest.java b/affinity/src/test/java/net/openhft/affinity/impl/PosixJNAAffinityTest.java index e58e1baa4..4fb776bac 100644 --- a/affinity/src/test/java/net/openhft/affinity/impl/PosixJNAAffinityTest.java +++ b/affinity/src/test/java/net/openhft/affinity/impl/PosixJNAAffinityTest.java @@ -55,7 +55,7 @@ public void testGettid() { tid = Thread.currentThread().getId(); time += System.nanoTime() - start; assertTrue(tid > 0); - assertTrue(tid < 1 << 16); + assertTrue(tid < 1 << 24); } System.out.printf("gettid took an average of %,d ns, tid=%d%n", time / runs, tid); } From b4e2bcd4ea21170d9fffe6e3debfe97a4af6cb51 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Mon, 21 Jan 2019 11:13:51 +0000 Subject: [PATCH 037/353] Use third-party-bom 3.6.9 --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index b3b86506e..4962d2a97 100755 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -42,7 +42,7 @@ net.openhft third-party-bom pom - 3.6.5 + 3.6.9 import diff --git a/affinity/pom.xml b/affinity/pom.xml index 0864a096f..da600d739 100755 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -43,7 +43,7 @@ net.openhft third-party-bom pom - 3.6.5 + 3.6.9 import From 1d155fc81737e811510d60b24bb07971bcab4492 Mon Sep 17 00:00:00 2001 From: Jan Nielsen Date: Sat, 16 Feb 2019 11:16:29 -0700 Subject: [PATCH 038/353] Update java-parent-pom version --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 4962d2a97..018e882f7 100755 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -20,7 +20,7 @@ net.openhft java-parent-pom - 1.1.16 + 1.1.18 diff --git a/affinity/pom.xml b/affinity/pom.xml index da600d739..2c50a8141 100755 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -20,7 +20,7 @@ net.openhft java-parent-pom - 1.1.16 + 1.1.18 From e0987f6f21aeea89830d8010483bb4abca54fc1b Mon Sep 17 00:00:00 2001 From: Dmitry Pisklov Date: Mon, 25 Feb 2019 12:25:04 +0000 Subject: [PATCH 039/353] Use latest java-parent-pom --- affinity-test/pom.xml | 3 +-- affinity/pom.xml | 8 +++----- pom.xml | 2 +- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 018e882f7..029f4236b 100755 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -20,7 +20,7 @@ net.openhft java-parent-pom - 1.1.18 + 1.1.22 @@ -125,7 +125,6 @@ org.apache.maven.plugins maven-compiler-plugin - 3.6.2 -Xlint:deprecation 1.8 diff --git a/affinity/pom.xml b/affinity/pom.xml index 2c50a8141..85b27bf6c 100755 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -20,8 +20,7 @@ net.openhft java-parent-pom - 1.1.18 - + 1.1.22 4.0.0 @@ -90,11 +89,10 @@ org.apache.maven.plugins maven-compiler-plugin - 3.6.2 -Xlint:deprecation - 1.7 - 1.7 + 1.8 + 1.8 UTF-8 diff --git a/pom.xml b/pom.xml index 2206c1a4e..50833ab8c 100755 --- a/pom.xml +++ b/pom.xml @@ -20,7 +20,7 @@ net.openhft root-parent-pom - 1.1.12 + 1.2.1 From b9e4a4074ac0e6820c66795370cc5db9d1026602 Mon Sep 17 00:00:00 2001 From: mprusakov <50633030+mprusakov@users.noreply.github.com> Date: Tue, 14 May 2019 17:43:18 +0100 Subject: [PATCH 040/353] Allow thread pinning by pid It is not always possible to access the thread to be pinned. This method allows any thread to be pinned. Tested on RHEL 7. --- .../java/net/openhft/affinity/impl/LinuxHelper.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java b/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java index be9689a08..84de3884b 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java @@ -66,7 +66,11 @@ cpu_set_t sched_getaffinity() { return cpuset; } - public static void sched_setaffinity(final BitSet affinity) { + public static void sched_setaffinity(final BitSet affinity) { + sched_setaffinity(0, affinity); + } + + public static void sched_setaffinity(final int pid, final BitSet affinity) { final CLibrary lib = CLibrary.INSTANCE; final cpu_set_t cpuset = new cpu_set_t(); final int size = version.isSameOrNewer(VERSION_2_6) ? cpu_set_t.SIZE_OF_CPU_SET_T : NativeLong.SIZE; @@ -80,12 +84,12 @@ public static void sched_setaffinity(final BitSet affinity) { } } try { - if (lib.sched_setaffinity(0, size, cpuset) != 0) { - throw new IllegalStateException("sched_setaffinity(0, " + size + + if (lib.sched_setaffinity(pid, size, cpuset) != 0) { + throw new IllegalStateException("sched_setaffinity(" + pid + ", " + size + ", 0x" + Utilities.toHexString(affinity) + ") failed; errno=" + Native.getLastError()); } } catch (LastErrorException e) { - throw new IllegalStateException("sched_setaffinity(0, " + size + + throw new IllegalStateException("sched_setaffinity(" + pid + ", " + size + ", 0x" + Utilities.toHexString(affinity) + ") failed; errno=" + e.getErrorCode(), e); } } From 6149523071cc87bdb682268471aab94fa9271fde Mon Sep 17 00:00:00 2001 From: leo <254213048@qq.com> Date: Tue, 25 Jun 2019 18:57:55 +0800 Subject: [PATCH 041/353] Update LockInventory.java I use intel i7. When I use -Daffinity.reserved=01 as vm argument, I found variable "reservable" is always printed as "true" LOGGER.trace("cpu " + i + " base={} reservable= {}", i, base, reservable); should be: LOGGER.trace("cpu {} base={} reservable= {}", i, base, reservable); --- .../src/main/java/net/openhft/affinity/LockInventory.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/affinity/src/main/java/net/openhft/affinity/LockInventory.java b/affinity/src/main/java/net/openhft/affinity/LockInventory.java index 9291e9837..55737c63d 100644 --- a/affinity/src/main/java/net/openhft/affinity/LockInventory.java +++ b/affinity/src/main/java/net/openhft/affinity/LockInventory.java @@ -83,8 +83,7 @@ public final synchronized void set(CpuLayout cpuLayout) { for (int i = 0; i < cpuLayout.cpus(); i++) { final boolean base = AffinityLock.BASE_AFFINITY.get(i); final boolean reservable = AffinityLock.RESERVED_AFFINITY.get(i); - - LOGGER.trace("cpu " + i + " base={} reservable= {}", i, base, reservable); + LOGGER.trace("cpu {} base={} reservable= {}", i, base, reservable); AffinityLock lock = logicalCoreLocks[i] = newLock(i, base, reservable); int layoutId = lock.cpuId(); @@ -213,4 +212,4 @@ private void releaseAffinityLock(final Thread t, final AffinityLock al, final St LockCheck.releaseLock(al.cpuId()); } -} \ No newline at end of file +} From 624ff54760ed3952b7fb51bf8f4e4e982e3e2eb5 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Fri, 28 Jun 2019 18:25:16 +0100 Subject: [PATCH 042/353] Fix Linux tests so they are ignored on windows. --- .../net/openhft/affinity/impl/LinuxJNAAffinity.java | 10 +++++++--- .../net/openhft/affinity/impl/VanillaCpuLayout.java | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) mode change 100644 => 100755 affinity/src/main/java/net/openhft/affinity/impl/LinuxJNAAffinity.java mode change 100644 => 100755 affinity/src/main/java/net/openhft/affinity/impl/VanillaCpuLayout.java diff --git a/affinity/src/main/java/net/openhft/affinity/impl/LinuxJNAAffinity.java b/affinity/src/main/java/net/openhft/affinity/impl/LinuxJNAAffinity.java old mode 100644 new mode 100755 index c4a25d9ee..04bc5901a --- a/affinity/src/main/java/net/openhft/affinity/impl/LinuxJNAAffinity.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/LinuxJNAAffinity.java @@ -33,11 +33,14 @@ public enum LinuxJNAAffinity implements IAffinity { private static final int SYS_gettid = Platform.is64Bit() ? 186 : 224; private static final Object[] NO_ARGS = {}; + private static final String OS = System.getProperty("os.name").toLowerCase(); + private static final boolean IS_LINUX = OS.startsWith("linux"); + static { int pid = -1; try { pid = LinuxHelper.getpid(); - } catch (Exception ignored) { + } catch (NoClassDefFoundError | Exception ignored) { } PROCESS_ID = pid; } @@ -47,8 +50,9 @@ public enum LinuxJNAAffinity implements IAffinity { try { INSTANCE.getAffinity(); loaded = true; - } catch (UnsatisfiedLinkError e) { - LOGGER.warn("Unable to load jna library {}", e); + } catch (NoClassDefFoundError | UnsatisfiedLinkError e) { + if (IS_LINUX) + LOGGER.warn("Unable to load jna library {}", e); } LOADED = loaded; } diff --git a/affinity/src/main/java/net/openhft/affinity/impl/VanillaCpuLayout.java b/affinity/src/main/java/net/openhft/affinity/impl/VanillaCpuLayout.java old mode 100644 new mode 100755 index 2436990b1..546fd968c --- a/affinity/src/main/java/net/openhft/affinity/impl/VanillaCpuLayout.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/VanillaCpuLayout.java @@ -30,7 +30,7 @@ * @author peter.lawrey */ public class VanillaCpuLayout implements CpuLayout { - public static final int MAX_CPUS_SUPPORTED = 64; + public static final int MAX_CPUS_SUPPORTED = 256; @NotNull private final List cpuDetails; From 5273f130292b4a8c91f628f30498488df91c6c67 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Thu, 15 Aug 2019 14:41:29 +0100 Subject: [PATCH 043/353] Reduce redundant newlines --- affinity/src/main/java/net/openhft/affinity/BootClassPath.java | 1 - 1 file changed, 1 deletion(-) diff --git a/affinity/src/main/java/net/openhft/affinity/BootClassPath.java b/affinity/src/main/java/net/openhft/affinity/BootClassPath.java index a6eb8e337..e51ac738a 100644 --- a/affinity/src/main/java/net/openhft/affinity/BootClassPath.java +++ b/affinity/src/main/java/net/openhft/affinity/BootClassPath.java @@ -76,7 +76,6 @@ private static Set findResourcesInJar(final Path path, final Logger logg jarResources.add(jarEntry.getName()); } } - } catch (IOException e) { logger.warn("Not a jar file: {}", path); } From ad3eccee19fca601152f7ea48c148b6fa3ebe0ad Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Thu, 22 Aug 2019 16:33:23 +0100 Subject: [PATCH 044/353] Activate pre-java9 via a profile for better post Java8 support. --- affinity-test/pom.xml | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 029f4236b..11a8da6bf 100755 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -54,10 +54,6 @@ - - com.sun.java - tools - net.openhft affinity @@ -185,6 +181,26 @@ + + + pre-java9 + + + com.sun + tools + 1.8.0 + system + ${java.home}/../lib/tools.jar + + + + + ${java.home}/../lib/tools.jar + + + + + scm:git:https://github.com/OpenHFT/Java-Thread-Affinity.git HEAD From b1d938dd7ed42bd5e0ec85a50d5f4716ba2857be Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Tue, 29 Oct 2019 14:58:45 +0000 Subject: [PATCH 045/353] Updating to bom version 2.17.414 From 146250b98285c6444bc49f3a12deef3c63462f86 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Tue, 29 Oct 2019 14:59:12 +0000 Subject: [PATCH 046/353] [maven-release-plugin] prepare release Java-Thread-Affinity-3.1.12 --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 11a8da6bf..cd004c7c4 100755 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ 4.0.0 affinity-test - 3.1.12-SNAPSHOT + 3.1.12 bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:https://github.com/OpenHFT/Java-Thread-Affinity.git - HEAD + Java-Thread-Affinity-3.1.12 diff --git a/affinity/pom.xml b/affinity/pom.xml index 85b27bf6c..d12a3cea8 100755 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -25,7 +25,7 @@ 4.0.0 affinity - 3.1.12-SNAPSHOT + 3.1.12 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -222,7 +222,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - master + Java-Thread-Affinity-3.1.12 diff --git a/pom.xml b/pom.xml index 50833ab8c..16ab77422 100755 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ 4.0.0 Java-Thread-Affinity - 3.1.12-SNAPSHOT + 3.1.12 pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - master + Java-Thread-Affinity-3.1.12 From 729ab2b565a8a60af572bdd2c495708ccbfda171 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Tue, 29 Oct 2019 14:59:19 +0000 Subject: [PATCH 047/353] [maven-release-plugin] prepare for next development iteration --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index cd004c7c4..6c163d12a 100755 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ 4.0.0 affinity-test - 3.1.12 + 3.1.13-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:https://github.com/OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.1.12 + HEAD diff --git a/affinity/pom.xml b/affinity/pom.xml index d12a3cea8..024764bd2 100755 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -25,7 +25,7 @@ 4.0.0 affinity - 3.1.12 + 3.1.13-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity @@ -222,7 +222,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.1.12 + master diff --git a/pom.xml b/pom.xml index 16ab77422..fda0f0454 100755 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ 4.0.0 Java-Thread-Affinity - 3.1.12 + 3.1.13-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.1.12 + master From 48d9960b8c54ea7026833ab9cb4ed46ea346c871 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Tue, 29 Oct 2019 15:32:57 +0000 Subject: [PATCH 048/353] Updating to bom version 2.17.414 From b689ce6d82e76eed857c1c14bee819e53cddb375 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Tue, 29 Oct 2019 15:33:22 +0000 Subject: [PATCH 049/353] [maven-release-plugin] prepare release Java-Thread-Affinity-3.1.13 --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 6c163d12a..455d3bca8 100755 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ 4.0.0 affinity-test - 3.1.13-SNAPSHOT + 3.1.13 bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:https://github.com/OpenHFT/Java-Thread-Affinity.git - HEAD + Java-Thread-Affinity-3.1.13 diff --git a/affinity/pom.xml b/affinity/pom.xml index 024764bd2..ebe3d8ae6 100755 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -25,7 +25,7 @@ 4.0.0 affinity - 3.1.13-SNAPSHOT + 3.1.13 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -222,7 +222,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - master + Java-Thread-Affinity-3.1.13 diff --git a/pom.xml b/pom.xml index fda0f0454..bac8f3c88 100755 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ 4.0.0 Java-Thread-Affinity - 3.1.13-SNAPSHOT + 3.1.13 pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - master + Java-Thread-Affinity-3.1.13 From 03847a968d7e8564b4316a1c9f94d9b4ff80802c Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Tue, 29 Oct 2019 15:33:29 +0000 Subject: [PATCH 050/353] [maven-release-plugin] prepare for next development iteration --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 455d3bca8..ece8fb7b7 100755 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ 4.0.0 affinity-test - 3.1.13 + 3.1.14-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:https://github.com/OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.1.13 + HEAD diff --git a/affinity/pom.xml b/affinity/pom.xml index ebe3d8ae6..bf11774c0 100755 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -25,7 +25,7 @@ 4.0.0 affinity - 3.1.13 + 3.1.14-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity @@ -222,7 +222,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.1.13 + master diff --git a/pom.xml b/pom.xml index bac8f3c88..e963ff54d 100755 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ 4.0.0 Java-Thread-Affinity - 3.1.13 + 3.1.14-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.1.13 + master From dc1e4efaabe2e44dd04d2f816ab1b271825c05d3 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Tue, 29 Oct 2019 15:35:07 +0000 Subject: [PATCH 051/353] Reverting back to bom version 2.17-SNAPSHOT From d212a0fff4fc394370f20b2bfcc59c084e4f6917 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Tue, 26 Nov 2019 08:29:10 +0000 Subject: [PATCH 052/353] third-party-bom -> 3.6.15 --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index ece8fb7b7..58c1812d7 100755 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -42,7 +42,7 @@ net.openhft third-party-bom pom - 3.6.9 + 3.6.15 import diff --git a/affinity/pom.xml b/affinity/pom.xml index bf11774c0..31d2427b0 100755 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -42,7 +42,7 @@ net.openhft third-party-bom pom - 3.6.9 + 3.6.15 import From 95715551baee1924a00b81073f34e5bd738a9745 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Mon, 9 Dec 2019 07:56:52 +0000 Subject: [PATCH 053/353] Added support for setting thread affinity using a description, closes https://github.com/OpenHFT/Java-Thread-Affinity/issues/54 --- .../net/openhft/affinity/AffinityLock.java | 69 ++++++++++++++++++- .../net/openhft/affinity/LockInventory.java | 12 ++-- .../affinity/impl/PosixJNAAffinity.java | 24 +------ .../net/openhft/affinity/impl/Utilities.java | 21 ++++++ .../openhft/affinity/AffinityLockTest.java | 39 ++++++++++- 5 files changed, 134 insertions(+), 31 deletions(-) diff --git a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java index c9c714115..886832ebb 100644 --- a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java +++ b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java @@ -175,6 +175,71 @@ public static AffinityLock acquireLock(int cpuId) { return acquireLock(true, cpuId, AffinityStrategies.ANY); } + /** + * Allocate from the end. + * + * @param n positive number to allocate from. + * @return the lock acquired + */ + public static AffinityLock acquireLockLastMinus(int n) { + return acquireLock(true, PROCESSORS - n, AffinityStrategies.ANY); + } + + /** + * Use a description to allocate a cpu. + *
    + *
  • "N" being a positive integer means allocate this CPU,
  • + *
  • "last" or "last-N" means allocate from the end,
  • + *
  • "any" means allow any
  • + *
  • "none" or null means
  • + *
  • "0" is not allowed
  • + *
+ * + * @param desc of which cpu to pick + * @return the AffinityLock obtained + */ + public static AffinityLock acquireLock(String desc) { + if (desc == null) + return LOCK_INVENTORY.noLock(); + + desc = desc.toLowerCase(); + int cpuId; + if (desc.startsWith("last")) { + String last = desc.substring(4); + int lastN; + if (last.isEmpty()) + lastN = 0; + else + try { + lastN = Integer.parseInt(last); + } catch (NumberFormatException e) { + throw new IllegalArgumentException("Cannot parse '" + desc + "'", e); + } + if (lastN > 0) + throw new IllegalArgumentException("Cannot parse '" + desc + "'"); + + cpuId = PROCESSORS + lastN - 1; + + } else if (desc.equals("none")) { + return LOCK_INVENTORY.noLock(); + + } else if (desc.equals("any")) { + return acquireLock(); + + } else { + try { + cpuId = Integer.parseInt(desc); + } catch (NumberFormatException e) { + throw new IllegalArgumentException("Cannot parse '" + desc + "'", e); + } + } + if (cpuId <= 0) { + System.err.println("Cannot allocate 0 or negative cpuIds '" + desc + "'"); + return LOCK_INVENTORY.noLock(); + } + return acquireLock(cpuId); + } + /** * Assign a core(and all its cpus) which can be bound to the current thread or another thread. *

This can be used for defining your thread layout centrally and passing the handle via @@ -256,12 +321,12 @@ public void bind(boolean wholeCore) { } } - final boolean canReserve() { + final boolean canReserve(boolean specified) { if (!LockCheck.isCpuFree(cpuId)) return false; - if (!reservable) return false; + if (!specified && !reservable) return false; if (assignedThread != null) { if (assignedThread.isAlive()) { return false; diff --git a/affinity/src/main/java/net/openhft/affinity/LockInventory.java b/affinity/src/main/java/net/openhft/affinity/LockInventory.java index 55737c63d..52aea2f63 100644 --- a/affinity/src/main/java/net/openhft/affinity/LockInventory.java +++ b/affinity/src/main/java/net/openhft/affinity/LockInventory.java @@ -100,7 +100,7 @@ public final synchronized AffinityLock acquireLock(boolean bind, int cpuId, Affi final boolean specificCpuRequested = !isAnyCpu(cpuId); if (specificCpuRequested && cpuId != 0) { final AffinityLock required = logicalCoreLocks[cpuId]; - if (required.canReserve() && anyStrategyMatches(cpuId, cpuId, strategies)) { + if (required.canReserve(true) && anyStrategyMatches(cpuId, cpuId, strategies)) { updateLockForCurrentThread(bind, required, false); return required; } @@ -113,7 +113,7 @@ public final synchronized AffinityLock acquireLock(boolean bind, int cpuId, Affi // if you have only one core, this library is not appropriate in any case. for (int i = logicalCoreLocks.length - 1; i > 0; i--) { AffinityLock al = logicalCoreLocks[i]; - if (al.canReserve() && (isAnyCpu(cpuId) || strategy.matches(cpuId, al.cpuId()))) { + if (al.canReserve(false) && (isAnyCpu(cpuId) || strategy.matches(cpuId, al.cpuId()))) { updateLockForCurrentThread(bind, al, false); return al; } @@ -122,7 +122,7 @@ public final synchronized AffinityLock acquireLock(boolean bind, int cpuId, Affi LOGGER.warn("No reservable CPU for {}", Thread.currentThread()); - return newLock(AffinityLock.ANY_CPU, false, false); + return noLock(); } public final synchronized AffinityLock acquireCore(boolean bind, int cpuId, AffinityStrategy... strategies) { @@ -130,7 +130,7 @@ public final synchronized AffinityLock acquireCore(boolean bind, int cpuId, Affi LOOP: for (AffinityLock[] als : physicalCoreLocks.descendingMap().values()) { for (AffinityLock al : als) - if (!al.canReserve() || !strategy.matches(cpuId, al.cpuId())) + if (!al.canReserve(false) || !strategy.matches(cpuId, al.cpuId())) continue LOOP; final AffinityLock al = als[0]; @@ -212,4 +212,8 @@ private void releaseAffinityLock(final Thread t, final AffinityLock al, final St LockCheck.releaseLock(al.cpuId()); } + + public AffinityLock noLock() { + return newLock(AffinityLock.ANY_CPU, false, false); + } } diff --git a/affinity/src/main/java/net/openhft/affinity/impl/PosixJNAAffinity.java b/affinity/src/main/java/net/openhft/affinity/impl/PosixJNAAffinity.java index 3a5cae58e..16dbaf94d 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/PosixJNAAffinity.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/PosixJNAAffinity.java @@ -44,9 +44,7 @@ public enum PosixJNAAffinity implements IAffinity { private static final Logger LOGGER = LoggerFactory.getLogger(PosixJNAAffinity.class); private static final String LIBRARY_NAME = Platform.isWindows() ? "msvcrt" : "c"; private static final int PROCESS_ID; - private static final boolean ISLINUX = "Linux".equals(System.getProperty("os.name")); - private static final boolean IS64BIT = is64Bit0(); - private static final int SYS_gettid = is64Bit() ? 186 : 224; + private static final int SYS_gettid = Utilities.is64Bit() ? 186 : 224; private static final Object[] NO_ARGS = {}; static { @@ -72,24 +70,6 @@ public enum PosixJNAAffinity implements IAffinity { private final ThreadLocal THREAD_ID = new ThreadLocal<>(); - public static boolean is64Bit() { - return IS64BIT; - } - - private static boolean is64Bit0() { - String systemProp; - systemProp = System.getProperty("com.ibm.vm.bitmode"); - if (systemProp != null) { - return "64".equals(systemProp); - } - systemProp = System.getProperty("sun.arch.data.model"); - if (systemProp != null) { - return "64".equals(systemProp); - } - systemProp = System.getProperty("java.vm.version"); - return systemProp != null && systemProp.contains("_64"); - } - @Override public BitSet getAffinity() { final CLibrary lib = CLibrary.INSTANCE; @@ -198,7 +178,7 @@ public int getProcessId() { @Override public int getThreadId() { - if (ISLINUX) { + if (Utilities.ISLINUX) { Integer tid = THREAD_ID.get(); if (tid == null) THREAD_ID.set(tid = CLibrary.INSTANCE.syscall(SYS_gettid, NO_ARGS)); diff --git a/affinity/src/main/java/net/openhft/affinity/impl/Utilities.java b/affinity/src/main/java/net/openhft/affinity/impl/Utilities.java index ebff4a42d..f5894990f 100755 --- a/affinity/src/main/java/net/openhft/affinity/impl/Utilities.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/Utilities.java @@ -25,6 +25,9 @@ * Created by andre on 20/06/15. */ public final class Utilities { + public static final boolean ISLINUX = "Linux".equals(System.getProperty("os.name")); + static final boolean IS64BIT = is64Bit0(); + private Utilities() { throw new InstantiationError("Must not instantiate this class"); } @@ -58,4 +61,22 @@ public static String toBinaryString(BitSet set) { return new String(out.toByteArray(), java.nio.charset.StandardCharsets.UTF_8); } + + public static boolean is64Bit() { + return IS64BIT; + } + + private static boolean is64Bit0() { + String systemProp; + systemProp = System.getProperty("com.ibm.vm.bitmode"); + if (systemProp != null) { + return "64".equals(systemProp); + } + systemProp = System.getProperty("sun.arch.data.model"); + if (systemProp != null) { + return "64".equals(systemProp); + } + systemProp = System.getProperty("java.vm.version"); + return systemProp != null && systemProp.contains("_64"); + } } diff --git a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java index 820453b50..25d1d6736 100644 --- a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java +++ b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java @@ -17,6 +17,7 @@ package net.openhft.affinity; +import net.openhft.affinity.impl.Utilities; import net.openhft.affinity.impl.VanillaCpuLayout; import net.openhft.affinity.testimpl.TestFileBasedLockChecker; import org.junit.Test; @@ -30,6 +31,7 @@ import java.util.ArrayList; import java.util.List; +import static net.openhft.affinity.AffinityLock.PROCESSORS; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.*; import static org.junit.Assume.assumeTrue; @@ -174,7 +176,7 @@ public void testIssue21() throws IOException { @Test public void testIssue19() { - System.out.println("AffinityLock.PROCESSORS=" + AffinityLock.PROCESSORS); + System.out.println("AffinityLock.PROCESSORS=" + PROCESSORS); AffinityLock al = AffinityLock.acquireLock(); List locks = new ArrayList<>(); @@ -231,8 +233,8 @@ public void shouldReturnLockForSpecifiedCpu() { @Test public void lockFilesShouldBeRemovedOnRelease() { - if (System.getProperty("os.name").toLowerCase().startsWith("win")) { - return;//doesn't work on Windows + if (!Utilities.ISLINUX) { + return; } final AffinityLock lock = AffinityLock.acquireLock(); @@ -246,4 +248,35 @@ public void lockFilesShouldBeRemovedOnRelease() { private void displayStatus() { System.out.println(Thread.currentThread() + " on " + Affinity.getCpu() + "\n" + AffinityLock.dumpLocks()); } + + @Test + public void testAffinityLockDescriptions() { + if (!Utilities.ISLINUX) { + return; + } + try (AffinityLock lock = AffinityLock.acquireLock("last")) { + assertEquals(PROCESSORS - 1, Affinity.getCpu()); + } + try (AffinityLock lock = AffinityLock.acquireLock("last")) { + assertEquals(PROCESSORS - 1, Affinity.getCpu()); + } + try (AffinityLock lock = AffinityLock.acquireLock("last-1")) { + assertEquals(PROCESSORS - 2, Affinity.getCpu()); + } + try (AffinityLock lock = AffinityLock.acquireLock("1")) { + assertEquals(1, Affinity.getCpu()); + } + try (AffinityLock lock = AffinityLock.acquireLock("any")) { + assertTrue(lock.bound); + } + try (AffinityLock lock = AffinityLock.acquireLock("none")) { + assertFalse(lock.bound); + } + try (AffinityLock lock = AffinityLock.acquireLock((String) null)) { + assertFalse(lock.bound); + } + try (AffinityLock lock = AffinityLock.acquireLock("0")) { + assertFalse(lock.bound); + } + } } From 24b5366fda46817f6adb0402f810121471278273 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Mon, 9 Dec 2019 07:58:33 +0000 Subject: [PATCH 054/353] Added support for setting thread affinity using a description, closes https://github.com/OpenHFT/Java-Thread-Affinity/issues/54 --- README.adoc | 132 +++++++++++++++++++++++++++++++++++----------------- pom.xml | 2 +- 2 files changed, 91 insertions(+), 43 deletions(-) diff --git a/README.adoc b/README.adoc index 79a6fb49c..57a8c48e5 100644 --- a/README.adoc +++ b/README.adoc @@ -2,13 +2,13 @@ image::/images/Thread-Affinity_line.png[width=20%] -=== Version +== Version [#image-maven] [caption="", link=https://maven-badges.herokuapp.com/maven-central/net.openhft/affinity] image::https://maven-badges.herokuapp.com/maven-central/net.openhft/affinity/badge.svg[] -=== Overview +== Overview Lets you bind a thread to a given core, this can improve performance (this library works best on linux). OpenHFT Java Thread Affinity library @@ -16,11 +16,12 @@ OpenHFT Java Thread Affinity library See https://github.com/OpenHFT/Java-Thread-Affinity/tree/master/affinity/src/test/java[affinity/src/test/java] for working examples of how to use this library. -==== Wold Wide Usage +=== Wold Wide Usage http://jrvis.com/red-dwarf/?user=openhft&repo=Java-Thread-Affinity[Thread Affinity usage Heatmap] -==== Changes +=== Changes +* V3.2.0 - Add support for text configuration * V3.1.1 - Upgraded JNA dependency to 4.4.0 * V2.0.1 - Added getThreadId for the process if of the thread. @@ -30,7 +31,7 @@ Java-Thread-Affinity will try to use https://github.com/java-native-access/jna[J to provide access to native thread-handling functions. JNA should be installed on your system to get the most from this library. -==== JNA version +=== JNA version Java-Thread-Affinity currently depends on JNA version 4.4.0, which in turn depends on a version of GLIBC >= 2.14. If your operating system is an old one, @@ -40,11 +41,11 @@ invoke native functions. To work around this problem, fork the repository, and override the `` tag for the artifacts `jna` and `jna-platform` in the project's `pom` file. -==== Installing JNA on Ubuntu +=== Installing JNA on Ubuntu sudo apt-get install libjna-java -==== Installing JNA on CentOS +=== Installing JNA on CentOS sudo yum install jna @@ -77,26 +78,28 @@ To isolate the 1st and 3rd CPU cores (CPU numbers start from 0) on your system, isolcpus=1,3 -==== Acquiring a CPU lock for a thread +== Using AffinityLock + +=== Acquiring a CPU lock for a thread You can acquire a lock for a CPU in the following way: In Java 6 [source, java] ---- - AffinityLock al = AffinityLock.acquireLock(); - try { - // do some work locked to a CPU. - } finally { - al.release(); - } +AffinityLock al = AffinityLock.acquireLock(); +try { + // do some work locked to a CPU. +} finally { + al.release(); +} ---- In Java 7 or 8 [source, java] ---- - try (AffinityLock al = AffinityLock.acquireLock()) { - // do some work while locked to a CPU. - } +try (AffinityLock al = AffinityLock.acquireLock()) { + // do some work while locked to a CPU. +} ---- You have further options such as @@ -104,27 +107,27 @@ You have further options such as You can reserve a whole core. If you have hyper-threading enabled, this will use one CPU and leave it's twin CPU unused. [source, java] ---- - try (AffinityLock al = AffinityLock.acquireCore()) { - // do some work while locked to a CPU. - } +try (AffinityLock al = AffinityLock.acquireCore()) { + // do some work while locked to a CPU. +} ---- === Controlling layout You can chose a layout relative to an existing lock. [source, java] ---- - try (final AffinityLock al = AffinityLock.acquireLock()) { - System.out.println("Main locked"); - Thread t = new Thread(new Runnable() { - @Override - public void run() { - try (AffinityLock al2 = al.acquireLock(AffinityStrategies.SAME_SOCKET, - AffinityStrategies.ANY)) { - System.out.println("Thread-0 locked"); - } +try (final AffinityLock al = AffinityLock.acquireLock()) { + System.out.println("Main locked"); + Thread t = new Thread(new Runnable() { + @Override + public void run() { + try (AffinityLock al2 = al.acquireLock(AffinityStrategies.SAME_SOCKET, + AffinityStrategies.ANY)) { + System.out.println("Thread-0 locked"); } - }); - t.start(); - } + } + }); + t.start(); +} ---- In this example, the library will prefer a free CPU on the same Socket as the first thread, otherwise it will pick any free CPU. @@ -132,31 +135,35 @@ In this example, the library will prefer a free CPU on the same Socket as the fi You can get the current thread id using [source, java] ---- - int threadId = AffinitySupport.getThreadId(); + +int threadId = AffinitySupport.getThreadId(); ---- === Determining which CPU you are running on. You can get the current CPU being used by [source, java] ---- - int cpuId = AffinitySupport.getCpu(); + +int cpuId = AffinitySupport.getCpu(); ---- === Controlling the affinity more directly. The affinity of the process on start up is [source, java] ---- - long baseAffinity = AffinityLock.BASE_AFFINITY; + +long baseAffinity = AffinityLock.BASE_AFFINITY; ---- The available CPU for reservation is [source, java] ---- - long reservedAffinity = AffinityLock.RESERVED_AFFINITY; +long reservedAffinity = AffinityLock.RESERVED_AFFINITY; ---- If you want to get/set the affinity directly you can do [source, java] ---- - long currentAffinity = AffinitySupport.getAffinity(); - AffinitySupport.setAffinity(1L << 5); // lock to CPU 5. +long currentAffinity = AffinitySupport.getAffinity(); +AffinitySupport.setAffinity(1L << 5); // lock to CPU 5. ---- + === Debugging affinity state For a detailed of view of the current affinity state (as seen by the library), @@ -188,18 +195,59 @@ For an article on how much difference affinity can make and how to use it http:/ == Questions and Answers -=== Question +=== Question: How to lock a specific cpuId I am currently working on a project related to deadlock detection in multithreaded programs in java. We are trying to run threads on different processors and thus came across your github posts regarding the same. https://github.com/peter-lawrey/Java-Thread-Affinity/wiki/Getting-started Being a beginner, I have little knowledge and thus need your assistance. We need to know how to run threads on specified cpu number and then switch threads when one is waiting. === Answer -Use : - [source, java] ---- -AffinityLock.setAffinity (1L << n); +// lock a cpuId +try (AffinityLock lock = AffinityLock.acquireLock(n)) { + +} ---- where n is the cpu you want to run the thread on. +OR + +[source,java] +---- +// lock one of the last CPUs +try (AffinityLock lock = AffinityLock.acquireLockLastMinus(n)) { + +} +---- + +=== Question: how to use a configuration file to set the cpuId + +I have the cpuId in a configuration file, how can I set it using a string? + +=== Answer: use one fo the following. + +[source,java] +---- +try (AffinityLock lock = AffinityLock.acquireLock("last")) { + assertEquals(PROCESSORS - 1, Affinity.getCpu()); +} +try (AffinityLock lock = AffinityLock.acquireLock("last-1")) { + assertEquals(PROCESSORS - 2, Affinity.getCpu()); +} +try (AffinityLock lock = AffinityLock.acquireLock("1")) { + assertEquals(1, Affinity.getCpu()); +} +try (AffinityLock lock = AffinityLock.acquireLock("any")) { + assertTrue(lock.bound); +} +try (AffinityLock lock = AffinityLock.acquireLock("none")) { + assertFalse(lock.bound); +} +try (AffinityLock lock = AffinityLock.acquireLock((String) null)) { + assertFalse(lock.bound); +} +try (AffinityLock lock = AffinityLock.acquireLock("0")) { // prints a warning + assertFalse(lock.bound); +} +---- diff --git a/pom.xml b/pom.xml index e963ff54d..3fcff944b 100755 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ 4.0.0 Java-Thread-Affinity - 3.1.14-SNAPSHOT + 3.2.0-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent From 2622d3318adc9d613ab9abd7f3eef7c67fe9e135 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Mon, 9 Dec 2019 08:07:49 +0000 Subject: [PATCH 055/353] Added support for setting thread affinity using a description, closes https://github.com/OpenHFT/Java-Thread-Affinity/issues/54 --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 58c1812d7..7b65063e4 100755 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ 4.0.0 affinity-test - 3.1.14-SNAPSHOT + 3.2.0-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test diff --git a/affinity/pom.xml b/affinity/pom.xml index 31d2427b0..81cf2d2fd 100755 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -25,7 +25,7 @@ 4.0.0 affinity - 3.1.14-SNAPSHOT + 3.2.0-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity From 961bbf0e5d9a5dc39a4ce072ad3c7e0f29e21eb1 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Mon, 9 Dec 2019 09:08:57 +0000 Subject: [PATCH 056/353] [maven-release-plugin] prepare release affinity-3.2.0 --- affinity/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index 81cf2d2fd..437910913 100755 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -25,7 +25,7 @@ 4.0.0 affinity - 3.2.0-SNAPSHOT + 3.2.0 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -222,7 +222,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - master + affinity-3.2.0 From 96ae1d2e4a03fe6295e05d5e3dcc8b13d0444591 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Mon, 9 Dec 2019 09:09:04 +0000 Subject: [PATCH 057/353] [maven-release-plugin] prepare for next development iteration --- affinity/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index 437910913..505a22dfc 100755 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -25,7 +25,7 @@ 4.0.0 affinity - 3.2.0 + 3.2.1-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity @@ -222,7 +222,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - affinity-3.2.0 + master From a3ad70296c1e315891817a41106fe8aeff06a67a Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Mon, 9 Dec 2019 09:58:33 +0000 Subject: [PATCH 058/353] Added support for setting thread affinity using a description, closes https://github.com/OpenHFT/Java-Thread-Affinity/issues/54 --- affinity/src/main/java/net/openhft/affinity/AffinityLock.java | 2 +- .../openhft/affinity/lockchecker/FileLockBasedLockChecker.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java index 886832ebb..d559743ed 100644 --- a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java +++ b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java @@ -312,7 +312,7 @@ public void bind(boolean wholeCore) { } else if (cpuId >= 0) { bound = true; assignedThread = Thread.currentThread(); - LOGGER.info("Assigning cpu {} to {}", cpuId, assignedThread); + LOGGER.info("Assigning cpu {} to {} on thread id {}", cpuId, assignedThread, Affinity.getThreadId()); } if (cpuId >= 0) { BitSet affinity = new BitSet(); diff --git a/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java b/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java index 30b924a3a..b142b6f72 100644 --- a/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java +++ b/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java @@ -137,7 +137,7 @@ public String getMetaInfo(int id) throws IOException { FileChannel fc = lr.channel; ByteBuffer buffer = ByteBuffer.allocate(64); int len = fc.read(buffer, 0); - String content = new String(buffer.array(), 0, len); + String content = len < 1 ? "" : new String(buffer.array(), 0, len); if (content.isEmpty()) { LOGGER.warn("Empty lock file {}", file.getAbsolutePath()); return null; From 05b3713bc2b056111d8fca26257bcf1f6e1970f1 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Mon, 9 Dec 2019 15:55:55 +0000 Subject: [PATCH 059/353] [maven-release-plugin] prepare release affinity-3.2.1 --- affinity/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index 505a22dfc..71e57f315 100755 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -25,7 +25,7 @@ 4.0.0 affinity - 3.2.1-SNAPSHOT + 3.2.1 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -222,7 +222,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - master + affinity-3.2.1 From b1169ef412943e2a466955a84fc67cb08913d6ad Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Mon, 9 Dec 2019 15:56:02 +0000 Subject: [PATCH 060/353] [maven-release-plugin] prepare for next development iteration --- affinity/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index 71e57f315..4c22ee801 100755 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -25,7 +25,7 @@ 4.0.0 affinity - 3.2.1 + 3.2.2-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity @@ -222,7 +222,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - affinity-3.2.1 + master From 5d7866365f1b53c9638f4282c5b2b8562548431e Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Mon, 9 Dec 2019 16:43:06 +0000 Subject: [PATCH 061/353] Added support for setting thread affinity using a description, closes https://github.com/OpenHFT/Java-Thread-Affinity/issues/54 --- affinity-test/pom.xml | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 7b65063e4..932584780 100755 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ 4.0.0 affinity-test - 3.2.0-SNAPSHOT + 3.2.2-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test diff --git a/pom.xml b/pom.xml index 3fcff944b..cafd5e741 100755 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ 4.0.0 Java-Thread-Affinity - 3.2.0-SNAPSHOT + 3.2.2-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent From 496f62e77262a9dee8c00994f7e37347c9900b3e Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Mon, 9 Dec 2019 17:02:21 +0000 Subject: [PATCH 062/353] [maven-release-plugin] prepare release affinity-3.2.2 --- affinity/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index 4c22ee801..4eb842c05 100755 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -25,7 +25,7 @@ 4.0.0 affinity - 3.2.2-SNAPSHOT + 3.2.2 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -222,7 +222,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - master + affinity-3.2.2 From 49a5b99cc4311ef145a127363941e24630bbe4dc Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Mon, 9 Dec 2019 17:02:28 +0000 Subject: [PATCH 063/353] [maven-release-plugin] prepare for next development iteration --- affinity/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index 4eb842c05..4cb0757d0 100755 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -25,7 +25,7 @@ 4.0.0 affinity - 3.2.2 + 3.2.3-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity @@ -222,7 +222,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - affinity-3.2.2 + master From 96d7475db467e446a869c1f4d282c56fe11b28c4 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Mon, 16 Dec 2019 16:53:21 +0000 Subject: [PATCH 064/353] Handle no affinity more gracefully. --- .../src/main/java/net/openhft/affinity/LockInventory.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/affinity/src/main/java/net/openhft/affinity/LockInventory.java b/affinity/src/main/java/net/openhft/affinity/LockInventory.java index 52aea2f63..fde57cf46 100644 --- a/affinity/src/main/java/net/openhft/affinity/LockInventory.java +++ b/affinity/src/main/java/net/openhft/affinity/LockInventory.java @@ -17,6 +17,7 @@ package net.openhft.affinity; +import net.openhft.affinity.impl.NullAffinity; import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -24,6 +25,8 @@ import java.util.NavigableMap; import java.util.TreeMap; +import static net.openhft.affinity.Affinity.getAffinityImpl; + class LockInventory { private static final Logger LOGGER = LoggerFactory.getLogger(LockInventory.class); @@ -97,6 +100,9 @@ public final synchronized void set(CpuLayout cpuLayout) { } public final synchronized AffinityLock acquireLock(boolean bind, int cpuId, AffinityStrategy... strategies) { + if (getAffinityImpl() instanceof NullAffinity) + return noLock(); + final boolean specificCpuRequested = !isAnyCpu(cpuId); if (specificCpuRequested && cpuId != 0) { final AffinityLock required = logicalCoreLocks[cpuId]; From becf18e478837749e516ad7b96f4493a76dc13e4 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Mon, 16 Dec 2019 19:30:25 +0000 Subject: [PATCH 065/353] Updating to bom version 2.17.515 From b54be486b298831dbc16d845dc8da78458fee786 Mon Sep 17 00:00:00 2001 From: vemv Date: Wed, 18 Dec 2019 03:03:19 +0100 Subject: [PATCH 066/353] README: remove dead link --- README.adoc | 3 --- 1 file changed, 3 deletions(-) diff --git a/README.adoc b/README.adoc index 57a8c48e5..8880e14af 100644 --- a/README.adoc +++ b/README.adoc @@ -16,9 +16,6 @@ OpenHFT Java Thread Affinity library See https://github.com/OpenHFT/Java-Thread-Affinity/tree/master/affinity/src/test/java[affinity/src/test/java] for working examples of how to use this library. -=== Wold Wide Usage -http://jrvis.com/red-dwarf/?user=openhft&repo=Java-Thread-Affinity[Thread Affinity usage Heatmap] - === Changes * V3.2.0 - Add support for text configuration From 826cf72be2f758611b058fec12d9a5d01199efb0 Mon Sep 17 00:00:00 2001 From: Jerry Shea Date: Sun, 2 Feb 2020 13:29:49 +1100 Subject: [PATCH 067/353] make all versions consistent --- affinity-test/pom.xml | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 932584780..b9de84806 100755 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ 4.0.0 affinity-test - 3.2.2-SNAPSHOT + 3.2.3-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test diff --git a/pom.xml b/pom.xml index cafd5e741..8585b46b3 100755 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ 4.0.0 Java-Thread-Affinity - 3.2.2-SNAPSHOT + 3.2.3-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent From 83fa65cb2bc67fa892e67dbe03c00c062042bcad Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Wed, 4 Mar 2020 09:32:34 +0000 Subject: [PATCH 068/353] Move to .19 releases --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index b9de84806..94c54b047 100755 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -42,7 +42,7 @@ net.openhft third-party-bom pom - 3.6.15 + 3.19.1 import diff --git a/affinity/pom.xml b/affinity/pom.xml index 4cb0757d0..8c4c9cbfc 100755 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -42,7 +42,7 @@ net.openhft third-party-bom pom - 3.6.15 + 3.19.1 import From b9eb3881442d48101a299c075fac6ac795985a96 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Wed, 4 Mar 2020 10:32:54 +0000 Subject: [PATCH 069/353] Move to .19 releases --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index 8c4c9cbfc..1cc1baa88 100755 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -62,7 +62,7 @@ jna-platform - com.intellij + org.jetbrains annotations From 01b1d63e33f21f688ab22382b7a2c6fb3793257e Mon Sep 17 00:00:00 2001 From: Jerry Shea Date: Fri, 17 Apr 2020 13:45:51 +1000 Subject: [PATCH 070/353] Continue even if /proc/cpuinfo is "unusual" (as sometimes seen on LXC or virtual environments) #59 --- affinity/src/main/java/net/openhft/affinity/AffinityLock.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java index d559743ed..1e8f998f1 100644 --- a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java +++ b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java @@ -26,7 +26,6 @@ import java.io.Closeable; import java.io.File; -import java.io.IOException; import java.util.BitSet; /** @@ -56,7 +55,7 @@ public class AffinityLock implements Closeable { cpuLayout = VanillaCpuLayout.fromCpuInfo(); processors = cpuLayout.cpus(); } - } catch (IOException e) { + } catch (Throwable e) { LOGGER.warn("Unable to load /proc/cpuinfo", e); } PROCESSORS = processors; From 6875a82398d9516d0de2eb79a7f5620032bfe266 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Fri, 17 Apr 2020 05:50:09 +0200 Subject: [PATCH 071/353] Updating to bom version 2.19.100 From cc016355c796d000df4be206f17992af9969d85e Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Fri, 17 Apr 2020 05:50:28 +0200 Subject: [PATCH 072/353] [maven-release-plugin] prepare release Java-Thread-Affinity-3.2.3 --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 94c54b047..a34b48083 100755 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ 4.0.0 affinity-test - 3.2.3-SNAPSHOT + 3.2.3 bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:https://github.com/OpenHFT/Java-Thread-Affinity.git - HEAD + Java-Thread-Affinity-3.2.3 diff --git a/affinity/pom.xml b/affinity/pom.xml index 1cc1baa88..34c3f2c93 100755 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -25,7 +25,7 @@ 4.0.0 affinity - 3.2.3-SNAPSHOT + 3.2.3 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -222,7 +222,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - master + Java-Thread-Affinity-3.2.3 diff --git a/pom.xml b/pom.xml index 8585b46b3..d5abfd7b7 100755 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ 4.0.0 Java-Thread-Affinity - 3.2.3-SNAPSHOT + 3.2.3 pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - master + Java-Thread-Affinity-3.2.3 From 12acead5bc6161d111c03810368b83f01848feb8 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Fri, 17 Apr 2020 05:50:36 +0200 Subject: [PATCH 073/353] [maven-release-plugin] prepare for next development iteration --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index a34b48083..0e1fd7783 100755 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ 4.0.0 affinity-test - 3.2.3 + 3.2.4-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:https://github.com/OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.2.3 + HEAD diff --git a/affinity/pom.xml b/affinity/pom.xml index 34c3f2c93..a89edcac1 100755 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -25,7 +25,7 @@ 4.0.0 affinity - 3.2.3 + 3.2.4-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity @@ -222,7 +222,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.2.3 + master diff --git a/pom.xml b/pom.xml index d5abfd7b7..aa2e2bb1e 100755 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ 4.0.0 Java-Thread-Affinity - 3.2.3 + 3.2.4-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.2.3 + master From 19832722c9fdca21b6f72ba5410995690a34ff6e Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Fri, 17 Apr 2020 05:51:46 +0200 Subject: [PATCH 074/353] Reverting back to bom version 2.19-SNAPSHOT From f1b75ab946cb4bb9f7b6b5d7d90cc48058b8ab10 Mon Sep 17 00:00:00 2001 From: Dmitry Pisklov Date: Fri, 24 Apr 2020 18:09:18 +0100 Subject: [PATCH 075/353] Update root pom --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 0e1fd7783..8ea90dafe 100755 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -20,7 +20,7 @@ net.openhft java-parent-pom - 1.1.22 + 1.1.23 @@ -42,7 +42,7 @@ net.openhft third-party-bom pom - 3.19.1 + 3.19.2 import diff --git a/affinity/pom.xml b/affinity/pom.xml index a89edcac1..102004fc6 100755 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -20,7 +20,7 @@ net.openhft java-parent-pom - 1.1.22 + 1.1.23 4.0.0 @@ -42,7 +42,7 @@ net.openhft third-party-bom pom - 3.19.1 + 3.19.2 import From 3daeee6a8c4aaef2de1c3b8abf0920d5c2363859 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Thu, 14 May 2020 13:25:41 +0100 Subject: [PATCH 076/353] Add results for a Windows 10 machine --- .../openhft/affinity/MicroJitterSampler.java | 45 +++++++++++-------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java b/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java index 353479b5e..699da9c1f 100755 --- a/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java +++ b/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java @@ -20,25 +20,32 @@ import java.io.PrintStream; /* e.g. -After 2430 seconds, the average per hour was -2us 78400 -3us 122703 -4us 345238 -6us 216098 -8us 78694 -10us 3977528 -14us 114495 -20us 4931 -30us 203 -40us 35 -60us 18 -80us 11 -100us 9 -140us 132 -200us 85 -300us 473 -400us 5 -1ms 24 +Windows 10 i7-4770 laptop +After 1845 seconds, the average per hour was +2us 2435969 +3us 548812 +4us 508041 +6us 60320 +8us 25374 +10us 1832324 +14us 2089216 +20us 391901 +30us 16063 +40us 6440 +60us 2617 +80us 1487 +100us 1241 +140us 826 +200us 2108 +300us 601 +400us 159 +600us 129 +800us 215 +1ms 155 +2ms 229 +5ms 24 +10ms 38 +20ms 32 */ /** From 7635e4aa232483d3f503f07292ab7642ef16ac99 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Thu, 14 May 2020 13:52:55 +0100 Subject: [PATCH 077/353] Add a sample Centos 7 MicroJitterSampler result. --- affinity/pom.xml | 11 +++++++++++ .../openhft/affinity/MicroJitterSampler.java | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/affinity/pom.xml b/affinity/pom.xml index 102004fc6..cd43e3f32 100755 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -84,6 +84,17 @@ + + + slf4j-simple + + + org.slf4j + slf4j-simple + + + + diff --git a/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java b/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java index 699da9c1f..8bdc7ad8f 100755 --- a/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java +++ b/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java @@ -46,6 +46,24 @@ 5ms 24 10ms 38 20ms 32 + +On an Centos 7 machine with an isolated CPU. +After 2145 seconds, the average per hour was +2us 781271 +3us 1212123 +4us 13504 +6us 489 +8us 2 +10us 3032577 +14us 17475 +20us 628 +30us 645 +40us 1301 +60us 1217 +80us 1306 +100us 1526 +140us 22 + */ /** From c27d35e21035ab58a10cec09f62685b654c81b89 Mon Sep 17 00:00:00 2001 From: Aayush Atharva Date: Sat, 23 May 2020 19:47:13 +0530 Subject: [PATCH 078/353] Update README.adoc Fix minor typo error. --- README.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.adoc b/README.adoc index 8880e14af..bb8c83404 100644 --- a/README.adoc +++ b/README.adoc @@ -222,7 +222,7 @@ try (AffinityLock lock = AffinityLock.acquireLockLastMinus(n)) { I have the cpuId in a configuration file, how can I set it using a string? -=== Answer: use one fo the following. +=== Answer: use one of the following. [source,java] ---- From b30167a9e64063006fc426186ddb7d433fa84d84 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Mon, 13 Jul 2020 15:05:21 +0100 Subject: [PATCH 079/353] Improve tuning and shutdown of tests in services, https://github.com/ChronicleEnterprise/Chronicle-Services/issues/172 --- affinity/src/main/java/net/openhft/affinity/AffinityLock.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java index 1e8f998f1..94cc2c716 100644 --- a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java +++ b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java @@ -353,6 +353,9 @@ public AffinityLock acquireLock(AffinityStrategy... strategies) { * Release the current AffinityLock which can be discarded. */ public void release() { + if (cpuId == ANY_CPU || !reservable) + return; + // expensive if not actually used. lockInventory.release(); } From 6dcc1859efd2252929ac6af8d51cb531e7f307de Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Mon, 13 Jul 2020 15:39:53 +0100 Subject: [PATCH 080/353] TODO FIX OSGI test harness fails. --- .../test/java/net/openhft/affinity/osgi/OSGiBundleTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/affinity-test/src/test/java/net/openhft/affinity/osgi/OSGiBundleTest.java b/affinity-test/src/test/java/net/openhft/affinity/osgi/OSGiBundleTest.java index b7eec56c8..a032a0496 100644 --- a/affinity-test/src/test/java/net/openhft/affinity/osgi/OSGiBundleTest.java +++ b/affinity-test/src/test/java/net/openhft/affinity/osgi/OSGiBundleTest.java @@ -17,6 +17,7 @@ package net.openhft.affinity.osgi; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.ops4j.pax.exam.Configuration; @@ -30,7 +31,7 @@ import static org.junit.Assert.*; import static org.ops4j.pax.exam.CoreOptions.*; -//@Ignore +@Ignore("TODO FIX") @RunWith(PaxExam.class) public class OSGiBundleTest extends net.openhft.affinity.osgi.OSGiTestBase { @Inject From e538d4b178b5cd5d74983526b31ab594d3b341b6 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Tue, 14 Jul 2020 15:17:25 +0100 Subject: [PATCH 081/353] Only release affinity if it was narrowed in the first place. --- affinity/src/main/java/net/openhft/affinity/AffinityLock.java | 2 +- .../src/test/java/net/openhft/affinity/AffinityLockTest.java | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java index 94cc2c716..452e884a4 100644 --- a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java +++ b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java @@ -353,7 +353,7 @@ public AffinityLock acquireLock(AffinityStrategy... strategies) { * Release the current AffinityLock which can be discarded. */ public void release() { - if (cpuId == ANY_CPU || !reservable) + if (cpuId == ANY_CPU) return; // expensive if not actually used. lockInventory.release(); diff --git a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java index 25d1d6736..e9d79a30a 100644 --- a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java +++ b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java @@ -133,6 +133,7 @@ public void assignReleaseThread() throws IOException { System.out.println("Cannot run affinity test as this system doesn't have a /proc/cpuinfo file"); return; } + AffinityLock.cpuLayout(VanillaCpuLayout.fromCpuInfo()); assertEquals(AffinityLock.BASE_AFFINITY, Affinity.getAffinity()); @@ -229,6 +230,7 @@ public void shouldReturnLockForSpecifiedCpu() { try (final AffinityLock affinityLock = AffinityLock.acquireLock(3)) { assertThat(affinityLock.cpuId(), is(3)); } + assertEquals(AffinityLock.BASE_AFFINITY, Affinity.getAffinity()); } @Test From 63a64d4e5f9bf12280f4eff2300043f8820d3a6f Mon Sep 17 00:00:00 2001 From: Mark Santos Date: Sun, 19 Jul 2020 14:44:23 +0800 Subject: [PATCH 082/353] Fix for FileLockBasedLockChecker attempting to release locks held by other processes --- affinity/src/main/java/net/openhft/affinity/AffinityLock.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java index 452e884a4..0b2d172b0 100644 --- a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java +++ b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java @@ -322,10 +322,12 @@ public void bind(boolean wholeCore) { final boolean canReserve(boolean specified) { + if (!specified && !reservable) + return false; + if (!LockCheck.isCpuFree(cpuId)) return false; - if (!specified && !reservable) return false; if (assignedThread != null) { if (assignedThread.isAlive()) { return false; From d22c564ed0d83524fa52a9acbe07834fa5f2d66b Mon Sep 17 00:00:00 2001 From: Rob Austin <6506056+RobAustin@users.noreply.github.com> Date: Thu, 6 Aug 2020 16:50:54 +0100 Subject: [PATCH 083/353] Update pom.xml --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index aa2e2bb1e..5d07b0fa0 100755 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ 4.0.0 Java-Thread-Affinity - 3.2.4-SNAPSHOT + 3.20.0-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent From 469f388feccfb8f9a203243ec68bf784b44e7b98 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Sat, 8 Aug 2020 10:28:37 +0100 Subject: [PATCH 084/353] java-parent-pom version 1.1.23 --- affinity-test/pom.xml | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 8ea90dafe..e9be7f8c8 100755 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom 1.1.23 - + 4.0.0 diff --git a/pom.xml b/pom.xml index 5d07b0fa0..5f7de5ab7 100755 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ net.openhft root-parent-pom 1.2.1 - + 4.0.0 From 7cb6427b3f78fb6171054855ac770c2631d6284f Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Wed, 16 Sep 2020 07:19:21 +0100 Subject: [PATCH 085/353] Allow an AffinityLock to be release without resetting the current thread. #65 --- .../net/openhft/affinity/AffinityLock.java | 21 ++++++++++++++++++- .../net/openhft/affinity/LockInventory.java | 5 +++-- .../openhft/affinity/AffinityLockTest.java | 14 +++++++++++++ 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java index 0b2d172b0..64dc5a2e7 100644 --- a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java +++ b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java @@ -85,6 +85,7 @@ public class AffinityLock implements Closeable { @Nullable Thread assignedThread; Throwable boundHere; + private boolean resetAffinity = true; AffinityLock(int cpuId, boolean base, boolean reservable, LockInventory lockInventory) { this.lockInventory = lockInventory; @@ -274,6 +275,22 @@ private static boolean areAssertionsEnabled() { return debug; } + /** + * @return Whether to reset the affinity, false indicates the thread is about to die anyway. + */ + public boolean resetAffinity() { + return resetAffinity; + } + + /** + * @param resetAffinity Whether to reset the affinity, false indicates the thread is about to die anyway. + * @return this + */ + public AffinityLock resetAffinity(boolean resetAffinity) { + this.resetAffinity = resetAffinity; + return this; + } + /** * Assigning the current thread has a side effect of preventing the lock being used again until * it is released. @@ -358,7 +375,9 @@ public void release() { if (cpuId == ANY_CPU) return; // expensive if not actually used. - lockInventory.release(); + boolean resetAffinity = this.resetAffinity; + this.resetAffinity = true; + lockInventory.release(resetAffinity); } @Override diff --git a/affinity/src/main/java/net/openhft/affinity/LockInventory.java b/affinity/src/main/java/net/openhft/affinity/LockInventory.java index fde57cf46..a3fba7751 100644 --- a/affinity/src/main/java/net/openhft/affinity/LockInventory.java +++ b/affinity/src/main/java/net/openhft/affinity/LockInventory.java @@ -179,7 +179,7 @@ public final synchronized void bindWholeCore(int logicalCoreID) { } } - public final synchronized void release() { + public final synchronized void release(boolean resetAffinity) { Thread t = Thread.currentThread(); for (AffinityLock al : logicalCoreLocks) { Thread at = al.assignedThread; @@ -189,7 +189,8 @@ public final synchronized void release() { releaseAffinityLock(t, al, "Releasing cpu {} from {} as it is not alive."); } } - Affinity.resetToBaseAffinity(); + if (resetAffinity) + Affinity.resetToBaseAffinity(); } public final synchronized String dumpLocks() { diff --git a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java index e9d79a30a..45b9cc19c 100644 --- a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java +++ b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java @@ -149,6 +149,20 @@ public void assignReleaseThread() throws IOException { assertEquals(AffinityLock.BASE_AFFINITY, Affinity.getAffinity()); } + @Test + public void resetAffinity() { + assertTrue(Affinity.getAffinity().cardinality() > 1); + try (AffinityLock lock = AffinityLock.acquireLock()) { + assertEquals(1, Affinity.getAffinity().cardinality()); + assertTrue(lock.resetAffinity()); + lock.resetAffinity(false); + } + assertEquals(1, Affinity.getAffinity().cardinality()); + try (AffinityLock lock = AffinityLock.acquireLock()) { + } + assertTrue(Affinity.getAffinity().cardinality() > 1); + } + @Test public void testIssue21() throws IOException { if (!new File("/proc/cpuinfo").exists()) { From b1deff899a9b874d12091fea7df2bc9a7762fb2c Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Wed, 16 Sep 2020 08:20:57 +0200 Subject: [PATCH 086/353] [maven-release-plugin] prepare release affinity-3.2.4 --- affinity/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index cd43e3f32..cb4850792 100755 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -25,7 +25,7 @@ 4.0.0 affinity - 3.2.4-SNAPSHOT + 3.2.4 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -233,7 +233,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - master + affinity-3.2.4 From a5e8600788159adc7b3e96bc782376395b15e2cf Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Wed, 16 Sep 2020 08:21:04 +0200 Subject: [PATCH 087/353] [maven-release-plugin] prepare for next development iteration --- affinity/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index cb4850792..3ca2257d5 100755 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -25,7 +25,7 @@ 4.0.0 affinity - 3.2.4 + 3.2.5-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity @@ -233,7 +233,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - affinity-3.2.4 + master From ddb499c616a8d0853a9679c851b31bc02df236d9 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Wed, 16 Sep 2020 15:35:11 +0100 Subject: [PATCH 088/353] Allow an AffinityLock to be release without resetting the current thread. #65 --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index e9be7f8c8..88035798b 100755 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ 4.0.0 affinity-test - 3.2.4-SNAPSHOT + 3.20.0-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test diff --git a/affinity/pom.xml b/affinity/pom.xml index 3ca2257d5..5bb3f4229 100755 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -25,7 +25,7 @@ 4.0.0 affinity - 3.2.5-SNAPSHOT + 3.20.0-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity From 2de0ffb0711380ff92027e933f99042f4628d260 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Wed, 16 Sep 2020 16:37:22 +0200 Subject: [PATCH 089/353] [maven-release-plugin] prepare release affinity-3.20.0 --- affinity/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index 5bb3f4229..cc2b9006f 100755 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -25,7 +25,7 @@ 4.0.0 affinity - 3.20.0-SNAPSHOT + 3.20.0 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -233,7 +233,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - master + affinity-3.20.0 From 89c8947e3481b513e28d1b3cd37fd47b6fd47383 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Wed, 16 Sep 2020 16:37:29 +0200 Subject: [PATCH 090/353] [maven-release-plugin] prepare for next development iteration --- affinity/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index cc2b9006f..529d8ef1c 100755 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -25,7 +25,7 @@ 4.0.0 affinity - 3.20.0 + 3.20.1-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity @@ -233,7 +233,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - affinity-3.20.0 + master From 52f29a0a04d520ca1fb1a28b7ba806bf16b0868b Mon Sep 17 00:00:00 2001 From: shinanca Date: Fri, 18 Sep 2020 01:45:00 +0300 Subject: [PATCH 091/353] Add support for ppc64le --- affinity/src/main/c/Makefile | 2 +- affinity/src/main/c/net_openhft_ticker_impl_JNIClock.cpp | 6 ++++++ .../java/net/openhft/affinity/impl/LinuxJNAAffinity.java | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/affinity/src/main/c/Makefile b/affinity/src/main/c/Makefile index 467161b89..58a06e53a 100755 --- a/affinity/src/main/c/Makefile +++ b/affinity/src/main/c/Makefile @@ -21,7 +21,7 @@ JAVA_BUILD_DIR := $(TARGET_DIR) JAVA_HOME ?= /usr/java/default JAVA_LIB := $(JAVA_HOME)/jre/lib -JVM_SHARED_LIBS := -L$(JAVA_LIB)/amd64/server -L$(JAVA_LIB)/i386/server -L$(JAVA_LIB)/amd64/jrockit/ -L$(JAVA_LIB)/i386/jrockit/ +JVM_SHARED_LIBS := -L$(JAVA_LIB)/amd64/server -L$(JAVA_LIB)/i386/server -L$(JAVA_LIB)/amd64/jrockit/ -L$(JAVA_LIB)/i386/jrockit/ -L$(JAVA_LIB)/ppc64le/server -L$(JAVA_LIB)/ppc64le/jrockit/ CXX=g++ INCLUDES := -I $(JAVA_HOME)/include -I $(JAVA_HOME)/include/linux -I $(WORKING_DIR) diff --git a/affinity/src/main/c/net_openhft_ticker_impl_JNIClock.cpp b/affinity/src/main/c/net_openhft_ticker_impl_JNIClock.cpp index a69ce129e..e269308a5 100644 --- a/affinity/src/main/c/net_openhft_ticker_impl_JNIClock.cpp +++ b/affinity/src/main/c/net_openhft_ticker_impl_JNIClock.cpp @@ -47,6 +47,12 @@ static __inline__ unsigned long long rdtsc (void) { clock_gettime (CLOCK_SGI_CYCLE, &tp); return (unsigned long long)(tp.tv_sec * (unsigned long long)1000000000) + (unsigned long long)tp.tv_nsec; } +#elif defined(__PPC64__) +unsigned long long rdtsc(){ + unsigned long long rval; + __asm__ __volatile__("mfspr %%r3, 268": "=r" (rval)); + return rval; +} #endif /* diff --git a/affinity/src/main/java/net/openhft/affinity/impl/LinuxJNAAffinity.java b/affinity/src/main/java/net/openhft/affinity/impl/LinuxJNAAffinity.java index 04bc5901a..9df082c6d 100755 --- a/affinity/src/main/java/net/openhft/affinity/impl/LinuxJNAAffinity.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/LinuxJNAAffinity.java @@ -30,7 +30,7 @@ public enum LinuxJNAAffinity implements IAffinity { public static final boolean LOADED; private static final Logger LOGGER = LoggerFactory.getLogger(LinuxJNAAffinity.class); private static final int PROCESS_ID; - private static final int SYS_gettid = Platform.is64Bit() ? 186 : 224; + private static final int SYS_gettid = Platform.isPPC() ? 207 : Platform.is64Bit() ? 186 : 224; private static final Object[] NO_ARGS = {}; private static final String OS = System.getProperty("os.name").toLowerCase(); From 08b07cec65741af889b1a0febe59d41d4a6b3913 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Fri, 18 Sep 2020 16:38:21 +0100 Subject: [PATCH 092/353] Warning in poms --- affinity/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/affinity/pom.xml b/affinity/pom.xml index 529d8ef1c..d8fc4cb1d 100755 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -21,6 +21,7 @@ net.openhft java-parent-pom 1.1.23 + 4.0.0 From 75f0a79628a95a13fd3a0f932e52951329745578 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Mon, 26 Oct 2020 10:57:02 +0000 Subject: [PATCH 093/353] Single repo to build all the others with the latest SNAPSHOT, tidy copyright, https://github.com/ChronicleSoftware/Build-All/issues/1 --- .../main/java/net/openhft/affinity/osgi/OSGiPlaceholder.java | 2 +- .../src/test/java/net/openhft/affinity/osgi/OSGiBundleTest.java | 2 +- .../src/test/java/net/openhft/affinity/osgi/OSGiTestBase.java | 2 +- affinity/src/main/java/java/lang/ThreadLifecycleListener.java | 2 +- affinity/src/main/java/java/lang/ThreadTrackingGroup.java | 2 +- affinity/src/main/java/net/openhft/affinity/Affinity.java | 2 +- affinity/src/main/java/net/openhft/affinity/AffinityLock.java | 2 +- .../src/main/java/net/openhft/affinity/AffinityStrategies.java | 2 +- .../src/main/java/net/openhft/affinity/AffinityStrategy.java | 2 +- .../src/main/java/net/openhft/affinity/AffinitySupport.java | 2 +- .../main/java/net/openhft/affinity/AffinityThreadFactory.java | 2 +- affinity/src/main/java/net/openhft/affinity/BootClassPath.java | 2 +- affinity/src/main/java/net/openhft/affinity/CpuLayout.java | 2 +- affinity/src/main/java/net/openhft/affinity/IAffinity.java | 2 +- affinity/src/main/java/net/openhft/affinity/LockCheck.java | 2 +- affinity/src/main/java/net/openhft/affinity/LockInventory.java | 2 +- .../src/main/java/net/openhft/affinity/MicroJitterSampler.java | 2 +- .../main/java/net/openhft/affinity/NonForkingAffinityLock.java | 2 +- .../src/main/java/net/openhft/affinity/impl/LinuxHelper.java | 2 +- .../main/java/net/openhft/affinity/impl/LinuxJNAAffinity.java | 2 +- .../src/main/java/net/openhft/affinity/impl/NoCpuLayout.java | 2 +- .../src/main/java/net/openhft/affinity/impl/NullAffinity.java | 2 +- .../src/main/java/net/openhft/affinity/impl/OSXJNAAffinity.java | 2 +- .../main/java/net/openhft/affinity/impl/PosixJNAAffinity.java | 2 +- .../main/java/net/openhft/affinity/impl/SolarisJNAAffinity.java | 2 +- affinity/src/main/java/net/openhft/affinity/impl/Utilities.java | 2 +- .../main/java/net/openhft/affinity/impl/VanillaCpuLayout.java | 2 +- .../src/main/java/net/openhft/affinity/impl/VersionHelper.java | 2 +- .../main/java/net/openhft/affinity/impl/WindowsJNAAffinity.java | 2 +- affinity/src/main/java/net/openhft/ticker/ITicker.java | 2 +- affinity/src/main/java/net/openhft/ticker/Ticker.java | 2 +- affinity/src/main/java/net/openhft/ticker/impl/JNIClock.java | 2 +- affinity/src/main/java/net/openhft/ticker/impl/SystemClock.java | 2 +- .../chronicle/enterprise/internals/impl/NativeAffinity.java | 2 +- .../test/java/net/openhft/affinity/AffinityLockBindMain.java | 2 +- .../src/test/java/net/openhft/affinity/AffinityLockMain.java | 2 +- .../src/test/java/net/openhft/affinity/AffinityLockTest.java | 2 +- .../src/test/java/net/openhft/affinity/AffinitySupportMain.java | 2 +- .../java/net/openhft/affinity/AffinityThreadFactoryMain.java | 2 +- .../test/java/net/openhft/affinity/FileLockLockCheckTest.java | 2 +- .../src/test/java/net/openhft/affinity/InterrupedThread.java | 2 +- affinity/src/test/java/net/openhft/affinity/LockCheckTest.java | 2 +- .../net/openhft/affinity/impl/AbstractAffinityImplTest.java | 2 +- .../java/net/openhft/affinity/impl/LinuxJNAAffinityTest.java | 2 +- .../java/net/openhft/affinity/impl/NativeAffinityImpTest.java | 2 +- .../java/net/openhft/affinity/impl/PosixJNAAffinityTest.java | 2 +- .../java/net/openhft/affinity/impl/VanillaCpuLayoutTest.java | 2 +- .../test/java/net/openhft/affinity/impl/VersionHelperTest.java | 2 +- .../src/test/java/net/openhft/ticker/impl/JNIClockTest.java | 2 +- affinity/src/test/java/org/junit/Assert.java | 2 +- .../chronicle/enterprise/internals/JnaAffinityTest.java | 2 +- .../chronicle/enterprise/internals/NativeAffinityTest.java | 2 +- 52 files changed, 52 insertions(+), 52 deletions(-) diff --git a/affinity-test/src/main/java/net/openhft/affinity/osgi/OSGiPlaceholder.java b/affinity-test/src/main/java/net/openhft/affinity/osgi/OSGiPlaceholder.java index 7ba5b283f..becba5df0 100644 --- a/affinity-test/src/main/java/net/openhft/affinity/osgi/OSGiPlaceholder.java +++ b/affinity-test/src/main/java/net/openhft/affinity/osgi/OSGiPlaceholder.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 higherfrequencytrading.com + * Copyright 2016-2020 chronicle.software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/affinity-test/src/test/java/net/openhft/affinity/osgi/OSGiBundleTest.java b/affinity-test/src/test/java/net/openhft/affinity/osgi/OSGiBundleTest.java index a032a0496..727ea8c28 100644 --- a/affinity-test/src/test/java/net/openhft/affinity/osgi/OSGiBundleTest.java +++ b/affinity-test/src/test/java/net/openhft/affinity/osgi/OSGiBundleTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 higherfrequencytrading.com + * Copyright 2016-2020 chronicle.software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/affinity-test/src/test/java/net/openhft/affinity/osgi/OSGiTestBase.java b/affinity-test/src/test/java/net/openhft/affinity/osgi/OSGiTestBase.java index 6e584355b..deb9d9d5f 100644 --- a/affinity-test/src/test/java/net/openhft/affinity/osgi/OSGiTestBase.java +++ b/affinity-test/src/test/java/net/openhft/affinity/osgi/OSGiTestBase.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 higherfrequencytrading.com + * Copyright 2016-2020 chronicle.software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/affinity/src/main/java/java/lang/ThreadLifecycleListener.java b/affinity/src/main/java/java/lang/ThreadLifecycleListener.java index fc1d3a6e7..f2e4c01e3 100644 --- a/affinity/src/main/java/java/lang/ThreadLifecycleListener.java +++ b/affinity/src/main/java/java/lang/ThreadLifecycleListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 higherfrequencytrading.com + * Copyright 2016-2020 chronicle.software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/affinity/src/main/java/java/lang/ThreadTrackingGroup.java b/affinity/src/main/java/java/lang/ThreadTrackingGroup.java index c8d1b8346..7a4d6bb35 100644 --- a/affinity/src/main/java/java/lang/ThreadTrackingGroup.java +++ b/affinity/src/main/java/java/lang/ThreadTrackingGroup.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 higherfrequencytrading.com + * Copyright 2016-2020 chronicle.software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/affinity/src/main/java/net/openhft/affinity/Affinity.java b/affinity/src/main/java/net/openhft/affinity/Affinity.java index 3253f817f..e9025f248 100644 --- a/affinity/src/main/java/net/openhft/affinity/Affinity.java +++ b/affinity/src/main/java/net/openhft/affinity/Affinity.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 higherfrequencytrading.com + * Copyright 2016-2020 chronicle.software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java index 64dc5a2e7..f2a8f10f7 100644 --- a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java +++ b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 higherfrequencytrading.com + * Copyright 2016-2020 chronicle.software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/affinity/src/main/java/net/openhft/affinity/AffinityStrategies.java b/affinity/src/main/java/net/openhft/affinity/AffinityStrategies.java index 2130f85ab..c9a6b8a5b 100644 --- a/affinity/src/main/java/net/openhft/affinity/AffinityStrategies.java +++ b/affinity/src/main/java/net/openhft/affinity/AffinityStrategies.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 higherfrequencytrading.com + * Copyright 2016-2020 chronicle.software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/affinity/src/main/java/net/openhft/affinity/AffinityStrategy.java b/affinity/src/main/java/net/openhft/affinity/AffinityStrategy.java index 27088f708..0d8dc27bd 100644 --- a/affinity/src/main/java/net/openhft/affinity/AffinityStrategy.java +++ b/affinity/src/main/java/net/openhft/affinity/AffinityStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 higherfrequencytrading.com + * Copyright 2016-2020 chronicle.software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/affinity/src/main/java/net/openhft/affinity/AffinitySupport.java b/affinity/src/main/java/net/openhft/affinity/AffinitySupport.java index 4ef081c13..ad80a8ef0 100644 --- a/affinity/src/main/java/net/openhft/affinity/AffinitySupport.java +++ b/affinity/src/main/java/net/openhft/affinity/AffinitySupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 higherfrequencytrading.com + * Copyright 2016-2020 chronicle.software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/affinity/src/main/java/net/openhft/affinity/AffinityThreadFactory.java b/affinity/src/main/java/net/openhft/affinity/AffinityThreadFactory.java index ba25ca0b9..a1b15f372 100644 --- a/affinity/src/main/java/net/openhft/affinity/AffinityThreadFactory.java +++ b/affinity/src/main/java/net/openhft/affinity/AffinityThreadFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 higherfrequencytrading.com + * Copyright 2016-2020 chronicle.software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/affinity/src/main/java/net/openhft/affinity/BootClassPath.java b/affinity/src/main/java/net/openhft/affinity/BootClassPath.java index e51ac738a..383e6576f 100644 --- a/affinity/src/main/java/net/openhft/affinity/BootClassPath.java +++ b/affinity/src/main/java/net/openhft/affinity/BootClassPath.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 higherfrequencytrading.com + * Copyright 2016-2020 chronicle.software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/affinity/src/main/java/net/openhft/affinity/CpuLayout.java b/affinity/src/main/java/net/openhft/affinity/CpuLayout.java index cfbb7a840..92981330e 100644 --- a/affinity/src/main/java/net/openhft/affinity/CpuLayout.java +++ b/affinity/src/main/java/net/openhft/affinity/CpuLayout.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 higherfrequencytrading.com + * Copyright 2016-2020 chronicle.software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/affinity/src/main/java/net/openhft/affinity/IAffinity.java b/affinity/src/main/java/net/openhft/affinity/IAffinity.java index e9aa985c5..f68598e08 100644 --- a/affinity/src/main/java/net/openhft/affinity/IAffinity.java +++ b/affinity/src/main/java/net/openhft/affinity/IAffinity.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 higherfrequencytrading.com + * Copyright 2016-2020 chronicle.software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/affinity/src/main/java/net/openhft/affinity/LockCheck.java b/affinity/src/main/java/net/openhft/affinity/LockCheck.java index 1ab24fb8b..2fe67ad8c 100644 --- a/affinity/src/main/java/net/openhft/affinity/LockCheck.java +++ b/affinity/src/main/java/net/openhft/affinity/LockCheck.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 higherfrequencytrading.com + * Copyright 2016-2020 chronicle.software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/affinity/src/main/java/net/openhft/affinity/LockInventory.java b/affinity/src/main/java/net/openhft/affinity/LockInventory.java index a3fba7751..1af307278 100644 --- a/affinity/src/main/java/net/openhft/affinity/LockInventory.java +++ b/affinity/src/main/java/net/openhft/affinity/LockInventory.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 higherfrequencytrading.com + * Copyright 2016-2020 chronicle.software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java b/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java index 8bdc7ad8f..d122999d2 100755 --- a/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java +++ b/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java @@ -1,7 +1,7 @@ /* * Copyright 2014 Higher Frequency Trading * - * http://www.higherfrequencytrading.com + * http://chronicle.software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/affinity/src/main/java/net/openhft/affinity/NonForkingAffinityLock.java b/affinity/src/main/java/net/openhft/affinity/NonForkingAffinityLock.java index 095881a51..d6e3440f2 100644 --- a/affinity/src/main/java/net/openhft/affinity/NonForkingAffinityLock.java +++ b/affinity/src/main/java/net/openhft/affinity/NonForkingAffinityLock.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 higherfrequencytrading.com + * Copyright 2016-2020 chronicle.software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java b/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java index 84de3884b..deee9a908 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 higherfrequencytrading.com + * Copyright 2016-2020 chronicle.software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/affinity/src/main/java/net/openhft/affinity/impl/LinuxJNAAffinity.java b/affinity/src/main/java/net/openhft/affinity/impl/LinuxJNAAffinity.java index 9df082c6d..1a4463319 100755 --- a/affinity/src/main/java/net/openhft/affinity/impl/LinuxJNAAffinity.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/LinuxJNAAffinity.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 higherfrequencytrading.com + * Copyright 2016-2020 chronicle.software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/affinity/src/main/java/net/openhft/affinity/impl/NoCpuLayout.java b/affinity/src/main/java/net/openhft/affinity/impl/NoCpuLayout.java index 139493b73..aabbc9d0e 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/NoCpuLayout.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/NoCpuLayout.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 higherfrequencytrading.com + * Copyright 2016-2020 chronicle.software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/affinity/src/main/java/net/openhft/affinity/impl/NullAffinity.java b/affinity/src/main/java/net/openhft/affinity/impl/NullAffinity.java index d9155cc0e..b33504b3c 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/NullAffinity.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/NullAffinity.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 higherfrequencytrading.com + * Copyright 2016-2020 chronicle.software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/affinity/src/main/java/net/openhft/affinity/impl/OSXJNAAffinity.java b/affinity/src/main/java/net/openhft/affinity/impl/OSXJNAAffinity.java index 6f35d037f..c9b7fa4b8 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/OSXJNAAffinity.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/OSXJNAAffinity.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 higherfrequencytrading.com + * Copyright 2016-2020 chronicle.software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/affinity/src/main/java/net/openhft/affinity/impl/PosixJNAAffinity.java b/affinity/src/main/java/net/openhft/affinity/impl/PosixJNAAffinity.java index 16dbaf94d..f3efd1947 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/PosixJNAAffinity.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/PosixJNAAffinity.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 higherfrequencytrading.com + * Copyright 2016-2020 chronicle.software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/affinity/src/main/java/net/openhft/affinity/impl/SolarisJNAAffinity.java b/affinity/src/main/java/net/openhft/affinity/impl/SolarisJNAAffinity.java index fbe1c2c6e..2718187c5 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/SolarisJNAAffinity.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/SolarisJNAAffinity.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 higherfrequencytrading.com + * Copyright 2016-2020 chronicle.software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/affinity/src/main/java/net/openhft/affinity/impl/Utilities.java b/affinity/src/main/java/net/openhft/affinity/impl/Utilities.java index f5894990f..b81f9d919 100755 --- a/affinity/src/main/java/net/openhft/affinity/impl/Utilities.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/Utilities.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 higherfrequencytrading.com + * Copyright 2016-2020 chronicle.software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/affinity/src/main/java/net/openhft/affinity/impl/VanillaCpuLayout.java b/affinity/src/main/java/net/openhft/affinity/impl/VanillaCpuLayout.java index 546fd968c..d30c8bba3 100755 --- a/affinity/src/main/java/net/openhft/affinity/impl/VanillaCpuLayout.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/VanillaCpuLayout.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 higherfrequencytrading.com + * Copyright 2016-2020 chronicle.software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/affinity/src/main/java/net/openhft/affinity/impl/VersionHelper.java b/affinity/src/main/java/net/openhft/affinity/impl/VersionHelper.java index b72b1e52f..b54d75081 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/VersionHelper.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/VersionHelper.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 higherfrequencytrading.com + * Copyright 2016-2020 chronicle.software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/affinity/src/main/java/net/openhft/affinity/impl/WindowsJNAAffinity.java b/affinity/src/main/java/net/openhft/affinity/impl/WindowsJNAAffinity.java index 69b81c669..1fdb8dc6a 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/WindowsJNAAffinity.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/WindowsJNAAffinity.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 higherfrequencytrading.com + * Copyright 2016-2020 chronicle.software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/affinity/src/main/java/net/openhft/ticker/ITicker.java b/affinity/src/main/java/net/openhft/ticker/ITicker.java index 5c514c099..70c3934df 100755 --- a/affinity/src/main/java/net/openhft/ticker/ITicker.java +++ b/affinity/src/main/java/net/openhft/ticker/ITicker.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 higherfrequencytrading.com + * Copyright 2016-2020 chronicle.software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/affinity/src/main/java/net/openhft/ticker/Ticker.java b/affinity/src/main/java/net/openhft/ticker/Ticker.java index 48fb77619..d8ac5a1e6 100644 --- a/affinity/src/main/java/net/openhft/ticker/Ticker.java +++ b/affinity/src/main/java/net/openhft/ticker/Ticker.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 higherfrequencytrading.com + * Copyright 2016-2020 chronicle.software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/affinity/src/main/java/net/openhft/ticker/impl/JNIClock.java b/affinity/src/main/java/net/openhft/ticker/impl/JNIClock.java index c7232ac8a..0115c19cd 100644 --- a/affinity/src/main/java/net/openhft/ticker/impl/JNIClock.java +++ b/affinity/src/main/java/net/openhft/ticker/impl/JNIClock.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 higherfrequencytrading.com + * Copyright 2016-2020 chronicle.software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/affinity/src/main/java/net/openhft/ticker/impl/SystemClock.java b/affinity/src/main/java/net/openhft/ticker/impl/SystemClock.java index a385be3ae..ed4d0db8b 100644 --- a/affinity/src/main/java/net/openhft/ticker/impl/SystemClock.java +++ b/affinity/src/main/java/net/openhft/ticker/impl/SystemClock.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 higherfrequencytrading.com + * Copyright 2016-2020 chronicle.software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/affinity/src/main/java/software/chronicle/enterprise/internals/impl/NativeAffinity.java b/affinity/src/main/java/software/chronicle/enterprise/internals/impl/NativeAffinity.java index 4391a7657..5da995bcd 100644 --- a/affinity/src/main/java/software/chronicle/enterprise/internals/impl/NativeAffinity.java +++ b/affinity/src/main/java/software/chronicle/enterprise/internals/impl/NativeAffinity.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 higherfrequencytrading.com + * Copyright 2016-2020 chronicle.software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/affinity/src/test/java/net/openhft/affinity/AffinityLockBindMain.java b/affinity/src/test/java/net/openhft/affinity/AffinityLockBindMain.java index dfa28c872..68ec39073 100644 --- a/affinity/src/test/java/net/openhft/affinity/AffinityLockBindMain.java +++ b/affinity/src/test/java/net/openhft/affinity/AffinityLockBindMain.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 higherfrequencytrading.com + * Copyright 2016-2020 chronicle.software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/affinity/src/test/java/net/openhft/affinity/AffinityLockMain.java b/affinity/src/test/java/net/openhft/affinity/AffinityLockMain.java index 261e7c1e8..689eabda4 100644 --- a/affinity/src/test/java/net/openhft/affinity/AffinityLockMain.java +++ b/affinity/src/test/java/net/openhft/affinity/AffinityLockMain.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 higherfrequencytrading.com + * Copyright 2016-2020 chronicle.software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java index 45b9cc19c..c4f8aa769 100644 --- a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java +++ b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 higherfrequencytrading.com + * Copyright 2016-2020 chronicle.software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/affinity/src/test/java/net/openhft/affinity/AffinitySupportMain.java b/affinity/src/test/java/net/openhft/affinity/AffinitySupportMain.java index 4f4330451..6841b3a65 100644 --- a/affinity/src/test/java/net/openhft/affinity/AffinitySupportMain.java +++ b/affinity/src/test/java/net/openhft/affinity/AffinitySupportMain.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 higherfrequencytrading.com + * Copyright 2016-2020 chronicle.software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/affinity/src/test/java/net/openhft/affinity/AffinityThreadFactoryMain.java b/affinity/src/test/java/net/openhft/affinity/AffinityThreadFactoryMain.java index 75deb050a..1b9fb99a2 100644 --- a/affinity/src/test/java/net/openhft/affinity/AffinityThreadFactoryMain.java +++ b/affinity/src/test/java/net/openhft/affinity/AffinityThreadFactoryMain.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 higherfrequencytrading.com + * Copyright 2016-2020 chronicle.software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/affinity/src/test/java/net/openhft/affinity/FileLockLockCheckTest.java b/affinity/src/test/java/net/openhft/affinity/FileLockLockCheckTest.java index a8f249c77..e59d0a805 100644 --- a/affinity/src/test/java/net/openhft/affinity/FileLockLockCheckTest.java +++ b/affinity/src/test/java/net/openhft/affinity/FileLockLockCheckTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 higherfrequencytrading.com + * Copyright 2016-2020 chronicle.software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/affinity/src/test/java/net/openhft/affinity/InterrupedThread.java b/affinity/src/test/java/net/openhft/affinity/InterrupedThread.java index c2b718a7f..8ea9c47e2 100644 --- a/affinity/src/test/java/net/openhft/affinity/InterrupedThread.java +++ b/affinity/src/test/java/net/openhft/affinity/InterrupedThread.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 higherfrequencytrading.com + * Copyright 2016-2020 chronicle.software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/affinity/src/test/java/net/openhft/affinity/LockCheckTest.java b/affinity/src/test/java/net/openhft/affinity/LockCheckTest.java index 6c5c32ee5..55cd8f7a6 100644 --- a/affinity/src/test/java/net/openhft/affinity/LockCheckTest.java +++ b/affinity/src/test/java/net/openhft/affinity/LockCheckTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 higherfrequencytrading.com + * Copyright 2016-2020 chronicle.software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/affinity/src/test/java/net/openhft/affinity/impl/AbstractAffinityImplTest.java b/affinity/src/test/java/net/openhft/affinity/impl/AbstractAffinityImplTest.java index 9912c628b..f858e8086 100644 --- a/affinity/src/test/java/net/openhft/affinity/impl/AbstractAffinityImplTest.java +++ b/affinity/src/test/java/net/openhft/affinity/impl/AbstractAffinityImplTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 higherfrequencytrading.com + * Copyright 2016-2020 chronicle.software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/affinity/src/test/java/net/openhft/affinity/impl/LinuxJNAAffinityTest.java b/affinity/src/test/java/net/openhft/affinity/impl/LinuxJNAAffinityTest.java index 4da60e6aa..670e0b99d 100755 --- a/affinity/src/test/java/net/openhft/affinity/impl/LinuxJNAAffinityTest.java +++ b/affinity/src/test/java/net/openhft/affinity/impl/LinuxJNAAffinityTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 higherfrequencytrading.com + * Copyright 2016-2020 chronicle.software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/affinity/src/test/java/net/openhft/affinity/impl/NativeAffinityImpTest.java b/affinity/src/test/java/net/openhft/affinity/impl/NativeAffinityImpTest.java index 856d7744b..4f038e3d1 100755 --- a/affinity/src/test/java/net/openhft/affinity/impl/NativeAffinityImpTest.java +++ b/affinity/src/test/java/net/openhft/affinity/impl/NativeAffinityImpTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 higherfrequencytrading.com + * Copyright 2016-2020 chronicle.software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/affinity/src/test/java/net/openhft/affinity/impl/PosixJNAAffinityTest.java b/affinity/src/test/java/net/openhft/affinity/impl/PosixJNAAffinityTest.java index 4fb776bac..034aa0a69 100644 --- a/affinity/src/test/java/net/openhft/affinity/impl/PosixJNAAffinityTest.java +++ b/affinity/src/test/java/net/openhft/affinity/impl/PosixJNAAffinityTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 higherfrequencytrading.com + * Copyright 2016-2020 chronicle.software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/affinity/src/test/java/net/openhft/affinity/impl/VanillaCpuLayoutTest.java b/affinity/src/test/java/net/openhft/affinity/impl/VanillaCpuLayoutTest.java index 924a8d5e1..e58206818 100644 --- a/affinity/src/test/java/net/openhft/affinity/impl/VanillaCpuLayoutTest.java +++ b/affinity/src/test/java/net/openhft/affinity/impl/VanillaCpuLayoutTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 higherfrequencytrading.com + * Copyright 2016-2020 chronicle.software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/affinity/src/test/java/net/openhft/affinity/impl/VersionHelperTest.java b/affinity/src/test/java/net/openhft/affinity/impl/VersionHelperTest.java index 18df07776..1ec30d1f1 100644 --- a/affinity/src/test/java/net/openhft/affinity/impl/VersionHelperTest.java +++ b/affinity/src/test/java/net/openhft/affinity/impl/VersionHelperTest.java @@ -1,5 +1,5 @@ /* - * Copyright 20127higherfrequencytrading.com + * Copyright 20127chronicle.software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/affinity/src/test/java/net/openhft/ticker/impl/JNIClockTest.java b/affinity/src/test/java/net/openhft/ticker/impl/JNIClockTest.java index 292418944..8af7760de 100755 --- a/affinity/src/test/java/net/openhft/ticker/impl/JNIClockTest.java +++ b/affinity/src/test/java/net/openhft/ticker/impl/JNIClockTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 higherfrequencytrading.com + * Copyright 2016-2020 chronicle.software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/affinity/src/test/java/org/junit/Assert.java b/affinity/src/test/java/org/junit/Assert.java index c0eab34d2..c48364546 100644 --- a/affinity/src/test/java/org/junit/Assert.java +++ b/affinity/src/test/java/org/junit/Assert.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 higherfrequencytrading.com + * Copyright 2016-2020 chronicle.software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/affinity/src/test/java/software/chronicle/enterprise/internals/JnaAffinityTest.java b/affinity/src/test/java/software/chronicle/enterprise/internals/JnaAffinityTest.java index 8d577a2ed..d9a723019 100644 --- a/affinity/src/test/java/software/chronicle/enterprise/internals/JnaAffinityTest.java +++ b/affinity/src/test/java/software/chronicle/enterprise/internals/JnaAffinityTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 higherfrequencytrading.com + * Copyright 2016-2020 chronicle.software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/affinity/src/test/java/software/chronicle/enterprise/internals/NativeAffinityTest.java b/affinity/src/test/java/software/chronicle/enterprise/internals/NativeAffinityTest.java index 26f746c23..61991595d 100644 --- a/affinity/src/test/java/software/chronicle/enterprise/internals/NativeAffinityTest.java +++ b/affinity/src/test/java/software/chronicle/enterprise/internals/NativeAffinityTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 higherfrequencytrading.com + * Copyright 2016-2020 chronicle.software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 772f23361b7e1a69f3075f73838c04162a282549 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Wed, 28 Oct 2020 15:28:57 +0000 Subject: [PATCH 094/353] 3rd party bom v3.19.4 --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 88035798b..9f37bf736 100755 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -42,7 +42,7 @@ net.openhft third-party-bom pom - 3.19.2 + 3.19.4 import diff --git a/affinity/pom.xml b/affinity/pom.xml index d8fc4cb1d..b2eeafaca 100755 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -43,7 +43,7 @@ net.openhft third-party-bom pom - 3.19.2 + 3.19.4 import From 00570163515f9419055246c1dc001af83c3a6330 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Wed, 28 Oct 2020 15:41:04 +0000 Subject: [PATCH 095/353] move modelVersion to the top --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 9f37bf736..bd017e1bc 100755 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -16,6 +16,7 @@ --> + 4.0.0 net.openhft @@ -24,7 +25,6 @@ - 4.0.0 affinity-test 3.20.0-SNAPSHOT bundle diff --git a/affinity/pom.xml b/affinity/pom.xml index b2eeafaca..ffd8d628f 100755 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -16,6 +16,7 @@ --> + 4.0.0 net.openhft @@ -24,7 +25,6 @@ - 4.0.0 affinity 3.20.1-SNAPSHOT bundle diff --git a/pom.xml b/pom.xml index 5f7de5ab7..0ee456b7e 100755 --- a/pom.xml +++ b/pom.xml @@ -16,6 +16,7 @@ --> + 4.0.0 net.openhft @@ -24,7 +25,6 @@ - 4.0.0 Java-Thread-Affinity 3.20.0-SNAPSHOT pom From f51783961db8fd4b1212948030e319d3e05fe47e Mon Sep 17 00:00:00 2001 From: Peter Lawrwy Date: Tue, 10 Nov 2020 15:02:18 +0000 Subject: [PATCH 096/353] Sync --- affinity-test/pom.xml | 0 affinity/pom.xml | 0 affinity/src/main/c/Makefile | 0 .../src/main/java/net/openhft/affinity/MicroJitterSampler.java | 0 .../src/main/java/net/openhft/affinity/impl/LinuxJNAAffinity.java | 0 affinity/src/main/java/net/openhft/affinity/impl/Utilities.java | 0 .../src/main/java/net/openhft/affinity/impl/VanillaCpuLayout.java | 0 affinity/src/main/java/net/openhft/ticker/ITicker.java | 0 .../test/java/net/openhft/affinity/impl/LinuxJNAAffinityTest.java | 0 .../java/net/openhft/affinity/impl/NativeAffinityImpTest.java | 0 affinity/src/test/java/net/openhft/ticker/impl/JNIClockTest.java | 0 pom.xml | 0 12 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 affinity-test/pom.xml mode change 100755 => 100644 affinity/pom.xml mode change 100755 => 100644 affinity/src/main/c/Makefile mode change 100755 => 100644 affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java mode change 100755 => 100644 affinity/src/main/java/net/openhft/affinity/impl/LinuxJNAAffinity.java mode change 100755 => 100644 affinity/src/main/java/net/openhft/affinity/impl/Utilities.java mode change 100755 => 100644 affinity/src/main/java/net/openhft/affinity/impl/VanillaCpuLayout.java mode change 100755 => 100644 affinity/src/main/java/net/openhft/ticker/ITicker.java mode change 100755 => 100644 affinity/src/test/java/net/openhft/affinity/impl/LinuxJNAAffinityTest.java mode change 100755 => 100644 affinity/src/test/java/net/openhft/affinity/impl/NativeAffinityImpTest.java mode change 100755 => 100644 affinity/src/test/java/net/openhft/ticker/impl/JNIClockTest.java mode change 100755 => 100644 pom.xml diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml old mode 100755 new mode 100644 diff --git a/affinity/pom.xml b/affinity/pom.xml old mode 100755 new mode 100644 diff --git a/affinity/src/main/c/Makefile b/affinity/src/main/c/Makefile old mode 100755 new mode 100644 diff --git a/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java b/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java old mode 100755 new mode 100644 diff --git a/affinity/src/main/java/net/openhft/affinity/impl/LinuxJNAAffinity.java b/affinity/src/main/java/net/openhft/affinity/impl/LinuxJNAAffinity.java old mode 100755 new mode 100644 diff --git a/affinity/src/main/java/net/openhft/affinity/impl/Utilities.java b/affinity/src/main/java/net/openhft/affinity/impl/Utilities.java old mode 100755 new mode 100644 diff --git a/affinity/src/main/java/net/openhft/affinity/impl/VanillaCpuLayout.java b/affinity/src/main/java/net/openhft/affinity/impl/VanillaCpuLayout.java old mode 100755 new mode 100644 diff --git a/affinity/src/main/java/net/openhft/ticker/ITicker.java b/affinity/src/main/java/net/openhft/ticker/ITicker.java old mode 100755 new mode 100644 diff --git a/affinity/src/test/java/net/openhft/affinity/impl/LinuxJNAAffinityTest.java b/affinity/src/test/java/net/openhft/affinity/impl/LinuxJNAAffinityTest.java old mode 100755 new mode 100644 diff --git a/affinity/src/test/java/net/openhft/affinity/impl/NativeAffinityImpTest.java b/affinity/src/test/java/net/openhft/affinity/impl/NativeAffinityImpTest.java old mode 100755 new mode 100644 diff --git a/affinity/src/test/java/net/openhft/ticker/impl/JNIClockTest.java b/affinity/src/test/java/net/openhft/ticker/impl/JNIClockTest.java old mode 100755 new mode 100644 diff --git a/pom.xml b/pom.xml old mode 100755 new mode 100644 From e03f92ff5efd935015e7597da188192f77b1a3ab Mon Sep 17 00:00:00 2001 From: m-anthony Date: Thu, 26 Nov 2020 09:30:48 +0100 Subject: [PATCH 097/353] Support for more than 64 core in -Daffinity.reserved --- .../main/java/net/openhft/affinity/AffinityLock.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java index f2a8f10f7..7f4018e1b 100644 --- a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java +++ b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java @@ -128,8 +128,14 @@ private static BitSet getReservedAffinity0() { return reserverable; } - long[] longs = new long[1]; - longs[0] = Long.parseLong(reservedAffinity, 16); + reservedAffinity = reservedAffinity.trim(); + long[] longs = new long[1 + (reservedAffinity.length() - 1) / 16]; + int end = reservedAffinity.length(); + for(int i = 0; i < longs.length ; i++) { + int begin = Math.max(0, end - 16); + longs[i] = Long.parseLong(reservedAffinity.substring(begin, end), 16); + end = begin; + } return BitSet.valueOf(longs); } From 597d9424a3dd48ac1594c139a7f919fc8ba649ef Mon Sep 17 00:00:00 2001 From: Rob Austin <6506056+RobAustin@users.noreply.github.com> Date: Fri, 27 Nov 2020 12:02:16 +0000 Subject: [PATCH 098/353] Update README.adoc --- README.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.adoc b/README.adoc index bb8c83404..dbe8ead46 100644 --- a/README.adoc +++ b/README.adoc @@ -7,7 +7,7 @@ image::/images/Thread-Affinity_line.png[width=20%] [#image-maven] [caption="", link=https://maven-badges.herokuapp.com/maven-central/net.openhft/affinity] image::https://maven-badges.herokuapp.com/maven-central/net.openhft/affinity/badge.svg[] - +image:https://javadoc.io/badge2/net.openhft/affinity/javadoc.svg[link="https://www.javadoc.io/doc/net.openhft/affinity/latest/index.html"] == Overview Lets you bind a thread to a given core, this can improve performance (this library works best on linux). From 5ca7aa72c2205c7cd02461cb818c3e6fbff50776 Mon Sep 17 00:00:00 2001 From: Rob Austin <6506056+RobAustin@users.noreply.github.com> Date: Fri, 27 Nov 2020 12:02:26 +0000 Subject: [PATCH 099/353] Update README.adoc --- README.adoc | 1 + 1 file changed, 1 insertion(+) diff --git a/README.adoc b/README.adoc index dbe8ead46..3916ae8a4 100644 --- a/README.adoc +++ b/README.adoc @@ -8,6 +8,7 @@ image::/images/Thread-Affinity_line.png[width=20%] [caption="", link=https://maven-badges.herokuapp.com/maven-central/net.openhft/affinity] image::https://maven-badges.herokuapp.com/maven-central/net.openhft/affinity/badge.svg[] image:https://javadoc.io/badge2/net.openhft/affinity/javadoc.svg[link="https://www.javadoc.io/doc/net.openhft/affinity/latest/index.html"] + == Overview Lets you bind a thread to a given core, this can improve performance (this library works best on linux). From 171b1707a55a0cca70d3f6d2e868a994a961d616 Mon Sep 17 00:00:00 2001 From: Rob Austin <6506056+RobAustin@users.noreply.github.com> Date: Fri, 27 Nov 2020 12:02:40 +0000 Subject: [PATCH 100/353] Update README.adoc --- README.adoc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.adoc b/README.adoc index 3916ae8a4..298396f25 100644 --- a/README.adoc +++ b/README.adoc @@ -6,8 +6,7 @@ image::/images/Thread-Affinity_line.png[width=20%] [#image-maven] [caption="", link=https://maven-badges.herokuapp.com/maven-central/net.openhft/affinity] -image::https://maven-badges.herokuapp.com/maven-central/net.openhft/affinity/badge.svg[] -image:https://javadoc.io/badge2/net.openhft/affinity/javadoc.svg[link="https://www.javadoc.io/doc/net.openhft/affinity/latest/index.html"] +image::https://maven-badges.herokuapp.com/maven-central/net.openhft/affinity/badge.svg[] image:https://javadoc.io/badge2/net.openhft/affinity/javadoc.svg[link="https://www.javadoc.io/doc/net.openhft/affinity/latest/index.html"] == Overview Lets you bind a thread to a given core, this can improve performance (this library works best on linux). From f24ed0f295edca87568f78660852fad1c075959b Mon Sep 17 00:00:00 2001 From: Rob Austin <6506056+RobAustin@users.noreply.github.com> Date: Fri, 27 Nov 2020 12:02:55 +0000 Subject: [PATCH 101/353] Update README.adoc --- README.adoc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.adoc b/README.adoc index 298396f25..3916ae8a4 100644 --- a/README.adoc +++ b/README.adoc @@ -6,7 +6,8 @@ image::/images/Thread-Affinity_line.png[width=20%] [#image-maven] [caption="", link=https://maven-badges.herokuapp.com/maven-central/net.openhft/affinity] -image::https://maven-badges.herokuapp.com/maven-central/net.openhft/affinity/badge.svg[] image:https://javadoc.io/badge2/net.openhft/affinity/javadoc.svg[link="https://www.javadoc.io/doc/net.openhft/affinity/latest/index.html"] +image::https://maven-badges.herokuapp.com/maven-central/net.openhft/affinity/badge.svg[] +image:https://javadoc.io/badge2/net.openhft/affinity/javadoc.svg[link="https://www.javadoc.io/doc/net.openhft/affinity/latest/index.html"] == Overview Lets you bind a thread to a given core, this can improve performance (this library works best on linux). From 4c11a81c504d2eff293653a9594e09ffe6519951 Mon Sep 17 00:00:00 2001 From: Peter Lawrwy Date: Thu, 3 Dec 2020 08:47:46 +0000 Subject: [PATCH 102/353] All @Deprecated members which have no comment are marked to be removed in x.22, closes https://github.com/OpenHFT/OpenHFT/issues/41 --- .../net/openhft/affinity/AffinitySupport.java | 2 +- affinity/src/test/java/org/junit/Assert.java | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/affinity/src/main/java/net/openhft/affinity/AffinitySupport.java b/affinity/src/main/java/net/openhft/affinity/AffinitySupport.java index ad80a8ef0..9fca750ef 100644 --- a/affinity/src/main/java/net/openhft/affinity/AffinitySupport.java +++ b/affinity/src/main/java/net/openhft/affinity/AffinitySupport.java @@ -20,7 +20,7 @@ /** * For backward compatibility with Affinity 2.x */ -@Deprecated +@Deprecated(/* to be removed in x.22 */) public class AffinitySupport { public static int getThreadId() { diff --git a/affinity/src/test/java/org/junit/Assert.java b/affinity/src/test/java/org/junit/Assert.java index c48364546..994c64395 100644 --- a/affinity/src/test/java/org/junit/Assert.java +++ b/affinity/src/test/java/org/junit/Assert.java @@ -579,8 +579,8 @@ static public void assertEquals(String message, long expected, long actual) { * assertEquals(double expected, double actual, double delta) * instead */ - @Deprecated - static public void assertEquals(double expected, double actual) { + @Deprecated(/* to be removed in x.22 */) +static public void assertEquals(double expected, double actual) { assertEquals(null, expected, actual); } @@ -589,8 +589,8 @@ static public void assertEquals(double expected, double actual) { * assertEquals(String message, double expected, double actual, double delta) * instead */ - @Deprecated - static public void assertEquals(String message, double expected, + @Deprecated(/* to be removed in x.22 */) +static public void assertEquals(String message, double expected, double actual) { fail("Use assertEquals(expected, actual, delta) to compare floating-point numbers"); } @@ -798,8 +798,8 @@ private static String formatClassAndValue(Object value, String valueString) { * actual values * @deprecated use assertArrayEquals */ - @Deprecated - public static void assertEquals(String message, Object[] expecteds, + @Deprecated(/* to be removed in x.22 */) +public static void assertEquals(String message, Object[] expecteds, Object[] actuals) { assertArrayEquals(message, expecteds, actuals); } @@ -816,8 +816,8 @@ public static void assertEquals(String message, Object[] expecteds, * actual values * @deprecated use assertArrayEquals */ - @Deprecated - public static void assertEquals(Object[] expecteds, Object[] actuals) { + @Deprecated(/* to be removed in x.22 */) +public static void assertEquals(Object[] expecteds, Object[] actuals) { assertArrayEquals(expecteds, actuals); } From 87b78fb91cd78c444968451b036a13428bacabbe Mon Sep 17 00:00:00 2001 From: rogersimmons Date: Fri, 4 Dec 2020 13:51:51 +0000 Subject: [PATCH 103/353] Extend AffinityLock.acquireLock to optionally take an explicit list of CPUs to choose from --- .../net/openhft/affinity/AffinityLock.java | 46 +++++++++++++++++++ .../net/openhft/affinity/LockInventory.java | 16 +++++++ 2 files changed, 62 insertions(+) diff --git a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java index 7f4018e1b..fc2eae07c 100644 --- a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java +++ b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java @@ -26,6 +26,7 @@ import java.io.Closeable; import java.io.File; +import java.util.Arrays; import java.util.BitSet; /** @@ -181,6 +182,30 @@ public static AffinityLock acquireLock(int cpuId) { return acquireLock(true, cpuId, AffinityStrategies.ANY); } + /** + * Assign a cpu which can be bound to the current thread or another thread + * Caller passes in an explicit set of preferred CPUs + * The first available CPU is used, and the lock returned + * If all CPUs in the set are unavailable then no lock is obtained + * + * @param cpus the array of available CPUs to bind to + * @return A handle for an affinity lock, or nolock if no available CPU in the array + */ + public static AffinityLock acquireLock(int[] cpus) { + for( int cpu : cpus ) + { + AffinityLock lock = tryAcquireLock(true, cpu); + if(lock != null) + { + LOGGER.info("Acquired lock on CPU {}", cpu); + return lock; + } + } + + LOGGER.warn("Failed to lock any CPU in explicit list " + Arrays.toString(cpus)); + return LOCK_INVENTORY.noLock(); + } + /** * Allocate from the end. * @@ -196,6 +221,7 @@ public static AffinityLock acquireLockLastMinus(int n) { *

    *
  • "N" being a positive integer means allocate this CPU,
  • *
  • "last" or "last-N" means allocate from the end,
  • + *
  • "csv:1,2,5,6 eg means allocate first free core from the provided
  • *
  • "any" means allow any
  • *
  • "none" or null means
  • *
  • "0" is not allowed
  • @@ -226,6 +252,14 @@ public static AffinityLock acquireLock(String desc) { cpuId = PROCESSORS + lastN - 1; + } else if (desc.startsWith("csv:")) { + String content = desc.substring(4); + int[] cpus = Arrays.asList(content.split(",")).stream() + .map(String::trim) + .mapToInt(Integer::parseInt).toArray(); + + return acquireLock(cpus); + } else if (desc.equals("none")) { return LOCK_INVENTORY.noLock(); @@ -263,6 +297,18 @@ private static AffinityLock acquireLock(boolean bind, int cpuId, @NotNull Affini return LOCK_INVENTORY.acquireLock(bind, cpuId, strategies); } + /** + * Try to acquire a lock on the specified core + * Returns lock if successful, or null if cpu cannot be acquired + * + * @param bind - if true, bind the current thread; if false, reserve a cpu which can be bound later + * @param cpuId - the cpu to lock + * @return - A handle to an affinity lock on success; null if failed to lock + */ + private static AffinityLock tryAcquireLock(boolean bind, int cpuId) { + return LOCK_INVENTORY.tryAcquireLock(bind, cpuId); + } + private static AffinityLock acquireCore(boolean bind, int cpuId, @NotNull AffinityStrategy... strategies) { return LOCK_INVENTORY.acquireCore(bind, cpuId, strategies); } diff --git a/affinity/src/main/java/net/openhft/affinity/LockInventory.java b/affinity/src/main/java/net/openhft/affinity/LockInventory.java index 1af307278..7523e5e28 100644 --- a/affinity/src/main/java/net/openhft/affinity/LockInventory.java +++ b/affinity/src/main/java/net/openhft/affinity/LockInventory.java @@ -131,6 +131,22 @@ public final synchronized AffinityLock acquireLock(boolean bind, int cpuId, Affi return noLock(); } + public final synchronized AffinityLock tryAcquireLock(boolean bind, int cpuId) { + if (getAffinityImpl() instanceof NullAffinity) + return null; + + final AffinityLock required = logicalCoreLocks[cpuId]; + if (required.canReserve(true)) { + updateLockForCurrentThread(bind, required, false); + return required; + } + + LOGGER.warn("Unable to acquire lock on CPU {} for thread {}, trying to find another CPU", + cpuId, Thread.currentThread()); + + return null; + } + public final synchronized AffinityLock acquireCore(boolean bind, int cpuId, AffinityStrategy... strategies) { for (AffinityStrategy strategy : strategies) { LOOP: From 1544d7494a4566ca784be93fef99a7803944f326 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Mon, 14 Dec 2020 16:24:18 +0000 Subject: [PATCH 104/353] Added compat_reports to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index bc0ad52f1..00caab13d 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,7 @@ *.ipr *.iws .idea +compat_reports .attach_pid* ### Virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml From a326315a5cd05cc967054d561def5433c723f9d1 Mon Sep 17 00:00:00 2001 From: Rob Austin Date: Mon, 21 Dec 2020 14:51:20 +0000 Subject: [PATCH 105/353] changed the SMC tag to EA for the ea branch --- affinity/pom.xml | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index ffd8d628f..fca902100 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -234,7 +234,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - master + ea diff --git a/pom.xml b/pom.xml index 0ee456b7e..22125da3d 100644 --- a/pom.xml +++ b/pom.xml @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - master + ea From ef184cbf4009b2d23e9246dc28ce5b6a9552049f Mon Sep 17 00:00:00 2001 From: Rob Austin Date: Thu, 31 Dec 2020 09:34:49 +0000 Subject: [PATCH 106/353] updated version to 21ea0-SNAPSHOT --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index bd017e1bc..e3f7e45fd 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.20.0-SNAPSHOT + 3.21ea0-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test diff --git a/affinity/pom.xml b/affinity/pom.xml index fca902100..ba4bac515 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.20.1-SNAPSHOT + 3.21ea0-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity diff --git a/pom.xml b/pom.xml index 22125da3d..601de9101 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.20.0-SNAPSHOT + 3.21ea0-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent From 5381c7757b58c8149484f7d52edf9e6028207a80 Mon Sep 17 00:00:00 2001 From: Rob Austin Date: Thu, 31 Dec 2020 10:47:06 +0000 Subject: [PATCH 107/353] ignore make file --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 00caab13d..7a6521cc6 100644 --- a/.gitignore +++ b/.gitignore @@ -48,6 +48,8 @@ local.properties .settings/ .loadpath +affinity/src/main/c/Makefile + ### Queue files *.cq4t *.cq4 From d52bfbb76b976346af2f622a63506f559579bd0c Mon Sep 17 00:00:00 2001 From: Rob Austin Date: Thu, 31 Dec 2020 16:10:05 +0000 Subject: [PATCH 108/353] updated to binary-compatibility-enforcer-plugin 1.0.7 --- affinity/src/main/c/Makefile | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 affinity/src/main/c/Makefile diff --git a/affinity/src/main/c/Makefile b/affinity/src/main/c/Makefile old mode 100644 new mode 100755 From 70394a0e988e58264089e01b35ccd1e03b09b4c1 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Wed, 13 Jan 2021 15:39:46 +0100 Subject: [PATCH 109/353] Updating to bom version 2.21ea18 From 181fcc9494ea021a6f156ffbac2202acb79c9fa4 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Wed, 13 Jan 2021 15:40:07 +0100 Subject: [PATCH 110/353] [maven-release-plugin] prepare release Java-Thread-Affinity-3.21ea0 --- affinity-test/pom.xml | 6 +++--- affinity/pom.xml | 6 +++--- pom.xml | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index e3f7e45fd..e2850d851 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -22,11 +22,11 @@ net.openhft java-parent-pom 1.1.23 - + affinity-test - 3.21ea0-SNAPSHOT + 3.21ea0 bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:https://github.com/OpenHFT/Java-Thread-Affinity.git - HEAD + Java-Thread-Affinity-3.21ea0 diff --git a/affinity/pom.xml b/affinity/pom.xml index ba4bac515..eff3fbc8a 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -22,11 +22,11 @@ net.openhft java-parent-pom 1.1.23 - + affinity - 3.21ea0-SNAPSHOT + 3.21ea0 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -234,7 +234,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.21ea0 diff --git a/pom.xml b/pom.xml index 601de9101..48106cca7 100644 --- a/pom.xml +++ b/pom.xml @@ -22,11 +22,11 @@ net.openhft root-parent-pom 1.2.1 - + Java-Thread-Affinity - 3.21ea0-SNAPSHOT + 3.21ea0 pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.21ea0 From 57ee8fb5e7119b338c49bd810da14d2f267ef766 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Wed, 13 Jan 2021 15:40:14 +0100 Subject: [PATCH 111/353] [maven-release-plugin] prepare for next development iteration --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index e2850d851..bb6992353 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.21ea0 + 3.21ea1-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:https://github.com/OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.21ea0 + HEAD diff --git a/affinity/pom.xml b/affinity/pom.xml index eff3fbc8a..9638c3127 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.21ea0 + 3.21ea1-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity @@ -234,7 +234,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.21ea0 + ea diff --git a/pom.xml b/pom.xml index 48106cca7..738bf60e5 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.21ea0 + 3.21ea1-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.21ea0 + ea From e71df9e51724300a977e3aa99138e0d66782fbd5 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Wed, 13 Jan 2021 15:40:34 +0100 Subject: [PATCH 112/353] Reverting back to bom version 2.21ea-SNAPSHOT From 6641b2339375b668ebfdb6201008de84287d6f4c Mon Sep 17 00:00:00 2001 From: Peter Lawrwy Date: Mon, 25 Jan 2021 10:08:58 +0000 Subject: [PATCH 113/353] crlf --- affinity/src/main/c/Makefile | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 affinity/src/main/c/Makefile diff --git a/affinity/src/main/c/Makefile b/affinity/src/main/c/Makefile old mode 100755 new mode 100644 From ade4d49b7293a191ce34a490ac833a4e34df1a32 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Mon, 22 Feb 2021 05:56:02 +0100 Subject: [PATCH 114/353] Updating to bom version 2.21ea56 From ac7cc482f81a3a93d9d5f6f3dc7fbb12a9d6b74e Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Mon, 22 Feb 2021 05:56:15 +0100 Subject: [PATCH 115/353] Reverting back to bom version 2.21ea-SNAPSHOT --- affinity/src/main/c/Makefile | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 affinity/src/main/c/Makefile diff --git a/affinity/src/main/c/Makefile b/affinity/src/main/c/Makefile old mode 100644 new mode 100755 From 8fb3c861313fb531e81432a0fd0003c49f281426 Mon Sep 17 00:00:00 2001 From: Jerry Shea Date: Mon, 22 Feb 2021 16:19:43 +1100 Subject: [PATCH 116/353] Makefile has execute permissions set in git --- .gitignore | 2 -- affinity/pom.xml | 22 ---------------------- 2 files changed, 24 deletions(-) diff --git a/.gitignore b/.gitignore index 7a6521cc6..00caab13d 100644 --- a/.gitignore +++ b/.gitignore @@ -48,8 +48,6 @@ local.properties .settings/ .loadpath -affinity/src/main/c/Makefile - ### Queue files *.cq4t *.cq4 diff --git a/affinity/pom.xml b/affinity/pom.xml index 9638c3127..19ee57922 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -109,28 +109,6 @@ - - - maven-antrun-plugin - 1.7 - - - build-native - process-classes - - run - - - - - - - - - - - - org.codehaus.mojo exec-maven-plugin From a05fdaadfa0a0114484de724dde923c9cb4ac6eb Mon Sep 17 00:00:00 2001 From: Jerry Shea Date: Mon, 22 Feb 2021 16:22:42 +1100 Subject: [PATCH 117/353] Makefile has execute permissions set in git --- affinity/pom.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/affinity/pom.xml b/affinity/pom.xml index 19ee57922..f87f83ca4 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -109,6 +109,8 @@ + + org.codehaus.mojo exec-maven-plugin From 54edece49990c9eeae852fe052e4a883cca04b62 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Mon, 22 Feb 2021 10:13:05 +0100 Subject: [PATCH 118/353] Updating to bom version 2.21ea57 From 43427a3bb58c67db5db84160d43d23df1a41e7e5 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Mon, 22 Feb 2021 10:13:22 +0100 Subject: [PATCH 119/353] [maven-release-plugin] prepare release Java-Thread-Affinity-3.21ea1 --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index bb6992353..207f98256 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.21ea1-SNAPSHOT + 3.21ea1 bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:https://github.com/OpenHFT/Java-Thread-Affinity.git - HEAD + Java-Thread-Affinity-3.21ea1 diff --git a/affinity/pom.xml b/affinity/pom.xml index f87f83ca4..b20dfd567 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.21ea1-SNAPSHOT + 3.21ea1 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -214,7 +214,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.21ea1 diff --git a/pom.xml b/pom.xml index 738bf60e5..923c85898 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.21ea1-SNAPSHOT + 3.21ea1 pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.21ea1 From 3078c600b321ed42b52e08ae1880ef874ce84d79 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Mon, 22 Feb 2021 10:13:28 +0100 Subject: [PATCH 120/353] [maven-release-plugin] prepare for next development iteration --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 207f98256..b085626b3 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.21ea1 + 3.21ea2-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:https://github.com/OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.21ea1 + HEAD diff --git a/affinity/pom.xml b/affinity/pom.xml index b20dfd567..56be3e094 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.21ea1 + 3.21ea2-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity @@ -214,7 +214,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.21ea1 + ea diff --git a/pom.xml b/pom.xml index 923c85898..7682635bb 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.21ea1 + 3.21ea2-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.21ea1 + ea From ad5e622ccd4042ec345798fa85f6f48a09461c96 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Mon, 22 Feb 2021 10:13:46 +0100 Subject: [PATCH 121/353] Reverting back to bom version 2.21ea-SNAPSHOT From fda18b45416545a4a211afad667788defd8e94d4 Mon Sep 17 00:00:00 2001 From: rogersimmons Date: Mon, 1 Mar 2021 10:54:50 +0000 Subject: [PATCH 122/353] Optional busywait for jitter test --- .../net/openhft/affinity/MicroJitterSampler.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java b/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java index d122999d2..dc4ac4a91 100644 --- a/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java +++ b/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java @@ -79,10 +79,22 @@ public class MicroJitterSampler { 20 * 1000 * 1000, 50 * 1000 * 1000, 100 * 1000 * 1000 }; private static final double UTIL = Double.parseDouble(System.getProperty("util", "50")); + private static final boolean BUSYWAIT = Boolean.parseBoolean(System.getProperty("busywait", "false")); + // static final int CPU = Integer.getInteger("cpu", 0); private final int[] count = new int[DELAY.length]; private long totalTime = 0; + private static void pause() throws InterruptedException + { + if(BUSYWAIT) { + long now = System.nanoTime(); + while(System.nanoTime() - now < 1_000_000); + } else { + Thread.sleep(1); + } + + } public static void main(String... ignored) throws InterruptedException { // AffinityLock al = AffinityLock.acquireLock(); @@ -98,7 +110,7 @@ public static void main(String... ignored) throws InterruptedException { for (int i = 0; i < 30 * 1000; i += 2) { microJitterSampler.sample(sampleLength); //noinspection BusyWait - Thread.sleep(1); + pause(); } } From 8c2a0494585879180476ebcc2adfd7b9038a5600 Mon Sep 17 00:00:00 2001 From: Peter Lawrwy Date: Sun, 7 Mar 2021 22:33:16 +0000 Subject: [PATCH 123/353] Ensure unmonitored Bytes create unmonitored BytesStore on resize. --- affinity/src/main/c/Makefile | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 affinity/src/main/c/Makefile diff --git a/affinity/src/main/c/Makefile b/affinity/src/main/c/Makefile old mode 100755 new mode 100644 From ff9322e38ebf0af696a9b79d3e2fc982745d3794 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Sat, 20 Mar 2021 19:07:05 +0000 Subject: [PATCH 124/353] Tidy newlines --- .../src/main/java/net/openhft/affinity/AffinityStrategies.java | 1 - affinity/src/main/java/net/openhft/affinity/AffinitySupport.java | 1 - affinity/src/main/java/net/openhft/ticker/impl/SystemClock.java | 1 - .../java/net/openhft/affinity/impl/LinuxJNAAffinityTest.java | 1 - .../test/java/net/openhft/affinity/impl/VersionHelperTest.java | 1 - 5 files changed, 5 deletions(-) diff --git a/affinity/src/main/java/net/openhft/affinity/AffinityStrategies.java b/affinity/src/main/java/net/openhft/affinity/AffinityStrategies.java index c9a6b8a5b..9a0d3e279 100644 --- a/affinity/src/main/java/net/openhft/affinity/AffinityStrategies.java +++ b/affinity/src/main/java/net/openhft/affinity/AffinityStrategies.java @@ -76,5 +76,4 @@ public boolean matches(int cpuId, int cpuId2) { return cpuLayout.socketId(cpuId) != cpuLayout.socketId(cpuId2); } } - } diff --git a/affinity/src/main/java/net/openhft/affinity/AffinitySupport.java b/affinity/src/main/java/net/openhft/affinity/AffinitySupport.java index 9fca750ef..d4cc6e249 100644 --- a/affinity/src/main/java/net/openhft/affinity/AffinitySupport.java +++ b/affinity/src/main/java/net/openhft/affinity/AffinitySupport.java @@ -30,5 +30,4 @@ public static int getThreadId() { public static void setThreadId() { Affinity.setThreadId(); } - } diff --git a/affinity/src/main/java/net/openhft/ticker/impl/SystemClock.java b/affinity/src/main/java/net/openhft/ticker/impl/SystemClock.java index ed4d0db8b..8844ab460 100644 --- a/affinity/src/main/java/net/openhft/ticker/impl/SystemClock.java +++ b/affinity/src/main/java/net/openhft/ticker/impl/SystemClock.java @@ -47,5 +47,4 @@ public long toNanos(long ticks) { public double toMicros(double ticks) { return ticks / 1e3; } - } \ No newline at end of file diff --git a/affinity/src/test/java/net/openhft/affinity/impl/LinuxJNAAffinityTest.java b/affinity/src/test/java/net/openhft/affinity/impl/LinuxJNAAffinityTest.java index 670e0b99d..52ab34bfe 100644 --- a/affinity/src/test/java/net/openhft/affinity/impl/LinuxJNAAffinityTest.java +++ b/affinity/src/test/java/net/openhft/affinity/impl/LinuxJNAAffinityTest.java @@ -52,5 +52,4 @@ public void LinuxJNA() { affinity.set(0, nbits); LinuxJNAAffinity.INSTANCE.setAffinity(affinity); } - } diff --git a/affinity/src/test/java/net/openhft/affinity/impl/VersionHelperTest.java b/affinity/src/test/java/net/openhft/affinity/impl/VersionHelperTest.java index 1ec30d1f1..232d12c3c 100644 --- a/affinity/src/test/java/net/openhft/affinity/impl/VersionHelperTest.java +++ b/affinity/src/test/java/net/openhft/affinity/impl/VersionHelperTest.java @@ -39,5 +39,4 @@ public void isSameOrNewerTest() { } } } - } From 7e8cd849726a994c2d1f205ee45a0452daf76761 Mon Sep 17 00:00:00 2001 From: Jerry Shea Date: Tue, 13 Apr 2021 08:12:19 +1000 Subject: [PATCH 125/353] set execute permissions set in git --- affinity/src/main/c/Makefile | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 affinity/src/main/c/Makefile diff --git a/affinity/src/main/c/Makefile b/affinity/src/main/c/Makefile old mode 100644 new mode 100755 From c08133e632c2e6799577c607ee6ef44e64f671b8 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Fri, 14 May 2021 11:34:32 +0100 Subject: [PATCH 126/353] Ignore a legacy way of finding a class, #71 --- .../src/test/java/net/openhft/affinity/BootClassPathTest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/affinity/src/test/java/net/openhft/affinity/BootClassPathTest.java b/affinity/src/test/java/net/openhft/affinity/BootClassPathTest.java index 071222d7e..6c101e18e 100644 --- a/affinity/src/test/java/net/openhft/affinity/BootClassPathTest.java +++ b/affinity/src/test/java/net/openhft/affinity/BootClassPathTest.java @@ -6,7 +6,9 @@ public class BootClassPathTest { @Test - public void shouldDetectClassesOnClassPath() throws Exception { + public void shouldDetectClassesOnClassPath() { + if (!System.getProperty("java.version").startsWith("1.8")) + return; assertTrue(BootClassPath.INSTANCE.has("java.lang.Thread")); assertTrue(BootClassPath.INSTANCE.has("java.lang.Runtime")); } From 084f808a742987ee503a9024e6c8544c23c2e69f Mon Sep 17 00:00:00 2001 From: Jerry Shea Date: Tue, 18 May 2021 10:49:31 +1000 Subject: [PATCH 127/353] improve log message for lock file deletion --- .../affinity/lockchecker/FileLockBasedLockChecker.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java b/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java index b142b6f72..c27a65bf9 100644 --- a/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java +++ b/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java @@ -70,8 +70,11 @@ private boolean isLockFree(File file, int id) { } //file is present but nobody has it locked - delete it - LOGGER.info(String.format("Deleting %s as nobody has the lock", file.getAbsolutePath())); - file.delete(); + boolean deleted = file.delete(); + if (deleted) + LOGGER.info(String.format("Deleted %s as nobody has the lock", file.getAbsolutePath())); + else + LOGGER.warn(String.format("Nobody has the lock on %s. Delete failed", file.getAbsolutePath())); return true; } From a73913cd2fc067a99e7b61f03dbf97f01223f095 Mon Sep 17 00:00:00 2001 From: foroughgoudarzi Date: Tue, 25 May 2021 16:15:06 +0100 Subject: [PATCH 128/353] Move images to docs/images. --- README.adoc | 2 +- {images => docs/images}/Thread-Affinity_line.png | Bin 2 files changed, 1 insertion(+), 1 deletion(-) rename {images => docs/images}/Thread-Affinity_line.png (100%) diff --git a/README.adoc b/README.adoc index 3916ae8a4..584aa96aa 100644 --- a/README.adoc +++ b/README.adoc @@ -1,6 +1,6 @@ = Thread Affinity -image::/images/Thread-Affinity_line.png[width=20%] +image::docs/images/Thread-Affinity_line.png[width=20%] == Version diff --git a/images/Thread-Affinity_line.png b/docs/images/Thread-Affinity_line.png similarity index 100% rename from images/Thread-Affinity_line.png rename to docs/images/Thread-Affinity_line.png From 41ed40f0c8355cc73b41eeb72c5f752fb9318360 Mon Sep 17 00:00:00 2001 From: Nick Tindall Date: Thu, 27 May 2021 09:15:28 +1000 Subject: [PATCH 129/353] Remove java.lang classes and NonForkingAffinityLock to support Java 12+, Fixes #58 --- .../java/lang/ThreadLifecycleListener.java | 45 ----- .../java/java/lang/ThreadTrackingGroup.java | 53 ----- .../java/net/openhft/affinity/Affinity.java | 13 +- .../affinity/NonForkingAffinityLock.java | 184 ------------------ 4 files changed, 4 insertions(+), 291 deletions(-) delete mode 100644 affinity/src/main/java/java/lang/ThreadLifecycleListener.java delete mode 100644 affinity/src/main/java/java/lang/ThreadTrackingGroup.java delete mode 100644 affinity/src/main/java/net/openhft/affinity/NonForkingAffinityLock.java diff --git a/affinity/src/main/java/java/lang/ThreadLifecycleListener.java b/affinity/src/main/java/java/lang/ThreadLifecycleListener.java deleted file mode 100644 index f2e4c01e3..000000000 --- a/affinity/src/main/java/java/lang/ThreadLifecycleListener.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2016-2020 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package java.lang; - -/** - * A listener for various events in a Thread's life: creation, termination, etc. - */ -public interface ThreadLifecycleListener { - - /** - * The specified thread is about to be started. - * - * @param t the thread which is being started - */ - void started(Thread t); - - /** - * The specified thread failed to start. - * - * @param t the thread that had a failed start - */ - void startFailed(Thread t); - - /** - * The specified thread has been terminated. - * - * @param t the thread that has been terminated - */ - void terminated(Thread t); -} diff --git a/affinity/src/main/java/java/lang/ThreadTrackingGroup.java b/affinity/src/main/java/java/lang/ThreadTrackingGroup.java deleted file mode 100644 index 7a4d6bb35..000000000 --- a/affinity/src/main/java/java/lang/ThreadTrackingGroup.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2016-2020 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package java.lang; - -/** - * A wrapper of {@link java.lang.ThreadGroup} that tracks the creation and termination of threads. - */ -public class ThreadTrackingGroup extends ThreadGroup { - - /** - * Listener to be notified of various events in thread lifecycles. - */ - private final ThreadLifecycleListener listener; - - public ThreadTrackingGroup(ThreadGroup parent, ThreadLifecycleListener listener) { - super(parent, ThreadTrackingGroup.class.getSimpleName().toLowerCase() + System.identityHashCode(listener)); - this.listener = listener; - } - - @Override - void add(Thread t) { - // System.out.println("ThreadTrackingGroup.add: " + t); //todo: remove - super.add(t); - listener.started(t); - } - - @Override - void threadStartFailed(Thread t) { - super.threadStartFailed(t); - listener.startFailed(t); - } - - @Override - void threadTerminated(Thread t) { - super.threadTerminated(t); - listener.terminated(t); - } -} diff --git a/affinity/src/main/java/net/openhft/affinity/Affinity.java b/affinity/src/main/java/net/openhft/affinity/Affinity.java index e9025f248..ef31c61ee 100644 --- a/affinity/src/main/java/net/openhft/affinity/Affinity.java +++ b/affinity/src/main/java/net/openhft/affinity/Affinity.java @@ -198,24 +198,19 @@ public static boolean isJNAAvailable() { } public static AffinityLock acquireLock() { - return isNonForkingAffinityAvailable() ? NonForkingAffinityLock.acquireLock() : AffinityLock.acquireLock(); + return AffinityLock.acquireLock(); } public static AffinityLock acquireCore() { - return isNonForkingAffinityAvailable() ? NonForkingAffinityLock.acquireCore() : AffinityLock.acquireCore(); + return AffinityLock.acquireCore(); } public static AffinityLock acquireLock(boolean bind) { - return isNonForkingAffinityAvailable() ? NonForkingAffinityLock.acquireLock(bind) : AffinityLock.acquireLock(bind); + return AffinityLock.acquireLock(bind); } public static AffinityLock acquireCore(boolean bind) { - return isNonForkingAffinityAvailable() ? NonForkingAffinityLock.acquireCore(bind) : AffinityLock.acquireCore(bind); - } - - private static boolean isNonForkingAffinityAvailable() { - BootClassPath bootClassPath = BootClassPath.INSTANCE; - return bootClassPath.has("java.lang.ThreadTrackingGroup") && bootClassPath.has("java.lang.ThreadLifecycleListener"); + return AffinityLock.acquireCore(bind); } public static void resetToBaseAffinity() { diff --git a/affinity/src/main/java/net/openhft/affinity/NonForkingAffinityLock.java b/affinity/src/main/java/net/openhft/affinity/NonForkingAffinityLock.java deleted file mode 100644 index d6e3440f2..000000000 --- a/affinity/src/main/java/net/openhft/affinity/NonForkingAffinityLock.java +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Copyright 2016-2020 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package net.openhft.affinity; - -import net.openhft.affinity.impl.NoCpuLayout; -import org.jetbrains.annotations.NotNull; - -import java.lang.reflect.Field; - -public class NonForkingAffinityLock extends AffinityLock implements ThreadLifecycleListener { - - private static final Field GROUP_FIELD = makeThreadFieldModifiable("group"); - - private static final Field TARGET_FIELD = makeThreadFieldModifiable("target"); - - private static final LockInventory LOCK_INVENTORY = new LockInventory(new NoCpuLayout(PROCESSORS)) { - @Override - protected AffinityLock newLock(int cpuId, boolean base, boolean reservable) { - return new NonForkingAffinityLock(cpuId, base, reservable, this); - } - }; - - NonForkingAffinityLock(int cpuId, boolean base, boolean reservable, LockInventory lockInventory) { - super(cpuId, base, reservable, lockInventory); - } - - /** - * Assign any free cpu to this thread. - * - * @return A handle for the current AffinityLock. - */ - public static AffinityLock acquireLock() { - return acquireLock(true); - } - - /** - * Assign any free core to this thread. - *

    - * In reality, only one cpu is assigned, the rest of the threads for that core are reservable so they are not used. - * - * @return A handle for the current AffinityLock. - */ - public static AffinityLock acquireCore() { - return acquireCore(true); - } - - /** - * Assign a cpu which can be bound to the current thread or another thread. - *

    - * This can be used for defining your thread layout centrally and passing the handle via dependency injection. - * - * @param bind if true, bind the current thread, if false, reserve a cpu which can be bound later. - * @return A handle for an affinity lock. - */ - public static AffinityLock acquireLock(boolean bind) { - return acquireLock(bind, AffinityLock.ANY_CPU, AffinityStrategies.ANY); - } - - /** - * Assign a core(and all its cpus) which can be bound to the current thread or another thread. - *

    - * This can be used for defining your thread layout centrally and passing the handle via dependency injection. - * - * @param bind if true, bind the current thread, if false, reserve a cpu which can be bound later. - * @return A handle for an affinity lock. - */ - public static AffinityLock acquireCore(boolean bind) { - return acquireCore(bind, AffinityLock.ANY_CPU, AffinityStrategies.ANY); - } - - private static AffinityLock acquireLock(boolean bind, int cpuId, @NotNull AffinityStrategy... strategies) { - return LOCK_INVENTORY.acquireLock(bind, cpuId, strategies); - } - - private static AffinityLock acquireCore(boolean bind, int cpuId, @NotNull AffinityStrategy... strategies) { - return LOCK_INVENTORY.acquireCore(bind, cpuId, strategies); - } - - /** - * Set the CPU layout for this machine. CPUs which are not mentioned will be ignored. - *

    - * Changing the layout will have no impact on thread which have already been assigned. - * It only affects subsequent assignments. - * - * @param cpuLayout for this application to use for this machine. - */ - public static void cpuLayout(@NotNull CpuLayout cpuLayout) { - LOCK_INVENTORY.set(cpuLayout); - } - - /** - * @return The current CpuLayout for the application. - */ - @NotNull - public static CpuLayout cpuLayout() { - return LOCK_INVENTORY.getCpuLayout(); - } - - /** - * @return All the current locks as a String. - */ - @NotNull - public static String dumpLocks() { - return LOCK_INVENTORY.dumpLocks(); - } - - private static Field makeThreadFieldModifiable(String fieldName) { - try { - Field field = Thread.class.getDeclaredField(fieldName); - field.setAccessible(true); - return field; - } catch (NoSuchFieldException e) { - throw new RuntimeException(Thread.class.getName() + " class doesn't have a " + fieldName + " field! Quite unexpected!"); - } - } - - private static void changeGroupOfThread(Thread thread, ThreadGroup group) { - try { - GROUP_FIELD.set(thread, group); - } catch (IllegalAccessException e) { - throw new RuntimeException("Failed changing " + Thread.class.getName() + "'s the '" + GROUP_FIELD.getName() + "' field! Reason: " + e.getMessage()); - } - } - - private static void wrapRunnableOfThread(Thread thread, final AffinityLock lock) { - try { - final Runnable originalRunnable = (Runnable) TARGET_FIELD.get(thread); - TARGET_FIELD.set( - thread, - new Runnable() { - @Override - public void run() { - lock.release(); - originalRunnable.run(); - } - } - ); - } catch (IllegalAccessException e) { - throw new RuntimeException("Failed wrapping " + Thread.class.getName() + "'s '" + TARGET_FIELD.getName() + "' field! Reason: " + e.getMessage()); - } - } - - @Override - public void bind(boolean wholeCore) { - super.bind(wholeCore); - Thread thread = Thread.currentThread(); - changeGroupOfThread(thread, new ThreadTrackingGroup(thread.getThreadGroup(), this)); - } - - @Override - public void release() { - Thread thread = Thread.currentThread(); - changeGroupOfThread(thread, thread.getThreadGroup().getParent()); - super.release(); - } - - @Override - public void started(Thread t) { - wrapRunnableOfThread(t, this); - } - - @Override - public void startFailed(Thread t) { - } - - @Override - public void terminated(Thread t) { - } -} From da11412523aff99853c187ca58e06ab971d50f4a Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Thu, 27 May 2021 06:11:02 +0200 Subject: [PATCH 130/353] Updating to bom version 2.21ea147 From 1db3c37a6f80b744362eea4c16c53838860fe281 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Thu, 27 May 2021 06:11:19 +0200 Subject: [PATCH 131/353] [maven-release-plugin] prepare release Java-Thread-Affinity-3.21ea2 --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index b085626b3..e49124b50 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.21ea2-SNAPSHOT + 3.21ea2 bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:https://github.com/OpenHFT/Java-Thread-Affinity.git - HEAD + Java-Thread-Affinity-3.21ea2 diff --git a/affinity/pom.xml b/affinity/pom.xml index 56be3e094..f3238730c 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.21ea2-SNAPSHOT + 3.21ea2 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -214,7 +214,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.21ea2 diff --git a/pom.xml b/pom.xml index 7682635bb..d2bb95a33 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.21ea2-SNAPSHOT + 3.21ea2 pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.21ea2 From 4b9cc072ce6755517d09f4380ee8d2a84790f831 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Thu, 27 May 2021 06:11:24 +0200 Subject: [PATCH 132/353] [maven-release-plugin] prepare for next development iteration --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index e49124b50..ae4dc309c 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.21ea2 + 3.21ea3-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:https://github.com/OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.21ea2 + HEAD diff --git a/affinity/pom.xml b/affinity/pom.xml index f3238730c..467027588 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.21ea2 + 3.21ea3-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity @@ -214,7 +214,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.21ea2 + ea diff --git a/pom.xml b/pom.xml index d2bb95a33..5eed94fe4 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.21ea2 + 3.21ea3-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.21ea2 + ea From 5ef467cf697e06ee701ccb55202df4454b213840 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Thu, 27 May 2021 06:11:42 +0200 Subject: [PATCH 133/353] Reverting back to bom version 2.21ea-SNAPSHOT From 55a3af1e7f4a0c84af11fbda733ce63e4dc27131 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Wed, 16 Jun 2021 14:02:07 +0200 Subject: [PATCH 134/353] Updating to bom version 2.21ea173 From 60254599ef140dc8d0ac65b34c2fda113d318457 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Wed, 16 Jun 2021 14:02:26 +0200 Subject: [PATCH 135/353] [maven-release-plugin] prepare release Java-Thread-Affinity-3.21ea3 --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index ae4dc309c..ecd833961 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.21ea3-SNAPSHOT + 3.21ea3 bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:https://github.com/OpenHFT/Java-Thread-Affinity.git - HEAD + Java-Thread-Affinity-3.21ea3 diff --git a/affinity/pom.xml b/affinity/pom.xml index 467027588..60d4e2f11 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.21ea3-SNAPSHOT + 3.21ea3 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -214,7 +214,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.21ea3 diff --git a/pom.xml b/pom.xml index 5eed94fe4..1840e09c9 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.21ea3-SNAPSHOT + 3.21ea3 pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.21ea3 From ce9b86eed32cffd23df7c9d2e65b2278f3d321d0 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Wed, 16 Jun 2021 14:02:31 +0200 Subject: [PATCH 136/353] [maven-release-plugin] prepare for next development iteration --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index ecd833961..f0e1ad5b6 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.21ea3 + 3.21ea4-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:https://github.com/OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.21ea3 + HEAD diff --git a/affinity/pom.xml b/affinity/pom.xml index 60d4e2f11..5fee01f92 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.21ea3 + 3.21ea4-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity @@ -214,7 +214,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.21ea3 + ea diff --git a/pom.xml b/pom.xml index 1840e09c9..b89104462 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.21ea3 + 3.21ea4-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.21ea3 + ea From 4ff58df8152fea9c2bbacc5f3d213e1917fffef6 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Wed, 16 Jun 2021 14:02:49 +0200 Subject: [PATCH 137/353] Reverting back to bom version 2.21ea-SNAPSHOT From 6f689854847b18eb0d07551e0105296fb10cb538 Mon Sep 17 00:00:00 2001 From: Jerry Shea Date: Thu, 17 Jun 2021 11:38:55 +1000 Subject: [PATCH 138/353] tidy doco --- README.adoc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.adoc b/README.adoc index 584aa96aa..773c4ffa7 100644 --- a/README.adoc +++ b/README.adoc @@ -129,21 +129,21 @@ try (final AffinityLock al = AffinityLock.acquireLock()) { ---- In this example, the library will prefer a free CPU on the same Socket as the first thread, otherwise it will pick any free CPU. -=== Getting the thread id. +=== Getting the thread id You can get the current thread id using [source, java] ---- int threadId = AffinitySupport.getThreadId(); ---- -=== Determining which CPU you are running on. +=== Determining which CPU you are running on You can get the current CPU being used by [source, java] ---- int cpuId = AffinitySupport.getCpu(); ---- -=== Controlling the affinity more directly. +=== Controlling the affinity more directly The affinity of the process on start up is [source, java] ---- @@ -223,7 +223,7 @@ try (AffinityLock lock = AffinityLock.acquireLockLastMinus(n)) { I have the cpuId in a configuration file, how can I set it using a string? -=== Answer: use one of the following. +=== Answer: use one of the following [source,java] ---- From 25390273dd5d44b906d9e8ad7479f749d75791f0 Mon Sep 17 00:00:00 2001 From: Peter Lawrwy Date: Thu, 17 Jun 2021 09:25:13 +0100 Subject: [PATCH 139/353] AffinityThreadFactory should bind all thread created, not just the first one. #75 --- .../main/java/net/openhft/affinity/AffinityThreadFactory.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/affinity/src/main/java/net/openhft/affinity/AffinityThreadFactory.java b/affinity/src/main/java/net/openhft/affinity/AffinityThreadFactory.java index a1b15f372..a70bfbe3d 100644 --- a/affinity/src/main/java/net/openhft/affinity/AffinityThreadFactory.java +++ b/affinity/src/main/java/net/openhft/affinity/AffinityThreadFactory.java @@ -66,7 +66,8 @@ public void run() { } private synchronized AffinityLock acquireLockBasedOnLast() { - AffinityLock al = lastAffinityLock == null ? AffinityLock.acquireLock() : lastAffinityLock.acquireLock(strategies); + AffinityLock al = lastAffinityLock == null ? AffinityLock.acquireLock(false) : lastAffinityLock.acquireLock(strategies); + al.bind(); if (al.cpuId() >= 0) lastAffinityLock = al; return al; From f824225eab5850c5501b1c6eccbe93777abec4e0 Mon Sep 17 00:00:00 2001 From: Peter Lawrwy Date: Thu, 17 Jun 2021 09:26:31 +0100 Subject: [PATCH 140/353] When SetThreadAffinityMask silently fails, give a warning and retain the affinity mask. #76 --- .../affinity/impl/WindowsJNAAffinity.java | 55 ++++++++++++------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/affinity/src/main/java/net/openhft/affinity/impl/WindowsJNAAffinity.java b/affinity/src/main/java/net/openhft/affinity/impl/WindowsJNAAffinity.java index 1fdb8dc6a..ba37fca1e 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/WindowsJNAAffinity.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/WindowsJNAAffinity.java @@ -25,6 +25,7 @@ import com.sun.jna.platform.win32.WinDef; import com.sun.jna.ptr.LongByReference; import net.openhft.affinity.IAffinity; +import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -42,6 +43,7 @@ public enum WindowsJNAAffinity implements IAffinity { INSTANCE; public static final boolean LOADED; private static final Logger LOGGER = LoggerFactory.getLogger(WindowsJNAAffinity.class); + private static final ThreadLocal currentAffinity = new ThreadLocal<>(); static { boolean loaded = false; @@ -58,26 +60,11 @@ public enum WindowsJNAAffinity implements IAffinity { @Override public BitSet getAffinity() { - final CLibrary lib = CLibrary.INSTANCE; - final LongByReference cpuset1 = new LongByReference(0); - final LongByReference cpuset2 = new LongByReference(0); - try { - - final int ret = lib.GetProcessAffinityMask(-1, cpuset1, cpuset2); - // Successful result is positive, according to the docs - // https://msdn.microsoft.com/en-us/library/windows/desktop/ms683213%28v=vs.85%29.aspx - if (ret <= 0) { - throw new IllegalStateException("GetProcessAffinityMask(( -1 ), &(" + cpuset1 + "), &(" + cpuset2 + ") ) return " + ret); - } - - long[] longs = new long[1]; - longs[0] = cpuset1.getValue(); - return BitSet.valueOf(longs); - } catch (Exception e) { - LOGGER.error(e.getMessage(), e); - } - - return new BitSet(); + BitSet bitSet = currentAffinity.get(); + if (bitSet != null) + return bitSet; + BitSet longs = getAffinity0(); + return longs != null ? longs : new BitSet(); } @Override @@ -103,6 +90,34 @@ public void setAffinity(final BitSet affinity) { } catch (LastErrorException e) { throw new IllegalStateException("SetThreadAffinityMask((" + pid + ") , &(" + affinity + ") ) errorNo=" + e.getErrorCode(), e); } + BitSet affinity2 = getAffinity0(); + if (!affinity2.equals(affinity)) { + LoggerFactory.getLogger(WindowsJNAAffinity.class).warn("Tried to set affinity to " + affinity + " but was " + affinity2 + " you may have in sufficient access rights"); + } + currentAffinity.set((BitSet) affinity.clone()); + } + + @Nullable + private BitSet getAffinity0() { + final CLibrary lib = CLibrary.INSTANCE; + final LongByReference cpuset1 = new LongByReference(0); + final LongByReference cpuset2 = new LongByReference(0); + try { + + final int ret = lib.GetProcessAffinityMask(-1, cpuset1, cpuset2); + // Successful result is positive, according to the docs + // https://msdn.microsoft.com/en-us/library/windows/desktop/ms683213%28v=vs.85%29.aspx + if (ret <= 0) { + throw new IllegalStateException("GetProcessAffinityMask(( -1 ), &(" + cpuset1 + "), &(" + cpuset2 + ") ) return " + ret); + } + + long[] longs = new long[1]; + longs[0] = cpuset1.getValue(); + return BitSet.valueOf(longs); + } catch (Exception e) { + LOGGER.error(e.getMessage(), e); + } + return null; } public int getTid() { From 4758ecfaf8b64b1d3bb7cf067ef87622cb05212b Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Thu, 17 Jun 2021 11:39:02 +0100 Subject: [PATCH 141/353] Allow for some CPUs to be turned off. --- .../main/java/net/openhft/affinity/impl/VanillaCpuLayout.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/affinity/src/main/java/net/openhft/affinity/impl/VanillaCpuLayout.java b/affinity/src/main/java/net/openhft/affinity/impl/VanillaCpuLayout.java index d30c8bba3..55790d734 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/VanillaCpuLayout.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/VanillaCpuLayout.java @@ -20,6 +20,7 @@ import net.openhft.affinity.CpuLayout; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.slf4j.LoggerFactory; import java.io.*; import java.util.*; @@ -60,7 +61,7 @@ public class VanillaCpuLayout implements CpuLayout { for (CpuInfo detail : cpuDetails) { error.append(detail).append('\n'); } - throw new AssertionError(error); + LoggerFactory.getLogger(VanillaCpuLayout.class).warn(error.toString()); } } From c10e9f8be999ce7f30a70f6f546302defee09be9 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Thu, 17 Jun 2021 14:26:33 +0200 Subject: [PATCH 142/353] Updating to bom version 2.21ea176 From 490a930b7855fdad55696f1fe0581c0ebb600f5f Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Thu, 17 Jun 2021 14:26:55 +0200 Subject: [PATCH 143/353] [maven-release-plugin] prepare release Java-Thread-Affinity-3.21ea4 --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index f0e1ad5b6..98368e773 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.21ea4-SNAPSHOT + 3.21ea4 bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:https://github.com/OpenHFT/Java-Thread-Affinity.git - HEAD + Java-Thread-Affinity-3.21ea4 diff --git a/affinity/pom.xml b/affinity/pom.xml index 5fee01f92..9ab9cfd71 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.21ea4-SNAPSHOT + 3.21ea4 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -214,7 +214,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.21ea4 diff --git a/pom.xml b/pom.xml index b89104462..c14ef7e28 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.21ea4-SNAPSHOT + 3.21ea4 pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.21ea4 From 6de4f343bf5ac75890fdef0591a9aa59df1bb01e Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Thu, 17 Jun 2021 14:27:01 +0200 Subject: [PATCH 144/353] [maven-release-plugin] prepare for next development iteration --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 98368e773..b613673ec 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.21ea4 + 3.21ea5-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:https://github.com/OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.21ea4 + HEAD diff --git a/affinity/pom.xml b/affinity/pom.xml index 9ab9cfd71..3907c284d 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.21ea4 + 3.21ea5-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity @@ -214,7 +214,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.21ea4 + ea diff --git a/pom.xml b/pom.xml index c14ef7e28..09de56907 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.21ea4 + 3.21ea5-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.21ea4 + ea From fc830d4a3564269b8361f6b07a1c1b7b8a35b03c Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Thu, 17 Jun 2021 14:27:20 +0200 Subject: [PATCH 145/353] Reverting back to bom version 2.21ea-SNAPSHOT From af951fd6437e51bb08c6c54fbaffe1ae80745641 Mon Sep 17 00:00:00 2001 From: Jerry Shea Date: Tue, 22 Jun 2021 09:31:00 +1000 Subject: [PATCH 146/353] Makefile optional for easier windows build --- affinity/pom.xml | 54 ++++++++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index 3907c284d..c111b518c 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -95,6 +95,38 @@ + + make-c + + + !dontMake + + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.2.1 + + + + build-native + process-classes + + exec + + + ${project.basedir}/${native.source.dir}/Makefile + ${project.basedir}/${native.source.dir} + + + + + + + @@ -109,28 +141,6 @@ - - - - org.codehaus.mojo - exec-maven-plugin - 1.2.1 - - - - build-native - process-classes - - exec - - - ${project.basedir}/${native.source.dir}/Makefile - ${project.basedir}/${native.source.dir} - - - - - org.apache.maven.plugins maven-scm-publish-plugin From 0638a3ac7aef7073d46b8342a96b1884026cd8cd Mon Sep 17 00:00:00 2001 From: Jerry Shea Date: Mon, 21 Jun 2021 14:41:30 +1000 Subject: [PATCH 147/353] JNA 5.8.0 --- affinity/pom.xml | 1 + .../openhft/affinity/impl/LinuxHelper.java | 2 +- .../openhft/affinity/impl/OSXJNAAffinity.java | 3 +-- .../affinity/impl/PosixJNAAffinity.java | 3 +-- .../affinity/impl/SolarisJNAAffinity.java | 3 +-- .../affinity/impl/WindowsJNAAffinity.java | 20 ++++++++++--------- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index c111b518c..b6e3e8d3f 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -128,6 +128,7 @@ + diff --git a/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java b/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java index deee9a908..459e474f0 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java @@ -158,7 +158,7 @@ public static int syscall(int number, Object... args) { } interface CLibrary extends Library { - CLibrary INSTANCE = (CLibrary) Native.loadLibrary(LIBRARY_NAME, CLibrary.class); + CLibrary INSTANCE = Native.load(LIBRARY_NAME, CLibrary.class); int sched_setaffinity(final int pid, final int cpusetsize, diff --git a/affinity/src/main/java/net/openhft/affinity/impl/OSXJNAAffinity.java b/affinity/src/main/java/net/openhft/affinity/impl/OSXJNAAffinity.java index c9b7fa4b8..39ed90d55 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/OSXJNAAffinity.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/OSXJNAAffinity.java @@ -72,8 +72,7 @@ public int getThreadId() { } interface CLibrary extends Library { - CLibrary INSTANCE = (CLibrary) - Native.loadLibrary("libpthread.dylib", CLibrary.class); + CLibrary INSTANCE = Native.load("libpthread.dylib", CLibrary.class); int pthread_self() throws LastErrorException; } diff --git a/affinity/src/main/java/net/openhft/affinity/impl/PosixJNAAffinity.java b/affinity/src/main/java/net/openhft/affinity/impl/PosixJNAAffinity.java index f3efd1947..25e3053f0 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/PosixJNAAffinity.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/PosixJNAAffinity.java @@ -191,8 +191,7 @@ public int getThreadId() { * @author BegemoT */ interface CLibrary extends Library { - CLibrary INSTANCE = (CLibrary) - Native.loadLibrary(LIBRARY_NAME, CLibrary.class); + CLibrary INSTANCE = Native.load(LIBRARY_NAME, CLibrary.class); int sched_setaffinity(final int pid, final int cpusetsize, diff --git a/affinity/src/main/java/net/openhft/affinity/impl/SolarisJNAAffinity.java b/affinity/src/main/java/net/openhft/affinity/impl/SolarisJNAAffinity.java index 2718187c5..a9c6b011b 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/SolarisJNAAffinity.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/SolarisJNAAffinity.java @@ -72,8 +72,7 @@ public int getThreadId() { } interface CLibrary extends Library { - CLibrary INSTANCE = (CLibrary) - Native.loadLibrary("c", CLibrary.class); + CLibrary INSTANCE = Native.load("c", CLibrary.class); int pthread_self() throws LastErrorException; } diff --git a/affinity/src/main/java/net/openhft/affinity/impl/WindowsJNAAffinity.java b/affinity/src/main/java/net/openhft/affinity/impl/WindowsJNAAffinity.java index ba37fca1e..1a8bb2cd0 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/WindowsJNAAffinity.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/WindowsJNAAffinity.java @@ -17,12 +17,10 @@ package net.openhft.affinity.impl; -import com.sun.jna.LastErrorException; -import com.sun.jna.Library; -import com.sun.jna.Native; -import com.sun.jna.PointerType; +import com.sun.jna.*; import com.sun.jna.platform.win32.Kernel32; import com.sun.jna.platform.win32.WinDef; +import com.sun.jna.platform.win32.WinNT; import com.sun.jna.ptr.LongByReference; import net.openhft.affinity.IAffinity; import org.jetbrains.annotations.Nullable; @@ -86,7 +84,7 @@ public void setAffinity(final BitSet affinity) { int pid = getTid(); try { - lib.SetThreadAffinityMask(pid, aff); + lib.SetThreadAffinityMask(handle(pid), aff); } catch (LastErrorException e) { throw new IllegalStateException("SetThreadAffinityMask((" + pid + ") , &(" + affinity + ") ) errorNo=" + e.getErrorCode(), e); } @@ -104,7 +102,7 @@ private BitSet getAffinity0() { final LongByReference cpuset2 = new LongByReference(0); try { - final int ret = lib.GetProcessAffinityMask(-1, cpuset1, cpuset2); + final int ret = lib.GetProcessAffinityMask(handle(-1), cpuset1, cpuset2); // Successful result is positive, according to the docs // https://msdn.microsoft.com/en-us/library/windows/desktop/ms683213%28v=vs.85%29.aspx if (ret <= 0) { @@ -120,6 +118,10 @@ private BitSet getAffinity0() { return null; } + private WinNT.HANDLE handle(int pid) { + return new WinNT.HANDLE(new Pointer(pid)); + } + public int getTid() { final CLibrary lib = CLibrary.INSTANCE; @@ -152,11 +154,11 @@ public int getThreadId() { * @author BegemoT */ private interface CLibrary extends Library { - CLibrary INSTANCE = (CLibrary) Native.loadLibrary("kernel32", CLibrary.class); + CLibrary INSTANCE = Native.load("kernel32", CLibrary.class); - int GetProcessAffinityMask(final int pid, final PointerType lpProcessAffinityMask, final PointerType lpSystemAffinityMask) throws LastErrorException; + int GetProcessAffinityMask(final WinNT.HANDLE pid, final PointerType lpProcessAffinityMask, final PointerType lpSystemAffinityMask) throws LastErrorException; - void SetThreadAffinityMask(final int pid, final WinDef.DWORD lpProcessAffinityMask) throws LastErrorException; + void SetThreadAffinityMask(final WinNT.HANDLE pid, final WinDef.DWORD lpProcessAffinityMask) throws LastErrorException; int GetCurrentThread() throws LastErrorException; } From 7a264a8e4022b9b482f7f5e0afffa38efa3df58b Mon Sep 17 00:00:00 2001 From: Jerry Shea Date: Mon, 21 Jun 2021 14:46:16 +1000 Subject: [PATCH 148/353] clean up and de-deprecate --- .../affinity/impl/NativeAffinityImpTest.java | 4 +- .../affinity/impl/PosixJNAAffinityTest.java | 3 +- .../affinity/impl/VanillaCpuLayoutTest.java | 2 +- affinity/src/test/java/org/junit/Assert.java | 886 ------------------ 4 files changed, 4 insertions(+), 891 deletions(-) delete mode 100644 affinity/src/test/java/org/junit/Assert.java diff --git a/affinity/src/test/java/net/openhft/affinity/impl/NativeAffinityImpTest.java b/affinity/src/test/java/net/openhft/affinity/impl/NativeAffinityImpTest.java index 4f038e3d1..3c98d9683 100644 --- a/affinity/src/test/java/net/openhft/affinity/impl/NativeAffinityImpTest.java +++ b/affinity/src/test/java/net/openhft/affinity/impl/NativeAffinityImpTest.java @@ -17,7 +17,7 @@ package net.openhft.affinity.impl; -import net.openhft.affinity.AffinitySupport; +import net.openhft.affinity.Affinity; import net.openhft.affinity.IAffinity; import org.junit.Assume; import org.junit.BeforeClass; @@ -45,7 +45,7 @@ public IAffinity getImpl() { public void testGettid() { System.out.println("pid=" + getImpl().getProcessId()); System.out.println("tid=" + getImpl().getThreadId()); - AffinitySupport.setThreadId(); + Affinity.setThreadId(); for (int j = 0; j < 3; j++) { final int runs = 100000; diff --git a/affinity/src/test/java/net/openhft/affinity/impl/PosixJNAAffinityTest.java b/affinity/src/test/java/net/openhft/affinity/impl/PosixJNAAffinityTest.java index 034aa0a69..a763cef05 100644 --- a/affinity/src/test/java/net/openhft/affinity/impl/PosixJNAAffinityTest.java +++ b/affinity/src/test/java/net/openhft/affinity/impl/PosixJNAAffinityTest.java @@ -18,7 +18,6 @@ package net.openhft.affinity.impl; import net.openhft.affinity.Affinity; -import net.openhft.affinity.AffinitySupport; import net.openhft.affinity.IAffinity; import org.junit.Assume; import org.junit.BeforeClass; @@ -44,7 +43,7 @@ public IAffinity getImpl() { public void testGettid() { System.out.println("pid=" + getImpl().getProcessId()); System.out.println("tid=" + getImpl().getThreadId()); - AffinitySupport.setThreadId(); + Affinity.setThreadId(); for (int j = 0; j < 3; j++) { final int runs = 100000; diff --git a/affinity/src/test/java/net/openhft/affinity/impl/VanillaCpuLayoutTest.java b/affinity/src/test/java/net/openhft/affinity/impl/VanillaCpuLayoutTest.java index e58206818..581874871 100644 --- a/affinity/src/test/java/net/openhft/affinity/impl/VanillaCpuLayoutTest.java +++ b/affinity/src/test/java/net/openhft/affinity/impl/VanillaCpuLayoutTest.java @@ -22,7 +22,7 @@ import java.io.IOException; import java.io.InputStream; -import static junit.framework.Assert.assertEquals; +import static org.junit.Assert.assertEquals; /** * @author peter.lawrey diff --git a/affinity/src/test/java/org/junit/Assert.java b/affinity/src/test/java/org/junit/Assert.java deleted file mode 100644 index 994c64395..000000000 --- a/affinity/src/test/java/org/junit/Assert.java +++ /dev/null @@ -1,886 +0,0 @@ -/* - * Copyright 2016-2020 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.junit; - -import org.hamcrest.Matcher; -import org.hamcrest.MatcherAssert; -import org.junit.internal.ArrayComparisonFailure; -import org.junit.internal.ExactComparisonCriteria; -import org.junit.internal.InexactComparisonCriteria; - -/** - * TODO replace with 4.12 when it is released with a simple bug fix. - *

    - * A set of assertion methods useful for writing tests. Only failed assertions - * are recorded. These methods can be used directly: - * Assert.assertEquals(...), however, they read better if they - * are referenced through static import:
    - *

    - *

    - * import static org.junit.Assert.*;
    - *    ...
    - *    assertEquals(...);
    - * 
    - * - * @see AssertionError - * @since 4.0 - */ -public class Assert { - /** - * Protect constructor since it is a static only class - */ - protected Assert() { - } - - /** - * Asserts that a condition is true. If it isn't it throws an - * {@link AssertionError} with the given message. - * - * @param message the identifying message for the {@link AssertionError} (null - * okay) - * @param condition condition to be checked - */ - static public void assertTrue(String message, boolean condition) { - if (!condition) { - fail(message); - } - } - - /** - * Asserts that a condition is true. If it isn't it throws an - * {@link AssertionError} without a message. - * - * @param condition condition to be checked - */ - static public void assertTrue(boolean condition) { - assertTrue(null, condition); - } - - /** - * Asserts that a condition is false. If it isn't it throws an - * {@link AssertionError} with the given message. - * - * @param message the identifying message for the {@link AssertionError} (null - * okay) - * @param condition condition to be checked - */ - static public void assertFalse(String message, boolean condition) { - assertTrue(message, !condition); - } - - /** - * Asserts that a condition is false. If it isn't it throws an - * {@link AssertionError} without a message. - * - * @param condition condition to be checked - */ - static public void assertFalse(boolean condition) { - assertFalse(null, condition); - } - - /** - * Fails a test with the given message. - * - * @param message the identifying message for the {@link AssertionError} (null - * okay) - * @see AssertionError - */ - static public void fail(String message) { - if (message == null) { - throw new AssertionError(); - } - throw new AssertionError(message); - } - - /** - * Fails a test with no message. - */ - static public void fail() { - fail(null); - } - - /** - * Asserts that two objects are equal. If they are not, an - * {@link AssertionError} is thrown with the given message. If - * expected and actual are null, - * they are considered equal. - * - * @param message the identifying message for the {@link AssertionError} (null - * okay) - * @param expected expected value - * @param actual actual value - */ - static public void assertEquals(String message, Object expected, - Object actual) { - if (equalsRegardingNull(expected, actual)) { - return; - - } else if (expected instanceof String && actual instanceof String) { - String cleanMessage = message == null ? "" : message; - throw new ComparisonFailure(cleanMessage, (String) expected, - (String) actual); - - } else { - failNotEquals(message, expected, actual); - } - } - - private static boolean equalsRegardingNull(Object expected, Object actual) { - if (expected == null) { - return actual == null; - } - - return isEquals(expected, actual); - } - - private static boolean isEquals(Object expected, Object actual) { - return expected.equals(actual); - } - - /** - * Asserts that two objects are equal. If they are not, an - * {@link AssertionError} without a message is thrown. If - * expected and actual are null, - * they are considered equal. - * - * @param expected expected value - * @param actual the value to check against expected - */ - static public void assertEquals(Object expected, Object actual) { - assertEquals(null, expected, actual); - } - - /** - * Asserts that two objects are not equals. If they are, an - * {@link AssertionError} is thrown with the given message. If - * first and second are null, - * they are considered equal. - * - * @param message the identifying message for the {@link AssertionError} (null - * okay) - * @param first first value to check - * @param second the value to check against first - */ - static public void assertNotEquals(String message, Object first, - Object second) { - if (equalsRegardingNull(first, second)) { - failEquals(message, first); - } - } - - /** - * Asserts that two objects are not equals. If they are, an - * {@link AssertionError} without a message is thrown. If - * first and second are null, - * they are considered equal. - * - * @param first first value to check - * @param second the value to check against first - */ - static public void assertNotEquals(Object first, Object second) { - assertNotEquals(null, first, second); - } - - private static void failEquals(String message, Object actual) { - String formatted = "Values should be different. "; - if (message != null) { - formatted = message + ". "; - } - - formatted += "Actual: " + actual; - fail(formatted); - } - - /** - * Asserts that two longs are not equals. If they are, an - * {@link AssertionError} is thrown with the given message. - * - * @param message the identifying message for the {@link AssertionError} (null - * okay) - * @param first first value to check - * @param second the value to check against first - */ - static public void assertNotEquals(String message, long first, long second) { - assertNotEquals(message, (Long) first, (Long) second); - } - - /** - * Asserts that two longs are not equals. If they are, an - * {@link AssertionError} without a message is thrown. - * - * @param first first value to check - * @param second the value to check against first - */ - static public void assertNotEquals(long first, long second) { - assertNotEquals(null, first, second); - } - - /** - * Asserts that two doubles or floats are not equal to within a positive delta. - * If they are, an {@link AssertionError} is thrown with the given - * message. If the expected value is infinity then the delta value is - * ignored. NaNs are considered equal: - * assertNotEquals(Double.NaN, Double.NaN, *) fails - * - * @param message the identifying message for the {@link AssertionError} (null - * okay) - * @param first first value to check - * @param second the value to check against first - * @param delta the maximum delta between expected and - * actual for which both numbers are still - * considered equal. - */ - static public void assertNotEquals(String message, double first, - double second, double delta) { - if (!doubleIsDifferent(first, second, delta)) { - failEquals(message, new Double(first)); - } - } - - /** - * Asserts that two doubles or floats are not equal to within a positive delta. - * If they are, an {@link AssertionError} is thrown. If the expected - * value is infinity then the delta value is ignored.NaNs are considered - * equal: assertNotEquals(Double.NaN, Double.NaN, *) fails - * - * @param first first value to check - * @param second the value to check against first - * @param delta the maximum delta between expected and - * actual for which both numbers are still - * considered equal. - */ - static public void assertNotEquals(double first, double second, double delta) { - assertNotEquals(null, first, second, delta); - } - - /** - * Asserts that two object arrays are equal. If they are not, an - * {@link AssertionError} is thrown with the given message. If - * expecteds and actuals are null, - * they are considered equal. - * - * @param message the identifying message for the {@link AssertionError} (null - * okay) - * @param expecteds Object array or array of arrays (multi-dimensional array) with - * expected values. - * @param actuals Object array or array of arrays (multi-dimensional array) with - * actual values - */ - public static void assertArrayEquals(String message, Object[] expecteds, - Object[] actuals) throws ArrayComparisonFailure { - internalArrayEquals(message, expecteds, actuals); - } - - /** - * Asserts that two object arrays are equal. If they are not, an - * {@link AssertionError} is thrown. If expected and - * actual are null, they are considered - * equal. - * - * @param expecteds Object array or array of arrays (multi-dimensional array) with - * expected values - * @param actuals Object array or array of arrays (multi-dimensional array) with - * actual values - */ - public static void assertArrayEquals(Object[] expecteds, Object[] actuals) { - assertArrayEquals(null, expecteds, actuals); - } - - /** - * Asserts that two byte arrays are equal. If they are not, an - * {@link AssertionError} is thrown with the given message. - * - * @param message the identifying message for the {@link AssertionError} (null - * okay) - * @param expecteds byte array with expected values. - * @param actuals byte array with actual values - */ - public static void assertArrayEquals(String message, byte[] expecteds, - byte[] actuals) throws ArrayComparisonFailure { - internalArrayEquals(message, expecteds, actuals); - } - - /** - * Asserts that two byte arrays are equal. If they are not, an - * {@link AssertionError} is thrown. - * - * @param expecteds byte array with expected values. - * @param actuals byte array with actual values - */ - public static void assertArrayEquals(byte[] expecteds, byte[] actuals) { - assertArrayEquals(null, expecteds, actuals); - } - - /** - * Asserts that two char arrays are equal. If they are not, an - * {@link AssertionError} is thrown with the given message. - * - * @param message the identifying message for the {@link AssertionError} (null - * okay) - * @param expecteds char array with expected values. - * @param actuals char array with actual values - */ - public static void assertArrayEquals(String message, char[] expecteds, - char[] actuals) throws ArrayComparisonFailure { - internalArrayEquals(message, expecteds, actuals); - } - - /** - * Asserts that two char arrays are equal. If they are not, an - * {@link AssertionError} is thrown. - * - * @param expecteds char array with expected values. - * @param actuals char array with actual values - */ - public static void assertArrayEquals(char[] expecteds, char[] actuals) { - assertArrayEquals(null, expecteds, actuals); - } - - /** - * Asserts that two short arrays are equal. If they are not, an - * {@link AssertionError} is thrown with the given message. - * - * @param message the identifying message for the {@link AssertionError} (null - * okay) - * @param expecteds short array with expected values. - * @param actuals short array with actual values - */ - public static void assertArrayEquals(String message, short[] expecteds, - short[] actuals) throws ArrayComparisonFailure { - internalArrayEquals(message, expecteds, actuals); - } - - /** - * Asserts that two short arrays are equal. If they are not, an - * {@link AssertionError} is thrown. - * - * @param expecteds short array with expected values. - * @param actuals short array with actual values - */ - public static void assertArrayEquals(short[] expecteds, short[] actuals) { - assertArrayEquals(null, expecteds, actuals); - } - - /** - * Asserts that two int arrays are equal. If they are not, an - * {@link AssertionError} is thrown with the given message. - * - * @param message the identifying message for the {@link AssertionError} (null - * okay) - * @param expecteds int array with expected values. - * @param actuals int array with actual values - */ - public static void assertArrayEquals(String message, int[] expecteds, - int[] actuals) throws ArrayComparisonFailure { - internalArrayEquals(message, expecteds, actuals); - } - - /** - * Asserts that two int arrays are equal. If they are not, an - * {@link AssertionError} is thrown. - * - * @param expecteds int array with expected values. - * @param actuals int array with actual values - */ - public static void assertArrayEquals(int[] expecteds, int[] actuals) { - assertArrayEquals(null, expecteds, actuals); - } - - /** - * Asserts that two long arrays are equal. If they are not, an - * {@link AssertionError} is thrown with the given message. - * - * @param message the identifying message for the {@link AssertionError} (null - * okay) - * @param expecteds long array with expected values. - * @param actuals long array with actual values - */ - public static void assertArrayEquals(String message, long[] expecteds, - long[] actuals) throws ArrayComparisonFailure { - internalArrayEquals(message, expecteds, actuals); - } - - /** - * Asserts that two long arrays are equal. If they are not, an - * {@link AssertionError} is thrown. - * - * @param expecteds long array with expected values. - * @param actuals long array with actual values - */ - public static void assertArrayEquals(long[] expecteds, long[] actuals) { - assertArrayEquals(null, expecteds, actuals); - } - - /** - * Asserts that two double arrays are equal. If they are not, an - * {@link AssertionError} is thrown with the given message. - * - * @param message the identifying message for the {@link AssertionError} (null - * okay) - * @param expecteds double array with expected values. - * @param actuals double array with actual values - */ - public static void assertArrayEquals(String message, double[] expecteds, - double[] actuals, double delta) throws ArrayComparisonFailure { - new InexactComparisonCriteria(delta).arrayEquals(message, expecteds, actuals); - } - - /** - * Asserts that two double arrays are equal. If they are not, an - * {@link AssertionError} is thrown. - * - * @param expecteds double array with expected values. - * @param actuals double array with actual values - */ - public static void assertArrayEquals(double[] expecteds, double[] actuals, double delta) { - assertArrayEquals(null, expecteds, actuals, delta); - } - - /** - * Asserts that two float arrays are equal. If they are not, an - * {@link AssertionError} is thrown with the given message. - * - * @param message the identifying message for the {@link AssertionError} (null - * okay) - * @param expecteds float array with expected values. - * @param actuals float array with actual values - */ - public static void assertArrayEquals(String message, float[] expecteds, - float[] actuals, float delta) throws ArrayComparisonFailure { - new InexactComparisonCriteria(delta).arrayEquals(message, expecteds, actuals); - } - - /** - * Asserts that two float arrays are equal. If they are not, an - * {@link AssertionError} is thrown. - * - * @param expecteds float array with expected values. - * @param actuals float array with actual values - */ - public static void assertArrayEquals(float[] expecteds, float[] actuals, float delta) { - assertArrayEquals(null, expecteds, actuals, delta); - } - - /** - * Asserts that two object arrays are equal. If they are not, an - * {@link AssertionError} is thrown with the given message. If - * expecteds and actuals are null, - * they are considered equal. - * - * @param message the identifying message for the {@link AssertionError} (null - * okay) - * @param expecteds Object array or array of arrays (multi-dimensional array) with - * expected values. - * @param actuals Object array or array of arrays (multi-dimensional array) with - * actual values - */ - private static void internalArrayEquals(String message, Object expecteds, - Object actuals) throws ArrayComparisonFailure { - new ExactComparisonCriteria().arrayEquals(message, expecteds, actuals); - } - - /** - * Asserts that two doubles are equal to within a positive delta. - * If they are not, an {@link AssertionError} is thrown with the given - * message. If the expected value is infinity then the delta value is - * ignored. NaNs are considered equal: - * assertEquals(Double.NaN, Double.NaN, *) passes - * - * @param message the identifying message for the {@link AssertionError} (null - * okay) - * @param expected expected value - * @param actual the value to check against expected - * @param delta the maximum delta between expected and - * actual for which both numbers are still - * considered equal. - */ - static public void assertEquals(String message, double expected, - double actual, double delta) { - if (doubleIsDifferent(expected, actual, delta)) { - failNotEquals(message, new Double(expected), new Double(actual)); - } - } - - /** - * Asserts that two floats are equal to within a positive delta. - * If they are not, an {@link AssertionError} is thrown with the given - * message. If the expected value is infinity then the delta value is - * ignored. NaNs are considered equal: - * assertEquals(Float.NaN, Float.NaN, *) passes - * - * @param message the identifying message for the {@link AssertionError} (null - * okay) - * @param expected expected value - * @param actual the value to check against expected - * @param delta the maximum delta between expected and - * actual for which both numbers are still - * considered equal. - */ - static public void assertEquals(String message, float expected, - float actual, float delta) { - if (Float.compare(expected, actual) == 0) { - return; - } - if (!(Math.abs(expected - actual) <= delta)) { - failNotEquals(message, new Float(expected), new Float(actual)); - } - } - - static private boolean doubleIsDifferent(double d1, double d2, double delta) { - if (Double.compare(d1, d2) == 0) { - return false; - } - return (Math.abs(d1 - d2) > delta); - - } - - /** - * Asserts that two longs are equal. If they are not, an - * {@link AssertionError} is thrown. - * - * @param expected expected long value. - * @param actual actual long value - */ - static public void assertEquals(long expected, long actual) { - if (expected != actual) - assertEquals(null, expected, actual); - } - - /** - * Asserts that two longs are equal. If they are not, an - * {@link AssertionError} is thrown with the given message. - * - * @param message the identifying message for the {@link AssertionError} (null - * okay) - * @param expected long expected value. - * @param actual long actual value - */ - static public void assertEquals(String message, long expected, long actual) { - assertEquals(message, (Long) expected, (Long) actual); - } - - /** - * @deprecated Use - * assertEquals(double expected, double actual, double delta) - * instead - */ - @Deprecated(/* to be removed in x.22 */) -static public void assertEquals(double expected, double actual) { - assertEquals(null, expected, actual); - } - - /** - * @deprecated Use - * assertEquals(String message, double expected, double actual, double delta) - * instead - */ - @Deprecated(/* to be removed in x.22 */) -static public void assertEquals(String message, double expected, - double actual) { - fail("Use assertEquals(expected, actual, delta) to compare floating-point numbers"); - } - - /** - * Asserts that two doubles are equal to within a positive delta. - * If they are not, an {@link AssertionError} is thrown. If the expected - * value is infinity then the delta value is ignored.NaNs are considered - * equal: assertEquals(Double.NaN, Double.NaN, *) passes - * - * @param expected expected value - * @param actual the value to check against expected - * @param delta the maximum delta between expected and - * actual for which both numbers are still - * considered equal. - */ - static public void assertEquals(double expected, double actual, double delta) { - assertEquals(null, expected, actual, delta); - } - - /** - * Asserts that two floats are equal to within a positive delta. - * If they are not, an {@link AssertionError} is thrown. If the expected - * value is infinity then the delta value is ignored. NaNs are considered - * equal: assertEquals(Float.NaN, Float.NaN, *) passes - * - * @param expected expected value - * @param actual the value to check against expected - * @param delta the maximum delta between expected and - * actual for which both numbers are still - * considered equal. - */ - static public void assertEquals(float expected, float actual, float delta) { - assertEquals(null, expected, actual, delta); - } - - /** - * Asserts that an object isn't null. If it is an {@link AssertionError} is - * thrown with the given message. - * - * @param message the identifying message for the {@link AssertionError} (null - * okay) - * @param object Object to check or null - */ - static public void assertNotNull(String message, Object object) { - assertTrue(message, object != null); - } - - /** - * Asserts that an object isn't null. If it is an {@link AssertionError} is - * thrown. - * - * @param object Object to check or null - */ - static public void assertNotNull(Object object) { - assertNotNull(null, object); - } - - /** - * Asserts that an object is null. If it is not, an {@link AssertionError} - * is thrown with the given message. - * - * @param message the identifying message for the {@link AssertionError} (null - * okay) - * @param object Object to check or null - */ - static public void assertNull(String message, Object object) { - if (object == null) { - return; - } - failNotNull(message, object); - } - - /** - * Asserts that an object is null. If it isn't an {@link AssertionError} is - * thrown. - * - * @param object Object to check or null - */ - static public void assertNull(Object object) { - assertNull(null, object); - } - - static private void failNotNull(String message, Object actual) { - String formatted = ""; - if (message != null) { - formatted = message + " "; - } - fail(formatted + "expected null, but was:<" + actual + ">"); - } - - /** - * Asserts that two objects refer to the same object. If they are not, an - * {@link AssertionError} is thrown with the given message. - * - * @param message the identifying message for the {@link AssertionError} (null - * okay) - * @param expected the expected object - * @param actual the object to compare to expected - */ - static public void assertSame(String message, Object expected, Object actual) { - if (expected == actual) { - return; - } - failNotSame(message, expected, actual); - } - - /** - * Asserts that two objects refer to the same object. If they are not the - * same, an {@link AssertionError} without a message is thrown. - * - * @param expected the expected object - * @param actual the object to compare to expected - */ - static public void assertSame(Object expected, Object actual) { - assertSame(null, expected, actual); - } - - /** - * Asserts that two objects do not refer to the same object. If they do - * refer to the same object, an {@link AssertionError} is thrown with the - * given message. - * - * @param message the identifying message for the {@link AssertionError} (null - * okay) - * @param unexpected the object you don't expect - * @param actual the object to compare to unexpected - */ - static public void assertNotSame(String message, Object unexpected, - Object actual) { - if (unexpected == actual) { - failSame(message); - } - } - - /** - * Asserts that two objects do not refer to the same object. If they do - * refer to the same object, an {@link AssertionError} without a message is - * thrown. - * - * @param unexpected the object you don't expect - * @param actual the object to compare to unexpected - */ - static public void assertNotSame(Object unexpected, Object actual) { - assertNotSame(null, unexpected, actual); - } - - static private void failSame(String message) { - String formatted = ""; - if (message != null) { - formatted = message + " "; - } - fail(formatted + "expected not same"); - } - - static private void failNotSame(String message, Object expected, - Object actual) { - String formatted = ""; - if (message != null) { - formatted = message + " "; - } - fail(formatted + "expected same:<" + expected + "> was not:<" + actual - + ">"); - } - - static private void failNotEquals(String message, Object expected, - Object actual) { - fail(format(message, expected, actual)); - } - - static String format(String message, Object expected, Object actual) { - String formatted = ""; - if (message != null && !message.equals("")) { - formatted = message + " "; - } - String expectedString = String.valueOf(expected); - String actualString = String.valueOf(actual); - if (expectedString.equals(actualString)) { - return formatted + "expected: " - + formatClassAndValue(expected, expectedString) - + " but was: " + formatClassAndValue(actual, actualString); - - } else { - return formatted + "expected:<" + expectedString + "> but was:<" - + actualString + ">"; - } - } - - private static String formatClassAndValue(Object value, String valueString) { - String className = value == null ? "null" : value.getClass().getName(); - return className + "<" + valueString + ">"; - } - - /** - * Asserts that two object arrays are equal. If they are not, an - * {@link AssertionError} is thrown with the given message. If - * expecteds and actuals are null, - * they are considered equal. - * - * @param message the identifying message for the {@link AssertionError} (null - * okay) - * @param expecteds Object array or array of arrays (multi-dimensional array) with - * expected values. - * @param actuals Object array or array of arrays (multi-dimensional array) with - * actual values - * @deprecated use assertArrayEquals - */ - @Deprecated(/* to be removed in x.22 */) -public static void assertEquals(String message, Object[] expecteds, - Object[] actuals) { - assertArrayEquals(message, expecteds, actuals); - } - - /** - * Asserts that two object arrays are equal. If they are not, an - * {@link AssertionError} is thrown. If expected and - * actual are null, they are considered - * equal. - * - * @param expecteds Object array or array of arrays (multi-dimensional array) with - * expected values - * @param actuals Object array or array of arrays (multi-dimensional array) with - * actual values - * @deprecated use assertArrayEquals - */ - @Deprecated(/* to be removed in x.22 */) -public static void assertEquals(Object[] expecteds, Object[] actuals) { - assertArrayEquals(expecteds, actuals); - } - - /** - * Asserts that actual satisfies the condition specified by - * matcher. If not, an {@link AssertionError} is thrown with - * information about the matcher and failing value. Example: - *

    - *

    -     *   assertThat(0, is(1)); // fails:
    -     *     // failure message:
    -     *     // expected: is <1>
    -     *     // got value: <0>
    -     *   assertThat(0, is(not(1))) // passes
    -     * 
    - *

    - * org.hamcrest.Matcher does not currently document the meaning - * of its type parameter T. This method assumes that a matcher - * typed as Matcher<T> can be meaningfully applied only - * to values that could be assigned to a variable of type T. - * - * @param the static type accepted by the matcher (this can flag obvious - * compile-time problems such as {@code assertThat(1, is("a"))} - * @param actual the computed value being compared - * @param matcher an expression, built of {@link Matcher}s, specifying allowed - * values - * @see org.hamcrest.CoreMatchers - * @see org.hamcrest.MatcherAssert - */ - public static void assertThat(T actual, Matcher matcher) { - assertThat("", actual, matcher); - } - - /** - * Asserts that actual satisfies the condition specified by - * matcher. If not, an {@link AssertionError} is thrown with - * the reason and information about the matcher and failing value. Example: - *

    - *

    -     *   assertThat("Help! Integers don't work", 0, is(1)); // fails:
    -     *     // failure message:
    -     *     // Help! Integers don't work
    -     *     // expected: is <1>
    -     *     // got value: <0>
    -     *   assertThat("Zero is one", 0, is(not(1))) // passes
    -     * 
    - *

    - * org.hamcrest.Matcher does not currently document the meaning - * of its type parameter T. This method assumes that a matcher - * typed as Matcher<T> can be meaningfully applied only - * to values that could be assigned to a variable of type T. - * - * @param reason additional information about the error - * @param the static type accepted by the matcher (this can flag obvious - * compile-time problems such as {@code assertThat(1, is("a"))} - * @param actual the computed value being compared - * @param matcher an expression, built of {@link Matcher}s, specifying allowed - * values - * @see org.hamcrest.CoreMatchers - * @see org.hamcrest.MatcherAssert - */ - public static void assertThat(String reason, T actual, - Matcher matcher) { - MatcherAssert.assertThat(reason, actual, matcher); - } -} From 73529b073c65d4862f561b3895e91093f4d968ed Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Tue, 22 Jun 2021 09:07:57 +0200 Subject: [PATCH 149/353] Updating to bom version 2.21ea178 From 1330882333bf30b5c89735b5ee4603fccc678cb6 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Tue, 22 Jun 2021 09:08:16 +0200 Subject: [PATCH 150/353] [maven-release-plugin] prepare release Java-Thread-Affinity-3.21ea5 --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index b613673ec..ba668bf6b 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.21ea5-SNAPSHOT + 3.21ea5 bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:https://github.com/OpenHFT/Java-Thread-Affinity.git - HEAD + Java-Thread-Affinity-3.21ea5 diff --git a/affinity/pom.xml b/affinity/pom.xml index b6e3e8d3f..d7381e9a2 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.21ea5-SNAPSHOT + 3.21ea5 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -225,7 +225,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.21ea5 diff --git a/pom.xml b/pom.xml index 09de56907..a17e342ef 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.21ea5-SNAPSHOT + 3.21ea5 pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.21ea5 From 065840da1f5d4b6942fedd3150eb23251c0443d0 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Tue, 22 Jun 2021 09:08:22 +0200 Subject: [PATCH 151/353] [maven-release-plugin] prepare for next development iteration --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index ba668bf6b..e9596bcce 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.21ea5 + 3.21ea6-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:https://github.com/OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.21ea5 + HEAD diff --git a/affinity/pom.xml b/affinity/pom.xml index d7381e9a2..0b6dc4803 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.21ea5 + 3.21ea6-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity @@ -225,7 +225,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.21ea5 + ea diff --git a/pom.xml b/pom.xml index a17e342ef..b8118a6dd 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.21ea5 + 3.21ea6-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.21ea5 + ea From 761dd09735412afe14fe139c68a099d584511edc Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Tue, 22 Jun 2021 09:08:41 +0200 Subject: [PATCH 152/353] Reverting back to bom version 2.21ea-SNAPSHOT From 71915d19769a23e410d530035f1e7d3def41cf4c Mon Sep 17 00:00:00 2001 From: Jerry Shea Date: Wed, 23 Jun 2021 15:05:13 +1000 Subject: [PATCH 153/353] latest parent and third-party pom/bom --- affinity/pom.xml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index 0b6dc4803..6ed2f25b3 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.1.23 + 1.1.26 @@ -43,7 +43,7 @@ net.openhft third-party-bom pom - 3.19.4 + 3.19.9 import @@ -108,7 +108,6 @@ org.codehaus.mojo exec-maven-plugin - 1.2.1 From 66cd3002e9d86bf2f6d193c10d2d8614bdc77353 Mon Sep 17 00:00:00 2001 From: Jerry Shea Date: Thu, 24 Jun 2021 10:06:33 +1000 Subject: [PATCH 154/353] latest third-party-pom --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index e9596bcce..f13eedf8b 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.1.23 + 1.1.26 @@ -42,7 +42,7 @@ net.openhft third-party-bom pom - 3.19.4 + 3.19.10 import diff --git a/affinity/pom.xml b/affinity/pom.xml index 6ed2f25b3..2f47ba9b1 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -43,7 +43,7 @@ net.openhft third-party-bom pom - 3.19.9 + 3.19.10 import From 5f30051f6345ca71a900fb67f2608b73a8d75f42 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Mon, 28 Jun 2021 12:49:39 +0100 Subject: [PATCH 155/353] Use Jvm.{level}() handlers instead of calling loggers directly, and unit tests cleanup esp use of @After, https://github.com/OpenHFT/Chronicle-Core/issues/233 --- affinity/src/main/java/net/openhft/affinity/Affinity.java | 3 +-- affinity/src/main/java/net/openhft/affinity/LockCheck.java | 3 +-- .../src/main/java/net/openhft/affinity/impl/LinuxHelper.java | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/affinity/src/main/java/net/openhft/affinity/Affinity.java b/affinity/src/main/java/net/openhft/affinity/Affinity.java index ef31c61ee..bf185147c 100644 --- a/affinity/src/main/java/net/openhft/affinity/Affinity.java +++ b/affinity/src/main/java/net/openhft/affinity/Affinity.java @@ -33,8 +33,7 @@ * * @author peter.lawrey */ -public enum Affinity { - ; +public enum Affinity {; static final Logger LOGGER = LoggerFactory.getLogger(Affinity.class); @NotNull private static final IAffinity AFFINITY_IMPL; diff --git a/affinity/src/main/java/net/openhft/affinity/LockCheck.java b/affinity/src/main/java/net/openhft/affinity/LockCheck.java index 2fe67ad8c..3a3551b6d 100644 --- a/affinity/src/main/java/net/openhft/affinity/LockCheck.java +++ b/affinity/src/main/java/net/openhft/affinity/LockCheck.java @@ -28,8 +28,7 @@ /** * @author Rob Austin. */ -enum LockCheck { - ; +enum LockCheck {; private static final Logger LOGGER = LoggerFactory.getLogger(LockCheck.class); private static final String OS = System.getProperty("os.name").toLowerCase(); diff --git a/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java b/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java index 459e474f0..3b4d301de 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java @@ -41,7 +41,7 @@ public class LinuxHelper { ver = new VersionHelper(uname.getRealeaseVersion()); } } catch (Throwable e) { - //logger.warn("Failed to determine Linux version: " + e); + //Jvm.warn().on(getClass(), "Failed to determine Linux version: " + e); } version = ver; From 3f2faf1ed2c1d2e41a17c064e2ddac570e1b48fc Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Mon, 28 Jun 2021 16:19:20 +0100 Subject: [PATCH 156/353] Release of all main libraries to x.21.80, https://github.com/OpenHFT/OpenHFT/issues/55 --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index f13eedf8b..318f5defc 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.21ea6-SNAPSHOT + 3.21ea80-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test diff --git a/affinity/pom.xml b/affinity/pom.xml index 2f47ba9b1..24b19a7a5 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.21ea6-SNAPSHOT + 3.21ea80-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity diff --git a/pom.xml b/pom.xml index b8118a6dd..c90304bc4 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.21ea6-SNAPSHOT + 3.21ea80-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent From e7f871325f8b46c438b2f9cf5338a442b6b69b35 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Tue, 29 Jun 2021 09:16:03 +0100 Subject: [PATCH 157/353] Reduce redundant newlines --- affinity/src/main/java/net/openhft/affinity/Affinity.java | 3 ++- affinity/src/main/java/net/openhft/affinity/LockCheck.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/affinity/src/main/java/net/openhft/affinity/Affinity.java b/affinity/src/main/java/net/openhft/affinity/Affinity.java index bf185147c..83986b2bc 100644 --- a/affinity/src/main/java/net/openhft/affinity/Affinity.java +++ b/affinity/src/main/java/net/openhft/affinity/Affinity.java @@ -33,7 +33,8 @@ * * @author peter.lawrey */ -public enum Affinity {; +public enum Affinity { + ; // none static final Logger LOGGER = LoggerFactory.getLogger(Affinity.class); @NotNull private static final IAffinity AFFINITY_IMPL; diff --git a/affinity/src/main/java/net/openhft/affinity/LockCheck.java b/affinity/src/main/java/net/openhft/affinity/LockCheck.java index 3a3551b6d..cfe4e78f6 100644 --- a/affinity/src/main/java/net/openhft/affinity/LockCheck.java +++ b/affinity/src/main/java/net/openhft/affinity/LockCheck.java @@ -28,7 +28,8 @@ /** * @author Rob Austin. */ -enum LockCheck {; +enum LockCheck { + ; // none private static final Logger LOGGER = LoggerFactory.getLogger(LockCheck.class); private static final String OS = System.getProperty("os.name").toLowerCase(); From 9d9483e27d9443eb5dcee7c25e90e1e47fd22f4b Mon Sep 17 00:00:00 2001 From: Peter K Lawrey Date: Tue, 27 Jul 2021 11:39:26 +0100 Subject: [PATCH 158/353] Update MicroJitterSampler.java --- .../java/net/openhft/affinity/MicroJitterSampler.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java b/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java index dc4ac4a91..6dc025cbf 100644 --- a/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java +++ b/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java @@ -20,6 +20,15 @@ import java.io.PrintStream; /* e.g. +Ubuntu 20.04, Ryzen 5950X with an isolated CPU. (init 3) +After 360 seconds, the average per hour was +2us 35600 +3us 22230 +4us 390 +10us 10 +20us 10 +30us 10 + Windows 10 i7-4770 laptop After 1845 seconds, the average per hour was 2us 2435969 From 70bcc79a33e763338847bbca8188a5f028cb629d Mon Sep 17 00:00:00 2001 From: Peter K Lawrey Date: Tue, 27 Jul 2021 11:53:53 +0100 Subject: [PATCH 159/353] Update MicroJitterSampler.java --- .../java/net/openhft/affinity/MicroJitterSampler.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java b/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java index 6dc025cbf..f22d3efdf 100644 --- a/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java +++ b/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java @@ -20,11 +20,11 @@ import java.io.PrintStream; /* e.g. -Ubuntu 20.04, Ryzen 5950X with an isolated CPU. (init 3) +Ubuntu 20.04, Ryzen 5950X with an isolated CPU. (init 3) sudo cpupower -c {cpu} -g performance After 360 seconds, the average per hour was -2us 35600 -3us 22230 -4us 390 +2us 1566 +3us 526 +4us 80 10us 10 20us 10 30us 10 From 6994fc4a95ade566b8e22fd9ed34e36f0f49fdf3 Mon Sep 17 00:00:00 2001 From: Peter K Lawrey Date: Tue, 27 Jul 2021 14:21:27 +0100 Subject: [PATCH 160/353] Update MicroJitterSampler.java --- .../openhft/affinity/MicroJitterSampler.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java b/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java index f22d3efdf..c7418c53b 100644 --- a/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java +++ b/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java @@ -21,13 +21,16 @@ import java.io.PrintStream; /* e.g. Ubuntu 20.04, Ryzen 5950X with an isolated CPU. (init 3) sudo cpupower -c {cpu} -g performance -After 360 seconds, the average per hour was -2us 1566 -3us 526 -4us 80 -10us 10 -20us 10 -30us 10 +After 3600 seconds, the average per hour was +2us 2571 +3us 2304 +4us 376 +6us 1 +10us 1 +20us 1 +30us 1 +40us 2 +60us 1 Windows 10 i7-4770 laptop After 1845 seconds, the average per hour was From dd26283aad8ff73e7d4ce370a79e01cf506c0646 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Tue, 3 Aug 2021 09:15:19 +0100 Subject: [PATCH 161/353] Added results for a new Ryzen 5950X --- .../openhft/affinity/MicroJitterSampler.java | 141 +++++++++++------- 1 file changed, 83 insertions(+), 58 deletions(-) diff --git a/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java b/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java index c7418c53b..c79e5b1e2 100644 --- a/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java +++ b/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java @@ -19,64 +19,6 @@ package net.openhft.affinity; import java.io.PrintStream; -/* e.g. -Ubuntu 20.04, Ryzen 5950X with an isolated CPU. (init 3) sudo cpupower -c {cpu} -g performance -After 3600 seconds, the average per hour was -2us 2571 -3us 2304 -4us 376 -6us 1 -10us 1 -20us 1 -30us 1 -40us 2 -60us 1 - -Windows 10 i7-4770 laptop -After 1845 seconds, the average per hour was -2us 2435969 -3us 548812 -4us 508041 -6us 60320 -8us 25374 -10us 1832324 -14us 2089216 -20us 391901 -30us 16063 -40us 6440 -60us 2617 -80us 1487 -100us 1241 -140us 826 -200us 2108 -300us 601 -400us 159 -600us 129 -800us 215 -1ms 155 -2ms 229 -5ms 24 -10ms 38 -20ms 32 - -On an Centos 7 machine with an isolated CPU. -After 2145 seconds, the average per hour was -2us 781271 -3us 1212123 -4us 13504 -6us 489 -8us 2 -10us 3032577 -14us 17475 -20us 628 -30us 645 -40us 1301 -60us 1217 -80us 1306 -100us 1526 -140us 22 - - */ /** * User: peter.lawrey Date: 30/06/13 Time: 13:13 @@ -166,3 +108,86 @@ void print(PrintStream ps) { ps.println(); } } + +/* e.g. +Ubuntu 20.04, Ryzen 5950X with an isolated CPU. (init 3) sudo cpupower -c {cpu} -g performance, run from command line +After 3600 seconds, the average per hour was +2us 2571 +3us 2304 +4us 376 +6us 1 +10us 1 +20us 1 +30us 1 +40us 2 +60us 1 + +Ubuntu 20.04, Ryzen 5950X with an isolated CPU. (init 5) sudo cpupower -c {cpu} -g performance, run from command line +After 3600 seconds, the average per hour was +2us 2157 +3us 3444 +4us 3654 +6us 135 +8us 4 +14us 1 +20us 1 +40us 2 +60us 1 + +Ubuntu 20.04, Ryzen 5950X with an isolated CPU. (init 5) sudo cpupower -c {cpu} -g performance, run from IntelliJ CE +After 7200 seconds, the average per hour was +2us 2189 +3us 3341 +4us 2335 +6us 191 +8us 4 +14us 1 +20us 1 + + + +Windows 10 i7-4770 laptop +After 1845 seconds, the average per hour was +2us 2435969 +3us 548812 +4us 508041 +6us 60320 +8us 25374 +10us 1832324 +14us 2089216 +20us 391901 +30us 16063 +40us 6440 +60us 2617 +80us 1487 +100us 1241 +140us 826 +200us 2108 +300us 601 +400us 159 +600us 129 +800us 215 +1ms 155 +2ms 229 +5ms 24 +10ms 38 +20ms 32 + +On an Centos 7 machine with an isolated CPU. +After 2145 seconds, the average per hour was +2us 781271 +3us 1212123 +4us 13504 +6us 489 +8us 2 +10us 3032577 +14us 17475 +20us 628 +30us 645 +40us 1301 +60us 1217 +80us 1306 +100us 1526 +140us 22 + + */ From 552cf8a53be6173a38a93361508178a928e092f9 Mon Sep 17 00:00:00 2001 From: rogersimmons Date: Mon, 9 Aug 2021 09:19:02 +0100 Subject: [PATCH 162/353] Split jitter test from main thread, and add explicit CPU binding option --- .../openhft/affinity/MicroJitterSampler.java | 63 +++++++++++++------ 1 file changed, 45 insertions(+), 18 deletions(-) diff --git a/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java b/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java index c79e5b1e2..fc9a84c49 100644 --- a/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java +++ b/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java @@ -34,8 +34,8 @@ public class MicroJitterSampler { }; private static final double UTIL = Double.parseDouble(System.getProperty("util", "50")); private static final boolean BUSYWAIT = Boolean.parseBoolean(System.getProperty("busywait", "false")); + private static final int CPU = Integer.parseInt(System.getProperty("cpu", "-1")); - // static final int CPU = Integer.getInteger("cpu", 0); private final int[] count = new int[DELAY.length]; private long totalTime = 0; @@ -50,25 +50,46 @@ private static void pause() throws InterruptedException } public static void main(String... ignored) throws InterruptedException { - // AffinityLock al = AffinityLock.acquireLock(); - - // warmup. - new MicroJitterSampler().sample(1000 * 1000 * 1000); - - MicroJitterSampler microJitterSampler = new MicroJitterSampler(); - while (!Thread.currentThread().isInterrupted()) { - if (UTIL >= 100) { - microJitterSampler.sample(30L * 1000 * 1000 * 1000); - } else { - long sampleLength = (long) ((1 / (1 - UTIL / 100) - 1) * 1000 * 1000); - for (int i = 0; i < 30 * 1000; i += 2) { - microJitterSampler.sample(sampleLength); - //noinspection BusyWait - pause(); - } + MicroJitterSampler sampler = new MicroJitterSampler(); + + Thread t = new Thread( sampler::run ); + t.start(); + t.join(); + } + + private void once() throws InterruptedException { + if (UTIL >= 100) { + sample(30L * 1000 * 1000 * 1000); + } else { + long sampleLength = (long) ((1 / (1 - UTIL / 100) - 1) * 1000 * 1000); + for (int i = 0; i < 30 * 1000; i += 2) { + sample(sampleLength); + //noinspection BusyWait + pause(); } + } + } + + public void run() { + if(CPU != -1) + Affinity.setAffinity(CPU); + + try { + boolean first = true; + System.out.println("Warming up..."); + while (!Thread.currentThread().isInterrupted()) { + once(); + + if(first) { + reset(); + first = false; + System.out.println("Warmup complete. Running jitter tests..."); + continue; + } - microJitterSampler.print(System.out); + print(System.out); + } + } catch(InterruptedException e) { } } @@ -79,6 +100,12 @@ private static String asString(long timeNS) { timeNS / 1000000000 + "sec"; } + void reset() { + for(int i=0; i Date: Tue, 7 Sep 2021 12:21:47 +0100 Subject: [PATCH 163/353] Remove redundant newlines. --- .../src/main/java/net/openhft/affinity/MicroJitterSampler.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java b/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java index fc9a84c49..05d0c344c 100644 --- a/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java +++ b/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java @@ -171,8 +171,6 @@ void print(PrintStream ps) { 14us 1 20us 1 - - Windows 10 i7-4770 laptop After 1845 seconds, the average per hour was 2us 2435969 From b2292655085dd3915fffbfe9c36ffc9b7cabf8fd Mon Sep 17 00:00:00 2001 From: Peter Lawrwy Date: Wed, 22 Sep 2021 16:24:20 +0100 Subject: [PATCH 164/353] Use off-heap rather than a ByteBuffer in this test. --- affinity/src/main/c/Makefile | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 affinity/src/main/c/Makefile diff --git a/affinity/src/main/c/Makefile b/affinity/src/main/c/Makefile old mode 100755 new mode 100644 From d35a426932aaafbae2fb1e1ca39e0e1a2ecf5bdb Mon Sep 17 00:00:00 2001 From: Nick Tindall Date: Sun, 17 Oct 2021 21:49:34 +1100 Subject: [PATCH 165/353] Fix getMetaInfo when another process holds the lock, Fixes #79 --- .../affinity/common/ProcessRunner.java | 113 ++++++++++++++++++ .../lockchecker/FileLockBasedLockChecker.java | 16 ++- .../affinity/MultiProcessAffinityTest.java | 59 +++++++++ 3 files changed, 183 insertions(+), 5 deletions(-) create mode 100644 affinity/src/main/java/net/openhft/affinity/common/ProcessRunner.java create mode 100644 affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java diff --git a/affinity/src/main/java/net/openhft/affinity/common/ProcessRunner.java b/affinity/src/main/java/net/openhft/affinity/common/ProcessRunner.java new file mode 100644 index 000000000..a3d7522e1 --- /dev/null +++ b/affinity/src/main/java/net/openhft/affinity/common/ProcessRunner.java @@ -0,0 +1,113 @@ +package net.openhft.affinity.common; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.lang.management.ManagementFactory; +import java.lang.management.RuntimeMXBean; +import java.nio.charset.Charset; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +public class ProcessRunner { + + private static final Logger LOGGER = LoggerFactory.getLogger(ProcessRunner.class); + + /** + * Spawn a process running the main method of a specified class + * + * @param clazz The class to execute + * @param args Any arguments to pass to the process + * @return the Process spawned + * @throws IOException if there is an error starting the process + */ + public static Process runClass(Class clazz, String... args) throws IOException { + // Because Java17 must be run using various module flags, these must be propagated + // to the child processes + // https://stackoverflow.com/questions/1490869/how-to-get-vm-arguments-from-inside-of-java-application + final RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean(); + + // filter out javaagent params, or this confuses the IntelliJ debugger + final List jvmArgsWithoutJavaAgents = runtimeMxBean.getInputArguments().stream() + .filter(arg -> !arg.startsWith("-javaagent:")) + .filter(arg -> !arg.startsWith("-agentlib:")) + .collect(Collectors.toList()); + + String classPath = System.getProperty("java.class.path"); + String className = clazz.getName(); + String javaBin = findJavaBinPath().toString(); + List allArgs = new ArrayList<>(); + allArgs.add(javaBin); + allArgs.addAll(jvmArgsWithoutJavaAgents); + allArgs.add("-cp"); + allArgs.add(classPath); + allArgs.add(className); + allArgs.addAll(Arrays.asList(args)); + ProcessBuilder processBuilder = new ProcessBuilder(allArgs.toArray(new String[]{})); +// processBuilder.inheritIO(); // this doesn't place nice with surefire + return processBuilder.start(); + } + + /** + * Log stdout and stderr for a process + *

    + * ProcessBuilder.inheritIO() didn't play nicely with Maven failsafe plugin + *

    + * https://maven.apache.org/surefire/maven-failsafe-plugin/faq.html#corruptedstream + */ + public static void printProcessOutput(String processName, Process process) { + LOGGER.info("\n" + + "Output for " + processName + "\n" + + "stdout:\n" + + copyStreamToString(process.getInputStream()) + "\n" + + "stderr:\n" + + copyStreamToString(process.getErrorStream())); + } + + /** + * Copies a stream to a string, up to the point where reading more would block + * + * @param inputStream The stream to read from + * @return The output as a string + */ + private static String copyStreamToString(InputStream inputStream) { + ByteArrayOutputStream os = new ByteArrayOutputStream(); + byte[] buffer = new byte[1024]; + int read; + try { + while (inputStream.available() > 0 && (read = inputStream.read(buffer)) >= 0) { + os.write(buffer, 0, read); + } + } catch (IOException e) { + // Ignore + } + return new String(os.toByteArray(), Charset.defaultCharset()); + } + + /** + * Try and work out what the java executable is cross platform + * + * @return the Path to the java executable + * @throws IllegalStateException if the executable couldn't be located + */ + private static Path findJavaBinPath() { + final Path javaBinPath = Paths.get(System.getProperty("java.home")).resolve("bin"); + final Path linuxJavaExecutable = javaBinPath.resolve("java"); + if (linuxJavaExecutable.toFile().exists()) { + return linuxJavaExecutable; + } else { + Path windowsJavaExecutable = javaBinPath.resolve("java.exe"); + if (windowsJavaExecutable.toFile().exists()) { + return windowsJavaExecutable; + } + } + throw new IllegalStateException("Couldn't locate java executable!"); + } +} diff --git a/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java b/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java index c27a65bf9..10f2a2203 100644 --- a/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java +++ b/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java @@ -134,15 +134,21 @@ public String getMetaInfo(int id) throws IOException { } LockReference lr = locks[id]; - if (lr == null) { - return null; + if (lr != null) { + return readMetaInfoFromLockFileChannel(file, lr.channel); + } else { + try (FileChannel fc = FileChannel.open(file.toPath(), READ)) { + return readMetaInfoFromLockFileChannel(file, fc); + } } - FileChannel fc = lr.channel; + } + + private String readMetaInfoFromLockFileChannel(File lockFile, FileChannel lockFileChannel) throws IOException { ByteBuffer buffer = ByteBuffer.allocate(64); - int len = fc.read(buffer, 0); + int len = lockFileChannel.read(buffer, 0); String content = len < 1 ? "" : new String(buffer.array(), 0, len); if (content.isEmpty()) { - LOGGER.warn("Empty lock file {}", file.getAbsolutePath()); + LOGGER.warn("Empty lock file {}", lockFile.getAbsolutePath()); return null; } return content.substring(0, content.indexOf("\n")); diff --git a/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java b/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java new file mode 100644 index 000000000..bf1516e96 --- /dev/null +++ b/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java @@ -0,0 +1,59 @@ +package net.openhft.affinity; + +import net.openhft.affinity.common.ProcessRunner; +import net.openhft.affinity.lockchecker.FileLockBasedLockChecker; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.concurrent.TimeUnit; + +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.fail; + +public class MultiProcessAffinityTest { + + @Test + public void shouldNotAcquireLockOnCoresLockedByOtherProcesses() throws IOException, InterruptedException { + // run the separate affinity locker + final Process last = ProcessRunner.runClass(AffinityLockerProcess.class, "last"); + try { + int lastCpuId = AffinityLock.PROCESSORS - 1; + + // wait for the CPU to be locked + long endTime = System.currentTimeMillis() + 5_000; + while (FileLockBasedLockChecker.getInstance().isLockFree(lastCpuId)) { + Thread.sleep(100); + if (System.currentTimeMillis() > endTime) { + fail("Timed out waiting for the sub-process to acquire the lock"); + } + } + + try (AffinityLock lock = AffinityLock.acquireLock("last")) { + assertNotEquals(lastCpuId, lock.cpuId()); + } + } finally { + last.destroy(); + if (!last.waitFor(5, TimeUnit.SECONDS)) { + fail("Sub-process didn't terminate!"); + } + } + } + + static class AffinityLockerProcess { + + private static final Logger LOGGER = LoggerFactory.getLogger(AffinityLockerProcess.class); + + public static void main(String[] args) { + String cpuIdToLock = args[0]; + + try (final AffinityLock affinityLock = AffinityLock.acquireLock(cpuIdToLock)) { + LOGGER.info("Got affinity lock " + affinityLock); + Thread.sleep(Integer.MAX_VALUE); + } catch (InterruptedException e) { + // expected, just end + } + } + } +} From ce6fb637d41e8f77366a1c31dec8fc37e9e50437 Mon Sep 17 00:00:00 2001 From: Nick Tindall Date: Mon, 18 Oct 2021 09:37:44 +1100 Subject: [PATCH 166/353] Disable test for non-linux builds --- .../java/net/openhft/affinity/MultiProcessAffinityTest.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java b/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java index bf1516e96..81cb52009 100644 --- a/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java +++ b/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java @@ -2,6 +2,7 @@ import net.openhft.affinity.common.ProcessRunner; import net.openhft.affinity.lockchecker.FileLockBasedLockChecker; +import org.junit.Assume; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -9,6 +10,7 @@ import java.io.IOException; import java.util.concurrent.TimeUnit; +import static net.openhft.affinity.LockCheck.IS_LINUX; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.fail; @@ -16,6 +18,7 @@ public class MultiProcessAffinityTest { @Test public void shouldNotAcquireLockOnCoresLockedByOtherProcesses() throws IOException, InterruptedException { + Assume.assumeTrue(IS_LINUX); // run the separate affinity locker final Process last = ProcessRunner.runClass(AffinityLockerProcess.class, "last"); try { From 255bc4dbecedfea863e4f9ba1e93653b0cdad13f Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Mon, 18 Oct 2021 14:49:13 +0200 Subject: [PATCH 167/353] Updating to bom version 2.22ea38 From f70e211425a3e9be66239a58f0ffe808a59a839b Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Mon, 18 Oct 2021 14:49:58 +0200 Subject: [PATCH 168/353] [maven-release-plugin] prepare release Java-Thread-Affinity-3.21ea80 --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 318f5defc..21cff5d9d 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.21ea80-SNAPSHOT + 3.21ea80 bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:https://github.com/OpenHFT/Java-Thread-Affinity.git - HEAD + Java-Thread-Affinity-3.21ea80 diff --git a/affinity/pom.xml b/affinity/pom.xml index 24b19a7a5..095d41d4f 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.21ea80-SNAPSHOT + 3.21ea80 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -224,7 +224,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.21ea80 diff --git a/pom.xml b/pom.xml index c90304bc4..ecba1f972 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.21ea80-SNAPSHOT + 3.21ea80 pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.21ea80 From e5b9177d4bcf3a3c973c9782c3fbfaeb3e4ac0de Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Mon, 18 Oct 2021 14:50:02 +0200 Subject: [PATCH 169/353] [maven-release-plugin] prepare for next development iteration --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 21cff5d9d..90d16a5a2 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.21ea80 + 3.21ea81-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:https://github.com/OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.21ea80 + HEAD diff --git a/affinity/pom.xml b/affinity/pom.xml index 095d41d4f..873b8789e 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.21ea80 + 3.21ea81-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity @@ -224,7 +224,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.21ea80 + ea diff --git a/pom.xml b/pom.xml index ecba1f972..7abbfc40a 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.21ea80 + 3.21ea81-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.21ea80 + ea From cd1cc3f15fe78e2b2d0f48ddddc1a0ea557761b5 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Mon, 18 Oct 2021 14:50:24 +0200 Subject: [PATCH 170/353] Reverting back to bom version 2.22ea-SNAPSHOT From a57cc41d3f71b860a1316f9bd271602c4ed98633 Mon Sep 17 00:00:00 2001 From: Nick Tindall Date: Tue, 19 Oct 2021 11:24:31 +1100 Subject: [PATCH 171/353] MultiProcessAffinityTest: Print sub-process output when it fails to acquire the lock --- .../net/openhft/affinity/MultiProcessAffinityTest.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java b/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java index 81cb52009..230dfd9eb 100644 --- a/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java +++ b/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java @@ -20,7 +20,7 @@ public class MultiProcessAffinityTest { public void shouldNotAcquireLockOnCoresLockedByOtherProcesses() throws IOException, InterruptedException { Assume.assumeTrue(IS_LINUX); // run the separate affinity locker - final Process last = ProcessRunner.runClass(AffinityLockerProcess.class, "last"); + final Process affinityLockerProcess = ProcessRunner.runClass(AffinityLockerProcess.class, "last"); try { int lastCpuId = AffinityLock.PROCESSORS - 1; @@ -29,6 +29,7 @@ public void shouldNotAcquireLockOnCoresLockedByOtherProcesses() throws IOExcepti while (FileLockBasedLockChecker.getInstance().isLockFree(lastCpuId)) { Thread.sleep(100); if (System.currentTimeMillis() > endTime) { + ProcessRunner.printProcessOutput("AffinityLockerProcess", affinityLockerProcess); fail("Timed out waiting for the sub-process to acquire the lock"); } } @@ -37,8 +38,8 @@ public void shouldNotAcquireLockOnCoresLockedByOtherProcesses() throws IOExcepti assertNotEquals(lastCpuId, lock.cpuId()); } } finally { - last.destroy(); - if (!last.waitFor(5, TimeUnit.SECONDS)) { + affinityLockerProcess.destroy(); + if (!affinityLockerProcess.waitFor(5, TimeUnit.SECONDS)) { fail("Sub-process didn't terminate!"); } } From 1af6529dd7f34d874f35458f41c5c847e4b756e9 Mon Sep 17 00:00:00 2001 From: Nick Tindall Date: Tue, 19 Oct 2021 17:34:46 +1100 Subject: [PATCH 172/353] Manage java.io.tmpdir better to make multi-process test pass reliably, move ProcessRunner into tests where it belongs --- .../affinity/FileLockLockCheckTest.java | 10 ++++---- .../net/openhft/affinity/LockCheckTest.java | 10 ++++---- .../affinity/MultiProcessAffinityTest.java | 23 ++++++++++++++++--- .../affinity/common/ProcessRunner.java | 16 ++++++++++++- 4 files changed, 47 insertions(+), 12 deletions(-) rename affinity/src/{main => test}/java/net/openhft/affinity/common/ProcessRunner.java (87%) diff --git a/affinity/src/test/java/net/openhft/affinity/FileLockLockCheckTest.java b/affinity/src/test/java/net/openhft/affinity/FileLockLockCheckTest.java index e59d0a805..1a41b2e47 100644 --- a/affinity/src/test/java/net/openhft/affinity/FileLockLockCheckTest.java +++ b/affinity/src/test/java/net/openhft/affinity/FileLockLockCheckTest.java @@ -18,10 +18,7 @@ package net.openhft.affinity; import net.openhft.affinity.testimpl.TestFileLockBasedLockChecker; -import org.junit.Assert; -import org.junit.Assume; -import org.junit.Before; -import org.junit.Test; +import org.junit.*; import java.io.File; import java.io.IOException; @@ -54,6 +51,11 @@ public void before() { System.setProperty("java.io.tmpdir", TARGET + "/" + System.nanoTime()); } + @After + public void after() { + System.setProperty("java.io.tmpdir", TMP); + } + @Test public void test() throws IOException { Assert.assertTrue(LockCheck.isCpuFree(cpu)); diff --git a/affinity/src/test/java/net/openhft/affinity/LockCheckTest.java b/affinity/src/test/java/net/openhft/affinity/LockCheckTest.java index 55cd8f7a6..595269bb7 100644 --- a/affinity/src/test/java/net/openhft/affinity/LockCheckTest.java +++ b/affinity/src/test/java/net/openhft/affinity/LockCheckTest.java @@ -18,10 +18,7 @@ package net.openhft.affinity; import net.openhft.affinity.testimpl.TestFileBasedLockChecker; -import org.junit.Assert; -import org.junit.Assume; -import org.junit.Before; -import org.junit.Test; +import org.junit.*; import java.io.File; import java.io.FileWriter; @@ -55,6 +52,11 @@ public void before() { System.setProperty("java.io.tmpdir", TARGET + "/" + System.nanoTime()); } + @After + public void after() { + System.setProperty("java.io.tmpdir", TMP); + } + @Test public void test() throws IOException { Assert.assertTrue(LockCheck.isCpuFree(cpu)); diff --git a/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java b/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java index 230dfd9eb..a6c7dd8f8 100644 --- a/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java +++ b/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java @@ -2,8 +2,8 @@ import net.openhft.affinity.common.ProcessRunner; import net.openhft.affinity.lockchecker.FileLockBasedLockChecker; -import org.junit.Assume; -import org.junit.Test; +import org.junit.*; +import org.junit.rules.TemporaryFolder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -16,11 +16,28 @@ public class MultiProcessAffinityTest { + @Rule + public TemporaryFolder folder = new TemporaryFolder(); + private String originalTmpDir; + + @Before + public void setUp() { + originalTmpDir = System.getProperty("java.io.tmpdir"); + System.setProperty("java.io.tmpdir", folder.getRoot().getAbsolutePath()); + } + + @After + public void tearDown() { + System.setProperty("java.io.tmpdir", originalTmpDir); + } + @Test public void shouldNotAcquireLockOnCoresLockedByOtherProcesses() throws IOException, InterruptedException { Assume.assumeTrue(IS_LINUX); // run the separate affinity locker - final Process affinityLockerProcess = ProcessRunner.runClass(AffinityLockerProcess.class, "last"); + final Process affinityLockerProcess = ProcessRunner.runClass(AffinityLockerProcess.class, + new String[]{"-Djava.io.tmpdir=" + folder.getRoot().getAbsolutePath()}, + new String[]{"last"}); try { int lastCpuId = AffinityLock.PROCESSORS - 1; diff --git a/affinity/src/main/java/net/openhft/affinity/common/ProcessRunner.java b/affinity/src/test/java/net/openhft/affinity/common/ProcessRunner.java similarity index 87% rename from affinity/src/main/java/net/openhft/affinity/common/ProcessRunner.java rename to affinity/src/test/java/net/openhft/affinity/common/ProcessRunner.java index a3d7522e1..73169e020 100644 --- a/affinity/src/main/java/net/openhft/affinity/common/ProcessRunner.java +++ b/affinity/src/test/java/net/openhft/affinity/common/ProcessRunner.java @@ -29,6 +29,19 @@ public class ProcessRunner { * @throws IOException if there is an error starting the process */ public static Process runClass(Class clazz, String... args) throws IOException { + return runClass(clazz, new String[]{}, args); + } + + /** + * Spawn a process running the main method of a specified class + * + * @param clazz The class to execute + * @param jvmArgs Any arguments to pass to the process + * @param programArgs Any arguments to pass to the process + * @return the Process spawned + * @throws IOException if there is an error starting the process + */ + public static Process runClass(Class clazz, String[] jvmArgs, String[] programArgs) throws IOException { // Because Java17 must be run using various module flags, these must be propagated // to the child processes // https://stackoverflow.com/questions/1490869/how-to-get-vm-arguments-from-inside-of-java-application @@ -46,10 +59,11 @@ public static Process runClass(Class clazz, String... args) throws IOExceptio List allArgs = new ArrayList<>(); allArgs.add(javaBin); allArgs.addAll(jvmArgsWithoutJavaAgents); + allArgs.addAll(Arrays.asList(jvmArgs)); allArgs.add("-cp"); allArgs.add(classPath); allArgs.add(className); - allArgs.addAll(Arrays.asList(args)); + allArgs.addAll(Arrays.asList(programArgs)); ProcessBuilder processBuilder = new ProcessBuilder(allArgs.toArray(new String[]{})); // processBuilder.inheritIO(); // this doesn't place nice with surefire return processBuilder.start(); From 0bdef1808617b84d9391a7859baf024f16457a36 Mon Sep 17 00:00:00 2001 From: Nick Tindall Date: Tue, 19 Oct 2021 17:40:42 +1100 Subject: [PATCH 173/353] Add more logging for when MultiProcessAffinityTest fails --- .../net/openhft/affinity/MultiProcessAffinityTest.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java b/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java index a6c7dd8f8..840b53f28 100644 --- a/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java +++ b/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java @@ -8,6 +8,7 @@ import org.slf4j.LoggerFactory; import java.io.IOException; +import java.time.LocalDateTime; import java.util.concurrent.TimeUnit; import static net.openhft.affinity.LockCheck.IS_LINUX; @@ -16,6 +17,8 @@ public class MultiProcessAffinityTest { + private static final Logger LOGGER = LoggerFactory.getLogger(MultiProcessAffinityTest.class); + @Rule public TemporaryFolder folder = new TemporaryFolder(); private String originalTmpDir; @@ -46,6 +49,8 @@ public void shouldNotAcquireLockOnCoresLockedByOtherProcesses() throws IOExcepti while (FileLockBasedLockChecker.getInstance().isLockFree(lastCpuId)) { Thread.sleep(100); if (System.currentTimeMillis() > endTime) { + LOGGER.info("Timed out waiting for the lock to be acquired: isAlive={}, exitCode={}", + affinityLockerProcess.isAlive(), affinityLockerProcess.isAlive() ? "N/A" : affinityLockerProcess.exitValue()); ProcessRunner.printProcessOutput("AffinityLockerProcess", affinityLockerProcess); fail("Timed out waiting for the sub-process to acquire the lock"); } @@ -70,10 +75,12 @@ public static void main(String[] args) { String cpuIdToLock = args[0]; try (final AffinityLock affinityLock = AffinityLock.acquireLock(cpuIdToLock)) { - LOGGER.info("Got affinity lock " + affinityLock); + LOGGER.info("Got affinity lock " + affinityLock + " at " + LocalDateTime.now() + ", CPU=" + affinityLock.cpuId()); Thread.sleep(Integer.MAX_VALUE); + LOGGER.error("Woke from sleep? this should never happen"); } catch (InterruptedException e) { // expected, just end + LOGGER.info("Interrupted at " + LocalDateTime.now() + " lock is released"); } } } From 6a7883dae5a8f0e8b4b7a6d4fbe48b614361d6ca Mon Sep 17 00:00:00 2001 From: Nick Tindall Date: Thu, 28 Oct 2021 07:15:17 +1100 Subject: [PATCH 174/353] Reproduction of and fix for #81 * Reproduction of #81 * Make lock acquisition atomic, Fixes #81 --- .../java/net/openhft/affinity/LockCheck.java | 47 +-- .../net/openhft/affinity/LockInventory.java | 41 +- .../lockchecker/FileBasedLockChecker.java | 83 ---- .../lockchecker/FileLockBasedLockChecker.java | 375 ++++++++++-------- .../openhft/affinity/AffinityLockTest.java | 10 +- .../openhft/affinity/BaseAffinityTest.java | 28 ++ .../affinity/FileLockLockCheckTest.java | 24 +- .../net/openhft/affinity/LockCheckTest.java | 28 +- .../affinity/MultiProcessAffinityTest.java | 213 +++++++++- .../testimpl/TestFileBasedLockChecker.java | 12 - .../TestFileLockBasedLockChecker.java | 24 +- 11 files changed, 495 insertions(+), 390 deletions(-) delete mode 100644 affinity/src/main/java/net/openhft/affinity/lockchecker/FileBasedLockChecker.java create mode 100644 affinity/src/test/java/net/openhft/affinity/BaseAffinityTest.java delete mode 100644 affinity/src/test/java/net/openhft/affinity/testimpl/TestFileBasedLockChecker.java diff --git a/affinity/src/main/java/net/openhft/affinity/LockCheck.java b/affinity/src/main/java/net/openhft/affinity/LockCheck.java index cfe4e78f6..8acaf4e23 100644 --- a/affinity/src/main/java/net/openhft/affinity/LockCheck.java +++ b/affinity/src/main/java/net/openhft/affinity/LockCheck.java @@ -28,7 +28,7 @@ /** * @author Rob Austin. */ -enum LockCheck { +public enum LockCheck { ; // none private static final Logger LOGGER = LoggerFactory.getLogger(LockCheck.class); @@ -38,7 +38,7 @@ enum LockCheck { private static final LockChecker lockChecker = FileLockBasedLockChecker.getInstance(); - static long getPID() { + public static long getPID() { String processName = java.lang.management.ManagementFactory.getRuntimeMXBean().getName(); return Long.parseLong(processName.split("@")[0]); @@ -52,30 +52,14 @@ public static boolean isCpuFree(int cpu) { if (!canOSSupportOperation()) return true; - if (isLockFree(cpu)) { - return true; - } else { - int currentProcess = 0; - try { - currentProcess = getProcessForCpu(cpu); - } catch (RuntimeException | IOException e) { - LOGGER.warn("Failed to determine process on cpu " + cpu, e); - e.printStackTrace(); - return true; - } - if (!isProcessRunning(currentProcess)) { - lockChecker.releaseLock(cpu); - return true; - } - return false; - } + return isLockFree(cpu); } - static void replacePid(int cpu, long processID) throws IOException { - storePid(processID, cpu); + static boolean replacePid(int cpu, long processID) throws IOException { + return storePid(processID, cpu); } - static boolean isProcessRunning(long pid) { + public static boolean isProcessRunning(long pid) { if (canOSSupportOperation()) return new File("/proc/" + pid).exists(); else @@ -86,17 +70,15 @@ static boolean isProcessRunning(long pid) { * stores the pid in a file, named by the core, the pid is written to the file with the date * below */ - private synchronized static void storePid(long processID, int cpu) throws IOException { - if (!lockChecker.obtainLock(cpu, Long.toString(processID))) { - throw new IOException(String.format("Cannot obtain file lock for cpu %d", cpu)); - } + private synchronized static boolean storePid(long processID, int cpu) throws IOException { + return lockChecker.obtainLock(cpu, Long.toString(processID)); } private synchronized static boolean isLockFree(int id) { return lockChecker.isLockFree(id); } - static int getProcessForCpu(int core) throws IOException { + public static int getProcessForCpu(int core) throws IOException { String meta = lockChecker.getMetaInfo(core); if (meta != null && !meta.isEmpty()) { @@ -109,15 +91,10 @@ static int getProcessForCpu(int core) throws IOException { return EMPTY_PID; } - static void updateCpu(int cpu) { + static boolean updateCpu(int cpu) throws IOException { if (!canOSSupportOperation()) - return; - try { - replacePid(cpu, getPID()); - } catch (IOException e) { - LOGGER.warn("Failed to update lock file for cpu " + cpu, e); - e.printStackTrace(); - } + return true; + return replacePid(cpu, getPID()); } public static void releaseLock(int cpu) { diff --git a/affinity/src/main/java/net/openhft/affinity/LockInventory.java b/affinity/src/main/java/net/openhft/affinity/LockInventory.java index 7523e5e28..6a68b1321 100644 --- a/affinity/src/main/java/net/openhft/affinity/LockInventory.java +++ b/affinity/src/main/java/net/openhft/affinity/LockInventory.java @@ -22,6 +22,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.IOException; import java.util.NavigableMap; import java.util.TreeMap; @@ -69,9 +70,24 @@ private static boolean isAnyCpu(final int cpuId) { return cpuId == AffinityLock.ANY_CPU; } - private static void updateLockForCurrentThread(final boolean bind, final AffinityLock al, final boolean b) { - al.assignCurrentThread(bind, b); - LockCheck.updateCpu(al.cpuId()); + /** + * Update the lock for the current thread + * + * @param bind Whether to also bind the thread to the core + * @param al The lock to update + * @param wholeCore Whether to bind the whole core + * @return true if the lock was acquired, false otherwise + */ + private static boolean updateLockForCurrentThread(final boolean bind, final AffinityLock al, final boolean wholeCore) { + try { + if (LockCheck.updateCpu(al.cpuId())) { + al.assignCurrentThread(bind, wholeCore); + return true; + } + } catch (IOException e) { + LOGGER.warn("Error occurred acquiring lock", e); + } + return false; } public final synchronized CpuLayout getCpuLayout() { @@ -106,8 +122,9 @@ public final synchronized AffinityLock acquireLock(boolean bind, int cpuId, Affi final boolean specificCpuRequested = !isAnyCpu(cpuId); if (specificCpuRequested && cpuId != 0) { final AffinityLock required = logicalCoreLocks[cpuId]; - if (required.canReserve(true) && anyStrategyMatches(cpuId, cpuId, strategies)) { - updateLockForCurrentThread(bind, required, false); + if (required.canReserve(true) + && anyStrategyMatches(cpuId, cpuId, strategies) + && updateLockForCurrentThread(bind, required, false)) { return required; } LOGGER.warn("Unable to acquire lock on CPU {} for thread {}, trying to find another CPU", @@ -119,8 +136,9 @@ public final synchronized AffinityLock acquireLock(boolean bind, int cpuId, Affi // if you have only one core, this library is not appropriate in any case. for (int i = logicalCoreLocks.length - 1; i > 0; i--) { AffinityLock al = logicalCoreLocks[i]; - if (al.canReserve(false) && (isAnyCpu(cpuId) || strategy.matches(cpuId, al.cpuId()))) { - updateLockForCurrentThread(bind, al, false); + if (al.canReserve(false) + && (isAnyCpu(cpuId) || strategy.matches(cpuId, al.cpuId())) + && updateLockForCurrentThread(bind, al, false)) { return al; } } @@ -136,8 +154,8 @@ public final synchronized AffinityLock tryAcquireLock(boolean bind, int cpuId) { return null; final AffinityLock required = logicalCoreLocks[cpuId]; - if (required.canReserve(true)) { - updateLockForCurrentThread(bind, required, false); + if (required.canReserve(true) + && updateLockForCurrentThread(bind, required, false)) { return required; } @@ -156,8 +174,9 @@ public final synchronized AffinityLock acquireCore(boolean bind, int cpuId, Affi continue LOOP; final AffinityLock al = als[0]; - updateLockForCurrentThread(bind, al, true); - return al; + if (updateLockForCurrentThread(bind, al, true)) { + return al; + } } } diff --git a/affinity/src/main/java/net/openhft/affinity/lockchecker/FileBasedLockChecker.java b/affinity/src/main/java/net/openhft/affinity/lockchecker/FileBasedLockChecker.java deleted file mode 100644 index 37224e104..000000000 --- a/affinity/src/main/java/net/openhft/affinity/lockchecker/FileBasedLockChecker.java +++ /dev/null @@ -1,83 +0,0 @@ -package net.openhft.affinity.lockchecker; - -import org.jetbrains.annotations.NotNull; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.*; -import java.text.SimpleDateFormat; -import java.util.Date; - -import static java.nio.charset.StandardCharsets.UTF_8; - -@SuppressWarnings("ResultOfMethodCallIgnored") -public class FileBasedLockChecker implements LockChecker { - - static final SimpleDateFormat df = new SimpleDateFormat("yyyy.MM" + ".dd 'at' HH:mm:ss z"); - private static final Logger LOGGER = LoggerFactory.getLogger(FileBasedLockChecker.class); - private static final LockChecker instance = new FileBasedLockChecker(); - - protected FileBasedLockChecker() { - //nothing - } - - public static LockChecker getInstance() { - return instance; - } - - private static File tmpDir() { - final File tempDir = new File(System.getProperty("java.io.tmpdir")); - - if (!tempDir.exists()) - tempDir.mkdirs(); - - return tempDir; - } - - @Override - public boolean isLockFree(int id) { - return !toFile(id).exists(); - } - - @Override - public boolean obtainLock(int id, String metaInfo) throws IOException { - File file = toFile(id); - file.delete(); - - try (Writer writer = new BufferedWriter(new OutputStreamWriter( - new FileOutputStream(file, false), UTF_8))) { - writer.write(metaInfo + "\n" + df.format(new Date())); - file.setWritable(true, false); - file.setExecutable(false, false); - return true; - } - } - - @Override - public boolean releaseLock(int id) { - return toFile(id).delete(); - } - - @Override - public String getMetaInfo(int id) throws IOException { - File file = toFile(id); - - if (!file.exists()) { - return null; - } - - try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), UTF_8))) { - final String firstLine = reader.readLine(); - if (firstLine == null) { - LOGGER.error(String.format("Empty lock file %s%n", file.getAbsolutePath())); - return null; - } - return firstLine.trim(); - } - } - - @NotNull - protected File toFile(int id) { - return new File(tmpDir(), "cpu-" + id + ".lock"); - } -} diff --git a/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java b/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java index 10f2a2203..9cd219523 100644 --- a/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java +++ b/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java @@ -1,170 +1,205 @@ -package net.openhft.affinity.lockchecker; - -import org.jetbrains.annotations.NotNull; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.File; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.nio.channels.FileChannel; -import java.nio.channels.FileLock; -import java.nio.channels.OverlappingFileLockException; -import java.nio.file.Files; -import java.nio.file.StandardOpenOption; -import java.nio.file.attribute.FileAttribute; -import java.nio.file.attribute.PosixFilePermission; -import java.nio.file.attribute.PosixFilePermissions; -import java.util.Arrays; -import java.util.Date; -import java.util.HashSet; -import java.util.Set; - -import static java.nio.file.StandardOpenOption.*; -import static net.openhft.affinity.impl.VanillaCpuLayout.MAX_CPUS_SUPPORTED; - -public class FileLockBasedLockChecker extends FileBasedLockChecker { - - private static final Logger LOGGER = LoggerFactory.getLogger(FileLockBasedLockChecker.class); - private static final String OS = System.getProperty("os.name").toLowerCase(); - - private static final LockChecker instance = new FileLockBasedLockChecker(); - private static final HashSet openOptions = new HashSet<>(Arrays.asList(CREATE_NEW, WRITE, READ, SYNC)); - private static final FileAttribute> fileAttr = PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("rw-rw-rw-")); - private final LockReference[] locks = new LockReference[MAX_CPUS_SUPPORTED]; - - protected FileLockBasedLockChecker() { - //nothing - } - - public static LockChecker getInstance() { - return instance; - } - - @Override - public boolean isLockFree(int id) { - return isLockFree(toFile(id), id); - } - - private boolean isLockFree(File file, int id) { - //if no file exists - nobody has the lock for sure - if (!file.exists()) { - return true; - } - - //do we have the lock already? - LockReference existingLock = locks[id]; - if (existingLock != null) { - return false; - } - - //does another process have the lock? - try { - FileChannel fc = FileChannel.open(file.toPath(), WRITE); - FileLock fileLock = fc.tryLock(); - if (fileLock == null) { - return false; - } - } catch (IOException | OverlappingFileLockException e) { - LOGGER.error(String.format("Exception occurred whilst trying to check lock on file %s : %s%n", file.getAbsolutePath(), e)); - } - - //file is present but nobody has it locked - delete it - boolean deleted = file.delete(); - if (deleted) - LOGGER.info(String.format("Deleted %s as nobody has the lock", file.getAbsolutePath())); - else - LOGGER.warn(String.format("Nobody has the lock on %s. Delete failed", file.getAbsolutePath())); - - return true; - } - - @Override - public boolean obtainLock(int id, String metaInfo) throws IOException { - final File file = toFile(id); - if (!isLockFree(file, id)) { - return false; - } - - FileChannel fc = FileChannel.open(file.toPath(), openOptions, fileAttr); - FileLock fl = fc.tryLock(); - - if (fl == null) { - LOGGER.error(String.format("Could not obtain lock on file %s%n", file.getAbsolutePath())); - return false; - } else { - LOGGER.debug(String.format("Obtained lock on file %s (%s)%n", file.getAbsolutePath(), metaInfo)); - locks[id] = new LockReference(fc, fl); - - byte[] content = String.format("%s%n%s", metaInfo, df.format(new Date())).getBytes(); - ByteBuffer buffer = ByteBuffer.wrap(content); - while (buffer.hasRemaining()) { - fc.write(buffer); - } - return true; - } - } - - @Override - public boolean releaseLock(int id) { - LockReference lock = locks[id]; - if (lock == null) { - LOGGER.error(String.format("Cannot release lock for id %d as don't have it!", id)); - return false; - } - - try { - locks[id] = null; - lock.lock.release(); - lock.channel.close(); - toFile(id).delete(); - return true; - } catch (IOException e) { - LOGGER.error(String.format("Couldn't release lock for id %d due to exception: %s%n", id, e.getMessage())); - return false; - } - } - - @Override - public String getMetaInfo(int id) throws IOException { - final File file = toFile(id); - if (isLockFree(file, id)) { - LOGGER.warn("Cannot obtain lock on lock file {}", file.getAbsolutePath()); - return null; - } - - LockReference lr = locks[id]; - if (lr != null) { - return readMetaInfoFromLockFileChannel(file, lr.channel); - } else { - try (FileChannel fc = FileChannel.open(file.toPath(), READ)) { - return readMetaInfoFromLockFileChannel(file, fc); - } - } - } - - private String readMetaInfoFromLockFileChannel(File lockFile, FileChannel lockFileChannel) throws IOException { - ByteBuffer buffer = ByteBuffer.allocate(64); - int len = lockFileChannel.read(buffer, 0); - String content = len < 1 ? "" : new String(buffer.array(), 0, len); - if (content.isEmpty()) { - LOGGER.warn("Empty lock file {}", lockFile.getAbsolutePath()); - return null; - } - return content.substring(0, content.indexOf("\n")); - } - - @NotNull - @Override - protected File toFile(int id) { - File file = super.toFile(id); - try { - if (file.exists() && OS.startsWith("linux")) { - Files.setPosixFilePermissions(file.toPath(), PosixFilePermissions.fromString("rwxrwxrwx")); - } - } catch (IOException e) { - LOGGER.warn("Unable to set file permissions \"rwxrwxrwx\" for {} due to {}", file.toString(), e); - } - return file; - } -} +package net.openhft.affinity.lockchecker; + +import org.jetbrains.annotations.NotNull; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.channels.FileChannel; +import java.nio.channels.FileLock; +import java.nio.file.NoSuchFileException; +import java.nio.file.OpenOption; +import java.nio.file.attribute.FileAttribute; +import java.nio.file.attribute.PosixFilePermission; +import java.nio.file.attribute.PosixFilePermissions; +import java.text.SimpleDateFormat; +import java.util.Arrays; +import java.util.Date; +import java.util.HashSet; +import java.util.Set; + +import static java.nio.file.StandardOpenOption.*; +import static net.openhft.affinity.impl.VanillaCpuLayout.MAX_CPUS_SUPPORTED; + +public class FileLockBasedLockChecker implements LockChecker { + + private static final int MAX_LOCK_RETRIES = 5; + private static final SimpleDateFormat df = new SimpleDateFormat("yyyy.MM" + ".dd 'at' HH:mm:ss z"); + private static final FileAttribute> LOCK_FILE_ATTRIBUTES = PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("rw-rw-rw-")); + private static final Set LOCK_FILE_OPEN_OPTIONS = new HashSet<>(Arrays.asList(READ, WRITE, CREATE, SYNC)); + private static final Logger LOGGER = LoggerFactory.getLogger(FileLockBasedLockChecker.class); + private static final FileLockBasedLockChecker instance = new FileLockBasedLockChecker(); + private final LockReference[] locks = new LockReference[MAX_CPUS_SUPPORTED]; + + protected FileLockBasedLockChecker() { + //nothing + } + + public static LockChecker getInstance() { + return instance; + } + + @Override + public synchronized boolean isLockFree(int id) { + // check if this process already has the lock + if (locks[id] != null) { + return false; + } + + // check if another process has the lock + File lockFile = toFile(id); + try (final FileChannel channel = FileChannel.open(lockFile.toPath(), READ)) { + // if we can acquire a shared lock, nobody has an exclusive lock + try (final FileLock fileLock = channel.tryLock(0, Long.MAX_VALUE, true)) { + if (fileLock != null && fileLock.isValid()) { + lockFile.delete(); // clean up the orphaned lock file + return true; + } else { + // another process has an exclusive lock + return false; + } + } + } catch (NoSuchFileException e) { + // no lock file exists, nobody has the lock + return true; + } catch (IOException e) { + LOGGER.warn("An unexpected error occurred checking if the lock was free, assuming it's not", e); + return false; + } + } + + @Override + public synchronized boolean obtainLock(int id, String metaInfo) throws IOException { + int attempt = 0; + while (attempt < MAX_LOCK_RETRIES) { + try { + LockReference lockReference = tryAcquireLockOnFile(id, metaInfo); + if (lockReference != null) { + locks[id] = lockReference; + return true; + } + return false; + } catch (ConcurrentLockFileDeletionException e) { + attempt++; + } + } + LOGGER.warn("Exceeded maximum retries for locking CPU " + id + ", failing acquire"); + return false; + } + + /** + * Attempts to acquire an exclusive lock on the core lock file. + *

    + * It will fail if another process already has an exclusive lock on the file. + * + * @param id The CPU ID to acquire + * @param metaInfo The meta-info to write to the file upon successful acquisition + * @return The {@link LockReference} if the lock was successfully acquired, null otherwise + * @throws IOException If an IOException occurs creating or writing to the file + * @throws ConcurrentLockFileDeletionException If another process deleted the file between us opening it and locking it + */ + private LockReference tryAcquireLockOnFile(int id, String metaInfo) throws IOException, ConcurrentLockFileDeletionException { + final File lockFile = toFile(id); + final FileChannel fileChannel = FileChannel.open(lockFile.toPath(), LOCK_FILE_OPEN_OPTIONS, LOCK_FILE_ATTRIBUTES); + final FileLock fileLock = fileChannel.tryLock(0, Long.MAX_VALUE, false); + if (fileLock == null) { + // someone else has a lock (exclusive or shared), fail to acquire + closeQuietly(fileChannel); + return null; + } else { + if (!lockFile.exists()) { + // someone deleted the file between us opening it and acquiring the lock, signal to retry + closeQuietly(fileLock, fileChannel); + throw new ConcurrentLockFileDeletionException(); + } else { + // we have the lock, the file exists. That's success. + writeMetaInfoToFile(fileChannel, metaInfo); + return new LockReference(fileChannel, fileLock); + } + } + } + + private void writeMetaInfoToFile(FileChannel fc, String metaInfo) throws IOException { + byte[] content = String.format("%s%n%s", metaInfo, df.format(new Date())).getBytes(); + ByteBuffer buffer = ByteBuffer.wrap(content); + while (buffer.hasRemaining()) { + fc.write(buffer); + } + } + + @Override + public synchronized boolean releaseLock(int id) { + if (locks[id] != null) { + final File lockFile = toFile(id); + if (!lockFile.delete()) { + LOGGER.warn("Couldn't delete lock file on release: " + lockFile); + } + closeQuietly(locks[id].lock, locks[id].channel); + locks[id] = null; + return true; + } + return false; + } + + private void closeQuietly(AutoCloseable... closeables) { + for (AutoCloseable closeable : closeables) { + try { + if (closeable != null) { + closeable.close(); + } + } catch (Exception e) { + LOGGER.warn("Error closing " + closeable.getClass().getName(), e); + } + } + } + + @Override + public String getMetaInfo(int id) throws IOException { + final File file = toFile(id); + + LockReference lr = locks[id]; + if (lr != null) { + return readMetaInfoFromLockFileChannel(file, lr.channel); + } else { + try (FileChannel fc = FileChannel.open(file.toPath(), READ)) { + return readMetaInfoFromLockFileChannel(file, fc); + } catch (NoSuchFileException e) { + return null; + } + } + } + + private String readMetaInfoFromLockFileChannel(File lockFile, FileChannel lockFileChannel) throws IOException { + ByteBuffer buffer = ByteBuffer.allocate(64); + int len = lockFileChannel.read(buffer, 0); + String content = len < 1 ? "" : new String(buffer.array(), 0, len); + if (content.isEmpty()) { + LOGGER.warn("Empty lock file {}", lockFile.getAbsolutePath()); + return null; + } + return content.substring(0, content.indexOf("\n")); + } + + @NotNull + protected File toFile(int id) { + assert id >= 0; + return new File(tmpDir(), "cpu-" + id + ".lock"); + } + + private File tmpDir() { + final File tempDir = new File(System.getProperty("java.io.tmpdir")); + + if (!tempDir.exists()) + tempDir.mkdirs(); + + return tempDir; + } + + /** + * Thrown when another process deleted the lock file between us opening the file and acquiring the lock + */ + class ConcurrentLockFileDeletionException extends Exception { + } +} diff --git a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java index c4f8aa769..80ff1fc77 100644 --- a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java +++ b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java @@ -19,7 +19,7 @@ import net.openhft.affinity.impl.Utilities; import net.openhft.affinity.impl.VanillaCpuLayout; -import net.openhft.affinity.testimpl.TestFileBasedLockChecker; +import net.openhft.affinity.testimpl.TestFileLockBasedLockChecker; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,10 +39,10 @@ /** * @author peter.lawrey */ -public class AffinityLockTest { +public class AffinityLockTest extends BaseAffinityTest { private static final Logger logger = LoggerFactory.getLogger(AffinityLockTest.class); - private final TestFileBasedLockChecker lockChecker = new TestFileBasedLockChecker(); + private final TestFileLockBasedLockChecker lockChecker = new TestFileLockBasedLockChecker(); @Test public void dumpLocksI7() throws IOException { @@ -254,11 +254,11 @@ public void lockFilesShouldBeRemovedOnRelease() { } final AffinityLock lock = AffinityLock.acquireLock(); - assertThat(Files.exists(Paths.get(lockChecker.doToFile(lock.cpuId()).getAbsolutePath())), is(true)); + assertTrue(Files.exists(Paths.get(lockChecker.doToFile(lock.cpuId()).getAbsolutePath()))); lock.release(); - assertThat(Files.exists(Paths.get(lockChecker.doToFile(lock.cpuId()).getAbsolutePath())), is(false)); + assertFalse(Files.exists(Paths.get(lockChecker.doToFile(lock.cpuId()).getAbsolutePath()))); } private void displayStatus() { diff --git a/affinity/src/test/java/net/openhft/affinity/BaseAffinityTest.java b/affinity/src/test/java/net/openhft/affinity/BaseAffinityTest.java new file mode 100644 index 000000000..9728f32a4 --- /dev/null +++ b/affinity/src/test/java/net/openhft/affinity/BaseAffinityTest.java @@ -0,0 +1,28 @@ +package net.openhft.affinity; + +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.rules.TemporaryFolder; + +public class BaseAffinityTest { + + @Rule + public TemporaryFolder folder = new TemporaryFolder(); + private String originalTmpDir; + + @Before + public void setTmpDirectory() { + originalTmpDir = System.getProperty("java.io.tmpdir"); + System.setProperty("java.io.tmpdir", folder.getRoot().getAbsolutePath()); + } + + @After + public void restoreTmpDirectoryAndReleaseAllLocks() { + // don't leave any locks locked + for (int i = 0; i < AffinityLock.PROCESSORS; i++) { + LockCheck.releaseLock(i); + } + System.setProperty("java.io.tmpdir", originalTmpDir); + } +} diff --git a/affinity/src/test/java/net/openhft/affinity/FileLockLockCheckTest.java b/affinity/src/test/java/net/openhft/affinity/FileLockLockCheckTest.java index 1a41b2e47..7268f26c6 100644 --- a/affinity/src/test/java/net/openhft/affinity/FileLockLockCheckTest.java +++ b/affinity/src/test/java/net/openhft/affinity/FileLockLockCheckTest.java @@ -18,7 +18,10 @@ package net.openhft.affinity; import net.openhft.affinity.testimpl.TestFileLockBasedLockChecker; -import org.junit.*; +import org.junit.Assert; +import org.junit.Assume; +import org.junit.Before; +import org.junit.Test; import java.io.File; import java.io.IOException; @@ -29,31 +32,14 @@ /** * @author Tom Shercliff */ -public class FileLockLockCheckTest { +public class FileLockLockCheckTest extends BaseAffinityTest { - private static final String TMP = System.getProperty("java.io.tmpdir"); - private static final String TARGET = System.getProperty("project.build.directory", findTarget()); private final TestFileLockBasedLockChecker lockChecker = new TestFileLockBasedLockChecker(); private int cpu = 11; - private static String findTarget() { - for (File dir = new File(System.getProperty("user.dir")); dir != null; dir = dir.getParentFile()) { - File target = new File(dir, "target"); - if (target.exists()) - return target.getAbsolutePath(); - } - return TMP + "/target"; - } - @Before public void before() { Assume.assumeTrue(IS_LINUX); - System.setProperty("java.io.tmpdir", TARGET + "/" + System.nanoTime()); - } - - @After - public void after() { - System.setProperty("java.io.tmpdir", TMP); } @Test diff --git a/affinity/src/test/java/net/openhft/affinity/LockCheckTest.java b/affinity/src/test/java/net/openhft/affinity/LockCheckTest.java index 595269bb7..c6ab5e042 100644 --- a/affinity/src/test/java/net/openhft/affinity/LockCheckTest.java +++ b/affinity/src/test/java/net/openhft/affinity/LockCheckTest.java @@ -17,8 +17,11 @@ package net.openhft.affinity; -import net.openhft.affinity.testimpl.TestFileBasedLockChecker; -import org.junit.*; +import net.openhft.affinity.testimpl.TestFileLockBasedLockChecker; +import org.junit.Assert; +import org.junit.Assume; +import org.junit.Before; +import org.junit.Test; import java.io.File; import java.io.FileWriter; @@ -30,31 +33,14 @@ /** * @author Rob Austin. */ -public class LockCheckTest { +public class LockCheckTest extends BaseAffinityTest { - private static final String TMP = System.getProperty("java.io.tmpdir"); - private static final String TARGET = System.getProperty("project.build.directory", findTarget()); - private final TestFileBasedLockChecker lockChecker = new TestFileBasedLockChecker(); + private final TestFileLockBasedLockChecker lockChecker = new TestFileLockBasedLockChecker(); private int cpu = 11; - private static String findTarget() { - for (File dir = new File(System.getProperty("user.dir")); dir != null; dir = dir.getParentFile()) { - File target = new File(dir, "target"); - if (target.exists()) - return target.getAbsolutePath(); - } - return TMP + "/target"; - } - @Before public void before() { Assume.assumeTrue(IS_LINUX); - System.setProperty("java.io.tmpdir", TARGET + "/" + System.nanoTime()); - } - - @After - public void after() { - System.setProperty("java.io.tmpdir", TMP); } @Test diff --git a/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java b/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java index 840b53f28..30bb03a53 100644 --- a/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java +++ b/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java @@ -1,42 +1,43 @@ package net.openhft.affinity; import net.openhft.affinity.common.ProcessRunner; -import net.openhft.affinity.lockchecker.FileLockBasedLockChecker; -import org.junit.*; -import org.junit.rules.TemporaryFolder; +import net.openhft.affinity.testimpl.TestFileLockBasedLockChecker; +import org.jetbrains.annotations.NotNull; +import org.junit.Assume; +import org.junit.Before; +import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.File; import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.channels.FileChannel; +import java.nio.charset.StandardCharsets; +import java.nio.file.FileAlreadyExistsException; +import java.nio.file.StandardOpenOption; import java.time.LocalDateTime; -import java.util.concurrent.TimeUnit; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.*; +import java.util.stream.Collectors; +import java.util.stream.IntStream; +import static java.lang.String.format; import static net.openhft.affinity.LockCheck.IS_LINUX; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.fail; +import static org.junit.Assert.*; -public class MultiProcessAffinityTest { +public class MultiProcessAffinityTest extends BaseAffinityTest { private static final Logger LOGGER = LoggerFactory.getLogger(MultiProcessAffinityTest.class); - @Rule - public TemporaryFolder folder = new TemporaryFolder(); - private String originalTmpDir; - @Before public void setUp() { - originalTmpDir = System.getProperty("java.io.tmpdir"); - System.setProperty("java.io.tmpdir", folder.getRoot().getAbsolutePath()); - } - - @After - public void tearDown() { - System.setProperty("java.io.tmpdir", originalTmpDir); + Assume.assumeTrue(IS_LINUX); } @Test public void shouldNotAcquireLockOnCoresLockedByOtherProcesses() throws IOException, InterruptedException { - Assume.assumeTrue(IS_LINUX); // run the separate affinity locker final Process affinityLockerProcess = ProcessRunner.runClass(AffinityLockerProcess.class, new String[]{"-Djava.io.tmpdir=" + folder.getRoot().getAbsolutePath()}, @@ -46,7 +47,7 @@ public void shouldNotAcquireLockOnCoresLockedByOtherProcesses() throws IOExcepti // wait for the CPU to be locked long endTime = System.currentTimeMillis() + 5_000; - while (FileLockBasedLockChecker.getInstance().isLockFree(lastCpuId)) { + while (LockCheck.isCpuFree(lastCpuId)) { Thread.sleep(100); if (System.currentTimeMillis() > endTime) { LOGGER.info("Timed out waiting for the lock to be acquired: isAlive={}, exitCode={}", @@ -61,12 +62,134 @@ public void shouldNotAcquireLockOnCoresLockedByOtherProcesses() throws IOExcepti } } finally { affinityLockerProcess.destroy(); - if (!affinityLockerProcess.waitFor(5, TimeUnit.SECONDS)) { - fail("Sub-process didn't terminate!"); + waitForProcessToEnd(5, "Affinity locker process", affinityLockerProcess, false); + } + } + + @Test + public void shouldAllocateCoresCorrectlyUnderContention() throws IOException, InterruptedException { + final int numberOfLockers = Math.max(2, Math.min(12, Runtime.getRuntime().availableProcessors())) / 2; + List lockers = new ArrayList<>(); + LOGGER.info("Running test with {} locker processes", numberOfLockers); + for (int i = 0; i < numberOfLockers; i++) { + lockers.add(ProcessRunner.runClass(RepeatedAffinityLocker.class, + new String[]{"-Djava.io.tmpdir=" + folder.getRoot().getAbsolutePath()}, + new String[]{"last", "30", "2"})); + } + for (int i = 0; i < numberOfLockers; i++) { + final Process process = lockers.get(i); + waitForProcessToEnd(20, "Locking process", process); + } + } + + @Test + public void shouldAllocateCoresCorrectlyUnderContentionWithFailures() throws IOException, InterruptedException { + final int numberOfLockers = Math.max(2, Math.min(12, Runtime.getRuntime().availableProcessors())) / 2; + List lockers = new ArrayList<>(); + LOGGER.info("Running test with {} locker processes", numberOfLockers); + Process lockFileDropper = ProcessRunner.runClass(LockFileDropper.class); + for (int i = 0; i < numberOfLockers; i++) { + lockers.add(ProcessRunner.runClass(RepeatedAffinityLocker.class, + new String[]{"-Djava.io.tmpdir=" + folder.getRoot().getAbsolutePath()}, + new String[]{"last", "30", "2"})); + } + for (int i = 0; i < numberOfLockers; i++) { + final Process process = lockers.get(i); + waitForProcessToEnd(20, "Locking process", process); + } + lockFileDropper.destroy(); + waitForProcessToEnd(5, "Lock file droppper", lockFileDropper); + } + + @Test + public void shouldBeAbleToAcquireLockLeftByOtherProcess() throws IOException, InterruptedException { + final Process process = ProcessRunner.runClass(AffinityLockerThatDoesNotReleaseProcess.class, + new String[]{"-Djava.io.tmpdir=" + folder.getRoot().getAbsolutePath()}, + new String[]{"last"}); + waitForProcessToEnd(5, "Locking process", process); + // We should be able to acquire the lock despite the other process not explicitly releasing it + try (final AffinityLock acquired = AffinityLock.acquireLock("last")) { + assertEquals(AffinityLock.PROCESSORS - 1, acquired.cpuId()); + } + } + + private void waitForProcessToEnd(int timeToWaitSeconds, String processDescription, Process process) throws InterruptedException { + waitForProcessToEnd(timeToWaitSeconds, processDescription, process, true); + } + + private void waitForProcessToEnd(int timeToWaitSeconds, String processDescription, Process process, boolean checkExitCode) throws InterruptedException { + if (!process.waitFor(timeToWaitSeconds, TimeUnit.SECONDS)) { + ProcessRunner.printProcessOutput(processDescription, process); + fail(processDescription + " didn't end in time"); + } + if (checkExitCode && process.exitValue() != 0) { + ProcessRunner.printProcessOutput(processDescription, process); + fail(processDescription + " failed, see output above (exit value " + process.exitValue() + ")"); + } + } + + /** + * Repeatedly acquires and releases a lock on the specified core + */ + static class RepeatedAffinityLocker implements Callable { + + private static final Logger LOGGER = LoggerFactory.getLogger(RepeatedAffinityLocker.class); + private static final long PID = LockCheck.getPID(); + private final int iterations; + private final String cpuIdToLock; + + public static void main(String[] args) throws InterruptedException, ExecutionException { + String cpuIdToLock = args[0]; + int iterations = Integer.parseInt(args[1]); + int threads = Integer.parseInt(args[2]); + + LOGGER.info("Acquiring lock with {} threads, {} iterations", threads, iterations); + ExecutorService executorService = Executors.newFixedThreadPool(threads); + final List> futures = executorService.invokeAll(IntStream.range(0, threads) + .mapToObj(tid -> new RepeatedAffinityLocker(cpuIdToLock, iterations)) + .collect(Collectors.toList())); + for (Future future : futures) { + future.get(); + } + executorService.shutdown(); + if (!executorService.awaitTermination(5, TimeUnit.SECONDS)) { + throw new IllegalStateException("Executor service didn't shut down"); + } + } + + public RepeatedAffinityLocker(String cpuIdToLock, int iterations) { + this.iterations = iterations; + this.cpuIdToLock = cpuIdToLock; + } + + @Override + public Void call() throws Exception { + for (int i = 0; i < iterations; i++) { + LOGGER.info("******* Starting iteration {} at {}", i, LocalDateTime.now()); + try (final AffinityLock affinityLock = AffinityLock.acquireLock(cpuIdToLock)) { + if (affinityLock.isAllocated()) { + assertLockFileContainsMyPid(affinityLock); + Thread.sleep(ThreadLocalRandom.current().nextInt(50)); + assertLockFileContainsMyPid(affinityLock); + } else { + LOGGER.info("Couldn't get a lock"); + } + } + } + return null; + } + + private void assertLockFileContainsMyPid(AffinityLock affinityLock) throws IOException { + int lockPID = LockCheck.getProcessForCpu(affinityLock.cpuId()); + if (lockPID != PID) { + throw new IllegalStateException(format("PID in lock file is not mine (lockPID=%d, myPID=%d)", lockPID, PID)); } } } + /** + * Acquires a lock on the specified CPU, holds it until interrupted + */ static class AffinityLockerProcess { private static final Logger LOGGER = LoggerFactory.getLogger(AffinityLockerProcess.class); @@ -84,4 +207,50 @@ public static void main(String[] args) { } } } + + /** + * Acquires a lock then ends + */ + static class AffinityLockerThatDoesNotReleaseProcess { + private static final Logger LOGGER = LoggerFactory.getLogger(AffinityLockerProcess.class); + + public static void main(String[] args) { + String cpuIdToLock = args[0]; + + final AffinityLock affinityLock = AffinityLock.acquireLock(cpuIdToLock); + LOGGER.info("Got affinity lock " + affinityLock + " at " + LocalDateTime.now() + ", CPU=" + affinityLock.cpuId()); + } + } + + /** + * Simulate failing processes by repeatedly dropping lock files + * with PIDs of non-existent processes + */ + static class LockFileDropper { + + public static void main(String[] args) throws InterruptedException, IOException { + while (Thread.currentThread().isInterrupted()) { + for (int cpu = 0; cpu < AffinityLock.PROCESSORS; cpu++) { + try { + File lockFile = toFile(cpu); + try (final FileChannel fc = FileChannel.open(lockFile.toPath(), StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE)) { + final long maxValue = Long.MAX_VALUE; // a PID that never exists + ByteBuffer buffer = ByteBuffer.wrap((maxValue + "\n").getBytes(StandardCharsets.UTF_8)); + while (buffer.hasRemaining()) { + fc.write(buffer); + } + } + } catch (FileAlreadyExistsException e) { + LOGGER.info("Failed, trying again"); + } + Thread.sleep(ThreadLocalRandom.current().nextInt(50)); + } + } + } + + @NotNull + protected static File toFile(int id) { + return new TestFileLockBasedLockChecker().doToFile(id); + } + } } diff --git a/affinity/src/test/java/net/openhft/affinity/testimpl/TestFileBasedLockChecker.java b/affinity/src/test/java/net/openhft/affinity/testimpl/TestFileBasedLockChecker.java deleted file mode 100644 index dd9b61881..000000000 --- a/affinity/src/test/java/net/openhft/affinity/testimpl/TestFileBasedLockChecker.java +++ /dev/null @@ -1,12 +0,0 @@ -package net.openhft.affinity.testimpl; - -import net.openhft.affinity.lockchecker.FileBasedLockChecker; - -import java.io.File; - -public class TestFileBasedLockChecker extends FileBasedLockChecker { - - public File doToFile(int cpu) { - return toFile(cpu); - } -} diff --git a/affinity/src/test/java/net/openhft/affinity/testimpl/TestFileLockBasedLockChecker.java b/affinity/src/test/java/net/openhft/affinity/testimpl/TestFileLockBasedLockChecker.java index 75d15f449..955be5d77 100644 --- a/affinity/src/test/java/net/openhft/affinity/testimpl/TestFileLockBasedLockChecker.java +++ b/affinity/src/test/java/net/openhft/affinity/testimpl/TestFileLockBasedLockChecker.java @@ -1,12 +1,12 @@ -package net.openhft.affinity.testimpl; - -import net.openhft.affinity.lockchecker.FileLockBasedLockChecker; - -import java.io.File; - -public class TestFileLockBasedLockChecker extends FileLockBasedLockChecker { - - public File doToFile(int cpu) { - return toFile(cpu); - } -} +package net.openhft.affinity.testimpl; + +import net.openhft.affinity.lockchecker.FileLockBasedLockChecker; + +import java.io.File; + +public class TestFileLockBasedLockChecker extends FileLockBasedLockChecker { + + public File doToFile(int cpu) { + return toFile(cpu); + } +} From 4d9a0626dcfe26db217cdabddda5881f2cf2fb5e Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Thu, 28 Oct 2021 22:14:58 +0200 Subject: [PATCH 175/353] Updating to bom version 2.22ea49 From bc263a582de0916810a3afe039526b9585ef6f64 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Thu, 28 Oct 2021 22:15:19 +0200 Subject: [PATCH 176/353] [maven-release-plugin] prepare release Java-Thread-Affinity-3.21ea81 --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 90d16a5a2..5d0122477 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.21ea81-SNAPSHOT + 3.21ea81 bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:https://github.com/OpenHFT/Java-Thread-Affinity.git - HEAD + Java-Thread-Affinity-3.21ea81 diff --git a/affinity/pom.xml b/affinity/pom.xml index 873b8789e..7a86296b5 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.21ea81-SNAPSHOT + 3.21ea81 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -224,7 +224,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.21ea81 diff --git a/pom.xml b/pom.xml index 7abbfc40a..61a8d3b43 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.21ea81-SNAPSHOT + 3.21ea81 pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.21ea81 From 3c36d1b2d0bb89fe17c932378b6e2e45b2dfc706 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Thu, 28 Oct 2021 22:15:22 +0200 Subject: [PATCH 177/353] [maven-release-plugin] prepare for next development iteration --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 5d0122477..d729240c3 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.21ea81 + 3.21ea82-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:https://github.com/OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.21ea81 + HEAD diff --git a/affinity/pom.xml b/affinity/pom.xml index 7a86296b5..da3dcdd8b 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.21ea81 + 3.21ea82-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity @@ -224,7 +224,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.21ea81 + ea diff --git a/pom.xml b/pom.xml index 61a8d3b43..1203bb495 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.21ea81 + 3.21ea82-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.21ea81 + ea From 44d434cfee2dbada553412d42b69460fd4adbaff Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Thu, 28 Oct 2021 22:15:38 +0200 Subject: [PATCH 178/353] Reverting back to bom version 2.22ea-SNAPSHOT From 738d7d06ac116922b81125282d886c5348f71bb5 Mon Sep 17 00:00:00 2001 From: Nick Tindall Date: Fri, 29 Oct 2021 07:55:43 +1100 Subject: [PATCH 179/353] Add sonar profile, update parent POM --- pom.xml | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 7abbfc40a..f0815fedd 100644 --- a/pom.xml +++ b/pom.xml @@ -15,14 +15,15 @@ ~ limitations under the License. --> - + 4.0.0 net.openhft root-parent-pom - 1.2.1 - + 1.2.13 + Java-Thread-Affinity @@ -37,12 +38,44 @@ affinity-test + + + sonar + + + + org.sonarsource.scanner.maven + sonar-maven-plugin + + + org.jacoco + jacoco-maven-plugin + + + + prepare-agent + + + + report + prepare-package + + report + + + + + + + + + scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + ea From 914c7d7968f7980ff96f858a03bbfea9575b057a Mon Sep 17 00:00:00 2001 From: Nick Tindall Date: Fri, 29 Oct 2021 08:17:38 +1100 Subject: [PATCH 180/353] Move sonar plugin into affinity module (it's not a child of parent POM) --- affinity/pom.xml | 36 +++++++++++++++++++++++++++++++++--- pom.xml | 32 -------------------------------- 2 files changed, 33 insertions(+), 35 deletions(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index da3dcdd8b..a1f84a169 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -15,14 +15,15 @@ ~ limitations under the License. --> - + 4.0.0 net.openhft java-parent-pom 1.1.26 - + affinity @@ -126,6 +127,35 @@ + + sonar + + + + org.sonarsource.scanner.maven + sonar-maven-plugin + + + org.jacoco + jacoco-maven-plugin + + + + prepare-agent + + + + report + prepare-package + + report + + + + + + + @@ -224,7 +254,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + ea diff --git a/pom.xml b/pom.xml index decdca724..8e3824fa9 100644 --- a/pom.xml +++ b/pom.xml @@ -38,38 +38,6 @@ affinity-test - - - sonar - - - - org.sonarsource.scanner.maven - sonar-maven-plugin - - - org.jacoco - jacoco-maven-plugin - - - - prepare-agent - - - - report - prepare-package - - report - - - - - - - - - scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git From e1df39dbb11983c1ec827870c2bddc9548236b90 Mon Sep 17 00:00:00 2001 From: Nick Tindall Date: Fri, 29 Oct 2021 10:23:37 +1100 Subject: [PATCH 181/353] Fix some Sonar smells --- .../net/openhft/affinity/BootClassPath.java | 3 +- .../openhft/affinity/MicroJitterSampler.java | 19 ++++++------ .../lockchecker/FileLockBasedLockChecker.java | 10 ++++--- .../affinity/main/AffinityTestMain.java | 29 +++++++++---------- 4 files changed, 30 insertions(+), 31 deletions(-) diff --git a/affinity/src/main/java/net/openhft/affinity/BootClassPath.java b/affinity/src/main/java/net/openhft/affinity/BootClassPath.java index 383e6576f..392ea7df6 100644 --- a/affinity/src/main/java/net/openhft/affinity/BootClassPath.java +++ b/affinity/src/main/java/net/openhft/affinity/BootClassPath.java @@ -67,8 +67,7 @@ private static Set findResources(final Path path, final Logger logger) { private static Set findResourcesInJar(final Path path, final Logger logger) { final Set jarResources = new HashSet<>(); - try { - final JarFile jarFile = new JarFile(path.toFile()); + try (final JarFile jarFile = new JarFile(path.toFile())) { final Enumeration entries = jarFile.entries(); while (entries.hasMoreElements()) { final JarEntry jarEntry = entries.nextElement(); diff --git a/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java b/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java index 05d0c344c..d637640bb 100644 --- a/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java +++ b/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java @@ -39,20 +39,20 @@ public class MicroJitterSampler { private final int[] count = new int[DELAY.length]; private long totalTime = 0; - private static void pause() throws InterruptedException - { - if(BUSYWAIT) { + private static void pause() throws InterruptedException { + if (BUSYWAIT) { long now = System.nanoTime(); - while(System.nanoTime() - now < 1_000_000); + while (System.nanoTime() - now < 1_000_000) ; } else { Thread.sleep(1); } } + public static void main(String... ignored) throws InterruptedException { MicroJitterSampler sampler = new MicroJitterSampler(); - Thread t = new Thread( sampler::run ); + Thread t = new Thread(sampler::run); t.start(); t.join(); } @@ -71,7 +71,7 @@ private void once() throws InterruptedException { } public void run() { - if(CPU != -1) + if (CPU != -1) Affinity.setAffinity(CPU); try { @@ -80,7 +80,7 @@ public void run() { while (!Thread.currentThread().isInterrupted()) { once(); - if(first) { + if (first) { reset(); first = false; System.out.println("Warmup complete. Running jitter tests..."); @@ -89,7 +89,8 @@ public void run() { print(System.out); } - } catch(InterruptedException e) { + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); } } @@ -101,7 +102,7 @@ private static String asString(long timeNS) { } void reset() { - for(int i=0; i dfTL = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyy.MM" + ".dd 'at' HH:mm:ss z")); private static final FileAttribute> LOCK_FILE_ATTRIBUTES = PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("rw-rw-rw-")); private static final Set LOCK_FILE_OPEN_OPTIONS = new HashSet<>(Arrays.asList(READ, WRITE, CREATE, SYNC)); private static final Logger LOGGER = LoggerFactory.getLogger(FileLockBasedLockChecker.class); @@ -54,7 +54,9 @@ public synchronized boolean isLockFree(int id) { // if we can acquire a shared lock, nobody has an exclusive lock try (final FileLock fileLock = channel.tryLock(0, Long.MAX_VALUE, true)) { if (fileLock != null && fileLock.isValid()) { - lockFile.delete(); // clean up the orphaned lock file + if (!lockFile.delete()) { // try and clean up the orphaned lock file + LOGGER.debug("Couldn't delete orphaned lock file " + lockFile); + } return true; } else { // another process has an exclusive lock @@ -102,7 +104,7 @@ public synchronized boolean obtainLock(int id, String metaInfo) throws IOExcepti */ private LockReference tryAcquireLockOnFile(int id, String metaInfo) throws IOException, ConcurrentLockFileDeletionException { final File lockFile = toFile(id); - final FileChannel fileChannel = FileChannel.open(lockFile.toPath(), LOCK_FILE_OPEN_OPTIONS, LOCK_FILE_ATTRIBUTES); + final FileChannel fileChannel = FileChannel.open(lockFile.toPath(), LOCK_FILE_OPEN_OPTIONS, LOCK_FILE_ATTRIBUTES); // NOSONAR final FileLock fileLock = fileChannel.tryLock(0, Long.MAX_VALUE, false); if (fileLock == null) { // someone else has a lock (exclusive or shared), fail to acquire @@ -122,7 +124,7 @@ private LockReference tryAcquireLockOnFile(int id, String metaInfo) throws IOExc } private void writeMetaInfoToFile(FileChannel fc, String metaInfo) throws IOException { - byte[] content = String.format("%s%n%s", metaInfo, df.format(new Date())).getBytes(); + byte[] content = String.format("%s%n%s", metaInfo, dfTL.get().format(new Date())).getBytes(); ByteBuffer buffer = ByteBuffer.wrap(content); while (buffer.hasRemaining()) { fc.write(buffer); diff --git a/affinity/src/main/java/net/openhft/affinity/main/AffinityTestMain.java b/affinity/src/main/java/net/openhft/affinity/main/AffinityTestMain.java index ef9070316..cae66db53 100644 --- a/affinity/src/main/java/net/openhft/affinity/main/AffinityTestMain.java +++ b/affinity/src/main/java/net/openhft/affinity/main/AffinityTestMain.java @@ -10,7 +10,6 @@ * @author Tom Shercliff */ public class AffinityTestMain { - private static final SimpleDateFormat df = new SimpleDateFormat("yyyy.MM" + ".dd 'at' HH:mm:ss z"); public static void main(String[] args) { @@ -28,21 +27,19 @@ public static void main(String[] args) { private static void acquireAndDoWork() { - Thread t = new Thread(new Runnable() { - @Override - public void run() { - try (AffinityLock al = Affinity.acquireLock()) { - String threadName = Thread.currentThread().getName(); - System.out.println("Thread (" + threadName + ") locked onto cpu " + al.cpuId()); - - while (true) { - System.out.println(df.format(new Date()) + " - Thread (" + threadName + ") doing work on cpu " + al.cpuId() + ". IsAllocated = " + al.isAllocated() + ", isBound = " + al.isBound() + ". " + al.toString()); - - try { - Thread.sleep(10000L); - } catch (InterruptedException e) { - //nothing - } + Thread t = new Thread(() -> { + final SimpleDateFormat df = new SimpleDateFormat("yyyy.MM" + ".dd 'at' HH:mm:ss z"); + try (AffinityLock al = Affinity.acquireLock()) { + String threadName = Thread.currentThread().getName(); + System.out.println("Thread (" + threadName + ") locked onto cpu " + al.cpuId()); + + while (true) { + System.out.println(df.format(new Date()) + " - Thread (" + threadName + ") doing work on cpu " + al.cpuId() + ". IsAllocated = " + al.isAllocated() + ", isBound = " + al.isBound() + ". " + al.toString()); + + try { + Thread.sleep(10000L); + } catch (InterruptedException e) { + //nothing } } } From bde620b15a2c2fa29c9096a374e545bd8e362c31 Mon Sep 17 00:00:00 2001 From: Peter Lawrwy Date: Sat, 30 Oct 2021 21:42:59 +0100 Subject: [PATCH 182/353] Skip test on mac. --- .../src/test/java/net/openhft/affinity/AffinityLockTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java index 80ff1fc77..92991fc79 100644 --- a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java +++ b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java @@ -151,6 +151,7 @@ public void assignReleaseThread() throws IOException { @Test public void resetAffinity() { + assumeTrue(System.getProperty("os.name").contains("nux")); assertTrue(Affinity.getAffinity().cardinality() > 1); try (AffinityLock lock = AffinityLock.acquireLock()) { assertEquals(1, Affinity.getAffinity().cardinality()); From a8b1a2248faa5b1cbfabaefaf6e190616836da3c Mon Sep 17 00:00:00 2001 From: Nick Tindall Date: Fri, 29 Oct 2021 17:17:17 +1100 Subject: [PATCH 183/353] Handle OverlappingFileLockException --- .../lockchecker/FileLockBasedLockChecker.java | 46 +++++++++++++------ 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java b/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java index 1f84c834f..a6eb4e983 100644 --- a/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java +++ b/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java @@ -9,6 +9,7 @@ import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import java.nio.channels.FileLock; +import java.nio.channels.OverlappingFileLockException; import java.nio.file.NoSuchFileException; import java.nio.file.OpenOption; import java.nio.file.attribute.FileAttribute; @@ -62,6 +63,14 @@ public synchronized boolean isLockFree(int id) { // another process has an exclusive lock return false; } + } catch (OverlappingFileLockException e) { + // someone else (in the same JVM) has an exclusive lock + /* + * This shouldn't happen under normal circumstances, we have the singleton + * {@link #locks} array to prevent overlapping locks from the same JVM, but + * it can occur when there are multiple classloaders in the JVM + */ + return false; } } catch (NoSuchFileException e) { // no lock file exists, nobody has the lock @@ -105,21 +114,32 @@ public synchronized boolean obtainLock(int id, String metaInfo) throws IOExcepti private LockReference tryAcquireLockOnFile(int id, String metaInfo) throws IOException, ConcurrentLockFileDeletionException { final File lockFile = toFile(id); final FileChannel fileChannel = FileChannel.open(lockFile.toPath(), LOCK_FILE_OPEN_OPTIONS, LOCK_FILE_ATTRIBUTES); // NOSONAR - final FileLock fileLock = fileChannel.tryLock(0, Long.MAX_VALUE, false); - if (fileLock == null) { - // someone else has a lock (exclusive or shared), fail to acquire - closeQuietly(fileChannel); - return null; - } else { - if (!lockFile.exists()) { - // someone deleted the file between us opening it and acquiring the lock, signal to retry - closeQuietly(fileLock, fileChannel); - throw new ConcurrentLockFileDeletionException(); + try { + final FileLock fileLock = fileChannel.tryLock(0, Long.MAX_VALUE, false); + if (fileLock == null) { + // someone else has a lock (exclusive or shared), fail to acquire + closeQuietly(fileChannel); + return null; } else { - // we have the lock, the file exists. That's success. - writeMetaInfoToFile(fileChannel, metaInfo); - return new LockReference(fileChannel, fileLock); + if (!lockFile.exists()) { + // someone deleted the file between us opening it and acquiring the lock, signal to retry + closeQuietly(fileLock, fileChannel); + throw new ConcurrentLockFileDeletionException(); + } else { + // we have the lock, the file exists. That's success. + writeMetaInfoToFile(fileChannel, metaInfo); + return new LockReference(fileChannel, fileLock); + } } + } catch (OverlappingFileLockException e) { + // someone else (in the same JVM) has a lock, fail to acquire + /* + * This shouldn't happen under normal circumstances, we have the singleton + * {@link #locks} array to prevent overlapping locks from the same JVM, but + * it can occur when there are multiple classloaders in the JVM + */ + closeQuietly(fileChannel); + return null; } } From 754b6b55e236adce1f45586f93c5ff384b491038 Mon Sep 17 00:00:00 2001 From: Nick Tindall Date: Wed, 3 Nov 2021 10:21:15 +1100 Subject: [PATCH 184/353] Make Makefile executable again --- affinity/src/main/c/Makefile | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 affinity/src/main/c/Makefile diff --git a/affinity/src/main/c/Makefile b/affinity/src/main/c/Makefile old mode 100644 new mode 100755 From dc2eb2f4f08a6badf555adb5679f6bf1f0b98a72 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Wed, 3 Nov 2021 21:04:00 +0100 Subject: [PATCH 185/353] Updating to bom version 2.22ea50 From f8fef3984d273d8de9efc41492187238cc10c4e9 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Wed, 3 Nov 2021 21:04:21 +0100 Subject: [PATCH 186/353] [maven-release-plugin] prepare release Java-Thread-Affinity-3.21ea82 --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 9 ++++----- pom.xml | 9 ++++----- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index d729240c3..ae5abd3b8 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.21ea82-SNAPSHOT + 3.21ea82 bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:https://github.com/OpenHFT/Java-Thread-Affinity.git - HEAD + Java-Thread-Affinity-3.21ea82 diff --git a/affinity/pom.xml b/affinity/pom.xml index a1f84a169..8683bf411 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -15,19 +15,18 @@ ~ limitations under the License. --> - + 4.0.0 net.openhft java-parent-pom 1.1.26 - + affinity - 3.21ea82-SNAPSHOT + 3.21ea82 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -254,7 +253,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.21ea82 diff --git a/pom.xml b/pom.xml index 8e3824fa9..df7a6b4f2 100644 --- a/pom.xml +++ b/pom.xml @@ -15,19 +15,18 @@ ~ limitations under the License. --> - + 4.0.0 net.openhft root-parent-pom 1.2.13 - + Java-Thread-Affinity - 3.21ea82-SNAPSHOT + 3.21ea82 pom OpenHFT/Java-Thread-Affinity Parent @@ -43,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.21ea82 From 72e3264fb0e6209133d0ec5d0f9fb15fbbc24206 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Wed, 3 Nov 2021 21:04:24 +0100 Subject: [PATCH 187/353] [maven-release-plugin] prepare for next development iteration --- affinity-test/pom.xml | 8 +++++--- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index ae5abd3b8..606fa9505 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.21ea82 + 3.21ea83-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -202,8 +202,10 @@ - scm:git:https://github.com/OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.21ea82 + scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git + ea + scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git + scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git diff --git a/affinity/pom.xml b/affinity/pom.xml index 8683bf411..ffddf67c1 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.21ea82 + 3.21ea83-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity @@ -253,7 +253,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.21ea82 + ea diff --git a/pom.xml b/pom.xml index df7a6b4f2..466f12800 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.21ea82 + 3.21ea83-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.21ea82 + ea From 9bdca1a83891864fa7c8d19b5fc610242b0df4d0 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Wed, 3 Nov 2021 21:04:40 +0100 Subject: [PATCH 188/353] Reverting back to bom version 2.22ea-SNAPSHOT From b1179db2b8e30d4d4b70e1067957885c302c4704 Mon Sep 17 00:00:00 2001 From: Nick Tindall Date: Thu, 18 Nov 2021 08:39:46 +1100 Subject: [PATCH 189/353] Use ProcessRunner from chronicle-test-framework --- affinity/pom.xml | 14 +- .../affinity/MultiProcessAffinityTest.java | 2 +- .../affinity/common/ProcessRunner.java | 127 ------------------ 3 files changed, 14 insertions(+), 129 deletions(-) delete mode 100644 affinity/src/test/java/net/openhft/affinity/common/ProcessRunner.java diff --git a/affinity/pom.xml b/affinity/pom.xml index ffddf67c1..98410fa76 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -43,7 +43,14 @@ net.openhft third-party-bom pom - 3.19.10 + 3.22.1 + import + + + net.openhft + chronicle-bom + 2.22ea-SNAPSHOT + pom import @@ -82,6 +89,11 @@ slf4j-simple test + + net.openhft + chronicle-test-framework + test + diff --git a/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java b/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java index 30bb03a53..a3914f1db 100644 --- a/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java +++ b/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java @@ -1,7 +1,7 @@ package net.openhft.affinity; -import net.openhft.affinity.common.ProcessRunner; import net.openhft.affinity.testimpl.TestFileLockBasedLockChecker; +import net.openhft.chronicle.testframework.process.ProcessRunner; import org.jetbrains.annotations.NotNull; import org.junit.Assume; import org.junit.Before; diff --git a/affinity/src/test/java/net/openhft/affinity/common/ProcessRunner.java b/affinity/src/test/java/net/openhft/affinity/common/ProcessRunner.java deleted file mode 100644 index 73169e020..000000000 --- a/affinity/src/test/java/net/openhft/affinity/common/ProcessRunner.java +++ /dev/null @@ -1,127 +0,0 @@ -package net.openhft.affinity.common; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.lang.management.ManagementFactory; -import java.lang.management.RuntimeMXBean; -import java.nio.charset.Charset; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -public class ProcessRunner { - - private static final Logger LOGGER = LoggerFactory.getLogger(ProcessRunner.class); - - /** - * Spawn a process running the main method of a specified class - * - * @param clazz The class to execute - * @param args Any arguments to pass to the process - * @return the Process spawned - * @throws IOException if there is an error starting the process - */ - public static Process runClass(Class clazz, String... args) throws IOException { - return runClass(clazz, new String[]{}, args); - } - - /** - * Spawn a process running the main method of a specified class - * - * @param clazz The class to execute - * @param jvmArgs Any arguments to pass to the process - * @param programArgs Any arguments to pass to the process - * @return the Process spawned - * @throws IOException if there is an error starting the process - */ - public static Process runClass(Class clazz, String[] jvmArgs, String[] programArgs) throws IOException { - // Because Java17 must be run using various module flags, these must be propagated - // to the child processes - // https://stackoverflow.com/questions/1490869/how-to-get-vm-arguments-from-inside-of-java-application - final RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean(); - - // filter out javaagent params, or this confuses the IntelliJ debugger - final List jvmArgsWithoutJavaAgents = runtimeMxBean.getInputArguments().stream() - .filter(arg -> !arg.startsWith("-javaagent:")) - .filter(arg -> !arg.startsWith("-agentlib:")) - .collect(Collectors.toList()); - - String classPath = System.getProperty("java.class.path"); - String className = clazz.getName(); - String javaBin = findJavaBinPath().toString(); - List allArgs = new ArrayList<>(); - allArgs.add(javaBin); - allArgs.addAll(jvmArgsWithoutJavaAgents); - allArgs.addAll(Arrays.asList(jvmArgs)); - allArgs.add("-cp"); - allArgs.add(classPath); - allArgs.add(className); - allArgs.addAll(Arrays.asList(programArgs)); - ProcessBuilder processBuilder = new ProcessBuilder(allArgs.toArray(new String[]{})); -// processBuilder.inheritIO(); // this doesn't place nice with surefire - return processBuilder.start(); - } - - /** - * Log stdout and stderr for a process - *

    - * ProcessBuilder.inheritIO() didn't play nicely with Maven failsafe plugin - *

    - * https://maven.apache.org/surefire/maven-failsafe-plugin/faq.html#corruptedstream - */ - public static void printProcessOutput(String processName, Process process) { - LOGGER.info("\n" - + "Output for " + processName + "\n" - + "stdout:\n" - + copyStreamToString(process.getInputStream()) + "\n" - + "stderr:\n" - + copyStreamToString(process.getErrorStream())); - } - - /** - * Copies a stream to a string, up to the point where reading more would block - * - * @param inputStream The stream to read from - * @return The output as a string - */ - private static String copyStreamToString(InputStream inputStream) { - ByteArrayOutputStream os = new ByteArrayOutputStream(); - byte[] buffer = new byte[1024]; - int read; - try { - while (inputStream.available() > 0 && (read = inputStream.read(buffer)) >= 0) { - os.write(buffer, 0, read); - } - } catch (IOException e) { - // Ignore - } - return new String(os.toByteArray(), Charset.defaultCharset()); - } - - /** - * Try and work out what the java executable is cross platform - * - * @return the Path to the java executable - * @throws IllegalStateException if the executable couldn't be located - */ - private static Path findJavaBinPath() { - final Path javaBinPath = Paths.get(System.getProperty("java.home")).resolve("bin"); - final Path linuxJavaExecutable = javaBinPath.resolve("java"); - if (linuxJavaExecutable.toFile().exists()) { - return linuxJavaExecutable; - } else { - Path windowsJavaExecutable = javaBinPath.resolve("java.exe"); - if (windowsJavaExecutable.toFile().exists()) { - return windowsJavaExecutable; - } - } - throw new IllegalStateException("Couldn't locate java executable!"); - } -} From 48da7af23ee5ef1e96985a72988b5ad4822cfb65 Mon Sep 17 00:00:00 2001 From: Jerry Shea Date: Mon, 6 Dec 2021 08:43:54 +1100 Subject: [PATCH 190/353] latest java-parent-pom --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 606fa9505..627d05365 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.1.26 + 1.1.29 diff --git a/affinity/pom.xml b/affinity/pom.xml index 98410fa76..e22b6af0c 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.1.26 + 1.1.29 From 49f7b7a5ba05925a90780fb021b3238d5de98c06 Mon Sep 17 00:00:00 2001 From: Ilya Kaznacheev Date: Fri, 21 Jan 2022 13:06:25 +0300 Subject: [PATCH 191/353] Support oligocore agents --- .../test/java/net/openhft/affinity/FileLockLockCheckTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/src/test/java/net/openhft/affinity/FileLockLockCheckTest.java b/affinity/src/test/java/net/openhft/affinity/FileLockLockCheckTest.java index 7268f26c6..5f39b87ce 100644 --- a/affinity/src/test/java/net/openhft/affinity/FileLockLockCheckTest.java +++ b/affinity/src/test/java/net/openhft/affinity/FileLockLockCheckTest.java @@ -35,7 +35,7 @@ public class FileLockLockCheckTest extends BaseAffinityTest { private final TestFileLockBasedLockChecker lockChecker = new TestFileLockBasedLockChecker(); - private int cpu = 11; + private int cpu = 5; @Before public void before() { From 5b3fa81975d18fae1b62d9734933eb7d9f6ac984 Mon Sep 17 00:00:00 2001 From: Nick Tindall Date: Mon, 31 Jan 2022 16:11:59 +1100 Subject: [PATCH 192/353] Allow use of descriptive core names for MicroJitterSampler affinity --- .../main/java/net/openhft/affinity/MicroJitterSampler.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java b/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java index d637640bb..696479b5f 100644 --- a/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java +++ b/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java @@ -34,7 +34,7 @@ public class MicroJitterSampler { }; private static final double UTIL = Double.parseDouble(System.getProperty("util", "50")); private static final boolean BUSYWAIT = Boolean.parseBoolean(System.getProperty("busywait", "false")); - private static final int CPU = Integer.parseInt(System.getProperty("cpu", "-1")); + private static final String CPU = System.getProperty("cpu", "none"); private final int[] count = new int[DELAY.length]; private long totalTime = 0; @@ -71,10 +71,7 @@ private void once() throws InterruptedException { } public void run() { - if (CPU != -1) - Affinity.setAffinity(CPU); - - try { + try (final AffinityLock lock = AffinityLock.acquireLock(CPU)) { boolean first = true; System.out.println("Warming up..."); while (!Thread.currentThread().isInterrupted()) { From fe7533072b768de4978d27167f651fd4ee6e5715 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Mon, 31 Jan 2022 17:52:57 +0000 Subject: [PATCH 193/353] Updating to bom version 2.22ea99 --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index e22b6af0c..72da8b21a 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.22ea-SNAPSHOT + 2.22ea99 pom import From aa97cd5d2c2b327332d0ef47bdda96809cbe7e27 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Mon, 31 Jan 2022 17:53:18 +0000 Subject: [PATCH 194/353] [maven-release-plugin] prepare release Java-Thread-Affinity-3.21ea83 --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 627d05365..853af3907 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.21ea83-SNAPSHOT + 3.21ea83 bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.21ea83 scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git diff --git a/affinity/pom.xml b/affinity/pom.xml index 72da8b21a..70aa37b74 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.21ea83-SNAPSHOT + 3.21ea83 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -265,7 +265,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.21ea83 diff --git a/pom.xml b/pom.xml index 466f12800..d7038e25d 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.21ea83-SNAPSHOT + 3.21ea83 pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.21ea83 From 06bc0b72370e5ed0be7beffeda02a197b08526a0 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Mon, 31 Jan 2022 17:53:21 +0000 Subject: [PATCH 195/353] [maven-release-plugin] prepare for next development iteration --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 853af3907..18452bf9a 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.21ea83 + 3.21ea84-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.21ea83 + ea scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git diff --git a/affinity/pom.xml b/affinity/pom.xml index 70aa37b74..06e4a7503 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.21ea83 + 3.21ea84-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity @@ -265,7 +265,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.21ea83 + ea diff --git a/pom.xml b/pom.xml index d7038e25d..b3ff64b9d 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.21ea83 + 3.21ea84-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.21ea83 + ea From e33976b81dafa367f4ea44dfef28878637eea6ba Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Mon, 31 Jan 2022 17:53:36 +0000 Subject: [PATCH 196/353] Reverting back to bom version 2.22ea-SNAPSHOT --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index 06e4a7503..f51ea293e 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.22ea99 + 2.22ea-SNAPSHOT pom import From 8da4b622453cac49dca3424653cdfd83a6d476e9 Mon Sep 17 00:00:00 2001 From: Ilya Kaznacheev Date: Wed, 2 Feb 2022 17:39:36 +0300 Subject: [PATCH 197/353] Use javac -h for C headers generation --- affinity/pom.xml | 6 +++++- affinity/src/main/c/Makefile | 10 ++-------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index f51ea293e..20d066339 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -175,7 +175,11 @@ org.apache.maven.plugins maven-compiler-plugin - -Xlint:deprecation + + -h + ${project.build.directory}/jni + -Xlint:deprecation + 1.8 1.8 UTF-8 diff --git a/affinity/src/main/c/Makefile b/affinity/src/main/c/Makefile index 58a06e53a..0138fe1af 100755 --- a/affinity/src/main/c/Makefile +++ b/affinity/src/main/c/Makefile @@ -13,15 +13,13 @@ WORKING_DIR := $(TARGET_DIR)/../jni JAVA_CLASSES = software.chronicle.enterprise.internals.impl.NativeAffinity net.openhft.ticker.impl.JNIClock JNI_STUBS := $(subst .,_,$(JAVA_CLASSES)) -JNI_HEADERS := $(patsubst %,$(WORKING_DIR)/%.h,$(JNI_STUBS)) JNI_SOURCES := $(patsubst %,%.cpp,$(JNI_STUBS)) -JNI_JAVA_SOURCES := $(patsubst %,$(TARGET_DIR)/%.class,$(subst .,/,$(JAVA_CLASSES))) JAVA_BUILD_DIR := $(TARGET_DIR) JAVA_HOME ?= /usr/java/default JAVA_LIB := $(JAVA_HOME)/jre/lib -JVM_SHARED_LIBS := -L$(JAVA_LIB)/amd64/server -L$(JAVA_LIB)/i386/server -L$(JAVA_LIB)/amd64/jrockit/ -L$(JAVA_LIB)/i386/jrockit/ -L$(JAVA_LIB)/ppc64le/server -L$(JAVA_LIB)/ppc64le/jrockit/ +JVM_SHARED_LIBS := -L$(JAVA_LIB)/amd64/server -L$(JAVA_LIB)/i386/server -L$(JAVA_LIB)/amd64/jrockit/ -L$(JAVA_LIB)/i386/jrockit/ -L$(JAVA_LIB)/ppc64le/server -L$(JAVA_LIB)/ppc64le/jrockit/ -L$(JAVA_HOME)/lib/server CXX=g++ INCLUDES := -I $(JAVA_HOME)/include -I $(JAVA_HOME)/include/linux -I $(WORKING_DIR) @@ -37,12 +35,8 @@ endif all: $(TARGET) -$(TARGET): $(JNI_HEADERS) $(JNI_SOURCES) +$(TARGET): $(JNI_SOURCES) $(CXX) -O3 -Wall -shared -fPIC $(JVM_SHARED_LIBS) -ljvm -lrt $(INCLUDES) $(JNI_SOURCES) -o $(TARGET) -$(JNI_HEADERS): $(JNI_JAVA_SOURCES) - mkdir -p $(TARGET_DIR)/jni - javah -force -classpath $(JAVAH_CLASSPATH) -d $(WORKING_DIR) $(JAVA_CLASSES) - clean: rm $(TARGET) From 1965f0283c21b9b9a8ad5fc41112753a9d747832 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Wed, 9 Feb 2022 12:28:37 +0000 Subject: [PATCH 198/353] Third-party-bom v 3.22.3 --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 18452bf9a..5cc1e1e59 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -42,7 +42,7 @@ net.openhft third-party-bom pom - 3.19.10 + 3.22.3 import diff --git a/affinity/pom.xml b/affinity/pom.xml index 20d066339..ae863ac0c 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -43,7 +43,7 @@ net.openhft third-party-bom pom - 3.22.1 + 3.22.3 import From 82dc0bb50ee729a135798977c07100a1e80fcab3 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Wed, 9 Feb 2022 16:57:08 +0000 Subject: [PATCH 199/353] Bump org.apache.felix.framework to 7.0.3 https://github.com/OpenHFT/OpenHFT/issues/69 --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 5cc1e1e59..9ca5af3f6 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -42,7 +42,7 @@ net.openhft third-party-bom pom - 3.22.3 + 3.22.4-SNAPSHOT import diff --git a/affinity/pom.xml b/affinity/pom.xml index ae863ac0c..30af7a8ee 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -43,7 +43,7 @@ net.openhft third-party-bom pom - 3.22.3 + 3.22.4-SNAPSHOT import From 8df6c63cbf0741d23abf6e34b07523a22ae179c2 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Tue, 12 Apr 2022 12:51:20 +0100 Subject: [PATCH 200/353] 'Updating parent POM (automated)' --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 9ca5af3f6..564fae94a 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.1.29 + 1.1.31 diff --git a/affinity/pom.xml b/affinity/pom.xml index 30af7a8ee..b67e5bcb8 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.1.29 + 1.1.31 diff --git a/pom.xml b/pom.xml index b3ff64b9d..d91d0b47a 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ net.openhft root-parent-pom - 1.2.13 + 1.2.18 From 323b3daeea2af568cf2b7e3e6b6e894088f01f09 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Wed, 1 Jun 2022 05:24:34 +0100 Subject: [PATCH 201/353] Updating parent POM (automated) --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 564fae94a..659641a06 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.1.31 + 1.1.32 diff --git a/affinity/pom.xml b/affinity/pom.xml index b67e5bcb8..0e2af0fdc 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.1.31 + 1.1.32 diff --git a/pom.xml b/pom.xml index d91d0b47a..c13c5bc36 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ net.openhft root-parent-pom - 1.2.18 + 1.2.20 From 2ceef30aaaa88678d73f138aaf627921e79cbc83 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Mon, 6 Jun 2022 07:32:03 +0100 Subject: [PATCH 202/353] Updating parent POM (automated) --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 659641a06..919c1b1f6 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.1.32 + 1.1.33 diff --git a/affinity/pom.xml b/affinity/pom.xml index 0e2af0fdc..b58029abd 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.1.32 + 1.1.33 diff --git a/pom.xml b/pom.xml index c13c5bc36..293d771e9 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ net.openhft root-parent-pom - 1.2.20 + 1.2.21 From 20d58159a24d651907db5a3d2e251a2fe2b7b846 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Thu, 28 Jul 2022 14:21:56 +0100 Subject: [PATCH 203/353] Handle ClosedByInterruptException for when acquireLock() is interrupted #92 --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- .../net/openhft/affinity/LockInventory.java | 65 ++++++++++++------- pom.xml | 2 +- 4 files changed, 46 insertions(+), 25 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 919c1b1f6..ca58fd9df 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.21ea84-SNAPSHOT + 3.23ea0-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test diff --git a/affinity/pom.xml b/affinity/pom.xml index b58029abd..f1aa7bb3e 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.21ea84-SNAPSHOT + 3.23ea0-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity diff --git a/affinity/src/main/java/net/openhft/affinity/LockInventory.java b/affinity/src/main/java/net/openhft/affinity/LockInventory.java index 6a68b1321..304c6b45f 100644 --- a/affinity/src/main/java/net/openhft/affinity/LockInventory.java +++ b/affinity/src/main/java/net/openhft/affinity/LockInventory.java @@ -23,6 +23,7 @@ import org.slf4j.LoggerFactory; import java.io.IOException; +import java.nio.channels.ClosedByInterruptException; import java.util.NavigableMap; import java.util.TreeMap; @@ -78,12 +79,15 @@ private static boolean isAnyCpu(final int cpuId) { * @param wholeCore Whether to bind the whole core * @return true if the lock was acquired, false otherwise */ - private static boolean updateLockForCurrentThread(final boolean bind, final AffinityLock al, final boolean wholeCore) { + private static boolean updateLockForCurrentThread(final boolean bind, final AffinityLock al, final boolean wholeCore) throws ClosedByInterruptException { try { if (LockCheck.updateCpu(al.cpuId())) { al.assignCurrentThread(bind, wholeCore); return true; } + } catch (ClosedByInterruptException e) { + throw e; + } catch (IOException e) { LOGGER.warn("Error occurred acquiring lock", e); } @@ -120,30 +124,36 @@ public final synchronized AffinityLock acquireLock(boolean bind, int cpuId, Affi return noLock(); final boolean specificCpuRequested = !isAnyCpu(cpuId); - if (specificCpuRequested && cpuId != 0) { - final AffinityLock required = logicalCoreLocks[cpuId]; - if (required.canReserve(true) - && anyStrategyMatches(cpuId, cpuId, strategies) - && updateLockForCurrentThread(bind, required, false)) { - return required; + try { + if (specificCpuRequested && cpuId != 0) { + final AffinityLock required = logicalCoreLocks[cpuId]; + if (required.canReserve(true) + && anyStrategyMatches(cpuId, cpuId, strategies) + && updateLockForCurrentThread(bind, required, false)) { + return required; + } + LOGGER.warn("Unable to acquire lock on CPU {} for thread {}, trying to find another CPU", + cpuId, Thread.currentThread()); } - LOGGER.warn("Unable to acquire lock on CPU {} for thread {}, trying to find another CPU", - cpuId, Thread.currentThread()); - } - for (AffinityStrategy strategy : strategies) { - // consider all processors except cpu 0 which is usually used by the OS. - // if you have only one core, this library is not appropriate in any case. - for (int i = logicalCoreLocks.length - 1; i > 0; i--) { - AffinityLock al = logicalCoreLocks[i]; - if (al.canReserve(false) - && (isAnyCpu(cpuId) || strategy.matches(cpuId, al.cpuId())) - && updateLockForCurrentThread(bind, al, false)) { - return al; + for (AffinityStrategy strategy : strategies) { + // consider all processors except cpu 0 which is usually used by the OS. + // if you have only one core, this library is not appropriate in any case. + for (int i = logicalCoreLocks.length - 1; i > 0; i--) { + AffinityLock al = logicalCoreLocks[i]; + if (al.canReserve(false) + && (isAnyCpu(cpuId) || strategy.matches(cpuId, al.cpuId())) + && updateLockForCurrentThread(bind, al, false)) { + return al; + } } } + } catch (ClosedByInterruptException e) { + Thread.currentThread().interrupt(); + return noLock(); } + LOGGER.warn("No reservable CPU for {}", Thread.currentThread()); return noLock(); @@ -154,11 +164,17 @@ public final synchronized AffinityLock tryAcquireLock(boolean bind, int cpuId) { return null; final AffinityLock required = logicalCoreLocks[cpuId]; - if (required.canReserve(true) - && updateLockForCurrentThread(bind, required, false)) { - return required; + try { + if (required.canReserve(true) + && updateLockForCurrentThread(bind, required, false)) { + return required; + } + } catch (ClosedByInterruptException e) { + Thread.currentThread().interrupt(); + return noLock(); } + LOGGER.warn("Unable to acquire lock on CPU {} for thread {}, trying to find another CPU", cpuId, Thread.currentThread()); @@ -174,9 +190,14 @@ public final synchronized AffinityLock acquireCore(boolean bind, int cpuId, Affi continue LOOP; final AffinityLock al = als[0]; + try { if (updateLockForCurrentThread(bind, al, true)) { return al; } + } catch (ClosedByInterruptException e) { + Thread.currentThread().interrupt(); + return noLock(); + } } } diff --git a/pom.xml b/pom.xml index 293d771e9..9d4bf8f84 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.21ea84-SNAPSHOT + 3.23ea0-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent From 1e4bbc6dba8d516fbfc3511f13c381df9f6ed76d Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Wed, 3 Aug 2022 14:36:00 +0100 Subject: [PATCH 204/353] Added Copyright headers --- .../openhft/affinity/MicroJitterSampler.java | 4 ++-- .../lockchecker/FileLockBasedLockChecker.java | 18 ++++++++++++++++++ .../affinity/lockchecker/LockChecker.java | 18 ++++++++++++++++++ .../affinity/lockchecker/LockReference.java | 18 ++++++++++++++++++ .../affinity/main/AffinityTestMain.java | 18 ++++++++++++++++++ .../net/openhft/affinity/BaseAffinityTest.java | 18 ++++++++++++++++++ .../openhft/affinity/BootClassPathTest.java | 18 ++++++++++++++++++ .../affinity/MultiProcessAffinityTest.java | 18 ++++++++++++++++++ .../testimpl/TestFileLockBasedLockChecker.java | 18 ++++++++++++++++++ 9 files changed, 146 insertions(+), 2 deletions(-) diff --git a/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java b/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java index 696479b5f..c2a8ef3aa 100644 --- a/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java +++ b/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java @@ -1,13 +1,13 @@ /* * Copyright 2014 Higher Frequency Trading * - * http://chronicle.software + * https://chronicle.software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java b/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java index a6eb4e983..77095375c 100644 --- a/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java +++ b/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java @@ -1,3 +1,21 @@ +/* + * Copyright 2016-2022 chronicle.software + * + * https://chronicle.software + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package net.openhft.affinity.lockchecker; import org.jetbrains.annotations.NotNull; diff --git a/affinity/src/main/java/net/openhft/affinity/lockchecker/LockChecker.java b/affinity/src/main/java/net/openhft/affinity/lockchecker/LockChecker.java index 0c95c335f..f0a02f6d5 100644 --- a/affinity/src/main/java/net/openhft/affinity/lockchecker/LockChecker.java +++ b/affinity/src/main/java/net/openhft/affinity/lockchecker/LockChecker.java @@ -1,3 +1,21 @@ +/* + * Copyright 2016-2022 chronicle.software + * + * https://chronicle.software + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package net.openhft.affinity.lockchecker; import java.io.IOException; diff --git a/affinity/src/main/java/net/openhft/affinity/lockchecker/LockReference.java b/affinity/src/main/java/net/openhft/affinity/lockchecker/LockReference.java index d5ed1c707..419073fe6 100644 --- a/affinity/src/main/java/net/openhft/affinity/lockchecker/LockReference.java +++ b/affinity/src/main/java/net/openhft/affinity/lockchecker/LockReference.java @@ -1,3 +1,21 @@ +/* + * Copyright 2016-2022 chronicle.software + * + * https://chronicle.software + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package net.openhft.affinity.lockchecker; import java.nio.channels.FileChannel; diff --git a/affinity/src/main/java/net/openhft/affinity/main/AffinityTestMain.java b/affinity/src/main/java/net/openhft/affinity/main/AffinityTestMain.java index cae66db53..6aa280014 100644 --- a/affinity/src/main/java/net/openhft/affinity/main/AffinityTestMain.java +++ b/affinity/src/main/java/net/openhft/affinity/main/AffinityTestMain.java @@ -1,3 +1,21 @@ +/* + * Copyright 2016-2022 chronicle.software + * + * https://chronicle.software + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package net.openhft.affinity.main; import net.openhft.affinity.Affinity; diff --git a/affinity/src/test/java/net/openhft/affinity/BaseAffinityTest.java b/affinity/src/test/java/net/openhft/affinity/BaseAffinityTest.java index 9728f32a4..5bfeacf95 100644 --- a/affinity/src/test/java/net/openhft/affinity/BaseAffinityTest.java +++ b/affinity/src/test/java/net/openhft/affinity/BaseAffinityTest.java @@ -1,3 +1,21 @@ +/* + * Copyright 2016-2022 chronicle.software + * + * https://chronicle.software + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package net.openhft.affinity; import org.junit.After; diff --git a/affinity/src/test/java/net/openhft/affinity/BootClassPathTest.java b/affinity/src/test/java/net/openhft/affinity/BootClassPathTest.java index 6c101e18e..d4c555938 100644 --- a/affinity/src/test/java/net/openhft/affinity/BootClassPathTest.java +++ b/affinity/src/test/java/net/openhft/affinity/BootClassPathTest.java @@ -1,3 +1,21 @@ +/* + * Copyright 2016-2022 chronicle.software + * + * https://chronicle.software + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package net.openhft.affinity; import org.junit.Test; diff --git a/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java b/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java index a3914f1db..61f3fa33a 100644 --- a/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java +++ b/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java @@ -1,3 +1,21 @@ +/* + * Copyright 2016-2022 chronicle.software + * + * https://chronicle.software + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package net.openhft.affinity; import net.openhft.affinity.testimpl.TestFileLockBasedLockChecker; diff --git a/affinity/src/test/java/net/openhft/affinity/testimpl/TestFileLockBasedLockChecker.java b/affinity/src/test/java/net/openhft/affinity/testimpl/TestFileLockBasedLockChecker.java index 955be5d77..68b3f3566 100644 --- a/affinity/src/test/java/net/openhft/affinity/testimpl/TestFileLockBasedLockChecker.java +++ b/affinity/src/test/java/net/openhft/affinity/testimpl/TestFileLockBasedLockChecker.java @@ -1,3 +1,21 @@ +/* + * Copyright 2016-2022 chronicle.software + * + * https://chronicle.software + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package net.openhft.affinity.testimpl; import net.openhft.affinity.lockchecker.FileLockBasedLockChecker; From 1933c596ea18f498e6a1aa5823b099fa4904bcc3 Mon Sep 17 00:00:00 2001 From: Jerry Shea Date: Mon, 8 Aug 2022 10:49:39 +1000 Subject: [PATCH 205/353] log warning instead of throw exception for too high cpuId. Closes #93 --- .../java/net/openhft/affinity/LockInventory.java | 9 ++++++++- .../java/net/openhft/affinity/AffinityLockTest.java | 12 ++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/affinity/src/main/java/net/openhft/affinity/LockInventory.java b/affinity/src/main/java/net/openhft/affinity/LockInventory.java index 304c6b45f..ce15aebed 100644 --- a/affinity/src/main/java/net/openhft/affinity/LockInventory.java +++ b/affinity/src/main/java/net/openhft/affinity/LockInventory.java @@ -126,6 +126,12 @@ public final synchronized AffinityLock acquireLock(boolean bind, int cpuId, Affi final boolean specificCpuRequested = !isAnyCpu(cpuId); try { if (specificCpuRequested && cpuId != 0) { + if (cpuId > logicalCoreLocks.length) { + LOGGER.warn("Unable to acquire lock on CPU {} for thread {}, as not enough CPUs", + cpuId, Thread.currentThread()); + return noLock(); + } + final AffinityLock required = logicalCoreLocks[cpuId]; if (required.canReserve(true) && anyStrategyMatches(cpuId, cpuId, strategies) @@ -162,7 +168,8 @@ && updateLockForCurrentThread(bind, al, false)) { public final synchronized AffinityLock tryAcquireLock(boolean bind, int cpuId) { if (getAffinityImpl() instanceof NullAffinity) return null; - + if (cpuId > logicalCoreLocks.length) + return null; final AffinityLock required = logicalCoreLocks[cpuId]; try { if (required.canReserve(true) diff --git a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java index 92991fc79..a44716375 100644 --- a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java +++ b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java @@ -296,4 +296,16 @@ public void testAffinityLockDescriptions() { assertFalse(lock.bound); } } + + @Test + public void testTooHighCpuId() { + try (AffinityLock ignored = AffinityLock.acquireLock(123456)) { + } + } + + @Test + public void testTooHighCpuId2() { + try (AffinityLock ignored = AffinityLock.acquireLock(new int[] {123456})) { + } + } } From 404cd9cd595a14e3579b623b5cf2ab3c2798dc9f Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Mon, 8 Aug 2022 17:52:07 +0100 Subject: [PATCH 206/353] Updating to bom version 2.23ea104 --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index f1aa7bb3e..da506bb76 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.22ea-SNAPSHOT + 2.23ea104 pom import From 00807ffbd33323b2f0f54b5593610c9af172a99d Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Mon, 8 Aug 2022 17:52:34 +0100 Subject: [PATCH 207/353] [maven-release-plugin] prepare release Java-Thread-Affinity-3.23ea0 --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index ca58fd9df..1599c31da 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.23ea0-SNAPSHOT + 3.23ea0 bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.23ea0 scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git diff --git a/affinity/pom.xml b/affinity/pom.xml index da506bb76..cd3bf582f 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.23ea0-SNAPSHOT + 3.23ea0 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -269,7 +269,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.23ea0 diff --git a/pom.xml b/pom.xml index 9d4bf8f84..f1948f8e4 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.23ea0-SNAPSHOT + 3.23ea0 pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.23ea0 From ded1728e5b4fa29758be197b6dcb4840e7da8daf Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Mon, 8 Aug 2022 17:52:37 +0100 Subject: [PATCH 208/353] [maven-release-plugin] prepare for next development iteration --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 1599c31da..c603c89f8 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.23ea0 + 3.23ea1-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.23ea0 + ea scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git diff --git a/affinity/pom.xml b/affinity/pom.xml index cd3bf582f..aaf3d1485 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.23ea0 + 3.23ea1-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity @@ -269,7 +269,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.23ea0 + ea diff --git a/pom.xml b/pom.xml index f1948f8e4..2a0394833 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.23ea0 + 3.23ea1-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.23ea0 + ea From 09de384f68af3817989c82297abf702f020e0f8a Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Mon, 8 Aug 2022 17:52:51 +0100 Subject: [PATCH 209/353] Reverting back to bom version 2.23ea-SNAPSHOT --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index aaf3d1485..9b4a54b56 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.23ea104 + 2.23ea-SNAPSHOT pom import From 125ec45f376a3d6441d195a037dd5f18c063e554 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Wed, 24 Aug 2022 08:37:46 +0100 Subject: [PATCH 210/353] Bump maven-exec-plugin to 3.1.0 --- affinity/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/affinity/pom.xml b/affinity/pom.xml index 9b4a54b56..b456abb62 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -120,6 +120,7 @@ org.codehaus.mojo exec-maven-plugin + 3.1.0 From eae579be0d8980b48c43856711cbb11e56011b6f Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Mon, 5 Sep 2022 11:31:45 +0100 Subject: [PATCH 211/353] Delay producing a warning until a lock is actually used --- .../main/java/net/openhft/affinity/AffinityLock.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java index fc2eae07c..67642daf5 100644 --- a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java +++ b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java @@ -121,7 +121,6 @@ private static BitSet getReservedAffinity0() { reserverable.set(1, PROCESSORS, true); reserverable.andNot(BASE_AFFINITY); if (reserverable.isEmpty() && PROCESSORS > 1) { - LoggerFactory.getLogger(AffinityLock.class).info("No isolated CPUs found, so assuming CPUs 1 to {} available.", (PROCESSORS - 1)); // make all but first CPUs available reserverable.set(1, PROCESSORS); return reserverable; @@ -149,6 +148,14 @@ public static AffinityLock acquireLock() { return acquireLock(true); } + static class Warnings { + static void warmNoReservedCPUs() { + if (RESERVED_AFFINITY.isEmpty() && PROCESSORS > 1) { + LoggerFactory.getLogger(AffinityLock.class).info("No isolated CPUs found, so assuming CPUs 1 to {} available.", (PROCESSORS - 1)); + } + } + } + /** * Assign any free core to this thread.

    In reality, only one cpu is assigned, the rest of * the threads for that core are reservable so they are not used. @@ -294,6 +301,7 @@ public static AffinityLock acquireCore(boolean bind) { } private static AffinityLock acquireLock(boolean bind, int cpuId, @NotNull AffinityStrategy... strategies) { + Warnings.warmNoReservedCPUs(); return LOCK_INVENTORY.acquireLock(bind, cpuId, strategies); } @@ -310,6 +318,7 @@ private static AffinityLock tryAcquireLock(boolean bind, int cpuId) { } private static AffinityLock acquireCore(boolean bind, int cpuId, @NotNull AffinityStrategy... strategies) { + Warnings.warmNoReservedCPUs(); return LOCK_INVENTORY.acquireCore(bind, cpuId, strategies); } From 5f8cf471e44c666f80833d11b25783f62603258d Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Wed, 7 Sep 2022 07:20:09 +0100 Subject: [PATCH 212/353] Updating to bom version 2.23ea116 --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index b456abb62..03c143051 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.23ea-SNAPSHOT + 2.23ea116 pom import From 12c79a1fde0b09c3cdc4013a23b58528b877f926 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Wed, 7 Sep 2022 07:20:30 +0100 Subject: [PATCH 213/353] [maven-release-plugin] prepare release Java-Thread-Affinity-3.23ea1 --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index c603c89f8..fe88c793d 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.23ea1-SNAPSHOT + 3.23ea1 bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.23ea1 scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git diff --git a/affinity/pom.xml b/affinity/pom.xml index 03c143051..3e290daaf 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.23ea1-SNAPSHOT + 3.23ea1 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -270,7 +270,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.23ea1 diff --git a/pom.xml b/pom.xml index 2a0394833..e0df04c8f 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.23ea1-SNAPSHOT + 3.23ea1 pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.23ea1 From f318a1d90d503c8ee867c04f795f8fb56d491a25 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Wed, 7 Sep 2022 07:20:33 +0100 Subject: [PATCH 214/353] [maven-release-plugin] prepare for next development iteration --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index fe88c793d..20f3f4535 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.23ea1 + 3.23ea2-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.23ea1 + ea scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git diff --git a/affinity/pom.xml b/affinity/pom.xml index 3e290daaf..9485d323f 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.23ea1 + 3.23ea2-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity @@ -270,7 +270,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.23ea1 + ea diff --git a/pom.xml b/pom.xml index e0df04c8f..23c6815fa 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.23ea1 + 3.23ea2-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.23ea1 + ea From 515830b6006fe2c3a3571a2577103386d6a9ea97 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Wed, 7 Sep 2022 07:20:49 +0100 Subject: [PATCH 215/353] Reverting back to bom version 2.23ea-SNAPSHOT --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index 9485d323f..1331ddc7f 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.23ea116 + 2.23ea-SNAPSHOT pom import From 4fe6e86d3e25b625f874390c119c1e571ee7908f Mon Sep 17 00:00:00 2001 From: Jerry Shea Date: Thu, 29 Sep 2022 19:12:39 +1000 Subject: [PATCH 216/353] de-snapshot third-party-bom --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 20f3f4535..87d7a4d2d 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -42,7 +42,7 @@ net.openhft third-party-bom pom - 3.22.4-SNAPSHOT + 3.22.4 import diff --git a/affinity/pom.xml b/affinity/pom.xml index 1331ddc7f..e767d0ffa 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -43,7 +43,7 @@ net.openhft third-party-bom pom - 3.22.4-SNAPSHOT + 3.22.4 import From 77e83117e0164f1a7f08d3ad8c7e8652f27f19d6 Mon Sep 17 00:00:00 2001 From: Ilya Kaznacheev Date: Thu, 29 Sep 2022 13:50:41 +0300 Subject: [PATCH 217/353] Bump to new BOM version --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 4 ++-- pom.xml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 87d7a4d2d..564aef2ee 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.23ea2-SNAPSHOT + 3.24ea0-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test diff --git a/affinity/pom.xml b/affinity/pom.xml index e767d0ffa..6468d6586 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.23ea2-SNAPSHOT + 3.24ea0-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.23ea-SNAPSHOT + 2.24ea-SNAPSHOT pom import diff --git a/pom.xml b/pom.xml index 23c6815fa..7b59a1516 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.23ea2-SNAPSHOT + 3.24ea0-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent From 7ee83543b17a0e960f4391d7c6da29ba00891b36 Mon Sep 17 00:00:00 2001 From: Ilya Kaznacheev Date: Thu, 29 Sep 2022 13:56:17 +0300 Subject: [PATCH 218/353] Fixes following breaking changes of 2.24 --- .../affinity/MultiProcessAffinityTest.java | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java b/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java index 61f3fa33a..fc5678cf3 100644 --- a/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java +++ b/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java @@ -19,7 +19,7 @@ package net.openhft.affinity; import net.openhft.affinity.testimpl.TestFileLockBasedLockChecker; -import net.openhft.chronicle.testframework.process.ProcessRunner; +import net.openhft.chronicle.testframework.process.JavaProcessBuilder; import org.jetbrains.annotations.NotNull; import org.junit.Assume; import org.junit.Before; @@ -57,9 +57,9 @@ public void setUp() { @Test public void shouldNotAcquireLockOnCoresLockedByOtherProcesses() throws IOException, InterruptedException { // run the separate affinity locker - final Process affinityLockerProcess = ProcessRunner.runClass(AffinityLockerProcess.class, - new String[]{"-Djava.io.tmpdir=" + folder.getRoot().getAbsolutePath()}, - new String[]{"last"}); + final Process affinityLockerProcess = JavaProcessBuilder.create(AffinityLockerProcess.class) + .withJvmArguments("-Djava.io.tmpdir=" + folder.getRoot().getAbsolutePath()) + .withProgramArguments("last").start(); try { int lastCpuId = AffinityLock.PROCESSORS - 1; @@ -70,7 +70,7 @@ public void shouldNotAcquireLockOnCoresLockedByOtherProcesses() throws IOExcepti if (System.currentTimeMillis() > endTime) { LOGGER.info("Timed out waiting for the lock to be acquired: isAlive={}, exitCode={}", affinityLockerProcess.isAlive(), affinityLockerProcess.isAlive() ? "N/A" : affinityLockerProcess.exitValue()); - ProcessRunner.printProcessOutput("AffinityLockerProcess", affinityLockerProcess); + JavaProcessBuilder.printProcessOutput("AffinityLockerProcess", affinityLockerProcess); fail("Timed out waiting for the sub-process to acquire the lock"); } } @@ -90,9 +90,9 @@ public void shouldAllocateCoresCorrectlyUnderContention() throws IOException, In List lockers = new ArrayList<>(); LOGGER.info("Running test with {} locker processes", numberOfLockers); for (int i = 0; i < numberOfLockers; i++) { - lockers.add(ProcessRunner.runClass(RepeatedAffinityLocker.class, - new String[]{"-Djava.io.tmpdir=" + folder.getRoot().getAbsolutePath()}, - new String[]{"last", "30", "2"})); + lockers.add(JavaProcessBuilder.create(RepeatedAffinityLocker.class) + .withJvmArguments("-Djava.io.tmpdir=" + folder.getRoot().getAbsolutePath()) + .withProgramArguments("last", "30", "2").start()); } for (int i = 0; i < numberOfLockers; i++) { final Process process = lockers.get(i); @@ -105,11 +105,11 @@ public void shouldAllocateCoresCorrectlyUnderContentionWithFailures() throws IOE final int numberOfLockers = Math.max(2, Math.min(12, Runtime.getRuntime().availableProcessors())) / 2; List lockers = new ArrayList<>(); LOGGER.info("Running test with {} locker processes", numberOfLockers); - Process lockFileDropper = ProcessRunner.runClass(LockFileDropper.class); + Process lockFileDropper = JavaProcessBuilder.create(LockFileDropper.class).start(); for (int i = 0; i < numberOfLockers; i++) { - lockers.add(ProcessRunner.runClass(RepeatedAffinityLocker.class, - new String[]{"-Djava.io.tmpdir=" + folder.getRoot().getAbsolutePath()}, - new String[]{"last", "30", "2"})); + lockers.add(JavaProcessBuilder.create(RepeatedAffinityLocker.class) + .withJvmArguments("-Djava.io.tmpdir=" + folder.getRoot().getAbsolutePath()) + .withProgramArguments("last", "30", "2").start()); } for (int i = 0; i < numberOfLockers; i++) { final Process process = lockers.get(i); @@ -121,9 +121,9 @@ public void shouldAllocateCoresCorrectlyUnderContentionWithFailures() throws IOE @Test public void shouldBeAbleToAcquireLockLeftByOtherProcess() throws IOException, InterruptedException { - final Process process = ProcessRunner.runClass(AffinityLockerThatDoesNotReleaseProcess.class, - new String[]{"-Djava.io.tmpdir=" + folder.getRoot().getAbsolutePath()}, - new String[]{"last"}); + final Process process = JavaProcessBuilder.create(AffinityLockerThatDoesNotReleaseProcess.class) + .withJvmArguments("-Djava.io.tmpdir=" + folder.getRoot().getAbsolutePath()) + .withProgramArguments("last").start(); waitForProcessToEnd(5, "Locking process", process); // We should be able to acquire the lock despite the other process not explicitly releasing it try (final AffinityLock acquired = AffinityLock.acquireLock("last")) { @@ -137,11 +137,11 @@ private void waitForProcessToEnd(int timeToWaitSeconds, String processDescriptio private void waitForProcessToEnd(int timeToWaitSeconds, String processDescription, Process process, boolean checkExitCode) throws InterruptedException { if (!process.waitFor(timeToWaitSeconds, TimeUnit.SECONDS)) { - ProcessRunner.printProcessOutput(processDescription, process); + JavaProcessBuilder.printProcessOutput(processDescription, process); fail(processDescription + " didn't end in time"); } if (checkExitCode && process.exitValue() != 0) { - ProcessRunner.printProcessOutput(processDescription, process); + JavaProcessBuilder.printProcessOutput(processDescription, process); fail(processDescription + " failed, see output above (exit value " + process.exitValue() + ")"); } } From 711cd191c7a3910a4b7f6e39dc457974cbb399d8 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Thu, 10 Nov 2022 03:18:57 +0000 Subject: [PATCH 219/353] Updating parent POM (automated) --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 564aef2ee..f4cda02be 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.1.33 + 1.1.36 diff --git a/affinity/pom.xml b/affinity/pom.xml index 6468d6586..d9dba943f 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.1.33 + 1.1.36 diff --git a/pom.xml b/pom.xml index 7b59a1516..30e513006 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ net.openhft root-parent-pom - 1.2.21 + 1.2.23 From c3a83b32ff2ce3da99c631fbc56d2dd8322c15ea Mon Sep 17 00:00:00 2001 From: Jerry Shea Date: Wed, 21 Dec 2022 19:44:28 +1100 Subject: [PATCH 220/353] spelling --- .../main/java/net/openhft/affinity/impl/WindowsJNAAffinity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/src/main/java/net/openhft/affinity/impl/WindowsJNAAffinity.java b/affinity/src/main/java/net/openhft/affinity/impl/WindowsJNAAffinity.java index 1a8bb2cd0..2c0fc2d7c 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/WindowsJNAAffinity.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/WindowsJNAAffinity.java @@ -90,7 +90,7 @@ public void setAffinity(final BitSet affinity) { } BitSet affinity2 = getAffinity0(); if (!affinity2.equals(affinity)) { - LoggerFactory.getLogger(WindowsJNAAffinity.class).warn("Tried to set affinity to " + affinity + " but was " + affinity2 + " you may have in sufficient access rights"); + LoggerFactory.getLogger(WindowsJNAAffinity.class).warn("Tried to set affinity to " + affinity + " but was " + affinity2 + " you may have insufficient access rights"); } currentAffinity.set((BitSet) affinity.clone()); } From 75814b29ce30b188ac3d4b35a950c7619fb4ecdf Mon Sep 17 00:00:00 2001 From: Jorge Villarreal Date: Sun, 19 Feb 2023 20:24:21 -0600 Subject: [PATCH 221/353] Typo in isMacJNAAffinityUsable warning message --- affinity/src/main/java/net/openhft/affinity/Affinity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/src/main/java/net/openhft/affinity/Affinity.java b/affinity/src/main/java/net/openhft/affinity/Affinity.java index 83986b2bc..f089d4da7 100644 --- a/affinity/src/main/java/net/openhft/affinity/Affinity.java +++ b/affinity/src/main/java/net/openhft/affinity/Affinity.java @@ -128,7 +128,7 @@ private static boolean isMacJNAAffinityUsable() { return true; } else { - LOGGER.warn("MAX OSX JNA-based affinity not usable due to JNA not being available!"); + LOGGER.warn("MAC OSX JNA-based affinity not usable due to JNA not being available!"); return false; } } From 44d1d3fcb93741bfa0ed2951aca34cbd8ce7eb6d Mon Sep 17 00:00:00 2001 From: rogersimmons <42873823+rogersimmons@users.noreply.github.com> Date: Thu, 22 Jun 2023 11:21:13 +0100 Subject: [PATCH 222/353] Add JNA minimum version check (#104) Co-authored-by: rogersimmons --- .../java/net/openhft/affinity/Affinity.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/affinity/src/main/java/net/openhft/affinity/Affinity.java b/affinity/src/main/java/net/openhft/affinity/Affinity.java index f089d4da7..89f049621 100644 --- a/affinity/src/main/java/net/openhft/affinity/Affinity.java +++ b/affinity/src/main/java/net/openhft/affinity/Affinity.java @@ -17,6 +17,7 @@ package net.openhft.affinity; +import com.sun.jna.Native; import net.openhft.affinity.impl.*; import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; @@ -187,13 +188,21 @@ public static void setThreadId() { } public static boolean isJNAAvailable() { - if (JNAAvailable == null) - try { - Class.forName("com.sun.jna.Platform"); - JNAAvailable = true; - } catch (ClassNotFoundException ignored) { + if (JNAAvailable == null) { + int majorVersion = Integer.parseInt(Native.VERSION.split("\\.")[0]); + if(majorVersion < 5) { + LOGGER.warn("Affinity library requires JNA version >= 5"); JNAAvailable = false; } + else { + try { + Class.forName("com.sun.jna.Platform"); + JNAAvailable = true; + } catch (ClassNotFoundException ignored) { + JNAAvailable = false; + } + } + } return JNAAvailable; } From 5497748938ab378386056286e722eaf032ec6af0 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Fri, 11 Aug 2023 10:24:26 +0100 Subject: [PATCH 223/353] Bring all versions to the same level so we test the version that a Chronicle ALL jar uses --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 5 ++--- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index f4cda02be..69c307d07 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.1.36 + 1.24.0-SNAPSHOT @@ -42,7 +42,7 @@ net.openhft third-party-bom pom - 3.22.4 + 3.24.0-SNAPSHOT import diff --git a/affinity/pom.xml b/affinity/pom.xml index d9dba943f..5cca00581 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.1.36 + 1.24.0-SNAPSHOT @@ -43,7 +43,7 @@ net.openhft third-party-bom pom - 3.22.4 + 3.24.0-SNAPSHOT import @@ -120,7 +120,6 @@ org.codehaus.mojo exec-maven-plugin - 3.1.0 diff --git a/pom.xml b/pom.xml index 30e513006..46f74b415 100644 --- a/pom.xml +++ b/pom.xml @@ -20,8 +20,8 @@ net.openhft - root-parent-pom - 1.2.23 + java-parent-pom + 1.24.0-SNAPSHOT From 980f26e8e81efdf7ad463a953adfa1a48fd2d1c2 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Wed, 30 Aug 2023 15:50:59 +0100 Subject: [PATCH 224/353] Updating parent POM (automated) --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 69c307d07..021ed5bd4 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.24.0-SNAPSHOT + 1.24.0 diff --git a/affinity/pom.xml b/affinity/pom.xml index 5cca00581..3b13191ce 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.24.0-SNAPSHOT + 1.24.0 diff --git a/pom.xml b/pom.xml index 46f74b415..0dc355831 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.24.0-SNAPSHOT + 1.24.0 From 6bfff924944d0af6e0597d10e846d974a1b34a57 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Thu, 31 Aug 2023 10:48:23 +0100 Subject: [PATCH 225/353] java-parent-pom version 1.24.0 --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 021ed5bd4..a603a8b62 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -42,7 +42,7 @@ net.openhft third-party-bom pom - 3.24.0-SNAPSHOT + 3.24.0 import diff --git a/affinity/pom.xml b/affinity/pom.xml index 3b13191ce..bc65cfe05 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -43,7 +43,7 @@ net.openhft third-party-bom pom - 3.24.0-SNAPSHOT + 3.24.0 import From 894231a7fc8d5de476b53672dcd22858d87947ac Mon Sep 17 00:00:00 2001 From: "yevgen.pavlenko" Date: Thu, 2 Nov 2023 13:24:09 +0200 Subject: [PATCH 226/353] Disable AffinityLockTest.dumpLocks for Java 21. --- .../openhft/affinity/AffinityLockTest.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java index a44716375..b3ff7def5 100644 --- a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java +++ b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java @@ -26,14 +26,18 @@ import java.io.File; import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; +import static java.lang.Runtime.getRuntime; import static net.openhft.affinity.AffinityLock.PROCESSORS; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.*; +import static org.junit.Assume.assumeFalse; import static org.junit.Assume.assumeTrue; /** @@ -41,11 +45,13 @@ */ public class AffinityLockTest extends BaseAffinityTest { private static final Logger logger = LoggerFactory.getLogger(AffinityLockTest.class); + private static final int JDK_VERSION = getMajorVersion(); private final TestFileLockBasedLockChecker lockChecker = new TestFileLockBasedLockChecker(); @Test public void dumpLocksI7() throws IOException { + assumeFalse(JDK_VERSION > 20); LockInventory lockInventory = new LockInventory(VanillaCpuLayout.fromCpuInfo("i7.cpuinfo")); AffinityLock[] locks = { new AffinityLock(0, true, false, lockInventory), @@ -83,6 +89,7 @@ public void dumpLocksI7() throws IOException { @Test public void dumpLocksI3() throws IOException { + assumeFalse(JDK_VERSION > 20); LockInventory lockInventory = new LockInventory(VanillaCpuLayout.fromCpuInfo("i3.cpuinfo")); AffinityLock[] locks = { new AffinityLock(0, true, false, lockInventory), @@ -106,6 +113,7 @@ public void dumpLocksI3() throws IOException { @Test public void dumpLocksCoreDuo() throws IOException { + assumeFalse(JDK_VERSION > 20); LockInventory lockInventory = new LockInventory(VanillaCpuLayout.fromCpuInfo("core.duo.cpuinfo")); AffinityLock[] locks = { new AffinityLock(0, true, false, lockInventory), @@ -308,4 +316,22 @@ public void testTooHighCpuId2() { try (AffinityLock ignored = AffinityLock.acquireLock(new int[] {123456})) { } } + + private static int getMajorVersion() { + try { + final Method method = Runtime.class.getDeclaredMethod("version"); + final Object version = method.invoke(getRuntime()); + final Class clz = Class.forName("java.lang.Runtime$Version"); + return (Integer) clz.getDeclaredMethod("major").invoke(version); + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | ClassNotFoundException | + IllegalArgumentException e) { + // ignore and fall back to pre-jdk9 + } + try { + return Integer.parseInt(Runtime.class.getPackage().getSpecificationVersion().split("\\.")[1]); + } catch (Exception e) { + System.err.println("Unable to get the major version, defaulting to 8 " + e); + return 8; + } + } } From afed6998b341adf2f94fae723fe767c98c786ae2 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Wed, 10 Jan 2024 14:31:52 +0000 Subject: [PATCH 227/353] Remove class that was moved --- .../net/openhft/affinity/AffinitySupport.java | 33 ------------------- 1 file changed, 33 deletions(-) delete mode 100644 affinity/src/main/java/net/openhft/affinity/AffinitySupport.java diff --git a/affinity/src/main/java/net/openhft/affinity/AffinitySupport.java b/affinity/src/main/java/net/openhft/affinity/AffinitySupport.java deleted file mode 100644 index d4cc6e249..000000000 --- a/affinity/src/main/java/net/openhft/affinity/AffinitySupport.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2016-2020 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package net.openhft.affinity; - -/** - * For backward compatibility with Affinity 2.x - */ -@Deprecated(/* to be removed in x.22 */) -public class AffinitySupport { - - public static int getThreadId() { - return Affinity.getThreadId(); - } - - public static void setThreadId() { - Affinity.setThreadId(); - } -} From 2a31656397765343879de8d00319c9daf0aed379 Mon Sep 17 00:00:00 2001 From: Tom Date: Thu, 25 Jan 2024 15:11:43 +0000 Subject: [PATCH 228/353] Fix AffinityLockTest on Java 21 (#113) Was broken because Thread#toString includes thread ID on Java 21. Ignore this in the test cases. --- .../openhft/affinity/AffinityLockTest.java | 38 ++++++------------- 1 file changed, 11 insertions(+), 27 deletions(-) diff --git a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java index b3ff7def5..a2decf585 100644 --- a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java +++ b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java @@ -20,24 +20,21 @@ import net.openhft.affinity.impl.Utilities; import net.openhft.affinity.impl.VanillaCpuLayout; import net.openhft.affinity.testimpl.TestFileLockBasedLockChecker; +import org.jetbrains.annotations.NotNull; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.File; import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; -import static java.lang.Runtime.getRuntime; import static net.openhft.affinity.AffinityLock.PROCESSORS; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.*; -import static org.junit.Assume.assumeFalse; import static org.junit.Assume.assumeTrue; /** @@ -45,13 +42,11 @@ */ public class AffinityLockTest extends BaseAffinityTest { private static final Logger logger = LoggerFactory.getLogger(AffinityLockTest.class); - private static final int JDK_VERSION = getMajorVersion(); private final TestFileLockBasedLockChecker lockChecker = new TestFileLockBasedLockChecker(); @Test public void dumpLocksI7() throws IOException { - assumeFalse(JDK_VERSION > 20); LockInventory lockInventory = new LockInventory(VanillaCpuLayout.fromCpuInfo("i7.cpuinfo")); AffinityLock[] locks = { new AffinityLock(0, true, false, lockInventory), @@ -70,7 +65,7 @@ public void dumpLocksI7() throws IOException { locks[6].assignedThread = new Thread(new InterrupedThread(), "main"); locks[7].assignedThread = new Thread(new InterrupedThread(), "tcp"); locks[7].assignedThread.start(); - final String actual = LockInventory.dumpLocks(locks); + final String actual = dumpLocks(locks); assertEquals("0: General use CPU\n" + "1: CPU not available\n" + "2: Thread[logger,5,main] alive=true\n" + @@ -89,7 +84,6 @@ public void dumpLocksI7() throws IOException { @Test public void dumpLocksI3() throws IOException { - assumeFalse(JDK_VERSION > 20); LockInventory lockInventory = new LockInventory(VanillaCpuLayout.fromCpuInfo("i3.cpuinfo")); AffinityLock[] locks = { new AffinityLock(0, true, false, lockInventory), @@ -101,7 +95,7 @@ public void dumpLocksI3() throws IOException { locks[1].assignedThread.start(); locks[3].assignedThread = new Thread(new InterrupedThread(), "main"); - final String actual = LockInventory.dumpLocks(locks); + final String actual = dumpLocks(locks); assertEquals("0: General use CPU\n" + "1: Thread[engine,5,main] alive=true\n" + "2: General use CPU\n" + @@ -113,7 +107,6 @@ public void dumpLocksI3() throws IOException { @Test public void dumpLocksCoreDuo() throws IOException { - assumeFalse(JDK_VERSION > 20); LockInventory lockInventory = new LockInventory(VanillaCpuLayout.fromCpuInfo("core.duo.cpuinfo")); AffinityLock[] locks = { new AffinityLock(0, true, false, lockInventory), @@ -122,7 +115,7 @@ public void dumpLocksCoreDuo() throws IOException { locks[1].assignedThread = new Thread(new InterrupedThread(), "engine"); locks[1].assignedThread.start(); - final String actual = LockInventory.dumpLocks(locks); + final String actual = dumpLocks(locks); assertEquals("0: General use CPU\n" + "1: Thread[engine,5,main] alive=true\n", actual); System.out.println(actual); @@ -317,21 +310,12 @@ public void testTooHighCpuId2() { } } - private static int getMajorVersion() { - try { - final Method method = Runtime.class.getDeclaredMethod("version"); - final Object version = method.invoke(getRuntime()); - final Class clz = Class.forName("java.lang.Runtime$Version"); - return (Integer) clz.getDeclaredMethod("major").invoke(version); - } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | ClassNotFoundException | - IllegalArgumentException e) { - // ignore and fall back to pre-jdk9 - } - try { - return Integer.parseInt(Runtime.class.getPackage().getSpecificationVersion().split("\\.")[1]); - } catch (Exception e) { - System.err.println("Unable to get the major version, defaulting to 8 " + e); - return 8; - } + /** + * In Java 21 the toString contents of Thread changed to include an ID. This breaks the tests here in Java 21. + * Strip out the thread ID here so that existing tests continue to pass. + */ + private static String dumpLocks(AffinityLock[] locks) { + String value = LockInventory.dumpLocks(locks); + return value.replaceAll("#[0-9]+(,)?", ""); } } From f83ea94d2af56bcc3f2c767beca94e2b09a2bf04 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Fri, 9 Feb 2024 00:54:51 +0000 Subject: [PATCH 229/353] Updating parent POM (automated) --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index a603a8b62..0c06e6569 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.24.0 + 1.25.3 diff --git a/affinity/pom.xml b/affinity/pom.xml index bc65cfe05..465215613 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.24.0 + 1.25.3 diff --git a/pom.xml b/pom.xml index 0dc355831..f96e7e5e3 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.24.0 + 1.25.3 From 3cebc6f6ccf41671a3752128f990f667612b359c Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Mon, 4 Mar 2024 21:03:07 +0000 Subject: [PATCH 230/353] Updating parent POM (automated) --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 0c06e6569..694444f84 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.25.3 + 1.25.4 diff --git a/affinity/pom.xml b/affinity/pom.xml index 465215613..d63ec73fa 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.25.3 + 1.25.4 diff --git a/pom.xml b/pom.xml index f96e7e5e3..0416056c1 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.25.3 + 1.25.4 From 959768b27877f57560c81b87d45165652d3275a3 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Mon, 25 Mar 2024 11:45:32 +0000 Subject: [PATCH 231/353] Initial branch of x.26 --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 6 +++--- pom.xml | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 694444f84..5cfe6cc26 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.24ea0-SNAPSHOT + 3.26ea0-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -42,7 +42,7 @@ net.openhft third-party-bom pom - 3.24.0 + 3.25.2 import diff --git a/affinity/pom.xml b/affinity/pom.xml index d63ec73fa..7387a7601 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.24ea0-SNAPSHOT + 3.26ea0-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity @@ -43,13 +43,13 @@ net.openhft third-party-bom pom - 3.24.0 + 3.25.2 import net.openhft chronicle-bom - 2.24ea-SNAPSHOT + 2.26ea-SNAPSHOT pom import diff --git a/pom.xml b/pom.xml index 0416056c1..a4b88a58f 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.24ea0-SNAPSHOT + 3.64ea0-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent From c05061f567317cc41a386da8e22a35deadc0277b Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Thu, 28 Mar 2024 10:48:52 +0000 Subject: [PATCH 232/353] fix deprecated usage --- .../src/test/java/net/openhft/affinity/AffinityLockTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java index a2decf585..96c19f341 100644 --- a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java +++ b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java @@ -20,6 +20,7 @@ import net.openhft.affinity.impl.Utilities; import net.openhft.affinity.impl.VanillaCpuLayout; import net.openhft.affinity.testimpl.TestFileLockBasedLockChecker; +import org.hamcrest.MatcherAssert; import org.jetbrains.annotations.NotNull; import org.junit.Test; import org.slf4j.Logger; @@ -244,7 +245,7 @@ public void shouldReturnLockForSpecifiedCpu() { assumeTrue(Runtime.getRuntime().availableProcessors() > 3); try (final AffinityLock affinityLock = AffinityLock.acquireLock(3)) { - assertThat(affinityLock.cpuId(), is(3)); + MatcherAssert.assertThat(affinityLock.cpuId(), is(3)); } assertEquals(AffinityLock.BASE_AFFINITY, Affinity.getAffinity()); } From f4c5df52f8e00f7371fd4af8579e7dad8320dddc Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Wed, 3 Apr 2024 11:39:43 +0100 Subject: [PATCH 233/353] Tidy up compiler setting and some warnings --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 5cfe6cc26..dc06e7229 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -42,7 +42,7 @@ net.openhft third-party-bom pom - 3.25.2 + 3.26.0-SNAPSHOT import diff --git a/affinity/pom.xml b/affinity/pom.xml index 7387a7601..8655b4567 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -43,7 +43,7 @@ net.openhft third-party-bom pom - 3.25.2 + 3.26.0-SNAPSHOT import From cfdc2f6e4760019fc272736c70871cb3cf51764f Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Wed, 10 Apr 2024 10:53:28 +0100 Subject: [PATCH 234/353] tidy SuppressWarnings --- .../java/net/openhft/affinity/impl/LinuxHelper.java | 12 ++++++------ .../net/openhft/affinity/impl/VersionHelper.java | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java b/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java index 3b4d301de..f2e456286 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java @@ -239,7 +239,7 @@ public String getSysname() { return new String(sysname, 0, length(sysname)); } - @SuppressWarnings({"UnusedDeclaration"}) + @SuppressWarnings("unused") public String getNodename() { return new String(nodename, 0, length(nodename)); } @@ -270,7 +270,7 @@ public String getMachine() { return new String(machine, 0, length(machine)); } - @SuppressWarnings({"UnusedDeclaration"}) + @SuppressWarnings("UnusedDeclaration") public String getDomainname() { return new String(domainname, 0, length(domainname)); } @@ -295,7 +295,7 @@ public cpu_set_t() { } } - @SuppressWarnings({"UnusedDeclaration"}) + @SuppressWarnings("UnusedDeclaration") public static void __CPU_ZERO(cpu_set_t cpuset) { for (NativeLong bits : cpuset.__bits) { bits.setValue(0L); @@ -310,19 +310,19 @@ public static long __CPUMASK(int cpu) { return 1L << (cpu % __NCPUBITS); } - @SuppressWarnings({"UnusedDeclaration"}) + @SuppressWarnings("UnusedDeclaration") public static void __CPU_SET(int cpu, cpu_set_t cpuset) { cpuset.__bits[__CPUELT(cpu)].setValue( cpuset.__bits[__CPUELT(cpu)].longValue() | __CPUMASK(cpu)); } - @SuppressWarnings({"UnusedDeclaration"}) + @SuppressWarnings("UnusedDeclaration") public static void __CPU_CLR(int cpu, cpu_set_t cpuset) { cpuset.__bits[__CPUELT(cpu)].setValue( cpuset.__bits[__CPUELT(cpu)].longValue() & ~__CPUMASK(cpu)); } - @SuppressWarnings({"UnusedDeclaration"}) + @SuppressWarnings("UnusedDeclaration") public static boolean __CPU_ISSET(int cpu, cpu_set_t cpuset) { return (cpuset.__bits[__CPUELT(cpu)].longValue() & __CPUMASK(cpu)) != 0; } diff --git a/affinity/src/main/java/net/openhft/affinity/impl/VersionHelper.java b/affinity/src/main/java/net/openhft/affinity/impl/VersionHelper.java index b54d75081..9729c2980 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/VersionHelper.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/VersionHelper.java @@ -61,7 +61,7 @@ public int hashCode() { return (major << 16) | (minor << 8) | release; } - @SuppressWarnings({"UnusedDeclaration"}) + @SuppressWarnings("unused") public boolean majorMinorEquals(final VersionHelper ver) { return ver != null && this.major == ver.major From 9a9148f9f5073cb4c8ff4a59804d3f7c74d84ce2 Mon Sep 17 00:00:00 2001 From: rogersimmons Date: Wed, 17 Apr 2024 09:33:05 +0100 Subject: [PATCH 235/353] Remove old comment (long since addressed) --- .../main/java/net/openhft/affinity/impl/LinuxJNAAffinity.java | 1 - 1 file changed, 1 deletion(-) diff --git a/affinity/src/main/java/net/openhft/affinity/impl/LinuxJNAAffinity.java b/affinity/src/main/java/net/openhft/affinity/impl/LinuxJNAAffinity.java index 1a4463319..5f93ca361 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/LinuxJNAAffinity.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/LinuxJNAAffinity.java @@ -72,7 +72,6 @@ public BitSet getAffinity() { return ret; } - // TODO: FIXME!!! CHANGE IAffinity TO SUPPORT PLATFORMS WITH 64+ CORES FIXME!!! @Override public void setAffinity(final BitSet affinity) { LinuxHelper.sched_setaffinity(affinity); From 25b21069372bb0feee5d3e3cf266f29fb65fec12 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Tue, 7 May 2024 18:48:15 +0100 Subject: [PATCH 236/353] Fix newlines --- .../src/test/java/net/openhft/affinity/osgi/OSGiTestBase.java | 1 - affinity/src/main/java/net/openhft/affinity/LockCheck.java | 2 +- affinity/src/main/java/net/openhft/affinity/LockInventory.java | 2 -- .../src/main/java/net/openhft/affinity/MicroJitterSampler.java | 2 -- .../src/main/java/net/openhft/affinity/impl/LinuxHelper.java | 2 +- .../src/main/java/net/openhft/affinity/impl/VersionHelper.java | 1 - affinity/src/main/java/net/openhft/ticker/Ticker.java | 2 +- affinity/src/main/java/net/openhft/ticker/impl/JNIClock.java | 2 +- affinity/src/main/java/net/openhft/ticker/impl/SystemClock.java | 2 +- .../src/test/java/net/openhft/affinity/BootClassPathTest.java | 2 +- .../test/java/net/openhft/affinity/FileLockLockCheckTest.java | 2 +- affinity/src/test/java/net/openhft/affinity/LockCheckTest.java | 2 +- .../src/test/java/net/openhft/ticker/impl/JNIClockTest.java | 2 +- 13 files changed, 9 insertions(+), 15 deletions(-) diff --git a/affinity-test/src/test/java/net/openhft/affinity/osgi/OSGiTestBase.java b/affinity-test/src/test/java/net/openhft/affinity/osgi/OSGiTestBase.java index deb9d9d5f..3dc8d2652 100644 --- a/affinity-test/src/test/java/net/openhft/affinity/osgi/OSGiTestBase.java +++ b/affinity-test/src/test/java/net/openhft/affinity/osgi/OSGiTestBase.java @@ -61,4 +61,3 @@ public static Bundle findBundle(BundleContext context, String symbolicName) { return null; } } - diff --git a/affinity/src/main/java/net/openhft/affinity/LockCheck.java b/affinity/src/main/java/net/openhft/affinity/LockCheck.java index 8acaf4e23..29b962f07 100644 --- a/affinity/src/main/java/net/openhft/affinity/LockCheck.java +++ b/affinity/src/main/java/net/openhft/affinity/LockCheck.java @@ -100,4 +100,4 @@ static boolean updateCpu(int cpu) throws IOException { public static void releaseLock(int cpu) { lockChecker.releaseLock(cpu); } -} \ No newline at end of file +} diff --git a/affinity/src/main/java/net/openhft/affinity/LockInventory.java b/affinity/src/main/java/net/openhft/affinity/LockInventory.java index ce15aebed..2ca7eb39e 100644 --- a/affinity/src/main/java/net/openhft/affinity/LockInventory.java +++ b/affinity/src/main/java/net/openhft/affinity/LockInventory.java @@ -159,7 +159,6 @@ && updateLockForCurrentThread(bind, al, false)) { return noLock(); } - LOGGER.warn("No reservable CPU for {}", Thread.currentThread()); return noLock(); @@ -181,7 +180,6 @@ && updateLockForCurrentThread(bind, required, false)) { return noLock(); } - LOGGER.warn("Unable to acquire lock on CPU {} for thread {}, trying to find another CPU", cpuId, Thread.currentThread()); diff --git a/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java b/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java index c2a8ef3aa..d0a971806 100644 --- a/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java +++ b/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java @@ -46,7 +46,6 @@ private static void pause() throws InterruptedException { } else { Thread.sleep(1); } - } public static void main(String... ignored) throws InterruptedException { @@ -133,7 +132,6 @@ void print(PrintStream ps) { ps.println(); } } - /* e.g. Ubuntu 20.04, Ryzen 5950X with an isolated CPU. (init 3) sudo cpupower -c {cpu} -g performance, run from command line After 3600 seconds, the average per hour was diff --git a/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java b/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java index f2e456286..da85e247f 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java @@ -69,7 +69,7 @@ cpu_set_t sched_getaffinity() { public static void sched_setaffinity(final BitSet affinity) { sched_setaffinity(0, affinity); } - + public static void sched_setaffinity(final int pid, final BitSet affinity) { final CLibrary lib = CLibrary.INSTANCE; final cpu_set_t cpuset = new cpu_set_t(); diff --git a/affinity/src/main/java/net/openhft/affinity/impl/VersionHelper.java b/affinity/src/main/java/net/openhft/affinity/impl/VersionHelper.java index 9729c2980..98e1c19f0 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/VersionHelper.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/VersionHelper.java @@ -77,4 +77,3 @@ public boolean isSameOrNewer(final VersionHelper ver) { && this.release >= ver.release)); } } - diff --git a/affinity/src/main/java/net/openhft/ticker/Ticker.java b/affinity/src/main/java/net/openhft/ticker/Ticker.java index d8ac5a1e6..6e17c653c 100644 --- a/affinity/src/main/java/net/openhft/ticker/Ticker.java +++ b/affinity/src/main/java/net/openhft/ticker/Ticker.java @@ -58,4 +58,4 @@ public static long toNanos(long ticks) { public static double toMicros(long ticks) { return INSTANCE.toMicros(ticks); } -} \ No newline at end of file +} diff --git a/affinity/src/main/java/net/openhft/ticker/impl/JNIClock.java b/affinity/src/main/java/net/openhft/ticker/impl/JNIClock.java index 0115c19cd..1808af9a7 100644 --- a/affinity/src/main/java/net/openhft/ticker/impl/JNIClock.java +++ b/affinity/src/main/java/net/openhft/ticker/impl/JNIClock.java @@ -103,4 +103,4 @@ public long toNanos(long ticks) { public double toMicros(double ticks) { return ticks * RDTSC_MICRO_FACTOR; } -} \ No newline at end of file +} diff --git a/affinity/src/main/java/net/openhft/ticker/impl/SystemClock.java b/affinity/src/main/java/net/openhft/ticker/impl/SystemClock.java index 8844ab460..2c3402433 100644 --- a/affinity/src/main/java/net/openhft/ticker/impl/SystemClock.java +++ b/affinity/src/main/java/net/openhft/ticker/impl/SystemClock.java @@ -47,4 +47,4 @@ public long toNanos(long ticks) { public double toMicros(double ticks) { return ticks / 1e3; } -} \ No newline at end of file +} diff --git a/affinity/src/test/java/net/openhft/affinity/BootClassPathTest.java b/affinity/src/test/java/net/openhft/affinity/BootClassPathTest.java index d4c555938..3c0c29df8 100644 --- a/affinity/src/test/java/net/openhft/affinity/BootClassPathTest.java +++ b/affinity/src/test/java/net/openhft/affinity/BootClassPathTest.java @@ -30,4 +30,4 @@ public void shouldDetectClassesOnClassPath() { assertTrue(BootClassPath.INSTANCE.has("java.lang.Thread")); assertTrue(BootClassPath.INSTANCE.has("java.lang.Runtime")); } -} \ No newline at end of file +} diff --git a/affinity/src/test/java/net/openhft/affinity/FileLockLockCheckTest.java b/affinity/src/test/java/net/openhft/affinity/FileLockLockCheckTest.java index 5f39b87ce..1576851f4 100644 --- a/affinity/src/test/java/net/openhft/affinity/FileLockLockCheckTest.java +++ b/affinity/src/test/java/net/openhft/affinity/FileLockLockCheckTest.java @@ -71,4 +71,4 @@ public void shouldNotBlowUpIfPidFileIsEmpty() throws Exception { LockCheck.isCpuFree(cpu); } -} \ No newline at end of file +} diff --git a/affinity/src/test/java/net/openhft/affinity/LockCheckTest.java b/affinity/src/test/java/net/openhft/affinity/LockCheckTest.java index c6ab5e042..11ec9463f 100644 --- a/affinity/src/test/java/net/openhft/affinity/LockCheckTest.java +++ b/affinity/src/test/java/net/openhft/affinity/LockCheckTest.java @@ -84,4 +84,4 @@ public void shouldNotBlowUpIfPidFileIsCorrupt() throws Exception { LockCheck.isCpuFree(cpu); } -} \ No newline at end of file +} diff --git a/affinity/src/test/java/net/openhft/ticker/impl/JNIClockTest.java b/affinity/src/test/java/net/openhft/ticker/impl/JNIClockTest.java index 8af7760de..b87b793fe 100644 --- a/affinity/src/test/java/net/openhft/ticker/impl/JNIClockTest.java +++ b/affinity/src/test/java/net/openhft/ticker/impl/JNIClockTest.java @@ -78,4 +78,4 @@ public void testJitter() { System.out.println(((long) (clock.toMicros(time[i]) * 10)) / 10.0 + ", " + ((long) (clock.toMicros(length[i]) * 10) / 10.0)); } } -} \ No newline at end of file +} From 4b8f50d83ee7dd2411e13a4d034306cb78d4df4e Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Mon, 20 May 2024 13:31:13 +0100 Subject: [PATCH 237/353] type:pom order --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index dc06e7229..9722d19fc 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -41,8 +41,8 @@ net.openhft third-party-bom - pom 3.26.0-SNAPSHOT + pom import diff --git a/affinity/pom.xml b/affinity/pom.xml index 8655b4567..ca116fbe0 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -42,8 +42,8 @@ net.openhft third-party-bom - pom 3.26.0-SNAPSHOT + pom import From 8386232d9a0848dec9e7946401d27f279cbe9ecd Mon Sep 17 00:00:00 2001 From: rogersimmons Date: Wed, 17 Apr 2024 09:33:05 +0100 Subject: [PATCH 238/353] Remove old comment (long since addressed) --- .../main/java/net/openhft/affinity/impl/LinuxJNAAffinity.java | 1 - 1 file changed, 1 deletion(-) diff --git a/affinity/src/main/java/net/openhft/affinity/impl/LinuxJNAAffinity.java b/affinity/src/main/java/net/openhft/affinity/impl/LinuxJNAAffinity.java index 1a4463319..5f93ca361 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/LinuxJNAAffinity.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/LinuxJNAAffinity.java @@ -72,7 +72,6 @@ public BitSet getAffinity() { return ret; } - // TODO: FIXME!!! CHANGE IAffinity TO SUPPORT PLATFORMS WITH 64+ CORES FIXME!!! @Override public void setAffinity(final BitSet affinity) { LinuxHelper.sched_setaffinity(affinity); From eb3ec15b9c881fafbc358fef2f5bae5e8c95f089 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Wed, 22 May 2024 19:16:40 +0100 Subject: [PATCH 239/353] parent poms -> x.26.0 --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 9722d19fc..c894212c9 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -41,7 +41,7 @@ net.openhft third-party-bom - 3.26.0-SNAPSHOT + 3.26.0 pom import diff --git a/affinity/pom.xml b/affinity/pom.xml index ca116fbe0..fd303d10a 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -42,7 +42,7 @@ net.openhft third-party-bom - 3.26.0-SNAPSHOT + 3.26.0 pom import From b21836e42701e6db0ef3cfbc5b41a1110b55c799 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Thu, 23 May 2024 13:06:41 +0100 Subject: [PATCH 240/353] correct version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a4b88a58f..2e42b312a 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.64ea0-SNAPSHOT + 3.26ea0-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent From bec873c5e1ff97fa7178ab5c5f21d8549ae27e16 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Thu, 23 May 2024 13:31:12 +0100 Subject: [PATCH 241/353] Bump the snapshot version for affinity --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index fd303d10a..9a4a91acd 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.26ea0-SNAPSHOT + 3.26ea1-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity From 4a33d97715d77acf6102a8eb117b71cb9cb8a630 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Thu, 23 May 2024 13:32:01 +0100 Subject: [PATCH 242/353] Bump the snapshot version for affinity --- affinity-test/pom.xml | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index c894212c9..7cf2554a9 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.26ea0-SNAPSHOT + 3.26ea1-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test diff --git a/pom.xml b/pom.xml index 2e42b312a..48714d4dc 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.26ea0-SNAPSHOT + 3.26ea1-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent From 91e88fd51b6af8b082191b34a827767cc02f46fd Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Thu, 23 May 2024 13:54:35 +0100 Subject: [PATCH 243/353] java-parent-pom -> 1.26.0 --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 4 ++-- .../src/main/java/net/openhft/affinity/AffinityLock.java | 1 + .../java/net/openhft/affinity/AffinityThreadFactory.java | 1 + .../main/java/net/openhft/affinity/MicroJitterSampler.java | 1 + .../main/java/net/openhft/affinity/impl/LinuxHelper.java | 4 ++-- .../affinity/lockchecker/FileLockBasedLockChecker.java | 1 + .../test/java/net/openhft/affinity/AffinityLockTest.java | 7 +++++++ .../net/openhft/affinity/impl/NativeAffinityImpTest.java | 4 +++- .../net/openhft/affinity/impl/PosixJNAAffinityTest.java | 4 +++- pom.xml | 2 +- 11 files changed, 23 insertions(+), 8 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 7cf2554a9..c4f20dd60 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.25.4 + 1.26.0 diff --git a/affinity/pom.xml b/affinity/pom.xml index 9a4a91acd..833855bf1 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.25.4 + 1.26.0 @@ -178,7 +178,7 @@ -h ${project.build.directory}/jni - -Xlint:deprecation + -Xlint:all,-options 1.8 1.8 diff --git a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java index 67642daf5..2fba8ce46 100644 --- a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java +++ b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java @@ -446,6 +446,7 @@ public void close() { release(); } + @SuppressWarnings("removal") @Override protected void finalize() throws Throwable { if (bound) { diff --git a/affinity/src/main/java/net/openhft/affinity/AffinityThreadFactory.java b/affinity/src/main/java/net/openhft/affinity/AffinityThreadFactory.java index a70bfbe3d..5962f4b62 100644 --- a/affinity/src/main/java/net/openhft/affinity/AffinityThreadFactory.java +++ b/affinity/src/main/java/net/openhft/affinity/AffinityThreadFactory.java @@ -57,6 +57,7 @@ public synchronized Thread newThread(@NotNull final Runnable r) { @Override public void run() { try (AffinityLock ignored = acquireLockBasedOnLast()) { + assert ignored != null; r.run(); } } diff --git a/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java b/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java index d0a971806..f9e34715d 100644 --- a/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java +++ b/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java @@ -71,6 +71,7 @@ private void once() throws InterruptedException { public void run() { try (final AffinityLock lock = AffinityLock.acquireLock(CPU)) { + assert lock != null; boolean first = true; System.out.println("Warming up..."); while (!Thread.currentThread().isInterrupted()) { diff --git a/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java b/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java index da85e247f..448d37bd7 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java @@ -231,7 +231,7 @@ static int length(final byte[] data) { } @Override - protected List getFieldOrder() { + protected List getFieldOrder() { return FIELD_ORDER; } @@ -328,7 +328,7 @@ public static boolean __CPU_ISSET(int cpu, cpu_set_t cpuset) { } @Override - protected List getFieldOrder() { + protected List getFieldOrder() { return FIELD_ORDER; } } diff --git a/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java b/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java index 77095375c..6b596a49f 100644 --- a/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java +++ b/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java @@ -241,5 +241,6 @@ private File tmpDir() { * Thrown when another process deleted the lock file between us opening the file and acquiring the lock */ class ConcurrentLockFileDeletionException extends Exception { + private static final long serialVersionUID = 0L; } } diff --git a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java index 96c19f341..dd286686f 100644 --- a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java +++ b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java @@ -162,6 +162,7 @@ public void resetAffinity() { } assertEquals(1, Affinity.getAffinity().cardinality()); try (AffinityLock lock = AffinityLock.acquireLock()) { + assertNotNull(lock); } assertTrue(Affinity.getAffinity().cardinality() > 1); } @@ -274,15 +275,19 @@ public void testAffinityLockDescriptions() { return; } try (AffinityLock lock = AffinityLock.acquireLock("last")) { + assertNotNull(lock); assertEquals(PROCESSORS - 1, Affinity.getCpu()); } try (AffinityLock lock = AffinityLock.acquireLock("last")) { + assertNotNull(lock); assertEquals(PROCESSORS - 1, Affinity.getCpu()); } try (AffinityLock lock = AffinityLock.acquireLock("last-1")) { + assertNotNull(lock); assertEquals(PROCESSORS - 2, Affinity.getCpu()); } try (AffinityLock lock = AffinityLock.acquireLock("1")) { + assertNotNull(lock); assertEquals(1, Affinity.getCpu()); } try (AffinityLock lock = AffinityLock.acquireLock("any")) { @@ -302,12 +307,14 @@ public void testAffinityLockDescriptions() { @Test public void testTooHighCpuId() { try (AffinityLock ignored = AffinityLock.acquireLock(123456)) { + assertNotNull(ignored); } } @Test public void testTooHighCpuId2() { try (AffinityLock ignored = AffinityLock.acquireLock(new int[] {123456})) { + assertNotNull(ignored); } } diff --git a/affinity/src/test/java/net/openhft/affinity/impl/NativeAffinityImpTest.java b/affinity/src/test/java/net/openhft/affinity/impl/NativeAffinityImpTest.java index 3c98d9683..04c200e3f 100644 --- a/affinity/src/test/java/net/openhft/affinity/impl/NativeAffinityImpTest.java +++ b/affinity/src/test/java/net/openhft/affinity/impl/NativeAffinityImpTest.java @@ -53,7 +53,9 @@ public void testGettid() { long time = 0; for (int i = 0; i < runs; i++) { long start = System.nanoTime(); - tid = Thread.currentThread().getId(); + @SuppressWarnings("deprecation") + long tid0 = Thread.currentThread().getId(); + tid = tid0; time += System.nanoTime() - start; assertTrue(tid > 0); assertTrue(tid < 1 << 16); diff --git a/affinity/src/test/java/net/openhft/affinity/impl/PosixJNAAffinityTest.java b/affinity/src/test/java/net/openhft/affinity/impl/PosixJNAAffinityTest.java index a763cef05..d25aa89ae 100644 --- a/affinity/src/test/java/net/openhft/affinity/impl/PosixJNAAffinityTest.java +++ b/affinity/src/test/java/net/openhft/affinity/impl/PosixJNAAffinityTest.java @@ -51,7 +51,9 @@ public void testGettid() { long time = 0; for (int i = 0; i < runs; i++) { long start = System.nanoTime(); - tid = Thread.currentThread().getId(); + @SuppressWarnings("deprecation") + long tid0 = Thread.currentThread().getId(); + tid = tid0; time += System.nanoTime() - start; assertTrue(tid > 0); assertTrue(tid < 1 << 24); diff --git a/pom.xml b/pom.xml index 48714d4dc..79ab1d2c7 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.25.4 + 1.26.0 From 5dcf176422ec646922127458a43a0dc6adcb3727 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Thu, 23 May 2024 15:47:36 +0100 Subject: [PATCH 244/353] java-parent-pom -> 1.26.0 (finalize) --- affinity/src/main/java/net/openhft/affinity/AffinityLock.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java index 2fba8ce46..f7a01619d 100644 --- a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java +++ b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java @@ -446,7 +446,7 @@ public void close() { release(); } - @SuppressWarnings("removal") + @SuppressWarnings({"deprecation", "removal"}) @Override protected void finalize() throws Throwable { if (bound) { From 461408b2b9a3ccc2e59a60178fee5c15b72d8e21 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Wed, 29 May 2024 16:27:53 +0100 Subject: [PATCH 245/353] Updating to bom version 2.26ea0 --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index 833855bf1..fc8b062b0 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea-SNAPSHOT + 2.26ea0 pom import From 730f7f688c89b2a9db4914312c37945c8235d207 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Wed, 29 May 2024 16:28:11 +0100 Subject: [PATCH 246/353] Reverting back to bom version 2.26ea-SNAPSHOT --- affinity/pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index fc8b062b0..43f964c8d 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.26ea1-SNAPSHOT + 3.26ea1 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea0 + 2.26ea-SNAPSHOT pom import @@ -269,7 +269,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.26ea1 From dd79316f2b37cc562d7069ba267177038ddc9821 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Wed, 29 May 2024 16:35:19 +0100 Subject: [PATCH 247/353] Updating to bom version 2.26ea1 --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index 43f964c8d..143ff8dc2 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea-SNAPSHOT + 2.26ea1 pom import From a0a58fb320320bc3267732691669db27169f79ec Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Wed, 29 May 2024 16:35:33 +0100 Subject: [PATCH 248/353] Reverting back to bom version 2.26ea-SNAPSHOT --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index 143ff8dc2..43f964c8d 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea1 + 2.26ea-SNAPSHOT pom import From bfcfd600d765db61a768076b651ac9d7f7b7af3e Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Wed, 29 May 2024 17:13:50 +0100 Subject: [PATCH 249/353] Re-release affinity --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index c4f20dd60..ae07c3ea9 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.26ea1-SNAPSHOT + 3.26ea2-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test diff --git a/affinity/pom.xml b/affinity/pom.xml index 43f964c8d..56851c13d 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.26ea1 + 3.26ea2-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity diff --git a/pom.xml b/pom.xml index 79ab1d2c7..b871d1851 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.26ea1-SNAPSHOT + 3.26ea2-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent From db1264b730358131e853aa9f20f45c22b4a67da2 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Wed, 29 May 2024 18:56:31 +0100 Subject: [PATCH 250/353] Updating to bom version 2.26ea1 --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index 56851c13d..3cb0a0047 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea-SNAPSHOT + 2.26ea1 pom import From 7e25a795341deb2c8c974b57f1e3396a2bb55c57 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Wed, 29 May 2024 18:56:47 +0100 Subject: [PATCH 251/353] Reverting back to bom version 2.26ea-SNAPSHOT --- affinity/pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index 3cb0a0047..6736c3564 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.26ea2-SNAPSHOT + 3.26ea2 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea1 + 2.26ea-SNAPSHOT pom import @@ -269,7 +269,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.26ea1 + Java-Thread-Affinity-3.26ea2 From ea37beb018cc4759ebcc23fd9ac1e3ff7b5a5935 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Thu, 30 May 2024 08:01:44 +0100 Subject: [PATCH 252/353] Re-release affinity --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index ae07c3ea9..93e457d06 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.26ea2-SNAPSHOT + 3.26ea3-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test diff --git a/affinity/pom.xml b/affinity/pom.xml index 6736c3564..d1fe17ab9 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.26ea2 + 3.26ea3-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity diff --git a/pom.xml b/pom.xml index b871d1851..1e11e7cb4 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.26ea2-SNAPSHOT + 3.26ea3-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent From 0122ee6e4a6a91d54d821b7fcade97fa5d397921 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Tue, 11 Jun 2024 10:34:22 +0100 Subject: [PATCH 253/353] Updating to bom version 2.26ea8 --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index d1fe17ab9..fbe386bcb 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea-SNAPSHOT + 2.26ea8 pom import From 2897de818ef4b41e160a57a70a1ccde957ded6b6 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Tue, 11 Jun 2024 10:34:38 +0100 Subject: [PATCH 254/353] Reverting back to bom version 2.26ea-SNAPSHOT --- affinity/pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index fbe386bcb..45be8631c 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.26ea3-SNAPSHOT + 3.26ea3 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea8 + 2.26ea-SNAPSHOT pom import @@ -269,7 +269,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.26ea2 + Java-Thread-Affinity-3.26ea3 From 041a62c492c96b13893d7c1637358dd1e120ff48 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Tue, 11 Jun 2024 11:02:40 +0100 Subject: [PATCH 255/353] Release affinity --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index 45be8631c..5c493be2c 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.26ea3 + 3.26ea3-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity From 3258abc52130de6c39a032044c696e8f2a4a5392 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Thu, 13 Jun 2024 09:10:23 +0100 Subject: [PATCH 256/353] Updating to bom version 2.26ea9 --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index 5c493be2c..60c1276d1 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea-SNAPSHOT + 2.26ea9 pom import From ae4ee4ebdbfc2c8d14631b1cdf3d7e8759aff43b Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Thu, 13 Jun 2024 09:10:38 +0100 Subject: [PATCH 257/353] Reverting back to bom version 2.26ea-SNAPSHOT --- affinity/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index 60c1276d1..45be8631c 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.26ea3-SNAPSHOT + 3.26ea3 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea9 + 2.26ea-SNAPSHOT pom import From d0c0cb130a1aed71f09b7b324f9b7b2088ce50dd Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Fri, 14 Jun 2024 14:36:45 +0100 Subject: [PATCH 258/353] revert affinity to 3.23.3 (#124) --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 93e457d06..d324ab26d 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.26ea3-SNAPSHOT + 3.26ea4-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test diff --git a/affinity/pom.xml b/affinity/pom.xml index 45be8631c..410f53d28 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.26ea3 + 3.26ea4-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity diff --git a/pom.xml b/pom.xml index 1e11e7cb4..3271c1b61 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.26ea3-SNAPSHOT + 3.26ea4-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent From a6be0bc146afa42756896abdfd44a9cf6c46b43e Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Fri, 14 Jun 2024 21:47:10 +0100 Subject: [PATCH 259/353] Updating to bom version 2.26ea11 --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index 410f53d28..45523d0a3 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea-SNAPSHOT + 2.26ea11 pom import From af618862835862cc8856fcc98bd4ce3a2c8bf824 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Fri, 14 Jun 2024 21:47:25 +0100 Subject: [PATCH 260/353] Reverting back to bom version 2.26ea-SNAPSHOT --- affinity/pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index 45523d0a3..fadcb8df6 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.26ea4-SNAPSHOT + 3.26ea4 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea11 + 2.26ea-SNAPSHOT pom import @@ -269,7 +269,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.26ea3 + Java-Thread-Affinity-3.26ea4 From a881052293ddb83191db4788ad9028d9ce9252d9 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Fri, 14 Jun 2024 22:30:41 +0100 Subject: [PATCH 261/353] Updating to bom version 2.26ea12 --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index fadcb8df6..2d0fb3c6b 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea-SNAPSHOT + 2.26ea12 pom import From 999da9e5ec3179564e56970d80c22161734e1010 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Fri, 14 Jun 2024 22:30:53 +0100 Subject: [PATCH 262/353] Reverting back to bom version 2.26ea-SNAPSHOT --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index 2d0fb3c6b..fadcb8df6 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea12 + 2.26ea-SNAPSHOT pom import From 60033e4d9625ad6b284548f86abbddb294e9035f Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Fri, 14 Jun 2024 22:55:51 +0100 Subject: [PATCH 263/353] Updating to bom version 2.26ea13 --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index fadcb8df6..ba2a60708 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea-SNAPSHOT + 2.26ea13 pom import From e41a026b61c211f32378abe55c8f0797a9fdbf98 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Fri, 14 Jun 2024 22:56:03 +0100 Subject: [PATCH 264/353] Reverting back to bom version 2.26ea-SNAPSHOT --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index ba2a60708..fadcb8df6 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea13 + 2.26ea-SNAPSHOT pom import From 60fc755bab401f51b4d120aa1c83d30ddfa352a4 Mon Sep 17 00:00:00 2001 From: Tom Date: Sat, 15 Jun 2024 13:17:41 +0100 Subject: [PATCH 265/353] Align snapshot versions 3.26ea4-SNAPSHOT (#125) --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index fadcb8df6..ca2a401d6 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.26ea4 + 3.26ea4-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity From f28cdb37f0108f914eb4db5d5c9700b4486c94f5 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Sat, 15 Jun 2024 16:29:43 +0100 Subject: [PATCH 266/353] Updating to bom version 2.26ea14 --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index ca2a401d6..cbe50eab6 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea-SNAPSHOT + 2.26ea14 pom import From c099d7106e2be55896c99cc3f7eaf30f830bb171 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Sat, 15 Jun 2024 16:29:58 +0100 Subject: [PATCH 267/353] Reverting back to bom version 2.26ea-SNAPSHOT --- affinity/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index cbe50eab6..fadcb8df6 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.26ea4-SNAPSHOT + 3.26ea4 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea14 + 2.26ea-SNAPSHOT pom import From 3e66fe1c35b9260516facfa00bd86cebe141d7ba Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Sat, 15 Jun 2024 18:10:32 +0100 Subject: [PATCH 268/353] Updating to bom version 2.26ea15 --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index fadcb8df6..cdd631c61 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea-SNAPSHOT + 2.26ea15 pom import From 680d0b2e1c2480156c1927db15a8bab6d07f5a8a Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Sat, 15 Jun 2024 18:10:46 +0100 Subject: [PATCH 269/353] Reverting back to bom version 2.26ea-SNAPSHOT --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index cdd631c61..fadcb8df6 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea15 + 2.26ea-SNAPSHOT pom import From c744a7b7282becd561edaf0071d237917411ea9e Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Sat, 15 Jun 2024 18:15:29 +0100 Subject: [PATCH 270/353] Updating to bom version 2.26ea16 --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index fadcb8df6..0b6183d08 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea-SNAPSHOT + 2.26ea16 pom import From 3cd3d15b388704ec8794318978ca41f8dd9604e2 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Sat, 15 Jun 2024 18:15:42 +0100 Subject: [PATCH 271/353] Reverting back to bom version 2.26ea-SNAPSHOT --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index 0b6183d08..fadcb8df6 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea16 + 2.26ea-SNAPSHOT pom import From 3bc506762a4a1680218929f69d8a510fb8d6b700 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Sat, 15 Jun 2024 19:05:26 +0100 Subject: [PATCH 272/353] Set snapshot version --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index fadcb8df6..ca2a401d6 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.26ea4 + 3.26ea4-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity From 4f7c73c9f73c460e7b3daf0ce1ac18d27c468913 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Sat, 15 Jun 2024 19:54:01 +0100 Subject: [PATCH 273/353] Updating to bom version 2.26ea17 --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index ca2a401d6..2aa138538 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea-SNAPSHOT + 2.26ea17 pom import From 065f5b028845ab5aeafdf82d52a982ebab4cfcda Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Sat, 15 Jun 2024 19:54:20 +0100 Subject: [PATCH 274/353] [maven-release-plugin] prepare release Java-Thread-Affinity-3.26ea4 --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 2 +- pom.xml | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index d324ab26d..df7887064 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.26ea4-SNAPSHOT + 3.26ea4 bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.26ea4 scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git diff --git a/affinity/pom.xml b/affinity/pom.xml index 2aa138538..1f1213a2d 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.26ea4-SNAPSHOT + 3.26ea4 bundle OpenHFT/Java-Thread-Affinity/affinity diff --git a/pom.xml b/pom.xml index 3271c1b61..f21e294b4 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.26ea4-SNAPSHOT + 3.26ea4 pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.26ea4 From 562f22f6bda298a309c28ccb43d3b2ed0a412c13 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Sat, 15 Jun 2024 19:54:23 +0100 Subject: [PATCH 275/353] [maven-release-plugin] prepare for next development iteration --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 2 +- pom.xml | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index df7887064..6ab139997 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.26ea4 + 3.26ea5-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.26ea4 + ea scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git diff --git a/affinity/pom.xml b/affinity/pom.xml index 1f1213a2d..03c1f2733 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.26ea4 + 3.26ea5-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity diff --git a/pom.xml b/pom.xml index f21e294b4..4c0fee020 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.26ea4 + 3.26ea5-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.26ea4 + ea From f44ec43781aede29ae8d43b221de5d23b6c1587f Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Sat, 15 Jun 2024 19:54:38 +0100 Subject: [PATCH 276/353] Reverting back to bom version 2.26ea-SNAPSHOT --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index 03c1f2733..caec040d6 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea17 + 2.26ea-SNAPSHOT pom import From 73cc564b0e7beb666b0d201e40a458340e6abdd5 Mon Sep 17 00:00:00 2001 From: rogersimmons <42873823+rogersimmons@users.noreply.github.com> Date: Sat, 29 Jun 2024 18:39:30 +0100 Subject: [PATCH 277/353] Add rdtsc for ARM 64 and 32 bit (#129) * Add rdtsc for ARM 64 and 32 bit * Remove link lib which isn't needed * Add macOS and Widows support for rdtsc() * Add OS detect to Makefile mac build * Add windows support Tweak macOS support * More macOS tweaks --------- Co-authored-by: rogersimmons --- affinity/pom.xml | 2 +- affinity/src/main/c/Makefile | 17 +++++++-- .../c/net_openhft_ticker_impl_JNIClock.cpp | 24 ++++++++++++ ...terprise_internals_impl_NativeAffinity.cpp | 37 ++++++++++++++++--- 4 files changed, 69 insertions(+), 11 deletions(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index caec040d6..ef717e9d5 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -129,7 +129,7 @@ exec - ${project.basedir}/${native.source.dir}/Makefile + make ${project.basedir}/${native.source.dir} diff --git a/affinity/src/main/c/Makefile b/affinity/src/main/c/Makefile index 0138fe1af..ac448e568 100755 --- a/affinity/src/main/c/Makefile +++ b/affinity/src/main/c/Makefile @@ -1,4 +1,3 @@ -#!/usr/bin/make -f # # Makefile for C code # @@ -10,6 +9,16 @@ TARGET := $(TARGET_DIR)/libCEInternals.so WORKING_DIR := $(TARGET_DIR)/../jni +JNI_OS := win32 +UNAME_S:= $(shell uname -s) +ifeq ($(UNAME_S), Linux) + JNI_OS := linux + LRT := -lrt +endif +ifeq ($(UNAME_S), Darwin) + JNI_OS := darwin +endif + JAVA_CLASSES = software.chronicle.enterprise.internals.impl.NativeAffinity net.openhft.ticker.impl.JNIClock JNI_STUBS := $(subst .,_,$(JAVA_CLASSES)) @@ -19,10 +28,10 @@ JAVA_BUILD_DIR := $(TARGET_DIR) JAVA_HOME ?= /usr/java/default JAVA_LIB := $(JAVA_HOME)/jre/lib -JVM_SHARED_LIBS := -L$(JAVA_LIB)/amd64/server -L$(JAVA_LIB)/i386/server -L$(JAVA_LIB)/amd64/jrockit/ -L$(JAVA_LIB)/i386/jrockit/ -L$(JAVA_LIB)/ppc64le/server -L$(JAVA_LIB)/ppc64le/jrockit/ -L$(JAVA_HOME)/lib/server +JVM_SHARED_LIBS := -L"$(JAVA_LIB)/amd64/server" -L"$(JAVA_LIB)/i386/server" -L"$(JAVA_LIB)/amd64/jrockit" -L"$(JAVA_LIB)/i386/jrockit" -L"$(JAVA_LIB)/ppc64le/server" -L"$(JAVA_LIB)/ppc64le/jrockit" -L"$(JAVA_HOME)/lib/server" CXX=g++ -INCLUDES := -I $(JAVA_HOME)/include -I $(JAVA_HOME)/include/linux -I $(WORKING_DIR) +INCLUDES := -I"$(JAVA_HOME)/include" -I"$(JAVA_HOME)/include/$(JNI_OS)" -I"$(WORKING_DIR)" # classpath for javah ifdef CLASSPATH @@ -36,7 +45,7 @@ endif all: $(TARGET) $(TARGET): $(JNI_SOURCES) - $(CXX) -O3 -Wall -shared -fPIC $(JVM_SHARED_LIBS) -ljvm -lrt $(INCLUDES) $(JNI_SOURCES) -o $(TARGET) + $(CXX) -O3 -Wall -shared -fPIC $(JVM_SHARED_LIBS) $(LRT) $(INCLUDES) $(JNI_SOURCES) -o $(TARGET) clean: rm $(TARGET) diff --git a/affinity/src/main/c/net_openhft_ticker_impl_JNIClock.cpp b/affinity/src/main/c/net_openhft_ticker_impl_JNIClock.cpp index e269308a5..d5534c073 100644 --- a/affinity/src/main/c/net_openhft_ticker_impl_JNIClock.cpp +++ b/affinity/src/main/c/net_openhft_ticker_impl_JNIClock.cpp @@ -53,6 +53,30 @@ unsigned long long rdtsc(){ __asm__ __volatile__("mfspr %%r3, 268": "=r" (rval)); return rval; } +#elif defined(__aarch64__) // ARMv8-A (AArch64) +#include +inline uint64_t rdtsc() { + uint64_t virtual_timer_value; + asm volatile("mrs %0, cntvct_el0" : "=r"(virtual_timer_value)); + return virtual_timer_value; +} +#elif defined(__ARM_ARCH) && (__ARM_ARCH >= 7) // ARMv7-A (32-bit) +#include +inline uint64_t rdtsc() { + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + return (uint64_t)ts.tv_sec * 1000000000ULL + (uint64_t)ts.tv_nsec; +} +#elif defined(__APPLE__) +#include +inline uint64_t rdtsc() { + return mach_absolute_time(); +} +#elif defined(_MSC_VER) +#include +inline uint64_t rdtsc() { + return __rdtsc(); +} #endif /* diff --git a/affinity/src/main/c/software_chronicle_enterprise_internals_impl_NativeAffinity.cpp b/affinity/src/main/c/software_chronicle_enterprise_internals_impl_NativeAffinity.cpp index 0a2384022..013b85433 100644 --- a/affinity/src/main/c/software_chronicle_enterprise_internals_impl_NativeAffinity.cpp +++ b/affinity/src/main/c/software_chronicle_enterprise_internals_impl_NativeAffinity.cpp @@ -19,12 +19,14 @@ #endif #include -#include -#include -#include -#include -#include - +#ifdef __linux__ + #include + #include + #include + #include + #include +#endif +#include #include "software_chronicle_enterprise_internals_impl_NativeAffinity.h" /* @@ -35,6 +37,7 @@ JNIEXPORT jbyteArray JNICALL Java_software_chronicle_enterprise_internals_impl_NativeAffinity_getAffinity0 (JNIEnv *env, jclass c) { +#ifdef __linux__ // The default size of the structure supports 1024 CPUs, should be enough // for now In the future we can use dynamic sets, which can support more // CPUs, given OS can handle them as well @@ -53,6 +56,9 @@ JNIEXPORT jbyteArray JNICALL Java_software_chronicle_enterprise_internals_impl_N env->SetByteArrayRegion(ret, 0, size, bytes); return ret; +#else + throw std::runtime_error("Not supported"); +#endif } /* @@ -63,6 +69,7 @@ JNIEXPORT jbyteArray JNICALL Java_software_chronicle_enterprise_internals_impl_N JNIEXPORT void JNICALL Java_software_chronicle_enterprise_internals_impl_NativeAffinity_setAffinity0 (JNIEnv *env, jclass c, jbyteArray affinity) { +#ifdef __linux__ cpu_set_t mask; const size_t size = sizeof(mask); CPU_ZERO(&mask); @@ -71,6 +78,9 @@ JNIEXPORT void JNICALL Java_software_chronicle_enterprise_internals_impl_NativeA memcpy(&mask, bytes, size); sched_setaffinity(0, size, &mask); +#else + throw std::runtime_error("Not supported"); +#endif } /* @@ -80,7 +90,12 @@ JNIEXPORT void JNICALL Java_software_chronicle_enterprise_internals_impl_NativeA */ JNIEXPORT jint JNICALL Java_software_chronicle_enterprise_internals_impl_NativeAffinity_getProcessId0 (JNIEnv *env, jclass c) { +#ifndef __linux__ + throw std::runtime_error("Not supported"); +#else + return (jint) getpid(); +#endif } /* @@ -90,7 +105,12 @@ JNIEXPORT jint JNICALL Java_software_chronicle_enterprise_internals_impl_NativeA */ JNIEXPORT jint JNICALL Java_software_chronicle_enterprise_internals_impl_NativeAffinity_getThreadId0 (JNIEnv *env, jclass c) { +#ifndef __linux__ + throw std::runtime_error("Not supported"); +#else + return (jint) (pid_t) syscall (SYS_gettid); +#endif } /* @@ -100,6 +120,11 @@ JNIEXPORT jint JNICALL Java_software_chronicle_enterprise_internals_impl_NativeA */ JNIEXPORT jint JNICALL Java_software_chronicle_enterprise_internals_impl_NativeAffinity_getCpu0 (JNIEnv *env, jclass c) { +#ifndef __linux__ + throw std::runtime_error("Not supported"); +#else + return (jint) sched_getcpu(); +#endif } From 830b24f0716104d44e3ac65172746914290c90e1 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Thu, 11 Jul 2024 18:06:12 +0100 Subject: [PATCH 278/353] Retrying acquiring a lock after failure to obtain lock file should be an info message, Fixes #130 --- affinity/src/main/java/net/openhft/affinity/LockInventory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/src/main/java/net/openhft/affinity/LockInventory.java b/affinity/src/main/java/net/openhft/affinity/LockInventory.java index 2ca7eb39e..f1b9b1a6d 100644 --- a/affinity/src/main/java/net/openhft/affinity/LockInventory.java +++ b/affinity/src/main/java/net/openhft/affinity/LockInventory.java @@ -89,7 +89,7 @@ private static boolean updateLockForCurrentThread(final boolean bind, final Affi throw e; } catch (IOException e) { - LOGGER.warn("Error occurred acquiring lock", e); + LOGGER.info("Error occurred acquiring lock, trying another " + e); } return false; } From ef4c9d0bfc4517a7c8a2afcbdf272bf67653cd64 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Fri, 19 Jul 2024 17:54:28 +0100 Subject: [PATCH 279/353] Updating to bom version 2.26ea26 --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index ef717e9d5..ec8c8e166 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea-SNAPSHOT + 2.26ea26 pom import From 7a51a6bc2440d5eca4eaaf9c38a0d913bb205087 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Fri, 19 Jul 2024 17:54:50 +0100 Subject: [PATCH 280/353] [maven-release-plugin] prepare release Java-Thread-Affinity-3.26ea5 --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 6ab139997..75fd793e9 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.26ea5-SNAPSHOT + 3.26ea5 bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.26ea5 scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git diff --git a/affinity/pom.xml b/affinity/pom.xml index ec8c8e166..51dd91634 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.26ea5-SNAPSHOT + 3.26ea5 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -269,7 +269,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.26ea4 + Java-Thread-Affinity-3.26ea5 diff --git a/pom.xml b/pom.xml index 4c0fee020..b5c9c6806 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.26ea5-SNAPSHOT + 3.26ea5 pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.26ea5 From 439e7be8180dcd982fc82a070e56f9683a4ea7cb Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Fri, 19 Jul 2024 17:54:54 +0100 Subject: [PATCH 281/353] [maven-release-plugin] prepare for next development iteration --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 75fd793e9..3edb7f160 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.26ea5 + 3.26ea6-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.26ea5 + ea scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git diff --git a/affinity/pom.xml b/affinity/pom.xml index 51dd91634..f27fb9f6d 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.26ea5 + 3.26ea6-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity @@ -269,7 +269,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.26ea5 + Java-Thread-Affinity-3.26ea4 diff --git a/pom.xml b/pom.xml index b5c9c6806..0d24f5c1e 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.26ea5 + 3.26ea6-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.26ea5 + ea From 9d92e04c421a491a2389b49fc473f79229bdec05 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Fri, 19 Jul 2024 17:55:09 +0100 Subject: [PATCH 282/353] Reverting back to bom version 2.26ea-SNAPSHOT --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index f27fb9f6d..65f0dd99d 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea26 + 2.26ea-SNAPSHOT pom import From 7f2e43e8d18a9cb0a5425aeffa9935a49093a682 Mon Sep 17 00:00:00 2001 From: Jerry Shea Date: Mon, 7 Oct 2024 11:20:24 +1100 Subject: [PATCH 283/353] fix NPE --- .../net/openhft/affinity/LockInventory.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/affinity/src/main/java/net/openhft/affinity/LockInventory.java b/affinity/src/main/java/net/openhft/affinity/LockInventory.java index f1b9b1a6d..25714b1d1 100644 --- a/affinity/src/main/java/net/openhft/affinity/LockInventory.java +++ b/affinity/src/main/java/net/openhft/affinity/LockInventory.java @@ -24,6 +24,7 @@ import java.io.IOException; import java.nio.channels.ClosedByInterruptException; +import java.util.Map; import java.util.NavigableMap; import java.util.TreeMap; @@ -117,6 +118,24 @@ public final synchronized void set(CpuLayout cpuLayout) { } locks[cpuLayout.threadId(layoutId)] = lock; } + shrink(physicalCoreLocks); + } + + /** + * If some CPUs are hyper-threaded, but not others, fix up the HT CPUs + */ + private void shrink(NavigableMap physicalCoreLocks) { + for (Map.Entry e : physicalCoreLocks.entrySet()) { + final AffinityLock[] locks = e.getValue(); + for (int i=0; i Date: Mon, 14 Oct 2024 12:11:48 +0100 Subject: [PATCH 284/353] Updating to bom version 2.26ea50 --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index 65f0dd99d..28b0d7136 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea-SNAPSHOT + 2.26ea50 pom import From 14153ba8f339f13e54015bbc7aaa3e816f580e0e Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Mon, 14 Oct 2024 12:12:07 +0100 Subject: [PATCH 285/353] [maven-release-plugin] prepare release Java-Thread-Affinity-3.26ea6 --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 3edb7f160..64931363a 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.26ea6-SNAPSHOT + 3.26ea6 bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.26ea6 scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git diff --git a/affinity/pom.xml b/affinity/pom.xml index 28b0d7136..6235f5a5f 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.26ea6-SNAPSHOT + 3.26ea6 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -269,7 +269,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.26ea4 + Java-Thread-Affinity-3.26ea6 diff --git a/pom.xml b/pom.xml index 0d24f5c1e..cf2b41a59 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.26ea6-SNAPSHOT + 3.26ea6 pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.26ea6 From 3969334cfdebcf8dde596ee26baede100bb0470f Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Mon, 14 Oct 2024 12:12:11 +0100 Subject: [PATCH 286/353] [maven-release-plugin] prepare for next development iteration --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 64931363a..6219ae0cd 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.26ea6 + 3.26ea7-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.26ea6 + ea scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git diff --git a/affinity/pom.xml b/affinity/pom.xml index 6235f5a5f..af2486979 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.26ea6 + 3.26ea7-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity @@ -269,7 +269,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.26ea6 + Java-Thread-Affinity-3.26ea4 diff --git a/pom.xml b/pom.xml index cf2b41a59..95460b583 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.26ea6 + 3.26ea7-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.26ea6 + ea From 59952c6f297cf837288b2c9466c0c7bc216be7ad Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Mon, 14 Oct 2024 12:12:25 +0100 Subject: [PATCH 287/353] Reverting back to bom version 2.26ea-SNAPSHOT --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index af2486979..aeb2f4a2f 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea50 + 2.26ea-SNAPSHOT pom import From 8ba321ce658b3aa498e3785818e34ef19571d0ae Mon Sep 17 00:00:00 2001 From: Tom Date: Mon, 11 Nov 2024 16:21:23 +0000 Subject: [PATCH 288/353] x27ea release roll * Roll version to 2.27ea0-SNAPSHOT * Update pom versions to x.27 snapshot versions --- affinity-test/pom.xml | 6 +++--- affinity/pom.xml | 8 ++++---- pom.xml | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 6219ae0cd..10a19d819 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -21,12 +21,12 @@ net.openhft java-parent-pom - 1.26.0 + 1.27ea0-SNAPSHOT affinity-test - 3.26ea7-SNAPSHOT + 3.27ea0-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -41,7 +41,7 @@ net.openhft third-party-bom - 3.26.0 + 3.27ea0-SNAPSHOT pom import diff --git a/affinity/pom.xml b/affinity/pom.xml index aeb2f4a2f..d5cbfa12b 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -21,12 +21,12 @@ net.openhft java-parent-pom - 1.26.0 + 1.27ea0-SNAPSHOT affinity - 3.26ea7-SNAPSHOT + 3.27ea0-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity @@ -42,14 +42,14 @@ net.openhft third-party-bom - 3.26.0 + 3.27ea0-SNAPSHOT pom import net.openhft chronicle-bom - 2.26ea-SNAPSHOT + 2.27ea-SNAPSHOT pom import diff --git a/pom.xml b/pom.xml index 95460b583..5eb4759bf 100644 --- a/pom.xml +++ b/pom.xml @@ -21,12 +21,12 @@ net.openhft java-parent-pom - 1.26.0 + 1.27ea0-SNAPSHOT Java-Thread-Affinity - 3.26ea7-SNAPSHOT + 3.27ea0-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent From 79dfb0475aad8dcf2aa558c3c2d41dc78fe04cb7 Mon Sep 17 00:00:00 2001 From: Tom Date: Wed, 13 Nov 2024 14:51:15 +0000 Subject: [PATCH 289/353] Bump parent pom and third party bom to release versions (#136) --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 10a19d819..232e47006 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.27ea0-SNAPSHOT + 1.27ea0 @@ -41,7 +41,7 @@ net.openhft third-party-bom - 3.27ea0-SNAPSHOT + 3.27ea0 pom import diff --git a/affinity/pom.xml b/affinity/pom.xml index d5cbfa12b..9e8839580 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.27ea0-SNAPSHOT + 1.27ea0 @@ -42,7 +42,7 @@ net.openhft third-party-bom - 3.27ea0-SNAPSHOT + 3.27ea0 pom import diff --git a/pom.xml b/pom.xml index 5eb4759bf..3f4a19ddc 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.27ea0-SNAPSHOT + 1.27ea0 From 39b85e398acf76c1c7aab9ccdbbea61e999f4891 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Fri, 15 Nov 2024 17:37:21 +0000 Subject: [PATCH 290/353] Updating to bom version 2.27ea0 --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index 9e8839580..74fe31427 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.27ea-SNAPSHOT + 2.27ea0 pom import From a4890dab52e0afe3b89217df6a9c2707a8734c11 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Fri, 15 Nov 2024 17:37:41 +0000 Subject: [PATCH 291/353] [maven-release-plugin] prepare release Java-Thread-Affinity-3.27ea0 --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 232e47006..eba35edf0 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.27ea0-SNAPSHOT + 3.27ea0 bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.27ea0 scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git diff --git a/affinity/pom.xml b/affinity/pom.xml index 74fe31427..f41c60851 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.27ea0-SNAPSHOT + 3.27ea0 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -269,7 +269,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.26ea4 + Java-Thread-Affinity-3.27ea0 diff --git a/pom.xml b/pom.xml index 3f4a19ddc..9982c35aa 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.27ea0-SNAPSHOT + 3.27ea0 pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.27ea0 From 880125221b17a20e9a44c3d50809c6495d45ac72 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Fri, 15 Nov 2024 17:37:44 +0000 Subject: [PATCH 292/353] [maven-release-plugin] prepare for next development iteration --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index eba35edf0..97b6857dc 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.27ea0 + 3.27ea1-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.27ea0 + ea scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git diff --git a/affinity/pom.xml b/affinity/pom.xml index f41c60851..a308d774f 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.27ea0 + 3.27ea1-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity @@ -269,7 +269,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.27ea0 + Java-Thread-Affinity-3.26ea4 diff --git a/pom.xml b/pom.xml index 9982c35aa..d6bd9c4a0 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.27ea0 + 3.27ea1-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.27ea0 + ea From 28d8ca876d57ceb3b40ca6e09bd10d8f883ad63d Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Fri, 15 Nov 2024 17:37:59 +0000 Subject: [PATCH 293/353] Reverting back to bom version 2.27ea-SNAPSHOT --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index a308d774f..6e84f2418 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.27ea0 + 2.27ea-SNAPSHOT pom import From 36c1cec731014df49e16f55419d45f7919178a56 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Thu, 22 May 2025 15:16:29 +0100 Subject: [PATCH 294/353] Update copyright year to 2025 in multiple files --- LICENSE | 2 +- affinity-test/pom.xml | 2 +- .../main/java/net/openhft/affinity/osgi/OSGiPlaceholder.java | 2 +- .../test/java/net/openhft/affinity/osgi/OSGiBundleTest.java | 2 +- .../src/test/java/net/openhft/affinity/osgi/OSGiTestBase.java | 2 +- affinity/pom.xml | 2 +- affinity/src/main/c/net_openhft_ticker_impl_JNIClock.cpp | 2 +- ...are_chronicle_enterprise_internals_impl_NativeAffinity.cpp | 2 +- ...hronicle_enterprise_internals_impl_NativeAffinity_MacOSX.c | 2 +- affinity/src/main/java/net/openhft/affinity/Affinity.java | 2 +- affinity/src/main/java/net/openhft/affinity/AffinityLock.java | 2 +- .../main/java/net/openhft/affinity/AffinityStrategies.java | 2 +- .../src/main/java/net/openhft/affinity/AffinityStrategy.java | 2 +- .../main/java/net/openhft/affinity/AffinityThreadFactory.java | 2 +- .../src/main/java/net/openhft/affinity/BootClassPath.java | 2 +- affinity/src/main/java/net/openhft/affinity/CpuLayout.java | 2 +- affinity/src/main/java/net/openhft/affinity/IAffinity.java | 2 +- affinity/src/main/java/net/openhft/affinity/LockCheck.java | 2 +- .../src/main/java/net/openhft/affinity/LockInventory.java | 2 +- .../main/java/net/openhft/affinity/MicroJitterSampler.java | 4 +--- .../src/main/java/net/openhft/affinity/impl/LinuxHelper.java | 2 +- .../main/java/net/openhft/affinity/impl/LinuxJNAAffinity.java | 2 +- .../src/main/java/net/openhft/affinity/impl/NoCpuLayout.java | 2 +- .../src/main/java/net/openhft/affinity/impl/NullAffinity.java | 2 +- .../main/java/net/openhft/affinity/impl/OSXJNAAffinity.java | 2 +- .../main/java/net/openhft/affinity/impl/PosixJNAAffinity.java | 2 +- .../java/net/openhft/affinity/impl/SolarisJNAAffinity.java | 2 +- .../src/main/java/net/openhft/affinity/impl/Utilities.java | 2 +- .../main/java/net/openhft/affinity/impl/VanillaCpuLayout.java | 2 +- .../main/java/net/openhft/affinity/impl/VersionHelper.java | 2 +- .../java/net/openhft/affinity/impl/WindowsJNAAffinity.java | 2 +- .../affinity/lockchecker/FileLockBasedLockChecker.java | 4 +--- .../java/net/openhft/affinity/lockchecker/LockChecker.java | 4 +--- .../java/net/openhft/affinity/lockchecker/LockReference.java | 4 +--- .../main/java/net/openhft/affinity/main/AffinityTestMain.java | 4 +--- affinity/src/main/java/net/openhft/ticker/ITicker.java | 2 +- affinity/src/main/java/net/openhft/ticker/Ticker.java | 2 +- affinity/src/main/java/net/openhft/ticker/impl/JNIClock.java | 2 +- .../src/main/java/net/openhft/ticker/impl/SystemClock.java | 2 +- .../chronicle/enterprise/internals/impl/NativeAffinity.java | 2 +- .../test/java/net/openhft/affinity/AffinityLockBindMain.java | 2 +- .../src/test/java/net/openhft/affinity/AffinityLockMain.java | 2 +- .../src/test/java/net/openhft/affinity/AffinityLockTest.java | 2 +- .../test/java/net/openhft/affinity/AffinitySupportMain.java | 2 +- .../java/net/openhft/affinity/AffinityThreadFactoryMain.java | 2 +- .../src/test/java/net/openhft/affinity/BaseAffinityTest.java | 4 +--- .../src/test/java/net/openhft/affinity/BootClassPathTest.java | 4 +--- .../test/java/net/openhft/affinity/FileLockLockCheckTest.java | 2 +- .../src/test/java/net/openhft/affinity/InterrupedThread.java | 2 +- .../src/test/java/net/openhft/affinity/LockCheckTest.java | 2 +- .../java/net/openhft/affinity/MultiProcessAffinityTest.java | 4 +--- .../net/openhft/affinity/impl/AbstractAffinityImplTest.java | 2 +- .../java/net/openhft/affinity/impl/LinuxJNAAffinityTest.java | 2 +- .../java/net/openhft/affinity/impl/NativeAffinityImpTest.java | 2 +- .../java/net/openhft/affinity/impl/PosixJNAAffinityTest.java | 2 +- .../java/net/openhft/affinity/impl/VanillaCpuLayoutTest.java | 2 +- .../java/net/openhft/affinity/impl/VersionHelperTest.java | 2 +- .../affinity/testimpl/TestFileLockBasedLockChecker.java | 4 +--- .../src/test/java/net/openhft/ticker/impl/JNIClockTest.java | 2 +- .../chronicle/enterprise/internals/JnaAffinityTest.java | 2 +- .../chronicle/enterprise/internals/NativeAffinityTest.java | 2 +- affinity/src/test/resources/i7.properties | 2 +- pom.xml | 2 +- 63 files changed, 63 insertions(+), 81 deletions(-) diff --git a/LICENSE b/LICENSE index a1993e4de..f7f8b7f7d 100644 --- a/LICENSE +++ b/LICENSE @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright 2014-2018 Chronicle Software Ltd + Copyright 2014-2025 chronicle.software Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 97b6857dc..e90b2d811 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -1,6 +1,6 @@ - sonatype-nexus-staging - https://oss.sonatype.org/content/repositories/staging + + true + + chronicle-enterprise-snapshots + Snapshot Repository + https://nexus.chronicle.software/content/repositories/snapshots + + true + chronicle-enterprise-release + https://nexus.chronicle.software/content/repositories/releases @@ -269,7 +276,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.26ea4 + ea From c7e60bb74ca99a5cc2eea78a0a3f1630a4921dd5 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Fri, 23 May 2025 11:29:12 +0100 Subject: [PATCH 296/353] Add requirements document for Java Thread Affinity library and update README with OS support details --- README.adoc | 129 +++++++- affinity/src/main/adoc/requirements.adoc | 297 ++++++++++++++++++ .../openhft/affinity/impl/LinuxHelper.java | 6 +- 3 files changed, 425 insertions(+), 7 deletions(-) create mode 100644 affinity/src/main/adoc/requirements.adoc diff --git a/README.adoc b/README.adoc index 773c4ffa7..91b0eeb06 100644 --- a/README.adoc +++ b/README.adoc @@ -17,6 +17,20 @@ OpenHFT Java Thread Affinity library See https://github.com/OpenHFT/Java-Thread-Affinity/tree/master/affinity/src/test/java[affinity/src/test/java] for working examples of how to use this library. +=== Supported operating systems + +The library detects the running platform in `Affinity.java` and selects an +implementation for that OS. Features differ between systems: + +* *Linux* - full affinity control via JNA. The implementation can get and set + thread affinity, query the current CPU, and obtain process and thread IDs. +* *Windows* - thread affinity is managed through the kernel API. Process and + thread IDs are available, while `getCpu()` returns `-1`. +* *macOS* - provides process and thread IDs but does not modify affinity and + reports the CPU id as `-1`. +* *Solaris* - mirrors the macOS implementation: only process and thread IDs are + returned with no affinity or CPU querying support. + === Changes * V3.2.0 - Add support for text configuration @@ -47,6 +61,12 @@ for the artifacts `jna` and `jna-platform` in the project's `pom` file. sudo yum install jna +=== Installing JNA on Windows + + choco install jna + +Or download jna.jar and jna-platform.jar from the JNA project and add them to your classpath. + === How does CPU allocation work? The library will read your `/proc/cpuinfo` if you have one or provide one and it will determine your CPU layout. If you don't have one it will assume every CPU is on one CPU socket. @@ -54,7 +74,20 @@ The library looks for isolated CPUs determined by looking at the CPUs you are no i.e. if you have 16 CPUs but 8 of them are not available for general use (as determined by the affinity of the process on startup) it will start assigning to those CPUs. Note: if you have more than one process using this library you need to specify which CPUs the process can use otherwise it will assign the same CPUs to both processes. -To control which CPUs a process can use, add -Daffinity.reserved={cpu-mask-in-hex} to the command line of the process. + +To control which CPUs a process can use, add `-Daffinity.reserved={cpu-mask-in-hex}` +to the command line of the process. The mask is a hexadecimal bit mask without +the `0x` prefix where bit `0` represents CPU `0`, bit `1` represents CPU `1` and +so on. Multiple CPUs can be specified by setting more than one bit. + +For example: + +* `-Daffinity.reserved=2` reserves only CPU `1`. +* `-Daffinity.reserved=6` reserves CPUs `1` and `2`. +* `-Daffinity.reserved=10` reserves CPUs `1` and `3` (hexadecimal `a`). + +Use an appropriate mask when starting each process to avoid reserving the same +cores for multiple JVMs. Note: the CPU 0 is reserved for the Operating System, it has to run somewhere. @@ -76,6 +109,21 @@ To isolate the 1st and 3rd CPU cores (CPU numbers start from 0) on your system, isolcpus=1,3 +Using GRUB +[source] +---- +sudo sed -i 's/^GRUB_CMDLINE_LINUX_DEFAULT="/GRUB_CMDLINE_LINUX_DEFAULT="isolcpus=1,3 /' /etc/default/grub +sudo update-grub +sudo reboot +---- + +Using systemd-boot +[source] +---- +sudo sed -i 's/^options \(.*\)/options \1 isolcpus=1,3/' /boot/loader/entries/*.conf +sudo reboot +---- + == Using AffinityLock === Acquiring a CPU lock for a thread @@ -127,7 +175,21 @@ try (final AffinityLock al = AffinityLock.acquireLock()) { t.start(); } ---- -In this example, the library will prefer a free CPU on the same Socket as the first thread, otherwise it will pick any free CPU. +In this example, the library will prefer a free CPU on the same Socket as the first thread, otherwise it will pick any free CPU. + +=== Affinity strategies +The `AffinityStrategies` enum defines hints for selecting a CPU relative to an existing lock. + +[options="header",cols="1,3"] +|=== +| Strategy | Meaning + +|`ANY`|Use any available CPU. +|`SAME_CORE`|Select a CPU on the same core. +|`SAME_SOCKET`|Select a CPU on the same socket but a different core. +|`DIFFERENT_CORE`|Select a CPU on another core (possibly another socket). +|`DIFFERENT_SOCKET`|Select a CPU on a different socket. +|=== === Getting the thread id You can get the current thread id using @@ -157,10 +219,50 @@ long reservedAffinity = AffinityLock.RESERVED_AFFINITY; ---- If you want to get/set the affinity directly you can do [source, java] ----- +---- long currentAffinity = AffinitySupport.getAffinity(); AffinitySupport.setAffinity(1L << 5); // lock to CPU 5. ----- +---- + +=== Understanding dumpLocks() output + +Several examples print the current CPU assignments using `AffinityLock.dumpLocks()`. +Each line of the output begins with the zero based CPU id followed by the status +of that CPU. Example output might look like: + +[source] +---- +0: Reserved for this application +1: Thread[reader,5,main] alive=true +2: General use CPU +3: CPU not available +---- + +The number on each line is the logical CPU index as recognised by the library. +The text after the colon describes whether that CPU is free, reserved or already +bound to a thread. Use these indices when calling `AffinityLock.acquireLock(n)` +or when constructing explicit affinity masks. + +=== Lock file directory + +AffinityLock stores a small lock file for each CPU. These files are placed in +the directory specified by the `java.io.tmpdir` system property, which by +default points to your system's temporary directory (usually `/tmp` on Linux). + +If you want to keep the lock files elsewhere, set this property before using any +affinity APIs: + +[source, bash] +---- +java -Djava.io.tmpdir=/path/to/dir ... +---- + +or in code + +[source, java] +---- +System.setProperty("java.io.tmpdir", "/path/to/dir"); +---- === Debugging affinity state @@ -185,6 +287,25 @@ $ for i in "$(ls cpu-*)"; ---- +== Using AffinityThreadFactory + +`AffinityThreadFactory` binds each thread it creates according to a set of +`AffinityStrategy` rules. This allows executors to automatically run tasks on +cores selected by the library. + +[source, java] +---- +ExecutorService es = Executors.newFixedThreadPool(4, + new AffinityThreadFactory("worker", + AffinityStrategies.SAME_CORE, + AffinityStrategies.DIFFERENT_SOCKET, + AffinityStrategies.ANY)); +es.submit(() -> { + // your task here +}); +System.out.println("\nThe assignment of CPUs is\n" + AffinityLock.dumpLocks()); +---- + == Support Material https://groups.google.com/forum/?hl=en-GB#!forum/java-thread-affinity[Java Thread Affinity support group] diff --git a/affinity/src/main/adoc/requirements.adoc b/affinity/src/main/adoc/requirements.adoc new file mode 100644 index 000000000..f15cf0ed4 --- /dev/null +++ b/affinity/src/main/adoc/requirements.adoc @@ -0,0 +1,297 @@ += Requirements Document: Java Thread Affinity +Author: Gemini AI +Date: 23 May 2025 +Version: 1.0 +:toc: left +:toclevels: 3 +:sectnums: + +== 1. Introduction + +This document outlines the requirements for the *Java Thread Affinity* library. The primary purpose of this library is to provide Java applications with the capability to control Central Processing Unit (CPU) affinity for their threads. This allows developers to bind specific threads to designated CPU cores, which can lead to performance improvements, especially in latency-sensitive applications, by reducing context switching and improving cache utilisation. + +The library aims to offer a cross-platform API, with the most comprehensive support for Linux systems, leveraging Java Native Access (JNA) and, where applicable, Java Native Interface (JNI) for low-level system interactions. + +== 2. Scope + +The scope of the Java Thread Affinity project includes: + +* Providing mechanisms to get and set thread affinity on supported operating systems. +* Offering a CPU locking mechanism (`AffinityLock`) to manage core reservations for threads or entire cores. +* Detecting or allowing specification of the CPU layout (sockets, cores, threads per core). +* Providing a high-resolution timer. +* Supporting inter-process lock checking for CPU core reservations. +* Delivering a thread factory that assigns affinity to newly created threads. +* Packaging the core library and an OSGi-compatible test bundle. + +== 3. Definitions, Acronyms, and Abbreviations + +* *CPU*: Central Processing Unit +* *JNA*: Java Native Access +* *JNI*: Java Native Interface +* *OS*: Operating System +* *PID*: Process Identifier +* *OSGi*: Open Service Gateway initiative +* *POM*: Project Object Model (Maven) +* *API*: Application Programming Interface + +== 4. References + +* Project Repository: https://github.com/OpenHFT/Java-Thread-Affinity +* JNA: https://github.com/java-native-access/jna + +== 5. Project Overview + +The *Java Thread Affinity* library enables fine-grained control over which CPU cores Java threads execute on. This is particularly beneficial for high-performance computing and low-latency applications where minimising jitter and maximising cache efficiency is critical. The library abstracts OS-specific details, providing a unified Java API. + +=== 5.1. Purpose + +* To allow Java threads to be bound to specific CPU cores. +* To provide tools for understanding and managing CPU topology from within a Java application. +* To offer a high-resolution timing mechanism. + +=== 5.2. Benefits + +* _Performance Improvement_: Reduced thread migration and context switching. +* _Cache Efficiency_: Better utilisation of CPU caches (L1, L2, L3). +* _Jitter Reduction_: More predictable thread execution times. + +== 6. Functional Requirements + +=== 6.1. Core Affinity Control (net.openhft.affinity.Affinity) + +* *FR1*: The system _shall_ allow setting the affinity of the current thread to a specific CPU core or a set of cores (BitSet). +** `Affinity.setAffinity(BitSet affinity)` +** `Affinity.setAffinity(int cpu)` +* *FR2*: The system _shall_ allow retrieving the current affinity mask of the current thread. +** `Affinity.getAffinity()` +* *FR3*: The system _shall_ allow querying the logical CPU ID the current thread is running on. +** `Affinity.getCpu()` +* *FR4*: The system _shall_ allow retrieving the native process ID of the current Java process. +** `IAffinity.getProcessId()` +* *FR5*: The system _shall_ allow retrieving the native thread ID of the current Java thread. +** `IAffinity.getThreadId()` +** `Affinity.setThreadId()` (to update `Thread.tid` via reflection if available) + +=== 6.2. CPU Lock Management (net.openhft.affinity.AffinityLock) + +* *FR6.1*: The system _shall_ provide a mechanism to acquire an exclusive lock on an available CPU core for the current thread. +** `AffinityLock.acquireLock()` +** `AffinityLock.acquireLock(boolean bind)` +** `AffinityLock.acquireLock(int cpuId)` +** `AffinityLock.acquireLock(String desc)` (e.g., "last", "last-N", "N", "any", "none", "csv:1,2,3") +* *FR6.2*: The system _shall_ provide a mechanism to acquire an exclusive lock on an entire physical core (including all its logical CPUs/hyper-threads). +** `AffinityLock.acquireCore()` +** `AffinityLock.acquireCore(boolean bind)` +* *FR6.3*: Acquired locks _shall_ be releasable, restoring the thread's affinity to a base state or a defined default. +** `AffinityLock.release()` +** `AffinityLock.close()` (for try-with-resources) +* *FR6.4*: The system _shall_ support affinity strategies for acquiring new locks relative to existing locks (e.g., same core, same socket, different core, different socket). +** `AffinityLock.acquireLock(AffinityStrategy... strategies)` +** `AffinityStrategies` enum: `ANY`, `SAME_CORE`, `SAME_SOCKET`, `DIFFERENT_CORE`, `DIFFERENT_SOCKET`. +* *FR6.5*: The system _shall_ provide a method to dump the current status of all CPU locks managed by the library. +** `AffinityLock.dumpLocks()` +* *FR6.6*: The system _shall_ allow querying if a lock is allocated and bound. +** `AffinityLock.isAllocated()` +** `AffinityLock.isBound()` + +=== 6.3. CPU Layout Detection (net.openhft.affinity.CpuLayout) + +* *FR7.1*: On Linux, the system _shall_ attempt to automatically detect the CPU layout (sockets, cores per socket, threads per core) by parsing `/proc/cpuinfo`. +** `VanillaCpuLayout.fromCpuInfo()` +* *FR7.2*: The system _shall_ allow applications to programmatically define the CPU layout. +** `AffinityLock.cpuLayout(CpuLayout cpuLayout)` +* *FR7.3*: The CPU layout _shall_ provide information about: +** Total number of logical CPUs: `CpuLayout.cpus()` +** Number of sockets: `CpuLayout.sockets()` +** Cores per socket: `CpuLayout.coresPerSocket()` +** Threads per core: `CpuLayout.threadsPerCore()` +** Mapping a logical CPU ID to its socket, core, and thread ID: `socketId(int)`, `coreId(int)`, `threadId(int)`. +** Hyper-threaded pair for a CPU: `pair(int)`. + +=== 6.4. High-Resolution Timer (net.openhft.ticker.Ticker) + +* *FR8.1*: The system _shall_ provide a high-resolution time source. +** `Ticker.ticks()` (raw timer ticks) +** `Ticker.nanoTime()` (ticks converted to nanoseconds) +* *FR8.2*: If native JNI components are available and loaded (specifically `libCEInternals.so`), the timer _shall_ attempt to use `rdtsc` (Read Time-Stamp Counter). +** `JNIClock.rdtsc0()` +* *FR8.3*: If JNI-based `rdtsc` is not available, the timer _shall_ fall back to `System.nanoTime()`. +** `SystemClock.INSTANCE` +* *FR8.4*: The timer _shall_ provide methods to convert ticks to nanoseconds and microseconds. +** `ITicker.toNanos(long ticks)` +** `ITicker.toMicros(double ticks)` + +=== 6.5. OS-Specific Implementations (net.openhft.affinity.impl) + +* *FR9.1*: The system _shall_ provide tailored implementations of `IAffinity` for different operating systems: +** *Linux*: Full affinity control, CPU ID, Process ID, Thread ID via JNA (`LinuxJNAAffinity`, `PosixJNAAffinity`) or JNI (`NativeAffinity`). +** *Windows*: Thread affinity control, Process ID, Thread ID via JNA (`WindowsJNAAffinity`). `getCpu()` returns -1. +** *macOS*: Process ID, Thread ID via JNA (`OSXJNAAffinity`). No affinity modification; `getCpu()` returns -1. +** *Solaris*: Process ID, Thread ID via JNA (`SolarisJNAAffinity`). No affinity modification; `getCpu()` returns -1. +* *FR9.2*: A `NullAffinity` implementation _shall_ be used as a fallback if no suitable native implementation can be loaded or for unsupported OS. + +=== 6.6. Affinity Thread Factory (net.openhft.affinity.AffinityThreadFactory) + +* *FR10.1*: The system _shall_ provide a `ThreadFactory` that assigns affinity to newly created threads based on specified `AffinityStrategy` rules. +** `new AffinityThreadFactory(String name, AffinityStrategy... strategies)` +* *FR10.2*: If no strategies are provided, `AffinityStrategies.ANY` _shall_ be used by default. + +=== 6.7. Inter-Process Lock Checking (net.openhft.affinity.lockchecker) + +* *FR11.1*: On Linux, the system _shall_ provide a mechanism to check if a specific CPU core is free or already locked by another process. +** `LockCheck.isCpuFree(int cpu)` +* *FR11.2*: This mechanism _shall_ use file-based locks located in the directory specified by the `java.io.tmpdir` system property. +** `FileLockBasedLockChecker` +* *FR11.3*: The system _shall_ allow obtaining and releasing these inter-process locks for specified CPU IDs. +** `LockChecker.obtainLock(int id, int id2, String metaInfo)` +** `LockChecker.releaseLock(int id)` +* *FR11.4*: The system _shall_ store meta-information (e.g., PID of the locking process) within the lock file and allow its retrieval. +** `LockChecker.getMetaInfo(int id)` + +=== 6.8. Native Code Compilation (C/C++) + +* *FR12.1*: The system _shall_ include C/C++ source code for native functions required for affinity and timer operations on Linux and macOS. + ** `software_chronicle_enterprise_internals_impl_NativeAffinity.cpp` (Linux) + ** `software_chronicle_enterprise_internals_impl_NativeAffinity_MacOSX.c` (macOS) + ** `net_openhft_ticker_impl_JNIClock.cpp` (for `rdtsc`) +* *FR12.2*: A Makefile _shall_ be provided to compile the native C/C++ code into a shared library (`libCEInternals.so`). +* *FR12.3*: The Java code _shall_ load this native library if available. +** `software.chronicle.enterprise.internals.impl.NativeAffinity.loadAffinityNativeLibrary()` + +== 7. Non-Functional Requirements + +* *NFR1. Platform Support*: +** *Primary Support*: Linux (full functionality). +** *Partial Support*: Windows (affinity setting, PID/TID, no `getCpu()`). +** *Limited Support*: macOS, Solaris (PID/TID only, no affinity setting or `getCpu()`). +* *NFR2. Dependencies*: +** *JNA*: `net.java.dev.jna:jna`, `net.java.dev.jna:jna-platform`. Version 5.x or higher is recommended for full functionality. The project currently uses version 4.4.0 (as per README, though POMs might show updates). +** *SLF4J API*: `org.slf4j:slf4j-api` for logging. +** *JetBrains Annotations*: `org.jetbrains:annotations` for code quality. +* *NFR3. Performance*: The library _should_ introduce minimal overhead. Native calls _should_ be efficient. The primary goal is to enable performance improvements in the client application. +* *NFR4. Licensing*: The project _shall_ be licensed under the Apache License, Version 2.0. +* *NFR5. Build System*: The project _shall_ use Apache Maven for building and dependency management. +* *NFR6. Language*: +** Core library _shall_ be implemented in Java (1.8+ as per POM). +** Native components _shall_ be implemented in C/C++. +* *NFR7. Usability*: +** The API _should_ be clear and relatively simple to use. +** Javadoc _shall_ be provided for public APIs. +** Example usage _shall_ be available (e.g., in test sources and README). +* *NFR8. Error Handling and Resilience*: +** The library _shall_ degrade gracefully if JNA or native libraries are not available or if an OS does not support certain features (e.g., falling back to `NullAffinity`). +** Errors during native calls _should_ be appropriately logged and/or propagated as exceptions. +* *NFR9. Configuration*: +** Reserved CPUs for the application _shall_ be configurable via the system property `affinity.reserved={hex-mask}`. +** The lock file directory _shall_ default to `java.io.tmpdir` and be overridable by setting this system property. +* *NFR10. OSGi Support*: The `affinity-test` module _shall_ be packaged as an OSGi bundle, demonstrating OSGi compatibility. +* *NFR11. Language Style*: Code and documentation _shall_ use British English, except for established technical US spellings (e.g., `synchronized`). + +== 8. System Architecture + +=== 8.1. High-Level Architecture + +The Java Thread Affinity library is a Java-based system that interfaces with the underlying operating system through JNA (primarily) and JNI (for specific `libCEInternals.so` functionalities). It abstracts OS-specific system calls related to thread affinity, CPU information, and timing. + +=== 8.2. Key Components + +* *`net.openhft.affinity.Affinity`*: Main public API facade for basic affinity operations. +* *`net.openhft.affinity.IAffinity`*: Interface defining the contract for OS-specific implementations. +** Concrete Implementations: `LinuxJNAAffinity`, `WindowsJNAAffinity`, `OSXJNAAffinity`, `SolarisJNAAffinity`, `PosixJNAAffinity`, `NativeAffinity` (JNI), `NullAffinity`. +* *`net.openhft.affinity.AffinityLock`*: Manages CPU reservations and bindings. +* *`net.openhft.affinity.LockInventory`*: Tracks the state of CPU locks based on `CpuLayout`. +* *`net.openhft.affinity.CpuLayout`*: Interface for CPU topology information. +** `VanillaCpuLayout`: Parses `/proc/cpuinfo` or properties files. +** `NoCpuLayout`: Default layout if detection fails. +* *`net.openhft.affinity.AffinityStrategies`*: Enum defining strategies for selecting CPUs. +* *`net.openhft.affinity.AffinityThreadFactory`*: A `java.util.concurrent.ThreadFactory` that sets affinity for new threads. +* *`net.openhft.ticker.Ticker`*: Provides high-resolution time. +** `JNIClock`: Uses `rdtsc` via JNI. +** `SystemClock`: Uses `System.nanoTime()`. +* *`net.openhft.affinity.lockchecker.LockChecker`*: Interface for inter-process lock management. +** `FileLockBasedLockChecker`: Implementation using file system locks. +* *Native Code (`src/main/c`)*: C/C++ sources for `libCEInternals.so` providing functions like `getAffinity0`, `setAffinity0` (Linux JNI), `rdtsc0`. + +=== 8.3. Maven Modules + +* *`Java-Thread-Affinity` (Parent POM)*: Aggregates sub-modules. +** Group ID: `net.openhft` +** Artifact ID: `Java-Thread-Affinity` +* *`affinity` (Core Library)*: Contains the main library code, JNA/JNI integrations, and native sources. +** Artifact ID: `affinity` +** Packaging: `bundle` (OSGi compatible) +* *`affinity-test` (Test Module)*: Contains OSGi integration tests and example usage. +** Artifact ID: `affinity-test` +** Packaging: `bundle` + +== 9. Native Components (libCEInternals.so) + +The library can utilise an optional native shared library, `libCEInternals.so`, for certain operations, primarily on Linux. + +* *Purpose*: Provides direct JNI implementations for thread affinity and the `rdtsc` timer. +* *Source Location*: `Java-Thread-Affinity/affinity/src/main/c/` +* *Build*: Compiled using the `Makefile` in the source directory (typically invoked by Maven's `exec-maven-plugin`). +* *Key Native Functions Implemented*: +** `Java_software_chronicle_enterprise_internals_impl_NativeAffinity_getAffinity0` +** `Java_software_chronicle_enterprise_internals_impl_NativeAffinity_setAffinity0` +** `Java_software_chronicle_enterprise_internals_impl_NativeAffinity_getCpu0` +** `Java_software_chronicle_enterprise_internals_impl_NativeAffinity_getProcessId0` +** `Java_software_chronicle_enterprise_internals_impl_NativeAffinity_getThreadId0` +** `Java_net_openhft_ticker_impl_JNIClock_rdtsc0` +* *Platform Specifics*: +** *Linux*: Uses `sched_getaffinity`, `sched_setaffinity`, `sched_getcpu`, `getpid`, `syscall(SYS_gettid)`. +** *macOS*: (Separate C file `software_chronicle_enterprise_internals_impl_NativeAffinity_MacOSX.c`) Uses `pthread_mach_thread_np`, `thread_policy_get`, `thread_policy_set`. Note: JNA implementations are generally preferred on macOS. +* *Loading*: The `NativeAffinity.java` class attempts to load `System.loadLibrary("CEInternals")`. + +== 10. API Overview + +A brief overview of the primary public classes and interfaces: + +* *`net.openhft.affinity.Affinity`*: +** Static utility methods for basic affinity operations: `getAffinity()`, `setAffinity(BitSet)`, `setAffinity(int cpu)`, `getCpu()`, `getThreadId()`. +** Manages selection of the appropriate `IAffinity` implementation. +* *`net.openhft.affinity.AffinityLock`*: +** Manages acquisition and release of CPU locks: `acquireLock()`, `acquireCore()`, `release()`, `close()`. +** Configures CPU layout: `cpuLayout(CpuLayout)`. +** Provides information about reserved CPUs: `BASE_AFFINITY`, `RESERVED_AFFINITY`. +* *`net.openhft.affinity.AffinityStrategies`*: +** Enum defining CPU selection strategies for `AffinityLock`. +* *`net.openhft.affinity.CpuLayout`*: +** Interface to describe the machine's CPU topology. +* *`net.openhft.affinity.IAffinity`*: +** Core interface implemented by OS-specific providers. +* *`net.openhft.ticker.Ticker`*: +** Static utility for accessing high-resolution time: `ticks()`, `nanoTime()`. +* *`net.openhft.affinity.AffinityThreadFactory`*: +** Implements `java.util.concurrent.ThreadFactory` to create threads with specific affinity settings. + +== 11. Build and Deployment + +* The project is built using Apache Maven. +* The main artifact `net.openhft:affinity` is an OSGi bundle. +* Dependencies are managed via `pom.xml` files, including a `third-party-bom` and `chronicle-bom`. +* The `make-c` profile in `affinity/pom.xml` triggers the compilation of native C code using `make`. +* The `maven-bundle-plugin` is used to generate OSGi manifest information. +* The `maven-scm-publish-plugin` is configured for publishing Javadoc to `gh-pages`. + +== 12. Testing + +The project includes a comprehensive suite of tests: + +* *Unit Tests*: Located in `affinity/src/test/java/`. +** `NativeAffinityTest`, `JnaAffinityTest`: Test core JNI/JNA functionalities. +** `AffinityLockTest`: Tests `AffinityLock` logic, including descriptions and inter-thread lock acquisition. +** `VanillaCpuLayoutTest`, `VanillaCpuLayoutPropertiesParseTest`: Test parsing of `cpuinfo` files and properties files for CPU layout. +** `TickerTest`, `JNIClockTest`: Test timer implementations. +** `LockCheckTest`, `FileLockLockCheckTest`: Test inter-process lock checking. +** `MultiProcessAffinityTest`: Tests affinity locking behavior across multiple Java processes. +* *OSGi Bundle Tests*: Located in `affinity-test/src/test/java/net/openhft/affinity/osgi/`. +** `OSGiBundleTest`: Verifies bundle activation and package exports in an OSGi environment using Pax Exam. +* *Test Resources*: Includes sample `cpuinfo` files for various architectures and corresponding properties files to test layout parsing. +** `affinity/src/test/resources/` +* *Test Infrastructure*: +** `BaseAffinityTest`: Provides common setup for tests, including temporary folder management for lock files. +** `chronicle-test-framework`: Used for some test utilities, like `JavaProcessBuilder` for multi-process tests. + +The tests cover various aspects including basic affinity setting, CPU layout parsing, lock management, multi-threading scenarios, multi-process contention, and OSGi integration. diff --git a/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java b/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java index efde99972..df5cbbc3d 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java @@ -66,9 +66,9 @@ cpu_set_t sched_getaffinity() { return cpuset; } - public static void sched_setaffinity(final BitSet affinity) { - sched_setaffinity(0, affinity); - } + public static void sched_setaffinity(final BitSet affinity) { + sched_setaffinity(0, affinity); + } public static void sched_setaffinity(final int pid, final BitSet affinity) { final CLibrary lib = CLibrary.INSTANCE; From e6f2812ba24d880ca0afdc538d8162b907ba02bb Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Fri, 23 May 2025 11:35:11 +0100 Subject: [PATCH 297/353] Enhance documentation for ITicker interface with detailed description of high resolution time source and utility methods --- .../main/java/net/openhft/ticker/ITicker.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/affinity/src/main/java/net/openhft/ticker/ITicker.java b/affinity/src/main/java/net/openhft/ticker/ITicker.java index 5438e51d8..0763f0871 100644 --- a/affinity/src/main/java/net/openhft/ticker/ITicker.java +++ b/affinity/src/main/java/net/openhft/ticker/ITicker.java @@ -17,8 +17,23 @@ package net.openhft.ticker; -/* - * Created by Peter Lawrey on 13/07/15. +/** + * Abstraction of a high resolution time source used throughout the library. + *

    + * Implementations may be based on {@link System#nanoTime()} or platform + * specific timers such as the processor's time stamp counter accessed via + * JNI. The {@linkplain #ticks() tick values} returned are therefore + * implementation dependent. They always increase monotonically but the unit + * they represent can vary from nanoseconds to CPU cycles. + *

    + * Utility methods are provided to convert these raw ticks into conventional + * time units. For example {@link #toNanos(long)} converts the supplied number + * of ticks to nanoseconds and {@link #toMicros(double)} converts them to + * microseconds. + *

    + * This interface is typically accessed via the {@link net.openhft.ticker.Ticker} + * helper class which selects the best available implementation for the + * running platform. */ public interface ITicker { long nanoTime(); From 32f317ae3a8ae1df8278056adb189f3bf64ceb59 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Fri, 23 May 2025 12:01:03 +0100 Subject: [PATCH 298/353] Code analysis fixes: Refactor code for consistency and readability, including assertion simplifications and formatting improvements --- .../openhft/affinity/osgi/OSGiBundleTest.java | 2 +- .../openhft/affinity/osgi/OSGiTestBase.java | 2 +- .../java/net/openhft/affinity/Affinity.java | 5 ++-- .../net/openhft/affinity/AffinityLock.java | 26 ++++++++++++------- .../affinity/AffinityThreadFactory.java | 12 ++++----- .../net/openhft/affinity/BootClassPath.java | 5 ++-- .../net/openhft/affinity/LockInventory.java | 12 ++++----- .../openhft/affinity/MicroJitterSampler.java | 1 + .../affinity/impl/LinuxJNAAffinity.java | 2 +- .../openhft/affinity/impl/NullAffinity.java | 2 +- .../openhft/affinity/impl/OSXJNAAffinity.java | 2 +- .../affinity/impl/PosixJNAAffinity.java | 2 +- .../affinity/impl/SolarisJNAAffinity.java | 2 +- .../affinity/impl/VanillaCpuLayout.java | 3 ++- .../openhft/affinity/impl/VersionHelper.java | 4 +-- .../lockchecker/FileLockBasedLockChecker.java | 10 +++---- .../affinity/main/AffinityTestMain.java | 7 ++--- .../net/openhft/ticker/impl/JNIClock.java | 5 ++-- .../openhft/affinity/AffinityLockTest.java | 15 ++++------- .../affinity/AffinityThreadFactoryMain.java | 10 +++---- .../affinity/MultiProcessAffinityTest.java | 19 ++++++++------ .../impl/AbstractAffinityImplTest.java | 8 ++---- .../enterprise/internals/JnaAffinityTest.java | 11 +++----- .../internals/NativeAffinityTest.java | 11 +++----- 24 files changed, 84 insertions(+), 94 deletions(-) diff --git a/affinity-test/src/test/java/net/openhft/affinity/osgi/OSGiBundleTest.java b/affinity-test/src/test/java/net/openhft/affinity/osgi/OSGiBundleTest.java index 9d1cfee02..80949898f 100644 --- a/affinity-test/src/test/java/net/openhft/affinity/osgi/OSGiBundleTest.java +++ b/affinity-test/src/test/java/net/openhft/affinity/osgi/OSGiBundleTest.java @@ -64,7 +64,7 @@ public void checkInject() { public void checkBundleState() { final Bundle bundle = findBundle(context, "net.openhft.affinity"); assertNotNull(bundle); - assertEquals(bundle.getState(), Bundle.ACTIVE); + assertEquals(Bundle.ACTIVE, bundle.getState()); } @Test diff --git a/affinity-test/src/test/java/net/openhft/affinity/osgi/OSGiTestBase.java b/affinity-test/src/test/java/net/openhft/affinity/osgi/OSGiTestBase.java index b50b0a8ce..a1e9fcc96 100644 --- a/affinity-test/src/test/java/net/openhft/affinity/osgi/OSGiTestBase.java +++ b/affinity-test/src/test/java/net/openhft/affinity/osgi/OSGiTestBase.java @@ -29,7 +29,7 @@ public class OSGiTestBase { public static Option workspaceBundle(String projectName) { String baseDir = System.getProperty("main.basedir"); - String bundleDir = null; + String bundleDir; bundleDir = String.format("%s/%s/target/classes", baseDir, projectName); if (new File(bundleDir).exists()) { diff --git a/affinity/src/main/java/net/openhft/affinity/Affinity.java b/affinity/src/main/java/net/openhft/affinity/Affinity.java index 034602821..d4654749a 100644 --- a/affinity/src/main/java/net/openhft/affinity/Affinity.java +++ b/affinity/src/main/java/net/openhft/affinity/Affinity.java @@ -190,11 +190,10 @@ public static void setThreadId() { public static boolean isJNAAvailable() { if (JNAAvailable == null) { int majorVersion = Integer.parseInt(Native.VERSION.split("\\.")[0]); - if(majorVersion < 5) { + if (majorVersion < 5) { LOGGER.warn("Affinity library requires JNA version >= 5"); JNAAvailable = false; - } - else { + } else { try { Class.forName("com.sun.jna.Platform"); JNAAvailable = true; diff --git a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java index 5954efcb4..2fcdb4d95 100644 --- a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java +++ b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java @@ -131,7 +131,7 @@ private static BitSet getReservedAffinity0() { reservedAffinity = reservedAffinity.trim(); long[] longs = new long[1 + (reservedAffinity.length() - 1) / 16]; int end = reservedAffinity.length(); - for(int i = 0; i < longs.length ; i++) { + for (int i = 0; i < longs.length; i++) { int begin = Math.max(0, end - 16); longs[i] = Long.parseLong(reservedAffinity.substring(begin, end), 16); end = begin; @@ -186,6 +186,9 @@ public static AffinityLock acquireLock(boolean bind) { * @return A handle for an affinity lock. */ public static AffinityLock acquireLock(int cpuId) { + if (cpuId < 0 || cpuId >= PROCESSORS) { + throw new IllegalArgumentException("cpuId must be between 0 and " + (PROCESSORS - 1) + ": " + cpuId); + } return acquireLock(true, cpuId, AffinityStrategies.ANY); } @@ -199,17 +202,18 @@ public static AffinityLock acquireLock(int cpuId) { * @return A handle for an affinity lock, or nolock if no available CPU in the array */ public static AffinityLock acquireLock(int[] cpus) { - for( int cpu : cpus ) - { + for (int cpu : cpus) { + if (cpu < 0 || cpu >= PROCESSORS) { + throw new IllegalArgumentException("cpuId must be between 0 and " + (PROCESSORS - 1) + ": " + cpu); + } AffinityLock lock = tryAcquireLock(true, cpu); - if(lock != null) - { + if (lock != null) { LOGGER.info("Acquired lock on CPU {}", cpu); return lock; } } - LOGGER.warn("Failed to lock any CPU in explicit list " + Arrays.toString(cpus)); + LOGGER.warn("Failed to lock any CPU in explicit list {}", Arrays.toString(cpus)); return LOCK_INVENTORY.noLock(); } @@ -228,7 +232,7 @@ public static AffinityLock acquireLockLastMinus(int n) { *

      *
    • "N" being a positive integer means allocate this CPU,
    • *
    • "last" or "last-N" means allocate from the end,
    • - *
    • "csv:1,2,5,6 eg means allocate first free core from the provided
    • + *
    • "csv:1,2,5,6" eg means allocate first free core from the provided
    • *
    • "any" means allow any
    • *
    • "none" or null means
    • *
    • "0" is not allowed
    • @@ -281,7 +285,7 @@ public static AffinityLock acquireLock(String desc) { } } if (cpuId <= 0) { - System.err.println("Cannot allocate 0 or negative cpuIds '" + desc + "'"); + LOGGER.warn("Cannot allocate 0 or negative cpuIds '{}'", desc); return LOCK_INVENTORY.noLock(); } return acquireLock(cpuId); @@ -309,7 +313,7 @@ private static AffinityLock acquireLock(boolean bind, int cpuId, @NotNull Affini * Try to acquire a lock on the specified core * Returns lock if successful, or null if cpu cannot be acquired * - * @param bind - if true, bind the current thread; if false, reserve a cpu which can be bound later + * @param bind - if true, bind the current thread; if false, reserve a cpu which can be bound later * @param cpuId - the cpu to lock * @return - A handle to an affinity lock on success; null if failed to lock */ @@ -332,7 +336,9 @@ public static String dumpLocks() { private static boolean areAssertionsEnabled() { boolean debug = false; + //noinspection AssertWithSideEffects assert debug = true; + //noinspection ConstantValue return debug; } @@ -450,7 +456,7 @@ public void close() { @Override protected void finalize() throws Throwable { if (bound) { - LOGGER.warn("Affinity lock for " + assignedThread + " was discarded rather than release()d in a controlled manner.", boundHere); + LOGGER.warn("Affinity lock for {} was discarded rather than release()d in a controlled manner.", assignedThread, boundHere); release(); } super.finalize(); diff --git a/affinity/src/main/java/net/openhft/affinity/AffinityThreadFactory.java b/affinity/src/main/java/net/openhft/affinity/AffinityThreadFactory.java index 91bd4d29b..7f789a4e5 100644 --- a/affinity/src/main/java/net/openhft/affinity/AffinityThreadFactory.java +++ b/affinity/src/main/java/net/openhft/affinity/AffinityThreadFactory.java @@ -53,13 +53,11 @@ public AffinityThreadFactory(String name, boolean daemon, @NotNull AffinityStrat public synchronized Thread newThread(@NotNull final Runnable r) { String name2 = id <= 1 ? name : (name + '-' + id); id++; - Thread t = new Thread(new Runnable() { - @Override - public void run() { - try (AffinityLock ignored = acquireLockBasedOnLast()) { - assert ignored != null; - r.run(); - } + Thread t = new Thread(() -> { + try (AffinityLock ignored = acquireLockBasedOnLast()) { + //noinspection ConstantValue + assert ignored != null; + r.run(); } }, name2); t.setDaemon(daemon); diff --git a/affinity/src/main/java/net/openhft/affinity/BootClassPath.java b/affinity/src/main/java/net/openhft/affinity/BootClassPath.java index 9dfa07f9d..5ae3ca125 100644 --- a/affinity/src/main/java/net/openhft/affinity/BootClassPath.java +++ b/affinity/src/main/java/net/openhft/affinity/BootClassPath.java @@ -17,6 +17,7 @@ package net.openhft.affinity; +import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -87,7 +88,7 @@ private static Set findResourcesInDirectory(final Path path, final Logge try { Files.walkFileTree(path, new SimpleFileVisitor() { @Override - public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException { + public @NotNull FileVisitResult visitFile(final @NotNull Path file, final @NotNull BasicFileAttributes attrs) throws IOException { if (file.getFileName().toString().endsWith(".class")) { dirResources.add(path.relativize(file).toString()); } @@ -95,7 +96,7 @@ public FileVisitResult visitFile(final Path file, final BasicFileAttributes attr } }); } catch (IOException e) { - logger.warn("Error walking dir: " + path, e); + logger.warn("Error walking dir: {}", path, e); } return dirResources; diff --git a/affinity/src/main/java/net/openhft/affinity/LockInventory.java b/affinity/src/main/java/net/openhft/affinity/LockInventory.java index 4b96edeec..b3743d3b6 100644 --- a/affinity/src/main/java/net/openhft/affinity/LockInventory.java +++ b/affinity/src/main/java/net/openhft/affinity/LockInventory.java @@ -53,7 +53,7 @@ public static String dumpLocks(@NotNull AffinityLock[] locks) { for (int i = 0; i < locks.length; i++) { AffinityLock al = locks[i]; sb.append(i).append(": "); - sb.append(al.toString()); + sb.append(al); sb.append('\n'); } return sb.toString(); @@ -90,7 +90,7 @@ private static boolean updateLockForCurrentThread(final boolean bind, final Affi throw e; } catch (IOException e) { - LOGGER.info("Error occurred acquiring lock, trying another " + e); + LOGGER.info("Error occurred acquiring lock, trying another {}", String.valueOf(e)); } return false; } @@ -127,7 +127,7 @@ public final synchronized void set(CpuLayout cpuLayout) { private void shrink(NavigableMap physicalCoreLocks) { for (Map.Entry e : physicalCoreLocks.entrySet()) { final AffinityLock[] locks = e.getValue(); - for (int i=0; i cpuDetails = new ArrayList<>(); CpuInfo details = new CpuInfo(); diff --git a/affinity/src/main/java/net/openhft/affinity/impl/VersionHelper.java b/affinity/src/main/java/net/openhft/affinity/impl/VersionHelper.java index 5ad224302..616f49232 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/VersionHelper.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/VersionHelper.java @@ -30,7 +30,7 @@ public VersionHelper(int major_, int minor_, int release_) { } public VersionHelper(String ver) { - if (ver != null && (ver = ver.trim()).length() > 0) { + if (ver != null && !(ver = ver.trim()).isEmpty()) { final String[] parts = ver.split("\\."); major = parts.length > 0 ? Integer.parseInt(parts[0]) : 0; minor = parts.length > 1 ? Integer.parseInt(parts[1]) : 0; @@ -46,7 +46,7 @@ public String toString() { } public boolean equals(Object o) { - if (o != null && (o instanceof VersionHelper)) { + if (o instanceof VersionHelper) { VersionHelper ver = (VersionHelper) o; return this.major == ver.major && this.minor == ver.minor diff --git a/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java b/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java index c13040e1d..a720efb67 100644 --- a/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java +++ b/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java @@ -72,7 +72,7 @@ public synchronized boolean isLockFree(int id) { try (final FileLock fileLock = channel.tryLock(0, Long.MAX_VALUE, true)) { if (fileLock != null && fileLock.isValid()) { if (!lockFile.delete()) { // try and clean up the orphaned lock file - LOGGER.debug("Couldn't delete orphaned lock file " + lockFile); + LOGGER.debug("Couldn't delete orphaned lock file {}", lockFile); } return true; } else { @@ -112,7 +112,7 @@ public synchronized boolean obtainLock(int id, String metaInfo) throws IOExcepti attempt++; } } - LOGGER.warn("Exceeded maximum retries for locking CPU " + id + ", failing acquire"); + LOGGER.warn("Exceeded maximum retries for locking CPU {}, failing acquire", id); return false; } @@ -172,7 +172,7 @@ public synchronized boolean releaseLock(int id) { if (locks[id] != null) { final File lockFile = toFile(id); if (!lockFile.delete()) { - LOGGER.warn("Couldn't delete lock file on release: " + lockFile); + LOGGER.warn("Couldn't delete lock file on release: {}", lockFile); } closeQuietly(locks[id].lock, locks[id].channel); locks[id] = null; @@ -188,7 +188,7 @@ private void closeQuietly(AutoCloseable... closeables) { closeable.close(); } } catch (Exception e) { - LOGGER.warn("Error closing " + closeable.getClass().getName(), e); + LOGGER.warn("Error closing {}", closeable.getClass().getName(), e); } } } @@ -238,7 +238,7 @@ private File tmpDir() { /** * Thrown when another process deleted the lock file between us opening the file and acquiring the lock */ - class ConcurrentLockFileDeletionException extends Exception { + static class ConcurrentLockFileDeletionException extends Exception { private static final long serialVersionUID = 0L; } } diff --git a/affinity/src/main/java/net/openhft/affinity/main/AffinityTestMain.java b/affinity/src/main/java/net/openhft/affinity/main/AffinityTestMain.java index 01ec845b3..78ca56302 100644 --- a/affinity/src/main/java/net/openhft/affinity/main/AffinityTestMain.java +++ b/affinity/src/main/java/net/openhft/affinity/main/AffinityTestMain.java @@ -29,11 +29,11 @@ public class AffinityTestMain { public static void main(String[] args) { - int cpus = 1; + int cpus; if (args.length == 0) { cpus = AffinityLock.cpuLayout().cpus() / 12; } else { - cpus = Integer.valueOf(args[0]); + cpus = Integer.parseInt(args[0]); } for (int i = 0; i < cpus; i++) { @@ -50,9 +50,10 @@ private static void acquireAndDoWork() { System.out.println("Thread (" + threadName + ") locked onto cpu " + al.cpuId()); while (true) { - System.out.println(df.format(new Date()) + " - Thread (" + threadName + ") doing work on cpu " + al.cpuId() + ". IsAllocated = " + al.isAllocated() + ", isBound = " + al.isBound() + ". " + al.toString()); + System.out.println(df.format(new Date()) + " - Thread (" + threadName + ") doing work on cpu " + al.cpuId() + ". IsAllocated = " + al.isAllocated() + ", isBound = " + al.isBound() + ". " + al); try { + //noinspection BusyWait Thread.sleep(10000L); } catch (InterruptedException e) { //nothing diff --git a/affinity/src/main/java/net/openhft/ticker/impl/JNIClock.java b/affinity/src/main/java/net/openhft/ticker/impl/JNIClock.java index b493d6020..58cb01ab6 100644 --- a/affinity/src/main/java/net/openhft/ticker/impl/JNIClock.java +++ b/affinity/src/main/java/net/openhft/ticker/impl/JNIClock.java @@ -65,13 +65,14 @@ static long tscToNano(final long tsc) { return (tsc * RDTSC_FACTOR) >> FACTOR_BITS; } + @SuppressWarnings("StatementWithEmptyBody") private static void estimateFrequency(int factor) { final long start = System.nanoTime(); long now; - while ((now = System.nanoTime()) == start) { + while (System.nanoTime() == start) { } - long end = start + factor * 1000000; + long end = start + factor * 1000000L; final long start0 = rdtsc0(); while ((now = System.nanoTime()) < end) { } diff --git a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java index f4d8bf76e..b8a14dd77 100644 --- a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java +++ b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java @@ -21,7 +21,6 @@ import net.openhft.affinity.impl.VanillaCpuLayout; import net.openhft.affinity.testimpl.TestFileLockBasedLockChecker; import org.hamcrest.MatcherAssert; -import org.jetbrains.annotations.NotNull; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -217,20 +216,16 @@ public void testGettid() { @Test public void testAffinity() throws InterruptedException { - // System.out.println("Started"); logger.info("Started"); displayStatus(); try (AffinityLock al = AffinityLock.acquireLock()) { System.out.println("Main locked"); displayStatus(); - Thread t = new Thread(new Runnable() { - @Override - public void run() { - AffinityLock al2 = al.acquireLock(AffinityStrategies.SAME_SOCKET, AffinityStrategies.ANY); - System.out.println("Thread-0 locked"); - displayStatus(); - al2.release(); - } + Thread t = new Thread(() -> { + AffinityLock al2 = al.acquireLock(AffinityStrategies.SAME_SOCKET, AffinityStrategies.ANY); + System.out.println("Thread-0 locked"); + displayStatus(); + al2.release(); }); t.start(); t.join(); diff --git a/affinity/src/test/java/net/openhft/affinity/AffinityThreadFactoryMain.java b/affinity/src/test/java/net/openhft/affinity/AffinityThreadFactoryMain.java index 9b7960e01..9052239b3 100644 --- a/affinity/src/test/java/net/openhft/affinity/AffinityThreadFactoryMain.java +++ b/affinity/src/test/java/net/openhft/affinity/AffinityThreadFactoryMain.java @@ -37,16 +37,14 @@ private AffinityThreadFactoryMain() { public static void main(String... args) throws InterruptedException { for (int i = 0; i < 12; i++) - ES.submit(new Callable() { - @Override - public Void call() throws InterruptedException { - Thread.sleep(100); - return null; - } + ES.submit((Callable) () -> { + Thread.sleep(100); + return null; }); Thread.sleep(200); System.out.println("\nThe assignment of CPUs is\n" + AffinityLock.dumpLocks()); ES.shutdown(); + //noinspection ResultOfMethodCallIgnored ES.awaitTermination(1, TimeUnit.SECONDS); } } diff --git a/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java b/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java index ed96007fb..6aa948297 100644 --- a/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java +++ b/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java @@ -53,7 +53,7 @@ public void setUp() { } @Test - public void shouldNotAcquireLockOnCoresLockedByOtherProcesses() throws IOException, InterruptedException { + public void shouldNotAcquireLockOnCoresLockedByOtherProcesses() throws InterruptedException { // run the separate affinity locker final Process affinityLockerProcess = JavaProcessBuilder.create(AffinityLockerProcess.class) .withJvmArguments("-Djava.io.tmpdir=" + folder.getRoot().getAbsolutePath()) @@ -64,6 +64,7 @@ public void shouldNotAcquireLockOnCoresLockedByOtherProcesses() throws IOExcepti // wait for the CPU to be locked long endTime = System.currentTimeMillis() + 5_000; while (LockCheck.isCpuFree(lastCpuId)) { + //noinspection BusyWait Thread.sleep(100); if (System.currentTimeMillis() > endTime) { LOGGER.info("Timed out waiting for the lock to be acquired: isAlive={}, exitCode={}", @@ -83,7 +84,7 @@ public void shouldNotAcquireLockOnCoresLockedByOtherProcesses() throws IOExcepti } @Test - public void shouldAllocateCoresCorrectlyUnderContention() throws IOException, InterruptedException { + public void shouldAllocateCoresCorrectlyUnderContention() throws InterruptedException { final int numberOfLockers = Math.max(2, Math.min(12, Runtime.getRuntime().availableProcessors())) / 2; List lockers = new ArrayList<>(); LOGGER.info("Running test with {} locker processes", numberOfLockers); @@ -99,7 +100,7 @@ public void shouldAllocateCoresCorrectlyUnderContention() throws IOException, In } @Test - public void shouldAllocateCoresCorrectlyUnderContentionWithFailures() throws IOException, InterruptedException { + public void shouldAllocateCoresCorrectlyUnderContentionWithFailures() throws InterruptedException { final int numberOfLockers = Math.max(2, Math.min(12, Runtime.getRuntime().availableProcessors())) / 2; List lockers = new ArrayList<>(); LOGGER.info("Running test with {} locker processes", numberOfLockers); @@ -118,7 +119,7 @@ public void shouldAllocateCoresCorrectlyUnderContentionWithFailures() throws IOE } @Test - public void shouldBeAbleToAcquireLockLeftByOtherProcess() throws IOException, InterruptedException { + public void shouldBeAbleToAcquireLockLeftByOtherProcess() throws InterruptedException { final Process process = JavaProcessBuilder.create(AffinityLockerThatDoesNotReleaseProcess.class) .withJvmArguments("-Djava.io.tmpdir=" + folder.getRoot().getAbsolutePath()) .withProgramArguments("last").start(); @@ -214,12 +215,12 @@ public static void main(String[] args) { String cpuIdToLock = args[0]; try (final AffinityLock affinityLock = AffinityLock.acquireLock(cpuIdToLock)) { - LOGGER.info("Got affinity lock " + affinityLock + " at " + LocalDateTime.now() + ", CPU=" + affinityLock.cpuId()); + LOGGER.info("Got affinity lock {} at {}, CPU={}", affinityLock, LocalDateTime.now(), affinityLock.cpuId()); Thread.sleep(Integer.MAX_VALUE); LOGGER.error("Woke from sleep? this should never happen"); } catch (InterruptedException e) { // expected, just end - LOGGER.info("Interrupted at " + LocalDateTime.now() + " lock is released"); + LOGGER.info("Interrupted at {} lock is released", LocalDateTime.now()); } } } @@ -228,13 +229,13 @@ public static void main(String[] args) { * Acquires a lock then ends */ static class AffinityLockerThatDoesNotReleaseProcess { - private static final Logger LOGGER = LoggerFactory.getLogger(AffinityLockerProcess.class); + private static final Logger LOGGER = LoggerFactory.getLogger(AffinityLockerThatDoesNotReleaseProcess.class); public static void main(String[] args) { String cpuIdToLock = args[0]; final AffinityLock affinityLock = AffinityLock.acquireLock(cpuIdToLock); - LOGGER.info("Got affinity lock " + affinityLock + " at " + LocalDateTime.now() + ", CPU=" + affinityLock.cpuId()); + LOGGER.info("Got affinity lock {} at {}, CPU={}", affinityLock, LocalDateTime.now(), affinityLock.cpuId()); } } @@ -253,12 +254,14 @@ public static void main(String[] args) throws InterruptedException, IOException final long maxValue = Long.MAX_VALUE; // a PID that never exists ByteBuffer buffer = ByteBuffer.wrap((maxValue + "\n").getBytes(StandardCharsets.UTF_8)); while (buffer.hasRemaining()) { + //noinspection ResultOfMethodCallIgnored fc.write(buffer); } } } catch (FileAlreadyExistsException e) { LOGGER.info("Failed, trying again"); } + //noinspection BusyWait Thread.sleep(ThreadLocalRandom.current().nextInt(50)); } } diff --git a/affinity/src/test/java/net/openhft/affinity/impl/AbstractAffinityImplTest.java b/affinity/src/test/java/net/openhft/affinity/impl/AbstractAffinityImplTest.java index 02ed43383..5757e32ba 100644 --- a/affinity/src/test/java/net/openhft/affinity/impl/AbstractAffinityImplTest.java +++ b/affinity/src/test/java/net/openhft/affinity/impl/AbstractAffinityImplTest.java @@ -23,8 +23,7 @@ import java.util.BitSet; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; /** * @author cheremin @@ -49,10 +48,7 @@ public void getAffinityCompletesGracefully() { @Test public void getAffinityReturnsValidValue() { final BitSet affinity = getImpl().getAffinity(); - assertTrue( - "Affinity mask " + Utilities.toBinaryString(affinity) + " must be non-empty", - !affinity.isEmpty() - ); + assertFalse("Affinity mask " + Utilities.toBinaryString(affinity) + " must be non-empty", affinity.isEmpty()); final long allCoresMask = (1L << CORES) - 1; assertTrue( "Affinity mask " + Utilities.toBinaryString(affinity) + " must be <=(2^" + CORES + "-1 = " + allCoresMask + ")", diff --git a/affinity/src/test/java/software/chronicle/enterprise/internals/JnaAffinityTest.java b/affinity/src/test/java/software/chronicle/enterprise/internals/JnaAffinityTest.java index db6fa69f4..85f0d7372 100644 --- a/affinity/src/test/java/software/chronicle/enterprise/internals/JnaAffinityTest.java +++ b/affinity/src/test/java/software/chronicle/enterprise/internals/JnaAffinityTest.java @@ -27,8 +27,7 @@ import java.util.BitSet; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; /** * @author peter.lawrey @@ -54,10 +53,7 @@ public void getAffinityCompletesGracefully() { @Test public void getAffinityReturnsValidValue() { final BitSet affinity = getImpl().getAffinity(); - assertTrue( - "Affinity mask " + Utilities.toBinaryString(affinity) + " must be non-empty", - !affinity.isEmpty() - ); + assertFalse("Affinity mask " + Utilities.toBinaryString(affinity) + " must be non-empty", affinity.isEmpty()); final int allCoresMask = (1 << CORES) - 1; assertTrue( "Affinity mask " + Utilities.toBinaryString(affinity) + " must be <=(2^" + CORES + "-1 = " + allCoresMask + ")", @@ -80,8 +76,7 @@ public void getAffinityReturnsValuePreviouslySet() { return; } final IAffinity impl = LinuxJNAAffinity.INSTANCE; - final int cores = CORES; - for (int core = 0; core < cores; core++) { + for (int core = 0; core < CORES; core++) { final BitSet mask = new BitSet(); mask.set(core, true); getAffinityReturnsValuePreviouslySet(impl, mask); diff --git a/affinity/src/test/java/software/chronicle/enterprise/internals/NativeAffinityTest.java b/affinity/src/test/java/software/chronicle/enterprise/internals/NativeAffinityTest.java index 33de98652..6534082b6 100644 --- a/affinity/src/test/java/software/chronicle/enterprise/internals/NativeAffinityTest.java +++ b/affinity/src/test/java/software/chronicle/enterprise/internals/NativeAffinityTest.java @@ -25,8 +25,7 @@ import java.util.BitSet; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; /** * @author peter.lawrey @@ -52,10 +51,7 @@ public void getAffinityCompletesGracefully() { @Test public void getAffinityReturnsValidValue() { final BitSet affinity = getImpl().getAffinity(); - assertTrue( - "Affinity mask " + Utilities.toBinaryString(affinity) + " must be non-empty", - !affinity.isEmpty() - ); + assertFalse("Affinity mask " + Utilities.toBinaryString(affinity) + " must be non-empty", affinity.isEmpty()); final int allCoresMask = (1 << CORES) - 1; assertTrue( "Affinity mask " + Utilities.toBinaryString(affinity) + " must be <=(2^" + CORES + "-1 = " + allCoresMask + ")", @@ -79,8 +75,7 @@ public void getAffinityReturnsValuePreviouslySet() { return; } final IAffinity impl = NativeAffinity.INSTANCE; - final int cores = CORES; - for (int core = 0; core < cores; core++) { + for (int core = 0; core < CORES; core++) { final BitSet mask = new BitSet(); mask.set(core, true); getAffinityReturnsValuePreviouslySet(impl, mask); From 04268d4b8b478628ec8b0f2d4f37e940777da663 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Fri, 23 May 2025 11:43:04 +0100 Subject: [PATCH 299/353] Added tests for edge cases --- .../affinity/AffinityLockDumpLocksTest.java | 58 +++++++++++++++++ .../affinity/AffinityLockReleaseTest.java | 48 ++++++++++++++ .../AffinityResetToBaseAffinityTest.java | 33 ++++++++++ .../affinity/AffinityThreadFactoryTest.java | 55 ++++++++++++++++ .../impl/CpuInfoLayoutMappingTest.java | 44 +++++++++++++ .../openhft/affinity/impl/UtilitiesTest.java | 64 +++++++++++++++++++ .../VanillaCpuLayoutPropertiesParseTest.java | 50 +++++++++++++++ .../src/test/resources/dual.E5405.properties | 24 +++++++ .../src/test/resources/dual.xeon.properties | 20 ++++++ affinity/src/test/resources/i3.properties | 20 ++++++ 10 files changed, 416 insertions(+) create mode 100644 affinity/src/test/java/net/openhft/affinity/AffinityLockDumpLocksTest.java create mode 100644 affinity/src/test/java/net/openhft/affinity/AffinityLockReleaseTest.java create mode 100644 affinity/src/test/java/net/openhft/affinity/AffinityResetToBaseAffinityTest.java create mode 100644 affinity/src/test/java/net/openhft/affinity/AffinityThreadFactoryTest.java create mode 100644 affinity/src/test/java/net/openhft/affinity/impl/CpuInfoLayoutMappingTest.java create mode 100644 affinity/src/test/java/net/openhft/affinity/impl/UtilitiesTest.java create mode 100644 affinity/src/test/java/net/openhft/affinity/impl/VanillaCpuLayoutPropertiesParseTest.java create mode 100644 affinity/src/test/resources/dual.E5405.properties create mode 100644 affinity/src/test/resources/dual.xeon.properties create mode 100644 affinity/src/test/resources/i3.properties diff --git a/affinity/src/test/java/net/openhft/affinity/AffinityLockDumpLocksTest.java b/affinity/src/test/java/net/openhft/affinity/AffinityLockDumpLocksTest.java new file mode 100644 index 000000000..e981e4e12 --- /dev/null +++ b/affinity/src/test/java/net/openhft/affinity/AffinityLockDumpLocksTest.java @@ -0,0 +1,58 @@ +package net.openhft.affinity; + +import net.openhft.affinity.impl.VanillaCpuLayout; +import org.junit.Assume; +import org.junit.Test; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import static org.junit.Assert.assertTrue; + +public class AffinityLockDumpLocksTest extends BaseAffinityTest { + + @Test + public void dumpLocksListsThreadsHoldingLocks() throws Exception { + Assume.assumeTrue(new File("/proc/cpuinfo").exists()); + + AffinityLock.cpuLayout(VanillaCpuLayout.fromCpuInfo()); + int nThreads = Math.min(3, Math.max(1, AffinityLock.PROCESSORS - 1)); + CountDownLatch acquired = new CountDownLatch(nThreads); + CountDownLatch release = new CountDownLatch(1); + List threads = new ArrayList<>(); + + for (int i = 0; i < nThreads; i++) { + String name = "worker-" + i; + Thread t = new Thread(() -> { + try (AffinityLock lock = AffinityLock.acquireLock()) { + supressUnusedWarning(lock); + acquired.countDown(); + release.await(); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + }, name); + threads.add(t); + t.start(); + } + + assertTrue("threads failed to acquire locks", acquired.await(5, TimeUnit.SECONDS)); + + String dump = AffinityLock.dumpLocks(); + for (Thread t : threads) { + assertTrue("Missing entry for " + t.getName(), dump.contains(t.getName())); + } + + release.countDown(); + for (Thread t : threads) { + t.join(); + } + } + + static void supressUnusedWarning(AutoCloseable c) { + // do nothing + } +} diff --git a/affinity/src/test/java/net/openhft/affinity/AffinityLockReleaseTest.java b/affinity/src/test/java/net/openhft/affinity/AffinityLockReleaseTest.java new file mode 100644 index 000000000..4cbc15f4d --- /dev/null +++ b/affinity/src/test/java/net/openhft/affinity/AffinityLockReleaseTest.java @@ -0,0 +1,48 @@ +/* + * Copyright 2016-2025 chronicle.software + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.openhft.affinity; + +import net.openhft.affinity.impl.VanillaCpuLayout; +import org.junit.Test; + +import java.io.File; + +import static org.junit.Assert.assertEquals; + +/** + * Unit test to verify that releasing an {@link AffinityLock} restores the + * affinity mask back to {@link AffinityLock#BASE_AFFINITY}. + */ +public class AffinityLockReleaseTest extends BaseAffinityTest { + + @Test + public void acquireAndReleaseShouldRestoreBaseAffinity() throws Exception { + if (!new File("/proc/cpuinfo").exists()) { + System.out.println("Cannot run affinity test as this system doesn't have a /proc/cpuinfo file"); + return; + } + + // initialise CPU layout from the running machine so acquireLock works + AffinityLock.cpuLayout(VanillaCpuLayout.fromCpuInfo()); + + assertEquals(AffinityLock.BASE_AFFINITY, Affinity.getAffinity()); + AffinityLock lock = AffinityLock.acquireLock(); + assertEquals(1, Affinity.getAffinity().cardinality()); + lock.release(); + assertEquals(AffinityLock.BASE_AFFINITY, Affinity.getAffinity()); + } +} diff --git a/affinity/src/test/java/net/openhft/affinity/AffinityResetToBaseAffinityTest.java b/affinity/src/test/java/net/openhft/affinity/AffinityResetToBaseAffinityTest.java new file mode 100644 index 000000000..502cb0e0b --- /dev/null +++ b/affinity/src/test/java/net/openhft/affinity/AffinityResetToBaseAffinityTest.java @@ -0,0 +1,33 @@ +package net.openhft.affinity; + +import net.openhft.affinity.impl.VanillaCpuLayout; +import org.junit.Test; + +import java.io.File; + +import static org.junit.Assert.assertEquals; + +public class AffinityResetToBaseAffinityTest extends BaseAffinityTest { + + @Test + public void resettingShouldRestoreBaseAffinity() throws Exception { + if (!new File("/proc/cpuinfo").exists()) { + System.out.println("Cannot run affinity test as this system doesn't have a /proc/cpuinfo file"); + return; + } + + // initialise CPU layout from the running machine so acquireLock works + AffinityLock.cpuLayout(VanillaCpuLayout.fromCpuInfo()); + + assertEquals(AffinityLock.BASE_AFFINITY, Affinity.getAffinity()); + AffinityLock lock = AffinityLock.acquireLock(); + try { + assertEquals(1, Affinity.getAffinity().cardinality()); + + Affinity.resetToBaseAffinity(); + assertEquals(AffinityLock.BASE_AFFINITY, Affinity.getAffinity()); + } finally { + lock.release(); + } + } +} diff --git a/affinity/src/test/java/net/openhft/affinity/AffinityThreadFactoryTest.java b/affinity/src/test/java/net/openhft/affinity/AffinityThreadFactoryTest.java new file mode 100644 index 000000000..7377cc7ea --- /dev/null +++ b/affinity/src/test/java/net/openhft/affinity/AffinityThreadFactoryTest.java @@ -0,0 +1,55 @@ +package net.openhft.affinity; + +import org.junit.Assume; +import org.junit.Before; +import org.junit.Test; + +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; + +import static org.junit.Assert.*; + +public class AffinityThreadFactoryTest extends BaseAffinityTest { + + @Before + public void checkLinux() { + Assume.assumeTrue(LockCheck.IS_LINUX); + } + + @Test + public void threadsReceiveDistinctCpus() throws InterruptedException { + int available = Math.max(1, AffinityLock.PROCESSORS - 1); + int nThreads = Math.min(4, available); + + ExecutorService es = Executors.newFixedThreadPool(nThreads, + new AffinityThreadFactory("test")); + + Set cpus = ConcurrentHashMap.newKeySet(); + CountDownLatch ready = new CountDownLatch(nThreads); + CountDownLatch finished = new CountDownLatch(nThreads); + + for (int i = 0; i < nThreads; i++) { + es.submit(() -> { + cpus.add(Affinity.getCpu()); + ready.countDown(); + try { + ready.await(); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + finished.countDown(); + }); + } + + assertTrue(finished.await(5, TimeUnit.SECONDS)); + es.shutdown(); + es.awaitTermination(5, TimeUnit.SECONDS); + + assertFalse(cpus.contains(-1)); + assertEquals(nThreads, cpus.size()); + } +} diff --git a/affinity/src/test/java/net/openhft/affinity/impl/CpuInfoLayoutMappingTest.java b/affinity/src/test/java/net/openhft/affinity/impl/CpuInfoLayoutMappingTest.java new file mode 100644 index 000000000..3cee5d4bc --- /dev/null +++ b/affinity/src/test/java/net/openhft/affinity/impl/CpuInfoLayoutMappingTest.java @@ -0,0 +1,44 @@ +/* + * Copyright 2016-2025 chronicle.software + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.openhft.affinity.impl; + +import org.junit.Test; + +import java.io.IOException; +import java.io.InputStream; + +import static org.junit.Assert.assertEquals; + +public class CpuInfoLayoutMappingTest { + + @Test + public void verifyI7CpuInfoMapping() throws IOException { + final InputStream i7 = getClass().getClassLoader().getResourceAsStream("i7.cpuinfo"); + VanillaCpuLayout vcl = VanillaCpuLayout.fromCpuInfo(i7); + assertEquals( + "0: CpuInfo{socketId=0, coreId=0, threadId=0}\n" + + "1: CpuInfo{socketId=0, coreId=1, threadId=0}\n" + + "2: CpuInfo{socketId=0, coreId=2, threadId=0}\n" + + "3: CpuInfo{socketId=0, coreId=3, threadId=0}\n" + + "4: CpuInfo{socketId=0, coreId=0, threadId=1}\n" + + "5: CpuInfo{socketId=0, coreId=1, threadId=1}\n" + + "6: CpuInfo{socketId=0, coreId=2, threadId=1}\n" + + "7: CpuInfo{socketId=0, coreId=3, threadId=1}\n", + vcl.toString()); + } +} + diff --git a/affinity/src/test/java/net/openhft/affinity/impl/UtilitiesTest.java b/affinity/src/test/java/net/openhft/affinity/impl/UtilitiesTest.java new file mode 100644 index 000000000..45d05dbfd --- /dev/null +++ b/affinity/src/test/java/net/openhft/affinity/impl/UtilitiesTest.java @@ -0,0 +1,64 @@ +/* + * Copyright 2016-2025 chronicle.software + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.openhft.affinity.impl; + +import org.junit.Test; + +import java.util.BitSet; + +import static org.junit.Assert.assertEquals; + +public class UtilitiesTest { + + private static String hex(BitSet set, int... bits) { + set.clear(); + for (int b : bits) { + set.set(b); + } + return Utilities.toHexString(set); + } + + private static String bin(BitSet set, int... bits) { + set.clear(); + for (int b : bits) { + set.set(b); + } + return Utilities.toBinaryString(set); + } + + @Test + public void testToHexString() { + BitSet set = new BitSet(); + assertEquals("", hex(set)); + assertEquals("1", hex(set, 0)); + assertEquals("10", hex(set, 4)); + assertEquals(Long.toHexString(1L << 63), hex(set, 63)); + assertEquals("01", hex(set, 64)); + assertEquals("101", hex(set, 0, 128)); + } + + @Test + public void testToBinaryString() { + BitSet set = new BitSet(); + assertEquals("", bin(set)); + assertEquals("1", bin(set, 0)); + assertEquals("10000", bin(set, 4)); + assertEquals(Long.toBinaryString(1L << 63), bin(set, 63)); + assertEquals("01", bin(set, 64)); + assertEquals("101", bin(set, 0, 128)); + } +} diff --git a/affinity/src/test/java/net/openhft/affinity/impl/VanillaCpuLayoutPropertiesParseTest.java b/affinity/src/test/java/net/openhft/affinity/impl/VanillaCpuLayoutPropertiesParseTest.java new file mode 100644 index 000000000..b539ccf98 --- /dev/null +++ b/affinity/src/test/java/net/openhft/affinity/impl/VanillaCpuLayoutPropertiesParseTest.java @@ -0,0 +1,50 @@ +package net.openhft.affinity.impl; + +import org.junit.Test; + +import java.io.InputStream; + +import static org.junit.Assert.assertEquals; + +public class VanillaCpuLayoutPropertiesParseTest { + + @Test + public void testCountsI7() throws Exception { + InputStream is = getClass().getClassLoader().getResourceAsStream("i7.properties"); + VanillaCpuLayout vcl = VanillaCpuLayout.fromProperties(is); + assertEquals(8, vcl.cpus()); + assertEquals(1, vcl.sockets()); + assertEquals(4, vcl.coresPerSocket()); + assertEquals(2, vcl.threadsPerCore()); + } + + @Test + public void testCountsDualXeon() throws Exception { + InputStream is = getClass().getClassLoader().getResourceAsStream("dual.xeon.properties"); + VanillaCpuLayout vcl = VanillaCpuLayout.fromProperties(is); + assertEquals(4, vcl.cpus()); + assertEquals(2, vcl.sockets()); + assertEquals(1, vcl.coresPerSocket()); + assertEquals(2, vcl.threadsPerCore()); + } + + @Test + public void testCountsDualE5405() throws Exception { + InputStream is = getClass().getClassLoader().getResourceAsStream("dual.E5405.properties"); + VanillaCpuLayout vcl = VanillaCpuLayout.fromProperties(is); + assertEquals(8, vcl.cpus()); + assertEquals(2, vcl.sockets()); + assertEquals(4, vcl.coresPerSocket()); + assertEquals(1, vcl.threadsPerCore()); + } + + @Test + public void testCountsI3() throws Exception { + InputStream is = getClass().getClassLoader().getResourceAsStream("i3.properties"); + VanillaCpuLayout vcl = VanillaCpuLayout.fromProperties(is); + assertEquals(4, vcl.cpus()); + assertEquals(1, vcl.sockets()); + assertEquals(2, vcl.coresPerSocket()); + assertEquals(2, vcl.threadsPerCore()); + } +} diff --git a/affinity/src/test/resources/dual.E5405.properties b/affinity/src/test/resources/dual.E5405.properties new file mode 100644 index 000000000..d656b7376 --- /dev/null +++ b/affinity/src/test/resources/dual.E5405.properties @@ -0,0 +1,24 @@ +# +# Copyright 2016-2025 chronicle.software +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +0=0,0,0 +1=0,1,0 +2=0,2,0 +3=0,3,0 +4=1,4,0 +5=1,5,0 +6=1,6,0 +7=1,7,0 diff --git a/affinity/src/test/resources/dual.xeon.properties b/affinity/src/test/resources/dual.xeon.properties new file mode 100644 index 000000000..36fc4ef90 --- /dev/null +++ b/affinity/src/test/resources/dual.xeon.properties @@ -0,0 +1,20 @@ +# +# Copyright 2016-2025 chronicle.software +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +0=0,0,0 +1=0,0,1 +2=3,3,0 +3=3,3,1 diff --git a/affinity/src/test/resources/i3.properties b/affinity/src/test/resources/i3.properties new file mode 100644 index 000000000..ab4e83876 --- /dev/null +++ b/affinity/src/test/resources/i3.properties @@ -0,0 +1,20 @@ +# +# Copyright 2016-2025 chronicle.software +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +0=0,0,0 +1=0,2,0 +2=0,0,1 +3=0,2,1 From e70ae8d05a78b2733d34953db05490ed5ee0b1eb Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Fri, 23 May 2025 12:17:03 +0100 Subject: [PATCH 300/353] AffinityLock.acquireCore should lock/unlock all cpus ie 2 when hyperthreaded --- .../net/openhft/affinity/AffinityLock.java | 19 ++++-- .../java/net/openhft/affinity/CpuLayout.java | 6 ++ .../java/net/openhft/affinity/LockCheck.java | 12 ++-- .../net/openhft/affinity/LockInventory.java | 12 ++-- .../openhft/affinity/impl/NoCpuLayout.java | 5 ++ .../affinity/impl/VanillaCpuLayout.java | 13 ++++ .../lockchecker/FileLockBasedLockChecker.java | 18 +++++- .../affinity/lockchecker/LockChecker.java | 2 +- .../openhft/affinity/AffinityLockTest.java | 60 +++++++++++++------ .../affinity/FileLockLockCheckTest.java | 6 +- .../net/openhft/affinity/LockCheckTest.java | 8 +-- .../impl/VanillaCpuLayoutPairTest.java | 56 +++++++++++++++++ 12 files changed, 170 insertions(+), 47 deletions(-) create mode 100644 affinity/src/test/java/net/openhft/affinity/impl/VanillaCpuLayoutPairTest.java diff --git a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java index 2fcdb4d95..79d576ac9 100644 --- a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java +++ b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java @@ -69,6 +69,7 @@ public class AffinityLock implements Closeable { * Logical ID of the CPU to which this lock belongs to. */ private final int cpuId; + private final int cpuId2; /** * CPU to which this lock belongs to is of general use. */ @@ -88,9 +89,10 @@ public class AffinityLock implements Closeable { Throwable boundHere; private boolean resetAffinity = true; - AffinityLock(int cpuId, boolean base, boolean reservable, LockInventory lockInventory) { + AffinityLock(int cpuId, int cpuId2, boolean base, boolean reservable, LockInventory lockInventory) { this.lockInventory = lockInventory; this.cpuId = cpuId; + this.cpuId2 = cpuId2; this.base = base; this.reservable = reservable; } @@ -133,7 +135,7 @@ private static BitSet getReservedAffinity0() { int end = reservedAffinity.length(); for (int i = 0; i < longs.length; i++) { int begin = Math.max(0, end - 16); - longs[i] = Long.parseLong(reservedAffinity.substring(begin, end), 16); + longs[i] = Long.parseUnsignedLong(reservedAffinity.substring(begin, end), 16); end = begin; } return BitSet.valueOf(longs); @@ -183,11 +185,11 @@ public static AffinityLock acquireLock(boolean bind) { * for defining your thread layout centrally and passing the handle via dependency injection. * * @param cpuId the CPU id to bind to - * @return A handle for an affinity lock. + * @return A handle for an affinity lock, or no lock if no available CPU in the array */ public static AffinityLock acquireLock(int cpuId) { if (cpuId < 0 || cpuId >= PROCESSORS) { - throw new IllegalArgumentException("cpuId must be between 0 and " + (PROCESSORS - 1) + ": " + cpuId); + return LOCK_INVENTORY.noLock(); } return acquireLock(true, cpuId, AffinityStrategies.ANY); } @@ -204,7 +206,8 @@ public static AffinityLock acquireLock(int cpuId) { public static AffinityLock acquireLock(int[] cpus) { for (int cpu : cpus) { if (cpu < 0 || cpu >= PROCESSORS) { - throw new IllegalArgumentException("cpuId must be between 0 and " + (PROCESSORS - 1) + ": " + cpu); + LOGGER.warn("cpuId {} is out of range", cpu); + continue; } AffinityLock lock = tryAcquireLock(true, cpu); if (lock != null) { @@ -265,7 +268,7 @@ public static AffinityLock acquireLock(String desc) { } else if (desc.startsWith("csv:")) { String content = desc.substring(4); - int[] cpus = Arrays.asList(content.split(",")).stream() + int[] cpus = Arrays.stream(content.split(",")) .map(String::trim) .mapToInt(Integer::parseInt).toArray(); @@ -469,6 +472,10 @@ public int cpuId() { return cpuId; } + public int cpuId2() { + return cpuId2; + } + /** * @return Was a cpu found to bind this lock to. */ diff --git a/affinity/src/main/java/net/openhft/affinity/CpuLayout.java b/affinity/src/main/java/net/openhft/affinity/CpuLayout.java index 7221d7dfb..12cbce61e 100644 --- a/affinity/src/main/java/net/openhft/affinity/CpuLayout.java +++ b/affinity/src/main/java/net/openhft/affinity/CpuLayout.java @@ -49,4 +49,10 @@ public interface CpuLayout { * @return which thread on a core this cpu is on. */ int threadId(int cpuId); + + /** + * @param cpuId the logical processor number + * @return the hyperthreaded pair number or 0 if not hyperthreaded. + */ + int pair(int cpuId); } diff --git a/affinity/src/main/java/net/openhft/affinity/LockCheck.java b/affinity/src/main/java/net/openhft/affinity/LockCheck.java index 259aaf40b..ac9ca6cc1 100644 --- a/affinity/src/main/java/net/openhft/affinity/LockCheck.java +++ b/affinity/src/main/java/net/openhft/affinity/LockCheck.java @@ -55,8 +55,8 @@ public static boolean isCpuFree(int cpu) { return isLockFree(cpu); } - static boolean replacePid(int cpu, long processID) throws IOException { - return storePid(processID, cpu); + static boolean replacePid(int cpu, int cpu2, long processID) throws IOException { + return storePid(processID, cpu, cpu2); } public static boolean isProcessRunning(long pid) { @@ -70,8 +70,8 @@ public static boolean isProcessRunning(long pid) { * stores the pid in a file, named by the core, the pid is written to the file with the date * below */ - private synchronized static boolean storePid(long processID, int cpu) throws IOException { - return lockChecker.obtainLock(cpu, Long.toString(processID)); + private synchronized static boolean storePid(long processID, int cpu, int cpu2) throws IOException { + return lockChecker.obtainLock(cpu, cpu2, Long.toString(processID)); } private synchronized static boolean isLockFree(int id) { @@ -91,10 +91,10 @@ public static int getProcessForCpu(int core) throws IOException { return EMPTY_PID; } - static boolean updateCpu(int cpu) throws IOException { + static boolean updateCpu(int cpu, int cpu2) throws IOException { if (!canOSSupportOperation()) return true; - return replacePid(cpu, getPID()); + return replacePid(cpu, cpu2, getPID()); } public static void releaseLock(int cpu) { diff --git a/affinity/src/main/java/net/openhft/affinity/LockInventory.java b/affinity/src/main/java/net/openhft/affinity/LockInventory.java index b3743d3b6..0fa41b114 100644 --- a/affinity/src/main/java/net/openhft/affinity/LockInventory.java +++ b/affinity/src/main/java/net/openhft/affinity/LockInventory.java @@ -82,7 +82,7 @@ private static boolean isAnyCpu(final int cpuId) { */ private static boolean updateLockForCurrentThread(final boolean bind, final AffinityLock al, final boolean wholeCore) throws ClosedByInterruptException { try { - if (LockCheck.updateCpu(al.cpuId())) { + if (LockCheck.updateCpu(al.cpuId(), wholeCore ? al.cpuId2() : 0)) { al.assignCurrentThread(bind, wholeCore); return true; } @@ -108,7 +108,9 @@ public final synchronized void set(CpuLayout cpuLayout) { final boolean base = AffinityLock.BASE_AFFINITY.get(i); final boolean reservable = AffinityLock.RESERVED_AFFINITY.get(i); LOGGER.trace("cpu {} base={} reservable= {}", i, base, reservable); - AffinityLock lock = logicalCoreLocks[i] = newLock(i, base, reservable); + assert logicalCoreLocks != null; + @SuppressWarnings("resource") + AffinityLock lock = logicalCoreLocks[i] = newLock(i, cpuLayout.pair(i), base, reservable); int layoutId = lock.cpuId(); int physicalCore = toPhysicalCore(layoutId); @@ -277,8 +279,8 @@ public final synchronized String dumpLocks() { return dumpLocks(logicalCoreLocks); } - protected AffinityLock newLock(int cpuId, boolean base, boolean reservable) { - return new AffinityLock(cpuId, base, reservable, this); + protected AffinityLock newLock(int cpuId, int cpuId2, boolean base, boolean reservable) { + return new AffinityLock(cpuId, cpuId2, base, reservable, this); } private void reset(CpuLayout cpuLayout) { @@ -301,6 +303,6 @@ private void releaseAffinityLock(final Thread t, final AffinityLock al, final St } public AffinityLock noLock() { - return newLock(AffinityLock.ANY_CPU, false, false); + return newLock(AffinityLock.ANY_CPU, 0, false, false); } } diff --git a/affinity/src/main/java/net/openhft/affinity/impl/NoCpuLayout.java b/affinity/src/main/java/net/openhft/affinity/impl/NoCpuLayout.java index b22c36cf7..2996bdf0d 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/NoCpuLayout.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/NoCpuLayout.java @@ -64,4 +64,9 @@ public int coreId(int cpuId) { public int threadId(int cpuId) { return 0; } + + @Override + public int pair(int cpuId) { + return 0; + } } diff --git a/affinity/src/main/java/net/openhft/affinity/impl/VanillaCpuLayout.java b/affinity/src/main/java/net/openhft/affinity/impl/VanillaCpuLayout.java index 7c17d1788..74ff2d580 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/VanillaCpuLayout.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/VanillaCpuLayout.java @@ -177,6 +177,19 @@ public int threadId(int cpuId) { return cpuDetails.get(cpuId).threadId; } + @Override + public int pair(int cpuId) { + for (int i = 0; i < cpuDetails.size(); i++) { + CpuInfo info = cpuDetails.get(i); + if (info.socketId == cpuDetails.get(cpuId).socketId && + info.coreId == cpuDetails.get(cpuId).coreId && + info.threadId != cpuDetails.get(cpuId).threadId) { + return i; + } + } + return 0; + } + @NotNull @Override public String toString() { diff --git a/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java b/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java index a720efb67..265d8923f 100644 --- a/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java +++ b/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java @@ -98,14 +98,25 @@ public synchronized boolean isLockFree(int id) { } @Override - public synchronized boolean obtainLock(int id, String metaInfo) throws IOException { + public synchronized boolean obtainLock(int id, int id2, String metaInfo) throws IOException { int attempt = 0; while (attempt < MAX_LOCK_RETRIES) { try { LockReference lockReference = tryAcquireLockOnFile(id, metaInfo); if (lockReference != null) { - locks[id] = lockReference; - return true; + if (id2 <= 0) { + // no second lock to acquire, return success + locks[id] = lockReference; + return true; + } + LockReference lockReference2 = tryAcquireLockOnFile(id2, metaInfo); + if (lockReference2 != null) { + locks[id] = lockReference; + locks[id2] = lockReference2; + return true; + } else { + releaseLock(id); + } } return false; } catch (ConcurrentLockFileDeletionException e) { @@ -163,6 +174,7 @@ private void writeMetaInfoToFile(FileChannel fc, String metaInfo) throws IOExcep byte[] content = String.format("%s%n%s", metaInfo, dfTL.get().format(new Date())).getBytes(); ByteBuffer buffer = ByteBuffer.wrap(content); while (buffer.hasRemaining()) { + //noinspection ResultOfMethodCallIgnored fc.write(buffer); } } diff --git a/affinity/src/main/java/net/openhft/affinity/lockchecker/LockChecker.java b/affinity/src/main/java/net/openhft/affinity/lockchecker/LockChecker.java index 8df4eafa1..62a6c2f52 100644 --- a/affinity/src/main/java/net/openhft/affinity/lockchecker/LockChecker.java +++ b/affinity/src/main/java/net/openhft/affinity/lockchecker/LockChecker.java @@ -26,7 +26,7 @@ public interface LockChecker { boolean isLockFree(int id); - boolean obtainLock(int id, String metaInfo) throws IOException; + boolean obtainLock(int id, int id2, String metaInfo) throws IOException; boolean releaseLock(int id); diff --git a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java index b8a14dd77..943ebdad4 100644 --- a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java +++ b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java @@ -19,7 +19,6 @@ import net.openhft.affinity.impl.Utilities; import net.openhft.affinity.impl.VanillaCpuLayout; -import net.openhft.affinity.testimpl.TestFileLockBasedLockChecker; import org.hamcrest.MatcherAssert; import org.junit.Test; import org.slf4j.Logger; @@ -28,6 +27,7 @@ import java.io.File; import java.io.IOException; import java.nio.file.Files; +import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; @@ -43,20 +43,19 @@ public class AffinityLockTest extends BaseAffinityTest { private static final Logger logger = LoggerFactory.getLogger(AffinityLockTest.class); - private final TestFileLockBasedLockChecker lockChecker = new TestFileLockBasedLockChecker(); @Test public void dumpLocksI7() throws IOException { LockInventory lockInventory = new LockInventory(VanillaCpuLayout.fromCpuInfo("i7.cpuinfo")); AffinityLock[] locks = { - new AffinityLock(0, true, false, lockInventory), - new AffinityLock(1, false, false, lockInventory), - new AffinityLock(2, false, true, lockInventory), - new AffinityLock(3, false, true, lockInventory), - new AffinityLock(4, true, false, lockInventory), - new AffinityLock(5, false, false, lockInventory), - new AffinityLock(6, false, true, lockInventory), - new AffinityLock(7, false, true, lockInventory), + new AffinityLock(0, 0, true, false, lockInventory), + new AffinityLock(1, 5, false, false, lockInventory), + new AffinityLock(2, 6, false, true, lockInventory), + new AffinityLock(3, 7, false, true, lockInventory), + new AffinityLock(4, 0, true, false, lockInventory), + new AffinityLock(5, 1, false, false, lockInventory), + new AffinityLock(6, 2, false, true, lockInventory), + new AffinityLock(7, 3, false, true, lockInventory), }; locks[2].assignedThread = new Thread(new InterrupedThread(), "logger"); locks[2].assignedThread.start(); @@ -86,10 +85,10 @@ public void dumpLocksI7() throws IOException { public void dumpLocksI3() throws IOException { LockInventory lockInventory = new LockInventory(VanillaCpuLayout.fromCpuInfo("i3.cpuinfo")); AffinityLock[] locks = { - new AffinityLock(0, true, false, lockInventory), - new AffinityLock(1, false, true, lockInventory), - new AffinityLock(2, true, false, lockInventory), - new AffinityLock(3, false, true, lockInventory), + new AffinityLock(0, 0, true, false, lockInventory), + new AffinityLock(1, 3, false, true, lockInventory), + new AffinityLock(2, 0, true, false, lockInventory), + new AffinityLock(3, 1, false, true, lockInventory), }; locks[1].assignedThread = new Thread(new InterrupedThread(), "engine"); locks[1].assignedThread.start(); @@ -109,8 +108,8 @@ public void dumpLocksI3() throws IOException { public void dumpLocksCoreDuo() throws IOException { LockInventory lockInventory = new LockInventory(VanillaCpuLayout.fromCpuInfo("core.duo.cpuinfo")); AffinityLock[] locks = { - new AffinityLock(0, true, false, lockInventory), - new AffinityLock(1, false, true, lockInventory), + new AffinityLock(0, 0, true, false, lockInventory), + new AffinityLock(1, 0, false, true, lockInventory), }; locks[1].assignedThread = new Thread(new InterrupedThread(), "engine"); locks[1].assignedThread.start(); @@ -253,11 +252,34 @@ public void lockFilesShouldBeRemovedOnRelease() { } final AffinityLock lock = AffinityLock.acquireLock(); - assertTrue(Files.exists(Paths.get(lockChecker.doToFile(lock.cpuId()).getAbsolutePath()))); + Path lockFile = Paths.get(System.getProperty("java.io.tmpdir"), "cpu-" + lock.cpuId() + ".lock"); + assertTrue(Files.exists(lockFile)); lock.release(); - assertFalse(Files.exists(Paths.get(lockChecker.doToFile(lock.cpuId()).getAbsolutePath()))); + assertFalse(Files.exists(lockFile)); + } + + @Test + public void wholeCoreLockReservesAllLogicalCpus() throws IOException { + if (!Utilities.ISLINUX || !new File("/proc/cpuinfo").exists()) { + return; + } + AffinityLock.cpuLayout(VanillaCpuLayout.fromCpuInfo()); + + CpuLayout layout = AffinityLock.cpuLayout(); + try (AffinityLock lock = AffinityLock.acquireCore()) { + int socketId = layout.socketId(lock.cpuId()); + int coreId = layout.coreId(lock.cpuId()); + for (int i = 0; i < layout.cpus(); i++) { + if (layout.socketId(i) == socketId && layout.coreId(i) == coreId) { + assertFalse("CPU " + i + " should be reserved", LockCheck.isCpuFree(i)); + } + } + } + for (int i = 0; i < layout.cpus(); i++) { + assertTrue("CPU " + i + " should not be reserved", LockCheck.isCpuFree(i)); + } } private void displayStatus() { @@ -308,7 +330,7 @@ public void testTooHighCpuId() { @Test public void testTooHighCpuId2() { - try (AffinityLock ignored = AffinityLock.acquireLock(new int[] {123456})) { + try (AffinityLock ignored = AffinityLock.acquireLock(new int[]{123456})) { assertNotNull(ignored); } } diff --git a/affinity/src/test/java/net/openhft/affinity/FileLockLockCheckTest.java b/affinity/src/test/java/net/openhft/affinity/FileLockLockCheckTest.java index 82b64435a..1d890d5fe 100644 --- a/affinity/src/test/java/net/openhft/affinity/FileLockLockCheckTest.java +++ b/affinity/src/test/java/net/openhft/affinity/FileLockLockCheckTest.java @@ -45,7 +45,7 @@ public void before() { @Test public void test() throws IOException { Assert.assertTrue(LockCheck.isCpuFree(cpu)); - LockCheck.updateCpu(cpu); + LockCheck.updateCpu(cpu, 0); Assert.assertEquals(LockCheck.getPID(), LockCheck.getProcessForCpu(cpu)); } @@ -58,13 +58,13 @@ public void testPidOnLinux() { public void testReplace() throws IOException { cpu++; Assert.assertTrue(LockCheck.isCpuFree(cpu + 1)); - LockCheck.replacePid(cpu, 123L); + LockCheck.replacePid(cpu, 0, 123L); Assert.assertEquals(123L, LockCheck.getProcessForCpu(cpu)); } @Test public void shouldNotBlowUpIfPidFileIsEmpty() throws Exception { - LockCheck.updateCpu(cpu); + LockCheck.updateCpu(cpu, 0); final File file = lockChecker.doToFile(cpu); new RandomAccessFile(file, "rw").setLength(0); diff --git a/affinity/src/test/java/net/openhft/affinity/LockCheckTest.java b/affinity/src/test/java/net/openhft/affinity/LockCheckTest.java index c7f04465b..40f5d18e5 100644 --- a/affinity/src/test/java/net/openhft/affinity/LockCheckTest.java +++ b/affinity/src/test/java/net/openhft/affinity/LockCheckTest.java @@ -46,7 +46,7 @@ public void before() { @Test public void test() throws IOException { Assert.assertTrue(LockCheck.isCpuFree(cpu)); - LockCheck.updateCpu(cpu); + LockCheck.updateCpu(cpu, 0); Assert.assertEquals(LockCheck.getPID(), LockCheck.getProcessForCpu(cpu)); } @@ -59,13 +59,13 @@ public void testPidOnLinux() { public void testReplace() throws IOException { cpu++; Assert.assertTrue(LockCheck.isCpuFree(cpu + 1)); - LockCheck.replacePid(cpu, 123L); + LockCheck.replacePid(cpu, 0, 123L); Assert.assertEquals(123L, LockCheck.getProcessForCpu(cpu)); } @Test public void shouldNotBlowUpIfPidFileIsEmpty() throws Exception { - LockCheck.updateCpu(cpu); + LockCheck.updateCpu(cpu, 0); final File file = lockChecker.doToFile(cpu); new RandomAccessFile(file, "rw").setLength(0); @@ -75,7 +75,7 @@ public void shouldNotBlowUpIfPidFileIsEmpty() throws Exception { @Test public void shouldNotBlowUpIfPidFileIsCorrupt() throws Exception { - LockCheck.updateCpu(cpu); + LockCheck.updateCpu(cpu, 0); final File file = lockChecker.doToFile(cpu); try (final FileWriter writer = new FileWriter(file, false)) { diff --git a/affinity/src/test/java/net/openhft/affinity/impl/VanillaCpuLayoutPairTest.java b/affinity/src/test/java/net/openhft/affinity/impl/VanillaCpuLayoutPairTest.java new file mode 100644 index 000000000..99986acd3 --- /dev/null +++ b/affinity/src/test/java/net/openhft/affinity/impl/VanillaCpuLayoutPairTest.java @@ -0,0 +1,56 @@ +/* + * Copyright 2016-2025 chronicle.software + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.openhft.affinity.impl; + +import org.junit.Test; + +import java.io.IOException; +import java.io.InputStream; + +import static org.junit.Assert.assertEquals; + +/** + * Tests for {@link VanillaCpuLayout#pair(int)} using sample cpuinfo files. + */ +public class VanillaCpuLayoutPairTest { + + @Test + public void testPairForI7() throws IOException { + try (InputStream is = getClass().getClassLoader().getResourceAsStream("i7.cpuinfo")) { + VanillaCpuLayout layout = VanillaCpuLayout.fromCpuInfo(is); + assertEquals(4, layout.pair(0)); + assertEquals(5, layout.pair(1)); + assertEquals(6, layout.pair(2)); + assertEquals(7, layout.pair(3)); + assertEquals(0, layout.pair(4)); + assertEquals(1, layout.pair(5)); + assertEquals(2, layout.pair(6)); + assertEquals(3, layout.pair(7)); + } + } + + @Test + public void testPairForI3() throws IOException { + try (InputStream is = getClass().getClassLoader().getResourceAsStream("i3.cpuinfo")) { + VanillaCpuLayout layout = VanillaCpuLayout.fromCpuInfo(is); + assertEquals(2, layout.pair(0)); + assertEquals(3, layout.pair(1)); + assertEquals(0, layout.pair(2)); + assertEquals(1, layout.pair(3)); + } + } +} From 526cfffaac65e3efd725bf361ce713583560d686 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Fri, 23 May 2025 12:25:12 +0100 Subject: [PATCH 301/353] Add tests for AffinityLock behavior and exception handling --- .../openhft/affinity/AffinityLockTest.java | 49 +++++++++++++++++-- 1 file changed, 44 insertions(+), 5 deletions(-) diff --git a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java index b8a14dd77..75397348d 100644 --- a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java +++ b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java @@ -30,6 +30,7 @@ import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; +import java.util.BitSet; import java.util.List; import static net.openhft.affinity.AffinityLock.PROCESSORS; @@ -300,16 +301,54 @@ public void testAffinityLockDescriptions() { } @Test + public void acquireLockWithoutBindingDoesNotChangeAffinity() { + BitSet before = (BitSet) Affinity.getAffinity().clone(); + try (AffinityLock lock = AffinityLock.acquireLock(false)) { + assertFalse(lock.isBound()); + assertEquals(before, Affinity.getAffinity()); + } + assertEquals(before, Affinity.getAffinity()); + } + + @Test(expected = IllegalArgumentException.class) public void testTooHighCpuId() { - try (AffinityLock ignored = AffinityLock.acquireLock(123456)) { - assertNotNull(ignored); + AffinityLock.acquireLock(123456); } + + @Test(expected = IllegalArgumentException.class) + public void testNegativeCpuId() { + AffinityLock.acquireLock(-1); } - @Test + @Test(expected = IllegalArgumentException.class) public void testTooHighCpuId2() { - try (AffinityLock ignored = AffinityLock.acquireLock(new int[] {123456})) { - assertNotNull(ignored); + AffinityLock.acquireLock(new int[]{123456}); + } + + @Test(expected = IllegalStateException.class) + public void bindingTwoThreadsToSameCpuThrows() throws InterruptedException { + assumeTrue(Runtime.getRuntime().availableProcessors() > 1); + + final AffinityLock lock = AffinityLock.acquireLock(false); + Thread t = new Thread(() -> { + lock.bind(); + try { + Thread.sleep(100); + } catch (InterruptedException ignored) { + // ignored + } + }); + t.start(); + + while (!lock.isBound()) { + Thread.sleep(10); + } + + try { + lock.bind(); + } finally { + t.join(); + lock.release(); } } From 69157afc7beea956dd178da9d286b1c12fb4d6e6 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Fri, 23 May 2025 12:17:03 +0100 Subject: [PATCH 302/353] AffinityLock.acquireCore should lock/unlock all cpus ie 2 when hyperthreaded --- .../net/openhft/affinity/AffinityLock.java | 19 ++++-- .../java/net/openhft/affinity/CpuLayout.java | 6 ++ .../java/net/openhft/affinity/LockCheck.java | 12 ++-- .../net/openhft/affinity/LockInventory.java | 12 ++-- .../openhft/affinity/impl/NoCpuLayout.java | 5 ++ .../affinity/impl/VanillaCpuLayout.java | 13 +++++ .../lockchecker/FileLockBasedLockChecker.java | 18 +++++- .../affinity/lockchecker/LockChecker.java | 2 +- .../openhft/affinity/AffinityLockTest.java | 58 +++++++++++++------ .../affinity/FileLockLockCheckTest.java | 6 +- .../net/openhft/affinity/LockCheckTest.java | 8 +-- .../impl/VanillaCpuLayoutPairTest.java | 56 ++++++++++++++++++ 12 files changed, 169 insertions(+), 46 deletions(-) create mode 100644 affinity/src/test/java/net/openhft/affinity/impl/VanillaCpuLayoutPairTest.java diff --git a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java index 2fcdb4d95..79d576ac9 100644 --- a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java +++ b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java @@ -69,6 +69,7 @@ public class AffinityLock implements Closeable { * Logical ID of the CPU to which this lock belongs to. */ private final int cpuId; + private final int cpuId2; /** * CPU to which this lock belongs to is of general use. */ @@ -88,9 +89,10 @@ public class AffinityLock implements Closeable { Throwable boundHere; private boolean resetAffinity = true; - AffinityLock(int cpuId, boolean base, boolean reservable, LockInventory lockInventory) { + AffinityLock(int cpuId, int cpuId2, boolean base, boolean reservable, LockInventory lockInventory) { this.lockInventory = lockInventory; this.cpuId = cpuId; + this.cpuId2 = cpuId2; this.base = base; this.reservable = reservable; } @@ -133,7 +135,7 @@ private static BitSet getReservedAffinity0() { int end = reservedAffinity.length(); for (int i = 0; i < longs.length; i++) { int begin = Math.max(0, end - 16); - longs[i] = Long.parseLong(reservedAffinity.substring(begin, end), 16); + longs[i] = Long.parseUnsignedLong(reservedAffinity.substring(begin, end), 16); end = begin; } return BitSet.valueOf(longs); @@ -183,11 +185,11 @@ public static AffinityLock acquireLock(boolean bind) { * for defining your thread layout centrally and passing the handle via dependency injection. * * @param cpuId the CPU id to bind to - * @return A handle for an affinity lock. + * @return A handle for an affinity lock, or no lock if no available CPU in the array */ public static AffinityLock acquireLock(int cpuId) { if (cpuId < 0 || cpuId >= PROCESSORS) { - throw new IllegalArgumentException("cpuId must be between 0 and " + (PROCESSORS - 1) + ": " + cpuId); + return LOCK_INVENTORY.noLock(); } return acquireLock(true, cpuId, AffinityStrategies.ANY); } @@ -204,7 +206,8 @@ public static AffinityLock acquireLock(int cpuId) { public static AffinityLock acquireLock(int[] cpus) { for (int cpu : cpus) { if (cpu < 0 || cpu >= PROCESSORS) { - throw new IllegalArgumentException("cpuId must be between 0 and " + (PROCESSORS - 1) + ": " + cpu); + LOGGER.warn("cpuId {} is out of range", cpu); + continue; } AffinityLock lock = tryAcquireLock(true, cpu); if (lock != null) { @@ -265,7 +268,7 @@ public static AffinityLock acquireLock(String desc) { } else if (desc.startsWith("csv:")) { String content = desc.substring(4); - int[] cpus = Arrays.asList(content.split(",")).stream() + int[] cpus = Arrays.stream(content.split(",")) .map(String::trim) .mapToInt(Integer::parseInt).toArray(); @@ -469,6 +472,10 @@ public int cpuId() { return cpuId; } + public int cpuId2() { + return cpuId2; + } + /** * @return Was a cpu found to bind this lock to. */ diff --git a/affinity/src/main/java/net/openhft/affinity/CpuLayout.java b/affinity/src/main/java/net/openhft/affinity/CpuLayout.java index 7221d7dfb..12cbce61e 100644 --- a/affinity/src/main/java/net/openhft/affinity/CpuLayout.java +++ b/affinity/src/main/java/net/openhft/affinity/CpuLayout.java @@ -49,4 +49,10 @@ public interface CpuLayout { * @return which thread on a core this cpu is on. */ int threadId(int cpuId); + + /** + * @param cpuId the logical processor number + * @return the hyperthreaded pair number or 0 if not hyperthreaded. + */ + int pair(int cpuId); } diff --git a/affinity/src/main/java/net/openhft/affinity/LockCheck.java b/affinity/src/main/java/net/openhft/affinity/LockCheck.java index 259aaf40b..ac9ca6cc1 100644 --- a/affinity/src/main/java/net/openhft/affinity/LockCheck.java +++ b/affinity/src/main/java/net/openhft/affinity/LockCheck.java @@ -55,8 +55,8 @@ public static boolean isCpuFree(int cpu) { return isLockFree(cpu); } - static boolean replacePid(int cpu, long processID) throws IOException { - return storePid(processID, cpu); + static boolean replacePid(int cpu, int cpu2, long processID) throws IOException { + return storePid(processID, cpu, cpu2); } public static boolean isProcessRunning(long pid) { @@ -70,8 +70,8 @@ public static boolean isProcessRunning(long pid) { * stores the pid in a file, named by the core, the pid is written to the file with the date * below */ - private synchronized static boolean storePid(long processID, int cpu) throws IOException { - return lockChecker.obtainLock(cpu, Long.toString(processID)); + private synchronized static boolean storePid(long processID, int cpu, int cpu2) throws IOException { + return lockChecker.obtainLock(cpu, cpu2, Long.toString(processID)); } private synchronized static boolean isLockFree(int id) { @@ -91,10 +91,10 @@ public static int getProcessForCpu(int core) throws IOException { return EMPTY_PID; } - static boolean updateCpu(int cpu) throws IOException { + static boolean updateCpu(int cpu, int cpu2) throws IOException { if (!canOSSupportOperation()) return true; - return replacePid(cpu, getPID()); + return replacePid(cpu, cpu2, getPID()); } public static void releaseLock(int cpu) { diff --git a/affinity/src/main/java/net/openhft/affinity/LockInventory.java b/affinity/src/main/java/net/openhft/affinity/LockInventory.java index b3743d3b6..0fa41b114 100644 --- a/affinity/src/main/java/net/openhft/affinity/LockInventory.java +++ b/affinity/src/main/java/net/openhft/affinity/LockInventory.java @@ -82,7 +82,7 @@ private static boolean isAnyCpu(final int cpuId) { */ private static boolean updateLockForCurrentThread(final boolean bind, final AffinityLock al, final boolean wholeCore) throws ClosedByInterruptException { try { - if (LockCheck.updateCpu(al.cpuId())) { + if (LockCheck.updateCpu(al.cpuId(), wholeCore ? al.cpuId2() : 0)) { al.assignCurrentThread(bind, wholeCore); return true; } @@ -108,7 +108,9 @@ public final synchronized void set(CpuLayout cpuLayout) { final boolean base = AffinityLock.BASE_AFFINITY.get(i); final boolean reservable = AffinityLock.RESERVED_AFFINITY.get(i); LOGGER.trace("cpu {} base={} reservable= {}", i, base, reservable); - AffinityLock lock = logicalCoreLocks[i] = newLock(i, base, reservable); + assert logicalCoreLocks != null; + @SuppressWarnings("resource") + AffinityLock lock = logicalCoreLocks[i] = newLock(i, cpuLayout.pair(i), base, reservable); int layoutId = lock.cpuId(); int physicalCore = toPhysicalCore(layoutId); @@ -277,8 +279,8 @@ public final synchronized String dumpLocks() { return dumpLocks(logicalCoreLocks); } - protected AffinityLock newLock(int cpuId, boolean base, boolean reservable) { - return new AffinityLock(cpuId, base, reservable, this); + protected AffinityLock newLock(int cpuId, int cpuId2, boolean base, boolean reservable) { + return new AffinityLock(cpuId, cpuId2, base, reservable, this); } private void reset(CpuLayout cpuLayout) { @@ -301,6 +303,6 @@ private void releaseAffinityLock(final Thread t, final AffinityLock al, final St } public AffinityLock noLock() { - return newLock(AffinityLock.ANY_CPU, false, false); + return newLock(AffinityLock.ANY_CPU, 0, false, false); } } diff --git a/affinity/src/main/java/net/openhft/affinity/impl/NoCpuLayout.java b/affinity/src/main/java/net/openhft/affinity/impl/NoCpuLayout.java index b22c36cf7..2996bdf0d 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/NoCpuLayout.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/NoCpuLayout.java @@ -64,4 +64,9 @@ public int coreId(int cpuId) { public int threadId(int cpuId) { return 0; } + + @Override + public int pair(int cpuId) { + return 0; + } } diff --git a/affinity/src/main/java/net/openhft/affinity/impl/VanillaCpuLayout.java b/affinity/src/main/java/net/openhft/affinity/impl/VanillaCpuLayout.java index 7c17d1788..74ff2d580 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/VanillaCpuLayout.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/VanillaCpuLayout.java @@ -177,6 +177,19 @@ public int threadId(int cpuId) { return cpuDetails.get(cpuId).threadId; } + @Override + public int pair(int cpuId) { + for (int i = 0; i < cpuDetails.size(); i++) { + CpuInfo info = cpuDetails.get(i); + if (info.socketId == cpuDetails.get(cpuId).socketId && + info.coreId == cpuDetails.get(cpuId).coreId && + info.threadId != cpuDetails.get(cpuId).threadId) { + return i; + } + } + return 0; + } + @NotNull @Override public String toString() { diff --git a/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java b/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java index a720efb67..265d8923f 100644 --- a/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java +++ b/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java @@ -98,14 +98,25 @@ public synchronized boolean isLockFree(int id) { } @Override - public synchronized boolean obtainLock(int id, String metaInfo) throws IOException { + public synchronized boolean obtainLock(int id, int id2, String metaInfo) throws IOException { int attempt = 0; while (attempt < MAX_LOCK_RETRIES) { try { LockReference lockReference = tryAcquireLockOnFile(id, metaInfo); if (lockReference != null) { - locks[id] = lockReference; - return true; + if (id2 <= 0) { + // no second lock to acquire, return success + locks[id] = lockReference; + return true; + } + LockReference lockReference2 = tryAcquireLockOnFile(id2, metaInfo); + if (lockReference2 != null) { + locks[id] = lockReference; + locks[id2] = lockReference2; + return true; + } else { + releaseLock(id); + } } return false; } catch (ConcurrentLockFileDeletionException e) { @@ -163,6 +174,7 @@ private void writeMetaInfoToFile(FileChannel fc, String metaInfo) throws IOExcep byte[] content = String.format("%s%n%s", metaInfo, dfTL.get().format(new Date())).getBytes(); ByteBuffer buffer = ByteBuffer.wrap(content); while (buffer.hasRemaining()) { + //noinspection ResultOfMethodCallIgnored fc.write(buffer); } } diff --git a/affinity/src/main/java/net/openhft/affinity/lockchecker/LockChecker.java b/affinity/src/main/java/net/openhft/affinity/lockchecker/LockChecker.java index 8df4eafa1..62a6c2f52 100644 --- a/affinity/src/main/java/net/openhft/affinity/lockchecker/LockChecker.java +++ b/affinity/src/main/java/net/openhft/affinity/lockchecker/LockChecker.java @@ -26,7 +26,7 @@ public interface LockChecker { boolean isLockFree(int id); - boolean obtainLock(int id, String metaInfo) throws IOException; + boolean obtainLock(int id, int id2, String metaInfo) throws IOException; boolean releaseLock(int id); diff --git a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java index 75397348d..18e4e666d 100644 --- a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java +++ b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java @@ -19,7 +19,6 @@ import net.openhft.affinity.impl.Utilities; import net.openhft.affinity.impl.VanillaCpuLayout; -import net.openhft.affinity.testimpl.TestFileLockBasedLockChecker; import org.hamcrest.MatcherAssert; import org.junit.Test; import org.slf4j.Logger; @@ -28,6 +27,7 @@ import java.io.File; import java.io.IOException; import java.nio.file.Files; +import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; import java.util.BitSet; @@ -44,20 +44,19 @@ public class AffinityLockTest extends BaseAffinityTest { private static final Logger logger = LoggerFactory.getLogger(AffinityLockTest.class); - private final TestFileLockBasedLockChecker lockChecker = new TestFileLockBasedLockChecker(); @Test public void dumpLocksI7() throws IOException { LockInventory lockInventory = new LockInventory(VanillaCpuLayout.fromCpuInfo("i7.cpuinfo")); AffinityLock[] locks = { - new AffinityLock(0, true, false, lockInventory), - new AffinityLock(1, false, false, lockInventory), - new AffinityLock(2, false, true, lockInventory), - new AffinityLock(3, false, true, lockInventory), - new AffinityLock(4, true, false, lockInventory), - new AffinityLock(5, false, false, lockInventory), - new AffinityLock(6, false, true, lockInventory), - new AffinityLock(7, false, true, lockInventory), + new AffinityLock(0, 0, true, false, lockInventory), + new AffinityLock(1, 5, false, false, lockInventory), + new AffinityLock(2, 6, false, true, lockInventory), + new AffinityLock(3, 7, false, true, lockInventory), + new AffinityLock(4, 0, true, false, lockInventory), + new AffinityLock(5, 1, false, false, lockInventory), + new AffinityLock(6, 2, false, true, lockInventory), + new AffinityLock(7, 3, false, true, lockInventory), }; locks[2].assignedThread = new Thread(new InterrupedThread(), "logger"); locks[2].assignedThread.start(); @@ -87,10 +86,10 @@ public void dumpLocksI7() throws IOException { public void dumpLocksI3() throws IOException { LockInventory lockInventory = new LockInventory(VanillaCpuLayout.fromCpuInfo("i3.cpuinfo")); AffinityLock[] locks = { - new AffinityLock(0, true, false, lockInventory), - new AffinityLock(1, false, true, lockInventory), - new AffinityLock(2, true, false, lockInventory), - new AffinityLock(3, false, true, lockInventory), + new AffinityLock(0, 0, true, false, lockInventory), + new AffinityLock(1, 3, false, true, lockInventory), + new AffinityLock(2, 0, true, false, lockInventory), + new AffinityLock(3, 1, false, true, lockInventory), }; locks[1].assignedThread = new Thread(new InterrupedThread(), "engine"); locks[1].assignedThread.start(); @@ -110,8 +109,8 @@ public void dumpLocksI3() throws IOException { public void dumpLocksCoreDuo() throws IOException { LockInventory lockInventory = new LockInventory(VanillaCpuLayout.fromCpuInfo("core.duo.cpuinfo")); AffinityLock[] locks = { - new AffinityLock(0, true, false, lockInventory), - new AffinityLock(1, false, true, lockInventory), + new AffinityLock(0, 0, true, false, lockInventory), + new AffinityLock(1, 0, false, true, lockInventory), }; locks[1].assignedThread = new Thread(new InterrupedThread(), "engine"); locks[1].assignedThread.start(); @@ -254,11 +253,34 @@ public void lockFilesShouldBeRemovedOnRelease() { } final AffinityLock lock = AffinityLock.acquireLock(); - assertTrue(Files.exists(Paths.get(lockChecker.doToFile(lock.cpuId()).getAbsolutePath()))); + Path lockFile = Paths.get(System.getProperty("java.io.tmpdir"), "cpu-" + lock.cpuId() + ".lock"); + assertTrue(Files.exists(lockFile)); lock.release(); - assertFalse(Files.exists(Paths.get(lockChecker.doToFile(lock.cpuId()).getAbsolutePath()))); + assertFalse(Files.exists(lockFile)); + } + + @Test + public void wholeCoreLockReservesAllLogicalCpus() throws IOException { + if (!Utilities.ISLINUX || !new File("/proc/cpuinfo").exists()) { + return; + } + AffinityLock.cpuLayout(VanillaCpuLayout.fromCpuInfo()); + + CpuLayout layout = AffinityLock.cpuLayout(); + try (AffinityLock lock = AffinityLock.acquireCore()) { + int socketId = layout.socketId(lock.cpuId()); + int coreId = layout.coreId(lock.cpuId()); + for (int i = 0; i < layout.cpus(); i++) { + if (layout.socketId(i) == socketId && layout.coreId(i) == coreId) { + assertFalse("CPU " + i + " should be reserved", LockCheck.isCpuFree(i)); + } + } + } + for (int i = 0; i < layout.cpus(); i++) { + assertTrue("CPU " + i + " should not be reserved", LockCheck.isCpuFree(i)); + } } private void displayStatus() { diff --git a/affinity/src/test/java/net/openhft/affinity/FileLockLockCheckTest.java b/affinity/src/test/java/net/openhft/affinity/FileLockLockCheckTest.java index 82b64435a..1d890d5fe 100644 --- a/affinity/src/test/java/net/openhft/affinity/FileLockLockCheckTest.java +++ b/affinity/src/test/java/net/openhft/affinity/FileLockLockCheckTest.java @@ -45,7 +45,7 @@ public void before() { @Test public void test() throws IOException { Assert.assertTrue(LockCheck.isCpuFree(cpu)); - LockCheck.updateCpu(cpu); + LockCheck.updateCpu(cpu, 0); Assert.assertEquals(LockCheck.getPID(), LockCheck.getProcessForCpu(cpu)); } @@ -58,13 +58,13 @@ public void testPidOnLinux() { public void testReplace() throws IOException { cpu++; Assert.assertTrue(LockCheck.isCpuFree(cpu + 1)); - LockCheck.replacePid(cpu, 123L); + LockCheck.replacePid(cpu, 0, 123L); Assert.assertEquals(123L, LockCheck.getProcessForCpu(cpu)); } @Test public void shouldNotBlowUpIfPidFileIsEmpty() throws Exception { - LockCheck.updateCpu(cpu); + LockCheck.updateCpu(cpu, 0); final File file = lockChecker.doToFile(cpu); new RandomAccessFile(file, "rw").setLength(0); diff --git a/affinity/src/test/java/net/openhft/affinity/LockCheckTest.java b/affinity/src/test/java/net/openhft/affinity/LockCheckTest.java index c7f04465b..40f5d18e5 100644 --- a/affinity/src/test/java/net/openhft/affinity/LockCheckTest.java +++ b/affinity/src/test/java/net/openhft/affinity/LockCheckTest.java @@ -46,7 +46,7 @@ public void before() { @Test public void test() throws IOException { Assert.assertTrue(LockCheck.isCpuFree(cpu)); - LockCheck.updateCpu(cpu); + LockCheck.updateCpu(cpu, 0); Assert.assertEquals(LockCheck.getPID(), LockCheck.getProcessForCpu(cpu)); } @@ -59,13 +59,13 @@ public void testPidOnLinux() { public void testReplace() throws IOException { cpu++; Assert.assertTrue(LockCheck.isCpuFree(cpu + 1)); - LockCheck.replacePid(cpu, 123L); + LockCheck.replacePid(cpu, 0, 123L); Assert.assertEquals(123L, LockCheck.getProcessForCpu(cpu)); } @Test public void shouldNotBlowUpIfPidFileIsEmpty() throws Exception { - LockCheck.updateCpu(cpu); + LockCheck.updateCpu(cpu, 0); final File file = lockChecker.doToFile(cpu); new RandomAccessFile(file, "rw").setLength(0); @@ -75,7 +75,7 @@ public void shouldNotBlowUpIfPidFileIsEmpty() throws Exception { @Test public void shouldNotBlowUpIfPidFileIsCorrupt() throws Exception { - LockCheck.updateCpu(cpu); + LockCheck.updateCpu(cpu, 0); final File file = lockChecker.doToFile(cpu); try (final FileWriter writer = new FileWriter(file, false)) { diff --git a/affinity/src/test/java/net/openhft/affinity/impl/VanillaCpuLayoutPairTest.java b/affinity/src/test/java/net/openhft/affinity/impl/VanillaCpuLayoutPairTest.java new file mode 100644 index 000000000..99986acd3 --- /dev/null +++ b/affinity/src/test/java/net/openhft/affinity/impl/VanillaCpuLayoutPairTest.java @@ -0,0 +1,56 @@ +/* + * Copyright 2016-2025 chronicle.software + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.openhft.affinity.impl; + +import org.junit.Test; + +import java.io.IOException; +import java.io.InputStream; + +import static org.junit.Assert.assertEquals; + +/** + * Tests for {@link VanillaCpuLayout#pair(int)} using sample cpuinfo files. + */ +public class VanillaCpuLayoutPairTest { + + @Test + public void testPairForI7() throws IOException { + try (InputStream is = getClass().getClassLoader().getResourceAsStream("i7.cpuinfo")) { + VanillaCpuLayout layout = VanillaCpuLayout.fromCpuInfo(is); + assertEquals(4, layout.pair(0)); + assertEquals(5, layout.pair(1)); + assertEquals(6, layout.pair(2)); + assertEquals(7, layout.pair(3)); + assertEquals(0, layout.pair(4)); + assertEquals(1, layout.pair(5)); + assertEquals(2, layout.pair(6)); + assertEquals(3, layout.pair(7)); + } + } + + @Test + public void testPairForI3() throws IOException { + try (InputStream is = getClass().getClassLoader().getResourceAsStream("i3.cpuinfo")) { + VanillaCpuLayout layout = VanillaCpuLayout.fromCpuInfo(is); + assertEquals(2, layout.pair(0)); + assertEquals(3, layout.pair(1)); + assertEquals(0, layout.pair(2)); + assertEquals(1, layout.pair(3)); + } + } +} From addd3eeab47396e1ed5495211239ea3b9af6d015 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Fri, 23 May 2025 12:41:22 +0100 Subject: [PATCH 303/353] Improve logging in FileLockBasedLockChecker to include additional CPU identifier on lock failure --- .../openhft/affinity/lockchecker/FileLockBasedLockChecker.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java b/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java index 265d8923f..8b06f7e39 100644 --- a/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java +++ b/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java @@ -123,7 +123,7 @@ public synchronized boolean obtainLock(int id, int id2, String metaInfo) throws attempt++; } } - LOGGER.warn("Exceeded maximum retries for locking CPU {}, failing acquire", id); + LOGGER.warn("Exceeded maximum retries for locking CPU {}, {}, failing acquire", id, id2); return false; } From 872cbffa41d94f5bb15c47b82c041e08ee66d18e Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Fri, 23 May 2025 12:44:31 +0100 Subject: [PATCH 304/353] Deprecate obtainLock method with single id parameter in LockChecker --- .../openhft/affinity/lockchecker/LockChecker.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/affinity/src/main/java/net/openhft/affinity/lockchecker/LockChecker.java b/affinity/src/main/java/net/openhft/affinity/lockchecker/LockChecker.java index 62a6c2f52..79a783e95 100644 --- a/affinity/src/main/java/net/openhft/affinity/lockchecker/LockChecker.java +++ b/affinity/src/main/java/net/openhft/affinity/lockchecker/LockChecker.java @@ -26,6 +26,18 @@ public interface LockChecker { boolean isLockFree(int id); + /** + * Obtain a lock for the given id. + */ + @Deprecated(/* to be removed in x.29 */) + default boolean obtainLock(int id, String metaInfo) throws IOException { + return obtainLock(id, 0, metaInfo); + } + + /** + * Obtain a lock for the given id and id2. The id2 is used to distinguish between + * multiple locks for the same core + */ boolean obtainLock(int id, int id2, String metaInfo) throws IOException; boolean releaseLock(int id); From dee81ed5fd420ca6173ea1b62f1cd14707f0e30a Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Tue, 3 Jun 2025 10:38:57 +0100 Subject: [PATCH 305/353] Shorter LICENSE.adoc --- LICENSE | 201 --------------------------------------------------- LICENSE.adoc | 9 +++ 2 files changed, 9 insertions(+), 201 deletions(-) delete mode 100644 LICENSE create mode 100644 LICENSE.adoc diff --git a/LICENSE b/LICENSE deleted file mode 100644 index f7f8b7f7d..000000000 --- a/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright 2014-2025 chronicle.software - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/LICENSE.adoc b/LICENSE.adoc new file mode 100644 index 000000000..f45056642 --- /dev/null +++ b/LICENSE.adoc @@ -0,0 +1,9 @@ +== Copyright 2016-2025 chronicle.software + +Licensed under the *Apache License, Version 2.0* (the "License"); you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. From 996d83cee9dacc4edb9f0b2dfedbe8a0b607a24d Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Tue, 3 Jun 2025 10:49:25 +0100 Subject: [PATCH 306/353] Refactor AffinityLock methods to improve CPU ID validation and logging --- .../java/net/openhft/affinity/AffinityLock.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java index 2fcdb4d95..b5c1f06b2 100644 --- a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java +++ b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java @@ -186,10 +186,14 @@ public static AffinityLock acquireLock(boolean bind) { * @return A handle for an affinity lock. */ public static AffinityLock acquireLock(int cpuId) { + checkCpuId(cpuId); + return acquireLock(true, cpuId, AffinityStrategies.ANY); + } + + private static void checkCpuId(int cpuId) { if (cpuId < 0 || cpuId >= PROCESSORS) { - throw new IllegalArgumentException("cpuId must be between 0 and " + (PROCESSORS - 1) + ": " + cpuId); + LOGGER.warn("cpuId must be between 0 and {}: {}", PROCESSORS - 1, cpuId); } - return acquireLock(true, cpuId, AffinityStrategies.ANY); } /** @@ -203,9 +207,7 @@ public static AffinityLock acquireLock(int cpuId) { */ public static AffinityLock acquireLock(int[] cpus) { for (int cpu : cpus) { - if (cpu < 0 || cpu >= PROCESSORS) { - throw new IllegalArgumentException("cpuId must be between 0 and " + (PROCESSORS - 1) + ": " + cpu); - } + checkCpuId(cpu); AffinityLock lock = tryAcquireLock(true, cpu); if (lock != null) { LOGGER.info("Acquired lock on CPU {}", cpu); @@ -265,7 +267,7 @@ public static AffinityLock acquireLock(String desc) { } else if (desc.startsWith("csv:")) { String content = desc.substring(4); - int[] cpus = Arrays.asList(content.split(",")).stream() + int[] cpus = Arrays.stream(content.split(",")) .map(String::trim) .mapToInt(Integer::parseInt).toArray(); From 2d931c38d84178a74903f2ce5d19cd091f39b5d7 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Tue, 3 Jun 2025 10:49:25 +0100 Subject: [PATCH 307/353] Refactor AffinityLock methods to improve CPU ID validation and logging --- .../java/net/openhft/affinity/AffinityLock.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java index 2fcdb4d95..b5c1f06b2 100644 --- a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java +++ b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java @@ -186,10 +186,14 @@ public static AffinityLock acquireLock(boolean bind) { * @return A handle for an affinity lock. */ public static AffinityLock acquireLock(int cpuId) { + checkCpuId(cpuId); + return acquireLock(true, cpuId, AffinityStrategies.ANY); + } + + private static void checkCpuId(int cpuId) { if (cpuId < 0 || cpuId >= PROCESSORS) { - throw new IllegalArgumentException("cpuId must be between 0 and " + (PROCESSORS - 1) + ": " + cpuId); + LOGGER.warn("cpuId must be between 0 and {}: {}", PROCESSORS - 1, cpuId); } - return acquireLock(true, cpuId, AffinityStrategies.ANY); } /** @@ -203,9 +207,7 @@ public static AffinityLock acquireLock(int cpuId) { */ public static AffinityLock acquireLock(int[] cpus) { for (int cpu : cpus) { - if (cpu < 0 || cpu >= PROCESSORS) { - throw new IllegalArgumentException("cpuId must be between 0 and " + (PROCESSORS - 1) + ": " + cpu); - } + checkCpuId(cpu); AffinityLock lock = tryAcquireLock(true, cpu); if (lock != null) { LOGGER.info("Acquired lock on CPU {}", cpu); @@ -265,7 +267,7 @@ public static AffinityLock acquireLock(String desc) { } else if (desc.startsWith("csv:")) { String content = desc.substring(4); - int[] cpus = Arrays.asList(content.split(",")).stream() + int[] cpus = Arrays.stream(content.split(",")) .map(String::trim) .mapToInt(Integer::parseInt).toArray(); From fa423ea52ad447c843fbf4756a996353e0f67fda Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Tue, 3 Jun 2025 10:57:12 +0100 Subject: [PATCH 308/353] Refactor CPU ID validation in AffinityLock and enhance test cases for invalid inputs --- .../net/openhft/affinity/AffinityLock.java | 9 ++++++--- .../net/openhft/affinity/AffinityLockTest.java | 18 +++++++++++------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java index b5c1f06b2..7c5701997 100644 --- a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java +++ b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java @@ -186,14 +186,17 @@ public static AffinityLock acquireLock(boolean bind) { * @return A handle for an affinity lock. */ public static AffinityLock acquireLock(int cpuId) { - checkCpuId(cpuId); + if (isInvalidCpuId(cpuId)) + return LOCK_INVENTORY.noLock(); return acquireLock(true, cpuId, AffinityStrategies.ANY); } - private static void checkCpuId(int cpuId) { + private static boolean isInvalidCpuId(int cpuId) { if (cpuId < 0 || cpuId >= PROCESSORS) { LOGGER.warn("cpuId must be between 0 and {}: {}", PROCESSORS - 1, cpuId); + return true; } + return false; } /** @@ -207,7 +210,7 @@ private static void checkCpuId(int cpuId) { */ public static AffinityLock acquireLock(int[] cpus) { for (int cpu : cpus) { - checkCpuId(cpu); + if (isInvalidCpuId(cpu)) continue; AffinityLock lock = tryAcquireLock(true, cpu); if (lock != null) { LOGGER.info("Acquired lock on CPU {}", cpu); diff --git a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java index 75397348d..bc059c6a8 100644 --- a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java +++ b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java @@ -310,19 +310,22 @@ public void acquireLockWithoutBindingDoesNotChangeAffinity() { assertEquals(before, Affinity.getAffinity()); } - @Test(expected = IllegalArgumentException.class) + @Test public void testTooHighCpuId() { - AffinityLock.acquireLock(123456); - } + AffinityLock lock = AffinityLock.acquireLock(123456); + assertFalse(lock.isBound()); + } - @Test(expected = IllegalArgumentException.class) + @Test public void testNegativeCpuId() { - AffinityLock.acquireLock(-1); + AffinityLock lock = AffinityLock.acquireLock(-1); + assertFalse(lock.isBound()); } - @Test(expected = IllegalArgumentException.class) + @Test public void testTooHighCpuId2() { - AffinityLock.acquireLock(new int[]{123456}); + AffinityLock lock = AffinityLock.acquireLock(new int[]{-1, 123456}); + assertFalse(lock.isBound()); } @Test(expected = IllegalStateException.class) @@ -341,6 +344,7 @@ public void bindingTwoThreadsToSameCpuThrows() throws InterruptedException { t.start(); while (!lock.isBound()) { + //noinspection BusyWait Thread.sleep(10); } From c22684498406c657c52a3479c78f85dd78538706 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Tue, 3 Jun 2025 10:49:25 +0100 Subject: [PATCH 309/353] Refactor AffinityLock methods to improve CPU ID validation and logging --- .../java/net/openhft/affinity/AffinityLock.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java index 79d576ac9..dee1eedad 100644 --- a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java +++ b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java @@ -188,10 +188,14 @@ public static AffinityLock acquireLock(boolean bind) { * @return A handle for an affinity lock, or no lock if no available CPU in the array */ public static AffinityLock acquireLock(int cpuId) { + checkCpuId(cpuId); + return acquireLock(true, cpuId, AffinityStrategies.ANY); + } + + private static void checkCpuId(int cpuId) { if (cpuId < 0 || cpuId >= PROCESSORS) { - return LOCK_INVENTORY.noLock(); + LOGGER.warn("cpuId must be between 0 and {}: {}", PROCESSORS - 1, cpuId); } - return acquireLock(true, cpuId, AffinityStrategies.ANY); } /** @@ -205,10 +209,7 @@ public static AffinityLock acquireLock(int cpuId) { */ public static AffinityLock acquireLock(int[] cpus) { for (int cpu : cpus) { - if (cpu < 0 || cpu >= PROCESSORS) { - LOGGER.warn("cpuId {} is out of range", cpu); - continue; - } + checkCpuId(cpu); AffinityLock lock = tryAcquireLock(true, cpu); if (lock != null) { LOGGER.info("Acquired lock on CPU {}", cpu); From df7941ec59ace9cb3761ec0b657f35f01b4c4f75 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Tue, 3 Jun 2025 10:57:12 +0100 Subject: [PATCH 310/353] Refactor CPU ID validation in AffinityLock and enhance test cases for invalid inputs --- .../net/openhft/affinity/AffinityLock.java | 9 ++++++--- .../net/openhft/affinity/AffinityLockTest.java | 18 +++++++++++------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java index dee1eedad..625578b9a 100644 --- a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java +++ b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java @@ -188,14 +188,17 @@ public static AffinityLock acquireLock(boolean bind) { * @return A handle for an affinity lock, or no lock if no available CPU in the array */ public static AffinityLock acquireLock(int cpuId) { - checkCpuId(cpuId); + if (isInvalidCpuId(cpuId)) + return LOCK_INVENTORY.noLock(); return acquireLock(true, cpuId, AffinityStrategies.ANY); } - private static void checkCpuId(int cpuId) { + private static boolean isInvalidCpuId(int cpuId) { if (cpuId < 0 || cpuId >= PROCESSORS) { LOGGER.warn("cpuId must be between 0 and {}: {}", PROCESSORS - 1, cpuId); + return true; } + return false; } /** @@ -209,7 +212,7 @@ private static void checkCpuId(int cpuId) { */ public static AffinityLock acquireLock(int[] cpus) { for (int cpu : cpus) { - checkCpuId(cpu); + if (isInvalidCpuId(cpu)) continue; AffinityLock lock = tryAcquireLock(true, cpu); if (lock != null) { LOGGER.info("Acquired lock on CPU {}", cpu); diff --git a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java index 18e4e666d..76416c74d 100644 --- a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java +++ b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java @@ -332,19 +332,22 @@ public void acquireLockWithoutBindingDoesNotChangeAffinity() { assertEquals(before, Affinity.getAffinity()); } - @Test(expected = IllegalArgumentException.class) + @Test public void testTooHighCpuId() { - AffinityLock.acquireLock(123456); - } + AffinityLock lock = AffinityLock.acquireLock(123456); + assertFalse(lock.isBound()); + } - @Test(expected = IllegalArgumentException.class) + @Test public void testNegativeCpuId() { - AffinityLock.acquireLock(-1); + AffinityLock lock = AffinityLock.acquireLock(-1); + assertFalse(lock.isBound()); } - @Test(expected = IllegalArgumentException.class) + @Test public void testTooHighCpuId2() { - AffinityLock.acquireLock(new int[]{123456}); + AffinityLock lock = AffinityLock.acquireLock(new int[]{-1, 123456}); + assertFalse(lock.isBound()); } @Test(expected = IllegalStateException.class) @@ -363,6 +366,7 @@ public void bindingTwoThreadsToSameCpuThrows() throws InterruptedException { t.start(); while (!lock.isBound()) { + //noinspection BusyWait Thread.sleep(10); } From d16bf605a9d740f2142ef66a6197a272aff819ef Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Tue, 3 Jun 2025 10:49:25 +0100 Subject: [PATCH 311/353] Refactor AffinityLock methods to improve CPU ID validation and logging --- .../src/main/java/net/openhft/affinity/AffinityLock.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java index 625578b9a..b73a03f6d 100644 --- a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java +++ b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java @@ -201,6 +201,12 @@ private static boolean isInvalidCpuId(int cpuId) { return false; } + private static void checkCpuId(int cpuId) { + if (cpuId < 0 || cpuId >= PROCESSORS) { + LOGGER.warn("cpuId must be between 0 and {}: {}", PROCESSORS - 1, cpuId); + } + } + /** * Assign a cpu which can be bound to the current thread or another thread * Caller passes in an explicit set of preferred CPUs From 53f1286813efb4bcbd4d94ff9e46c6789dbbf145 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Fri, 23 May 2025 12:25:12 +0100 Subject: [PATCH 312/353] Add tests for AffinityLock behavior and exception handling --- .../java/net/openhft/affinity/AffinityLockTest.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java index 76416c74d..b1c560da7 100644 --- a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java +++ b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java @@ -333,6 +333,16 @@ public void acquireLockWithoutBindingDoesNotChangeAffinity() { } @Test + public void acquireLockWithoutBindingDoesNotChangeAffinity() { + BitSet before = (BitSet) Affinity.getAffinity().clone(); + try (AffinityLock lock = AffinityLock.acquireLock(false)) { + assertFalse(lock.isBound()); + assertEquals(before, Affinity.getAffinity()); + } + assertEquals(before, Affinity.getAffinity()); + } + + @Test(expected = IllegalArgumentException.class) public void testTooHighCpuId() { AffinityLock lock = AffinityLock.acquireLock(123456); assertFalse(lock.isBound()); @@ -344,7 +354,7 @@ public void testNegativeCpuId() { assertFalse(lock.isBound()); } - @Test + @Test(expected = IllegalArgumentException.class) public void testTooHighCpuId2() { AffinityLock lock = AffinityLock.acquireLock(new int[]{-1, 123456}); assertFalse(lock.isBound()); From 08f97564d4ce541d81a295d6fbdddeb74287d839 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Fri, 23 May 2025 12:33:41 +0100 Subject: [PATCH 313/353] Fixes for java 9+ support --- affinity/pom.xml | 4 ++ .../net/openhft/affinity/BootClassPath.java | 49 ++++++++++++++++--- .../java/net/openhft/affinity/LockCheck.java | 8 +-- .../openhft/affinity/impl/NullAffinity.java | 4 +- .../openhft/affinity/impl/OSXJNAAffinity.java | 4 +- .../affinity/impl/SolarisJNAAffinity.java | 4 +- .../net/openhft/affinity/impl/Utilities.java | 26 ++++++++++ .../affinity/impl/WindowsJNAAffinity.java | 5 +- .../openhft/affinity/AffinityLockTest.java | 20 ++------ .../openhft/affinity/BootClassPathTest.java | 2 - .../affinity/FileLockLockCheckTest.java | 33 +++++++++++++ .../net/openhft/affinity/LockCheckTest.java | 5 ++ 12 files changed, 126 insertions(+), 38 deletions(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index f634d4435..53a072427 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -110,6 +110,10 @@ make-c + + linux + !arm + !dontMake diff --git a/affinity/src/main/java/net/openhft/affinity/BootClassPath.java b/affinity/src/main/java/net/openhft/affinity/BootClassPath.java index 5ae3ca125..b13d16684 100644 --- a/affinity/src/main/java/net/openhft/affinity/BootClassPath.java +++ b/affinity/src/main/java/net/openhft/affinity/BootClassPath.java @@ -21,7 +21,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.File; import java.io.IOException; +import java.net.URI; import java.nio.file.*; import java.nio.file.attribute.BasicFileAttributes; import java.util.Collections; @@ -39,21 +41,56 @@ enum BootClassPath { private static Set getResourcesOnBootClasspath() { final Logger logger = LoggerFactory.getLogger(BootClassPath.class); final Set resources = new HashSet<>(); + final String bootClassPath = System.getProperty("sun.boot.class.path", ""); - logger.trace("Boot class-path is: {}", bootClassPath); + if (!bootClassPath.isEmpty()) { + logger.trace("Boot class-path is: {}", bootClassPath); - final String pathSeparator = System.getProperty("path.separator"); - logger.trace("Path separator is: '{}'", pathSeparator); + final String pathSeparator = File.pathSeparator; + logger.trace("Path separator is: '{}'", pathSeparator); - final String[] pathElements = bootClassPath.split(pathSeparator); + final String[] pathElements = bootClassPath.split(pathSeparator); - for (final String pathElement : pathElements) { - resources.addAll(findResources(Paths.get(pathElement), logger)); + for (final String pathElement : pathElements) { + resources.addAll(findResources(Paths.get(pathElement), logger)); + } + } else { + resources.addAll(findResourcesInJrt(logger)); } return resources; } + private static Set findResourcesInJrt(final Logger logger) { + final Set jrtResources = new HashSet<>(); + try { + FileSystem fs; + try { + fs = FileSystems.getFileSystem(URI.create("jrt:/")); + } catch (FileSystemNotFoundException | ProviderNotFoundException e) { + fs = FileSystems.newFileSystem(URI.create("jrt:/"), Collections.emptyMap()); + } + final Path modules = fs.getPath("/modules"); + Files.walkFileTree(modules, new SimpleFileVisitor() { + @Override + public @NotNull FileVisitResult visitFile(final @NotNull Path file, + final @NotNull BasicFileAttributes attrs) throws IOException { + if (file.getFileName().toString().endsWith(".class")) { + Path relative = modules.relativize(file); + if (relative.getNameCount() > 1) { + Path classPath = relative.subpath(1, relative.getNameCount()); + jrtResources.add(classPath.toString()); + } + } + return FileVisitResult.CONTINUE; + } + }); + } catch (IOException e) { + logger.warn("Error walking jrt filesystem", e); + } + return jrtResources; + } + private static Set findResources(final Path path, final Logger logger) { if (!Files.exists(path)) { return Collections.emptySet(); diff --git a/affinity/src/main/java/net/openhft/affinity/LockCheck.java b/affinity/src/main/java/net/openhft/affinity/LockCheck.java index ac9ca6cc1..2953637c3 100644 --- a/affinity/src/main/java/net/openhft/affinity/LockCheck.java +++ b/affinity/src/main/java/net/openhft/affinity/LockCheck.java @@ -17,6 +17,7 @@ package net.openhft.affinity; +import net.openhft.affinity.impl.Utilities; import net.openhft.affinity.lockchecker.FileLockBasedLockChecker; import net.openhft.affinity.lockchecker.LockChecker; import org.slf4j.Logger; @@ -39,9 +40,7 @@ public enum LockCheck { private static final LockChecker lockChecker = FileLockBasedLockChecker.getInstance(); public static long getPID() { - String processName = - java.lang.management.ManagementFactory.getRuntimeMXBean().getName(); - return Long.parseLong(processName.split("@")[0]); + return Utilities.currentProcessId(); } static boolean canOSSupportOperation() { @@ -79,6 +78,9 @@ private synchronized static boolean isLockFree(int id) { } public static int getProcessForCpu(int core) throws IOException { + if (!canOSSupportOperation()) + return EMPTY_PID; + String meta = lockChecker.getMetaInfo(core); if (meta != null && !meta.isEmpty()) { diff --git a/affinity/src/main/java/net/openhft/affinity/impl/NullAffinity.java b/affinity/src/main/java/net/openhft/affinity/impl/NullAffinity.java index 9ee9f1844..c9ebc183c 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/NullAffinity.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/NullAffinity.java @@ -21,7 +21,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.lang.management.ManagementFactory; import java.util.BitSet; /** @@ -48,8 +47,7 @@ public int getCpu() { @Override public int getProcessId() { - final String name = ManagementFactory.getRuntimeMXBean().getName(); - return Integer.parseInt(name.split("@")[0]); + return Utilities.currentProcessId(); } @Override diff --git a/affinity/src/main/java/net/openhft/affinity/impl/OSXJNAAffinity.java b/affinity/src/main/java/net/openhft/affinity/impl/OSXJNAAffinity.java index 9a944ecc6..39db80875 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/OSXJNAAffinity.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/OSXJNAAffinity.java @@ -24,7 +24,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.lang.management.ManagementFactory; import java.util.BitSet; /** @@ -55,8 +54,7 @@ public int getCpu() { @Override public int getProcessId() { - final String name = ManagementFactory.getRuntimeMXBean().getName(); - return Integer.parseInt(name.split("@")[0]); + return Utilities.currentProcessId(); } @Override diff --git a/affinity/src/main/java/net/openhft/affinity/impl/SolarisJNAAffinity.java b/affinity/src/main/java/net/openhft/affinity/impl/SolarisJNAAffinity.java index 4b58eca56..ebe49b154 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/SolarisJNAAffinity.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/SolarisJNAAffinity.java @@ -24,7 +24,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.lang.management.ManagementFactory; import java.util.BitSet; /** @@ -55,8 +54,7 @@ public int getCpu() { @Override public int getProcessId() { - final String name = ManagementFactory.getRuntimeMXBean().getName(); - return Integer.parseInt(name.split("@")[0]); + return Utilities.currentProcessId(); } @Override diff --git a/affinity/src/main/java/net/openhft/affinity/impl/Utilities.java b/affinity/src/main/java/net/openhft/affinity/impl/Utilities.java index 676f1567f..4d3bfd13b 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/Utilities.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/Utilities.java @@ -79,4 +79,30 @@ private static boolean is64Bit0() { systemProp = System.getProperty("java.vm.version"); return systemProp != null && systemProp.contains("_64"); } + + /** + * Returns the current process id. Uses {@code ProcessHandle} when running + * on Java 9 or later and falls back to parsing + * {@code RuntimeMXBean#getName()} on earlier versions. + * + * @return the process id or {@code -1} if it cannot be determined + */ + public static int currentProcessId() { + try { + // Java 9+ provides ProcessHandle which has a pid() method. + Class phClass = Class.forName("java.lang.ProcessHandle"); + Object current = phClass.getMethod("current").invoke(null); + long pid = (Long) phClass.getMethod("pid").invoke(current); + return (int) pid; + } catch (Throwable ignored) { + // ignore and fallback to the pre-Java 9 approach + } + + try { + String name = java.lang.management.ManagementFactory.getRuntimeMXBean().getName(); + return Integer.parseInt(name.split("@")[0]); + } catch (Throwable e) { + return -1; + } + } } diff --git a/affinity/src/main/java/net/openhft/affinity/impl/WindowsJNAAffinity.java b/affinity/src/main/java/net/openhft/affinity/impl/WindowsJNAAffinity.java index 27b3af156..c64bd15be 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/WindowsJNAAffinity.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/WindowsJNAAffinity.java @@ -89,8 +89,9 @@ public void setAffinity(final BitSet affinity) { throw new IllegalStateException("SetThreadAffinityMask((" + pid + ") , &(" + affinity + ") ) errorNo=" + e.getErrorCode(), e); } BitSet affinity2 = getAffinity0(); - if (!affinity2.equals(affinity)) { - LoggerFactory.getLogger(WindowsJNAAffinity.class).warn("Tried to set affinity to " + affinity + " but was " + affinity2 + " you may have insufficient access rights"); + assert affinity2 != null; + if (!affinity2.intersects(affinity)) { + LoggerFactory.getLogger(WindowsJNAAffinity.class).warn("Tried to set affinity to {} but was {} you may have insufficient access rights", affinity, affinity2); } currentAffinity.set((BitSet) affinity.clone()); } diff --git a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java index b1c560da7..8bafde68a 100644 --- a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java +++ b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java @@ -333,30 +333,18 @@ public void acquireLockWithoutBindingDoesNotChangeAffinity() { } @Test - public void acquireLockWithoutBindingDoesNotChangeAffinity() { - BitSet before = (BitSet) Affinity.getAffinity().clone(); - try (AffinityLock lock = AffinityLock.acquireLock(false)) { - assertFalse(lock.isBound()); - assertEquals(before, Affinity.getAffinity()); - } - assertEquals(before, Affinity.getAffinity()); - } - - @Test(expected = IllegalArgumentException.class) public void testTooHighCpuId() { - AffinityLock lock = AffinityLock.acquireLock(123456); - assertFalse(lock.isBound()); + assertFalse(AffinityLock.acquireLock(123456).isBound()); } @Test public void testNegativeCpuId() { - AffinityLock lock = AffinityLock.acquireLock(-1); - assertFalse(lock.isBound()); + assertFalse(AffinityLock.acquireLock(-1).isBound()); } - @Test(expected = IllegalArgumentException.class) + @Test public void testTooHighCpuId2() { - AffinityLock lock = AffinityLock.acquireLock(new int[]{-1, 123456}); + AffinityLock lock = AffinityLock.acquireLock(new int[]{123456}); assertFalse(lock.isBound()); } diff --git a/affinity/src/test/java/net/openhft/affinity/BootClassPathTest.java b/affinity/src/test/java/net/openhft/affinity/BootClassPathTest.java index bf0cb8268..9e1db8097 100644 --- a/affinity/src/test/java/net/openhft/affinity/BootClassPathTest.java +++ b/affinity/src/test/java/net/openhft/affinity/BootClassPathTest.java @@ -23,8 +23,6 @@ public class BootClassPathTest { @Test public void shouldDetectClassesOnClassPath() { - if (!System.getProperty("java.version").startsWith("1.8")) - return; assertTrue(BootClassPath.INSTANCE.has("java.lang.Thread")); assertTrue(BootClassPath.INSTANCE.has("java.lang.Runtime")); } diff --git a/affinity/src/test/java/net/openhft/affinity/FileLockLockCheckTest.java b/affinity/src/test/java/net/openhft/affinity/FileLockLockCheckTest.java index 1d890d5fe..6be18c5d7 100644 --- a/affinity/src/test/java/net/openhft/affinity/FileLockLockCheckTest.java +++ b/affinity/src/test/java/net/openhft/affinity/FileLockLockCheckTest.java @@ -71,4 +71,37 @@ public void shouldNotBlowUpIfPidFileIsEmpty() throws Exception { LockCheck.isCpuFree(cpu); } + + @Test + public void lockFileDeletedWhileHeld() throws Exception { + cpu++; + + Assert.assertTrue(LockCheck.isCpuFree(cpu)); + LockCheck.updateCpu(cpu, 0); + + File lockFile = lockChecker.doToFile(cpu); + Assert.assertTrue(lockFile.exists()); + + Assert.assertTrue("Could not delete lock file", lockFile.delete()); + Assert.assertFalse(lockFile.exists()); + + Assert.assertFalse("CPU should remain locked despite missing file", LockCheck.isCpuFree(cpu)); + Assert.assertEquals(LockCheck.getPID(), LockCheck.getProcessForCpu(cpu)); + + LockCheck.releaseLock(cpu); + + Assert.assertTrue("Lock should be free after release", LockCheck.isCpuFree(cpu)); + LockCheck.updateCpu(cpu, 0); + + lockFile = lockChecker.doToFile(cpu); + Assert.assertTrue("Lock file should be recreated", lockFile.exists()); + } + + @Test + public void getProcessForCpuReturnsEmptyPidWhenNoFile() throws IOException { + int freeCpu = 99; + File lockFile = lockChecker.doToFile(freeCpu); + Assert.assertFalse(lockFile.exists()); + Assert.assertEquals(Integer.MIN_VALUE, LockCheck.getProcessForCpu(freeCpu)); + } } diff --git a/affinity/src/test/java/net/openhft/affinity/LockCheckTest.java b/affinity/src/test/java/net/openhft/affinity/LockCheckTest.java index 40f5d18e5..2612886ce 100644 --- a/affinity/src/test/java/net/openhft/affinity/LockCheckTest.java +++ b/affinity/src/test/java/net/openhft/affinity/LockCheckTest.java @@ -55,6 +55,11 @@ public void testPidOnLinux() { Assert.assertTrue(LockCheck.isProcessRunning(LockCheck.getPID())); } + @Test + public void testNegativePidOnLinux() { + Assert.assertFalse(LockCheck.isProcessRunning(-1)); + } + @Test public void testReplace() throws IOException { cpu++; From 4685c33ada79c871dd4533fe44b128510cd5e15d Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Tue, 3 Jun 2025 11:12:31 +0100 Subject: [PATCH 314/353] Replace busy wait with Waiters utility for lock binding in AffinityLockTest --- .../test/java/net/openhft/affinity/AffinityLockTest.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java index 8bafde68a..b1f422871 100644 --- a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java +++ b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java @@ -19,6 +19,7 @@ import net.openhft.affinity.impl.Utilities; import net.openhft.affinity.impl.VanillaCpuLayout; +import net.openhft.chronicle.testframework.Waiters; import org.hamcrest.MatcherAssert; import org.junit.Test; import org.slf4j.Logger; @@ -363,10 +364,7 @@ public void bindingTwoThreadsToSameCpuThrows() throws InterruptedException { }); t.start(); - while (!lock.isBound()) { - //noinspection BusyWait - Thread.sleep(10); - } + Waiters.waitForCondition("Waiting for lock to be bound", lock::isBound, 1000); try { lock.bind(); From c489075a82c8682ade39289bf32841b6857a71c1 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Thu, 3 Jul 2025 16:30:59 +0100 Subject: [PATCH 315/353] Updating parent POM (automated) --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index e90b2d811..897ee4010 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.27ea0 + 1.27ea1 diff --git a/affinity/pom.xml b/affinity/pom.xml index 53a072427..f3ea41994 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.27ea0 + 1.27ea1 diff --git a/pom.xml b/pom.xml index 9d328d8d4..eaaeebf26 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.27ea0 + 1.27ea1 From c6bf7da4d07074e11b2130f8670d34f58cbf807f Mon Sep 17 00:00:00 2001 From: Kevin Powe <140356637+chroniclekevinpowe@users.noreply.github.com> Date: Tue, 8 Jul 2025 17:44:01 +1000 Subject: [PATCH 316/353] Update third party BOM version to 3.27ea2 to remove references to legacy staging repository URL. (#184) --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index f3ea41994..2b0b51701 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -42,7 +42,7 @@ net.openhft third-party-bom - 3.27ea0 + 3.27ea2 pom import From 675403433e0a0b412f51e2460982871675b2f630 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Wed, 9 Jul 2025 09:31:51 +0100 Subject: [PATCH 317/353] Add assertion to verify base affinity in BaseAffinityTest --- .../test/java/net/openhft/affinity/BaseAffinityTest.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/affinity/src/test/java/net/openhft/affinity/BaseAffinityTest.java b/affinity/src/test/java/net/openhft/affinity/BaseAffinityTest.java index 63f4f46af..d25764f0a 100644 --- a/affinity/src/test/java/net/openhft/affinity/BaseAffinityTest.java +++ b/affinity/src/test/java/net/openhft/affinity/BaseAffinityTest.java @@ -21,6 +21,8 @@ import org.junit.Rule; import org.junit.rules.TemporaryFolder; +import static org.junit.Assert.assertEquals; + public class BaseAffinityTest { @Rule @@ -41,4 +43,9 @@ public void restoreTmpDirectoryAndReleaseAllLocks() { } System.setProperty("java.io.tmpdir", originalTmpDir); } + + @After + public void baseAffinity() { + assertEquals(AffinityLock.BASE_AFFINITY, Affinity.getAffinity()); + } } From 954a4dfb9b26778b848ed40e990abca249c8bf14 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Wed, 9 Jul 2025 09:50:16 +0100 Subject: [PATCH 318/353] Add assertion to verify base affinity in BaseAffinityTest --- .../affinity/AffinityLockDumpLocksTest.java | 8 +++---- .../openhft/affinity/AffinityLockTest.java | 17 +++++++-------- .../affinity/AffinityThreadFactoryTest.java | 6 +----- .../openhft/affinity/BaseAffinityTest.java | 6 +++++- .../openhft/affinity/BootClassPathTest.java | 2 +- .../affinity/MultiProcessAffinityTest.java | 10 ++++----- .../impl/AbstractAffinityImplTest.java | 3 ++- .../impl/CpuInfoLayoutMappingTest.java | 21 ++++++++++--------- .../affinity/impl/LinuxJNAAffinityTest.java | 3 ++- .../openhft/affinity/impl/UtilitiesTest.java | 3 ++- .../impl/VanillaCpuLayoutPairTest.java | 3 ++- .../VanillaCpuLayoutPropertiesParseTest.java | 3 ++- .../affinity/impl/VanillaCpuLayoutTest.java | 3 ++- .../affinity/impl/VersionHelperTest.java | 3 ++- .../net/openhft/ticker/impl/JNIClockTest.java | 3 ++- .../enterprise/internals/JnaAffinityTest.java | 3 ++- .../internals/NativeAffinityTest.java | 3 ++- 17 files changed, 55 insertions(+), 45 deletions(-) diff --git a/affinity/src/test/java/net/openhft/affinity/AffinityLockDumpLocksTest.java b/affinity/src/test/java/net/openhft/affinity/AffinityLockDumpLocksTest.java index e981e4e12..0336ab660 100644 --- a/affinity/src/test/java/net/openhft/affinity/AffinityLockDumpLocksTest.java +++ b/affinity/src/test/java/net/openhft/affinity/AffinityLockDumpLocksTest.java @@ -14,6 +14,10 @@ public class AffinityLockDumpLocksTest extends BaseAffinityTest { + static void supressUnusedWarning(AutoCloseable c) { + // do nothing + } + @Test public void dumpLocksListsThreadsHoldingLocks() throws Exception { Assume.assumeTrue(new File("/proc/cpuinfo").exists()); @@ -51,8 +55,4 @@ public void dumpLocksListsThreadsHoldingLocks() throws Exception { t.join(); } } - - static void supressUnusedWarning(AutoCloseable c) { - // do nothing - } } diff --git a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java index b1f422871..a101f477d 100644 --- a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java +++ b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java @@ -45,6 +45,14 @@ public class AffinityLockTest extends BaseAffinityTest { private static final Logger logger = LoggerFactory.getLogger(AffinityLockTest.class); + /** + * In Java 21 the toString contents of Thread changed to include an ID. This breaks the tests here in Java 21. + * Strip out the thread ID here so that existing tests continue to pass. + */ + private static String dumpLocks(AffinityLock[] locks) { + String value = LockInventory.dumpLocks(locks); + return value.replaceAll("#[0-9]+(,)?", ""); + } @Test public void dumpLocksI7() throws IOException { @@ -373,13 +381,4 @@ public void bindingTwoThreadsToSameCpuThrows() throws InterruptedException { lock.release(); } } - - /** - * In Java 21 the toString contents of Thread changed to include an ID. This breaks the tests here in Java 21. - * Strip out the thread ID here so that existing tests continue to pass. - */ - private static String dumpLocks(AffinityLock[] locks) { - String value = LockInventory.dumpLocks(locks); - return value.replaceAll("#[0-9]+(,)?", ""); - } } diff --git a/affinity/src/test/java/net/openhft/affinity/AffinityThreadFactoryTest.java b/affinity/src/test/java/net/openhft/affinity/AffinityThreadFactoryTest.java index 7377cc7ea..7368178d7 100644 --- a/affinity/src/test/java/net/openhft/affinity/AffinityThreadFactoryTest.java +++ b/affinity/src/test/java/net/openhft/affinity/AffinityThreadFactoryTest.java @@ -5,11 +5,7 @@ import org.junit.Test; import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; +import java.util.concurrent.*; import static org.junit.Assert.*; diff --git a/affinity/src/test/java/net/openhft/affinity/BaseAffinityTest.java b/affinity/src/test/java/net/openhft/affinity/BaseAffinityTest.java index d25764f0a..85491595c 100644 --- a/affinity/src/test/java/net/openhft/affinity/BaseAffinityTest.java +++ b/affinity/src/test/java/net/openhft/affinity/BaseAffinityTest.java @@ -21,6 +21,8 @@ import org.junit.Rule; import org.junit.rules.TemporaryFolder; +import java.util.BitSet; + import static org.junit.Assert.assertEquals; public class BaseAffinityTest { @@ -46,6 +48,8 @@ public void restoreTmpDirectoryAndReleaseAllLocks() { @After public void baseAffinity() { - assertEquals(AffinityLock.BASE_AFFINITY, Affinity.getAffinity()); + BitSet affinity = Affinity.getAffinity(); + Affinity.resetToBaseAffinity(); + assertEquals(AffinityLock.BASE_AFFINITY, affinity); } } diff --git a/affinity/src/test/java/net/openhft/affinity/BootClassPathTest.java b/affinity/src/test/java/net/openhft/affinity/BootClassPathTest.java index 9e1db8097..426ad9f22 100644 --- a/affinity/src/test/java/net/openhft/affinity/BootClassPathTest.java +++ b/affinity/src/test/java/net/openhft/affinity/BootClassPathTest.java @@ -20,7 +20,7 @@ import static org.junit.Assert.assertTrue; -public class BootClassPathTest { +public class BootClassPathTest extends BaseAffinityTest { @Test public void shouldDetectClassesOnClassPath() { assertTrue(BootClassPath.INSTANCE.has("java.lang.Thread")); diff --git a/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java b/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java index 6aa948297..98eeb0a2b 100644 --- a/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java +++ b/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java @@ -155,6 +155,11 @@ static class RepeatedAffinityLocker implements Callable { private final int iterations; private final String cpuIdToLock; + public RepeatedAffinityLocker(String cpuIdToLock, int iterations) { + this.iterations = iterations; + this.cpuIdToLock = cpuIdToLock; + } + public static void main(String[] args) throws InterruptedException, ExecutionException { String cpuIdToLock = args[0]; int iterations = Integer.parseInt(args[1]); @@ -174,11 +179,6 @@ public static void main(String[] args) throws InterruptedException, ExecutionExc } } - public RepeatedAffinityLocker(String cpuIdToLock, int iterations) { - this.iterations = iterations; - this.cpuIdToLock = cpuIdToLock; - } - @Override public Void call() throws Exception { for (int i = 0; i < iterations; i++) { diff --git a/affinity/src/test/java/net/openhft/affinity/impl/AbstractAffinityImplTest.java b/affinity/src/test/java/net/openhft/affinity/impl/AbstractAffinityImplTest.java index 5757e32ba..9cf1b7119 100644 --- a/affinity/src/test/java/net/openhft/affinity/impl/AbstractAffinityImplTest.java +++ b/affinity/src/test/java/net/openhft/affinity/impl/AbstractAffinityImplTest.java @@ -17,6 +17,7 @@ package net.openhft.affinity.impl; +import net.openhft.affinity.BaseAffinityTest; import net.openhft.affinity.IAffinity; import org.junit.After; import org.junit.Test; @@ -29,7 +30,7 @@ * @author cheremin * @since 29.12.11, 20:25 */ -public abstract class AbstractAffinityImplTest { +public abstract class AbstractAffinityImplTest extends BaseAffinityTest { protected static final int CORES = Runtime.getRuntime().availableProcessors(); protected static final BitSet CORES_MASK = new BitSet(CORES); diff --git a/affinity/src/test/java/net/openhft/affinity/impl/CpuInfoLayoutMappingTest.java b/affinity/src/test/java/net/openhft/affinity/impl/CpuInfoLayoutMappingTest.java index 3cee5d4bc..f58bcfb01 100644 --- a/affinity/src/test/java/net/openhft/affinity/impl/CpuInfoLayoutMappingTest.java +++ b/affinity/src/test/java/net/openhft/affinity/impl/CpuInfoLayoutMappingTest.java @@ -16,6 +16,7 @@ package net.openhft.affinity.impl; +import net.openhft.affinity.BaseAffinityTest; import org.junit.Test; import java.io.IOException; @@ -23,21 +24,21 @@ import static org.junit.Assert.assertEquals; -public class CpuInfoLayoutMappingTest { +public class CpuInfoLayoutMappingTest extends BaseAffinityTest { @Test public void verifyI7CpuInfoMapping() throws IOException { final InputStream i7 = getClass().getClassLoader().getResourceAsStream("i7.cpuinfo"); VanillaCpuLayout vcl = VanillaCpuLayout.fromCpuInfo(i7); - assertEquals( - "0: CpuInfo{socketId=0, coreId=0, threadId=0}\n" + - "1: CpuInfo{socketId=0, coreId=1, threadId=0}\n" + - "2: CpuInfo{socketId=0, coreId=2, threadId=0}\n" + - "3: CpuInfo{socketId=0, coreId=3, threadId=0}\n" + - "4: CpuInfo{socketId=0, coreId=0, threadId=1}\n" + - "5: CpuInfo{socketId=0, coreId=1, threadId=1}\n" + - "6: CpuInfo{socketId=0, coreId=2, threadId=1}\n" + - "7: CpuInfo{socketId=0, coreId=3, threadId=1}\n", + assertEquals("" + + "0: CpuInfo{socketId=0, coreId=0, threadId=0}\n" + + "1: CpuInfo{socketId=0, coreId=1, threadId=0}\n" + + "2: CpuInfo{socketId=0, coreId=2, threadId=0}\n" + + "3: CpuInfo{socketId=0, coreId=3, threadId=0}\n" + + "4: CpuInfo{socketId=0, coreId=0, threadId=1}\n" + + "5: CpuInfo{socketId=0, coreId=1, threadId=1}\n" + + "6: CpuInfo{socketId=0, coreId=2, threadId=1}\n" + + "7: CpuInfo{socketId=0, coreId=3, threadId=1}\n", vcl.toString()); } } diff --git a/affinity/src/test/java/net/openhft/affinity/impl/LinuxJNAAffinityTest.java b/affinity/src/test/java/net/openhft/affinity/impl/LinuxJNAAffinityTest.java index 0a4e924e4..760201c04 100644 --- a/affinity/src/test/java/net/openhft/affinity/impl/LinuxJNAAffinityTest.java +++ b/affinity/src/test/java/net/openhft/affinity/impl/LinuxJNAAffinityTest.java @@ -17,6 +17,7 @@ package net.openhft.affinity.impl; +import net.openhft.affinity.BaseAffinityTest; import org.junit.Assume; import org.junit.BeforeClass; import org.junit.Test; @@ -28,7 +29,7 @@ /* * Created by Peter Lawrey on 23/03/16. */ -public class LinuxJNAAffinityTest { +public class LinuxJNAAffinityTest extends BaseAffinityTest { @BeforeClass public static void checkJniLibraryPresent() { Assume.assumeTrue(LinuxJNAAffinity.LOADED); diff --git a/affinity/src/test/java/net/openhft/affinity/impl/UtilitiesTest.java b/affinity/src/test/java/net/openhft/affinity/impl/UtilitiesTest.java index 45d05dbfd..9b282ac15 100644 --- a/affinity/src/test/java/net/openhft/affinity/impl/UtilitiesTest.java +++ b/affinity/src/test/java/net/openhft/affinity/impl/UtilitiesTest.java @@ -16,13 +16,14 @@ package net.openhft.affinity.impl; +import net.openhft.affinity.BaseAffinityTest; import org.junit.Test; import java.util.BitSet; import static org.junit.Assert.assertEquals; -public class UtilitiesTest { +public class UtilitiesTest extends BaseAffinityTest { private static String hex(BitSet set, int... bits) { set.clear(); diff --git a/affinity/src/test/java/net/openhft/affinity/impl/VanillaCpuLayoutPairTest.java b/affinity/src/test/java/net/openhft/affinity/impl/VanillaCpuLayoutPairTest.java index 99986acd3..a09e6cd07 100644 --- a/affinity/src/test/java/net/openhft/affinity/impl/VanillaCpuLayoutPairTest.java +++ b/affinity/src/test/java/net/openhft/affinity/impl/VanillaCpuLayoutPairTest.java @@ -16,6 +16,7 @@ package net.openhft.affinity.impl; +import net.openhft.affinity.BaseAffinityTest; import org.junit.Test; import java.io.IOException; @@ -26,7 +27,7 @@ /** * Tests for {@link VanillaCpuLayout#pair(int)} using sample cpuinfo files. */ -public class VanillaCpuLayoutPairTest { +public class VanillaCpuLayoutPairTest extends BaseAffinityTest { @Test public void testPairForI7() throws IOException { diff --git a/affinity/src/test/java/net/openhft/affinity/impl/VanillaCpuLayoutPropertiesParseTest.java b/affinity/src/test/java/net/openhft/affinity/impl/VanillaCpuLayoutPropertiesParseTest.java index b539ccf98..32c6ae11b 100644 --- a/affinity/src/test/java/net/openhft/affinity/impl/VanillaCpuLayoutPropertiesParseTest.java +++ b/affinity/src/test/java/net/openhft/affinity/impl/VanillaCpuLayoutPropertiesParseTest.java @@ -1,12 +1,13 @@ package net.openhft.affinity.impl; +import net.openhft.affinity.BaseAffinityTest; import org.junit.Test; import java.io.InputStream; import static org.junit.Assert.assertEquals; -public class VanillaCpuLayoutPropertiesParseTest { +public class VanillaCpuLayoutPropertiesParseTest extends BaseAffinityTest { @Test public void testCountsI7() throws Exception { diff --git a/affinity/src/test/java/net/openhft/affinity/impl/VanillaCpuLayoutTest.java b/affinity/src/test/java/net/openhft/affinity/impl/VanillaCpuLayoutTest.java index 73ceb7fee..b712dab54 100644 --- a/affinity/src/test/java/net/openhft/affinity/impl/VanillaCpuLayoutTest.java +++ b/affinity/src/test/java/net/openhft/affinity/impl/VanillaCpuLayoutTest.java @@ -17,6 +17,7 @@ package net.openhft.affinity.impl; +import net.openhft.affinity.BaseAffinityTest; import org.junit.Test; import java.io.IOException; @@ -27,7 +28,7 @@ /** * @author peter.lawrey */ -public class VanillaCpuLayoutTest { +public class VanillaCpuLayoutTest extends BaseAffinityTest { @Test public void testFromCpuInfoI7() throws IOException { diff --git a/affinity/src/test/java/net/openhft/affinity/impl/VersionHelperTest.java b/affinity/src/test/java/net/openhft/affinity/impl/VersionHelperTest.java index 9521d5cb2..ba6a08b84 100644 --- a/affinity/src/test/java/net/openhft/affinity/impl/VersionHelperTest.java +++ b/affinity/src/test/java/net/openhft/affinity/impl/VersionHelperTest.java @@ -17,10 +17,11 @@ package net.openhft.affinity.impl; +import net.openhft.affinity.BaseAffinityTest; import org.junit.Assert; import org.junit.Test; -public class VersionHelperTest { +public class VersionHelperTest extends BaseAffinityTest { @Test public void isSameOrNewerTest() { diff --git a/affinity/src/test/java/net/openhft/ticker/impl/JNIClockTest.java b/affinity/src/test/java/net/openhft/ticker/impl/JNIClockTest.java index 56335a56c..84d39c833 100644 --- a/affinity/src/test/java/net/openhft/ticker/impl/JNIClockTest.java +++ b/affinity/src/test/java/net/openhft/ticker/impl/JNIClockTest.java @@ -18,6 +18,7 @@ package net.openhft.ticker.impl; import net.openhft.affinity.Affinity; +import net.openhft.affinity.BaseAffinityTest; import org.junit.Ignore; import org.junit.Test; @@ -26,7 +27,7 @@ /* * Created by Peter Lawrey on 13/07/15. */ -public class JNIClockTest { +public class JNIClockTest extends BaseAffinityTest { @Test @Ignore("TODO Fix") diff --git a/affinity/src/test/java/software/chronicle/enterprise/internals/JnaAffinityTest.java b/affinity/src/test/java/software/chronicle/enterprise/internals/JnaAffinityTest.java index 85f0d7372..5f49c8503 100644 --- a/affinity/src/test/java/software/chronicle/enterprise/internals/JnaAffinityTest.java +++ b/affinity/src/test/java/software/chronicle/enterprise/internals/JnaAffinityTest.java @@ -17,6 +17,7 @@ package software.chronicle.enterprise.internals; +import net.openhft.affinity.BaseAffinityTest; import net.openhft.affinity.IAffinity; import net.openhft.affinity.impl.LinuxJNAAffinity; import net.openhft.affinity.impl.Utilities; @@ -32,7 +33,7 @@ /** * @author peter.lawrey */ -public class JnaAffinityTest { +public class JnaAffinityTest extends BaseAffinityTest { protected static final int CORES = Runtime.getRuntime().availableProcessors(); protected static final BitSet CORES_MASK = new BitSet(CORES); diff --git a/affinity/src/test/java/software/chronicle/enterprise/internals/NativeAffinityTest.java b/affinity/src/test/java/software/chronicle/enterprise/internals/NativeAffinityTest.java index 6534082b6..7f7afecd3 100644 --- a/affinity/src/test/java/software/chronicle/enterprise/internals/NativeAffinityTest.java +++ b/affinity/src/test/java/software/chronicle/enterprise/internals/NativeAffinityTest.java @@ -17,6 +17,7 @@ package software.chronicle.enterprise.internals; +import net.openhft.affinity.BaseAffinityTest; import net.openhft.affinity.IAffinity; import net.openhft.affinity.impl.LinuxJNAAffinity; import net.openhft.affinity.impl.Utilities; @@ -30,7 +31,7 @@ /** * @author peter.lawrey */ -public class NativeAffinityTest { +public class NativeAffinityTest extends BaseAffinityTest { protected static final int CORES = Runtime.getRuntime().availableProcessors(); protected static final BitSet CORES_MASK = new BitSet(CORES); From af6d763c3f280c7e68bfff2575e712ae9251c000 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Wed, 9 Jul 2025 10:52:25 +0100 Subject: [PATCH 319/353] Suspend a flaky tests for functionality which isn't used AFAIK --- .../java/net/openhft/affinity/impl/PosixJNAAffinityTest.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/affinity/src/test/java/net/openhft/affinity/impl/PosixJNAAffinityTest.java b/affinity/src/test/java/net/openhft/affinity/impl/PosixJNAAffinityTest.java index e04c06610..82a20f2e3 100644 --- a/affinity/src/test/java/net/openhft/affinity/impl/PosixJNAAffinityTest.java +++ b/affinity/src/test/java/net/openhft/affinity/impl/PosixJNAAffinityTest.java @@ -24,6 +24,8 @@ import org.junit.Test; import static org.junit.Assert.assertTrue; +import static org.junit.Assume.assumeFalse; +import static org.junit.Assume.assumeTrue; /** * @author peter.lawrey @@ -31,7 +33,8 @@ public class PosixJNAAffinityTest extends AbstractAffinityImplTest { @BeforeClass public static void checkJniLibraryPresent() { - Assume.assumeTrue("linux".equalsIgnoreCase(System.getProperty("os.name"))); + assumeTrue("TODO FIX JNA library is not used, but the test is flaky", false); + assumeTrue("linux".equalsIgnoreCase(System.getProperty("os.name"))); } @Override From b2392cfbe891c7ab1ac102af247c4e93a0e1c711 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Wed, 9 Jul 2025 12:28:30 +0100 Subject: [PATCH 320/353] Updating to bom version 2.27ea52 --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index 2b0b51701..db8b0381e 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.27ea-SNAPSHOT + 2.27ea52 pom import From 6dd6ecf61de5f584851223a66184d78d9304e5e1 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Wed, 9 Jul 2025 12:28:49 +0100 Subject: [PATCH 321/353] [maven-release-plugin] prepare release Java-Thread-Affinity-3.27ea1 --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 897ee4010..ff433733e 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.27ea1-SNAPSHOT + 3.27ea1 bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.27ea1 scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git diff --git a/affinity/pom.xml b/affinity/pom.xml index db8b0381e..b4f16d4c8 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.27ea1-SNAPSHOT + 3.27ea1 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -280,7 +280,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.27ea1 diff --git a/pom.xml b/pom.xml index eaaeebf26..e46d2e2b8 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.27ea1-SNAPSHOT + 3.27ea1 pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.27ea1 From f429f06b9ab2bfbbdc0a25cbb1bbdc8478b409ec Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Wed, 9 Jul 2025 12:28:52 +0100 Subject: [PATCH 322/353] [maven-release-plugin] prepare for next development iteration --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index ff433733e..baa74ad86 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.27ea1 + 3.27ea2-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.27ea1 + ea scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git diff --git a/affinity/pom.xml b/affinity/pom.xml index b4f16d4c8..e896dc5d5 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.27ea1 + 3.27ea2-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity @@ -280,7 +280,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.27ea1 + ea diff --git a/pom.xml b/pom.xml index e46d2e2b8..e08693cd9 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.27ea1 + 3.27ea2-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.27ea1 + ea From 27df98d7440f95dd1de23eddb0ad066890d3df17 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Wed, 9 Jul 2025 12:29:08 +0100 Subject: [PATCH 323/353] Reverting back to bom version 2.27ea-SNAPSHOT --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index e896dc5d5..b1c9e4561 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.27ea52 + 2.27ea-SNAPSHOT pom import From afd9574ea0f895feae4ce5b3ca3f4eaa91c302d2 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Fri, 17 Oct 2025 14:48:21 +0100 Subject: [PATCH 324/353] Documentation polish (LICENSE/README/requirements) + test import cleanup (#189) * Refactor requirements document for clarity and formatting improvements * Remove unused imports in PosixJNAAffinityTest * Format LICENSE.adoc for improved readability * Fix formatting and punctuation in README.adoc for improved readability --- LICENSE.adoc | 10 +- README.adoc | 140 +++++++++--------- affinity/src/main/adoc/requirements.adoc | 55 ++++--- .../affinity/impl/PosixJNAAffinityTest.java | 2 - 4 files changed, 111 insertions(+), 96 deletions(-) diff --git a/LICENSE.adoc b/LICENSE.adoc index f45056642..f93a31eb3 100644 --- a/LICENSE.adoc +++ b/LICENSE.adoc @@ -1,9 +1,13 @@ == Copyright 2016-2025 chronicle.software -Licensed under the *Apache License, Version 2.0* (the "License"); you may not use this file except in compliance with the License. +Licensed under the *Apache License, Version 2.0* (the "License"); +you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and limitations under the License. +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/README.adoc b/README.adoc index 91b0eeb06..61367bd58 100644 --- a/README.adoc +++ b/README.adoc @@ -5,7 +5,7 @@ image::docs/images/Thread-Affinity_line.png[width=20%] == Version [#image-maven] -[caption="", link=https://maven-badges.herokuapp.com/maven-central/net.openhft/affinity] +[caption="",link=https://maven-badges.herokuapp.com/maven-central/net.openhft/affinity] image::https://maven-badges.herokuapp.com/maven-central/net.openhft/affinity/badge.svg[] image:https://javadoc.io/badge2/net.openhft/affinity/javadoc.svg[link="https://www.javadoc.io/doc/net.openhft/affinity/latest/index.html"] @@ -14,22 +14,20 @@ Lets you bind a thread to a given core, this can improve performance (this libra OpenHFT Java Thread Affinity library -See https://github.com/OpenHFT/Java-Thread-Affinity/tree/master/affinity/src/test/java[affinity/src/test/java] +See https://github.com/OpenHFT/Java-Thread-Affinity/tree/master/affinity/src/test/java[affinity/src/test/java] for working examples of how to use this library. === Supported operating systems -The library detects the running platform in `Affinity.java` and selects an -implementation for that OS. Features differ between systems: +The library detects the running platform in `Affinity.java` and selects an implementation for that OS. +Features differ between systems: -* *Linux* - full affinity control via JNA. The implementation can get and set - thread affinity, query the current CPU, and obtain process and thread IDs. -* *Windows* - thread affinity is managed through the kernel API. Process and - thread IDs are available, while `getCpu()` returns `-1`. -* *macOS* - provides process and thread IDs but does not modify affinity and - reports the CPU id as `-1`. -* *Solaris* - mirrors the macOS implementation: only process and thread IDs are - returned with no affinity or CPU querying support. +* *Linux* - full affinity control via JNA. +The implementation can get and set thread affinity, query the current CPU, and obtain process and thread IDs. +* *Windows* - thread affinity is managed through the kernel API. +Process and thread IDs are available, while `getCpu()` returns `-1`. +* *macOS* - provides process and thread IDs but does not modify affinity and reports the CPU id as `-1`. +* *Solaris* - mirrors the macOS implementation: only process and thread IDs are returned with no affinity or CPU querying support. === Changes @@ -39,19 +37,15 @@ implementation for that OS. Features differ between systems: === Dependencies -Java-Thread-Affinity will try to use https://github.com/java-native-access/jna[JNA] -to provide access to native thread-handling functions. JNA should be installed on -your system to get the most from this library. +Java-Thread-Affinity will try to use link:https://github.com/java-native-access/jna[JNA] +to provide access to native thread-handling functions. +JNA should be installed on your system to get the most from this library. === JNA version -Java-Thread-Affinity currently depends on JNA version 4.4.0, which in turn -depends on a version of GLIBC >= 2.14. If your operating system is an old one, -with a version of GLIBC released before 2011, this library will not be able to -invoke native functions. +Java-Thread-Affinity currently depends on JNA version 4.4.0, which in turn depends on a version of GLIBC >= 2.14. If your operating system is an old one, with a version of GLIBC released before 2011, this library will not be able to invoke native functions. -To work around this problem, fork the repository, and override the `` tag -for the artifacts `jna` and `jna-platform` in the project's `pom` file. +To work around this problem, fork the repository, and override the `` tag for the artifacts `jna` and `jna-platform` in the project's `pom` file. === Installing JNA on Ubuntu @@ -68,17 +62,17 @@ for the artifacts `jna` and `jna-platform` in the project's `pom` file. Or download jna.jar and jna-platform.jar from the JNA project and add them to your classpath. === How does CPU allocation work? -The library will read your `/proc/cpuinfo` if you have one or provide one and it will determine your CPU layout. If you don't have one it will assume every CPU is on one CPU socket. +The library will read your `/proc/cpuinfo` if you have one or provide one and it will determine your CPU layout. +If you don't have one it will assume every CPU is on one CPU socket. -The library looks for isolated CPUs determined by looking at the CPUs you are not running on by default. +The library looks for isolated CPUs determined by looking at the CPUs you are not running on by default. i.e. if you have 16 CPUs but 8 of them are not available for general use (as determined by the affinity of the process on startup) it will start assigning to those CPUs. Note: if you have more than one process using this library you need to specify which CPUs the process can use otherwise it will assign the same CPUs to both processes. -To control which CPUs a process can use, add `-Daffinity.reserved={cpu-mask-in-hex}` -to the command line of the process. The mask is a hexadecimal bit mask without -the `0x` prefix where bit `0` represents CPU `0`, bit `1` represents CPU `1` and -so on. Multiple CPUs can be specified by setting more than one bit. +To control which CPUs a process can use, add `-Daffinity.reserved={cpu-mask-in-hex}` to the command line of the process. +The mask is a hexadecimal bit mask without the `0x` prefix where bit `0` represents CPU `0`, bit `1` represents CPU `1` and so on. +Multiple CPUs can be specified by setting more than one bit. For example: @@ -86,8 +80,7 @@ For example: * `-Daffinity.reserved=6` reserves CPUs `1` and `2`. * `-Daffinity.reserved=10` reserves CPUs `1` and `3` (hexadecimal `a`). -Use an appropriate mask when starting each process to avoid reserving the same -cores for multiple JVMs. +Use an appropriate mask when starting each process to avoid reserving the same cores for multiple JVMs. Note: the CPU 0 is reserved for the Operating System, it has to run somewhere. @@ -103,13 +96,14 @@ http://vanillajava.blogspot.co.uk/2013/07/micro-jitter-busy-waiting-and-binding. Java-Thread-Affinity requires that you first isolate some CPU's. -Once a CPU core is isolated, the Linux scheduler will not use the CPU core to run any user-space processes. The isolated CPUs will not participate in load balancing, and will not have tasks running on them unless explicitly assigned. +Once a CPU core is isolated, the Linux scheduler will not use the CPU core to run any user-space processes. +The isolated CPUs will not participate in load balancing, and will not have tasks running on them unless explicitly assigned. To isolate the 1st and 3rd CPU cores (CPU numbers start from 0) on your system, add the following to the kernel command line during boot: isolcpus=1,3 -Using GRUB +.Using GRUB [source] ---- sudo sed -i 's/^GRUB_CMDLINE_LINUX_DEFAULT="/GRUB_CMDLINE_LINUX_DEFAULT="isolcpus=1,3 /' /etc/default/grub @@ -117,7 +111,7 @@ sudo update-grub sudo reboot ---- -Using systemd-boot +.Using systemd-boot [source] ---- sudo sed -i 's/^options \(.*\)/options \1 isolcpus=1,3/' /boot/loader/entries/*.conf @@ -129,8 +123,8 @@ sudo reboot === Acquiring a CPU lock for a thread You can acquire a lock for a CPU in the following way: -In Java 6 -[source, java] +.In Java 6 +[source,java] ---- AffinityLock al = AffinityLock.acquireLock(); try { @@ -140,26 +134,32 @@ try { } ---- -In Java 7 or 8 -[source, java] +.In Java 7 or 8 +[source,java] ---- try (AffinityLock al = AffinityLock.acquireLock()) { // do some work while locked to a CPU. } ---- + You have further options such as === Acquiring a CORE lock for a thread -You can reserve a whole core. If you have hyper-threading enabled, this will use one CPU and leave it's twin CPU unused. -[source, java] +You can reserve a whole core. +If you have hyper-threading enabled, this will use one CPU and leave it's twin CPU unused. + +[source,java] ---- try (AffinityLock al = AffinityLock.acquireCore()) { // do some work while locked to a CPU. } ---- + === Controlling layout + You can chose a layout relative to an existing lock. -[source, java] + +[source,java] ---- try (final AffinityLock al = AffinityLock.acquireLock()) { System.out.println("Main locked"); @@ -175,6 +175,7 @@ try (final AffinityLock al = AffinityLock.acquireLock()) { t.start(); } ---- + In this example, the library will prefer a free CPU on the same Socket as the first thread, otherwise it will pick any free CPU. === Affinity strategies @@ -193,32 +194,39 @@ The `AffinityStrategies` enum defines hints for selecting a CPU relative to an e === Getting the thread id You can get the current thread id using -[source, java] ----- +[source,java] +---- int threadId = AffinitySupport.getThreadId(); ---- + === Determining which CPU you are running on You can get the current CPU being used by -[source, java] ----- +[source,java] +---- int cpuId = AffinitySupport.getCpu(); ---- + === Controlling the affinity more directly + The affinity of the process on start up is -[source, java] ----- +[source,java] +---- long baseAffinity = AffinityLock.BASE_AFFINITY; ---- + The available CPU for reservation is -[source, java] + +[source,java] ---- long reservedAffinity = AffinityLock.RESERVED_AFFINITY; ---- + If you want to get/set the affinity directly you can do -[source, java] + +[source,java] ---- long currentAffinity = AffinitySupport.getAffinity(); AffinitySupport.setAffinity(1L << 5); // lock to CPU 5. @@ -227,8 +235,8 @@ AffinitySupport.setAffinity(1L << 5); // lock to CPU 5. === Understanding dumpLocks() output Several examples print the current CPU assignments using `AffinityLock.dumpLocks()`. -Each line of the output begins with the zero based CPU id followed by the status -of that CPU. Example output might look like: +Each line of the output begins with the zero based CPU id followed by the status of that CPU. +Example output might look like: [source] ---- @@ -239,35 +247,32 @@ of that CPU. Example output might look like: ---- The number on each line is the logical CPU index as recognised by the library. -The text after the colon describes whether that CPU is free, reserved or already -bound to a thread. Use these indices when calling `AffinityLock.acquireLock(n)` +The text after the colon describes whether that CPU is free, reserved or already bound to a thread. +Use these indices when calling `AffinityLock.acquireLock(n)` or when constructing explicit affinity masks. === Lock file directory -AffinityLock stores a small lock file for each CPU. These files are placed in -the directory specified by the `java.io.tmpdir` system property, which by -default points to your system's temporary directory (usually `/tmp` on Linux). +AffinityLock stores a small lock file for each CPU. +These files are placed in the directory specified by the `java.io.tmpdir` system property, which by default points to your system's temporary directory (usually `/tmp` on Linux). -If you want to keep the lock files elsewhere, set this property before using any -affinity APIs: +If you want to keep the lock files elsewhere, set this property before using any affinity APIs: -[source, bash] +[source,bash] ---- java -Djava.io.tmpdir=/path/to/dir ... ---- or in code -[source, java] +[source,java] ---- System.setProperty("java.io.tmpdir", "/path/to/dir"); ---- === Debugging affinity state -For a detailed of view of the current affinity state (as seen by the library), -execute the following script on Linux systems: +For a detailed of view of the current affinity state (as seen by the library), execute the following script on Linux systems: [source] ---- @@ -289,11 +294,10 @@ $ for i in "$(ls cpu-*)"; == Using AffinityThreadFactory -`AffinityThreadFactory` binds each thread it creates according to a set of -`AffinityStrategy` rules. This allows executors to automatically run tasks on -cores selected by the library. +`AffinityThreadFactory` binds each thread it creates according to a set of `AffinityStrategy` rules. +This allows executors to automatically run tasks on cores selected by the library. -[source, java] +[source,java] ---- ExecutorService es = Executors.newFixedThreadPool(4, new AffinityThreadFactory("worker", @@ -315,12 +319,14 @@ For an article on how much difference affinity can make and how to use it http:/ == Questions and Answers === Question: How to lock a specific cpuId -I am currently working on a project related to deadlock detection in multithreaded programs in java. We are trying to run threads on different processors and thus came across your github posts regarding the same. https://github.com/peter-lawrey/Java-Thread-Affinity/wiki/Getting-started -Being a beginner, I have little knowledge and thus need your assistance. We need to know how to run threads on specified cpu number and then switch threads when one is waiting. +I am currently working on a project related to deadlock detection in multithreaded programs in java. +We are trying to run threads on different processors and thus came across your github posts regarding the same. https://github.com/peter-lawrey/Java-Thread-Affinity/wiki/Getting-started +Being a beginner, I have little knowledge and thus need your assistance. +We need to know how to run threads on specified cpu number and then switch threads when one is waiting. === Answer -[source, java] +[source,java] ---- // lock a cpuId try (AffinityLock lock = AffinityLock.acquireLock(n)) { diff --git a/affinity/src/main/adoc/requirements.adoc b/affinity/src/main/adoc/requirements.adoc index f15cf0ed4..8132561a5 100644 --- a/affinity/src/main/adoc/requirements.adoc +++ b/affinity/src/main/adoc/requirements.adoc @@ -1,14 +1,11 @@ = Requirements Document: Java Thread Affinity -Author: Gemini AI -Date: 23 May 2025 -Version: 1.0 -:toc: left -:toclevels: 3 -:sectnums: +:toc: == 1. Introduction -This document outlines the requirements for the *Java Thread Affinity* library. The primary purpose of this library is to provide Java applications with the capability to control Central Processing Unit (CPU) affinity for their threads. This allows developers to bind specific threads to designated CPU cores, which can lead to performance improvements, especially in latency-sensitive applications, by reducing context switching and improving cache utilisation. +This document outlines the requirements for the *Java Thread Affinity* library. +The primary purpose of this library is to provide Java applications with the capability to control Central Processing Unit (CPU) affinity for their threads. +This allows developers to bind specific threads to designated CPU cores, which can lead to performance improvements, especially in latency-sensitive applications, by reducing context switching and improving cache utilisation. The library aims to offer a cross-platform API, with the most comprehensive support for Linux systems, leveraging Java Native Access (JNA) and, where applicable, Java Native Interface (JNI) for low-level system interactions. @@ -26,23 +23,25 @@ The scope of the Java Thread Affinity project includes: == 3. Definitions, Acronyms, and Abbreviations -* *CPU*: Central Processing Unit -* *JNA*: Java Native Access -* *JNI*: Java Native Interface -* *OS*: Operating System -* *PID*: Process Identifier -* *OSGi*: Open Service Gateway initiative -* *POM*: Project Object Model (Maven) -* *API*: Application Programming Interface +CPU :: Central Processing Unit +JNA :: Java Native Access +JNI :: Java Native Interface +OS :: Operating System +PID :: Process Identifier +OSGi :: Open Service Gateway initiative +POM :: Project Object Model (Maven) +API :: Application Programming Interface == 4. References -* Project Repository: https://github.com/OpenHFT/Java-Thread-Affinity -* JNA: https://github.com/java-native-access/jna +* Project Repository: link:https://github.com/OpenHFT/Java-Thread-Affinity[] +* JNA: link:https://github.com/java-native-access/jna[] == 5. Project Overview -The *Java Thread Affinity* library enables fine-grained control over which CPU cores Java threads execute on. This is particularly beneficial for high-performance computing and low-latency applications where minimising jitter and maximising cache efficiency is critical. The library abstracts OS-specific details, providing a unified Java API. +The *Java Thread Affinity* library enables fine-grained control over which CPU cores Java threads execute on. +This is particularly beneficial for high-performance computing and low-latency applications where minimising jitter and maximising cache efficiency is critical. +The library abstracts OS-specific details, providing a unified Java API. === 5.1. Purpose @@ -127,8 +126,10 @@ The *Java Thread Affinity* library enables fine-grained control over which CPU c * *FR9.1*: The system _shall_ provide tailored implementations of `IAffinity` for different operating systems: ** *Linux*: Full affinity control, CPU ID, Process ID, Thread ID via JNA (`LinuxJNAAffinity`, `PosixJNAAffinity`) or JNI (`NativeAffinity`). ** *Windows*: Thread affinity control, Process ID, Thread ID via JNA (`WindowsJNAAffinity`). `getCpu()` returns -1. -** *macOS*: Process ID, Thread ID via JNA (`OSXJNAAffinity`). No affinity modification; `getCpu()` returns -1. -** *Solaris*: Process ID, Thread ID via JNA (`SolarisJNAAffinity`). No affinity modification; `getCpu()` returns -1. +** *macOS*: Process ID, Thread ID via JNA (`OSXJNAAffinity`). +No affinity modification; `getCpu()` returns -1. +** *Solaris*: Process ID, Thread ID via JNA (`SolarisJNAAffinity`). +No affinity modification; `getCpu()` returns -1. * *FR9.2*: A `NullAffinity` implementation _shall_ be used as a fallback if no suitable native implementation can be loaded or for unsupported OS. === 6.6. Affinity Thread Factory (net.openhft.affinity.AffinityThreadFactory) @@ -166,10 +167,14 @@ The *Java Thread Affinity* library enables fine-grained control over which CPU c ** *Partial Support*: Windows (affinity setting, PID/TID, no `getCpu()`). ** *Limited Support*: macOS, Solaris (PID/TID only, no affinity setting or `getCpu()`). * *NFR2. Dependencies*: -** *JNA*: `net.java.dev.jna:jna`, `net.java.dev.jna:jna-platform`. Version 5.x or higher is recommended for full functionality. The project currently uses version 4.4.0 (as per README, though POMs might show updates). +** *JNA*: `net.java.dev.jna:jna`, `net.java.dev.jna:jna-platform`. +Version 5.x or higher is recommended for full functionality. +The project currently uses version 4.4.0 (as per README, though POMs might show updates). ** *SLF4J API*: `org.slf4j:slf4j-api` for logging. ** *JetBrains Annotations*: `org.jetbrains:annotations` for code quality. -* *NFR3. Performance*: The library _should_ introduce minimal overhead. Native calls _should_ be efficient. The primary goal is to enable performance improvements in the client application. +* *NFR3. Performance*: The library _should_ introduce minimal overhead. +Native calls _should_ be efficient. +The primary goal is to enable performance improvements in the client application. * *NFR4. Licensing*: The project _shall_ be licensed under the Apache License, Version 2.0. * *NFR5. Build System*: The project _shall_ use Apache Maven for building and dependency management. * *NFR6. Language*: @@ -192,7 +197,8 @@ The *Java Thread Affinity* library enables fine-grained control over which CPU c === 8.1. High-Level Architecture -The Java Thread Affinity library is a Java-based system that interfaces with the underlying operating system through JNA (primarily) and JNI (for specific `libCEInternals.so` functionalities). It abstracts OS-specific system calls related to thread affinity, CPU information, and timing. +The Java Thread Affinity library is a Java-based system that interfaces with the underlying operating system through JNA (primarily) and JNI (for specific `libCEInternals.so` functionalities). +It abstracts OS-specific system calls related to thread affinity, CPU information, and timing. === 8.2. Key Components @@ -241,7 +247,8 @@ The library can utilise an optional native shared library, `libCEInternals.so`, ** `Java_net_openhft_ticker_impl_JNIClock_rdtsc0` * *Platform Specifics*: ** *Linux*: Uses `sched_getaffinity`, `sched_setaffinity`, `sched_getcpu`, `getpid`, `syscall(SYS_gettid)`. -** *macOS*: (Separate C file `software_chronicle_enterprise_internals_impl_NativeAffinity_MacOSX.c`) Uses `pthread_mach_thread_np`, `thread_policy_get`, `thread_policy_set`. Note: JNA implementations are generally preferred on macOS. +** *macOS*: (Separate C file `software_chronicle_enterprise_internals_impl_NativeAffinity_MacOSX.c`) Uses `pthread_mach_thread_np`, `thread_policy_get`, `thread_policy_set`. +Note: JNA implementations are generally preferred on macOS. * *Loading*: The `NativeAffinity.java` class attempts to load `System.loadLibrary("CEInternals")`. == 10. API Overview diff --git a/affinity/src/test/java/net/openhft/affinity/impl/PosixJNAAffinityTest.java b/affinity/src/test/java/net/openhft/affinity/impl/PosixJNAAffinityTest.java index 82a20f2e3..3c7ec1a7f 100644 --- a/affinity/src/test/java/net/openhft/affinity/impl/PosixJNAAffinityTest.java +++ b/affinity/src/test/java/net/openhft/affinity/impl/PosixJNAAffinityTest.java @@ -19,12 +19,10 @@ import net.openhft.affinity.Affinity; import net.openhft.affinity.IAffinity; -import org.junit.Assume; import org.junit.BeforeClass; import org.junit.Test; import static org.junit.Assert.assertTrue; -import static org.junit.Assume.assumeFalse; import static org.junit.Assume.assumeTrue; /** From d1e39805e62d7f616d7299a07a76a0ab8964bb33 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Tue, 11 Nov 2025 15:07:47 +0000 Subject: [PATCH 325/353] Update copyright headers to reflect 2013-2025 and SPDX-License-Identifier: Apache-2.0 --- affinity-test/pom.xml | 20 +-- .../affinity/osgi/OSGiPlaceholder.java | 16 +-- .../openhft/affinity/osgi/OSGiBundleTest.java | 16 +-- .../openhft/affinity/osgi/OSGiTestBase.java | 16 +-- affinity/pom.xml | 20 +-- .../c/net_openhft_ticker_impl_JNIClock.cpp | 17 +-- ...terprise_internals_impl_NativeAffinity.cpp | 17 +-- ...ise_internals_impl_NativeAffinity_MacOSX.c | 17 +-- .../java/net/openhft/affinity/Affinity.java | 16 +-- .../net/openhft/affinity/AffinityLock.java | 16 +-- .../openhft/affinity/AffinityStrategies.java | 16 +-- .../openhft/affinity/AffinityStrategy.java | 16 +-- .../affinity/AffinityThreadFactory.java | 16 +-- .../net/openhft/affinity/BootClassPath.java | 16 +-- .../java/net/openhft/affinity/CpuLayout.java | 16 +-- .../java/net/openhft/affinity/IAffinity.java | 16 +-- .../java/net/openhft/affinity/LockCheck.java | 16 +-- .../net/openhft/affinity/LockInventory.java | 16 +-- .../openhft/affinity/MicroJitterSampler.java | 15 +-- .../openhft/affinity/impl/LinuxHelper.java | 16 +-- .../affinity/impl/LinuxJNAAffinity.java | 16 +-- .../openhft/affinity/impl/NoCpuLayout.java | 16 +-- .../openhft/affinity/impl/NullAffinity.java | 16 +-- .../openhft/affinity/impl/OSXJNAAffinity.java | 16 +-- .../affinity/impl/PosixJNAAffinity.java | 16 +-- .../affinity/impl/SolarisJNAAffinity.java | 16 +-- .../net/openhft/affinity/impl/Utilities.java | 16 +-- .../affinity/impl/VanillaCpuLayout.java | 16 +-- .../openhft/affinity/impl/VersionHelper.java | 16 +-- .../affinity/impl/WindowsJNAAffinity.java | 16 +-- .../lockchecker/FileLockBasedLockChecker.java | 15 +-- .../affinity/lockchecker/LockChecker.java | 79 +++++------- .../affinity/lockchecker/LockReference.java | 63 ++++------ .../affinity/main/AffinityTestMain.java | 119 ++++++++---------- .../main/java/net/openhft/ticker/ITicker.java | 16 +-- .../main/java/net/openhft/ticker/Ticker.java | 16 +-- .../net/openhft/ticker/impl/JNIClock.java | 16 +-- .../net/openhft/ticker/impl/SystemClock.java | 16 +-- .../internals/impl/NativeAffinity.java | 16 +-- .../affinity/AffinityLockBindMain.java | 16 +-- .../affinity/AffinityLockDumpLocksTest.java | 3 + .../openhft/affinity/AffinityLockMain.java | 16 +-- .../affinity/AffinityLockReleaseTest.java | 15 +-- .../openhft/affinity/AffinityLockTest.java | 16 +-- .../AffinityResetToBaseAffinityTest.java | 3 + .../openhft/affinity/AffinitySupportMain.java | 16 +-- .../affinity/AffinityThreadFactoryMain.java | 16 +-- .../affinity/AffinityThreadFactoryTest.java | 3 + .../openhft/affinity/BaseAffinityTest.java | 15 +-- .../openhft/affinity/BootClassPathTest.java | 15 +-- .../affinity/FileLockLockCheckTest.java | 16 +-- .../openhft/affinity/InterrupedThread.java | 16 +-- .../net/openhft/affinity/LockCheckTest.java | 16 +-- .../affinity/MultiProcessAffinityTest.java | 15 +-- .../impl/AbstractAffinityImplTest.java | 16 +-- .../impl/CpuInfoLayoutMappingTest.java | 15 +-- .../affinity/impl/LinuxJNAAffinityTest.java | 16 +-- .../affinity/impl/NativeAffinityImpTest.java | 16 +-- .../affinity/impl/PosixJNAAffinityTest.java | 16 +-- .../openhft/affinity/impl/UtilitiesTest.java | 15 +-- .../impl/VanillaCpuLayoutPairTest.java | 15 +-- .../VanillaCpuLayoutPropertiesParseTest.java | 3 + .../affinity/impl/VanillaCpuLayoutTest.java | 16 +-- .../affinity/impl/VersionHelperTest.java | 16 +-- .../TestFileLockBasedLockChecker.java | 15 +-- .../net/openhft/ticker/impl/JNIClockTest.java | 16 +-- .../enterprise/internals/JnaAffinityTest.java | 16 +-- .../internals/NativeAffinityTest.java | 16 +-- pom.xml | 20 +-- 69 files changed, 200 insertions(+), 1070 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index baa74ad86..9b75487b5 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -1,19 +1,9 @@ + + Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 + +--> 4.0.0 @@ -21,7 +11,7 @@ net.openhft java-parent-pom - 1.27ea1 + 1.27ea2-SNAPSHOT diff --git a/affinity-test/src/main/java/net/openhft/affinity/osgi/OSGiPlaceholder.java b/affinity-test/src/main/java/net/openhft/affinity/osgi/OSGiPlaceholder.java index bd9b2d0a3..a6e7ef36d 100644 --- a/affinity-test/src/main/java/net/openhft/affinity/osgi/OSGiPlaceholder.java +++ b/affinity-test/src/main/java/net/openhft/affinity/osgi/OSGiPlaceholder.java @@ -1,20 +1,6 @@ /* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package net.openhft.affinity.osgi; /** diff --git a/affinity-test/src/test/java/net/openhft/affinity/osgi/OSGiBundleTest.java b/affinity-test/src/test/java/net/openhft/affinity/osgi/OSGiBundleTest.java index 80949898f..7896c6d7a 100644 --- a/affinity-test/src/test/java/net/openhft/affinity/osgi/OSGiBundleTest.java +++ b/affinity-test/src/test/java/net/openhft/affinity/osgi/OSGiBundleTest.java @@ -1,20 +1,6 @@ /* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package net.openhft.affinity.osgi; import org.junit.Ignore; diff --git a/affinity-test/src/test/java/net/openhft/affinity/osgi/OSGiTestBase.java b/affinity-test/src/test/java/net/openhft/affinity/osgi/OSGiTestBase.java index a1e9fcc96..347d2edf0 100644 --- a/affinity-test/src/test/java/net/openhft/affinity/osgi/OSGiTestBase.java +++ b/affinity-test/src/test/java/net/openhft/affinity/osgi/OSGiTestBase.java @@ -1,20 +1,6 @@ /* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package net.openhft.affinity.osgi; import org.ops4j.pax.exam.CoreOptions; diff --git a/affinity/pom.xml b/affinity/pom.xml index b1c9e4561..e778dd9e1 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -1,19 +1,9 @@ + + Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 + +--> 4.0.0 @@ -21,7 +11,7 @@ net.openhft java-parent-pom - 1.27ea1 + 1.27ea2-SNAPSHOT diff --git a/affinity/src/main/c/net_openhft_ticker_impl_JNIClock.cpp b/affinity/src/main/c/net_openhft_ticker_impl_JNIClock.cpp index e68c32036..2cf233d3a 100644 --- a/affinity/src/main/c/net_openhft_ticker_impl_JNIClock.cpp +++ b/affinity/src/main/c/net_openhft_ticker_impl_JNIClock.cpp @@ -1,19 +1,6 @@ -/* vim: syntax=cpp - * Copyright 2015-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/** + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif diff --git a/affinity/src/main/c/software_chronicle_enterprise_internals_impl_NativeAffinity.cpp b/affinity/src/main/c/software_chronicle_enterprise_internals_impl_NativeAffinity.cpp index 721f1e7f3..f13d566a1 100644 --- a/affinity/src/main/c/software_chronicle_enterprise_internals_impl_NativeAffinity.cpp +++ b/affinity/src/main/c/software_chronicle_enterprise_internals_impl_NativeAffinity.cpp @@ -1,19 +1,6 @@ -/* vim: syntax=cpp - * Copyright 2011-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/** + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif diff --git a/affinity/src/main/c/software_chronicle_enterprise_internals_impl_NativeAffinity_MacOSX.c b/affinity/src/main/c/software_chronicle_enterprise_internals_impl_NativeAffinity_MacOSX.c index f0f2fdc09..67dafb1ef 100644 --- a/affinity/src/main/c/software_chronicle_enterprise_internals_impl_NativeAffinity_MacOSX.c +++ b/affinity/src/main/c/software_chronicle_enterprise_internals_impl_NativeAffinity_MacOSX.c @@ -1,19 +1,6 @@ -/* - * Copyright 2011-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/** + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - #include #include #include diff --git a/affinity/src/main/java/net/openhft/affinity/Affinity.java b/affinity/src/main/java/net/openhft/affinity/Affinity.java index d4654749a..8dadd8a15 100644 --- a/affinity/src/main/java/net/openhft/affinity/Affinity.java +++ b/affinity/src/main/java/net/openhft/affinity/Affinity.java @@ -1,20 +1,6 @@ /* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package net.openhft.affinity; import com.sun.jna.Native; diff --git a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java index 625578b9a..cf0ed4ca0 100644 --- a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java +++ b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java @@ -1,20 +1,6 @@ /* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package net.openhft.affinity; import net.openhft.affinity.impl.NoCpuLayout; diff --git a/affinity/src/main/java/net/openhft/affinity/AffinityStrategies.java b/affinity/src/main/java/net/openhft/affinity/AffinityStrategies.java index b833eaa87..65ee0cbf9 100644 --- a/affinity/src/main/java/net/openhft/affinity/AffinityStrategies.java +++ b/affinity/src/main/java/net/openhft/affinity/AffinityStrategies.java @@ -1,20 +1,6 @@ /* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package net.openhft.affinity; /** diff --git a/affinity/src/main/java/net/openhft/affinity/AffinityStrategy.java b/affinity/src/main/java/net/openhft/affinity/AffinityStrategy.java index ccdc782f0..400c6d3c6 100644 --- a/affinity/src/main/java/net/openhft/affinity/AffinityStrategy.java +++ b/affinity/src/main/java/net/openhft/affinity/AffinityStrategy.java @@ -1,20 +1,6 @@ /* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package net.openhft.affinity; /** diff --git a/affinity/src/main/java/net/openhft/affinity/AffinityThreadFactory.java b/affinity/src/main/java/net/openhft/affinity/AffinityThreadFactory.java index 7f789a4e5..6e1d67e5a 100644 --- a/affinity/src/main/java/net/openhft/affinity/AffinityThreadFactory.java +++ b/affinity/src/main/java/net/openhft/affinity/AffinityThreadFactory.java @@ -1,20 +1,6 @@ /* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package net.openhft.affinity; import org.jetbrains.annotations.NotNull; diff --git a/affinity/src/main/java/net/openhft/affinity/BootClassPath.java b/affinity/src/main/java/net/openhft/affinity/BootClassPath.java index b13d16684..85efa3279 100644 --- a/affinity/src/main/java/net/openhft/affinity/BootClassPath.java +++ b/affinity/src/main/java/net/openhft/affinity/BootClassPath.java @@ -1,20 +1,6 @@ /* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package net.openhft.affinity; import org.jetbrains.annotations.NotNull; diff --git a/affinity/src/main/java/net/openhft/affinity/CpuLayout.java b/affinity/src/main/java/net/openhft/affinity/CpuLayout.java index 12cbce61e..0cbdd6412 100644 --- a/affinity/src/main/java/net/openhft/affinity/CpuLayout.java +++ b/affinity/src/main/java/net/openhft/affinity/CpuLayout.java @@ -1,20 +1,6 @@ /* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package net.openhft.affinity; /** diff --git a/affinity/src/main/java/net/openhft/affinity/IAffinity.java b/affinity/src/main/java/net/openhft/affinity/IAffinity.java index d389c5afa..c473a5400 100644 --- a/affinity/src/main/java/net/openhft/affinity/IAffinity.java +++ b/affinity/src/main/java/net/openhft/affinity/IAffinity.java @@ -1,20 +1,6 @@ /* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package net.openhft.affinity; import java.util.BitSet; diff --git a/affinity/src/main/java/net/openhft/affinity/LockCheck.java b/affinity/src/main/java/net/openhft/affinity/LockCheck.java index 2953637c3..e3c485fed 100644 --- a/affinity/src/main/java/net/openhft/affinity/LockCheck.java +++ b/affinity/src/main/java/net/openhft/affinity/LockCheck.java @@ -1,20 +1,6 @@ /* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package net.openhft.affinity; import net.openhft.affinity.impl.Utilities; diff --git a/affinity/src/main/java/net/openhft/affinity/LockInventory.java b/affinity/src/main/java/net/openhft/affinity/LockInventory.java index 0fa41b114..b54615219 100644 --- a/affinity/src/main/java/net/openhft/affinity/LockInventory.java +++ b/affinity/src/main/java/net/openhft/affinity/LockInventory.java @@ -1,20 +1,6 @@ /* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package net.openhft.affinity; import net.openhft.affinity.impl.NullAffinity; diff --git a/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java b/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java index 21a6e5b3c..30e27d221 100644 --- a/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java +++ b/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java @@ -1,19 +1,6 @@ /* - * Copyright 2014-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package net.openhft.affinity; import java.io.PrintStream; diff --git a/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java b/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java index df5cbbc3d..a52404bba 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java @@ -1,20 +1,6 @@ /* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package net.openhft.affinity.impl; import com.sun.jna.*; diff --git a/affinity/src/main/java/net/openhft/affinity/impl/LinuxJNAAffinity.java b/affinity/src/main/java/net/openhft/affinity/impl/LinuxJNAAffinity.java index 313f8c8ec..d16fc3beb 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/LinuxJNAAffinity.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/LinuxJNAAffinity.java @@ -1,20 +1,6 @@ /* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package net.openhft.affinity.impl; import com.sun.jna.NativeLong; diff --git a/affinity/src/main/java/net/openhft/affinity/impl/NoCpuLayout.java b/affinity/src/main/java/net/openhft/affinity/impl/NoCpuLayout.java index 2996bdf0d..e57b1decc 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/NoCpuLayout.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/NoCpuLayout.java @@ -1,20 +1,6 @@ /* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package net.openhft.affinity.impl; import net.openhft.affinity.CpuLayout; diff --git a/affinity/src/main/java/net/openhft/affinity/impl/NullAffinity.java b/affinity/src/main/java/net/openhft/affinity/impl/NullAffinity.java index c9ebc183c..4c5e8e304 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/NullAffinity.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/NullAffinity.java @@ -1,20 +1,6 @@ /* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package net.openhft.affinity.impl; import net.openhft.affinity.IAffinity; diff --git a/affinity/src/main/java/net/openhft/affinity/impl/OSXJNAAffinity.java b/affinity/src/main/java/net/openhft/affinity/impl/OSXJNAAffinity.java index 39db80875..fd020fd21 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/OSXJNAAffinity.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/OSXJNAAffinity.java @@ -1,20 +1,6 @@ /* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package net.openhft.affinity.impl; import com.sun.jna.LastErrorException; diff --git a/affinity/src/main/java/net/openhft/affinity/impl/PosixJNAAffinity.java b/affinity/src/main/java/net/openhft/affinity/impl/PosixJNAAffinity.java index 50b0f299d..39aed93ab 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/PosixJNAAffinity.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/PosixJNAAffinity.java @@ -1,20 +1,6 @@ /* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package net.openhft.affinity.impl; import com.sun.jna.*; diff --git a/affinity/src/main/java/net/openhft/affinity/impl/SolarisJNAAffinity.java b/affinity/src/main/java/net/openhft/affinity/impl/SolarisJNAAffinity.java index ebe49b154..fcb5b8db0 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/SolarisJNAAffinity.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/SolarisJNAAffinity.java @@ -1,20 +1,6 @@ /* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package net.openhft.affinity.impl; import com.sun.jna.LastErrorException; diff --git a/affinity/src/main/java/net/openhft/affinity/impl/Utilities.java b/affinity/src/main/java/net/openhft/affinity/impl/Utilities.java index 4d3bfd13b..babf6b360 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/Utilities.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/Utilities.java @@ -1,20 +1,6 @@ /* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package net.openhft.affinity.impl; import java.io.ByteArrayOutputStream; diff --git a/affinity/src/main/java/net/openhft/affinity/impl/VanillaCpuLayout.java b/affinity/src/main/java/net/openhft/affinity/impl/VanillaCpuLayout.java index 74ff2d580..4fac94fe4 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/VanillaCpuLayout.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/VanillaCpuLayout.java @@ -1,20 +1,6 @@ /* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package net.openhft.affinity.impl; import net.openhft.affinity.CpuLayout; diff --git a/affinity/src/main/java/net/openhft/affinity/impl/VersionHelper.java b/affinity/src/main/java/net/openhft/affinity/impl/VersionHelper.java index 616f49232..08a01ab19 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/VersionHelper.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/VersionHelper.java @@ -1,20 +1,6 @@ /* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package net.openhft.affinity.impl; public class VersionHelper { diff --git a/affinity/src/main/java/net/openhft/affinity/impl/WindowsJNAAffinity.java b/affinity/src/main/java/net/openhft/affinity/impl/WindowsJNAAffinity.java index c64bd15be..bdeef6710 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/WindowsJNAAffinity.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/WindowsJNAAffinity.java @@ -1,20 +1,6 @@ /* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package net.openhft.affinity.impl; import com.sun.jna.*; diff --git a/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java b/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java index 8b06f7e39..eb2394ddd 100644 --- a/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java +++ b/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java @@ -1,19 +1,6 @@ /* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package net.openhft.affinity.lockchecker; import org.jetbrains.annotations.NotNull; diff --git a/affinity/src/main/java/net/openhft/affinity/lockchecker/LockChecker.java b/affinity/src/main/java/net/openhft/affinity/lockchecker/LockChecker.java index 79a783e95..ddbe0d49c 100644 --- a/affinity/src/main/java/net/openhft/affinity/lockchecker/LockChecker.java +++ b/affinity/src/main/java/net/openhft/affinity/lockchecker/LockChecker.java @@ -1,46 +1,33 @@ -/* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.openhft.affinity.lockchecker; - -import java.io.IOException; - -/** - * @author Tom Shercliff - */ - -public interface LockChecker { - - boolean isLockFree(int id); - - /** - * Obtain a lock for the given id. - */ - @Deprecated(/* to be removed in x.29 */) - default boolean obtainLock(int id, String metaInfo) throws IOException { - return obtainLock(id, 0, metaInfo); - } - - /** - * Obtain a lock for the given id and id2. The id2 is used to distinguish between - * multiple locks for the same core - */ - boolean obtainLock(int id, int id2, String metaInfo) throws IOException; - - boolean releaseLock(int id); - - String getMetaInfo(int id) throws IOException; -} +/* + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 + */ +package net.openhft.affinity.lockchecker; + +import java.io.IOException; + +/** + * @author Tom Shercliff + */ + +public interface LockChecker { + + boolean isLockFree(int id); + + /** + * Obtain a lock for the given id. + */ + @Deprecated(/* to be removed in x.29 */) + default boolean obtainLock(int id, String metaInfo) throws IOException { + return obtainLock(id, 0, metaInfo); + } + + /** + * Obtain a lock for the given id and id2. The id2 is used to distinguish between + * multiple locks for the same core + */ + boolean obtainLock(int id, int id2, String metaInfo) throws IOException; + + boolean releaseLock(int id); + + String getMetaInfo(int id) throws IOException; +} diff --git a/affinity/src/main/java/net/openhft/affinity/lockchecker/LockReference.java b/affinity/src/main/java/net/openhft/affinity/lockchecker/LockReference.java index 82d89489d..10e2b1bdf 100644 --- a/affinity/src/main/java/net/openhft/affinity/lockchecker/LockReference.java +++ b/affinity/src/main/java/net/openhft/affinity/lockchecker/LockReference.java @@ -1,38 +1,25 @@ -/* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.openhft.affinity.lockchecker; - -import java.nio.channels.FileChannel; -import java.nio.channels.FileLock; - -/** - * @author Tom Shercliff - */ - -public class LockReference { - protected final FileChannel channel; - protected final FileLock lock; - - public LockReference(final FileChannel channel, final FileLock lock) { - this.channel = channel; - this.lock = lock; - } - - public FileChannel getChannel() { - return channel; - } -} +/* + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 + */ +package net.openhft.affinity.lockchecker; + +import java.nio.channels.FileChannel; +import java.nio.channels.FileLock; + +/** + * @author Tom Shercliff + */ + +public class LockReference { + protected final FileChannel channel; + protected final FileLock lock; + + public LockReference(final FileChannel channel, final FileLock lock) { + this.channel = channel; + this.lock = lock; + } + + public FileChannel getChannel() { + return channel; + } +} diff --git a/affinity/src/main/java/net/openhft/affinity/main/AffinityTestMain.java b/affinity/src/main/java/net/openhft/affinity/main/AffinityTestMain.java index 78ca56302..fcaa3281a 100644 --- a/affinity/src/main/java/net/openhft/affinity/main/AffinityTestMain.java +++ b/affinity/src/main/java/net/openhft/affinity/main/AffinityTestMain.java @@ -1,66 +1,53 @@ -/* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.openhft.affinity.main; - -import net.openhft.affinity.Affinity; -import net.openhft.affinity.AffinityLock; - -import java.text.SimpleDateFormat; -import java.util.Date; - -/** - * @author Tom Shercliff - */ -public class AffinityTestMain { - - public static void main(String[] args) { - - int cpus; - if (args.length == 0) { - cpus = AffinityLock.cpuLayout().cpus() / 12; - } else { - cpus = Integer.parseInt(args[0]); - } - - for (int i = 0; i < cpus; i++) { - acquireAndDoWork(); - } - } - - private static void acquireAndDoWork() { - - Thread t = new Thread(() -> { - final SimpleDateFormat df = new SimpleDateFormat("yyyy.MM" + ".dd 'at' HH:mm:ss z"); - try (AffinityLock al = Affinity.acquireLock()) { - String threadName = Thread.currentThread().getName(); - System.out.println("Thread (" + threadName + ") locked onto cpu " + al.cpuId()); - - while (true) { - System.out.println(df.format(new Date()) + " - Thread (" + threadName + ") doing work on cpu " + al.cpuId() + ". IsAllocated = " + al.isAllocated() + ", isBound = " + al.isBound() + ". " + al); - - try { - //noinspection BusyWait - Thread.sleep(10000L); - } catch (InterruptedException e) { - //nothing - } - } - } - }); - t.start(); - } -} +/* + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 + */ +package net.openhft.affinity.main; + +import net.openhft.affinity.Affinity; +import net.openhft.affinity.AffinityLock; + +import java.text.SimpleDateFormat; +import java.util.Date; + +/** + * @author Tom Shercliff + */ +public class AffinityTestMain { + + public static void main(String[] args) { + + int cpus; + if (args.length == 0) { + cpus = AffinityLock.cpuLayout().cpus() / 12; + } else { + cpus = Integer.parseInt(args[0]); + } + + for (int i = 0; i < cpus; i++) { + acquireAndDoWork(); + } + } + + private static void acquireAndDoWork() { + + Thread t = new Thread(() -> { + final SimpleDateFormat df = new SimpleDateFormat("yyyy.MM" + ".dd 'at' HH:mm:ss z"); + try (AffinityLock al = Affinity.acquireLock()) { + String threadName = Thread.currentThread().getName(); + System.out.println("Thread (" + threadName + ") locked onto cpu " + al.cpuId()); + + while (true) { + System.out.println(df.format(new Date()) + " - Thread (" + threadName + ") doing work on cpu " + al.cpuId() + ". IsAllocated = " + al.isAllocated() + ", isBound = " + al.isBound() + ". " + al); + + try { + //noinspection BusyWait + Thread.sleep(10000L); + } catch (InterruptedException e) { + //nothing + } + } + } + }); + t.start(); + } +} diff --git a/affinity/src/main/java/net/openhft/ticker/ITicker.java b/affinity/src/main/java/net/openhft/ticker/ITicker.java index 0763f0871..3a9ab33d3 100644 --- a/affinity/src/main/java/net/openhft/ticker/ITicker.java +++ b/affinity/src/main/java/net/openhft/ticker/ITicker.java @@ -1,20 +1,6 @@ /* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package net.openhft.ticker; /** diff --git a/affinity/src/main/java/net/openhft/ticker/Ticker.java b/affinity/src/main/java/net/openhft/ticker/Ticker.java index 596fe9f2b..4d057cf2a 100644 --- a/affinity/src/main/java/net/openhft/ticker/Ticker.java +++ b/affinity/src/main/java/net/openhft/ticker/Ticker.java @@ -1,20 +1,6 @@ /* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package net.openhft.ticker; import net.openhft.ticker.impl.JNIClock; diff --git a/affinity/src/main/java/net/openhft/ticker/impl/JNIClock.java b/affinity/src/main/java/net/openhft/ticker/impl/JNIClock.java index 58cb01ab6..c50c3826c 100644 --- a/affinity/src/main/java/net/openhft/ticker/impl/JNIClock.java +++ b/affinity/src/main/java/net/openhft/ticker/impl/JNIClock.java @@ -1,20 +1,6 @@ /* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package net.openhft.ticker.impl; import net.openhft.ticker.ITicker; diff --git a/affinity/src/main/java/net/openhft/ticker/impl/SystemClock.java b/affinity/src/main/java/net/openhft/ticker/impl/SystemClock.java index 8c88c2aef..cbbd3545e 100644 --- a/affinity/src/main/java/net/openhft/ticker/impl/SystemClock.java +++ b/affinity/src/main/java/net/openhft/ticker/impl/SystemClock.java @@ -1,20 +1,6 @@ /* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package net.openhft.ticker.impl; import net.openhft.ticker.ITicker; diff --git a/affinity/src/main/java/software/chronicle/enterprise/internals/impl/NativeAffinity.java b/affinity/src/main/java/software/chronicle/enterprise/internals/impl/NativeAffinity.java index 2071dd77e..cf95002bb 100644 --- a/affinity/src/main/java/software/chronicle/enterprise/internals/impl/NativeAffinity.java +++ b/affinity/src/main/java/software/chronicle/enterprise/internals/impl/NativeAffinity.java @@ -1,20 +1,6 @@ /* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package software.chronicle.enterprise.internals.impl; import net.openhft.affinity.IAffinity; diff --git a/affinity/src/test/java/net/openhft/affinity/AffinityLockBindMain.java b/affinity/src/test/java/net/openhft/affinity/AffinityLockBindMain.java index 1935e105f..b1ed7effe 100644 --- a/affinity/src/test/java/net/openhft/affinity/AffinityLockBindMain.java +++ b/affinity/src/test/java/net/openhft/affinity/AffinityLockBindMain.java @@ -1,20 +1,6 @@ /* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package net.openhft.affinity; import static net.openhft.affinity.AffinityStrategies.*; diff --git a/affinity/src/test/java/net/openhft/affinity/AffinityLockDumpLocksTest.java b/affinity/src/test/java/net/openhft/affinity/AffinityLockDumpLocksTest.java index 0336ab660..984b18b5f 100644 --- a/affinity/src/test/java/net/openhft/affinity/AffinityLockDumpLocksTest.java +++ b/affinity/src/test/java/net/openhft/affinity/AffinityLockDumpLocksTest.java @@ -1,3 +1,6 @@ +/* + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 + */ package net.openhft.affinity; import net.openhft.affinity.impl.VanillaCpuLayout; diff --git a/affinity/src/test/java/net/openhft/affinity/AffinityLockMain.java b/affinity/src/test/java/net/openhft/affinity/AffinityLockMain.java index 5f09608c9..cf7388ec6 100644 --- a/affinity/src/test/java/net/openhft/affinity/AffinityLockMain.java +++ b/affinity/src/test/java/net/openhft/affinity/AffinityLockMain.java @@ -1,20 +1,6 @@ /* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package net.openhft.affinity; /** diff --git a/affinity/src/test/java/net/openhft/affinity/AffinityLockReleaseTest.java b/affinity/src/test/java/net/openhft/affinity/AffinityLockReleaseTest.java index 4cbc15f4d..dc964296f 100644 --- a/affinity/src/test/java/net/openhft/affinity/AffinityLockReleaseTest.java +++ b/affinity/src/test/java/net/openhft/affinity/AffinityLockReleaseTest.java @@ -1,19 +1,6 @@ /* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package net.openhft.affinity; import net.openhft.affinity.impl.VanillaCpuLayout; diff --git a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java index a101f477d..4e8ff5519 100644 --- a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java +++ b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java @@ -1,20 +1,6 @@ /* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package net.openhft.affinity; import net.openhft.affinity.impl.Utilities; diff --git a/affinity/src/test/java/net/openhft/affinity/AffinityResetToBaseAffinityTest.java b/affinity/src/test/java/net/openhft/affinity/AffinityResetToBaseAffinityTest.java index 502cb0e0b..86ad17fed 100644 --- a/affinity/src/test/java/net/openhft/affinity/AffinityResetToBaseAffinityTest.java +++ b/affinity/src/test/java/net/openhft/affinity/AffinityResetToBaseAffinityTest.java @@ -1,3 +1,6 @@ +/* + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 + */ package net.openhft.affinity; import net.openhft.affinity.impl.VanillaCpuLayout; diff --git a/affinity/src/test/java/net/openhft/affinity/AffinitySupportMain.java b/affinity/src/test/java/net/openhft/affinity/AffinitySupportMain.java index 9e0d8efc9..d7cf5b35d 100644 --- a/affinity/src/test/java/net/openhft/affinity/AffinitySupportMain.java +++ b/affinity/src/test/java/net/openhft/affinity/AffinitySupportMain.java @@ -1,20 +1,6 @@ /* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package net.openhft.affinity; /** diff --git a/affinity/src/test/java/net/openhft/affinity/AffinityThreadFactoryMain.java b/affinity/src/test/java/net/openhft/affinity/AffinityThreadFactoryMain.java index 9052239b3..3dbd15396 100644 --- a/affinity/src/test/java/net/openhft/affinity/AffinityThreadFactoryMain.java +++ b/affinity/src/test/java/net/openhft/affinity/AffinityThreadFactoryMain.java @@ -1,20 +1,6 @@ /* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package net.openhft.affinity; import java.util.concurrent.Callable; diff --git a/affinity/src/test/java/net/openhft/affinity/AffinityThreadFactoryTest.java b/affinity/src/test/java/net/openhft/affinity/AffinityThreadFactoryTest.java index 7368178d7..4c95b8bd4 100644 --- a/affinity/src/test/java/net/openhft/affinity/AffinityThreadFactoryTest.java +++ b/affinity/src/test/java/net/openhft/affinity/AffinityThreadFactoryTest.java @@ -1,3 +1,6 @@ +/* + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 + */ package net.openhft.affinity; import org.junit.Assume; diff --git a/affinity/src/test/java/net/openhft/affinity/BaseAffinityTest.java b/affinity/src/test/java/net/openhft/affinity/BaseAffinityTest.java index 85491595c..f147ce33b 100644 --- a/affinity/src/test/java/net/openhft/affinity/BaseAffinityTest.java +++ b/affinity/src/test/java/net/openhft/affinity/BaseAffinityTest.java @@ -1,19 +1,6 @@ /* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package net.openhft.affinity; import org.junit.After; diff --git a/affinity/src/test/java/net/openhft/affinity/BootClassPathTest.java b/affinity/src/test/java/net/openhft/affinity/BootClassPathTest.java index 426ad9f22..17558a01e 100644 --- a/affinity/src/test/java/net/openhft/affinity/BootClassPathTest.java +++ b/affinity/src/test/java/net/openhft/affinity/BootClassPathTest.java @@ -1,19 +1,6 @@ /* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package net.openhft.affinity; import org.junit.Test; diff --git a/affinity/src/test/java/net/openhft/affinity/FileLockLockCheckTest.java b/affinity/src/test/java/net/openhft/affinity/FileLockLockCheckTest.java index 6be18c5d7..f1a88ddc1 100644 --- a/affinity/src/test/java/net/openhft/affinity/FileLockLockCheckTest.java +++ b/affinity/src/test/java/net/openhft/affinity/FileLockLockCheckTest.java @@ -1,20 +1,6 @@ /* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package net.openhft.affinity; import net.openhft.affinity.testimpl.TestFileLockBasedLockChecker; diff --git a/affinity/src/test/java/net/openhft/affinity/InterrupedThread.java b/affinity/src/test/java/net/openhft/affinity/InterrupedThread.java index 92441d61a..9e85c0790 100644 --- a/affinity/src/test/java/net/openhft/affinity/InterrupedThread.java +++ b/affinity/src/test/java/net/openhft/affinity/InterrupedThread.java @@ -1,20 +1,6 @@ /* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package net.openhft.affinity; /** diff --git a/affinity/src/test/java/net/openhft/affinity/LockCheckTest.java b/affinity/src/test/java/net/openhft/affinity/LockCheckTest.java index 2612886ce..3f19a4a2f 100644 --- a/affinity/src/test/java/net/openhft/affinity/LockCheckTest.java +++ b/affinity/src/test/java/net/openhft/affinity/LockCheckTest.java @@ -1,20 +1,6 @@ /* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package net.openhft.affinity; import net.openhft.affinity.testimpl.TestFileLockBasedLockChecker; diff --git a/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java b/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java index 98eeb0a2b..56fd81b69 100644 --- a/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java +++ b/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java @@ -1,19 +1,6 @@ /* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package net.openhft.affinity; import net.openhft.affinity.testimpl.TestFileLockBasedLockChecker; diff --git a/affinity/src/test/java/net/openhft/affinity/impl/AbstractAffinityImplTest.java b/affinity/src/test/java/net/openhft/affinity/impl/AbstractAffinityImplTest.java index 9cf1b7119..ec45f0e3f 100644 --- a/affinity/src/test/java/net/openhft/affinity/impl/AbstractAffinityImplTest.java +++ b/affinity/src/test/java/net/openhft/affinity/impl/AbstractAffinityImplTest.java @@ -1,20 +1,6 @@ /* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package net.openhft.affinity.impl; import net.openhft.affinity.BaseAffinityTest; diff --git a/affinity/src/test/java/net/openhft/affinity/impl/CpuInfoLayoutMappingTest.java b/affinity/src/test/java/net/openhft/affinity/impl/CpuInfoLayoutMappingTest.java index f58bcfb01..7687f6967 100644 --- a/affinity/src/test/java/net/openhft/affinity/impl/CpuInfoLayoutMappingTest.java +++ b/affinity/src/test/java/net/openhft/affinity/impl/CpuInfoLayoutMappingTest.java @@ -1,19 +1,6 @@ /* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package net.openhft.affinity.impl; import net.openhft.affinity.BaseAffinityTest; diff --git a/affinity/src/test/java/net/openhft/affinity/impl/LinuxJNAAffinityTest.java b/affinity/src/test/java/net/openhft/affinity/impl/LinuxJNAAffinityTest.java index 760201c04..cf0db12bd 100644 --- a/affinity/src/test/java/net/openhft/affinity/impl/LinuxJNAAffinityTest.java +++ b/affinity/src/test/java/net/openhft/affinity/impl/LinuxJNAAffinityTest.java @@ -1,20 +1,6 @@ /* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package net.openhft.affinity.impl; import net.openhft.affinity.BaseAffinityTest; diff --git a/affinity/src/test/java/net/openhft/affinity/impl/NativeAffinityImpTest.java b/affinity/src/test/java/net/openhft/affinity/impl/NativeAffinityImpTest.java index 4b807d7a2..2b9cbb73a 100644 --- a/affinity/src/test/java/net/openhft/affinity/impl/NativeAffinityImpTest.java +++ b/affinity/src/test/java/net/openhft/affinity/impl/NativeAffinityImpTest.java @@ -1,20 +1,6 @@ /* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package net.openhft.affinity.impl; import net.openhft.affinity.Affinity; diff --git a/affinity/src/test/java/net/openhft/affinity/impl/PosixJNAAffinityTest.java b/affinity/src/test/java/net/openhft/affinity/impl/PosixJNAAffinityTest.java index 3c7ec1a7f..180506e70 100644 --- a/affinity/src/test/java/net/openhft/affinity/impl/PosixJNAAffinityTest.java +++ b/affinity/src/test/java/net/openhft/affinity/impl/PosixJNAAffinityTest.java @@ -1,20 +1,6 @@ /* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package net.openhft.affinity.impl; import net.openhft.affinity.Affinity; diff --git a/affinity/src/test/java/net/openhft/affinity/impl/UtilitiesTest.java b/affinity/src/test/java/net/openhft/affinity/impl/UtilitiesTest.java index 9b282ac15..80eed46ea 100644 --- a/affinity/src/test/java/net/openhft/affinity/impl/UtilitiesTest.java +++ b/affinity/src/test/java/net/openhft/affinity/impl/UtilitiesTest.java @@ -1,19 +1,6 @@ /* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package net.openhft.affinity.impl; import net.openhft.affinity.BaseAffinityTest; diff --git a/affinity/src/test/java/net/openhft/affinity/impl/VanillaCpuLayoutPairTest.java b/affinity/src/test/java/net/openhft/affinity/impl/VanillaCpuLayoutPairTest.java index a09e6cd07..c356f3c81 100644 --- a/affinity/src/test/java/net/openhft/affinity/impl/VanillaCpuLayoutPairTest.java +++ b/affinity/src/test/java/net/openhft/affinity/impl/VanillaCpuLayoutPairTest.java @@ -1,19 +1,6 @@ /* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package net.openhft.affinity.impl; import net.openhft.affinity.BaseAffinityTest; diff --git a/affinity/src/test/java/net/openhft/affinity/impl/VanillaCpuLayoutPropertiesParseTest.java b/affinity/src/test/java/net/openhft/affinity/impl/VanillaCpuLayoutPropertiesParseTest.java index 32c6ae11b..7452c060f 100644 --- a/affinity/src/test/java/net/openhft/affinity/impl/VanillaCpuLayoutPropertiesParseTest.java +++ b/affinity/src/test/java/net/openhft/affinity/impl/VanillaCpuLayoutPropertiesParseTest.java @@ -1,3 +1,6 @@ +/* + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 + */ package net.openhft.affinity.impl; import net.openhft.affinity.BaseAffinityTest; diff --git a/affinity/src/test/java/net/openhft/affinity/impl/VanillaCpuLayoutTest.java b/affinity/src/test/java/net/openhft/affinity/impl/VanillaCpuLayoutTest.java index b712dab54..0e90d5069 100644 --- a/affinity/src/test/java/net/openhft/affinity/impl/VanillaCpuLayoutTest.java +++ b/affinity/src/test/java/net/openhft/affinity/impl/VanillaCpuLayoutTest.java @@ -1,20 +1,6 @@ /* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package net.openhft.affinity.impl; import net.openhft.affinity.BaseAffinityTest; diff --git a/affinity/src/test/java/net/openhft/affinity/impl/VersionHelperTest.java b/affinity/src/test/java/net/openhft/affinity/impl/VersionHelperTest.java index ba6a08b84..a7f21afff 100644 --- a/affinity/src/test/java/net/openhft/affinity/impl/VersionHelperTest.java +++ b/affinity/src/test/java/net/openhft/affinity/impl/VersionHelperTest.java @@ -1,20 +1,6 @@ /* - * Copyright 2017-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package net.openhft.affinity.impl; import net.openhft.affinity.BaseAffinityTest; diff --git a/affinity/src/test/java/net/openhft/affinity/testimpl/TestFileLockBasedLockChecker.java b/affinity/src/test/java/net/openhft/affinity/testimpl/TestFileLockBasedLockChecker.java index 8e93c0f21..56b47d9e1 100644 --- a/affinity/src/test/java/net/openhft/affinity/testimpl/TestFileLockBasedLockChecker.java +++ b/affinity/src/test/java/net/openhft/affinity/testimpl/TestFileLockBasedLockChecker.java @@ -1,19 +1,6 @@ /* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package net.openhft.affinity.testimpl; import net.openhft.affinity.lockchecker.FileLockBasedLockChecker; diff --git a/affinity/src/test/java/net/openhft/ticker/impl/JNIClockTest.java b/affinity/src/test/java/net/openhft/ticker/impl/JNIClockTest.java index 84d39c833..359c06e02 100644 --- a/affinity/src/test/java/net/openhft/ticker/impl/JNIClockTest.java +++ b/affinity/src/test/java/net/openhft/ticker/impl/JNIClockTest.java @@ -1,20 +1,6 @@ /* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package net.openhft.ticker.impl; import net.openhft.affinity.Affinity; diff --git a/affinity/src/test/java/software/chronicle/enterprise/internals/JnaAffinityTest.java b/affinity/src/test/java/software/chronicle/enterprise/internals/JnaAffinityTest.java index 5f49c8503..19be7b0b4 100644 --- a/affinity/src/test/java/software/chronicle/enterprise/internals/JnaAffinityTest.java +++ b/affinity/src/test/java/software/chronicle/enterprise/internals/JnaAffinityTest.java @@ -1,20 +1,6 @@ /* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package software.chronicle.enterprise.internals; import net.openhft.affinity.BaseAffinityTest; diff --git a/affinity/src/test/java/software/chronicle/enterprise/internals/NativeAffinityTest.java b/affinity/src/test/java/software/chronicle/enterprise/internals/NativeAffinityTest.java index 7f7afecd3..138d64337 100644 --- a/affinity/src/test/java/software/chronicle/enterprise/internals/NativeAffinityTest.java +++ b/affinity/src/test/java/software/chronicle/enterprise/internals/NativeAffinityTest.java @@ -1,20 +1,6 @@ /* - * Copyright 2016-2025 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * + * Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 */ - package software.chronicle.enterprise.internals; import net.openhft.affinity.BaseAffinityTest; diff --git a/pom.xml b/pom.xml index e08693cd9..0cf19304e 100644 --- a/pom.xml +++ b/pom.xml @@ -1,19 +1,9 @@ + + Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0 + +--> 4.0.0 @@ -21,7 +11,7 @@ net.openhft java-parent-pom - 1.27ea1 + 1.27ea2-SNAPSHOT From 4b22ead225ae98c514041499c4bf21354189f250 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Tue, 11 Nov 2025 16:15:48 +0000 Subject: [PATCH 326/353] Fix URL in README for micro-jitter article --- README.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.adoc b/README.adoc index 61367bd58..13720fe77 100644 --- a/README.adoc +++ b/README.adoc @@ -90,7 +90,7 @@ https://github.com/peter-lawrey/Java-Thread-Affinity/wiki/Getting-started https://github.com/peter-lawrey/Java-Thread-Affinity/wiki/How-it-works -http://vanillajava.blogspot.co.uk/2013/07/micro-jitter-busy-waiting-and-binding.html +https://vanillajava.blogspot.com/2013/07/micro-jitter-busy-waiting-and-binding.html === isolcpus From e9b0f01b9f7f258e09fb7485b01fbcd183389592 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Tue, 11 Nov 2025 16:46:32 +0000 Subject: [PATCH 327/353] Refactor access modifiers and suppress warnings in affinity classes --- affinity-test/pom.xml | 2 ++ .../openhft/affinity/osgi/OSGiBundleTest.java | 2 +- .../openhft/affinity/osgi/OSGiTestBase.java | 8 ++--- affinity/pom.xml | 31 ++----------------- .../internals/impl/NativeAffinity.java | 1 + .../affinity/AffinityLockDumpLocksTest.java | 2 +- .../affinity/MultiProcessAffinityTest.java | 4 +-- .../impl/AbstractAffinityImplTest.java | 6 ++-- .../enterprise/internals/JnaAffinityTest.java | 6 ++-- .../internals/NativeAffinityTest.java | 6 ++-- 10 files changed, 22 insertions(+), 46 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 9b75487b5..97d18e308 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -24,6 +24,8 @@ UTF-8 + 0 + 0 diff --git a/affinity-test/src/test/java/net/openhft/affinity/osgi/OSGiBundleTest.java b/affinity-test/src/test/java/net/openhft/affinity/osgi/OSGiBundleTest.java index 7896c6d7a..a3213a6e7 100644 --- a/affinity-test/src/test/java/net/openhft/affinity/osgi/OSGiBundleTest.java +++ b/affinity-test/src/test/java/net/openhft/affinity/osgi/OSGiBundleTest.java @@ -21,7 +21,7 @@ @RunWith(PaxExam.class) public class OSGiBundleTest extends net.openhft.affinity.osgi.OSGiTestBase { @Inject - BundleContext context; + private BundleContext context; @Configuration public Option[] config() { diff --git a/affinity-test/src/test/java/net/openhft/affinity/osgi/OSGiTestBase.java b/affinity-test/src/test/java/net/openhft/affinity/osgi/OSGiTestBase.java index 347d2edf0..a5fb702dd 100644 --- a/affinity-test/src/test/java/net/openhft/affinity/osgi/OSGiTestBase.java +++ b/affinity-test/src/test/java/net/openhft/affinity/osgi/OSGiTestBase.java @@ -11,9 +11,9 @@ import java.io.File; -public class OSGiTestBase { +class OSGiTestBase { - public static Option workspaceBundle(String projectName) { + static Option workspaceBundle(String projectName) { String baseDir = System.getProperty("main.basedir"); String bundleDir; @@ -30,11 +30,11 @@ public static Option workspaceBundle(String projectName) { return null; } - public static MavenArtifactProvisionOption mavenBundleAsInProject(final String groupId, final String artifactId) { + static MavenArtifactProvisionOption mavenBundleAsInProject(final String groupId, final String artifactId) { return CoreOptions.mavenBundle().groupId(groupId).artifactId(artifactId).versionAsInProject(); } - public static Bundle findBundle(BundleContext context, String symbolicName) { + static Bundle findBundle(BundleContext context, String symbolicName) { Bundle[] bundles = context.getBundles(); for (Bundle bundle : bundles) { if (bundle != null) { diff --git a/affinity/pom.xml b/affinity/pom.xml index e778dd9e1..b2071fe41 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -25,6 +25,8 @@ src/main/c UTF-8 + 0.5 + 0.4 @@ -132,35 +134,6 @@ - - sonar - - - - org.sonarsource.scanner.maven - sonar-maven-plugin - - - org.jacoco - jacoco-maven-plugin - - - - prepare-agent - - - - report - prepare-package - - report - - - - - - - diff --git a/affinity/src/main/java/software/chronicle/enterprise/internals/impl/NativeAffinity.java b/affinity/src/main/java/software/chronicle/enterprise/internals/impl/NativeAffinity.java index cf95002bb..aa501a8f0 100644 --- a/affinity/src/main/java/software/chronicle/enterprise/internals/impl/NativeAffinity.java +++ b/affinity/src/main/java/software/chronicle/enterprise/internals/impl/NativeAffinity.java @@ -28,6 +28,7 @@ public enum NativeAffinity implements IAffinity { private native static long rdtsc0(); + @SuppressWarnings("restricted") private static boolean loadAffinityNativeLibrary() { try { System.loadLibrary("CEInternals"); diff --git a/affinity/src/test/java/net/openhft/affinity/AffinityLockDumpLocksTest.java b/affinity/src/test/java/net/openhft/affinity/AffinityLockDumpLocksTest.java index 984b18b5f..dd87e4f4e 100644 --- a/affinity/src/test/java/net/openhft/affinity/AffinityLockDumpLocksTest.java +++ b/affinity/src/test/java/net/openhft/affinity/AffinityLockDumpLocksTest.java @@ -17,7 +17,7 @@ public class AffinityLockDumpLocksTest extends BaseAffinityTest { - static void supressUnusedWarning(AutoCloseable c) { + private static void supressUnusedWarning(AutoCloseable c) { // do nothing } diff --git a/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java b/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java index 56fd81b69..63dd9105b 100644 --- a/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java +++ b/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java @@ -142,7 +142,7 @@ static class RepeatedAffinityLocker implements Callable { private final int iterations; private final String cpuIdToLock; - public RepeatedAffinityLocker(String cpuIdToLock, int iterations) { + RepeatedAffinityLocker(String cpuIdToLock, int iterations) { this.iterations = iterations; this.cpuIdToLock = cpuIdToLock; } @@ -255,7 +255,7 @@ public static void main(String[] args) throws InterruptedException, IOException } @NotNull - protected static File toFile(int id) { + static File toFile(int id) { return new TestFileLockBasedLockChecker().doToFile(id); } } diff --git a/affinity/src/test/java/net/openhft/affinity/impl/AbstractAffinityImplTest.java b/affinity/src/test/java/net/openhft/affinity/impl/AbstractAffinityImplTest.java index ec45f0e3f..6c1cc5fbf 100644 --- a/affinity/src/test/java/net/openhft/affinity/impl/AbstractAffinityImplTest.java +++ b/affinity/src/test/java/net/openhft/affinity/impl/AbstractAffinityImplTest.java @@ -18,14 +18,14 @@ */ public abstract class AbstractAffinityImplTest extends BaseAffinityTest { - protected static final int CORES = Runtime.getRuntime().availableProcessors(); - protected static final BitSet CORES_MASK = new BitSet(CORES); + private static final int CORES = Runtime.getRuntime().availableProcessors(); + private static final BitSet CORES_MASK = new BitSet(CORES); static { CORES_MASK.set(0, CORES, true); } - public abstract IAffinity getImpl(); + protected abstract IAffinity getImpl(); @Test public void getAffinityCompletesGracefully() { diff --git a/affinity/src/test/java/software/chronicle/enterprise/internals/JnaAffinityTest.java b/affinity/src/test/java/software/chronicle/enterprise/internals/JnaAffinityTest.java index 19be7b0b4..a65863c1d 100644 --- a/affinity/src/test/java/software/chronicle/enterprise/internals/JnaAffinityTest.java +++ b/affinity/src/test/java/software/chronicle/enterprise/internals/JnaAffinityTest.java @@ -20,8 +20,8 @@ * @author peter.lawrey */ public class JnaAffinityTest extends BaseAffinityTest { - protected static final int CORES = Runtime.getRuntime().availableProcessors(); - protected static final BitSet CORES_MASK = new BitSet(CORES); + private static final int CORES = Runtime.getRuntime().availableProcessors(); + private static final BitSet CORES_MASK = new BitSet(CORES); static { CORES_MASK.set(0, CORES, true); @@ -90,7 +90,7 @@ public void tearDown() { getImpl().setAffinity(CORES_MASK); } - public IAffinity getImpl() { + private IAffinity getImpl() { return LinuxJNAAffinity.INSTANCE; } } diff --git a/affinity/src/test/java/software/chronicle/enterprise/internals/NativeAffinityTest.java b/affinity/src/test/java/software/chronicle/enterprise/internals/NativeAffinityTest.java index 138d64337..fa2bc7fba 100644 --- a/affinity/src/test/java/software/chronicle/enterprise/internals/NativeAffinityTest.java +++ b/affinity/src/test/java/software/chronicle/enterprise/internals/NativeAffinityTest.java @@ -18,8 +18,8 @@ * @author peter.lawrey */ public class NativeAffinityTest extends BaseAffinityTest { - protected static final int CORES = Runtime.getRuntime().availableProcessors(); - protected static final BitSet CORES_MASK = new BitSet(CORES); + private static final int CORES = Runtime.getRuntime().availableProcessors(); + private static final BitSet CORES_MASK = new BitSet(CORES); static { CORES_MASK.set(0, CORES, true); @@ -116,7 +116,7 @@ public void tearDown() { getImpl().setAffinity(CORES_MASK); } - public IAffinity getImpl() { + private IAffinity getImpl() { return NativeAffinity.INSTANCE; } } From ddda97892e3e5ea9162d1be58e48f55f144d74ba Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Wed, 12 Nov 2025 18:43:13 +0000 Subject: [PATCH 328/353] Updating parent POM (automated) --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 97d18e308..dda8870da 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -11,7 +11,7 @@ net.openhft java-parent-pom - 1.27ea2-SNAPSHOT + 1.27ea1 diff --git a/affinity/pom.xml b/affinity/pom.xml index b2071fe41..5a9e309eb 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -11,7 +11,7 @@ net.openhft java-parent-pom - 1.27ea2-SNAPSHOT + 1.27ea1 diff --git a/pom.xml b/pom.xml index 0cf19304e..ca8cfcb7b 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ net.openhft java-parent-pom - 1.27ea2-SNAPSHOT + 1.27ea1 From 4fd4253a565a53c71fea45f733c6744d21048d65 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Fri, 14 Nov 2025 22:02:39 +0000 Subject: [PATCH 329/353] Updating third-party-bom version (automated) --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index dda8870da..8f7a2baa3 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -33,7 +33,7 @@ net.openhft third-party-bom - 3.27ea0 + 3.27ea5 pom import diff --git a/affinity/pom.xml b/affinity/pom.xml index 5a9e309eb..8b9a31249 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -34,7 +34,7 @@ net.openhft third-party-bom - 3.27ea2 + 3.27ea5 pom import From 7078d184258da23a63388c7c8ca21771ecb12a0e Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Mon, 1 Dec 2025 16:49:24 +0000 Subject: [PATCH 330/353] Initial update of version 2026.0-SNAPSHOT --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 8f7a2baa3..8ff70df8e 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -16,7 +16,7 @@ affinity-test - 3.27ea2-SNAPSHOT + 2026.0-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -33,7 +33,7 @@ net.openhft third-party-bom - 3.27ea5 + 2026.0-SNAPSHOT pom import diff --git a/affinity/pom.xml b/affinity/pom.xml index 8b9a31249..8a477942f 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -16,7 +16,7 @@ affinity - 3.27ea2-SNAPSHOT + 2026.0-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity @@ -34,7 +34,7 @@ net.openhft third-party-bom - 3.27ea5 + 2026.0-SNAPSHOT pom import diff --git a/pom.xml b/pom.xml index ca8cfcb7b..5d9698d72 100644 --- a/pom.xml +++ b/pom.xml @@ -16,7 +16,7 @@ Java-Thread-Affinity - 3.27ea2-SNAPSHOT + 2026.0-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent From 7ba30baf9ae34fd7671fa980b8dcc1e196d0fcc4 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Tue, 2 Dec 2025 09:57:02 +0000 Subject: [PATCH 331/353] Add the quality profile --- affinity/pom.xml | 76 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/affinity/pom.xml b/affinity/pom.xml index 8a477942f..c1e94865b 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -134,6 +134,82 @@ + + + quality + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + 3.6.0 + + + validate + validate + + check + + + + + net/openhft/quality/checkstyle26/chronicle-baseline-checkstyle.xml + true + true + true + warning + + + + com.puppycrawl.tools + checkstyle + 10.26.1 + + + net.openhft + quality + 2026.0-SNAPSHOT + + + + + com.github.spotbugs + spotbugs-maven-plugin + 4.9.8.1 + + Max + Low + true + true + net/openhft/quality/spotbugs26/chronicle-spotbugs-include.xml + net/openhft/quality/spotbugs26/chronicle-spotbugs-exclude.xml + + + + net.openhft + quality + 2026.0-SNAPSHOT + + + + + spotbugs-main + + process-test-classes + + check + + + + + + + From ee3af8e598a96a1714fa328920660627863746eb Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Tue, 2 Dec 2025 13:58:12 +0000 Subject: [PATCH 332/353] Update dependencies and add third-party smoke tests --- affinity-test/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 8ff70df8e..c7f3168eb 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -51,8 +51,8 @@ affinity - javax.inject - javax.inject + jakarta.inject + jakarta.inject-api test From 780e34cb5b4658ca8d31a493052b53be168b9bfd Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Tue, 2 Dec 2025 14:27:51 +0000 Subject: [PATCH 333/353] quality rules to be moved to OpenHFT and inherited --- affinity/pom.xml | 76 ------------------------------------------------ 1 file changed, 76 deletions(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index c1e94865b..8a477942f 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -134,82 +134,6 @@ - - - quality - - - - - org.apache.maven.plugins - maven-checkstyle-plugin - 3.6.0 - - - validate - validate - - check - - - - - net/openhft/quality/checkstyle26/chronicle-baseline-checkstyle.xml - true - true - true - warning - - - - com.puppycrawl.tools - checkstyle - 10.26.1 - - - net.openhft - quality - 2026.0-SNAPSHOT - - - - - com.github.spotbugs - spotbugs-maven-plugin - 4.9.8.1 - - Max - Low - true - true - net/openhft/quality/spotbugs26/chronicle-spotbugs-include.xml - net/openhft/quality/spotbugs26/chronicle-spotbugs-exclude.xml - - - - net.openhft - quality - 2026.0-SNAPSHOT - - - - - spotbugs-main - - process-test-classes - - check - - - - - - - From c7df5f7d5a3cd794981e97f8ad6c08b38acf0307 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Wed, 3 Dec 2025 11:18:42 +0000 Subject: [PATCH 334/353] Update POM versions to 2026.0-SNAPSHOT --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 4 ++-- pom.xml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index c7f3168eb..7304c6eb2 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -11,7 +11,7 @@ net.openhft java-parent-pom - 1.27ea1 + 2026.0-SNAPSHOT diff --git a/affinity/pom.xml b/affinity/pom.xml index 8a477942f..e4e8e4bd6 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -11,7 +11,7 @@ net.openhft java-parent-pom - 1.27ea1 + 2026.0-SNAPSHOT @@ -41,7 +41,7 @@ net.openhft chronicle-bom - 2.27ea-SNAPSHOT + 2026.0-SNAPSHOT pom import diff --git a/pom.xml b/pom.xml index 5d9698d72..ee5a566df 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ net.openhft java-parent-pom - 1.27ea1 + 2026.0-SNAPSHOT From 41db4a3b1b6b98d6c18b1ffa8b38846f71177b28 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Thu, 4 Dec 2025 09:12:47 +0000 Subject: [PATCH 335/353] Update JaCoCo coverage thresholds and clean up pom.xml properties --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index e4e8e4bd6..76c3d50d9 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -25,7 +25,7 @@ src/main/c UTF-8 - 0.5 + 0.40 0.4 From 5f6ec5c44ec5b129a385b20f765f45fd692c61fa Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Fri, 19 Dec 2025 21:06:19 +0000 Subject: [PATCH 336/353] Updating parent POM (automated) --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 7304c6eb2..c7f3168eb 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -11,7 +11,7 @@ net.openhft java-parent-pom - 2026.0-SNAPSHOT + 1.27ea1 diff --git a/affinity/pom.xml b/affinity/pom.xml index 76c3d50d9..e3cd6173d 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -11,7 +11,7 @@ net.openhft java-parent-pom - 2026.0-SNAPSHOT + 1.27ea1 diff --git a/pom.xml b/pom.xml index ee5a566df..5d9698d72 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ net.openhft java-parent-pom - 2026.0-SNAPSHOT + 1.27ea1 From e30814c4defc0e35112c149f26aa5081eb71fab7 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Wed, 21 Jan 2026 21:02:11 +0000 Subject: [PATCH 337/353] Updating parent POM (automated) --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index c7f3168eb..7df0cfa95 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -11,7 +11,7 @@ net.openhft java-parent-pom - 1.27ea1 + 2026.XYZ diff --git a/affinity/pom.xml b/affinity/pom.xml index e3cd6173d..d926c2898 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -11,7 +11,7 @@ net.openhft java-parent-pom - 1.27ea1 + 2026.XYZ diff --git a/pom.xml b/pom.xml index 5d9698d72..fb9202f55 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ net.openhft java-parent-pom - 1.27ea1 + 2026.XYZ From d7bf1a6679c325424197fd059ccf6f8547c96b44 Mon Sep 17 00:00:00 2001 From: james-mcsherry <164900221+james-mcsherry@users.noreply.github.com> Date: Tue, 27 Jan 2026 11:36:31 +0000 Subject: [PATCH 338/353] Rolled java-parent-pom to 2026.0 (#193) --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index fb9202f55..4e0a0159c 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ net.openhft java-parent-pom - 2026.XYZ + 2026.0 From 3af30511723a03555507dc07a94485360a915c9b Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Tue, 27 Jan 2026 21:11:34 +0000 Subject: [PATCH 339/353] Updating parent POM (automated) --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 4e0a0159c..fb9202f55 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ net.openhft java-parent-pom - 2026.0 + 2026.XYZ From 36cb41a28425d8aeb1fb7102066bcd15d34f2277 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Tue, 27 Jan 2026 23:24:36 +0000 Subject: [PATCH 340/353] Rolling back parent POM to 2026.0 (automated) --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 7df0cfa95..5c26527cd 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -11,7 +11,7 @@ net.openhft java-parent-pom - 2026.XYZ + 2026.0 diff --git a/affinity/pom.xml b/affinity/pom.xml index d926c2898..ed28979b3 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -11,7 +11,7 @@ net.openhft java-parent-pom - 2026.XYZ + 2026.0 diff --git a/pom.xml b/pom.xml index fb9202f55..4e0a0159c 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ net.openhft java-parent-pom - 2026.XYZ + 2026.0 From a687f94ffd4f319f33606f5068c7ba3fab90e238 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Wed, 28 Jan 2026 11:15:19 +0000 Subject: [PATCH 341/353] Updating to bom version 2026.0 --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index ed28979b3..5303ed48a 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -41,7 +41,7 @@ net.openhft chronicle-bom - 2026.0-SNAPSHOT + 2026.0 pom import From 5f6b5ff2bae0cb84dbaf3d1b29ddcd9e86870312 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Wed, 28 Jan 2026 11:15:40 +0000 Subject: [PATCH 342/353] [maven-release-plugin] prepare release Java-Thread-Affinity-2026.0 --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 5c26527cd..fce9fb1c0 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -16,7 +16,7 @@ affinity-test - 2026.0-SNAPSHOT + 2026.0 bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -195,7 +195,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-2026.0 scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git diff --git a/affinity/pom.xml b/affinity/pom.xml index 5303ed48a..021b2a819 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -16,7 +16,7 @@ affinity - 2026.0-SNAPSHOT + 2026.0 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -243,7 +243,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-2026.0 diff --git a/pom.xml b/pom.xml index 4e0a0159c..593566274 100644 --- a/pom.xml +++ b/pom.xml @@ -16,7 +16,7 @@ Java-Thread-Affinity - 2026.0-SNAPSHOT + 2026.0 pom OpenHFT/Java-Thread-Affinity Parent @@ -32,7 +32,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-2026.0 From 82a4978b01bc70a924cdb1e30a624d0a31bfc3f6 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Wed, 28 Jan 2026 11:15:44 +0000 Subject: [PATCH 343/353] [maven-release-plugin] prepare for next development iteration --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index fce9fb1c0..7e54615b0 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -16,7 +16,7 @@ affinity-test - 2026.0 + 2026.1-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -195,7 +195,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-2026.0 + ea scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git diff --git a/affinity/pom.xml b/affinity/pom.xml index 021b2a819..b4792efbe 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -16,7 +16,7 @@ affinity - 2026.0 + 2026.1-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity @@ -243,7 +243,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-2026.0 + ea diff --git a/pom.xml b/pom.xml index 593566274..2989b50c0 100644 --- a/pom.xml +++ b/pom.xml @@ -16,7 +16,7 @@ Java-Thread-Affinity - 2026.0 + 2026.1-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent @@ -32,7 +32,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-2026.0 + ea From 3fac1551f0dbf3b606a6123b5839941c53940d35 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Wed, 28 Jan 2026 11:16:01 +0000 Subject: [PATCH 344/353] Reverting back to bom version 2026.0-SNAPSHOT --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index b4792efbe..88a01719d 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -41,7 +41,7 @@ net.openhft chronicle-bom - 2026.0 + 2026.0-SNAPSHOT pom import From 91c2b9ebc2db1680300991abbbbbe23e03949b0c Mon Sep 17 00:00:00 2001 From: james-mcsherry <164900221+james-mcsherry@users.noreply.github.com> Date: Wed, 28 Jan 2026 13:48:56 +0000 Subject: [PATCH 345/353] 2026.staging (#194) Rolled java-parent-pom to 2026.0 --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 7e54615b0..76bb65447 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -33,7 +33,7 @@ net.openhft third-party-bom - 2026.0-SNAPSHOT + 2026.0 pom import diff --git a/affinity/pom.xml b/affinity/pom.xml index 88a01719d..587a7db0b 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -34,7 +34,7 @@ net.openhft third-party-bom - 2026.0-SNAPSHOT + 2026.0 pom import From c89c58b6c0fca4a802f8ae208660fb34c93db9fb Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Wed, 28 Jan 2026 20:04:53 +0000 Subject: [PATCH 346/353] Updating to bom version 2026.1 --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index 587a7db0b..8f9fb8d79 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -41,7 +41,7 @@ net.openhft chronicle-bom - 2026.0-SNAPSHOT + 2026.1 pom import From 82d820ea460a86a1cf3a925c7972fed3e8e8ccbd Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Wed, 28 Jan 2026 20:05:16 +0000 Subject: [PATCH 347/353] [maven-release-plugin] prepare release Java-Thread-Affinity-2026.1 --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 76bb65447..8cee439b7 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -16,7 +16,7 @@ affinity-test - 2026.1-SNAPSHOT + 2026.1 bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -195,7 +195,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-2026.1 scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git diff --git a/affinity/pom.xml b/affinity/pom.xml index 8f9fb8d79..1fc290127 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -16,7 +16,7 @@ affinity - 2026.1-SNAPSHOT + 2026.1 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -243,7 +243,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-2026.1 diff --git a/pom.xml b/pom.xml index 2989b50c0..be028b4c5 100644 --- a/pom.xml +++ b/pom.xml @@ -16,7 +16,7 @@ Java-Thread-Affinity - 2026.1-SNAPSHOT + 2026.1 pom OpenHFT/Java-Thread-Affinity Parent @@ -32,7 +32,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-2026.1 From 2b016984c148a97267a8eea903d56f1eeb8c33ca Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Wed, 28 Jan 2026 20:05:19 +0000 Subject: [PATCH 348/353] [maven-release-plugin] prepare for next development iteration --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 8cee439b7..cbe59f27e 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -16,7 +16,7 @@ affinity-test - 2026.1 + 2026.2-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -195,7 +195,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-2026.1 + ea scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git diff --git a/affinity/pom.xml b/affinity/pom.xml index 1fc290127..f56ea9043 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -16,7 +16,7 @@ affinity - 2026.1 + 2026.2-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity @@ -243,7 +243,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-2026.1 + ea diff --git a/pom.xml b/pom.xml index be028b4c5..3a35c1b1a 100644 --- a/pom.xml +++ b/pom.xml @@ -16,7 +16,7 @@ Java-Thread-Affinity - 2026.1 + 2026.2-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent @@ -32,7 +32,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-2026.1 + ea From b1772d78a20f5d8f03eb0ad6b9d2e4f0ab2f160d Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Wed, 28 Jan 2026 20:05:36 +0000 Subject: [PATCH 349/353] Reverting back to bom version 2026.0-SNAPSHOT --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index f56ea9043..66e0d8dbd 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -41,7 +41,7 @@ net.openhft chronicle-bom - 2026.1 + 2026.0-SNAPSHOT pom import From d1df717bd2f0a8ecbf443e72948ccba2e7ef2f47 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Wed, 28 Jan 2026 22:23:42 +0000 Subject: [PATCH 350/353] Updating to bom version 2026.2 --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index 66e0d8dbd..b0e7e2224 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -41,7 +41,7 @@ net.openhft chronicle-bom - 2026.0-SNAPSHOT + 2026.2 pom import From 1c87c6431c2de38fb360db8f5975f7927acb8d05 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Wed, 28 Jan 2026 22:24:07 +0000 Subject: [PATCH 351/353] [maven-release-plugin] prepare release Java-Thread-Affinity-2026.2 --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index cbe59f27e..6fe1e720c 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -16,7 +16,7 @@ affinity-test - 2026.2-SNAPSHOT + 2026.2 bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -195,7 +195,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-2026.2 scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git diff --git a/affinity/pom.xml b/affinity/pom.xml index b0e7e2224..13884d4ac 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -16,7 +16,7 @@ affinity - 2026.2-SNAPSHOT + 2026.2 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -243,7 +243,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-2026.2 diff --git a/pom.xml b/pom.xml index 3a35c1b1a..8f8a1b1af 100644 --- a/pom.xml +++ b/pom.xml @@ -16,7 +16,7 @@ Java-Thread-Affinity - 2026.2-SNAPSHOT + 2026.2 pom OpenHFT/Java-Thread-Affinity Parent @@ -32,7 +32,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-2026.2 From 1daa446e90c02478cb887bb4536f43ee295afa98 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Wed, 28 Jan 2026 22:24:10 +0000 Subject: [PATCH 352/353] [maven-release-plugin] prepare for next development iteration --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 6fe1e720c..3ce950e34 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -16,7 +16,7 @@ affinity-test - 2026.2 + 2026.3-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -195,7 +195,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-2026.2 + ea scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git diff --git a/affinity/pom.xml b/affinity/pom.xml index 13884d4ac..b0d40e616 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -16,7 +16,7 @@ affinity - 2026.2 + 2026.3-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity @@ -243,7 +243,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-2026.2 + ea diff --git a/pom.xml b/pom.xml index 8f8a1b1af..f88f45845 100644 --- a/pom.xml +++ b/pom.xml @@ -16,7 +16,7 @@ Java-Thread-Affinity - 2026.2 + 2026.3-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent @@ -32,7 +32,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-2026.2 + ea From 9aff40476109cf30e22267b4a112d966ebde4e86 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Wed, 28 Jan 2026 22:24:27 +0000 Subject: [PATCH 353/353] Reverting back to bom version 2026.0-SNAPSHOT --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index b0d40e616..33f352b16 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -41,7 +41,7 @@ net.openhft chronicle-bom - 2026.2 + 2026.0-SNAPSHOT pom import