Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 28 Jul 2015 13:16:09 +0000 (UTC)
From:      Zbigniew Bodek <zbb@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r285957 - head/sys/dev/ofw
Message-ID:  <201507281316.t6SDG9If014965@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: zbb
Date: Tue Jul 28 13:16:08 2015
New Revision: 285957
URL: https://svnweb.freebsd.org/changeset/base/285957

Log:
  Limit ofw_cpu_early_foreach() to CPUs only
  
  On some platforms, the /cpus node contains cpu-to-cluster
  map which deffinitely is not a CPU node. Its presence was
  causing incrementing of "id" variable and reporting more
  CPUs available than it should.
  To make "id" valid, increment it only when an entry really
  is a CPU device.
  
  Reviewed by:   andrew
  Obtained from: Semihalf
  Sponsored by:  The FreeBSD Foundation
  Differential Revision: https://reviews.freebsd.org/D3216

Modified:
  head/sys/dev/ofw/ofw_cpu.c

Modified: head/sys/dev/ofw/ofw_cpu.c
==============================================================================
--- head/sys/dev/ofw/ofw_cpu.c	Tue Jul 28 13:11:31 2015	(r285956)
+++ head/sys/dev/ofw/ofw_cpu.c	Tue Jul 28 13:16:08 2015	(r285957)
@@ -281,11 +281,13 @@ ofw_cpu_early_foreach(ofw_cpu_foreach_cb
 	phandle_t node, child;
 	pcell_t addr_cells, reg[2];
 	char status[16];
-	u_int id;
+	char device_type[16];
+	u_int id, next_id;
 	int count, rv;
 
 	count = 0;
 	id = 0;
+	next_id = 0;
 
 	node = OF_finddevice("/cpus");
 	if (node == -1)
@@ -296,7 +298,21 @@ ofw_cpu_early_foreach(ofw_cpu_foreach_cb
 	    sizeof(addr_cells)) < 0)
 		return (-1);
 
-	for (child = OF_child(node); child != 0; child = OF_peer(child), id++) {
+	for (child = OF_child(node); child != 0; child = OF_peer(child),
+	    id = next_id) {
+
+		/* Check if child is a CPU */
+		memset(device_type, 0, sizeof(device_type));
+		rv = OF_getprop(child, "device_type", device_type,
+		    sizeof(device_type) - 1);
+		if (rv < 0)
+			continue;
+		if (strcmp(device_type, "cpu") != 0)
+			continue;
+
+		/* We're processing CPU, update next_id used in the next iteration */
+		next_id++;
+
 		/*
 		 * If we are filtering by runnable then limit to only
 		 * those that have been enabled.



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