Blame SOURCES/blktrace-1.0.5-blktrace-high-cpu-count.patch

644205
commit 0a915aabe88ff98786a88f30d2e062ef34d0826c
644205
Author: Nathan Zimmer <nzimmer@sgi.com>
644205
Date:   Mon Apr 15 09:53:36 2013 -0500
644205
644205
    blktrace blkreplay: convert to use a dynamic cpu_set_t
644205
    
644205
    Some distros have changed CPU_SETSIZE in glibc to 4096 since that matches
644205
    the NR_CPUS in the linux kernel config file.  Some distros have decided to
644205
    leave CPU_SETSIZE at 1024. This is a problem if you want to run that distro
644205
    on a very large machine.
644205
    
644205
    CPU_SETSIZE is use by the struct cpu_set_t.  This means you to deal with cpus
644205
    greater the 1024 you must use the dynamic cpu sets, which involves converting
644205
    from things like CPU_SET to CPU_SET_S.
644205
    
644205
    Cc: Jens Axboe <axboe@kernel.dk>
644205
    
644205
    Modified by Jens to fix the CPU_{SET,ZERO}_S pointer mixup.
644205
    
644205
    Signed-off-by: Nathan Zimmer <nzimmer@sgi.com>
644205
    Signed-off-by: Jens Axboe <axboe@kernel.dk>
644205
644205
commit 67313d8f411fe08f3f8a0c94ad2cf45bf569f0f8
644205
Author: Nathan Zimmer <nzimmer@sgi.com>
644205
Date:   Mon Apr 15 09:53:35 2013 -0500
644205
644205
    blktrace: use number of configured cpus instead of online cpus
644205
    
644205
    We want to run on all online processors.  However is there is a hole in the
644205
    online cpumask this won't happen.  We need the number of configured processors
644205
    instead of online.
644205
    
644205
    Cc: Jens Axboe <axboe@kernel.dk>
644205
    Signed-off-by: Nathan Zimmer <nzimmer@sgi.com>
644205
    Signed-off-by: Jens Axboe <axboe@kernel.dk>
644205
644205
commit fb69749415ae2bd7c3180605d01a5a39f3bd988f
644205
Author: Nathan Zimmer <nzimmer@sgi.com>
644205
Date:   Mon Apr 15 09:53:34 2013 -0500
644205
644205
    btreplay: use sysconf to get the number of configured cpus
644205
    
644205
    We should use the standard methods for getting the number of cpus in the
644205
    system when they are available.  It is good practice to leave the old ways in
644205
    place for people stuck on older systems.
644205
    
644205
    Cc: Jens Axboe <axboe@kernel.dk>
644205
    Signed-off-by: Nathan Zimmer <nzimmer@sgi.com>
644205
    Signed-off-by: Jens Axboe <axboe@kernel.dk>
644205
644205
commit 80c4041b2e7a7d5afb75df563bf51bb27773c095
644205
Author: Abutalib Aghayev <agayev@gmail.com>
644205
Date:   Tue Feb 9 08:17:50 2016 -0700
644205
644205
    blktrace: Use number of online CPUs
644205
    
644205
    Currently, blktrace uses _SC_NPROCESSORS_CONF to find out the number of
644205
    CPUs.  This is a problem, because if you reduce the number of online
644205
    CPUs by passing kernel parameter maxcpus, then blktrace fails to start
644205
    with the error:
644205
    
644205
    FAILED to start thread on CPU 4: 22/Invalid argument
644205
    FAILED to start thread on CPU 5: 22/Invalid argument
644205
    ...
644205
    
644205
    The attached patch fixes it to use _SC_NPROCESSORS_ONLN.
644205
    
644205
    Signed-off-by: Jens Axboe <axboe@fb.com>
644205
644205
commit f6541f75f2822252b057f08e9f5f0c40d4079a8c
644205
Author: Roman Pen <r.peniaev@gmail.com>
644205
Date:   Sat Apr 23 13:44:08 2016 +0200
644205
644205
    btreplay: fix memory corruption caused by CPU_ZERO_S
644205
    
644205
    Size should be provided, not cpus number.
644205
    
644205
    Signed-off-by: Roman Pen <r.peniaev@gmail.com>
