From patchwork Tue Feb 22 15:34:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huang Rui X-Patchwork-Id: 545499 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 77AE9C3525B for ; Tue, 22 Feb 2022 15:35:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233576AbiBVPgS (ORCPT ); Tue, 22 Feb 2022 10:36:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233574AbiBVPgI (ORCPT ); Tue, 22 Feb 2022 10:36:08 -0500 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2067.outbound.protection.outlook.com [40.107.223.67]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3491164D01; Tue, 22 Feb 2022 07:35:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NweVAgTBj5gN0exlTPGplOPTVN8Dc5NDuJS6qvZ9zMTSugnOfzLccOZyKhjv8GJM1P3aCoGMYeUZ4PQOoTreGKlPwGCeOWlgC5ZF8s6ziQFAxN+DwRmbuVs8Z4whUiJVMjk4teSfMpHzG11+BhwEfkJOtLbgLK88yDTpxp//nE+Hh19zn9BuvaImnK0nFHheCt1F4RnwootZVedGHHoEqu+PqdhxdxmCjdTmYkuCwo+UkGDw/g4NZgB/aLS3XI2uXEtfSOPUmAsVwYr4/l0vkZZAx3YSZsgNMyF+czUk6NGdU3Buok64rWgNUvnJaf0jmm+J0hk2tjL7LxeY06bHfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=PMNLMZVzUW2YdiqmtmxHGym4ga1Wvo7eKoqFM3xREQ4=; b=NxQpAIlrsLhwYtJRut+rl2WS8KKets9pLuJoiiTbKgemmNMTSmvn9V8dt6RFY8jyT2+1qyxfdVlr/8haT5PLSmjCnjde+gqKquTtYhrtSJVKd9+U/BA09xXnuReTe0IXutZM6Vzj5NqHyMH+kL2oxzx/FlwMWT7amAcsCGb/EPhuQWkUqSfQaBbgq9nibe3iBTdSdUGmIWBarlwaqAHws2c/6frTOEuILPwBJi1ZWSCOLnFtmKapRxAgLS3ykoLpeb3YMtfEBgWZejjQyg1cf2Bdw/2Ll2Np9FxBfsdmqcQv3E28ayCbfSACSV2/bsk4+1b5HR7yhUlfqmItiXAmRw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=linuxfoundation.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=PMNLMZVzUW2YdiqmtmxHGym4ga1Wvo7eKoqFM3xREQ4=; b=VhkQkKEbx3A/1lQPdI+8JaySwA/gbKFmaFvpzCripqM3k6AzjY7IJdvti739wg/0hEE50nLyXkKiwCBclVj1X4AsMdJMHqYN1YQRkwAaar/VAemjUG4NVwP1UBaMUerm7GKeHBtOeENVU1XTOmGjRcOExNQqx9URSP28I7NV2IY= Received: from DS7PR03CA0072.namprd03.prod.outlook.com (2603:10b6:5:3bb::17) by MN2PR12MB3920.namprd12.prod.outlook.com (2603:10b6:208:168::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4995.16; Tue, 22 Feb 2022 15:35:29 +0000 Received: from DM6NAM11FT064.eop-nam11.prod.protection.outlook.com (2603:10b6:5:3bb:cafe::e5) by DS7PR03CA0072.outlook.office365.com (2603:10b6:5:3bb::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4995.16 via Frontend Transport; Tue, 22 Feb 2022 15:35:29 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT064.mail.protection.outlook.com (10.13.172.234) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4995.15 via Frontend Transport; Tue, 22 Feb 2022 15:35:29 +0000 Received: from hr-amd.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.18; Tue, 22 Feb 2022 09:35:23 -0600 From: Huang Rui To: Shuah Khan , "Rafael J . Wysocki" , CC: Deepak Sharma , Alex Deucher , Mario Limonciello , Steven Noonan , Nathan Fontenot , Jinzhou Su , Xiaojian Du , Perry Yuan , Jassmine Meng , Borislav Petkov , Peter Zijlstra , Ingo Molnar , Viresh Kumar , Steven Rostedt , "Giovanni Gherdovich" , , Huang Rui Subject: [PATCH v7 08/10] cpupower: Move print_speed function into misc helper Date: Tue, 22 Feb 2022 23:34:24 +0800 Message-ID: <20220222153426.2216974-9-ray.huang@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220222153426.2216974-1-ray.huang@amd.com> References: <20220222153426.2216974-1-ray.huang@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 24348850-70ed-4375-148e-08d9f618f4a1 X-MS-TrafficTypeDiagnostic: MN2PR12MB3920:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RcRFlyGQrGc5smaxAiao6jAcU/OgWcJfDmYY7dp1aLpGn00BuFIsArEQbT6S1MAZ0Wlh2YTGgQ5swzPkhF/CFx1tNBMY63U8Z0MvAbt3omRhWExP+G3hpU1obptYxobBkEPBEhvGnAcYHkvmeff37W1Af4psfy+J4YRDtol8bDmlEUpQ37S+2PhDDTTOk2qEDS0czydJDpU+w3mj1XHlMhRCvOAfsOT/gjHxcVM0uxbnAjsztjZgSAmwVSZ5TObxBx1Mst1E3Cx0+Hu0Tx6b/6fj92qUibUBcmBb4aKL2wfmFir7jjIkEp2sMs6jb7VViv5nXcSOaRfwK30dzbnAYNThcRTrO0WaIf1761tonroi+s4agL0+iJn++pw6cTsAJlGPyCQeouTd53wZiFeXtYVAn/mbSJPXtXwIPxywo0m5zV26JrQ8WmWjlYwYTxAj+gs8p2jiu0AFhlvhq38jEJ1SUmdU7U2zaZmEzOrHn3d9nT+CD8uNyvmifX90TL1WcwNJTB9/m3+X+yOd8rytIK9VWRQM1Z0JX7w+rSnyTjEb08gTsTSuzKHukfPCD/QxTQlK3/EfMHS2LwRRbyR+69OQzgkVSjVtqDF1fKxJ46tlEGqnC3w/QzL9vdM/v4JhFQUac/axaZPpeD6Pw/x+ir4UmzqNNTCionXSTNUgLsxck32W6HO0jpTrIXTe4F8HvMR2pNvIjRm/PzCByUn+iQ== X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230001)(4636009)(36840700001)(40470700004)(46966006)(36756003)(2616005)(40460700003)(7696005)(508600001)(47076005)(36860700001)(2906002)(1076003)(186003)(16526019)(5660300002)(4326008)(110136005)(54906003)(8936002)(26005)(8676002)(316002)(356005)(82310400004)(86362001)(336012)(426003)(81166007)(70586007)(70206006)(83380400001)(7416002)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Feb 2022 15:35:29.2231 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 24348850-70ed-4375-148e-08d9f618f4a1 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT064.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3920 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The print_speed can be as a common function, and expose it into misc helper header. Then it can be used on other helper files as well. Signed-off-by: Huang Rui --- tools/power/cpupower/utils/cpufreq-info.c | 59 ++++---------------- tools/power/cpupower/utils/helpers/helpers.h | 1 + tools/power/cpupower/utils/helpers/misc.c | 40 +++++++++++++ 3 files changed, 52 insertions(+), 48 deletions(-) diff --git a/tools/power/cpupower/utils/cpufreq-info.c b/tools/power/cpupower/utils/cpufreq-info.c index f9895e31ff5a..b429454bf3ae 100644 --- a/tools/power/cpupower/utils/cpufreq-info.c +++ b/tools/power/cpupower/utils/cpufreq-info.c @@ -84,43 +84,6 @@ static void proc_cpufreq_output(void) } static int no_rounding; -static void print_speed(unsigned long speed) -{ - unsigned long tmp; - - if (no_rounding) { - if (speed > 1000000) - printf("%u.%06u GHz", ((unsigned int) speed/1000000), - ((unsigned int) speed%1000000)); - else if (speed > 1000) - printf("%u.%03u MHz", ((unsigned int) speed/1000), - (unsigned int) (speed%1000)); - else - printf("%lu kHz", speed); - } else { - if (speed > 1000000) { - tmp = speed%10000; - if (tmp >= 5000) - speed += 10000; - printf("%u.%02u GHz", ((unsigned int) speed/1000000), - ((unsigned int) (speed%1000000)/10000)); - } else if (speed > 100000) { - tmp = speed%1000; - if (tmp >= 500) - speed += 1000; - printf("%u MHz", ((unsigned int) speed/1000)); - } else if (speed > 1000) { - tmp = speed%100; - if (tmp >= 50) - speed += 100; - printf("%u.%01u MHz", ((unsigned int) speed/1000), - ((unsigned int) (speed%1000)/100)); - } - } - - return; -} - static void print_duration(unsigned long duration) { unsigned long tmp; @@ -254,11 +217,11 @@ static int get_boost_mode(unsigned int cpu) if (freqs) { printf(_(" boost frequency steps: ")); while (freqs->next) { - print_speed(freqs->frequency); + print_speed(freqs->frequency, no_rounding); printf(", "); freqs = freqs->next; } - print_speed(freqs->frequency); + print_speed(freqs->frequency, no_rounding); printf("\n"); cpufreq_put_available_frequencies(freqs); } @@ -277,7 +240,7 @@ static int get_freq_kernel(unsigned int cpu, unsigned int human) return -EINVAL; } if (human) { - print_speed(freq); + print_speed(freq, no_rounding); } else printf("%lu", freq); printf(_(" (asserted by call to kernel)\n")); @@ -296,7 +259,7 @@ static int get_freq_hardware(unsigned int cpu, unsigned int human) return -EINVAL; } if (human) { - print_speed(freq); + print_speed(freq, no_rounding); } else printf("%lu", freq); printf(_(" (asserted by call to hardware)\n")); @@ -316,9 +279,9 @@ static int get_hardware_limits(unsigned int cpu, unsigned int human) if (human) { printf(_(" hardware limits: ")); - print_speed(min); + print_speed(min, no_rounding); printf(" - "); - print_speed(max); + print_speed(max, no_rounding); printf("\n"); } else { printf("%lu %lu\n", min, max); @@ -350,9 +313,9 @@ static int get_policy(unsigned int cpu) return -EINVAL; } printf(_(" current policy: frequency should be within ")); - print_speed(policy->min); + print_speed(policy->min, no_rounding); printf(_(" and ")); - print_speed(policy->max); + print_speed(policy->max, no_rounding); printf(".\n "); printf(_("The governor \"%s\" may decide which speed to use\n" @@ -436,7 +399,7 @@ static int get_freq_stats(unsigned int cpu, unsigned int human) struct cpufreq_stats *stats = cpufreq_get_stats(cpu, &total_time); while (stats) { if (human) { - print_speed(stats->frequency); + print_speed(stats->frequency, no_rounding); printf(":%.2f%%", (100.0 * stats->time_in_state) / total_time); } else @@ -486,11 +449,11 @@ static void debug_output_one(unsigned int cpu) if (freqs) { printf(_(" available frequency steps: ")); while (freqs->next) { - print_speed(freqs->frequency); + print_speed(freqs->frequency, no_rounding); printf(", "); freqs = freqs->next; } - print_speed(freqs->frequency); + print_speed(freqs->frequency, no_rounding); printf("\n"); cpufreq_put_available_frequencies(freqs); } diff --git a/tools/power/cpupower/utils/helpers/helpers.h b/tools/power/cpupower/utils/helpers/helpers.h index 326491e11c6e..fa2a8c1b1d26 100644 --- a/tools/power/cpupower/utils/helpers/helpers.h +++ b/tools/power/cpupower/utils/helpers/helpers.h @@ -200,5 +200,6 @@ extern struct bitmask *offline_cpus; void get_cpustate(void); void print_online_cpus(void); void print_offline_cpus(void); +void print_speed(unsigned long speed, int no_rounding); #endif /* __CPUPOWERUTILS_HELPERS__ */ diff --git a/tools/power/cpupower/utils/helpers/misc.c b/tools/power/cpupower/utils/helpers/misc.c index e0d3145434d3..9547b29254a7 100644 --- a/tools/power/cpupower/utils/helpers/misc.c +++ b/tools/power/cpupower/utils/helpers/misc.c @@ -164,3 +164,43 @@ void print_offline_cpus(void) printf(_("cpupower set operation was not performed on them\n")); } } + +/* + * print_speed + * + * Print the exact CPU frequency with appropriate unit + */ +void print_speed(unsigned long speed, int no_rounding) +{ + unsigned long tmp; + + if (no_rounding) { + if (speed > 1000000) + printf("%u.%06u GHz", ((unsigned int)speed / 1000000), + ((unsigned int)speed % 1000000)); + else if (speed > 1000) + printf("%u.%03u MHz", ((unsigned int)speed / 1000), + (unsigned int)(speed % 1000)); + else + printf("%lu kHz", speed); + } else { + if (speed > 1000000) { + tmp = speed % 10000; + if (tmp >= 5000) + speed += 10000; + printf("%u.%02u GHz", ((unsigned int)speed / 1000000), + ((unsigned int)(speed % 1000000) / 10000)); + } else if (speed > 100000) { + tmp = speed % 1000; + if (tmp >= 500) + speed += 1000; + printf("%u MHz", ((unsigned int)speed / 1000)); + } else if (speed > 1000) { + tmp = speed % 100; + if (tmp >= 50) + speed += 100; + printf("%u.%01u MHz", ((unsigned int)speed / 1000), + ((unsigned int)(speed % 1000) / 100)); + } + } +}