From patchwork Fri Oct 21 16:56:57 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Guittot X-Patchwork-Id: 4786 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 82A9223DEF for ; Fri, 21 Oct 2011 16:57:10 +0000 (UTC) Received: from mail-yw0-f52.google.com (mail-yw0-f52.google.com [209.85.213.52]) by fiordland.canonical.com (Postfix) with ESMTP id 4AF69A182E2 for ; Fri, 21 Oct 2011 16:57:10 +0000 (UTC) Received: by ywm39 with SMTP id 39so2125223ywm.11 for ; Fri, 21 Oct 2011 09:57:09 -0700 (PDT) Received: by 10.223.85.139 with SMTP id o11mr25993934fal.0.1319216229525; Fri, 21 Oct 2011 09:57:09 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.152.1.71 with SMTP id 7cs22918lak; Fri, 21 Oct 2011 09:57:09 -0700 (PDT) Received: by 10.227.180.74 with SMTP id bt10mr5682926wbb.97.1319216228752; Fri, 21 Oct 2011 09:57:08 -0700 (PDT) Received: from mail-wy0-f178.google.com (mail-wy0-f178.google.com [74.125.82.178]) by mx.google.com with ESMTPS id fc16si10176533wbb.51.2011.10.21.09.57.08 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 21 Oct 2011 09:57:08 -0700 (PDT) Received-SPF: neutral (google.com: 74.125.82.178 is neither permitted nor denied by best guess record for domain of vincent.guittot@linaro.org) client-ip=74.125.82.178; Authentication-Results: mx.google.com; spf=neutral (google.com: 74.125.82.178 is neither permitted nor denied by best guess record for domain of vincent.guittot@linaro.org) smtp.mail=vincent.guittot@linaro.org Received: by wyf28 with SMTP id 28so4820029wyf.37 for ; Fri, 21 Oct 2011 09:57:08 -0700 (PDT) Received: by 10.227.142.1 with SMTP id o1mr5671108wbu.32.1319216228060; Fri, 21 Oct 2011 09:57:08 -0700 (PDT) Received: from localhost.localdomain (pas72-1-88-161-60-229.fbx.proxad.net. [88.161.60.229]) by mx.google.com with ESMTPS id fo7sm22810006wbb.20.2011.10.21.09.57.06 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 21 Oct 2011 09:57:07 -0700 (PDT) From: Vincent Guittot To: linaro-dev@lists.linaro.org Cc: patches@linaro.org, Vincent Guittot Subject: [RFC PATCH 09/11] ARM: cpu topology: Add debugfs interface for cpu_power Date: Fri, 21 Oct 2011 18:56:57 +0200 Message-Id: <1319216217-2693-1-git-send-email-vincent.guittot@linaro.org> X-Mailer: git-send-email 1.7.4.1 Signed-off-by: Vincent Guittot --- arch/arm/kernel/topology.c | 115 ++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 115 insertions(+), 0 deletions(-) diff --git a/arch/arm/kernel/topology.c b/arch/arm/kernel/topology.c index c312937..aee6b44 100644 --- a/arch/arm/kernel/topology.c +++ b/arch/arm/kernel/topology.c @@ -24,6 +24,11 @@ #include #endif +#ifdef CONFIG_DEBUG_FS +#include +#include /* for copy_from_user */ +#endif + #include #include @@ -412,3 +417,113 @@ void init_cpu_topology(void) } smp_wmb(); } + +/* + * debugfs interface for scaling cpu power + */ + +#ifdef CONFIG_DEBUG_FS +static struct dentry *topo_debugfs_root; + +static ssize_t dbg_write(struct file *file, const char __user *buf, + size_t size, loff_t *off) +{ + unsigned int *value = file->f_dentry->d_inode->i_private; + char cdata[128]; + unsigned long tmp; + unsigned int cpu, scale, freq; + + if (size < (sizeof(cdata)-1)) { + if (copy_from_user(cdata, buf, size)) + return -EFAULT; + cdata[size] = 0; + if (!strict_strtoul(cdata, 10, &tmp)) { + *value = tmp; + + for_each_online_cpu(cpu) { + scale = cpu_power[cpu].scale; + freq = cpu_power[cpu].freq; + + per_cpu(cpu_scale, cpu) = + table_cpu_power[scale][freq]; + smp_wmb(); + } + } + return size; + } + return -EINVAL; +} + +static ssize_t dbg_read(struct file *file, char __user *buf, + size_t size, loff_t *off) +{ + unsigned int *value = file->f_dentry->d_inode->i_private; + char cdata[128]; + unsigned int len; + + len = sprintf(cdata, "%u\n", *value); + return simple_read_from_buffer(buf, size, off, cdata, len); +} + +static const struct file_operations debugfs_fops = { + .read = dbg_read, + .write = dbg_write, +}; + +static struct dentry *topo_debugfs_register(unsigned int cpu, + struct dentry *parent) +{ + struct dentry *cpu_d, *d; + char cpu_name[16]; + + sprintf(cpu_name, "cpu%u", cpu); + + cpu_d = debugfs_create_dir(cpu_name, parent); + if (!cpu_d) + return NULL; + + d = debugfs_create_file("cpu_power", S_IRUGO | S_IWUGO, + cpu_d, &per_cpu(cpu_scale, cpu), &debugfs_fops); + if (!d) + goto err_out; + + d = debugfs_create_file("scale", S_IRUGO | S_IWUGO, + cpu_d, &cpu_power[cpu].scale, &debugfs_fops); + if (!d) + goto err_out; + d = debugfs_create_file("freq", S_IRUGO, + cpu_d, &cpu_power[cpu].freq, &debugfs_fops); + if (!d) + goto err_out; + + return cpu_d; + +err_out: + debugfs_remove_recursive(cpu_d); + return NULL; +} + +static int __init topo_debugfs_init(void) +{ + struct dentry *d; + unsigned int cpu; + + d = debugfs_create_dir("cpu_topo", NULL); + if (!d) + return -ENOMEM; + topo_debugfs_root = d; + + for_each_possible_cpu(cpu) { + d = topo_debugfs_register(cpu, topo_debugfs_root); + if (d == NULL) + goto err_out; + } + return 0; + +err_out: + debugfs_remove_recursive(topo_debugfs_root); + return -ENOMEM; +} + +late_initcall(topo_debugfs_init); +#endif