Skip to contentSkip to conversation

lmbench: fix/clean-up the build for lmbench

PATCH In review [email protected] 4 participants 16 messages Oct 15, 2019 – Feb 11, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lmbench: fix/clean-up the build for lmbench

From: Marek Bykowski <[email protected]>

Fix/clean up a couple of things:
- if lmbench doesn't use a return from a function attributed to warn_unused_result supress it
- fix buffer overflow
- define feature_test_macro __USE_GNU compiling in sched_{get,set}affinity() used in one of the lmbench binaries

---
 .../0001-lmbench-clean-up-the-build.patch     | 434 ++++++++++++++++++
 .../lmbench/lmbench_3.0-a9.bb                 |   1 +
 2 files changed, 435 insertions(+)
 create mode 100644 meta-oe/recipes-benchmark/lmbench/lmbench-3.0-a9/0001-lmbench-clean-up-the-build.patch
meta-oe/recipes-benchmark/lmbench/lmbench-3.0-a9/0001-lmbench-clean-up-the-build.patch new file +434 -0
new file mode 100644
index 000000000..476b3711a
@@ -0,0 +1,434 @@
+From 78b3d1b51ffd4830869cd1db01ce56a279b1c048 Mon Sep 17 00:00:00 2001
+From: Marek Bykowski <[email protected]>
+Date: Tue, 15 Oct 2019 05:30:00 -0500
+Subject: [PATCH] lmbench: clean-up the build
+
+Fix/clean up a coule of things:
+- if lmbench doesn't use the return from a function attributed to warn_unused_result
+  supress it
+- fix buffer overflow
+- define feature_test_macro __USE_GNU compiling in sched_{get,set}affinity()
+
+Signed-off-by: Marek Bykowski <[email protected]>
+---
+ src/bw_tcp.c           |  2 +-
+ src/bw_unix.c          |  4 ++--
+ src/hello.c            |  2 +-
+ src/lat_connect.c      |  2 +-
+ src/lat_fcntl.c        |  4 ++--
+ src/lat_fs.c           |  2 +-
+ src/lat_http.c         |  6 +++---
+ src/lat_proc.c         |  2 +-
+ src/lat_select.c       |  2 +-
+ src/lat_tcp.c          |  8 ++++----
+ src/lat_unix.c         |  2 +-
+ src/lat_unix_connect.c |  4 ++--
+ src/lib_sched.c        |  7 +++++--
+ src/lib_timing.c       | 18 +++++++++---------
+ src/lmhttp.c           | 26 +++++++++++++++++---------
+ src/memsize.c          |  4 ++--
+ 16 files changed, 53 insertions(+), 42 deletions(-)
+
+diff --git a/src/bw_tcp.c b/src/bw_tcp.c
+index cc27098..bf76fac 100644
+--- a/src/bw_tcp.c
++++ b/src/bw_tcp.c
+@@ -60,7 +60,7 @@ main(int ac, char **av)
+ 		{
+ 			int	conn;
+ 			conn = tcp_connect(optarg, TCP_DATA, SOCKOPT_NONE);
+-			write(conn, "0", 1);
++			(void) !write(conn, "0", 1);
+ 			exit(0);
+ 		}
+ 		case 'm':
+diff --git a/src/bw_unix.c b/src/bw_unix.c
+index ad71157..493db7c 100644
+--- a/src/bw_unix.c
++++ b/src/bw_unix.c
+@@ -97,7 +97,7 @@ reader(iter_t iterations, void* cookie)
+ 	size_t	todo = state->bytes;
+ 
+ 	while (iterations-- > 0) {
+-		write(state->control[1], &todo, sizeof(todo));
++		(void) !write(state->control[1], &todo, sizeof(todo));
+ 		for (done = 0; done < todo; done += n) {
+ 			if ((n = read(state->pipes[0], state->buf, state->xfer)) <= 0) {
+ 				/* error! */
+@@ -115,7 +115,7 @@ writer(int controlfd, int writefd, char* buf, void* cookie)
+ 	struct _state* state = (struct _state*)cookie;
+ 
+ 	for ( ;; ) {
+-		read(controlfd, &todo, sizeof(todo));
++		(void) !read(controlfd, &todo, sizeof(todo));
+ 		for (done = 0; done < todo; done += n) {
+ #ifdef TOUCH
+ 			touch(buf, XFERSIZE);
+diff --git a/src/hello.c b/src/hello.c
+index 15a2493..0f7f237 100644
+--- a/src/hello.c
++++ b/src/hello.c
+@@ -3,6 +3,6 @@
+ int
+ main()
+ {
+-	write(1, "Hello world\n", 12);
++	(void) !write(1, "Hello world\n", 12);
+ 	return (0);
+ }
+diff --git a/src/lat_connect.c b/src/lat_connect.c
+index 4e5538e..2e08731 100644
+--- a/src/lat_connect.c
++++ b/src/lat_connect.c
+@@ -52,7 +52,7 @@ main(int ac, char **av)
+ 			int sock = tcp_connect(av[optind],
+ 					       TCP_CONNECT,
+ 					       SOCKOPT_NONE);
+-			write(sock, "0", 1);
++			(void) !write(sock, "0", 1);
+ 			close(sock);
+ 			exit(0);
+ 		}
+diff --git a/src/lat_fcntl.c b/src/lat_fcntl.c
+index 01847a8..3b9fd65 100644
+--- a/src/lat_fcntl.c
++++ b/src/lat_fcntl.c
+@@ -120,8 +120,8 @@ initialize(iter_t iterations, void* cookie)
+ 	}
+ 	unlink(state->filename1);
+ 	unlink(state->filename2);
+-	write(state->fd1, buf, sizeof(buf));
+-	write(state->fd2, buf, sizeof(buf));
++	(void) !write(state->fd1, buf, sizeof(buf));
++	(void) !write(state->fd2, buf, sizeof(buf));
+ 	lock.l_type = F_WRLCK;
+ 	lock.l_whence = 0;
+ 	lock.l_start = 0;
+diff --git a/src/lat_fs.c b/src/lat_fs.c
+index 003a4ea..14efa25 100644
+--- a/src/lat_fs.c
++++ b/src/lat_fs.c
+@@ -117,7 +117,7 @@ mkfile(char *name, size_t size)
+ 
+ 	while (size > 0) {
+ 		chunk = ((size > (128*1024)) ? (128*1024) : size);
+-		write(fd, buf, chunk);
++		(void) !write(fd, buf, chunk);
+ 		size -= chunk;
+ 	}
+ 	close(fd);
+diff --git a/src/lat_http.c b/src/lat_http.c
+index 28d04f7..6ccc88e 100644
+--- a/src/lat_http.c
++++ b/src/lat_http.c
+@@ -29,11 +29,11 @@ http(char *server, char *file, int prog)
+ 	if (debug) {
+ 		printf("%s", buf);
+ 	}
+-	write(sock, buf, strlen(buf));
++	(void) !write(sock, buf, strlen(buf));
+ 	while ((n = read(sock, buf, XFERSIZE)) > 0) {
+ 		b += n;
+ 		if (echo) {
+-			write(1, buf, n);
++			(void) !write(1, buf, n);
+ 		}
+ 	}
+ 	close(sock);
+@@ -49,7 +49,7 @@ killhttp(char *server, int prog)
+ 	int     sock;
+ 
+ 	sock = tcp_connect(server, prog, SOCKOPT_REUSE);
+-	write(sock, "EXIT", 4);
++	(void) !write(sock, "EXIT", 4);
+ 	close(sock);
+ }
+ 
+diff --git a/src/lat_proc.c b/src/lat_proc.c
+index 6142661..e368956 100644
+--- a/src/lat_proc.c
++++ b/src/lat_proc.c
+@@ -111,7 +111,7 @@ do_shell(iter_t iterations, void* cookie)
+ 		case 0:	/* child */
+ 			handle_scheduler(benchmp_childid(), 1, 1);
+ 			close(1);
+-			execlp("/bin/sh", "sh", "-c", PROG, 0);
++			execlp("/bin/sh", "sh", "-c", PROG, (char *)0);
+ 			exit(1);
+ 
+ 		default:
+diff --git a/src/lat_select.c b/src/lat_select.c
+index 5217878..662e0ac 100644
+--- a/src/lat_select.c
++++ b/src/lat_select.c
+@@ -131,7 +131,7 @@ server(void* cookie)
+ 		/* child server process */
+ 		while (pid == getppid()) {
+ 			int newsock = tcp_accept(state->sock, SOCKOPT_NONE);
+-			read(newsock, &state->fid, 1);
++			(void) !read(newsock, &state->fid, 1);
+ 			close(newsock);
+ 		}
+ 		exit(0);
+diff --git a/src/lat_tcp.c b/src/lat_tcp.c
+index 6a11996..aad56b3 100644
+--- a/src/lat_tcp.c
++++ b/src/lat_tcp.c
+@@ -104,7 +104,7 @@ init(iter_t iterations, void* cookie)
+ 		exit(1);
+ 	}
+ 
+-	write(state->sock, &msize, sizeof(int));
++	(void) !write(state->sock, &msize, sizeof(int));
+ }
+ 
+ void
+@@ -125,8 +125,8 @@ doclient(iter_t iterations, void* cookie)
+ 	int 	sock   = state->sock;
+ 
+ 	while (iterations-- > 0) {
+-		write(sock, state->buf, state->msize);
+-		read(sock, state->buf, state->msize);
++		(void) !write(sock, state->buf, state->msize);
++		(void) !read(sock, state->buf, state->msize);
+ 	}
+ }
+ 
+@@ -169,7 +169,7 @@ doserver(int sock)
+ 			exit(4);
+ 		}
+ 		for (n = 0; read(sock, buf, msize) > 0; n++) {
+-			write(sock, buf, msize);
++			(void) !write(sock, buf, msize);
+ 		}
+ 		free(buf);
+ 	} else {
+diff --git a/src/lat_unix.c b/src/lat_unix.c
+index 43ad6a3..d7ed2f3 100644
+--- a/src/lat_unix.c
++++ b/src/lat_unix.c
+@@ -93,7 +93,7 @@ initialize(iter_t iterations, void* cookie)
+ 	/* Child sits and ping-pongs packets back to parent */
+ 	signal(SIGTERM, exit);
+ 	while (read(pState->sv[0], pState->buf, pState->msize) == pState->msize) {
+-		write(pState->sv[0], pState->buf, pState->msize);
++		(void) !write(pState->sv[0], pState->buf, pState->msize);
+ 	}
+ 	exit(0);
+ }
+diff --git a/src/lat_unix_connect.c b/src/lat_unix_connect.c
+index a66b256..d21747c 100644
+--- a/src/lat_unix_connect.c
++++ b/src/lat_unix_connect.c
+@@ -47,7 +47,7 @@ int main(int ac, char **av)
+ 		}
+ 		if (!strcmp(av[1], "-S")) {
+ 			int sock = unix_connect(CONNAME);
+-			write(sock, "0", 1);
++			(void) !write(sock, "0", 1);
+ 			close(sock);
+ 			exit(0);
+ 		}
+@@ -92,7 +92,7 @@ void server_main(void)
+ 	for (;;) {
+ 		newsock = unix_accept(sock);
+ 		c = 0;
+-		read(newsock, &c, 1);
++		(void) !read(newsock, &c, 1);
+ 		if (c && c == '0') {
+ 			unix_done(sock, CONNAME);
+ 			exit(0);
+diff --git a/src/lib_sched.c b/src/lib_sched.c
+index fc5f82d..635685f 100644
+--- a/src/lib_sched.c
++++ b/src/lib_sched.c
+@@ -22,6 +22,7 @@
+ #endif
+ 
+ #if defined(HAVE_SCHED_SETAFFINITY)
++#define __USE_GNU
+ #include <sched.h>
+ #endif
+ 
+@@ -205,7 +206,8 @@ sched_pin(int cpu)
+ 		sz = 1 + (2 * sched_ncpus()) / (8 * sizeof(unsigned long));
+ 		mask = (unsigned long*)malloc(sz * sizeof(unsigned long));
+ 		cpumask = (unsigned long*)malloc(sz * sizeof(unsigned long));
+-		retval = sched_getaffinity(0, sz * sizeof(unsigned long), cpumask);
++		retval = sched_getaffinity(0, sz * sizeof(unsigned long),
++					(cpu_set_t *) cpumask);
+ 		if (retval < 0) perror("sched_getaffinity:");
+ 		if (retval < 0) return retval;
+ 
+@@ -229,7 +231,8 @@ sched_pin(int cpu)
+ 			j++;
+ 		}
+ 	}
+-	retval = sched_setaffinity(0, sz * sizeof(unsigned long), mask);
++	retval = sched_setaffinity(0, sz * sizeof(unsigned long),
++			(const cpu_set_t *) mask);
+ 	if (retval < 0) perror("sched_setaffinity:");
+ #ifdef _DEBUG
+ 	fprintf(stderr, "sched_pin(%d): pid=%d, returning %d\n", cpu, (int)getpid(), retval);
+diff --git a/src/lib_timing.c b/src/lib_timing.c
+index 714f0da..db84e8f 100644
+--- a/src/lib_timing.c
++++ b/src/lib_timing.c
+@@ -398,7 +398,7 @@ benchmp_parent(	int response,
+ 	}
+ 
+ 	/* send 'start' signal */
+-	write(start_signal, signals, parallel * sizeof(char));
++	(void) !write(start_signal, signals, parallel * sizeof(char));
+ 
+ 	/* Collect 'done' signals */
+ 	for (i = 0; i < parallel * sizeof(char); i += bytes_read) {
+@@ -443,7 +443,7 @@ benchmp_parent(	int response,
+ 		FD_ZERO(&fds_error);
+ 
+ 		/* tell one child to report its results */
+-		write(result_signal, buf, sizeof(char));
++		(void) !write(result_signal, buf, sizeof(char));
+ 
+ 		for (; n > 0; n -= bytes_read, buf += bytes_read) {
+ 			bytes_read = 0;
+@@ -484,7 +484,7 @@ benchmp_parent(	int response,
+ 	signal(SIGCHLD, SIG_DFL);
+ 	
+ 	/* send 'exit' signals */
+-	write(exit_signal, results, parallel * sizeof(char));
++	(void) !write(exit_signal, results, parallel * sizeof(char));
+ 
+ 	/* Compute median time; iterations is constant! */
+ 	set_results(merged_results);
+@@ -690,13 +690,13 @@ benchmp_interval(void* _state)
+ 		       NULL, &timeout);
+ 		if (FD_ISSET(state->start_signal, &fds)) {
+ 			state->state = timing_interval;
+-			read(state->start_signal, &c, sizeof(char));
++			(void) !read(state->start_signal, &c, sizeof(char));
+ 			iterations = state->iterations;
+ 		}
+ 		if (state->need_warmup) {
+ 			state->need_warmup = 0;
+ 			/* send 'ready' */
+-			write(state->response, &c, sizeof(char));
++			(void) !write(state->response, &c, sizeof(char));
+ 		}
+ 		break;
+ 	case timing_interval:
+@@ -726,7 +726,7 @@ benchmp_interval(void* _state)
+ 		state->iterations = iterations;
+ 		if (state->state == cooldown) {
+ 			/* send 'done' */
+-			write(state->response, (void*)&c, sizeof(char));
++			(void) !write(state->response, (void*)&c, sizeof(char));
+ 			iterations = state->iterations_batch;
+ 		}
+ 		break;
+@@ -741,8 +741,8 @@ benchmp_interval(void* _state)
+ 			 * the parent to tell us to send our results back.
+ 			 * From this point on, we will do no more "work".
+ 			 */
+-			read(state->result_signal, (void*)&c, sizeof(char));
+-			write(state->response, (void*)get_results(), state->r_size);
++			(void) !read(state->result_signal, (void*)&c, sizeof(char));
++			(void) !write(state->response, (void*)get_results(), state->r_size);
+ 			if (state->cleanup) {
+ 				if (benchmp_sigchld_handler == SIG_DFL)
+ 					signal(SIGCHLD, SIG_DFL);
+@@ -750,7 +750,7 @@ benchmp_interval(void* _state)
+ 			}
+ 
+ 			/* Now wait for signal to exit */
+-			read(state->exit_signal, (void*)&c, sizeof(char));
++			(void) !read(state->exit_signal, (void*)&c, sizeof(char));
+ 			exit(0);
+ 		}
+ 	};
+diff --git a/src/lmhttp.c b/src/lmhttp.c
+index 41d9949..080b462 100644
+--- a/src/lmhttp.c
++++ b/src/lmhttp.c
+@@ -277,26 +277,34 @@ void
+ dodir(char *name, int sock)
+ {
+ 	FILE	*p;
+-	char	buf[1024];
++	char	*buf;
+ 	char	path[1024];
++	size_t 	bytes;
+ 
+ 	if (dflg) printf("dodir(%s)\n", name);
++	/* figure out a buf size and allocate with malloc */
++	bytes = snprintf(buf, 0, "cd %s && ls -1a", name);
++	buf = (char*) malloc(bytes + 1);
+ 	sprintf(buf, "cd %s && ls -1a", name);
+ 	p = popen(buf, "r");
+ 	if (!p && dflg) printf("Couldn't popen %s\n", buf);
++	bytes = snprintf(buf, 0, "\
++<HTML><HEAD>\n<TITLE>Index of /%s</TITLE></HEAD><BODY><H1>Index of /%s</H1>\n",
++	    name, name);
++	buf = (char*) realloc(buf, bytes + 1);
+ 	sprintf(buf, "\
+ <HTML><HEAD>\n<TITLE>Index of /%s</TITLE></HEAD><BODY><H1>Index of /%s</H1>\n",
+ 	    name, name);
+-	write(sock, buf, strlen(buf));
++	(void) !write(sock, buf, strlen(buf));
+ 	while (fgets(buf, sizeof(buf), p)) {
+ 		buf[strlen(buf) - 1] = 0;
+ 		sprintf(path, "/%s/%s", name, buf);
+ 		if (dflg) printf("\t%s\n", path);
+-		write(sock, "<A HREF=\"", 9);
+-		write(sock, path, strlen(path));
+-		write(sock, "\">", 2);
+-		write(sock, buf, strlen(buf));
+-		write(sock, "</A><BR>\n", 9);
++		(void) !write(sock, "<A HREF=\"", 9);
++		(void) !write(sock, path, strlen(path));
++		(void) !write(sock, "\">", 2);
++		(void) !write(sock, buf, strlen(buf));
++		(void) !write(sock, "</A><BR>\n", 9);
+ 	}
+ 	pclose(p);
+ }
+@@ -380,7 +388,7 @@ logit(int sock, char *name, int size)
+ 	len = sprintf(buf, "%u %u %s %u\n",
+ 	    *((unsigned int*)&sin.sin_addr), (unsigned int)time(0), name, size);
+ 	if (nbytes + len >= sizeof(logbuf)) {
+-		write(logfile, logbuf, nbytes);
++		(void) !write(logfile, logbuf, nbytes);
+ 		nbytes = 0;
+ 	}
+ 	bcopy(buf, &logbuf[nbytes], len);
+@@ -390,7 +398,7 @@ logit(int sock, char *name, int size)
+ void die()
+ {
+ 	if (nbytes) {
+-		write(logfile, logbuf, nbytes);
++		(void) !write(logfile, logbuf, nbytes);
+ 		nbytes = 0;
+ 	}
+ 	exit(1);
+diff --git a/src/memsize.c b/src/memsize.c
+index 82d7faf..35fff9d 100644
+--- a/src/memsize.c
++++ b/src/memsize.c
+@@ -111,7 +111,7 @@ timeit(char *where, size_t size)
+ 		clear_alarm();
+ 		if ((sum / n) > too_long || alarm_triggered) {
+ 			size = range - incr;
+-			fprintf(stderr, "Error! Memory testing timeout! Touch one page of memory needs more than %d (usecs)\n ", too_long);
++			fprintf(stderr, "Error! Memory testing timeout! Touch one page of memory needs more than %zu (usecs)\n ", too_long);
+ 			break;
+ 		}
+ 		for (s = s_prev; s <= range; s_prev = s, s *= 2)
+@@ -157,7 +157,7 @@ test_malloc(size_t size)
+ 		close(fid[0]);
+ 		p = malloc(size);
+ 		result = (p ? 1 : 0);
+-		write(fid[1], &result, sizeof(int));
++		(void) !write(fid[1], &result, sizeof(int));
+ 		close(fid[1]);
+ 		if (p) free(p);
+ 		exit(0);
meta-oe/recipes-benchmark/lmbench/lmbench_3.0-a9.bb +1 -0
index 8e6e803a8..88d67f602 100644
@@ -26,6 +26,7 @@ SRC_URI = "${SOURCEFORGE_MIRROR}/lmbench/lmbench-${PV}.tgz \
            file://0001-Check-for-musl-define-guard-before-redefining-sockle.patch \
            file://0002-build-Adjust-CFLAGS-LDFLAGS-to-append-values-passed-.patch \
            file://0001-src-Makefile-use-libdir-instead-of-hardcoded-lib.patch \
+           file://0001-lmbench-clean-up-the-build.patch \
            "
 SRC_URI[md5sum] = "b3351a3294db66a72e2864a199d37cbf"
 SRC_URI[sha256sum] = "cbd5777d15f44eab7666dcac418054c3c09df99826961a397d9acf43d8a2a551"
Signature · 1 line
2.21.0.896.g6a6c0f1
#1 lore raw
Quoted 11 lines · On Tue, Oct 15, 2019 at 02:13:41PM +0200, [email protected] wrote:

...
+--- a/src/lib_sched.c
++++ b/src/lib_sched.c
+@@ -22,6 +22,7 @@
+ #endif
+
+ #if defined(HAVE_SCHED_SETAFFINITY)
++#define __USE_GNU
+ #include <sched.h>
+ #endif
...

1. The correct macro is _GNU_SOURCE.

2. It must be defined before including any headers, otherwise it might have no effect or cause weird breakages.

cu
Adrian

Signature · 4 lines
       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed
author Reviewed-by Marcin Lapaj
#2 lore raw

Re: [meta-oe] [PATCHv2] lmbench: Fix/clean-up the build for lmbench

Fix/clean up a couple of things:
- if lmbench doesn't use a return from a function attributed to warn_unused_result suppress the warning/s
- fix buffer overflow
- define a feature_test_macro _GNU_SOURCE compiling in sched_{get,set}affinity() used in one of the binaries

---
Changelog v1->v2:
- remove __USE_GNU macro definition and define _GNU_SOURCE instead exactly as per Adrian's suggestion.

---
 ...h-Fix-clean-up-the-build-for-lmbench.patch | 433 ++++++++++++++++++
 .../lmbench/lmbench_3.0-a9.bb                 |   1 +
 2 files changed, 434 insertions(+)
 create mode 100644 meta-oe/recipes-benchmark/lmbench/lmbench-3.0-a9/0001-lmbench-Fix-clean-up-the-build-for-lmbench.patch
meta-oe/recipes-benchmark/lmbench/lmbench-3.0-a9/0001-lmbench-Fix-clean-up-the-build-for-lmbench.patch new file +433 -0
new file mode 100644
index 000000000..ee9b8ded2
@@ -0,0 +1,433 @@
+From 4a4e381fde224a8738d9de6412b432264a381d7e Mon Sep 17 00:00:00 2001
+From: Marek Bykowski <[email protected]>
+Date: Wed, 16 Oct 2019 06:34:16 -0500
+Subject: [PATCH] lmbench: Fix/clean-up the build for lmbench
+
+Fix/clean up a coule of things:
+- if lmbench doesn't use a return from a function attributed to warn_unused_result
+  supress the warning/s
+- fix buffer overflow
+- define feature_test_macro _GNU_SOURCE compiling in sched_{get,set}affinity()
+
+Signed-off-by: Marek Bykowski <[email protected]>
+Signed-off-by: Marcin Lapaj <[email protected]>
+---
+ src/bw_tcp.c           |  2 +-
+ src/bw_unix.c          |  4 ++--
+ src/hello.c            |  2 +-
+ src/lat_connect.c      |  2 +-
+ src/lat_fcntl.c        |  4 ++--
+ src/lat_fs.c           |  2 +-
+ src/lat_http.c         |  6 +++---
+ src/lat_proc.c         |  2 +-
+ src/lat_select.c       |  2 +-
+ src/lat_tcp.c          |  8 ++++----
+ src/lat_unix.c         |  2 +-
+ src/lat_unix_connect.c |  4 ++--
+ src/lib_sched.c        |  8 ++++++--
+ src/lib_timing.c       | 18 +++++++++---------
+ src/lmhttp.c           | 26 +++++++++++++++++---------
+ src/memsize.c          |  4 ++--
+ 16 files changed, 54 insertions(+), 42 deletions(-)
+
+diff --git a/src/bw_tcp.c b/src/bw_tcp.c
+index cc27098..bf76fac 100644
+--- a/src/bw_tcp.c
++++ b/src/bw_tcp.c
+@@ -60,7 +60,7 @@ main(int ac, char **av)
+ 		{
+ 			int	conn;
+ 			conn = tcp_connect(optarg, TCP_DATA, SOCKOPT_NONE);
+-			write(conn, "0", 1);
++			(void) !write(conn, "0", 1);
+ 			exit(0);
+ 		}
+ 		case 'm':
+diff --git a/src/bw_unix.c b/src/bw_unix.c
+index ad71157..493db7c 100644
+--- a/src/bw_unix.c
++++ b/src/bw_unix.c
+@@ -97,7 +97,7 @@ reader(iter_t iterations, void* cookie)
+ 	size_t	todo = state->bytes;
+ 
+ 	while (iterations-- > 0) {
+-		write(state->control[1], &todo, sizeof(todo));
++		(void) !write(state->control[1], &todo, sizeof(todo));
+ 		for (done = 0; done < todo; done += n) {
+ 			if ((n = read(state->pipes[0], state->buf, state->xfer)) <= 0) {
+ 				/* error! */
+@@ -115,7 +115,7 @@ writer(int controlfd, int writefd, char* buf, void* cookie)
+ 	struct _state* state = (struct _state*)cookie;
+ 
+ 	for ( ;; ) {
+-		read(controlfd, &todo, sizeof(todo));
++		(void) !read(controlfd, &todo, sizeof(todo));
+ 		for (done = 0; done < todo; done += n) {
+ #ifdef TOUCH
+ 			touch(buf, XFERSIZE);
+diff --git a/src/hello.c b/src/hello.c
+index 15a2493..0f7f237 100644
+--- a/src/hello.c
++++ b/src/hello.c
+@@ -3,6 +3,6 @@
+ int
+ main()
+ {
+-	write(1, "Hello world\n", 12);
++	(void) !write(1, "Hello world\n", 12);
+ 	return (0);
+ }
+diff --git a/src/lat_connect.c b/src/lat_connect.c
+index 4e5538e..2e08731 100644
+--- a/src/lat_connect.c
++++ b/src/lat_connect.c
+@@ -52,7 +52,7 @@ main(int ac, char **av)
+ 			int sock = tcp_connect(av[optind],
+ 					       TCP_CONNECT,
+ 					       SOCKOPT_NONE);
+-			write(sock, "0", 1);
++			(void) !write(sock, "0", 1);
+ 			close(sock);
+ 			exit(0);
+ 		}
+diff --git a/src/lat_fcntl.c b/src/lat_fcntl.c
+index 01847a8..3b9fd65 100644
+--- a/src/lat_fcntl.c
++++ b/src/lat_fcntl.c
+@@ -120,8 +120,8 @@ initialize(iter_t iterations, void* cookie)
+ 	}
+ 	unlink(state->filename1);
+ 	unlink(state->filename2);
+-	write(state->fd1, buf, sizeof(buf));
+-	write(state->fd2, buf, sizeof(buf));
++	(void) !write(state->fd1, buf, sizeof(buf));
++	(void) !write(state->fd2, buf, sizeof(buf));
+ 	lock.l_type = F_WRLCK;
+ 	lock.l_whence = 0;
+ 	lock.l_start = 0;
+diff --git a/src/lat_fs.c b/src/lat_fs.c
+index 003a4ea..14efa25 100644
+--- a/src/lat_fs.c
++++ b/src/lat_fs.c
+@@ -117,7 +117,7 @@ mkfile(char *name, size_t size)
+ 
+ 	while (size > 0) {
+ 		chunk = ((size > (128*1024)) ? (128*1024) : size);
+-		write(fd, buf, chunk);
++		(void) !write(fd, buf, chunk);
+ 		size -= chunk;
+ 	}
+ 	close(fd);
+diff --git a/src/lat_http.c b/src/lat_http.c
+index 28d04f7..6ccc88e 100644
+--- a/src/lat_http.c
++++ b/src/lat_http.c
+@@ -29,11 +29,11 @@ http(char *server, char *file, int prog)
+ 	if (debug) {
+ 		printf("%s", buf);
+ 	}
+-	write(sock, buf, strlen(buf));
++	(void) !write(sock, buf, strlen(buf));
+ 	while ((n = read(sock, buf, XFERSIZE)) > 0) {
+ 		b += n;
+ 		if (echo) {
+-			write(1, buf, n);
++			(void) !write(1, buf, n);
+ 		}
+ 	}
+ 	close(sock);
+@@ -49,7 +49,7 @@ killhttp(char *server, int prog)
+ 	int     sock;
+ 
+ 	sock = tcp_connect(server, prog, SOCKOPT_REUSE);
+-	write(sock, "EXIT", 4);
++	(void) !write(sock, "EXIT", 4);
+ 	close(sock);
+ }
+ 
+diff --git a/src/lat_proc.c b/src/lat_proc.c
+index 6142661..e368956 100644
+--- a/src/lat_proc.c
++++ b/src/lat_proc.c
+@@ -111,7 +111,7 @@ do_shell(iter_t iterations, void* cookie)
+ 		case 0:	/* child */
+ 			handle_scheduler(benchmp_childid(), 1, 1);
+ 			close(1);
+-			execlp("/bin/sh", "sh", "-c", PROG, 0);
++			execlp("/bin/sh", "sh", "-c", PROG, (char *)0);
+ 			exit(1);
+ 
+ 		default:
+diff --git a/src/lat_select.c b/src/lat_select.c
+index 5217878..662e0ac 100644
+--- a/src/lat_select.c
++++ b/src/lat_select.c
+@@ -131,7 +131,7 @@ server(void* cookie)
+ 		/* child server process */
+ 		while (pid == getppid()) {
+ 			int newsock = tcp_accept(state->sock, SOCKOPT_NONE);
+-			read(newsock, &state->fid, 1);
++			(void) !read(newsock, &state->fid, 1);
+ 			close(newsock);
+ 		}
+ 		exit(0);
+diff --git a/src/lat_tcp.c b/src/lat_tcp.c
+index 6a11996..aad56b3 100644
+--- a/src/lat_tcp.c
++++ b/src/lat_tcp.c
+@@ -104,7 +104,7 @@ init(iter_t iterations, void* cookie)
+ 		exit(1);
+ 	}
+ 
+-	write(state->sock, &msize, sizeof(int));
++	(void) !write(state->sock, &msize, sizeof(int));
+ }
+ 
+ void
+@@ -125,8 +125,8 @@ doclient(iter_t iterations, void* cookie)
+ 	int 	sock   = state->sock;
+ 
+ 	while (iterations-- > 0) {
+-		write(sock, state->buf, state->msize);
+-		read(sock, state->buf, state->msize);
++		(void) !write(sock, state->buf, state->msize);
++		(void) !read(sock, state->buf, state->msize);
+ 	}
+ }
+ 
+@@ -169,7 +169,7 @@ doserver(int sock)
+ 			exit(4);
+ 		}
+ 		for (n = 0; read(sock, buf, msize) > 0; n++) {
+-			write(sock, buf, msize);
++			(void) !write(sock, buf, msize);
+ 		}
+ 		free(buf);
+ 	} else {
+diff --git a/src/lat_unix.c b/src/lat_unix.c
+index 43ad6a3..d7ed2f3 100644
+--- a/src/lat_unix.c
++++ b/src/lat_unix.c
+@@ -93,7 +93,7 @@ initialize(iter_t iterations, void* cookie)
+ 	/* Child sits and ping-pongs packets back to parent */
+ 	signal(SIGTERM, exit);
+ 	while (read(pState->sv[0], pState->buf, pState->msize) == pState->msize) {
+-		write(pState->sv[0], pState->buf, pState->msize);
++		(void) !write(pState->sv[0], pState->buf, pState->msize);
+ 	}
+ 	exit(0);
+ }
+diff --git a/src/lat_unix_connect.c b/src/lat_unix_connect.c
+index a66b256..d21747c 100644
+--- a/src/lat_unix_connect.c
++++ b/src/lat_unix_connect.c
+@@ -47,7 +47,7 @@ int main(int ac, char **av)
+ 		}
+ 		if (!strcmp(av[1], "-S")) {
+ 			int sock = unix_connect(CONNAME);
+-			write(sock, "0", 1);
++			(void) !write(sock, "0", 1);
+ 			close(sock);
+ 			exit(0);
+ 		}
+@@ -92,7 +92,7 @@ void server_main(void)
+ 	for (;;) {
+ 		newsock = unix_accept(sock);
+ 		c = 0;
+-		read(newsock, &c, 1);
++		(void) !read(newsock, &c, 1);
+ 		if (c && c == '0') {
+ 			unix_done(sock, CONNAME);
+ 			exit(0);
+diff --git a/src/lib_sched.c b/src/lib_sched.c
+index fc5f82d..b284dbe 100644
+--- a/src/lib_sched.c
++++ b/src/lib_sched.c
+@@ -1,3 +1,5 @@
++#define _GNU_SOURCE
++
+ #include "bench.h"
+ 
+ /* #define _DEBUG */
+@@ -205,7 +207,8 @@ sched_pin(int cpu)
+ 		sz = 1 + (2 * sched_ncpus()) / (8 * sizeof(unsigned long));
+ 		mask = (unsigned long*)malloc(sz * sizeof(unsigned long));
+ 		cpumask = (unsigned long*)malloc(sz * sizeof(unsigned long));
+-		retval = sched_getaffinity(0, sz * sizeof(unsigned long), cpumask);
++		retval = sched_getaffinity(0, sz * sizeof(unsigned long),
++					(cpu_set_t *) cpumask);
+ 		if (retval < 0) perror("sched_getaffinity:");
+ 		if (retval < 0) return retval;
+ 
+@@ -229,7 +232,8 @@ sched_pin(int cpu)
+ 			j++;
+ 		}
+ 	}
+-	retval = sched_setaffinity(0, sz * sizeof(unsigned long), mask);
++	retval = sched_setaffinity(0, sz * sizeof(unsigned long),
++			(const cpu_set_t *) mask);
+ 	if (retval < 0) perror("sched_setaffinity:");
+ #ifdef _DEBUG
+ 	fprintf(stderr, "sched_pin(%d): pid=%d, returning %d\n", cpu, (int)getpid(), retval);
+diff --git a/src/lib_timing.c b/src/lib_timing.c
+index 714f0da..db84e8f 100644
+--- a/src/lib_timing.c
++++ b/src/lib_timing.c
+@@ -398,7 +398,7 @@ benchmp_parent(	int response,
+ 	}
+ 
+ 	/* send 'start' signal */
+-	write(start_signal, signals, parallel * sizeof(char));
++	(void) !write(start_signal, signals, parallel * sizeof(char));
+ 
+ 	/* Collect 'done' signals */
+ 	for (i = 0; i < parallel * sizeof(char); i += bytes_read) {
+@@ -443,7 +443,7 @@ benchmp_parent(	int response,
+ 		FD_ZERO(&fds_error);
+ 
+ 		/* tell one child to report its results */
+-		write(result_signal, buf, sizeof(char));
++		(void) !write(result_signal, buf, sizeof(char));
+ 
+ 		for (; n > 0; n -= bytes_read, buf += bytes_read) {
+ 			bytes_read = 0;
+@@ -484,7 +484,7 @@ benchmp_parent(	int response,
+ 	signal(SIGCHLD, SIG_DFL);
+ 	
+ 	/* send 'exit' signals */
+-	write(exit_signal, results, parallel * sizeof(char));
++	(void) !write(exit_signal, results, parallel * sizeof(char));
+ 
+ 	/* Compute median time; iterations is constant! */
+ 	set_results(merged_results);
+@@ -690,13 +690,13 @@ benchmp_interval(void* _state)
+ 		       NULL, &timeout);
+ 		if (FD_ISSET(state->start_signal, &fds)) {
+ 			state->state = timing_interval;
+-			read(state->start_signal, &c, sizeof(char));
++			(void) !read(state->start_signal, &c, sizeof(char));
+ 			iterations = state->iterations;
+ 		}
+ 		if (state->need_warmup) {
+ 			state->need_warmup = 0;
+ 			/* send 'ready' */
+-			write(state->response, &c, sizeof(char));
++			(void) !write(state->response, &c, sizeof(char));
+ 		}
+ 		break;
+ 	case timing_interval:
+@@ -726,7 +726,7 @@ benchmp_interval(void* _state)
+ 		state->iterations = iterations;
+ 		if (state->state == cooldown) {
+ 			/* send 'done' */
+-			write(state->response, (void*)&c, sizeof(char));
++			(void) !write(state->response, (void*)&c, sizeof(char));
+ 			iterations = state->iterations_batch;
+ 		}
+ 		break;
+@@ -741,8 +741,8 @@ benchmp_interval(void* _state)
+ 			 * the parent to tell us to send our results back.
+ 			 * From this point on, we will do no more "work".
+ 			 */
+-			read(state->result_signal, (void*)&c, sizeof(char));
+-			write(state->response, (void*)get_results(), state->r_size);
++			(void) !read(state->result_signal, (void*)&c, sizeof(char));
++			(void) !write(state->response, (void*)get_results(), state->r_size);
+ 			if (state->cleanup) {
+ 				if (benchmp_sigchld_handler == SIG_DFL)
+ 					signal(SIGCHLD, SIG_DFL);
+@@ -750,7 +750,7 @@ benchmp_interval(void* _state)
+ 			}
+ 
+ 			/* Now wait for signal to exit */
+-			read(state->exit_signal, (void*)&c, sizeof(char));
++			(void) !read(state->exit_signal, (void*)&c, sizeof(char));
+ 			exit(0);
+ 		}
+ 	};
+diff --git a/src/lmhttp.c b/src/lmhttp.c
+index 41d9949..080b462 100644
+--- a/src/lmhttp.c
++++ b/src/lmhttp.c
+@@ -277,26 +277,34 @@ void
+ dodir(char *name, int sock)
+ {
+ 	FILE	*p;
+-	char	buf[1024];
++	char	*buf;
+ 	char	path[1024];
++	size_t 	bytes;
+ 
+ 	if (dflg) printf("dodir(%s)\n", name);
++	/* figure out a buf size and allocate with malloc */
++	bytes = snprintf(buf, 0, "cd %s && ls -1a", name);
++	buf = (char*) malloc(bytes + 1);
+ 	sprintf(buf, "cd %s && ls -1a", name);
+ 	p = popen(buf, "r");
+ 	if (!p && dflg) printf("Couldn't popen %s\n", buf);
++	bytes = snprintf(buf, 0, "\
++<HTML><HEAD>\n<TITLE>Index of /%s</TITLE></HEAD><BODY><H1>Index of /%s</H1>\n",
++	    name, name);
++	buf = (char*) realloc(buf, bytes + 1);
+ 	sprintf(buf, "\
+ <HTML><HEAD>\n<TITLE>Index of /%s</TITLE></HEAD><BODY><H1>Index of /%s</H1>\n",
+ 	    name, name);
+-	write(sock, buf, strlen(buf));
++	(void) !write(sock, buf, strlen(buf));
+ 	while (fgets(buf, sizeof(buf), p)) {
+ 		buf[strlen(buf) - 1] = 0;
+ 		sprintf(path, "/%s/%s", name, buf);
+ 		if (dflg) printf("\t%s\n", path);
+-		write(sock, "<A HREF=\"", 9);
+-		write(sock, path, strlen(path));
+-		write(sock, "\">", 2);
+-		write(sock, buf, strlen(buf));
+-		write(sock, "</A><BR>\n", 9);
++		(void) !write(sock, "<A HREF=\"", 9);
++		(void) !write(sock, path, strlen(path));
++		(void) !write(sock, "\">", 2);
++		(void) !write(sock, buf, strlen(buf));
++		(void) !write(sock, "</A><BR>\n", 9);
+ 	}
+ 	pclose(p);
+ }
+@@ -380,7 +388,7 @@ logit(int sock, char *name, int size)
+ 	len = sprintf(buf, "%u %u %s %u\n",
+ 	    *((unsigned int*)&sin.sin_addr), (unsigned int)time(0), name, size);
+ 	if (nbytes + len >= sizeof(logbuf)) {
+-		write(logfile, logbuf, nbytes);
++		(void) !write(logfile, logbuf, nbytes);
+ 		nbytes = 0;
+ 	}
+ 	bcopy(buf, &logbuf[nbytes], len);
+@@ -390,7 +398,7 @@ logit(int sock, char *name, int size)
+ void die()
+ {
+ 	if (nbytes) {
+-		write(logfile, logbuf, nbytes);
++		(void) !write(logfile, logbuf, nbytes);
+ 		nbytes = 0;
+ 	}
+ 	exit(1);
+diff --git a/src/memsize.c b/src/memsize.c
+index 82d7faf..35fff9d 100644
+--- a/src/memsize.c
++++ b/src/memsize.c
+@@ -111,7 +111,7 @@ timeit(char *where, size_t size)
+ 		clear_alarm();
+ 		if ((sum / n) > too_long || alarm_triggered) {
+ 			size = range - incr;
+-			fprintf(stderr, "Error! Memory testing timeout! Touch one page of memory needs more than %d (usecs)\n ", too_long);
++			fprintf(stderr, "Error! Memory testing timeout! Touch one page of memory needs more than %zu (usecs)\n ", too_long);
+ 			break;
+ 		}
+ 		for (s = s_prev; s <= range; s_prev = s, s *= 2)
+@@ -157,7 +157,7 @@ test_malloc(size_t size)
+ 		close(fid[0]);
+ 		p = malloc(size);
+ 		result = (p ? 1 : 0);
+-		write(fid[1], &result, sizeof(int));
++		(void) !write(fid[1], &result, sizeof(int));
+ 		close(fid[1]);
+ 		if (p) free(p);
+ 		exit(0);
meta-oe/recipes-benchmark/lmbench/lmbench_3.0-a9.bb +1 -0
index 8e6e803a8..cc43c6bd5 100644
@@ -26,6 +26,7 @@ SRC_URI = "${SOURCEFORGE_MIRROR}/lmbench/lmbench-${PV}.tgz \
            file://0001-Check-for-musl-define-guard-before-redefining-sockle.patch \
            file://0002-build-Adjust-CFLAGS-LDFLAGS-to-append-values-passed-.patch \
            file://0001-src-Makefile-use-libdir-instead-of-hardcoded-lib.patch \
+           file://0001-lmbench-Fix-clean-up-the-build-for-lmbench.patch \
            "
 SRC_URI[md5sum] = "b3351a3294db66a72e2864a199d37cbf"
 SRC_URI[sha256sum] = "cbd5777d15f44eab7666dcac418054c3c09df99826961a397d9acf43d8a2a551"
Signature · 1 line
2.21.0.896.g6a6c0f1
#3 lore raw

Re: [meta-oe] [PATCHv2] lmbench: Fix/clean-up the build for lmbench

fails to compile
https://errors.yoctoproject.org/Errors/Details/273942/

Quoted 479 lines · Marek Bykowski

Fix/clean up a couple of things:
- if lmbench doesn't use a return from a function attributed to warn_unused_result suppress the warning/s
- fix buffer overflow
- define a feature_test_macro _GNU_SOURCE compiling in sched_{get,set}affinity() used in one of the binaries

---
Changelog v1->v2:
- remove __USE_GNU macro definition and define _GNU_SOURCE instead exactly as per Adrian's suggestion.

---
 ...h-Fix-clean-up-the-build-for-lmbench.patch | 433 ++++++++++++++++++
 .../lmbench/lmbench_3.0-a9.bb                 |   1 +
 2 files changed, 434 insertions(+)
 create mode 100644 meta-oe/recipes-benchmark/lmbench/lmbench-3.0-a9/0001-lmbench-Fix-clean-up-the-build-for-lmbench.patch
meta-oe/recipes-benchmark/lmbench/lmbench-3.0-a9/0001-lmbench-Fix-clean-up-the-build-for-lmbench.patch new file +433 -0
new file mode 100644
index 000000000..ee9b8ded2
@@ -0,0 +1,433 @@
+From 4a4e381fde224a8738d9de6412b432264a381d7e Mon Sep 17 00:00:00 2001
+From: Marek Bykowski <[email protected]>
+Date: Wed, 16 Oct 2019 06:34:16 -0500
+Subject: [PATCH] lmbench: Fix/clean-up the build for lmbench
+
+Fix/clean up a coule of things:
+- if lmbench doesn't use a return from a function attributed to warn_unused_result
+  supress the warning/s
+- fix buffer overflow
+- define feature_test_macro _GNU_SOURCE compiling in sched_{get,set}affinity()
+
+Signed-off-by: Marek Bykowski <[email protected]>
+Signed-off-by: Marcin Lapaj <[email protected]>
+---
+ src/bw_tcp.c           |  2 +-
+ src/bw_unix.c          |  4 ++--
+ src/hello.c            |  2 +-
+ src/lat_connect.c      |  2 +-
+ src/lat_fcntl.c        |  4 ++--
+ src/lat_fs.c           |  2 +-
+ src/lat_http.c         |  6 +++---
+ src/lat_proc.c         |  2 +-
+ src/lat_select.c       |  2 +-
+ src/lat_tcp.c          |  8 ++++----
+ src/lat_unix.c         |  2 +-
+ src/lat_unix_connect.c |  4 ++--
+ src/lib_sched.c        |  8 ++++++--
+ src/lib_timing.c       | 18 +++++++++---------
+ src/lmhttp.c           | 26 +++++++++++++++++---------
+ src/memsize.c          |  4 ++--
+ 16 files changed, 54 insertions(+), 42 deletions(-)
+
+diff --git a/src/bw_tcp.c b/src/bw_tcp.c
+index cc27098..bf76fac 100644
+--- a/src/bw_tcp.c
++++ b/src/bw_tcp.c
+@@ -60,7 +60,7 @@ main(int ac, char **av)
+               {
+                       int     conn;
+                       conn = tcp_connect(optarg, TCP_DATA, SOCKOPT_NONE);
+-                      write(conn, "0", 1);
++                      (void) !write(conn, "0", 1);
+                       exit(0);
+               }
+               case 'm':
+diff --git a/src/bw_unix.c b/src/bw_unix.c
+index ad71157..493db7c 100644
+--- a/src/bw_unix.c
++++ b/src/bw_unix.c
+@@ -97,7 +97,7 @@ reader(iter_t iterations, void* cookie)
+       size_t  todo = state->bytes;
+
+       while (iterations-- > 0) {
+-              write(state->control[1], &todo, sizeof(todo));
++              (void) !write(state->control[1], &todo, sizeof(todo));
+               for (done = 0; done < todo; done += n) {
+                       if ((n = read(state->pipes[0], state->buf, state->xfer)) <= 0) {
+                               /* error! */
+@@ -115,7 +115,7 @@ writer(int controlfd, int writefd, char* buf, void* cookie)
+       struct _state* state = (struct _state*)cookie;
+
+       for ( ;; ) {
+-              read(controlfd, &todo, sizeof(todo));
++              (void) !read(controlfd, &todo, sizeof(todo));
+               for (done = 0; done < todo; done += n) {
+ #ifdef TOUCH
+                       touch(buf, XFERSIZE);
+diff --git a/src/hello.c b/src/hello.c
+index 15a2493..0f7f237 100644
+--- a/src/hello.c
++++ b/src/hello.c
+@@ -3,6 +3,6 @@
+ int
+ main()
+ {
+-      write(1, "Hello world\n", 12);
++      (void) !write(1, "Hello world\n", 12);
+       return (0);
+ }
+diff --git a/src/lat_connect.c b/src/lat_connect.c
+index 4e5538e..2e08731 100644
+--- a/src/lat_connect.c
++++ b/src/lat_connect.c
+@@ -52,7 +52,7 @@ main(int ac, char **av)
+                       int sock = tcp_connect(av[optind],
+                                              TCP_CONNECT,
+                                              SOCKOPT_NONE);
+-                      write(sock, "0", 1);
++                      (void) !write(sock, "0", 1);
+                       close(sock);
+                       exit(0);
+               }
+diff --git a/src/lat_fcntl.c b/src/lat_fcntl.c
+index 01847a8..3b9fd65 100644
+--- a/src/lat_fcntl.c
++++ b/src/lat_fcntl.c
+@@ -120,8 +120,8 @@ initialize(iter_t iterations, void* cookie)
+       }
+       unlink(state->filename1);
+       unlink(state->filename2);
+-      write(state->fd1, buf, sizeof(buf));
+-      write(state->fd2, buf, sizeof(buf));
++      (void) !write(state->fd1, buf, sizeof(buf));
++      (void) !write(state->fd2, buf, sizeof(buf));
+       lock.l_type = F_WRLCK;
+       lock.l_whence = 0;
+       lock.l_start = 0;
+diff --git a/src/lat_fs.c b/src/lat_fs.c
+index 003a4ea..14efa25 100644
+--- a/src/lat_fs.c
++++ b/src/lat_fs.c
+@@ -117,7 +117,7 @@ mkfile(char *name, size_t size)
+
+       while (size > 0) {
+               chunk = ((size > (128*1024)) ? (128*1024) : size);
+-              write(fd, buf, chunk);
++              (void) !write(fd, buf, chunk);
+               size -= chunk;
+       }
+       close(fd);
+diff --git a/src/lat_http.c b/src/lat_http.c
+index 28d04f7..6ccc88e 100644
+--- a/src/lat_http.c
++++ b/src/lat_http.c
+@@ -29,11 +29,11 @@ http(char *server, char *file, int prog)
+       if (debug) {
+               printf("%s", buf);
+       }
+-      write(sock, buf, strlen(buf));
++      (void) !write(sock, buf, strlen(buf));
+       while ((n = read(sock, buf, XFERSIZE)) > 0) {
+               b += n;
+               if (echo) {
+-                      write(1, buf, n);
++                      (void) !write(1, buf, n);
+               }
+       }
+       close(sock);
+@@ -49,7 +49,7 @@ killhttp(char *server, int prog)
+       int     sock;
+
+       sock = tcp_connect(server, prog, SOCKOPT_REUSE);
+-      write(sock, "EXIT", 4);
++      (void) !write(sock, "EXIT", 4);
+       close(sock);
+ }
+
+diff --git a/src/lat_proc.c b/src/lat_proc.c
+index 6142661..e368956 100644
+--- a/src/lat_proc.c
++++ b/src/lat_proc.c
+@@ -111,7 +111,7 @@ do_shell(iter_t iterations, void* cookie)
+               case 0: /* child */
+                       handle_scheduler(benchmp_childid(), 1, 1);
+                       close(1);
+-                      execlp("/bin/sh", "sh", "-c", PROG, 0);
++                      execlp("/bin/sh", "sh", "-c", PROG, (char *)0);
+                       exit(1);
+
+               default:
+diff --git a/src/lat_select.c b/src/lat_select.c
+index 5217878..662e0ac 100644
+--- a/src/lat_select.c
++++ b/src/lat_select.c
+@@ -131,7 +131,7 @@ server(void* cookie)
+               /* child server process */
+               while (pid == getppid()) {
+                       int newsock = tcp_accept(state->sock, SOCKOPT_NONE);
+-                      read(newsock, &state->fid, 1);
++                      (void) !read(newsock, &state->fid, 1);
+                       close(newsock);
+               }
+               exit(0);
+diff --git a/src/lat_tcp.c b/src/lat_tcp.c
+index 6a11996..aad56b3 100644
+--- a/src/lat_tcp.c
++++ b/src/lat_tcp.c
+@@ -104,7 +104,7 @@ init(iter_t iterations, void* cookie)
+               exit(1);
+       }
+
+-      write(state->sock, &msize, sizeof(int));
++      (void) !write(state->sock, &msize, sizeof(int));
+ }
+
+ void
+@@ -125,8 +125,8 @@ doclient(iter_t iterations, void* cookie)
+       int     sock   = state->sock;
+
+       while (iterations-- > 0) {
+-              write(sock, state->buf, state->msize);
+-              read(sock, state->buf, state->msize);
++              (void) !write(sock, state->buf, state->msize);
++              (void) !read(sock, state->buf, state->msize);
+       }
+ }
+
+@@ -169,7 +169,7 @@ doserver(int sock)
+                       exit(4);
+               }
+               for (n = 0; read(sock, buf, msize) > 0; n++) {
+-                      write(sock, buf, msize);
++                      (void) !write(sock, buf, msize);
+               }
+               free(buf);
+       } else {
+diff --git a/src/lat_unix.c b/src/lat_unix.c
+index 43ad6a3..d7ed2f3 100644
+--- a/src/lat_unix.c
++++ b/src/lat_unix.c
+@@ -93,7 +93,7 @@ initialize(iter_t iterations, void* cookie)
+       /* Child sits and ping-pongs packets back to parent */
+       signal(SIGTERM, exit);
+       while (read(pState->sv[0], pState->buf, pState->msize) == pState->msize) {
+-              write(pState->sv[0], pState->buf, pState->msize);
++              (void) !write(pState->sv[0], pState->buf, pState->msize);
+       }
+       exit(0);
+ }
+diff --git a/src/lat_unix_connect.c b/src/lat_unix_connect.c
+index a66b256..d21747c 100644
+--- a/src/lat_unix_connect.c
++++ b/src/lat_unix_connect.c
+@@ -47,7 +47,7 @@ int main(int ac, char **av)
+               }
+               if (!strcmp(av[1], "-S")) {
+                       int sock = unix_connect(CONNAME);
+-                      write(sock, "0", 1);
++                      (void) !write(sock, "0", 1);
+                       close(sock);
+                       exit(0);
+               }
+@@ -92,7 +92,7 @@ void server_main(void)
+       for (;;) {
+               newsock = unix_accept(sock);
+               c = 0;
+-              read(newsock, &c, 1);
++              (void) !read(newsock, &c, 1);
+               if (c && c == '0') {
+                       unix_done(sock, CONNAME);
+                       exit(0);
+diff --git a/src/lib_sched.c b/src/lib_sched.c
+index fc5f82d..b284dbe 100644
+--- a/src/lib_sched.c
++++ b/src/lib_sched.c
+@@ -1,3 +1,5 @@
++#define _GNU_SOURCE
++
+ #include "bench.h"
+
+ /* #define _DEBUG */
+@@ -205,7 +207,8 @@ sched_pin(int cpu)
+               sz = 1 + (2 * sched_ncpus()) / (8 * sizeof(unsigned long));
+               mask = (unsigned long*)malloc(sz * sizeof(unsigned long));
+               cpumask = (unsigned long*)malloc(sz * sizeof(unsigned long));
+-              retval = sched_getaffinity(0, sz * sizeof(unsigned long), cpumask);
++              retval = sched_getaffinity(0, sz * sizeof(unsigned long),
++                                      (cpu_set_t *) cpumask);
+               if (retval < 0) perror("sched_getaffinity:");
+               if (retval < 0) return retval;
+
+@@ -229,7 +232,8 @@ sched_pin(int cpu)
+                       j++;
+               }
+       }
+-      retval = sched_setaffinity(0, sz * sizeof(unsigned long), mask);
++      retval = sched_setaffinity(0, sz * sizeof(unsigned long),
++                      (const cpu_set_t *) mask);
+       if (retval < 0) perror("sched_setaffinity:");
+ #ifdef _DEBUG
+       fprintf(stderr, "sched_pin(%d): pid=%d, returning %d\n", cpu, (int)getpid(), retval);
+diff --git a/src/lib_timing.c b/src/lib_timing.c
+index 714f0da..db84e8f 100644
+--- a/src/lib_timing.c
++++ b/src/lib_timing.c
+@@ -398,7 +398,7 @@ benchmp_parent(    int response,
+       }
+
+       /* send 'start' signal */
+-      write(start_signal, signals, parallel * sizeof(char));
++      (void) !write(start_signal, signals, parallel * sizeof(char));
+
+       /* Collect 'done' signals */
+       for (i = 0; i < parallel * sizeof(char); i += bytes_read) {
+@@ -443,7 +443,7 @@ benchmp_parent(    int response,
+               FD_ZERO(&fds_error);
+
+               /* tell one child to report its results */
+-              write(result_signal, buf, sizeof(char));
++              (void) !write(result_signal, buf, sizeof(char));
+
+               for (; n > 0; n -= bytes_read, buf += bytes_read) {
+                       bytes_read = 0;
+@@ -484,7 +484,7 @@ benchmp_parent(    int response,
+       signal(SIGCHLD, SIG_DFL);
+
+       /* send 'exit' signals */
+-      write(exit_signal, results, parallel * sizeof(char));
++      (void) !write(exit_signal, results, parallel * sizeof(char));
+
+       /* Compute median time; iterations is constant! */
+       set_results(merged_results);
+@@ -690,13 +690,13 @@ benchmp_interval(void* _state)
+                      NULL, &timeout);
+               if (FD_ISSET(state->start_signal, &fds)) {
+                       state->state = timing_interval;
+-                      read(state->start_signal, &c, sizeof(char));
++                      (void) !read(state->start_signal, &c, sizeof(char));
+                       iterations = state->iterations;
+               }
+               if (state->need_warmup) {
+                       state->need_warmup = 0;
+                       /* send 'ready' */
+-                      write(state->response, &c, sizeof(char));
++                      (void) !write(state->response, &c, sizeof(char));
+               }
+               break;
+       case timing_interval:
+@@ -726,7 +726,7 @@ benchmp_interval(void* _state)
+               state->iterations = iterations;
+               if (state->state == cooldown) {
+                       /* send 'done' */
+-                      write(state->response, (void*)&c, sizeof(char));
++                      (void) !write(state->response, (void*)&c, sizeof(char));
+                       iterations = state->iterations_batch;
+               }
+               break;
+@@ -741,8 +741,8 @@ benchmp_interval(void* _state)
+                        * the parent to tell us to send our results back.
+                        * From this point on, we will do no more "work".
+                        */
+-                      read(state->result_signal, (void*)&c, sizeof(char));
+-                      write(state->response, (void*)get_results(), state->r_size);
++                      (void) !read(state->result_signal, (void*)&c, sizeof(char));
++                      (void) !write(state->response, (void*)get_results(), state->r_size);
+                       if (state->cleanup) {
+                               if (benchmp_sigchld_handler == SIG_DFL)
+                                       signal(SIGCHLD, SIG_DFL);
+@@ -750,7 +750,7 @@ benchmp_interval(void* _state)
+                       }
+
+                       /* Now wait for signal to exit */
+-                      read(state->exit_signal, (void*)&c, sizeof(char));
++                      (void) !read(state->exit_signal, (void*)&c, sizeof(char));
+                       exit(0);
+               }
+       };
+diff --git a/src/lmhttp.c b/src/lmhttp.c
+index 41d9949..080b462 100644
+--- a/src/lmhttp.c
++++ b/src/lmhttp.c
+@@ -277,26 +277,34 @@ void
+ dodir(char *name, int sock)
+ {
+       FILE    *p;
+-      char    buf[1024];
++      char    *buf;
+       char    path[1024];
++      size_t  bytes;
+
+       if (dflg) printf("dodir(%s)\n", name);
++      /* figure out a buf size and allocate with malloc */
++      bytes = snprintf(buf, 0, "cd %s && ls -1a", name);
++      buf = (char*) malloc(bytes + 1);
+       sprintf(buf, "cd %s && ls -1a", name);
+       p = popen(buf, "r");
+       if (!p && dflg) printf("Couldn't popen %s\n", buf);
++      bytes = snprintf(buf, 0, "\
++<HTML><HEAD>\n<TITLE>Index of /%s</TITLE></HEAD><BODY><H1>Index of /%s</H1>\n",
++          name, name);
++      buf = (char*) realloc(buf, bytes + 1);
+       sprintf(buf, "\
+ <HTML><HEAD>\n<TITLE>Index of /%s</TITLE></HEAD><BODY><H1>Index of /%s</H1>\n",
+           name, name);
+-      write(sock, buf, strlen(buf));
++      (void) !write(sock, buf, strlen(buf));
+       while (fgets(buf, sizeof(buf), p)) {
+               buf[strlen(buf) - 1] = 0;
+               sprintf(path, "/%s/%s", name, buf);
+               if (dflg) printf("\t%s\n", path);
+-              write(sock, "<A HREF=\"", 9);
+-              write(sock, path, strlen(path));
+-              write(sock, "\">", 2);
+-              write(sock, buf, strlen(buf));
+-              write(sock, "</A><BR>\n", 9);
++              (void) !write(sock, "<A HREF=\"", 9);
++              (void) !write(sock, path, strlen(path));
++              (void) !write(sock, "\">", 2);
++              (void) !write(sock, buf, strlen(buf));
++              (void) !write(sock, "</A><BR>\n", 9);
+       }
+       pclose(p);
+ }
+@@ -380,7 +388,7 @@ logit(int sock, char *name, int size)
+       len = sprintf(buf, "%u %u %s %u\n",
+           *((unsigned int*)&sin.sin_addr), (unsigned int)time(0), name, size);
+       if (nbytes + len >= sizeof(logbuf)) {
+-              write(logfile, logbuf, nbytes);
++              (void) !write(logfile, logbuf, nbytes);
+               nbytes = 0;
+       }
+       bcopy(buf, &logbuf[nbytes], len);
+@@ -390,7 +398,7 @@ logit(int sock, char *name, int size)
+ void die()
+ {
+       if (nbytes) {
+-              write(logfile, logbuf, nbytes);
++              (void) !write(logfile, logbuf, nbytes);
+               nbytes = 0;
+       }
+       exit(1);
+diff --git a/src/memsize.c b/src/memsize.c
+index 82d7faf..35fff9d 100644
+--- a/src/memsize.c
++++ b/src/memsize.c
+@@ -111,7 +111,7 @@ timeit(char *where, size_t size)
+               clear_alarm();
+               if ((sum / n) > too_long || alarm_triggered) {
+                       size = range - incr;
+-                      fprintf(stderr, "Error! Memory testing timeout! Touch one page of memory needs more than %d (usecs)\n ", too_long);
++                      fprintf(stderr, "Error! Memory testing timeout! Touch one page of memory needs more than %zu (usecs)\n ", too_long);
+                       break;
+               }
+               for (s = s_prev; s <= range; s_prev = s, s *= 2)
+@@ -157,7 +157,7 @@ test_malloc(size_t size)
+               close(fid[0]);
+               p = malloc(size);
+               result = (p ? 1 : 0);
+-              write(fid[1], &result, sizeof(int));
++              (void) !write(fid[1], &result, sizeof(int));
+               close(fid[1]);
+               if (p) free(p);
+               exit(0);
meta-oe/recipes-benchmark/lmbench/lmbench_3.0-a9.bb +1 -1
index 8e6e803a8..cc43c6bd5 100644
@@ -26,6 +26,7 @@ SRC_URI = "${SOURCEFORGE_MIRROR}/lmbench/lmbench-${PV}.tgz \
            file://0001-Check-for-musl-define-guard-before-redefining-sockle.patch \
            file://0002-build-Adjust-CFLAGS-LDFLAGS-to-append-values-passed-.patch \
            file://0001-src-Makefile-use-libdir-instead-of-hardcoded-lib.patch \
+           file://0001-lmbench-Fix-clean-up-the-build-for-lmbench.patch \
            "
 SRC_URI[md5sum] = "b3351a3294db66a72e2864a199d37cbf"
 SRC_URI[sha256sum] = "cbd5777d15f44eab7666dcac418054c3c09df99826961a397d9acf43d8a2a551"
--

2.21.0.896.g6a6c0f1

--
_______________________________________________
Openembedded-devel mailing list
[email protected]
http://lists.openembedded.org/mailman/listinfo/openembedded-devel

#5 lore raw

Re: [meta-oe] [PATCHv3] lmbench: Fix/clean-up the build for lmbench

In reply to Khem Raj

Fix/clean up a couple of things:
- if lmbench doesn't use a return from a function attributed to warn_unused_result suppress the warning/s
- fix buffer overflow
- define feature_test_macro _GNU_SOURCE compiling in sched_{get,set}affinity()
- go strict for a pre-build check if sched_{get,set}affinity() from glibc builds cleanly. If it is not compile it out.

---
Changelog V2->V3:
- primary I have made it strict in a pre-build check if sched_{get,set}affinity() do not throw any warnings. If they do there is a possibility of a mismatch between the routines signatures in the app and their definitions in the glibc and, as a result, decided on skipping the affinity all together. Anyway I don't think affinity is used that often (if at all) in lmbench. It is better-off to script it around and use "taskset" to control the CPU's affinity
- additionally I have tested building it against x86 and aarch64 toolchains

---
 ...h-Fix-clean-up-the-build-for-lmbench.patch | 475 ++++++++++++++++++
 .../lmbench/lmbench_3.0-a9.bb                 |   1 +
 2 files changed, 476 insertions(+)
 create mode 100644 meta-oe/recipes-benchmark/lmbench/lmbench-3.0-a9/0001-lmbench-Fix-clean-up-the-build-for-lmbench.patch
meta-oe/recipes-benchmark/lmbench/lmbench-3.0-a9/0001-lmbench-Fix-clean-up-the-build-for-lmbench.patch new file +475 -0
new file mode 100644
index 000000000..ba650040e
@@ -0,0 +1,475 @@
+lmbench: Fix/clean-up the build for lmbench
+
+Fix/clean up a coule of things:
+- if lmbench doesn't use a return from a function attributed to warn_unused_result
+  supress the warning/s
+- fix buffer overflow
+- define feature_test_macro _GNU_SOURCE compiling in sched_{get,set}affinity()
+- go strict for a pre-build check if sched_{get,set}affinity() from glibc builds
+  cleanly. If it is not compile it out.
+
+Signed-off-by: Marek Bykowski <[email protected]>
+Reviewed-off-by: Marcin Lapaj <[email protected]>
+
+---
+ scripts/build          | 24 +++++++++++++++---------
+ src/bw_tcp.c           |  2 +-
+ src/bw_unix.c          |  4 ++--
+ src/hello.c            |  2 +-
+ src/lat_connect.c      |  2 +-
+ src/lat_fcntl.c        |  4 ++--
+ src/lat_fs.c           |  2 +-
+ src/lat_http.c         |  6 +++---
+ src/lat_proc.c         |  2 +-
+ src/lat_select.c       |  2 +-
+ src/lat_tcp.c          |  8 ++++----
+ src/lat_unix.c         |  2 +-
+ src/lat_unix_connect.c |  4 ++--
+ src/lib_sched.c        |  7 +++++--
+ src/lib_timing.c       | 18 +++++++++---------
+ src/lmhttp.c           | 26 +++++++++++++++++---------
+ src/memsize.c          |  4 ++--
+ 17 files changed, 68 insertions(+), 51 deletions(-)
+
+diff --git a/scripts/build b/scripts/build
+index 3786741..c0930d6 100755
+--- a/scripts/build
++++ b/scripts/build
+@@ -33,7 +33,7 @@ else
+ 	fi
+ fi
+ rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
+-	
++
+ # check for IA64 HP-UX w/ HP's ANSI compiler; may need pointer swizzling
+ arch=`echo $OS | awk -F- '{print $1;}'`
+ if [ "X$CC" = "Xcc" -a "X$arch" = "Xia64" ]
+@@ -272,14 +272,20 @@ ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c ${LDLIBS} 1>${NULL} 2>${NULL} \
+ 	&& CFLAGS="${CFLAGS} -DHAVE_BINDPROCESSOR=1";
+ rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
+ 
+-# check that we have sched_setaffinity
+-echo "#include <stdlib.h>" > ${BASE}$$.c
+-echo "#include <unistd.h>" >> ${BASE}$$.c
+-echo "#include <sched.h>" >> ${BASE}$$.c
+-echo "main() { unsigned long mask = 1; return sched_setaffinity(0, sizeof(unsigned long), &mask); }" >> ${BASE}$$.c
+-${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c ${LDLIBS} 1>${NULL} 2>${NULL} \
+-	&& CFLAGS="${CFLAGS} -DHAVE_SCHED_SETAFFINITY=1";
+-rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
++# check that we have sched_setaffinity and it builds cleanly
++cat << '_ACEOF' > ${BASE}$$.c
++#define _GNU_SOURCE
++#include <stdlib.h>
++#include <unistd.h>
++#include <sched.h>
++int main() {
++cpu_set_t set; CPU_ZERO(&set); CPU_SET(0, &set);
++if (sched_setaffinity(0, sizeof(set), &set) == -1) exit(EXIT_FAILURE); exit(EXIT_SUCCESS);
++}
++_ACEOF
++${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c ${LDLIBS} 1>${NULL} 2>${BASE}$$_err
++test -s ${BASE}$$_err || CFLAGS="${CFLAGS} -DHAVE_SCHED_SETAFFINITY=1"
++rm -f ${BASE}$$_err ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
+ 
+ 
+ if [ ! -d ${BINDIR} ]; then mkdir -p ${BINDIR}; fi
+diff --git a/src/bw_tcp.c b/src/bw_tcp.c
+index cc27098..bf76fac 100644
+--- a/src/bw_tcp.c
++++ b/src/bw_tcp.c
+@@ -60,7 +60,7 @@ main(int ac, char **av)
+ 		{
+ 			int	conn;
+ 			conn = tcp_connect(optarg, TCP_DATA, SOCKOPT_NONE);
+-			write(conn, "0", 1);
++			(void) !write(conn, "0", 1);
+ 			exit(0);
+ 		}
+ 		case 'm':
+diff --git a/src/bw_unix.c b/src/bw_unix.c
+index ad71157..493db7c 100644
+--- a/src/bw_unix.c
++++ b/src/bw_unix.c
+@@ -97,7 +97,7 @@ reader(iter_t iterations, void* cookie)
+ 	size_t	todo = state->bytes;
+ 
+ 	while (iterations-- > 0) {
+-		write(state->control[1], &todo, sizeof(todo));
++		(void) !write(state->control[1], &todo, sizeof(todo));
+ 		for (done = 0; done < todo; done += n) {
+ 			if ((n = read(state->pipes[0], state->buf, state->xfer)) <= 0) {
+ 				/* error! */
+@@ -115,7 +115,7 @@ writer(int controlfd, int writefd, char* buf, void* cookie)
+ 	struct _state* state = (struct _state*)cookie;
+ 
+ 	for ( ;; ) {
+-		read(controlfd, &todo, sizeof(todo));
++		(void) !read(controlfd, &todo, sizeof(todo));
+ 		for (done = 0; done < todo; done += n) {
+ #ifdef TOUCH
+ 			touch(buf, XFERSIZE);
+diff --git a/src/hello.c b/src/hello.c
+index 15a2493..0f7f237 100644
+--- a/src/hello.c
++++ b/src/hello.c
+@@ -3,6 +3,6 @@
+ int
+ main()
+ {
+-	write(1, "Hello world\n", 12);
++	(void) !write(1, "Hello world\n", 12);
+ 	return (0);
+ }
+diff --git a/src/lat_connect.c b/src/lat_connect.c
+index 4e5538e..2e08731 100644
+--- a/src/lat_connect.c
++++ b/src/lat_connect.c
+@@ -52,7 +52,7 @@ main(int ac, char **av)
+ 			int sock = tcp_connect(av[optind],
+ 					       TCP_CONNECT,
+ 					       SOCKOPT_NONE);
+-			write(sock, "0", 1);
++			(void) !write(sock, "0", 1);
+ 			close(sock);
+ 			exit(0);
+ 		}
+diff --git a/src/lat_fcntl.c b/src/lat_fcntl.c
+index 01847a8..3b9fd65 100644
+--- a/src/lat_fcntl.c
++++ b/src/lat_fcntl.c
+@@ -120,8 +120,8 @@ initialize(iter_t iterations, void* cookie)
+ 	}
+ 	unlink(state->filename1);
+ 	unlink(state->filename2);
+-	write(state->fd1, buf, sizeof(buf));
+-	write(state->fd2, buf, sizeof(buf));
++	(void) !write(state->fd1, buf, sizeof(buf));
++	(void) !write(state->fd2, buf, sizeof(buf));
+ 	lock.l_type = F_WRLCK;
+ 	lock.l_whence = 0;
+ 	lock.l_start = 0;
+diff --git a/src/lat_fs.c b/src/lat_fs.c
+index 003a4ea..14efa25 100644
+--- a/src/lat_fs.c
++++ b/src/lat_fs.c
+@@ -117,7 +117,7 @@ mkfile(char *name, size_t size)
+ 
+ 	while (size > 0) {
+ 		chunk = ((size > (128*1024)) ? (128*1024) : size);
+-		write(fd, buf, chunk);
++		(void) !write(fd, buf, chunk);
+ 		size -= chunk;
+ 	}
+ 	close(fd);
+diff --git a/src/lat_http.c b/src/lat_http.c
+index 28d04f7..6ccc88e 100644
+--- a/src/lat_http.c
++++ b/src/lat_http.c
+@@ -29,11 +29,11 @@ http(char *server, char *file, int prog)
+ 	if (debug) {
+ 		printf("%s", buf);
+ 	}
+-	write(sock, buf, strlen(buf));
++	(void) !write(sock, buf, strlen(buf));
+ 	while ((n = read(sock, buf, XFERSIZE)) > 0) {
+ 		b += n;
+ 		if (echo) {
+-			write(1, buf, n);
++			(void) !write(1, buf, n);
+ 		}
+ 	}
+ 	close(sock);
+@@ -49,7 +49,7 @@ killhttp(char *server, int prog)
+ 	int     sock;
+ 
+ 	sock = tcp_connect(server, prog, SOCKOPT_REUSE);
+-	write(sock, "EXIT", 4);
++	(void) !write(sock, "EXIT", 4);
+ 	close(sock);
+ }
+ 
+diff --git a/src/lat_proc.c b/src/lat_proc.c
+index 6142661..e368956 100644
+--- a/src/lat_proc.c
++++ b/src/lat_proc.c
+@@ -111,7 +111,7 @@ do_shell(iter_t iterations, void* cookie)
+ 		case 0:	/* child */
+ 			handle_scheduler(benchmp_childid(), 1, 1);
+ 			close(1);
+-			execlp("/bin/sh", "sh", "-c", PROG, 0);
++			execlp("/bin/sh", "sh", "-c", PROG, (char *)0);
+ 			exit(1);
+ 
+ 		default:
+diff --git a/src/lat_select.c b/src/lat_select.c
+index 5217878..662e0ac 100644
+--- a/src/lat_select.c
++++ b/src/lat_select.c
+@@ -131,7 +131,7 @@ server(void* cookie)
+ 		/* child server process */
+ 		while (pid == getppid()) {
+ 			int newsock = tcp_accept(state->sock, SOCKOPT_NONE);
+-			read(newsock, &state->fid, 1);
++			(void) !read(newsock, &state->fid, 1);
+ 			close(newsock);
+ 		}
+ 		exit(0);
+diff --git a/src/lat_tcp.c b/src/lat_tcp.c
+index 6a11996..aad56b3 100644
+--- a/src/lat_tcp.c
++++ b/src/lat_tcp.c
+@@ -104,7 +104,7 @@ init(iter_t iterations, void* cookie)
+ 		exit(1);
+ 	}
+ 
+-	write(state->sock, &msize, sizeof(int));
++	(void) !write(state->sock, &msize, sizeof(int));
+ }
+ 
+ void
+@@ -125,8 +125,8 @@ doclient(iter_t iterations, void* cookie)
+ 	int 	sock   = state->sock;
+ 
+ 	while (iterations-- > 0) {
+-		write(sock, state->buf, state->msize);
+-		read(sock, state->buf, state->msize);
++		(void) !write(sock, state->buf, state->msize);
++		(void) !read(sock, state->buf, state->msize);
+ 	}
+ }
+ 
+@@ -169,7 +169,7 @@ doserver(int sock)
+ 			exit(4);
+ 		}
+ 		for (n = 0; read(sock, buf, msize) > 0; n++) {
+-			write(sock, buf, msize);
++			(void) !write(sock, buf, msize);
+ 		}
+ 		free(buf);
+ 	} else {
+diff --git a/src/lat_unix.c b/src/lat_unix.c
+index 43ad6a3..d7ed2f3 100644
+--- a/src/lat_unix.c
++++ b/src/lat_unix.c
+@@ -93,7 +93,7 @@ initialize(iter_t iterations, void* cookie)
+ 	/* Child sits and ping-pongs packets back to parent */
+ 	signal(SIGTERM, exit);
+ 	while (read(pState->sv[0], pState->buf, pState->msize) == pState->msize) {
+-		write(pState->sv[0], pState->buf, pState->msize);
++		(void) !write(pState->sv[0], pState->buf, pState->msize);
+ 	}
+ 	exit(0);
+ }
+diff --git a/src/lat_unix_connect.c b/src/lat_unix_connect.c
+index a66b256..d21747c 100644
+--- a/src/lat_unix_connect.c
++++ b/src/lat_unix_connect.c
+@@ -47,7 +47,7 @@ int main(int ac, char **av)
+ 		}
+ 		if (!strcmp(av[1], "-S")) {
+ 			int sock = unix_connect(CONNAME);
+-			write(sock, "0", 1);
++			(void) !write(sock, "0", 1);
+ 			close(sock);
+ 			exit(0);
+ 		}
+@@ -92,7 +92,7 @@ void server_main(void)
+ 	for (;;) {
+ 		newsock = unix_accept(sock);
+ 		c = 0;
+-		read(newsock, &c, 1);
++		(void) !read(newsock, &c, 1);
+ 		if (c && c == '0') {
+ 			unix_done(sock, CONNAME);
+ 			exit(0);
+diff --git a/src/lib_sched.c b/src/lib_sched.c
+index fc5f82d..32616fa 100644
+--- a/src/lib_sched.c
++++ b/src/lib_sched.c
+@@ -1,3 +1,4 @@
++#define _GNU_SOURCE
+ #include "bench.h"
+ 
+ /* #define _DEBUG */
+@@ -205,7 +206,8 @@ sched_pin(int cpu)
+ 		sz = 1 + (2 * sched_ncpus()) / (8 * sizeof(unsigned long));
+ 		mask = (unsigned long*)malloc(sz * sizeof(unsigned long));
+ 		cpumask = (unsigned long*)malloc(sz * sizeof(unsigned long));
+-		retval = sched_getaffinity(0, sz * sizeof(unsigned long), cpumask);
++		retval = sched_getaffinity(0, sz * sizeof(unsigned long),
++					(cpu_set_t *) cpumask);
+ 		if (retval < 0) perror("sched_getaffinity:");
+ 		if (retval < 0) return retval;
+ 
+@@ -229,7 +231,8 @@ sched_pin(int cpu)
+ 			j++;
+ 		}
+ 	}
+-	retval = sched_setaffinity(0, sz * sizeof(unsigned long), mask);
++	retval = sched_setaffinity(0, sz * sizeof(unsigned long),
++			(const cpu_set_t *) mask);
+ 	if (retval < 0) perror("sched_setaffinity:");
+ #ifdef _DEBUG
+ 	fprintf(stderr, "sched_pin(%d): pid=%d, returning %d\n", cpu, (int)getpid(), retval);
+diff --git a/src/lib_timing.c b/src/lib_timing.c
+index 714f0da..db84e8f 100644
+--- a/src/lib_timing.c
++++ b/src/lib_timing.c
+@@ -398,7 +398,7 @@ benchmp_parent(	int response,
+ 	}
+ 
+ 	/* send 'start' signal */
+-	write(start_signal, signals, parallel * sizeof(char));
++	(void) !write(start_signal, signals, parallel * sizeof(char));
+ 
+ 	/* Collect 'done' signals */
+ 	for (i = 0; i < parallel * sizeof(char); i += bytes_read) {
+@@ -443,7 +443,7 @@ benchmp_parent(	int response,
+ 		FD_ZERO(&fds_error);
+ 
+ 		/* tell one child to report its results */
+-		write(result_signal, buf, sizeof(char));
++		(void) !write(result_signal, buf, sizeof(char));
+ 
+ 		for (; n > 0; n -= bytes_read, buf += bytes_read) {
+ 			bytes_read = 0;
+@@ -484,7 +484,7 @@ benchmp_parent(	int response,
+ 	signal(SIGCHLD, SIG_DFL);
+ 	
+ 	/* send 'exit' signals */
+-	write(exit_signal, results, parallel * sizeof(char));
++	(void) !write(exit_signal, results, parallel * sizeof(char));
+ 
+ 	/* Compute median time; iterations is constant! */
+ 	set_results(merged_results);
+@@ -690,13 +690,13 @@ benchmp_interval(void* _state)
+ 		       NULL, &timeout);
+ 		if (FD_ISSET(state->start_signal, &fds)) {
+ 			state->state = timing_interval;
+-			read(state->start_signal, &c, sizeof(char));
++			(void) !read(state->start_signal, &c, sizeof(char));
+ 			iterations = state->iterations;
+ 		}
+ 		if (state->need_warmup) {
+ 			state->need_warmup = 0;
+ 			/* send 'ready' */
+-			write(state->response, &c, sizeof(char));
++			(void) !write(state->response, &c, sizeof(char));
+ 		}
+ 		break;
+ 	case timing_interval:
+@@ -726,7 +726,7 @@ benchmp_interval(void* _state)
+ 		state->iterations = iterations;
+ 		if (state->state == cooldown) {
+ 			/* send 'done' */
+-			write(state->response, (void*)&c, sizeof(char));
++			(void) !write(state->response, (void*)&c, sizeof(char));
+ 			iterations = state->iterations_batch;
+ 		}
+ 		break;
+@@ -741,8 +741,8 @@ benchmp_interval(void* _state)
+ 			 * the parent to tell us to send our results back.
+ 			 * From this point on, we will do no more "work".
+ 			 */
+-			read(state->result_signal, (void*)&c, sizeof(char));
+-			write(state->response, (void*)get_results(), state->r_size);
++			(void) !read(state->result_signal, (void*)&c, sizeof(char));
++			(void) !write(state->response, (void*)get_results(), state->r_size);
+ 			if (state->cleanup) {
+ 				if (benchmp_sigchld_handler == SIG_DFL)
+ 					signal(SIGCHLD, SIG_DFL);
+@@ -750,7 +750,7 @@ benchmp_interval(void* _state)
+ 			}
+ 
+ 			/* Now wait for signal to exit */
+-			read(state->exit_signal, (void*)&c, sizeof(char));
++			(void) !read(state->exit_signal, (void*)&c, sizeof(char));
+ 			exit(0);
+ 		}
+ 	};
+diff --git a/src/lmhttp.c b/src/lmhttp.c
+index 41d9949..080b462 100644
+--- a/src/lmhttp.c
++++ b/src/lmhttp.c
+@@ -277,26 +277,34 @@ void
+ dodir(char *name, int sock)
+ {
+ 	FILE	*p;
+-	char	buf[1024];
++	char	*buf;
+ 	char	path[1024];
++	size_t 	bytes;
+ 
+ 	if (dflg) printf("dodir(%s)\n", name);
++	/* figure out a buf size and allocate with malloc */
++	bytes = snprintf(buf, 0, "cd %s && ls -1a", name);
++	buf = (char*) malloc(bytes + 1);
+ 	sprintf(buf, "cd %s && ls -1a", name);
+ 	p = popen(buf, "r");
+ 	if (!p && dflg) printf("Couldn't popen %s\n", buf);
++	bytes = snprintf(buf, 0, "\
++<HTML><HEAD>\n<TITLE>Index of /%s</TITLE></HEAD><BODY><H1>Index of /%s</H1>\n",
++	    name, name);
++	buf = (char*) realloc(buf, bytes + 1);
+ 	sprintf(buf, "\
+ <HTML><HEAD>\n<TITLE>Index of /%s</TITLE></HEAD><BODY><H1>Index of /%s</H1>\n",
+ 	    name, name);
+-	write(sock, buf, strlen(buf));
++	(void) !write(sock, buf, strlen(buf));
+ 	while (fgets(buf, sizeof(buf), p)) {
+ 		buf[strlen(buf) - 1] = 0;
+ 		sprintf(path, "/%s/%s", name, buf);
+ 		if (dflg) printf("\t%s\n", path);
+-		write(sock, "<A HREF=\"", 9);
+-		write(sock, path, strlen(path));
+-		write(sock, "\">", 2);
+-		write(sock, buf, strlen(buf));
+-		write(sock, "</A><BR>\n", 9);
++		(void) !write(sock, "<A HREF=\"", 9);
++		(void) !write(sock, path, strlen(path));
++		(void) !write(sock, "\">", 2);
++		(void) !write(sock, buf, strlen(buf));
++		(void) !write(sock, "</A><BR>\n", 9);
+ 	}
+ 	pclose(p);
+ }
+@@ -380,7 +388,7 @@ logit(int sock, char *name, int size)
+ 	len = sprintf(buf, "%u %u %s %u\n",
+ 	    *((unsigned int*)&sin.sin_addr), (unsigned int)time(0), name, size);
+ 	if (nbytes + len >= sizeof(logbuf)) {
+-		write(logfile, logbuf, nbytes);
++		(void) !write(logfile, logbuf, nbytes);
+ 		nbytes = 0;
+ 	}
+ 	bcopy(buf, &logbuf[nbytes], len);
+@@ -390,7 +398,7 @@ logit(int sock, char *name, int size)
+ void die()
+ {
+ 	if (nbytes) {
+-		write(logfile, logbuf, nbytes);
++		(void) !write(logfile, logbuf, nbytes);
+ 		nbytes = 0;
+ 	}
+ 	exit(1);
+diff --git a/src/memsize.c b/src/memsize.c
+index 82d7faf..35fff9d 100644
+--- a/src/memsize.c
++++ b/src/memsize.c
+@@ -111,7 +111,7 @@ timeit(char *where, size_t size)
+ 		clear_alarm();
+ 		if ((sum / n) > too_long || alarm_triggered) {
+ 			size = range - incr;
+-			fprintf(stderr, "Error! Memory testing timeout! Touch one page of memory needs more than %d (usecs)\n ", too_long);
++			fprintf(stderr, "Error! Memory testing timeout! Touch one page of memory needs more than %zu (usecs)\n ", too_long);
+ 			break;
+ 		}
+ 		for (s = s_prev; s <= range; s_prev = s, s *= 2)
+@@ -157,7 +157,7 @@ test_malloc(size_t size)
+ 		close(fid[0]);
+ 		p = malloc(size);
+ 		result = (p ? 1 : 0);
+-		write(fid[1], &result, sizeof(int));
++		(void) !write(fid[1], &result, sizeof(int));
+ 		close(fid[1]);
+ 		if (p) free(p);
+ 		exit(0);
meta-oe/recipes-benchmark/lmbench/lmbench_3.0-a9.bb +1 -0
index 8e6e803a8..cc43c6bd5 100644
@@ -26,6 +26,7 @@ SRC_URI = "${SOURCEFORGE_MIRROR}/lmbench/lmbench-${PV}.tgz \
            file://0001-Check-for-musl-define-guard-before-redefining-sockle.patch \
            file://0002-build-Adjust-CFLAGS-LDFLAGS-to-append-values-passed-.patch \
            file://0001-src-Makefile-use-libdir-instead-of-hardcoded-lib.patch \
+           file://0001-lmbench-Fix-clean-up-the-build-for-lmbench.patch \
            "
 SRC_URI[md5sum] = "b3351a3294db66a72e2864a199d37cbf"
 SRC_URI[sha256sum] = "cbd5777d15f44eab7666dcac418054c3c09df99826961a397d9acf43d8a2a551"
Signature · 1 line
2.21.0.896.g6a6c0f1
#6 lore raw

Re: [meta-oe] [PATCHv3] lmbench: Fix/clean-up the build for lmbench

Quoted 141 lines · On 10/18/19 7:42 AM, [email protected] wrote:

Fix/clean up a couple of things:
- if lmbench doesn't use a return from a function attributed to warn_unused_result suppress the warning/s
- fix buffer overflow
- define feature_test_macro_GNU_SOURCE compiling in sched_{get,set}affinity()
- go strict for a pre-build check if sched_{get,set}affinity() from glibc builds cleanly. If it is not compile it out.

---
Changelog V2->V3:
- primary I have made it strict in a pre-build check if sched_{get,set}affinity() do not throw any warnings. If they do there is a possibility of a mismatch between the routines signatures in the app and their definitions in the glibc and, as a result, decided on skipping the affinity all together. Anyway I don't think affinity is used that often (if at all) in lmbench. It is better-off to script it around and use "taskset" to control the CPU's affinity
- additionally I have tested building it against x86 and aarch64 toolchains

---
  ...h-Fix-clean-up-the-build-for-lmbench.patch | 475 ++++++++++++++++++
  .../lmbench/lmbench_3.0-a9.bb                 |   1 +
  2 files changed, 476 insertions(+)

create mode 100644 meta-oe/recipes-benchmark/lmbench/lmbench-3.0-a9/0001-lmbench-Fix-clean-up-the-build-for-lmbench.patch

meta-oe/recipes-benchmark/lmbench/lmbench-3.0-a9/0001-lmbench-Fix-clean-up-the-build-for-lmbench.patch new file +110 -0
new file mode 100644
index 000000000..ba650040e
@@ -0,0 +1,475 @@
+lmbench: Fix/clean-up the build for lmbench
+
+Fix/clean up a coule of things:
+- if lmbench doesn't use a return from a function attributed to warn_unused_result
+  supress the warning/s
+- fix buffer overflow
+- define feature_test_macro_GNU_SOURCE compiling in sched_{get,set}affinity()
+- go strict for a pre-build check if sched_{get,set}affinity() from glibc builds
+  cleanly. If it is not compile it out.
+
+Signed-off-by: Marek Bykowski<[email protected]>
+Reviewed-off-by: Marcin Lapaj<[email protected]>
+
+---
+ scripts/build          | 24 +++++++++++++++---------
+ src/bw_tcp.c           |  2 +-
+ src/bw_unix.c          |  4 ++--
+ src/hello.c            |  2 +-
+ src/lat_connect.c      |  2 +-
+ src/lat_fcntl.c        |  4 ++--
+ src/lat_fs.c           |  2 +-
+ src/lat_http.c         |  6 +++---
+ src/lat_proc.c         |  2 +-
+ src/lat_select.c       |  2 +-
+ src/lat_tcp.c          |  8 ++++----
+ src/lat_unix.c         |  2 +-
+ src/lat_unix_connect.c |  4 ++--
+ src/lib_sched.c        |  7 +++++--
+ src/lib_timing.c       | 18 +++++++++---------
+ src/lmhttp.c           | 26 +++++++++++++++++---------
+ src/memsize.c          |  4 ++--
+ 17 files changed, 68 insertions(+), 51 deletions(-)
+
+diff --git a/scripts/build b/scripts/build
+index 3786741..c0930d6 100755
+--- a/scripts/build
++++ b/scripts/build
+@@ -33,7 +33,7 @@ else
+ 	fi
+ fi
+ rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
+-	
++
+ # check for IA64 HP-UX w/ HP's ANSI compiler; may need pointer swizzling
+ arch=`echo $OS | awk -F- '{print $1;}'`
+ if [ "X$CC" = "Xcc" -a "X$arch" = "Xia64" ]
+@@ -272,14 +272,20 @@ ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c ${LDLIBS} 1>${NULL} 2>${NULL} \
+ 	&& CFLAGS="${CFLAGS} -DHAVE_BINDPROCESSOR=1";
+ rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
+
+-# check that we have sched_setaffinity
+-echo "#include <stdlib.h>" > ${BASE}$$.c
+-echo "#include <unistd.h>" >> ${BASE}$$.c
+-echo "#include <sched.h>" >> ${BASE}$$.c
+-echo "main() { unsigned long mask = 1; return sched_setaffinity(0, sizeof(unsigned long), &mask); }" >> ${BASE}$$.c
+-${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c ${LDLIBS} 1>${NULL} 2>${NULL} \
+-	&& CFLAGS="${CFLAGS} -DHAVE_SCHED_SETAFFINITY=1";
+-rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
++# check that we have sched_setaffinity and it builds cleanly
++cat << '_ACEOF' > ${BASE}$$.c
++#define _GNU_SOURCE
++#include <stdlib.h>
++#include <unistd.h>
++#include <sched.h>
++int main() {
++cpu_set_t set; CPU_ZERO(&set); CPU_SET(0, &set);
++if (sched_setaffinity(0, sizeof(set), &set) == -1) exit(EXIT_FAILURE); exit(EXIT_SUCCESS);
++}
++_ACEOF
++${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c ${LDLIBS} 1>${NULL} 2>${BASE}$$_err
++test -s ${BASE}$$_err || CFLAGS="${CFLAGS} -DHAVE_SCHED_SETAFFINITY=1"
++rm -f ${BASE}$$_err ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
+
+
+ if [ ! -d ${BINDIR} ]; then mkdir -p ${BINDIR}; fi
+diff --git a/src/bw_tcp.c b/src/bw_tcp.c
+index cc27098..bf76fac 100644
+--- a/src/bw_tcp.c
++++ b/src/bw_tcp.c
+@@ -60,7 +60,7 @@ main(int ac, char **av)
+ 		{
+ 			int	conn;
+ 			conn = tcp_connect(optarg, TCP_DATA, SOCKOPT_NONE);
+-			write(conn, "0", 1);
++			(void) !write(conn, "0", 1);
+ 			exit(0);
+ 		}
+ 		case 'm':
+diff --git a/src/bw_unix.c b/src/bw_unix.c
+index ad71157..493db7c 100644
+--- a/src/bw_unix.c
++++ b/src/bw_unix.c
+@@ -97,7 +97,7 @@ reader(iter_t iterations, void* cookie)
+ 	size_t	todo = state->bytes;
+
+ 	while (iterations-- > 0) {
+-		write(state->control[1], &todo, sizeof(todo));
++		(void) !write(state->control[1], &todo, sizeof(todo));
+ 		for (done = 0; done < todo; done += n) {
+ 			if ((n = read(state->pipes[0], state->buf, state->xfer)) <= 0) {
+ 				/* error! */
+@@ -115,7 +115,7 @@ writer(int controlfd, int writefd, char* buf, void* cookie)
+ 	struct _state* state = (struct _state*)cookie;
+
+ 	for ( ;; ) {
+-		read(controlfd, &todo, sizeof(todo));
++		(void) !read(controlfd, &todo, sizeof(todo));
+ 		for (done = 0; done < todo; done += n) {
+ #ifdef TOUCH
+ 			touch(buf, XFERSIZE);

meta-oe/recipes-benchmark/lmbench/lmbench-3.0-a9/0001-lmbench-Fix-clean-up-the-build-for-lmbench.patch line 120

Quoted 10 lines
meta-oe/recipes-benchmark/lmbench/lmbench-3.0-a9/0001-lmbench-Fix-clean-up-the-build-for-lmbench.patch new file +10 -0
+diff --git a/src/hello.c b/src/hello.c
+index 15a2493..0f7f237 100644
+--- a/src/hello.c
++++ b/src/hello.c
+@@ -3,6 +3,6 @@
+ int
+ main()
+ {
+-	write(1, "Hello world\n", 12);
++	(void) !write(1, "Hello world\n", 12);

Hi Merek,

What's the "!" for ? It doesn't seem to be essential.

In unistd.h:
extern ssize_t write (int __fd, const void *__buf, size_t __n) __wur;

and in cdefs.h:
---------------
/* If fortification mode, we warn about unused results of certain
function calls which can lead to problems. */
#if __GNUC_PREREQ (3,4)

# define __attribute_warn_unused_result__ \
   __attribute__ ((__warn_unused_result__))
# if __USE_FORTIFY_LEVEL > 0
#  define __wur __attribute_warn_unused_result__
# endif
#else
# define __attribute_warn_unused_result__ /* empty */
#endif
#ifndef __wur
# define __wur /* Ignore */
#endif
---------------

so did you consider just making a compiler specific fix/hack for gcc/clang such as:
#define __wur /* Ignore */
You could do that in each file that needs it. While that's still ugly, it is at least more localized.

Also, did you confirm that this change doesn't affect the resulting binary code? I expect that it won't but it's a benchmark so it's worth confirming.

Finally, lmbench hasn't released a new tarball on sf.net in 5 years:
https://sourceforge.net/projects/lmbench/
There's a new somewhat active version of lmbench:
https://github.com/intel/lmbench
Should we use that version?

Sorry to leave this until v3 but the:
(void) !foo()
syntax triggered me! ;-)

Signature · 2 lines
# Randy MacLeod
# Wind River Linux
#7 lore raw

Re: [meta-oe] [PATCHv3] lmbench: Fix/clean-up the build for lmbench

Quoted 1 line

What's the "!" for ? It doesn't seem to be essential.

It is a logical negation making warn_unused_result happy (one uses the result in the end) followed by a cast to void discarding the result. With only casting to void the compiler remains to warn.

Quoted 5 lines

so did you consider just making a compiler specific fix/hack for gcc/clang such as:

    #define __wur /* Ignore */

You could do that in each file that needs it. While that's still ugly, it is at least more localized.

In your hack/fix #define __wur /* Ignore */ should be preceded with #undef __wur, isn't it? Yes, this should indeed be neater than "(void) !foo()" but my concern would be it may impact all the routines using __wur discarding they attributes and not only the ones of our interest (somehow a short list of the routines using __wur from glibc below). Not sure if this is a worry though, haven't inspected lmbench if uses any functions with __wur except the write/read being "fixed" by this "(void)!".

$ grep -Irn extern.*__wur ./stdlib/stdlib.h
97:extern size_t __ctype_get_mb_cur_max (void) __THROW __wur;
385:extern char *l64a (long int __n) __THROW __wur;
634:extern char *getenv (const char *__name) __THROW __nonnull ((1)) __wur;
688:extern int mkstemp (char *__template) __nonnull ((1)) __wur;
698:extern int mkstemp64 (char *__template) __nonnull ((1)) __wur;
710:extern int mkstemps (char *__template, int __suffixlen) __nonnull ((1)) __wur;
731:extern char *mkdtemp (char *__template) __THROW __nonnull ((1)) __wur;
742:extern int mkostemp (char *__template, int __flags) __nonnull ((1)) __wur;
752:extern int mkostemp64 (char *__template, int __flags) __nonnull ((1)) __wur;
784:extern int system (const char *__command) __wur;
840:extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
841:extern long int labs (long int __x) __THROW __attribute__ ((__const__)) __wur;
946:extern int rpmatch (const char *__response) __THROW __nonnull ((1)) __wur;
968:extern int posix_openpt (int __oflag) __wur;
985:extern char *ptsname (int __fd) __THROW __wur;
Quoted 3 lines

Also, did you confirm that this change doesn't affect the resulting binary code? I expect that it won't but it's a benchmark so it's worth confirming.

I think it will, as the write/read are parts of latency path but I feel this should be negligent eating up a tens/hundreds?! of CPU cycles (say with CPU 1G, 100 cycles is 10ns)

Quoted 5 lines

Finally, lmbench hasn't released a new tarball on sf.net in 5 years:
https://sourceforge.net/projects/lmbench/
There's a new somewhat active version of lmbench:
https://github.com/intel/lmbench
Should we use that version?

I'm not sure what is better, the original (sf.net) but not maintained in a quite few years or one taken over by one of the companies (intel), looked after by them, that is just making a use of it. Such company's project may go to an end of the life cycle leaving openembedded without the sources. Besides you never know who is committing and if you can rely on their changes. I think all together the biggest problem is that lmbench is being officially discontinued in a few years to date and to have reliable in openembedded I would be inclined somebody from openembedded takes the original over and maintains it (as intel did).

Quoted 3 lines

Sorry to leave this until v3 but the:

    (void) !foo()

syntax triggered me! ;-)

Suppressing the warning I may refer to as to "better than nothing" but the golden solution would be to fix it properly and probably use the return as suggested by the authors of this routine/s.

#8 lore raw

Re: [meta-oe] [PATCHv3] lmbench: Fix/clean-up the build for lmbench

Quoted 2 lines · On 10/21/19 5:30 AM, [email protected] wrote:
Quoted 1 line

What's the "!" for ? It doesn't seem to be essential.

It is a logical negation making warn_unused_result happy (one uses the result in the end) followed by a cast to void discarding the result. With only casting to void the compiler remains to warn.

Ah, right. I guess that's admirably terse even if it is visually and idiomatically ugly!

Quoted 7 lines
Quoted 5 lines

so did you consider just making a compiler specific fix/hack for gcc/clang such as:

     #define __wur /* Ignore */

You could do that in each file that needs it. While that's still ugly, it is at least more localized.

In your hack/fix #define __wur /* Ignore */ should be preceded with #undef __wur, isn't it?

Yes.

Quoted 18 lines

Yes, this should indeed be neater than "(void) !foo()" but my concern would be it may impact all the routines using __wur discarding they attributes and not only the ones of our interest (somehow a short list of the routines using __wur from glibc below). Not sure if this is a worry though, haven't inspected lmbench if uses any functions with __wur except the write/read being "fixed" by this "(void)!".

$ grep -Irn extern.*__wur ./stdlib/stdlib.h
97:extern size_t __ctype_get_mb_cur_max (void) __THROW __wur;
385:extern char *l64a (long int __n) __THROW __wur;
634:extern char *getenv (const char *__name) __THROW __nonnull ((1)) __wur;
688:extern int mkstemp (char *__template) __nonnull ((1)) __wur;
698:extern int mkstemp64 (char *__template) __nonnull ((1)) __wur;
710:extern int mkstemps (char *__template, int __suffixlen) __nonnull ((1)) __wur;
731:extern char *mkdtemp (char *__template) __THROW __nonnull ((1)) __wur;
742:extern int mkostemp (char *__template, int __flags) __nonnull ((1)) __wur;
752:extern int mkostemp64 (char *__template, int __flags) __nonnull ((1)) __wur;
784:extern int system (const char *__command) __wur;
840:extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
841:extern long int labs (long int __x) __THROW __attribute__ ((__const__)) __wur;
946:extern int rpmatch (const char *__response) __THROW __nonnull ((1)) __wur;
968:extern int posix_openpt (int __oflag) __wur;
985:extern char *ptsname (int __fd) __THROW __wur;

Yes, I  thought of that after sending my email.

Your fix is less intrusive and therefore lower risk.

Quoted 5 lines
Quoted 3 lines

Also, did you confirm that this change doesn't affect the resulting binary code? I expect that it won't but it's a benchmark so it's worth confirming.

I think it will, as the write/read are parts of latency path but I feel this should be negligent eating up a tens/hundreds?! of CPU cycles (say with CPU 1G, 100 cycles is 10ns)

I may have a look at the assembly and do some testing but you're correct that a few instructions on a read/write path is likely to be in the noise even in the ago of high speed storage devices.

Quoted 6 lines
Quoted 5 lines

Finally, lmbench hasn't released a new tarball on sf.net in 5 years:
https://sourceforge.net/projects/lmbench/
There's a new somewhat active version of lmbench:
https://github.com/intel/lmbench
Should we use that version?

I'm not sure what is better, the original (sf.net) but not maintained in a quite few years or one taken over by one of the companies (intel), looked after by them, that is just making a use of it. Such company's project may go to an end of the life cycle leaving openembedded without the sources. Besides you never know who is committing and if you can rely on their changes. I think all together the biggest problem is that lmbench is being officially discontinued in a few years to date and to have reliable in openembedded I would be inclined somebody from openembedded takes the original over and maintains it (as intel did).

If you see the developer S-O-B line, the commit is on github without license changes, and the code has been or can be reviewed then it should outlast even Intel! It would be good if the original authors reviewed commits but they don't seen to be interested. We have had Intel employees working on oe-core / meta-openembedded for years so I hope that you will send the commit to that repo on github and indicate the upstream-status in the patch what we integrate into meta-oe.

../Randy

Quoted 5 lines
Quoted 4 lines

Sorry to leave this until v3 but the:

     (void) !foo()

syntax triggered me! ;-)

Suppressing the warning I may refer to as to "better than nothing" but the golden solution would be to fix it properly and probably use the return as suggested by the authors of this routine/s.

Signature · 2 lines
# Randy MacLeod
# Wind River Linux
#9 lore raw

Re: [meta-oe] [PATCHv3] lmbench: Fix/clean-up the build for lmbench

Quoted 4 lines · On Mon, 21 Oct 2019 19:42:45 -0400 Randy MacLeod <[email protected]>…

We have had Intel employees working on oe-core / meta-openembedded for years so I hope that you will send the commit to that repo on github and indicate the
upstream-status in the patch what we integrate into meta-oe.

Hi Randy,

I'm Intel (actually a subcontractor to them) working on occasion with Daniel Drogomir, Charlie Paul, and Chantale Ouimet from Windriver. I have put the names as chances they may be your colleagues. Even though I'm Intel I didn't know of lmbench Intel repo on github - this must a totally different team. Sure I'll send the patch onto that repo indicating these are the changes integration planned into meta-oe.

Regards,
Marek

#10 lore raw

Re: [meta-oe] [PATCHv3] lmbench: Fix/clean-up the build for lmbench

Quoted 18 lines · On Tue, 22 Oct 2019 09:15:23 +0200 "[email protected]"…
Quoted 4 lines · On Mon, 21 Oct 2019 19:42:45 -0400 Randy MacLeod <[email protected]>…

We have had Intel employees working on oe-core / meta-openembedded for years so I hope that you will send the commit to that repo on github and indicate the
upstream-status in the patch what we integrate into meta-oe.

Hi Randy,

I'm Intel (actually a subcontractor to them) working on occasion with Daniel Drogomir, Charlie Paul, and Chantale Ouimet from Windriver. I have put the names as chances they may be your colleagues. Even though I'm Intel I didn't know of lmbench Intel repo on github - this must a totally different team. Sure I'll send the patch onto that repo indicating these are the changes integration planned into meta-oe.

Quoted 2 lines

Regards,
Marek

Done https://github.com/intel/lmbench/pull/9

author
#11 lore raw

Re: [meta-oe] [PATCHv3] lmbench: Fix/clean-up the build for lmbench

Any thoughts if this is going to be included in the upstream? Thanks,
Marek

Quoted 26 lines · On Tue, 22 Oct 2019 at 12:03, [email protected]…
Quoted 18 lines · On Tue, 22 Oct 2019 09:15:23 +0200 "[email protected]"…
Quoted 4 lines · On Mon, 21 Oct 2019 19:42:45 -0400 Randy MacLeod <[email protected]>…

We have had Intel employees working on oe-core / meta-openembedded for years so I hope that you will send the commit to that repo on github and indicate the
upstream-status in the patch what we integrate into meta-oe.

Hi Randy,

I'm Intel (actually a subcontractor to them) working on occasion with Daniel Drogomir, Charlie Paul, and Chantale Ouimet from Windriver. I have put the names as chances they may be your colleagues. Even though I'm Intel I didn't know of lmbench Intel repo on github - this must a totally different team. Sure I'll send the patch onto that repo indicating these are the changes integration planned into meta-oe.

Quoted 2 lines

Regards,
Marek

Done https://github.com/intel/lmbench/pull/9

Signature · 2 lines
Slán,
Marek
#12 lore raw

Re: [meta-oe] [PATCHv3] lmbench: Fix/clean-up the build for lmbench

Hi Marek

I thought there are some feedbacks to be addressed, so I was hoping to get a v3

Quoted 39 lines · Marek

Any thoughts if this is going to be included in the upstream? Thanks,
Marek

Quoted 22 lines · On Tue, 22 Oct 2019 at 12:03, [email protected]…
Quoted 18 lines · On Tue, 22 Oct 2019 09:15:23 +0200 "[email protected]"…
Quoted 4 lines · On Mon, 21 Oct 2019 19:42:45 -0400 Randy MacLeod <[email protected]>…

We have had Intel employees working on oe-core / meta-openembedded for years so I hope that you will send the commit to that repo on github and indicate the
upstream-status in the patch what we integrate into meta-oe.

Hi Randy,

I'm Intel (actually a subcontractor to them) working on occasion with Daniel Drogomir, Charlie Paul, and Chantale Ouimet from Windriver. I have put the names as chances they may be your colleagues. Even though I'm Intel I didn't know of lmbench Intel repo on github - this must a totally different team. Sure I'll send the patch onto that repo indicating these are the changes integration planned into meta-oe.

Quoted 4 lines
Quoted 2 lines

Regards,
Marek

Done https://github.com/intel/lmbench/pull/9

--
Slán,
Marek

author
#13 lore raw

Re: [meta-oe] [PATCHv3] lmbench: Fix/clean-up the build for lmbench

I don't think Intel is interested in the pull request (
https://github.com/intel/lmbench/pull/9). With that are you still planning on taking the change in?

Thanks,
Marek

Quoted 46 lines · Khem Raj

Hi Marek

I thought there are some feedbacks to be addressed, so I was hoping to get a v3

Quoted 39 lines · Marek

Any thoughts if this is going to be included in the upstream? Thanks,
Marek

Quoted 22 lines · On Tue, 22 Oct 2019 at 12:03, [email protected]…
Quoted 18 lines · On Tue, 22 Oct 2019 09:15:23 +0200 "[email protected]"…
Quoted 4 lines · On Mon, 21 Oct 2019 19:42:45 -0400 Randy MacLeod <[email protected]>…

We have had Intel employees working on oe-core / meta-openembedded for years so I hope that you will send the commit to that repo on github and indicate the
upstream-status in the patch what we integrate into meta-oe.

Hi Randy,

I'm Intel (actually a subcontractor to them) working on occasion with Daniel Drogomir, Charlie Paul, and Chantale Ouimet from Windriver. I have put the names as chances they may be your colleagues. Even though I'm Intel I didn't know of lmbench Intel repo on github - this must a totally different team. Sure I'll send the patch onto that repo indicating these are the changes integration planned into meta-oe.

Quoted 4 lines
Quoted 2 lines

Regards,
Marek

Done https://github.com/intel/lmbench/pull/9

--
Slán,
Marek

Signature · 2 lines
Slán,
Marek
author
#14 lore raw

Re: [meta-oe] [PATCHv3] lmbench: Fix/clean-up the build for lmbench

Any updates if it is going to be taken in?
Thanks,
Marek

Quoted 63 lines · Marek

I don't think Intel is interested in the pull request (
https://github.com/intel/lmbench/pull/9). With that are you still planning on taking the change in?

Thanks,
Marek

Quoted 25 lines · Khem Raj

Hi Marek

I thought there are some feedbacks to be addressed, so I was hoping to get a v3

Quoted 19 lines · Marek

Any thoughts if this is going to be included in the upstream? Thanks,
Marek

Quoted 12 lines · On Tue, 22 Oct 2019 at 12:03, [email protected]…
Quoted 8 lines · On Tue, 22 Oct 2019 09:15:23 +0200 "[email protected]"…
Quoted 4 lines · On Mon, 21 Oct 2019 19:42:45 -0400 Randy MacLeod <[email protected]>…

We have had Intel employees working on oe-core / meta-openembedded for years so I hope that you will send the commit to that repo on github and indicate the
upstream-status in the patch what we integrate into meta-oe.

Quoted 23 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Hi Randy,

I'm Intel (actually a subcontractor to them) working on occasion

with

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Daniel Drogomir, Charlie Paul, and Chantale Ouimet from Windriver. I have put the names as chances they may be your colleagues. Even though I'm Intel I didn't know of lmbench Intel repo on github -

this

Quoted 14 lines
Quoted 8 lines
Quoted 6 lines

must a totally different team. Sure I'll send the patch onto that repo indicating these are the changes integration planned into meta-oe.

Regards,
Marek

Done https://github.com/intel/lmbench/pull/9

--
Slán,
Marek

--
Slán,
Marek

Signature · 2 lines
Slán,
Marek
#15 lore raw

Re: [meta-oe] [PATCHv3] lmbench: Fix/clean-up the build for lmbench

Quoted 2 lines · Marek

Any updates if it is going to be taken in?

Can you resend the latest patch once again? with all feedbacks addressed

Quoted 68 lines

Thanks,
Marek

Quoted 55 lines · Marek

I don't think Intel is interested in the pull request (https://github.com/intel/lmbench/pull/9). With that are you still planning on taking the change in?

Thanks,
Marek

Quoted 45 lines · Khem Raj

Hi Marek

I thought there are some feedbacks to be addressed, so I was hoping to get a v3

Quoted 39 lines · Marek

Any thoughts if this is going to be included in the upstream? Thanks,
Marek

Quoted 22 lines · On Tue, 22 Oct 2019 at 12:03, [email protected]…
Quoted 18 lines · On Tue, 22 Oct 2019 09:15:23 +0200 "[email protected]"…
Quoted 4 lines · On Mon, 21 Oct 2019 19:42:45 -0400 Randy MacLeod <[email protected]>…

We have had Intel employees working on oe-core / meta-openembedded for years so I hope that you will send the commit to that repo on github and indicate the
upstream-status in the patch what we integrate into meta-oe.

Hi Randy,

I'm Intel (actually a subcontractor to them) working on occasion with Daniel Drogomir, Charlie Paul, and Chantale Ouimet from Windriver. I have put the names as chances they may be your colleagues. Even though I'm Intel I didn't know of lmbench Intel repo on github - this must a totally different team. Sure I'll send the patch onto that repo indicating these are the changes integration planned into meta-oe.

Quoted 4 lines
Quoted 2 lines

Regards,
Marek

Done https://github.com/intel/lmbench/pull/9

--
Slán,
Marek

Quoted 3 lines

--
Slán,
Marek

--
Slán,
Marek