From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756873AbcJ3Amh (ORCPT ); Sat, 29 Oct 2016 20:42:37 -0400 Received: from mail-pf0-f173.google.com ([209.85.192.173]:32921 "EHLO mail-pf0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756286AbcJ3Ake (ORCPT ); Sat, 29 Oct 2016 20:40:34 -0400 From: David Carrillo-Cisneros To: linux-kernel@vger.kernel.org Cc: "x86@kernel.org" , Ingo Molnar , Thomas Gleixner , Andi Kleen , Kan Liang , Peter Zijlstra , Vegard Nossum , Marcelo Tosatti , Nilay Vaish , Borislav Petkov , Vikas Shivappa , Ravi V Shankar , Fenghua Yu , Paul Turner , Stephane Eranian , David Carrillo-Cisneros Subject: [PATCH v3 39/46] perf/x86/intel/cmt: add max_recycle_threshold sysfs attribute Date: Sat, 29 Oct 2016 17:38:36 -0700 Message-Id: <1477787923-61185-40-git-send-email-davidcc@google.com> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 In-Reply-To: <1477787923-61185-1-git-send-email-davidcc@google.com> References: <1477787923-61185-1-git-send-email-davidcc@google.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Expose max_recycle_threshold as a configurable sysfs attribute of intel_cmt pmu. max_recycle_threshold determines the maximum dirty threshold for rmids with no zero occupancy. Signed-off-by: David Carrillo-Cisneros --- arch/x86/events/intel/cmt.c | 57 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/arch/x86/events/intel/cmt.c b/arch/x86/events/intel/cmt.c index 649eb5f..05803a8 100644 --- a/arch/x86/events/intel/cmt.c +++ b/arch/x86/events/intel/cmt.c @@ -61,6 +61,7 @@ static struct pkg_data **cmt_pkgs_data; * @__cmt_pre_mon_slice: Min time a monr is monitored before being readable. * @__cmt_min_mon_slice: Min time a monr stays monitored after becoming * readable. + * @__cmt_max_threshold: Max bytes of error due to reusing dirty rmids. */ #define CMT_DEFAULT_PRE_MON_SLICE 2000 /* ms */ static u64 __cmt_pre_mon_slice; @@ -68,6 +69,7 @@ static u64 __cmt_pre_mon_slice; #define CMT_DEFAULT_MIN_MON_SLICE 5000 /* ms */ static u64 __cmt_min_mon_slice; +static unsigned int __cmt_max_threshold; /* bytes */ /* * If @pkgd == NULL, return first online, pkg_data in cmt_pkgs_data. @@ -1831,9 +1833,54 @@ static struct attribute_group intel_cmt_format_group = { .attrs = intel_cmt_formats_attr, }; +static ssize_t max_recycle_threshold_show(struct device *dev, + struct device_attribute *attr, char *page) +{ + ssize_t rv; + + mutex_lock(&cmt_mutex); + rv = snprintf(page, PAGE_SIZE - 1, "%u\n", + READ_ONCE(__cmt_max_threshold)); + + mutex_unlock(&cmt_mutex); + return rv; +} + +static ssize_t max_recycle_threshold_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + unsigned int bytes; + int err; + + err = kstrtouint(buf, 0, &bytes); + if (err) + return err; + + mutex_lock(&cmt_mutex); + monr_hrchy_acquire_mutexes(); + WRITE_ONCE(__cmt_max_threshold, bytes); + monr_hrchy_release_mutexes(); + mutex_unlock(&cmt_mutex); + + return count; +} + +static DEVICE_ATTR_RW(max_recycle_threshold); + +static struct attribute *intel_cmt_attrs[] = { + &dev_attr_max_recycle_threshold.attr, + NULL, +}; + +static const struct attribute_group intel_cmt_group = { + .attrs = intel_cmt_attrs, +}; + static const struct attribute_group *intel_cmt_attr_groups[] = { &intel_cmt_events_group, &intel_cmt_format_group, + &intel_cmt_group, NULL, }; @@ -2270,6 +2317,16 @@ static int __init cmt_start(void) if (err) goto rm_prep; + /* + * A reasonable default upper limit on the max threshold is half of + * the number of lines tagged per RMID if all RMIDs had the same + * number of lines tagged in the LLC. + * + * For a 35MB LLC and 56 RMIDs, this is ~0.9% of the LLC or 320 KBs. + */ + __cmt_max_threshold = boot_cpu_data.x86_cache_size * 1024 / + (2 * (__min_max_rmid + 1)); + snprintf(scale, sizeof(scale), "%u", cmt_l3_scale); str = kstrdup(scale, GFP_KERNEL); if (!str) { -- 2.8.0.rc3.226.g39d4020