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

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