644205
    Cc: Jens Axboe <axboe@fb.com>
644205
    Cc: <linux-btrace@vger.kernel.org>
644205
    Signed-off-by: Jens Axboe <axboe@fb.com>
644205
644205
Index: blktrace-1.0.5/blktrace.c
644205
===================================================================
644205
--- blktrace-1.0.5.orig/blktrace.c
644205
+++ blktrace-1.0.5/blktrace.c
644205
@@ -621,13 +621,19 @@ static void dpp_free(struct devpath *dpp
644205
 
644205
 static int lock_on_cpu(int cpu)
644205
 {
644205
-	cpu_set_t cpu_mask;
644205
-
644205
-	CPU_ZERO(&cpu_mask);
644205
-	CPU_SET(cpu, &cpu_mask);
644205
-	if (sched_setaffinity(0, sizeof(cpu_mask), &cpu_mask) < 0)
644205
+	cpu_set_t * cpu_mask;
644205
+	size_t size;
644205
+	cpu_mask = CPU_ALLOC(ncpus);
644205
+	size = CPU_ALLOC_SIZE(ncpus);
644205
+
644205
+	CPU_ZERO_S(size, cpu_mask);
644205
+	CPU_SET_S(cpu, size, cpu_mask);
644205
+	if (sched_setaffinity(0, size, cpu_mask) < 0) {
644205
+		CPU_FREE(cpu_mask);		
644205
 		return errno;
644205
+	}
644205
 
644205
+	CPU_FREE(cpu_mask);		
644205
 	return 0;
644205
 }
644205
 
644205
Index: blktrace-1.0.5/btreplay/btreplay.c
644205
===================================================================
644205
--- blktrace-1.0.5.orig/btreplay/btreplay.c
644205
+++ blktrace-1.0.5/btreplay/btreplay.c
644205
@@ -502,19 +502,34 @@ static inline void start_iter(void)
644205
  */
644205
 static void get_ncpus(void)
644205
 {
644205
-	cpu_set_t cpus;
644205
-
644205
-	if (sched_getaffinity(getpid(), sizeof(cpus), &cpus)) {
644205
+#ifdef _SC_NPROCESSORS_ONLN
644205
+	ncpus = sysconf(_SC_NPROCESSORS_ONLN);
644205
+#else
644205
+	int nrcpus = 4096;
644205
+	cpu_set_t * cpus;
644205
+	
644205
+realloc:
644205
+	cpus = CPU_ALLOC(nrcpus);
644205
+	size = CPU_ALLOC_SIZE(nrcpus);
644205
+	CPU_ZERO_S(size, cpus);
644205
+
644205
+	if (sched_getaffinity(getpid(), size, cpus)) {
644205
+		if( errno == EINVAL && nrcpus < (4096<<4) ) {
644205
+			CPU_FREE(cpus);
644205
+			nrcpus <= 1;
644205
+			goto realloc;
644205
+		}
644205
 		fatal("sched_getaffinity", ERR_SYSCALL, "Can't get CPU info\n");
644205
 		/*NOTREACHED*/
644205
 	}
644205
 
644205
-	/*
644205
-	 * XXX This assumes (perhaps wrongly) that there are no /holes/ 
644205
-	 * XXX in the mask.
644205
-	 */
644205
-	for (ncpus = 0; ncpus < CPU_SETSIZE && CPU_ISSET(ncpus, &cpus); ncpus++)
644205
-		;
644205
+	ncpus = -1;
644205
+	for (last_cpu = 0; last_cpu < CPU_SETSIZE && CPU_ISSET(last_cpu, &cpus); last_cpu++)
644205
+		if (CPU_ISSET( last_cpu, &cpus) ) 
644205
+			ncpus = last_cpu;
644205
+	ncpus++;
644205
+	CPU_FREE(cpus);
644205
+#endif
644205
 	if (ncpus == 0) {
644205
 		fatal(NULL, ERR_SYSCALL, "Insufficient number of CPUs\n");
644205
 		/*NOTREACHED*/
644205
@@ -527,25 +542,29 @@ static void get_ncpus(void)
644205
  */
644205
 static void pin_to_cpu(struct thr_info *tip)
644205
 {
644205
-	cpu_set_t cpus;
644205
+	cpu_set_t *cpus;
644205
+	size_t size;
644205
+
644205
+	cpus = CPU_ALLOC(ncpus);
644205
+	size = CPU_ALLOC_SIZE(ncpus);	
644205
 
644205
 	assert(0 <= tip->cpu && tip->cpu < ncpus);
644205
 
644205
-	CPU_ZERO(&cpus);
644205
-	CPU_SET(tip->cpu, &cpus);
644205
-	if (sched_setaffinity(getpid(), sizeof(cpus), &cpus)) {
644205
+	CPU_ZERO_S(size, cpus);
644205
+	CPU_SET_S(tip->cpu, size, cpus);
644205
+	if (sched_setaffinity(getpid(), size, cpus)) {
644205
 		fatal("sched_setaffinity", ERR_SYSCALL, "Failed to pin CPU\n");
644205
 		/*NOTREACHED*/
644205
 	}
644205
 
644205
 	if (verbose > 1) {
644205
 		int i;
644205
-		cpu_set_t now;
644205
+		cpu_set_t *now = CPU_ALLOC(ncpus);
644205
 
644205
-		(void)sched_getaffinity(getpid(), sizeof(now), &now;;
644205
+		(void)sched_getaffinity(getpid(), size, now);
644205
 		fprintf(tip->vfp, "Pinned to CPU %02d ", tip->cpu);
644205
 		for (i = 0; i < ncpus; i++)
644205
-			fprintf(tip->vfp, "%1d", CPU_ISSET(i, &now));
644205
+			fprintf(tip->vfp, "%1d", CPU_ISSET_S(i, size, now));
644205
 		fprintf(tip->vfp, "\n");
644205
 	}
644205
 }
644205
Index: blktrace-1.0.5/verify_blkparse.c
644205
===================================================================
644205
--- blktrace-1.0.5.orig/verify_blkparse.c
644205
+++ blktrace-1.0.5/verify_blkparse.c
644205
@@ -3,18 +3,33 @@
644205
 #include <fcntl.h>
644205
 #include <string.h>
644205
 #include <unistd.h>
644205
-
644205
-#define MAX_CPUS	(512)
644205
+#include <errno.h>
644205
 
644205
 int main(int argc, char *argv[])
644205
 {
644205
 	double this_time, last_time;
644205
 	char line[256], last_line[256], *p;
644205
 	int major, minor, cpu, nr, alias;
644205
+	long  MAX_CPUS;
644205
 	unsigned long long total_entries;
644205
-	unsigned int last_seq[MAX_CPUS], seq;
644205
+	unsigned int *last_seq;
644205
+	unsigned int seq;
644205
 	FILE *f;
644205
 
644205
+#ifdef _SC_NPROCESSORS_ONLN
644205
+	MAX_CPUS = sysconf(_SC_NPROCESSORS_ONLN);
644205
+	if (MAX_CPUS < 1)
644205
+	{
644205
+		fprintf(stderr, "Could not determine number of CPUs online:\n%s\n", 
644205
+			strerror (errno));
644205
+		fprintf(stderr, "Assuming 1024\n");
644205
+		MAX_CPUS = 1024;
644205
+  	}
644205
+#else
644205
+	MAX_CPUS = CPU_SETSIZE;
644205
+#endif 
644205
+	
644205
+	last_seq = malloc( sizeof(unsigned int) * MAX_CPUS );
644205
 	for (nr = 0; nr < MAX_CPUS; nr++)
644205
 		last_seq[nr] = -1;
644205
 
644205
@@ -33,7 +48,7 @@ int main(int argc, char *argv[])
644205
 	alias = nr = 0;
644205
 	total_entries = 0;
644205
 	while ((p = fgets(line, sizeof(line), f)) != NULL) {
644205
-		if (sscanf(p, "%3d,%3d %2d %8d %lf", &major, &minor, &cpu, &seq, &this_time) != 5)
644205
+		if (sscanf(p, "%3d,%3d %5d %8d %lf", &major, &minor, &cpu, &seq, &this_time) != 5)
644205
 			break;
644205
 
644205
 		if (this_time < last_time) {