Received: by 10.192.165.148 with SMTP id m20csp1479856imm; Wed, 2 May 2018 23:24:42 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqVJU3u/N6B9oeZ1oWZu+ttpIldyUrHxCeiwPkck42wmsoLg/aJv7n6SQhukk/xoLpMpr08 X-Received: by 2002:a17:902:9042:: with SMTP id w2-v6mr22594183plz.34.1525328682759; Wed, 02 May 2018 23:24:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525328682; cv=none; d=google.com; s=arc-20160816; b=DBsGTWdS+0oimnU4j44NqWsASiI9LeewgKXDclO+4whpqjG8a6uH5EIEytoWuBo02X pi6tG+kCkAdzAwTahD0RZl9ULtGGT9+KcE+whTKV09iBqPiq3BXAAZBR3P9EMsLbim/X isKNw7W2AMjVh2UZT8V9un/aFRNKms2HR7El2BMszOegN3oi44Kmd15+rXEklx4l0oS2 uaqnojNjDQ+La/pL/umt4VD6x/FbU1ZSTCancK3ykoqixluzsj01u801IP1e85NJUf9C 6NAhsZPHwiDebIoV+QVmgzYtEx9M9OovalecIp9k388N35hoJEKRFEuxndfUc00r5yBH b0AA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=9iByaj+ZMWO9VMoYaGPNmNnYgIElth1ugSk8irBVDBk=; b=YJlxgTt/s7YG2SU53/TuITDqRuFYg4TspRSFrUhb/WVg6FC6UBY5ol8dRnfBZuhGVh +l523EEFtx67i1nXK1dQlJpyuYnJ9XSJqsZ9vck9atsT348ZTUQS+ejbygCv6Aui1ZYK ZR8dhOsgBKkE1hTi0P4aiyAlyUbhSFgQQI6cNGtQsbOkiU7xeN1M+ViZHapIDPKMVVG5 BqgXyVRYEk7ilyMcLHSWTolXpl5wkWdDUn87Y4CXx01JwvjUyoU39owyqq1oBTiJyIFt 6oKrkK4CoPD1y1a/xQt6I9XMFkDjDDs/Nq0PLLf4q9ouSAXdUTCjoWAbiipcFLOKDvL3 bEAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=BuETlGr+; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p66-v6si10902113pga.180.2018.05.02.23.24.28; Wed, 02 May 2018 23:24:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=BuETlGr+; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752049AbeECGXq (ORCPT + 99 others); Thu, 3 May 2018 02:23:46 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:36838 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751894AbeECGXn (ORCPT ); Thu, 3 May 2018 02:23:43 -0400 Received: by mail-pf0-f196.google.com with SMTP id w129so8438270pfd.3; Wed, 02 May 2018 23:23:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=9iByaj+ZMWO9VMoYaGPNmNnYgIElth1ugSk8irBVDBk=; b=BuETlGr+P380PV5v4AJwJh7LErLkKCaYinYpJGErBp/1302fns9GzKJVN77kWX949f Yl4rCpNHGx2LqEwB7qcSzmOMdrjzw3QsZUa4VEYEY2/VXF2nzcT6236eRS3/TcttfSHP VzCyaa42uTPBtrFaN505RWDBL2brUMmgZGHigGlvrqO3kHaHdeh3K3UM6nlnONYVBdrZ YgvEvMFuXhllHgsXNmimKU2Ckt7BEc+GKxmhmFuRLXeuR2XCFI4IE4aQF/WERUOGPqGL PgT2PzVMv/9eOk+b9iDM8y2L2MZ/2F7bSVbWFcUNfF9s9fwzYZejjDxxMhZjcyA8U/sc 4wbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=9iByaj+ZMWO9VMoYaGPNmNnYgIElth1ugSk8irBVDBk=; b=Vci9Xd93Z5gBS6jO4P/ftNkhZY25hLBvjS1KCQh13sC0MKsLGKevt0WlQlOta1lsO/ bTeQUl5c2fLQtT3waqcL02e9QHOk3SkaUzwC+PSewgePtzaFv7+hMNErtA4DxFyCS37d ZkjbSWp7RWrXUmdEOdoav0SFHOVb2Wbi67FzeMSRkkHs13BEfR5RhzTRz05CQrlCnj5c u943VsCdr+ePY/HmF6FBgIZIAQtYHwTfn782o6F3XKI00LTXuXH49F5ZMVO86KQUd3TY C3WCZjdSAfr5byE8GbGPnp5KSsXURu+k2E8MtuAr8nFmAfrQjEHjS74XpZCWsFNAoeq7 7M6A== X-Gm-Message-State: ALQs6tCiko5xGs9YIKEtC7i0KfBl2yT6+9zTRTRL/ao1iVpSzGVblPPs tzSFIQpW9birQ38EkrnulSYI1Q== X-Received: by 2002:a17:902:7c0d:: with SMTP id x13-v6mr4074720pll.291.1525328622950; Wed, 02 May 2018 23:23:42 -0700 (PDT) Received: from s15.smythies.com (mail.smythies.com. [173.180.45.4]) by smtp.gmail.com with ESMTPSA id y29sm28671528pff.42.2018.05.02.23.23.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 02 May 2018 23:23:42 -0700 (PDT) From: Doug Smythies X-Google-Original-From: Doug Smythies To: srinivas.pandruvada@linux.intel.com, rjw@rjwysocki.net Cc: dsmythies@telus.net, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Subject: [PATCH V5] cpufreq: intel_pstate: allow trace in passive mode Date: Wed, 2 May 2018 23:22:47 -0700 Message-Id: <1525328567-23747-1-git-send-email-dsmythies@telus.net> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Allow use of the trace_pstate_sample trace function when the intel_pstate driver is in passive mode. Since the core_busy and scaled_busy fields are not used, and it might be desirable to know which path through the driver was used, either intel_cpufreq_target or intel_cpufreq_fast_switch, re-task the core_busy field as a flag indicator. The user can then use the intel_pstate_tracer.py utility to summarize and plot the trace. Note: The core_busy feild still goes by that name in include/trace/events/power.h and within the intel_pstate_tracer.py script and csv file headers, but it is graphed as "performance", and called core_avg_perf now in the intel_pstate driver. Sometimes, in passive mode, the driver is not called for many tens or even hundreds of seconds. The user needs to understand, and not be confused by, this limitation. Signed-off-by: Doug Smythies --- V5: Changes as per Rafael J. Wysocki feedback. See: https://lkml.org/lkml/2018/1/7/270 V4: Only execute the trace specific overhead code if trace is enabled. Suggested by Srinivas Pandruvada. V3: Move largely duplicate code to a subroutine. Suggested by Rafael J. Wysocki. V2: prepare for resend. Rebase to current kernel, 4.15-rc3. --- drivers/cpufreq/intel_pstate.c | 44 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c index 17e566af..4a08686 100644 --- a/drivers/cpufreq/intel_pstate.c +++ b/drivers/cpufreq/intel_pstate.c @@ -1939,13 +1939,49 @@ static int intel_cpufreq_verify_policy(struct cpufreq_policy *policy) return 0; } +/* Use of trace in passive mode: + * + * In passive mode the trace core_busy field (also known as the + * performance field, and lablelled as such on the graphs; also known as + * core_avg_perf) is not needed and so is re-assigned to indicate if the + * driver call was via the normal or fast switch path. Various graphs + * output from the intel_pstate_tracer.py utility that include core_busy + * (or performance or core_avg_perf) have a fixed y-axis from 0 to 100%, + * so we use 10 to indicate the the normal path through the driver, and + * 90 to indicate the fast switch path through the driver. + * The scaled_busy field is not used, and is set to 0. + */ + +#define INTEL_PSTATE_TRACE_TARGET 10 +#define INTEL_PSTATE_TRACE_FAST_SWITCH 90 + +static void intel_cpufreq_trace(struct cpudata *cpu, unsigned int trace_type, int old_pstate) +{ + struct sample *sample; + + if (!trace_pstate_sample_enabled()) + return; + if (!intel_pstate_sample(cpu, ktime_get())) + return; + sample = &cpu->sample; + trace_pstate_sample(trace_type, + 0, + old_pstate, + cpu->pstate.current_pstate, + sample->mperf, + sample->aperf, + sample->tsc, + get_avg_frequency(cpu), + fp_toint(cpu->iowait_boost * 100)); +} + static int intel_cpufreq_target(struct cpufreq_policy *policy, unsigned int target_freq, unsigned int relation) { struct cpudata *cpu = all_cpu_data[policy->cpu]; struct cpufreq_freqs freqs; - int target_pstate; + int target_pstate, old_pstate; update_turbo_state(); @@ -1965,12 +2001,14 @@ static int intel_cpufreq_target(struct cpufreq_policy *policy, break; } target_pstate = intel_pstate_prepare_request(cpu, target_pstate); + old_pstate = cpu->pstate.current_pstate; if (target_pstate != cpu->pstate.current_pstate) { cpu->pstate.current_pstate = target_pstate; wrmsrl_on_cpu(policy->cpu, MSR_IA32_PERF_CTL, pstate_funcs.get_val(cpu, target_pstate)); } freqs.new = target_pstate * cpu->pstate.scaling; + intel_cpufreq_trace(cpu, INTEL_PSTATE_TRACE_TARGET, old_pstate); cpufreq_freq_transition_end(policy, &freqs, false); return 0; @@ -1980,13 +2018,15 @@ static unsigned int intel_cpufreq_fast_switch(struct cpufreq_policy *policy, unsigned int target_freq) { struct cpudata *cpu = all_cpu_data[policy->cpu]; - int target_pstate; + int target_pstate, old_pstate; update_turbo_state(); target_pstate = DIV_ROUND_UP(target_freq, cpu->pstate.scaling); target_pstate = intel_pstate_prepare_request(cpu, target_pstate); + old_pstate = cpu->pstate.current_pstate; intel_pstate_update_pstate(cpu, target_pstate); + intel_cpufreq_trace(cpu, INTEL_PSTATE_TRACE_FAST_SWITCH, old_pstate); return target_pstate * cpu->pstate.scaling; } -- 2.7.4