From patchwork Wed May 17 18:26:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuah Khan X-Patchwork-Id: 683160 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 A9F98C77B75 for ; Wed, 17 May 2023 18:27:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229555AbjEQS07 (ORCPT ); Wed, 17 May 2023 14:26:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229475AbjEQS06 (ORCPT ); Wed, 17 May 2023 14:26:58 -0400 Received: from mail-io1-xd36.google.com (mail-io1-xd36.google.com [IPv6:2607:f8b0:4864:20::d36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A38CF1FDA for ; Wed, 17 May 2023 11:26:55 -0700 (PDT) Received: by mail-io1-xd36.google.com with SMTP id ca18e2360f4ac-76c6ba5fafaso6875739f.1 for ; Wed, 17 May 2023 11:26:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; t=1684348015; x=1686940015; h=subject:from:cc:to:content-language:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=SefrbI4luUxkGPhDruiHFtUBNRN3yZ6zgSDA+Ss60NY=; b=H3JFE1jHp5TEZJc7lLOVSzFimQ6OuqRvaHdKgsh+0FijfB4S8X+4Tpfty2B9sQuhxu JavwJmSIC6V4ciE5nSbf0L13cOleRE84BdxZhvMy4Xhsu0bEvFRR8CJBkT7CMyKfC/44 MTt+JfNXAMlgq9M/jF4jAz+BKxEbqLw1jK6Rg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684348015; x=1686940015; h=subject:from:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=SefrbI4luUxkGPhDruiHFtUBNRN3yZ6zgSDA+Ss60NY=; b=WZbHx2Kh7sBSRY6sD+UUoG9beihE3xYP8XwJi/eR5EO0w3dxoNjk/SQ9GLkb2xumuJ PEZTMwhQk8F6MMSZBaqsV9VIUoRdHCRqrkhPh38vqmYOfe2IWe89iuFhUwoXdEETS+jc 40nZKwcW+G+rcdw37BCSOVOGDQykyJxTM41tBJbI6uDvbuIrqlCYoa1aYQjIPaYzv1O2 0VpIeRPMIIOoacObhekqANy14YK3A84/cZdflVPC/flt/nfok/W0PjcjnSM0KpJICVt3 EjIJ16MyL3buadGbu9YUa78bQruqkfs04GiJhn16EpF7H8LvcFuLsE4shzZ5ZcM5f4+P Q1HQ== X-Gm-Message-State: AC+VfDw8jWTux5TGINxmXYow0u3wUzXbCCLdElQJsoz2A+gmrwlssx75 u20e3Ex973TSLOzPZNKvAKLAUQ== X-Google-Smtp-Source: ACHHUZ4f//BL/tJ6X+98JURia5it3s8oKIZoUOVYBr7jSyI9pGhj6RAqk9wyfzBF1hn33q0tLld4YA== X-Received: by 2002:a05:6e02:1b0d:b0:332:fcce:c26d with SMTP id i13-20020a056e021b0d00b00332fccec26dmr2703997ilv.0.1684348014895; Wed, 17 May 2023 11:26:54 -0700 (PDT) Received: from [192.168.1.128] ([38.15.45.1]) by smtp.gmail.com with ESMTPSA id b6-20020a92dcc6000000b003350c8ae201sm7593874ilr.29.2023.05.17.11.26.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 17 May 2023 11:26:54 -0700 (PDT) Message-ID: <8abea32a-4895-7826-8a9c-9ddc5a7ad2bd@linuxfoundation.org> Date: Wed, 17 May 2023 12:26:53 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Content-Language: en-US To: "Rafael J. Wysocki" Cc: Shuah Khan , shuah , Thomas Renninger , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org From: Shuah Khan Subject: [GIT PULL] cpupower update for Linux 6.4-rc3 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Hi Rafael, Please pull the following cpupower update for Linux 6.4-rc3 or for a later rc. This cpupower fixes update for Linux 6.4-rc3 consists of: - a resource leak fix - fix drift in C0 percentage calculation due to System-wide TSC read. To lower this drift read TSC per CPU and also just after mperf read. This technique improves C0 percentage calculation in Mperf monitor diff is attached. thanks, -- Shuah ---------------------------------------------------------------- The following changes since commit ac9a78681b921877518763ba0e89202254349d1b: Linux 6.4-rc1 (2023-05-07 13:34:35 -0700) are available in the Git repository at: git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux tags/linux-cpupower-6.4-rc3 for you to fetch changes up to c2adb1877b76fc81ae041e1db1a6ed2078c6746b: cpupower: Make TSC read per CPU for Mperf monitor (2023-05-08 10:46:49 -0600) ---------------------------------------------------------------- linux-cpupower-6.4-rc3 This cpupower fixes update for Linux 6.4-rc3 consists of: - a resource leak fix - fix drift in C0 percentage calculation due to System-wide TSC read. To lower this drift read TSC per CPU and also just after mperf read. This technique improves C0 percentage calculation in Mperf monitor ---------------------------------------------------------------- Hao Zeng (1): cpupower:Fix resource leaks in sysfs_get_enabled() Wyes Karny (1): cpupower: Make TSC read per CPU for Mperf monitor tools/power/cpupower/lib/powercap.c | 23 +++++++++++----- .../cpupower/utils/idle_monitor/mperf_monitor.c | 31 ++++++++++------------ 2 files changed, 30 insertions(+), 24 deletions(-) ---------------------------------------------------------------- diff --git a/tools/power/cpupower/lib/powercap.c b/tools/power/cpupower/lib/powercap.c index 0ce29ee4c2e4..a7a59c6bacda 100644 --- a/tools/power/cpupower/lib/powercap.c +++ b/tools/power/cpupower/lib/powercap.c @@ -40,25 +40,34 @@ static int sysfs_get_enabled(char *path, int *mode) { int fd; char yes_no; + int ret = 0; *mode = 0; fd = open(path, O_RDONLY); - if (fd == -1) - return -1; + if (fd == -1) { + ret = -1; + goto out; + } if (read(fd, &yes_no, 1) != 1) { - close(fd); - return -1; + ret = -1; + goto out_close; } if (yes_no == '1') { *mode = 1; - return 0; + goto out_close; } else if (yes_no == '0') { - return 0; + goto out_close; + } else { + ret = -1; + goto out_close; } - return -1; +out_close: + close(fd); +out: + return ret; } int powercap_get_enabled(int *mode) diff --git a/tools/power/cpupower/utils/idle_monitor/mperf_monitor.c b/tools/power/cpupower/utils/idle_monitor/mperf_monitor.c index e7d48cb563c0..ae6af354a81d 100644 --- a/tools/power/cpupower/utils/idle_monitor/mperf_monitor.c +++ b/tools/power/cpupower/utils/idle_monitor/mperf_monitor.c @@ -70,8 +70,8 @@ static int max_freq_mode; */ static unsigned long max_frequency; -static unsigned long long tsc_at_measure_start; -static unsigned long long tsc_at_measure_end; +static unsigned long long *tsc_at_measure_start; +static unsigned long long *tsc_at_measure_end; static unsigned long long *mperf_previous_count; static unsigned long long *aperf_previous_count; static unsigned long long *mperf_current_count; @@ -169,7 +169,7 @@ static int mperf_get_count_percent(unsigned int id, double *percent, aperf_diff = aperf_current_count[cpu] - aperf_previous_count[cpu]; if (max_freq_mode == MAX_FREQ_TSC_REF) { - tsc_diff = tsc_at_measure_end - tsc_at_measure_start; + tsc_diff = tsc_at_measure_end[cpu] - tsc_at_measure_start[cpu]; *percent = 100.0 * mperf_diff / tsc_diff; dprint("%s: TSC Ref - mperf_diff: %llu, tsc_diff: %llu\n", mperf_cstates[id].name, mperf_diff, tsc_diff); @@ -206,7 +206,7 @@ static int mperf_get_count_freq(unsigned int id, unsigned long long *count, if (max_freq_mode == MAX_FREQ_TSC_REF) { /* Calculate max_freq from TSC count */ - tsc_diff = tsc_at_measure_end - tsc_at_measure_start; + tsc_diff = tsc_at_measure_end[cpu] - tsc_at_measure_start[cpu]; time_diff = timespec_diff_us(time_start, time_end); max_frequency = tsc_diff / time_diff; } @@ -225,33 +225,27 @@ static int mperf_get_count_freq(unsigned int id, unsigned long long *count, static int mperf_start(void) { int cpu; - unsigned long long dbg; clock_gettime(CLOCK_REALTIME, &time_start); - mperf_get_tsc(&tsc_at_measure_start); - for (cpu = 0; cpu < cpu_count; cpu++) + for (cpu = 0; cpu < cpu_count; cpu++) { + mperf_get_tsc(&tsc_at_measure_start[cpu]); mperf_init_stats(cpu); + } - mperf_get_tsc(&dbg); - dprint("TSC diff: %llu\n", dbg - tsc_at_measure_start); return 0; } static int mperf_stop(void) { - unsigned long long dbg; int cpu; - for (cpu = 0; cpu < cpu_count; cpu++) + for (cpu = 0; cpu < cpu_count; cpu++) { mperf_measure_stats(cpu); + mperf_get_tsc(&tsc_at_measure_end[cpu]); + } - mperf_get_tsc(&tsc_at_measure_end); clock_gettime(CLOCK_REALTIME, &time_end); - - mperf_get_tsc(&dbg); - dprint("TSC diff: %llu\n", dbg - tsc_at_measure_end); - return 0; } @@ -353,7 +347,8 @@ struct cpuidle_monitor *mperf_register(void) aperf_previous_count = calloc(cpu_count, sizeof(unsigned long long)); mperf_current_count = calloc(cpu_count, sizeof(unsigned long long)); aperf_current_count = calloc(cpu_count, sizeof(unsigned long long)); - + tsc_at_measure_start = calloc(cpu_count, sizeof(unsigned long long)); + tsc_at_measure_end = calloc(cpu_count, sizeof(unsigned long long)); mperf_monitor.name_len = strlen(mperf_monitor.name); return &mperf_monitor; } @@ -364,6 +359,8 @@ void mperf_unregister(void) free(aperf_previous_count); free(mperf_current_count); free(aperf_current_count); + free(tsc_at_measure_start); + free(tsc_at_measure_end); free(is_valid); }