Skip to contentSkip to conversation

padata: add helper function for queue length

PATCH In review Jason A. Donenfeld 2 participants 3 messages Oct 2, 2016 – Oct 12, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 padata: add helper function for queue length

Since padata has a maximum number of inflight jobs, currently 1000, it's very useful to know how many jobs are currently queued up. This adds a simple helper function to expose this information.

---
 include/linux/padata.h |  2 ++
 kernel/padata.c        | 16 ++++++++++++++++
 2 files changed, 18 insertions(+)
include/linux/padata.h +2 -0
index 113ee62..4840ae4 100644
@@ -3,6 +3,7 @@
  *
  * Copyright (C) 2008, 2009 secunet Security Networks AG
  * Copyright (C) 2008, 2009 Steffen Klassert <[email protected]>
+ * Copyright (C) 2016 Jason A. Donenfeld <[email protected]>
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms and conditions of the GNU General Public License,
@@ -181,4 +182,5 @@ extern int padata_register_cpumask_notifier(struct padata_instance *pinst,
 					    struct notifier_block *nblock);
 extern int padata_unregister_cpumask_notifier(struct padata_instance *pinst,
 					      struct notifier_block *nblock);
+extern int padata_queue_len(struct padata_instance *pinst);
 #endif
kernel/padata.c +16 -0
index 9932788..17c1e08 100644
@@ -5,6 +5,7 @@
  *
  * Copyright (C) 2008, 2009 secunet Security Networks AG
  * Copyright (C) 2008, 2009 Steffen Klassert <[email protected]>
+ * Copyright (C) 2016 Jason A. Donenfeld <[email protected]>
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms and conditions of the GNU General Public License,
@@ -1039,3 +1040,18 @@ void padata_free(struct padata_instance *pinst)
 	kobject_put(&pinst->kobj);
 }
 EXPORT_SYMBOL(padata_free);
+
+/**
+ * padata_queue_len - retreive the number of in progress jobs
+ *
+ * @padata_inst: padata instance from which to read the queue size
+ */
+int padata_queue_len(struct padata_instance *pinst)
+{
+	int len;
+	rcu_read_lock_bh();
+	len = atomic_read(&rcu_dereference_bh(pinst->pd)->refcnt);
+	rcu_read_unlock_bh();
+	return len;
+}
+EXPORT_SYMBOL(padata_queue_len);
Signature · 1 line
2.10.0
maintainer
#1 lore raw
Quoted 49 lines · Jason A. Donenfeld

Since padata has a maximum number of inflight jobs, currently 1000, it's very useful to know how many jobs are currently queued up. This adds a simple helper function to expose this information.

---
 include/linux/padata.h |  2 ++
 kernel/padata.c        | 16 ++++++++++++++++
 2 files changed, 18 insertions(+)
include/linux/padata.h +2 -0
index 113ee62..4840ae4 100644
@@ -3,6 +3,7 @@
  *
  * Copyright (C) 2008, 2009 secunet Security Networks AG
  * Copyright (C) 2008, 2009 Steffen Klassert <[email protected]>
+ * Copyright (C) 2016 Jason A. Donenfeld <[email protected]>
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms and conditions of the GNU General Public License,
@@ -181,4 +182,5 @@ extern int padata_register_cpumask_notifier(struct padata_instance *pinst,
 					    struct notifier_block *nblock);
 extern int padata_unregister_cpumask_notifier(struct padata_instance *pinst,
 					      struct notifier_block *nblock);
+extern int padata_queue_len(struct padata_instance *pinst);
 #endif
kernel/padata.c +6 -0
index 9932788..17c1e08 100644
@@ -5,6 +5,7 @@
  *
  * Copyright (C) 2008, 2009 secunet Security Networks AG
  * Copyright (C) 2008, 2009 Steffen Klassert <[email protected]>
+ * Copyright (C) 2016 Jason A. Donenfeld <[email protected]>
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms and conditions of the GNU General Public License,
@@ -1039,3 +1040,18 @@ void padata_free(struct padata_instance *pinst)
 	kobject_put(&pinst->kobj);
 }
 EXPORT_SYMBOL(padata_free);
+
+/**
+ * padata_queue_len - retreive the number of in progress jobs
+ *
+ * @padata_inst: padata instance from which to read the queue size

kernel/padata.c void padata_free(struct padata_instance *pinst) · line 1057

Quoted 10 lines
kernel/padata.c +10 -0
+ */
+int padata_queue_len(struct padata_instance *pinst)
+{
+	int len;
+	rcu_read_lock_bh();
+	len = atomic_read(&rcu_dereference_bh(pinst->pd)->refcnt);
+	rcu_read_unlock_bh();
+	return len;
+}
+EXPORT_SYMBOL(padata_queue_len);

Why you want to have this? Without having a user of this function, there is no point on adding it.

#2 lore raw

Hi Steffen,

Quoted 1 line · Steffen Klassert

Why you want to have this?

I'm working on some bufferbloat/queue code that could benefit from knowing how many items are currently in flight. The goal is to always keep padata busy, but never with more jobs than absolutely necessary. The model is CoDel.

Regards,
Jason