interconnect: Add debugfs test code
Allow setting constraints from userspace for more convenient testing. Example usage: cd /sys/kernel/debug/interconnect-test/ echo -n 3 > src_port echo -n 53 > dst_port echo -n 1 > get echo -n 80000000 > avg_bw echo -n 90000000 > peak_bw echo -n 1 > commit Change-Id: I8a47c45a8060607470edc870b1eb4245bb7ffc54 Signed-off-by: Georgi Djakov <georgi.djakov@linaro.org> Signed-off-by: David Dai <daidavid1@codeaurora.org> Git-commit: 8b9e75c3e826f6a719ff02fa409f6b9c92aee66c Git-repo: https://git.linaro.org/people/georgi.djakov/linux.git Signed-off-by: Georgi Djakov <gdjako@codeaurora.org>
This commit is contained in:
parent
7ac860672f
commit
fcd2ba62ee
@ -11,6 +11,16 @@ menuconfig INTERCONNECT
|
||||
|
||||
if INTERCONNECT
|
||||
|
||||
menuconfig INTERCONNECT_TEST
|
||||
tristate "Debugfs test"
|
||||
depends on DEBUG_FS
|
||||
help
|
||||
Expose the interconnect API to userspace for testing purposes. This
|
||||
will create /sys/kernel/debug/interconnect-test to allow requesting
|
||||
bandwidth between endpoints.
|
||||
|
||||
If unsure, say no.
|
||||
|
||||
source "drivers/interconnect/imx/Kconfig"
|
||||
source "drivers/interconnect/qcom/Kconfig"
|
||||
source "drivers/interconnect/samsung/Kconfig"
|
||||
|
@ -2,8 +2,10 @@
|
||||
|
||||
CFLAGS_core.o := -I$(src)
|
||||
icc-core-objs := core.o bulk.o
|
||||
icc-test-objs := debugfs-test.o
|
||||
|
||||
obj-$(CONFIG_INTERCONNECT) += icc-core.o
|
||||
obj-$(CONFIG_INTERCONNECT_TEST) += icc-test.o
|
||||
obj-$(CONFIG_INTERCONNECT_IMX) += imx/
|
||||
obj-$(CONFIG_INTERCONNECT_QCOM) += qcom/
|
||||
obj-$(CONFIG_INTERCONNECT_SAMSUNG) += samsung/
|
||||
|
115
drivers/interconnect/debugfs-test.c
Normal file
115
drivers/interconnect/debugfs-test.c
Normal file
@ -0,0 +1,115 @@
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
/*
|
||||
* Copyright (c) 2017, Linaro Ltd.
|
||||
*
|
||||
* This software is licensed under the terms of the GNU General Public
|
||||
* License version 2, as published by the Free Software Foundation, and
|
||||
* may be copied, distributed, and modified under those terms.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
#ifdef CONFIG_DEBUG_FS
|
||||
|
||||
#include <linux/debugfs.h>
|
||||
#include <linux/interconnect.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/uaccess.h>
|
||||
|
||||
static struct platform_device *icc_pdev;
|
||||
static struct dentry *debugfs_dir;
|
||||
static struct icc_path *path;
|
||||
static u32 src_port;
|
||||
static u32 dst_port;
|
||||
|
||||
static u32 avg_bw;
|
||||
static u32 peak_bw;
|
||||
|
||||
static ssize_t get_write_op(struct file *file, char const __user *buf,
|
||||
size_t count, loff_t *ppos)
|
||||
{
|
||||
unsigned long val;
|
||||
int ret;
|
||||
|
||||
ret = kstrtoul_from_user(buf, count, 10, &val);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
path = icc_get(&icc_pdev->dev, src_port, dst_port);
|
||||
if (IS_ERR(path))
|
||||
return PTR_ERR(path);
|
||||
|
||||
*ppos += count;
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
static const struct file_operations get_fops = {
|
||||
.owner = THIS_MODULE,
|
||||
.write = get_write_op
|
||||
};
|
||||
|
||||
static ssize_t commit_write_op(struct file *file, char const __user *buf,
|
||||
size_t count, loff_t *ppos)
|
||||
{
|
||||
unsigned long val;
|
||||
int ret;
|
||||
|
||||
ret = kstrtoul_from_user(buf, count, 10, &val);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
if (IS_ERR(path))
|
||||
return PTR_ERR(path);
|
||||
|
||||
ret = icc_set_bw(path, avg_bw, peak_bw);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
*ppos += count;
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
static const struct file_operations commit_fops = {
|
||||
.owner = THIS_MODULE,
|
||||
.write = commit_write_op
|
||||
};
|
||||
|
||||
static void __exit icc_test_exit(void)
|
||||
{
|
||||
if (!IS_ERR(path))
|
||||
icc_put(path);
|
||||
|
||||
debugfs_remove_recursive(debugfs_dir);
|
||||
platform_device_del(icc_pdev);
|
||||
platform_device_put(icc_pdev);
|
||||
}
|
||||
|
||||
static int __init icc_test_init(void)
|
||||
{
|
||||
icc_pdev = platform_device_alloc("icc-test", PLATFORM_DEVID_AUTO);
|
||||
platform_device_add(icc_pdev);
|
||||
|
||||
debugfs_dir = debugfs_create_dir("interconnect-test", NULL);
|
||||
if (!debugfs_dir)
|
||||
pr_err("interconnect: error creating debugfs directory\n");
|
||||
|
||||
debugfs_create_u32("src_port", 0600, debugfs_dir, &src_port);
|
||||
debugfs_create_u32("dst_port", 0600, debugfs_dir, &dst_port);
|
||||
debugfs_create_file("get", 0200, debugfs_dir, NULL, &get_fops);
|
||||
debugfs_create_u32("avg_bw", 0600, debugfs_dir, &avg_bw);
|
||||
debugfs_create_u32("peak_bw", 0600, debugfs_dir, &peak_bw);
|
||||
debugfs_create_file("commit", 0200, debugfs_dir, NULL, &commit_fops);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
module_init(icc_test_init);
|
||||
module_exit(icc_test_exit);
|
||||
MODULE_LICENSE("GPL v2");
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user