All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mark Gross <mgross@linux.intel.com>
To: Randy Dunlap <randy.dunlap@oracle.com>
Cc: Paul Mundt <lethal@linux-sh.org>,
	linux-pm <linux-pm@lists.linux-foundation.org>,
	lkml <linux-kernel@vger.kernel.org>
Subject: Re: [RFC] QoS params patch update.
Date: Thu, 27 Sep 2007 13:17:39 -0700	[thread overview]
Message-ID: <20070927201739.GA2831@linux.intel.com> (raw)
In-Reply-To: <20070926210515.6725e745.randy.dunlap@oracle.com>

On Wed, Sep 26, 2007 at 09:05:15PM -0700, Randy Dunlap wrote:
> On Thu, 27 Sep 2007 11:24:40 +0900 Paul Mundt wrote:
> 
> > > +/* static helper functions */
> > > +static s32 max_compare(s32 v1, s32 v2)
> > > +{
> > > +	if (v1 < v2)
> > > +		return v2;
> > > +	else
> > > +		return v1;
> > > +}
> > > +
> > > +static s32 min_compare(s32 v1, s32 v2)
> > > +{
> > > +	if (v1 < v2)
> > > +		return v1;
> > > +	else
> > > +		return v2;
> > > +}
> > > +
> > min()/max() instead?
> 
> Other code wants function pointers to the min & max functions.
> That's why they are here AFAICT.
> 
> 
> > > +/* assumes qos_lock is held */
> > > +static void update_target(int i)
> > > +{
> > 'target' might be a more meaningful variable name.
> 
> Anything but 'i'.
> 
> ---


Updated qos PM parameter patch:
Note: the replacing of latency.c with this is a separate patch.

this patch attempts to address the issues raised so far.

--mgross



Signed-off-by: mark gross <mgross@linux.intel.com>

mgross@mgross-t43:~/workstuff/power_qos$ diffstat -p1 qos_params_sept_27.patch 
 include/linux/qos_params.h |   35 +++
 kernel/Makefile            |    2 
 kernel/qos_params.c        |  413 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 449 insertions(+), 1 deletion(-)


diff -urN -X linux-2.6.23-rc8/Documentation/dontdiff linux-2.6.23-rc8/include/linux/qos_params.h linux-2.6.23-rc8-qos/include/linux/qos_params.h
--- linux-2.6.23-rc8/include/linux/qos_params.h	1969-12-31 16:00:00.000000000 -0800
+++ linux-2.6.23-rc8-qos/include/linux/qos_params.h	2007-09-27 08:42:54.000000000 -0700
@@ -0,0 +1,35 @@
+/* interface for the qos_power infrastructure of the linux kernel.
+ *
+ * Mark Gross
+ */
+#include <linux/list.h>
+#include <linux/notifier.h>
+#include <linux/miscdevice.h>
+
+struct requirement_list {
+	struct list_head list;
+	union {
+		s32 value;
+		s32 usec;
+		s32 kbps;
+	};
+	char *name;
+};
+
+#define QOS_RESERVED 0
+#define QOS_CPU_DMA_LATENCY 1
+#define QOS_NETWORK_LATENCY 2
+#define QOS_NETWORK_THROUGHPUT 3
+
+#define QOS_NUM_CLASSES 4
+#define QOS_DEFAULT_VALUE -1
+
+int qos_add_requirement(int qos, char *name, s32 value);
+int qos_update_requirement(int qos, char *name, s32 new_value);
+void qos_remove_requirement(int qos, char *name);
+
+int qos_requirement(int qos);
+
+int qos_add_notifier(int qos, struct notifier_block *notifier);
+int qos_remove_notifier(int qos, struct notifier_block *notifier);
+
diff -urN -X linux-2.6.23-rc8/Documentation/dontdiff linux-2.6.23-rc8/kernel/Makefile linux-2.6.23-rc8-qos/kernel/Makefile
--- linux-2.6.23-rc8/kernel/Makefile	2007-09-26 13:54:54.000000000 -0700
+++ linux-2.6.23-rc8-qos/kernel/Makefile	2007-09-26 14:06:38.000000000 -0700
@@ -9,7 +9,7 @@
 	    rcupdate.o extable.o params.o posix-timers.o \
 	    kthread.o wait.o kfifo.o sys_ni.o posix-cpu-timers.o mutex.o \
 	    hrtimer.o rwsem.o latency.o nsproxy.o srcu.o die_notifier.o \
-	    utsname.o
+	    utsname.o qos_params.o
 
 obj-$(CONFIG_STACKTRACE) += stacktrace.o
 obj-y += time/
diff -urN -X linux-2.6.23-rc8/Documentation/dontdiff linux-2.6.23-rc8/kernel/qos_params.c linux-2.6.23-rc8-qos/kernel/qos_params.c
--- linux-2.6.23-rc8/kernel/qos_params.c	1969-12-31 16:00:00.000000000 -0800
+++ linux-2.6.23-rc8-qos/kernel/qos_params.c	2007-09-27 12:46:13.000000000 -0700
@@ -0,0 +1,413 @@
+/*
+ * This module exposes the interface to kernel space for specifying
+ * QoS dependencies.  It provides infrastructure for registration of:
+ *
+ * Dependents on a QoS value : register requirements
+ * Watchers of QoS value : get notified when target QoS value changes
+ *
+ * This QoS design is best effort based.  Dependents register their QoS needs.
+ * Watchers register to keep track of the current QoS needs of the system.
+ *
+ * There are 3 basic classes of QoS parameter: latency, timeout, throughput
+ * each have defined units:
+ * latency: usec
+ * timeout: usec <-- currently not used.
+ * throughput: kbs (kilo byte / sec)
+ *
+ * There are lists of qos_objects each one wrapping requirements, notifiers
+ *
+ * User mode requirements on a QOS parameter register themselves to the
+ * subsystem by opening the device node /dev/... and writing there request to
+ * the node.  As long as the process holds a file handle open to the node the
+ * client continues to be accounted for.  Upon file release the usermode
+ * requirement is removed and a new qos target is computed.  This way when the
+ * requirement that the application has is cleaned up when closes the file
+ * pointer or exits the qos_object will get an opportunity to clean up.
+ *
+ * mark gross mgross@linux.intel.com
+ */
+
+#include <linux/qos_params.h>
+#include <linux/sched.h>
+#include <linux/spinlock.h>
+#include <linux/slab.h>
+#include <linux/time.h>
+#include <linux/fs.h>
+#include <linux/device.h>
+#include <linux/miscdevice.h>
+#include <linux/string.h>
+#include <linux/platform_device.h>
+#include <linux/init.h>
+
+#include <linux/uaccess.h>
+
+/*
+ * locking rule: all changes to target_value or requirements or notifiers lists
+ * or qos_object list and qos_objects need to happen with qos_lock held, taken
+ * with _irqsave.  One lock to rule them all
+ */
+
+struct qos_object {
+	struct requirement_list requirements;
+	struct srcu_notifier_head notifiers;
+	struct miscdevice qos_power_miscdev;
+	char *name;
+	s32 default_value;
+	s32 target_value;
+	s32 (*comparitor)(s32, s32);
+};
+static struct qos_object qos_array[QOS_NUM_CLASSES];
+static DEFINE_SPINLOCK(qos_lock);
+
+static ssize_t qos_power_write(struct file *filp, const char __user *buf,
+		size_t count, loff_t *f_pos);
+static int qos_power_open(struct inode *inode, struct file *filp);
+static int qos_power_release(struct inode *inode, struct file *filp);
+
+static const struct file_operations qos_power_fops = {
+	.write = qos_power_write,
+	.open = qos_power_open,
+	.release = qos_power_release,
+};
+
+/* static helper functions */
+static s32 max_compare(s32 v1, s32 v2)
+{
+	return max(v1, v2);
+}
+
+static s32 min_compare(s32 v1, s32 v2)
+{
+	return min(v1, v2);
+}
+
+/* assumes qos_lock is held */
+static void update_target(int target)
+{
+	s32 extreme_value;
+	struct requirement_list *node;
+
+	extreme_value = qos_array[target].default_value;
+	list_for_each_entry(node, &qos_array[target].requirements.list, list) {
+		extreme_value = qos_array[target].comparitor(
+				extreme_value, node->value);
+	}
+	if (qos_array[target].target_value != extreme_value) {
+		qos_array[target].target_value = extreme_value;
+		printk(KERN_ERR "new target for qos %d is %d\n", target,
+			qos_array[target].target_value);
+		srcu_notifier_call_chain(&qos_array[target].notifiers,
+			(unsigned long) qos_array[target].target_value, NULL);
+	}
+}
+
+static int register_new_qos_misc(struct qos_object *qos)
+{
+	int ret;
+
+	qos->qos_power_miscdev.minor = MISC_DYNAMIC_MINOR;
+	qos->qos_power_miscdev.name = qos->name;
+	qos->qos_power_miscdev.fops = &qos_power_fops;
+
+	ret = misc_register(&qos->qos_power_miscdev);
+
+	return ret;
+}
+
+
+/* constructors */
+static int init_qos_object(int qos_class, const char *name, s32 default_value,
+	s32 (*comparitor)(s32, s32))
+{
+	int ret = -ENOMEM;
+	struct qos_object *qos = NULL;
+
+	if (qos_class < QOS_NUM_CLASSES) {
+		qos = &qos_array[qos_class];
+		qos->name = kstrdup(name, GFP_KERNEL);
+		if (!qos->name)
+			goto cleanup;
+
+		qos->default_value = default_value;
+		qos->target_value = default_value;
+		qos->comparitor = comparitor;
+		srcu_init_notifier_head(&qos->notifiers);
+		INIT_LIST_HEAD(&qos->requirements.list);
+		ret = register_new_qos_misc(qos);
+		if (ret < 0)
+			goto cleanup;
+	} else
+		ret = -EINVAL;
+
+	return ret;
+cleanup:
+	kfree(qos->name);
+
+	return ret;
+}
+
+static int find_qos_object_by_minor(int minor)
+{
+	int qos_class;
+
+	for (qos_class = 0; qos_class < QOS_NUM_CLASSES; qos_class++) {
+		if (minor == qos_array[qos_class].qos_power_miscdev.minor)
+			return qos_class;
+	}
+	return -1;
+}
+
+static int new_latency_qos(int qos_class, const char *name)
+{
+	return init_qos_object(qos_class, name, 2000 * USEC_PER_SEC,
+			min_compare);
+	/* 2000 sec is about infinite */
+}
+
+static int new_throughput_qos(int qos_class, const char *name)
+{
+	return init_qos_object(qos_class, name, 0, max_compare);
+}
+
+/**
+ * qos_requirement - returns current system wide qos expectation
+ * @qos_class: identification of which qos value is requested
+ *
+ * This function returns the current target value in an atomic manner.
+ */
+int qos_requirement(int qos_class)
+{
+	int ret_val;
+	unsigned long flags;
+
+	spin_lock_irqsave(&qos_lock, flags);
+	ret_val = qos_array[qos_class].target_value;
+	spin_unlock_irqrestore(&qos_lock, flags);
+
+	return ret_val;
+}
+EXPORT_SYMBOL_GPL(qos_requirement);
+
+/**
+ * qos_add_requirement - inserts new qos request into the list
+ * @qos_class: identifies which list of qos request to us
+ * @name: identifies the request
+ * @value: defines the qos request
+ *
+ * This function inserts a new entry in the qos_class list of requested qos
+ * performance charactoistics.  It recomputes the agregate QoS expectations for
+ * the qos_class of parrameters.
+ */
+int qos_add_requirement(int qos_class, char *name, s32 value)
+{
+	struct requirement_list *dep;
+	unsigned long flags;
+
+	dep = kzalloc(sizeof(struct requirement_list), GFP_KERNEL);
+	if (dep) {
+		if (value == QOS_DEFAULT_VALUE)
+			dep->value = qos_array[qos_class].default_value;
+		else
+			dep->value = value;
+		dep->name = kstrdup(name, GFP_KERNEL);
+		if (!dep->name)
+			goto cleanup;
+
+		spin_lock_irqsave(&qos_lock, flags);
+		list_add(&dep->list, &qos_array[qos_class].requirements.list);
+		update_target(qos_class);
+		spin_unlock_irqrestore(&qos_lock, flags);
+
+		return 0;
+	}
+
+cleanup:
+	kfree(dep);
+	return -ENOMEM;
+}
+EXPORT_SYMBOL_GPL(qos_add_requirement);
+
+/**
+ * qos_update_requirement - modifies an existing qos request
+ * @qos_class: identifies which list of qos request to us
+ * @name: identifies the request
+ * @value: defines the qos request
+ *
+ * Updates an existing qos requierement for the qos_class of parameters along
+ * with updating the target qos_class value.
+ *
+ * If the named request isn't in the lest then no change is made.
+ */
+int qos_update_requirement(int qos_class, char *name, s32 new_value)
+{
+	unsigned long flags;
+	struct requirement_list *node;
+	int pending_update = 0;
+
+	spin_lock_irqsave(&qos_lock, flags);
+	list_for_each_entry(node,
+		&qos_array[qos_class].requirements.list, list) {
+		if (strcmp(node->name, name) == 0) {
+			if (new_value == QOS_DEFAULT_VALUE)
+				node->value =
+					qos_array[qos_class].default_value;
+			else
+				node->value = new_value;
+			pending_update = 1;
+			break;
+		}
+	}
+	if (pending_update)
+		update_target(qos_class);
+
+	spin_unlock_irqrestore(&qos_lock, flags);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(qos_update_requirement);
+
+/**
+ * qos_remove_requirement - modifies an existing qos request
+ * @qos_class: identifies which list of qos request to us
+ * @name: identifies the request
+ *
+ * Will remove named qos request from qos_class list of parrameters and
+ * recompute the current target value for the qos_class.
+ */
+void qos_remove_requirement(int qos_class, char *name)
+{
+	unsigned long flags;
+	struct requirement_list *node;
+	int pending_update = 0;
+
+	spin_lock_irqsave(&qos_lock, flags);
+	list_for_each_entry(node,
+		&qos_array[qos_class].requirements.list, list) {
+		if (strcmp(node->name, name) == 0) {
+			kfree(node->name);
+			list_del(&node->list);
+			kfree(node);
+			pending_update = 1;
+			break;
+		}
+	}
+	if (pending_update)
+		update_target(qos_class);
+	spin_unlock_irqrestore(&qos_lock, flags);
+}
+EXPORT_SYMBOL_GPL(qos_remove_requirement);
+
+/**
+ * qos_add_notifier - sets notification entry for changes to target value
+ * @qos_class: identifies which qos target changes should be notified.
+ * @notifier: notifier block managed by caller.
+ *
+ * will register the notifier into a notification chain that gets called
+ * uppon changes to the qos_class target value.
+ */
+ int qos_add_notifier(int qos_class, struct notifier_block *notifier)
+{
+	unsigned long flags;
+	int retval;
+
+	spin_lock_irqsave(&qos_lock, flags);
+	retval = srcu_notifier_chain_register(&qos_array[qos_class].notifiers,
+			notifier);
+	spin_unlock_irqrestore(&qos_lock, flags);
+
+	return retval;
+}
+EXPORT_SYMBOL_GPL(qos_add_notifier);
+
+/**
+ * qos_remove_notifier - deletes notification entry from chain.
+ * @qos_class: identifies which qos target changes are notified.
+ * @notifier: notifier block to be removed.
+ *
+ * will remove the notifier from the notification chain that gets called
+ * uppon changes to the qos_class target value.
+ */
+int qos_remove_notifier(int qos_class, struct notifier_block *notifier)
+{
+	unsigned long flags;
+	int retval;
+
+	spin_lock_irqsave(&qos_lock, flags);
+	retval = srcu_notifier_chain_unregister(&qos_array[qos_class].notifiers,
+			notifier);
+	spin_unlock_irqrestore(&qos_lock, flags);
+
+	return retval;
+}
+EXPORT_SYMBOL_GPL(qos_remove_notifier);
+
+#define PID_NAME_LEN sizeof("process_1234567890")
+static char name[PID_NAME_LEN];
+
+static int qos_power_open(struct inode *inode, struct file *filp)
+{
+	int ret;
+	int qos_class;
+
+	qos_class = find_qos_object_by_minor(iminor(inode));
+	if (qos_class >= 0) {
+		filp->private_data = (void *) qos_class;
+		sprintf(name, "process_%d", current->pid);
+		ret = qos_add_requirement(qos_class, name, QOS_DEFAULT_VALUE);
+		if (ret >= 0)
+			return 0;
+	}
+
+	return -EPERM;
+}
+
+static int qos_power_release(struct inode *inode, struct file *filp)
+{
+	int qos_class;
+
+	qos_class = (int) filp->private_data;
+	sprintf(name, "process_%d", current->pid);
+	qos_remove_requirement(qos_class, name);
+
+	return 0;
+}
+
+static ssize_t qos_power_write(struct file *filp, const char __user *buf,
+		size_t count, loff_t *f_pos)
+{
+	s32 value;
+	int qos_class;
+
+	qos_class = (int) filp->private_data;
+	if (count != sizeof(s32))
+		return -EINVAL;
+	if (copy_from_user(&value, buf, sizeof(s32)))
+		return -EFAULT;
+	sprintf(name, "process_%d", current->pid);
+	qos_update_requirement(qos_class, name, value);
+
+	return  sizeof(s32);
+}
+
+
+static int __init qos_power_init(void)
+{
+	int ret = 0;
+	ret = new_latency_qos(QOS_CPU_DMA_LATENCY, "cpu_dma_latency");
+	if (ret < 0) {
+		printk(KERN_ERR "qos_param: cpu_dma_latency setup failed\n");
+		return ret;
+	}
+	ret = new_latency_qos(QOS_NETWORK_LATENCY, "network_latency");
+	if (ret < 0) {
+		printk(KERN_ERR "qos_param: network_latency setup failed\n");
+		return ret;
+	}
+	ret = new_throughput_qos(QOS_NETWORK_THROUGHPUT, "network_throughput");
+	if (ret < 0)
+		printk(KERN_ERR "qos_param: network_throughput setup failed\n");
+
+	return ret;
+}
+
+late_initcall(qos_power_init);

  parent reply	other threads:[~2007-09-27 20:18 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-26 22:37 [RFC] QoS power Management enabling patch set Mark Gross
2007-09-26 22:40 ` [RFC] QoS params patch Mark Gross
2007-09-26 23:41   ` Randy Dunlap
2007-09-27  0:40     ` Mark Gross
2007-09-27  2:53       ` Valdis.Kletnieks
2007-09-27  3:18         ` Paul Mundt
2007-09-27 15:17           ` Mark Gross
2007-09-27 15:17           ` Mark Gross
2007-09-27  3:18         ` Paul Mundt
2007-09-27 15:36         ` Mark Gross
2007-09-27 15:36         ` Mark Gross
2007-09-27  2:53       ` Valdis.Kletnieks
2007-09-27 13:00       ` roel
2007-09-27 13:00       ` roel
2007-09-27  0:40     ` Mark Gross
2007-09-26 23:41   ` Randy Dunlap
2007-09-27  2:24   ` Paul Mundt
2007-09-27  2:24   ` Paul Mundt
2007-09-27  4:05     ` Randy Dunlap
2007-09-27 15:37       ` Mark Gross
2007-09-27 15:37       ` Mark Gross
2007-09-27 20:17       ` Mark Gross [this message]
2007-09-28  0:08         ` [RFC] QoS params patch update Paul Mundt
2007-09-28  0:08         ` Paul Mundt
2007-09-27 20:17       ` Mark Gross
2007-09-27  4:05     ` [RFC] QoS params patch Randy Dunlap
2007-09-27 16:21     ` Mark Gross
2007-09-27 16:21     ` Mark Gross
2007-09-28  6:25   ` Andrew Morton
2007-09-28  6:25   ` Andrew Morton
2007-09-28  6:41     ` Paul Mundt
2007-09-28  6:41     ` Paul Mundt
2007-09-28 17:22       ` Mark Gross
2007-09-28 17:22       ` Mark Gross
2007-09-28 17:19     ` Mark Gross
2007-09-28 18:51       ` Andrew Morton
2007-10-01 16:11         ` Mark Gross
2007-10-01 16:11         ` Mark Gross
2007-09-28 18:51       ` Andrew Morton
2007-09-28 17:19     ` Mark Gross
2007-09-26 22:40 ` Mark Gross
2007-09-26 22:42 ` [RFC] QoS power Management enabling patch set Mark Gross
2007-09-26 22:42 ` Mark Gross
2007-09-26 22:45 ` [RFC] QoS power example / hack Mark Gross
2007-09-26 22:45 ` Mark Gross

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070927201739.GA2831@linux.intel.com \
    --to=mgross@linux.intel.com \
    --cc=lethal@linux-sh.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@lists.linux-foundation.org \
    --cc=randy.dunlap@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.