Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 18 Oct 2016 13:12:19 +0000 (UTC)
From:      Sean Bruno <sbruno@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r307560 - head/sys/net
Message-ID:  <201610181312.u9IDCJxc093705@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: sbruno
Date: Tue Oct 18 13:12:19 2016
New Revision: 307560
URL: https://svnweb.freebsd.org/changeset/base/307560

Log:
  Fix misusage of CPU_FFS when binding queues to cpus
  
  ref: https://github.com/NextBSD/NextBSD/commit/922d0bdf2277f30954f143107d2a3eddb02abd2d
  
  Submitted by:	mmacy@nextbsd.org

Modified:
  head/sys/net/iflib.c

Modified: head/sys/net/iflib.c
==============================================================================
--- head/sys/net/iflib.c	Tue Oct 18 12:58:17 2016	(r307559)
+++ head/sys/net/iflib.c	Tue Oct 18 13:12:19 2016	(r307560)
@@ -4294,17 +4294,23 @@ iflib_irq_alloc(if_ctx_t ctx, if_irq_t i
 	return (_iflib_irq_alloc(ctx, irq, rid, filter, handler, arg, name));
 }
 
-static void
+static int
 find_nth(if_ctx_t ctx, cpuset_t *cpus, int qid)
 {
-	int i, cpuid;
+	int i, cpuid, eqid, count;
 
 	CPU_COPY(&ctx->ifc_cpus, cpus);
+	count = CPU_COUNT(&ctx->ifc_cpus);
+	eqid = qid % count;
 	/* clear up to the qid'th bit */
-	for (i = 0; i < qid; i++) {
+	for (i = 0; i < eqid; i++) {
 		cpuid = CPU_FFS(cpus);
-		CPU_CLR(cpuid, cpus);
+		MPASS(cpuid != 0);
+		CPU_CLR(cpuid-1, cpus);
 	}
+	cpuid = CPU_FFS(cpus);
+	MPASS(cpuid != 0);
+	return (cpuid-1);
 }
 
 int
@@ -4317,7 +4323,7 @@ iflib_irq_alloc_generic(if_ctx_t ctx, if
 	iflib_filter_info_t info;
 	cpuset_t cpus;
 	gtask_fn_t *fn;
-	int tqrid, err;
+	int tqrid, err, cpuid;
 	void *q;
 
 	info = &ctx->ifc_filter_info;
@@ -4363,11 +4369,11 @@ iflib_irq_alloc_generic(if_ctx_t ctx, if
 	if (err != 0)
 		return (err);
 	if (tqrid != -1) {
-		find_nth(ctx, &cpus, qid);
-		taskqgroup_attach_cpu(tqg, gtask, q, CPU_FFS(&cpus), irq->ii_rid, name);
-	} else
+		cpuid = find_nth(ctx, &cpus, qid);
+		taskqgroup_attach_cpu(tqg, gtask, q, cpuid, irq->ii_rid, name);
+	} else {
 		taskqgroup_attach(tqg, gtask, q, tqrid, name);
-
+	}
 
 	return (0);
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201610181312.u9IDCJxc093705>