[bootlin/training-materials updates] master: preempt-rt: Add tweaks to the lab3 program (b3af57a3)

Maxime Chevallier maxime.chevallier at bootlin.com
Wed Jan 18 18:52:05 CET 2023


Repository : https://github.com/bootlin/training-materials
On branch  : master
Link       : https://github.com/bootlin/training-materials/commit/b3af57a3fb924fa917151a42c1db7ce74d1df217

>---------------------------------------------------------------

commit b3af57a3fb924fa917151a42c1db7ce74d1df217
Author: Maxime Chevallier <maxime.chevallier at bootlin.com>
Date:   Wed Jan 18 18:27:39 2023 +0100

    preempt-rt: Add tweaks to the lab3 program
    
    Signed-off-by: Maxime Chevallier <maxime.chevallier at bootlin.com>


>---------------------------------------------------------------

b3af57a3fb924fa917151a42c1db7ce74d1df217
 lab-data/preempt-rt/lab3/crc/Makefile |   4 ----
 lab-data/preempt-rt/lab3/crc/crc_test | Bin 25632 -> 0 bytes
 lab-data/preempt-rt/lab3/crc_test.c   |  38 +++++++++++++++++-----------------
 3 files changed, 19 insertions(+), 23 deletions(-)

diff --git a/lab-data/preempt-rt/lab3/crc/Makefile b/lab-data/preempt-rt/lab3/crc/Makefile
deleted file mode 100644
index 447de688..00000000
--- a/lab-data/preempt-rt/lab3/crc/Makefile
+++ /dev/null
@@ -1,4 +0,0 @@
-CC=${CROSS_COMPILE}gcc
-
-crc_test: crc_test.c
-	${CC} $< -o $@
diff --git a/lab-data/preempt-rt/lab3/crc/crc_test b/lab-data/preempt-rt/lab3/crc/crc_test
deleted file mode 100755
index 7ed07c39..00000000
Binary files a/lab-data/preempt-rt/lab3/crc/crc_test and /dev/null differ
diff --git a/lab-data/preempt-rt/lab3/crc_test.c b/lab-data/preempt-rt/lab3/crc_test.c
index d865170d..6a9ac16a 100644
--- a/lab-data/preempt-rt/lab3/crc_test.c
+++ b/lab-data/preempt-rt/lab3/crc_test.c
@@ -1,3 +1,4 @@
+#include <malloc.h>
 #include <time.h>
 #include <fcntl.h>
 #include <stdio.h>
@@ -7,11 +8,10 @@
 #include <unistd.h>
 #include <stdbool.h>
 #include <inttypes.h>
+#include <sys/mman.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 
-#include <malloc.h>
-#include <sys/mman.h>
 
 #define DATA_SIZE	(16 * 1024 * 1024)
 
@@ -52,16 +52,7 @@ static uint32_t crc32(const void *data, size_t n_bytes)
 }
 
 void init_rt() {
-	char *buff;
-
-	mlockall(MCL_CURRENT | MCL_FUTURE);
-	mallopt(M_TRIM_THRESHOLD, -1);
-	mallopt(M_MMAP_MAX, 0);
-
-	buff= malloc(2 * DATA_SIZE);
-	memset(buff, 0, 2 * DATA_SIZE);
-	free(buff);
-
+	/*  Perform your init steps here... */
 }
 
 int main(int argc, char **argv)
@@ -76,28 +67,37 @@ int main(int argc, char **argv)
 
 	init_crc_table();
 
-	//init_rt();
+	/* Perform some initialisation steps to make sure we can safely run
+	 * without much interferences
+	 */
+	init_rt();
 
 	data = malloc(DATA_SIZE);
-	while (1) {
+	if (!data) {
+		fprintf(stderr, "Failed to allocate %d bytes\n", DATA_SIZE);
+		return EXIT_FAILURE;
+	}
+
 
+	while (1) {
 
 		clock_gettime(CLOCK_MONOTONIC, &start);
 		start_nano = timespec_to_nano(&start);
 
-		if (!data) {
-			fprintf(stderr, "Failed to allocate %d bytes\n", DATA_SIZE);
-			return EXIT_FAILURE;
-		}
-
+		/* Beginning of critical section */
 		memset(data, i++, DATA_SIZE);
 		crc = crc32(data, DATA_SIZE);
+		/* End of critical section */
 
 		clock_gettime(CLOCK_MONOTONIC, &end);
 		end_nano = timespec_to_nano(&end);
 
 
 		printf("Computed crc 0x%" PRIx32 " in %" PRIu64 " nano\n", crc, end_nano - start_nano);
+
+		/* Sleeping here as an example, but we could just wait for any
+		 * kind of external event
+		 */
 		sleep(1);
 	}
 	free(data);




More information about the training-materials-updates mailing list