From nobody Fri Sep 08 08:08:09 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4RhpdP69Jrz4sHVh; Fri, 8 Sep 2023 08:08:09 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4RhpdP5LLLz3GxF; Fri, 8 Sep 2023 08:08:09 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1694160489; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=4l0+uDj1PLafu0Q+4ZWIw5hpmq+q7xeQZCIF23soOYY=; b=x6ZD+f4hUEBKisyhUtquBCr2zeDsHjOLSN4K5IdlBAj6oavh/Q/mA+Eq/NM6jbZsEySMuG P2SnpwY1DpvBanz971zpgf8/qVV2wUNMLBQ1ML6SNyR5Un0PVT/12jCEaTcJGuGnwjRu1S Qi66dW57smrNvEMJxGM/IMikBMiyfWcimujmP4end0jnG1Zcno9aP67KtChEJrPToSI3Jg r3MDD/Tbt5lmfp7YHtOkm+PuQSCfjxiF5ciJnLmsSJ8HJA+gedVEAkdpLI3bkjqlWGr898 7SPVROowW17u/IT/O2+tXMGtxFMmlB2ssRcIfPF8yePFVtd+IXXxM1ygXPIu0A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1694160489; a=rsa-sha256; cv=none; b=PqoVBZoW5octWXUWmqgbt10Wlv5zH6ocUcWKN63lUfjODhVNMGBfN0a8XUMDVgP3jt4F8g 588LYX57FbabXsAA6hIryQ9VkDOB6X0n7+Qf8WgBCWJ2nkAKXF0RZBQgHzKBE6TsCTpeLU xb4NS9D8j0//m+NJ6PO1wcKwHZhwESNxzboZ4XtmvkOWP3NDZuJ//8riY2x7wzvwtd7Ejf BlPwniXZHMWc9oQwgY3LokUaC8WH+IthDauXNuNwLl9nAEjleL6crVE/EXviKrZEt+3GT6 YZJmRGRJEznLT9s34UmyhFLx9CSH8XtanmwReBolCUQkD18IK+cThIn80ml8/A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1694160489; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=4l0+uDj1PLafu0Q+4ZWIw5hpmq+q7xeQZCIF23soOYY=; b=I1PL+OVIAAfOmZtazwz2+fb/ZpFg4dLK7GOHL2gvfZMzf6pWFKmxrczsPe3zDGt/Ed46MR nkYdc3RkyoW2c90A4rbY86WY8lJacUCysKAxlYJuYorNDU3aQWfGLHCJIixBXSbY1X/cBJ uOm+K+0mxDKP1F739qNtg7EKpWK6fqLs4JEqYtMYfrcxyNE+sVRC1cUM4OXlTUsMr9Acdw Z1R4CfsnNc6UdH87iAgm0VdY4GYNdMYoBzHKgTvab8zNv1J5V7wK9bv/0CY2bXx+fLhFpI pxlTYSraQlBQKkYlTNbOrUPpXDGqgupBu05sENY68gVNVTJ0sKsR5Qrfvelg8g== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4RhpdP4M0WzZmw; Fri, 8 Sep 2023 08:08:09 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 388889TB025659; Fri, 8 Sep 2023 08:08:09 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3888893Y025656; Fri, 8 Sep 2023 08:08:09 GMT (envelope-from git) Date: Fri, 8 Sep 2023 08:08:09 GMT Message-Id: <202309080808.3888893Y025656@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Emmanuel Vadot Subject: git: 17c17872ca98 - main - cpufreq_dt: Find the closest frequency List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: manu X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 17c17872ca98df0e2b9f9c7a2c41ef73f7dee21a Auto-Submitted: auto-generated The branch main has been updated by manu: URL: https://cgit.FreeBSD.org/src/commit/?id=17c17872ca98df0e2b9f9c7a2c41ef73f7dee21a commit 17c17872ca98df0e2b9f9c7a2c41ef73f7dee21a Author: Emmanuel Vadot AuthorDate: 2023-09-06 16:40:17 +0000 Commit: Emmanuel Vadot CommitDate: 2023-09-08 07:44:32 +0000 cpufreq_dt: Find the closest frequency When building the frequencies table we convert the value in the DTS to megahertz and loose precision. While it's not a problem for most of the DTS it is when the expected frequency value is strict down to the hertz. So it's either we don't truncate the value and have some ugly and long values in the sysctls or we just find the closest frequency. Do the latter. Reviewed by: mmel Differential Revision: https://reviews.freebsd.org/D41762 Sponsored by: Beckhoff Automation GmbH & Co. KG --- sys/dev/cpufreq/cpufreq_dt.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/sys/dev/cpufreq/cpufreq_dt.c b/sys/dev/cpufreq/cpufreq_dt.c index aaeada3a4e58..be434cabb4fd 100644 --- a/sys/dev/cpufreq/cpufreq_dt.c +++ b/sys/dev/cpufreq/cpufreq_dt.c @@ -104,17 +104,26 @@ static const struct cpufreq_dt_opp * cpufreq_dt_find_opp(device_t dev, uint64_t freq) { struct cpufreq_dt_softc *sc; - ssize_t n; + uint64_t diff, best_diff; + ssize_t n, best_n; sc = device_get_softc(dev); + diff = 0; + best_diff = ~0; DPRINTF(dev, "Looking for freq %ju\n", freq); - for (n = 0; n < sc->nopp; n++) - if (CPUFREQ_CMP(sc->opp[n].freq, freq)) - return (&sc->opp[n]); + for (n = 0; n < sc->nopp; n++) { + diff = abs64((int64_t)sc->opp[n].freq - (int64_t)freq); + DPRINTF(dev, "Testing %ju, diff is %ju\n", sc->opp[n].freq, diff); + if (diff < best_diff) { + best_diff = diff; + best_n = n; + DPRINTF(dev, "%ju is best for now\n", sc->opp[n].freq); + } + } - DPRINTF(dev, "Couldn't find one\n"); - return (NULL); + DPRINTF(dev, "Will use %ju\n", sc->opp[best_n].freq); + return (&sc->opp[best_n]); } static void