You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2019/02/28 19:06:24 UTC

[activemq-artemis-native] branch master updated: ARTEMIS-1977 Adding comments and stuff

This is an automated email from the ASF dual-hosted git repository.

clebertsuconic pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/activemq-artemis-native.git


The following commit(s) were added to refs/heads/master by this push:
     new 6d47689  ARTEMIS-1977 Adding comments and stuff
6d47689 is described below

commit 6d476899836b0d3f89dd3eddf201079228b3fcc3
Author: Clebert Suconic <cl...@apache.org>
AuthorDate: Thu Feb 28 14:04:10 2019 -0500

    ARTEMIS-1977 Adding comments and stuff
---
 scripts/64test.sh                                  |  2 +-
 scripts/compile-using-docker.sh                    |  3 ++-
 ...activemq_artemis_nativo_jlibaio_LibaioContext.c | 25 ++++++++++++++++------
 3 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/scripts/64test.sh b/scripts/64test.sh
index 4106d5b..25b84f9 100755
--- a/scripts/64test.sh
+++ b/scripts/64test.sh
@@ -24,4 +24,4 @@ docker build -f docker-build/Dockerfile-centos -t artemis-native-builder .
 docker run -it --rm -v $PWD/bin:/work/bin -v $HOME/.m2/repository/:/root/.m2/repository artemis-native-builder ./mvnw test
 
 # you could use it this way
-#docker run -it --rm -v $PWD/bin:/work/bin -v $HOME/.m2/repository/:/root/.m2/repository artemis-native-builder bash
+#docker build -f docker-build/Dockerfile-centos -t artemis-native-builder . && docker run -it --rm -v $PWD/bin:/work/bin -v $HOME/.m2/repository/:/root/.m2/repository artemis-native-builder bash
diff --git a/scripts/compile-using-docker.sh b/scripts/compile-using-docker.sh
index 9d24fca..d19494e 100755
--- a/scripts/compile-using-docker.sh
+++ b/scripts/compile-using-docker.sh
@@ -15,12 +15,13 @@
 # specific language governing permissions and limitations
 # under the License.
 
+rm -rf ./bin/*so
 docker build -f docker-build/Dockerfile-centos -t artemis-native-builder . 
 docker run -it --rm -v $PWD/bin:/work/bin artemis-native-builder "$@"
 chown -Rv $USER:$GID ./bin
 
 # Note: You may need to authorize docker to map folder at your folder structure
-#docker run -it --rm -v $PWD/bin:/work/bin artemis-native-builder bash
+#docker build -f docker-build/Dockerfile-centos -t artemis-native-builder . && docker run -it --rm -v $PWD/bin:/work/bin artemis-native-builder bash
 
 
 ## 64 bits build
diff --git a/src/main/c/org_apache_activemq_artemis_nativo_jlibaio_LibaioContext.c b/src/main/c/org_apache_activemq_artemis_nativo_jlibaio_LibaioContext.c
index 768e62a..8130139 100644
--- a/src/main/c/org_apache_activemq_artemis_nativo_jlibaio_LibaioContext.c
+++ b/src/main/c/org_apache_activemq_artemis_nativo_jlibaio_LibaioContext.c
@@ -63,12 +63,17 @@ struct io_control {
 };
 
 //These should be used to check if the user-space io_getevents is supported:
-//Linux ABI for the ring buffer: https://elixir.bootlin.com/linux/latest/source/fs/aio.c#L54
-//aio_read_events_ring: https://elixir.bootlin.com/linux/latest/source/fs/aio.c#L1148
+//Linux ABI for the ring buffer: https://elixir.bootlin.com/linux/v4.20.13/source/fs/aio.c#L54
+//aio_read_events_ring: https://elixir.bootlin.com/linux/v4.20.13/source/fs/aio.c#L1148
+
+// NOTE: if the kernel ever updates the structure, the RING-MAGIC will change and the code will switch back to normal IO calls
 #define AIO_RING_MAGIC	0xa10a10a1
 #define AIO_RING_INCOMPAT_FEATURES	0
 
 
+/** There is no defined aio_ring anywhere in an include,
+    This is an implementation detail, that is a binary contract.
+    it is safe to use the feature though. */
 struct aio_ring {
 	unsigned	id;	/* kernel internal index number */
 	unsigned	nr;	/* number of io_events */
@@ -84,16 +89,20 @@ struct aio_ring {
 	struct io_event		io_events[0];
 }; /* 128 bytes + ring size */
 
+// Check if the implementation supports AIO_RING by checking this number directly.
 static inline int has_usable_ring(struct aio_ring *ring) {
     return ring->magic == AIO_RING_MAGIC && ring->incompat_features == AIO_RING_INCOMPAT_FEATURES;
 }
 
+// Newer versions of the kernel (newer here being a relative word, a couple years already at the time
+// I am writing this), will have io_context_t as an opaque type, and the real type being the aio_ring.
 static inline struct aio_ring* to_aio_ring(io_context_t aio_ctx) {
     return (struct aio_ring*) aio_ctx;
 }
 
 //It implements a user space batch read io events implementation that attempts to read io avoiding any sys calls
-static int artemis_io_getevents(io_context_t aio_ctx, long min_nr, long max,
+// This implementation will look at the internal structure (aio_ring) and move along the memory result
+static int ringio_get_events(io_context_t aio_ctx, long min_nr, long max,
                                                        struct io_event *events, struct timespec *timeout) {
     struct aio_ring *ring = to_aio_ring(aio_ctx);
     //checks if it could be completed in user space, saving a sys call
@@ -138,6 +147,10 @@ static int artemis_io_getevents(io_context_t aio_ctx, long min_nr, long max,
             #endif
             return available_nr;
         }
+    } else {
+        #ifdef DEBUG
+            fprintf(stdout, "The kernel is not supoprting the ring buffer any longer\n");
+        #endif
     }
     int sys_call_events = io_getevents(aio_ctx, min_nr, max, events, timeout);
     #ifdef DEBUG
@@ -616,7 +629,7 @@ JNIEXPORT void JNICALL Java_org_apache_activemq_artemis_nativo_jlibaio_LibaioCon
     pthread_mutex_unlock(&(theControl->pollLock));
 
     // To return any pending IOCBs
-    int result = artemis_io_getevents(theControl->ioContext, 0, 1, theControl->events, 0);
+    int result = ringio_get_events(theControl->ioContext, 0, 1, theControl->events, 0);
     for (i = 0; i < result; i++) {
         struct io_event * event = &(theControl->events[i]);
         struct iocb * iocbp = event->obj;
@@ -738,7 +751,7 @@ JNIEXPORT void JNICALL Java_org_apache_activemq_artemis_nativo_jlibaio_LibaioCon
 
     while (running) {
 
-        int result = artemis_io_getevents(theControl->ioContext, 1, max, theControl->events, 0);
+        int result = ringio_get_events(theControl->ioContext, 1, max, theControl->events, 0);
 
         if (result == -EINTR)
         {
@@ -829,7 +842,7 @@ JNIEXPORT jint JNICALL Java_org_apache_activemq_artemis_nativo_jlibaio_LibaioCon
     }
 
 
-    int result = artemis_io_getevents(theControl->ioContext, min, max, theControl->events, 0);
+    int result = ringio_get_events(theControl->ioContext, min, max, theControl->events, 0);
     int retVal = result;
 
     for (i = 0; i < result; i++) {