Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 18 Jun 2020 23:31:56 +0000 (UTC)
From:      Emmanuel Vadot <manu@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r362352 - stable/12/sys/dev/cpufreq
Message-ID:  <202006182331.05INVuhN057568@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: manu
Date: Thu Jun 18 23:31:56 2020
New Revision: 362352
URL: https://svnweb.freebsd.org/changeset/base/362352

Log:
  MFC r358555, r358799-r358800
  
  r358555:
  cpufreq_dt: Improve multiple opp support
  
  When looking for cpu with the same OPP starts from the root /cpus node
  so each instance of cpufreq_dt will now each cpu with the same operating
  point.
  Also test that the node we are testing have the property "device_type" set
  to be equal to "cpu".
  While here add more debug printfs (off by defaults).
  
  r358799:
  cpufreq_dt: Fix r358555
  
  Before skipping the current cpu when trying to find the ones that
  have the same opp, record that this one have this opp.
  
  Reported by:	mmel
  X-MFC-With:	r358555
  
  r358800:
  cpufreq: Unbreak build.

Modified:
  stable/12/sys/dev/cpufreq/cpufreq_dt.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sys/dev/cpufreq/cpufreq_dt.c
==============================================================================
--- stable/12/sys/dev/cpufreq/cpufreq_dt.c	Thu Jun 18 23:23:21 2020	(r362351)
+++ stable/12/sys/dev/cpufreq/cpufreq_dt.c	Thu Jun 18 23:31:56 2020	(r362352)
@@ -82,6 +82,7 @@ struct cpufreq_dt_softc {
 	struct cpufreq_dt_opp *opp;
 	ssize_t nopp;
 
+	int cpu;
 	cpuset_t cpus;
 };
 
@@ -170,6 +171,13 @@ cpufreq_dt_set(device_t dev, const struct cf_setting *
 
 	sc = device_get_softc(dev);
 
+	DEBUG(dev, "Working on cpu %d\n", sc->cpu);
+	DEBUG(dev, "We have %d cpu on this dev\n", CPU_COUNT(&sc->cpus));
+	if (!CPU_ISSET(sc->cpu, &sc->cpus)) {
+		DEBUG(dev, "Not for this CPU\n");
+		return (0);
+	}
+
 	if (clk_get_freq(sc->clk, &freq) != 0) {
 		device_printf(dev, "Can't get current clk freq\n");
 		return (ENXIO);
@@ -191,7 +199,6 @@ cpufreq_dt_set(device_t dev, const struct cf_setting *
 			return (ENOENT);
 		}
 		uvolt = copp->uvolt_target;
-
 	}
 
 	opp = cpufreq_dt_find_opp(sc->dev, set->freq * 1000000);
@@ -450,14 +457,16 @@ cpufreq_dt_attach(device_t dev)
 	int cpu;
 	uint64_t freq;
 	int rv = 0;
+	char device_type[16];
 	enum opp_version version;
 
 	sc = device_get_softc(dev);
 	sc->dev = dev;
 	node = ofw_bus_get_node(device_get_parent(dev));
-	cpu = device_get_unit(device_get_parent(dev));
+	sc->cpu = device_get_unit(device_get_parent(dev));
 
-	if (cpu >= mp_ncpus) {
+	DEBUG(dev, "cpu=%d\n", sc->cpu);
+	if (sc->cpu >= mp_ncpus) {
 		device_printf(dev, "Not attaching as cpu is not present\n");
 		return (ENXIO);
 	}
@@ -503,7 +512,19 @@ cpufreq_dt_attach(device_t dev)
 	 * Find all CPUs that share the same opp table
 	 */
 	CPU_ZERO(&sc->cpus);
-	for (cnode = node; cnode > 0; cnode = OF_peer(cnode), cpu++) {
+	cnode = OF_parent(node);
+	for (cpu = 0, cnode = OF_child(cnode); cnode > 0; cnode = OF_peer(cnode)) {
+		if (OF_getprop(cnode, "device_type", device_type, sizeof(device_type)) <= 0)
+			continue;
+		if (strcmp(device_type, "cpu") != 0)
+			continue;
+		if (cpu == sc->cpu) {
+			DEBUG(dev, "Skipping our cpu\n");
+			CPU_SET(cpu, &sc->cpus);
+			cpu++;
+			continue;
+		}
+		DEBUG(dev, "Testing CPU %d\n", cpu);
 		copp = -1;
 		if (version == OPP_V1)
 			OF_getencprop(cnode, "operating-points", &copp,
@@ -511,8 +532,11 @@ cpufreq_dt_attach(device_t dev)
 		else if (version == OPP_V2)
 			OF_getencprop(cnode, "operating-points-v2",
 			    &copp, sizeof(copp));
-		if (opp == copp)
+		if (opp == copp) {
+			DEBUG(dev, "CPU %d is using the same opp as this one (%d)\n", cpu, sc->cpu);
 			CPU_SET(cpu, &sc->cpus);
+		}
+		cpu++;
 	}
 
 	if (clk_get_freq(sc->clk, &freq) == 0)



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