//#include <linux/kernel_stat.h>
#include <linux/notifier.h>
#include <linux/cpu.h>
+#include <linux/workqueue.h>
#include "appldata.h"
static int appldata_timer_active;
/*
- * Tasklet
+ * Work queue
*/
-static struct tasklet_struct appldata_tasklet_struct;
+static struct workqueue_struct *appldata_wq;
+static void appldata_work_fn(void *data);
+static DECLARE_WORK(appldata_work, appldata_work_fn, NULL);
+
/*
* Ops list
static LIST_HEAD(appldata_ops_list);
-/************************* timer, tasklet, DIAG ******************************/
+/*************************** timer, work, DIAG *******************************/
/*
* appldata_timer_function()
*
- * schedule tasklet and reschedule timer
+ * schedule work and reschedule timer
*/
static void appldata_timer_function(unsigned long data, struct pt_regs *regs)
{
atomic_read(&appldata_expire_count));
if (atomic_dec_and_test(&appldata_expire_count)) {
atomic_set(&appldata_expire_count, num_online_cpus());
- tasklet_schedule((struct tasklet_struct *) data);
+ queue_work(appldata_wq, (struct work_struct *) data);
}
}
/*
- * appldata_tasklet_function()
+ * appldata_work_fn()
*
* call data gathering function for each (active) module
*/
-static void appldata_tasklet_function(unsigned long data)
+static void appldata_work_fn(void *data)
{
struct list_head *lh;
struct appldata_ops *ops;
int i;
- P_DEBUG(" -= Tasklet =-\n");
+ P_DEBUG(" -= Work Queue =-\n");
i = 0;
spin_lock(&appldata_ops_lock);
list_for_each(lh, &appldata_ops_list) {
: "=d" (ry) : "d" (&(appldata_parameter_list)) : "cc");
return (int) ry;
}
-/********************** timer, tasklet, DIAG <END> ***************************/
+/************************ timer, work, DIAG <END> ****************************/
/****************************** /proc stuff **********************************/
struct list_head *lh;
found = 0;
- spin_lock_bh(&appldata_ops_lock);
+ spin_lock(&appldata_ops_lock);
list_for_each(lh, &appldata_ops_list) {
tmp_ops = list_entry(lh, struct appldata_ops, list);
if (&tmp_ops->ctl_table[2] == ctl) {
}
}
if (!found) {
- spin_unlock_bh(&appldata_ops_lock);
+ spin_unlock(&appldata_ops_lock);
return -ENODEV;
}
ops = ctl->data;
if (!try_module_get(ops->owner)) { // protect this function
- spin_unlock_bh(&appldata_ops_lock);
+ spin_unlock(&appldata_ops_lock);
return -ENODEV;
}
- spin_unlock_bh(&appldata_ops_lock);
+ spin_unlock(&appldata_ops_lock);
if (!*lenp || *ppos) {
*lenp = 0;
return -EFAULT;
}
- spin_lock_bh(&appldata_ops_lock);
+ spin_lock(&appldata_ops_lock);
if ((buf[0] == '1') && (ops->active == 0)) {
- if (!try_module_get(ops->owner)) { // protect tasklet
- spin_unlock_bh(&appldata_ops_lock);
+ // protect work queue callback
+ if (!try_module_get(ops->owner)) {
+ spin_unlock(&appldata_ops_lock);
module_put(ops->owner);
return -ENODEV;
}
}
module_put(ops->owner);
}
- spin_unlock_bh(&appldata_ops_lock);
+ spin_unlock(&appldata_ops_lock);
out:
*lenp = len;
*ppos += len;
}
memset(ops->ctl_table, 0, 4*sizeof(struct ctl_table));
- spin_lock_bh(&appldata_ops_lock);
+ spin_lock(&appldata_ops_lock);
list_for_each(lh, &appldata_ops_list) {
tmp_ops = list_entry(lh, struct appldata_ops, list);
P_DEBUG("register_ops loop: %i) name = %s, ctl = %i\n",
APPLDATA_PROC_NAME_LENGTH) == 0) {
P_ERROR("Name \"%s\" already registered!\n", ops->name);
kfree(ops->ctl_table);
- spin_unlock_bh(&appldata_ops_lock);
+ spin_unlock(&appldata_ops_lock);
return -EBUSY;
}
if (tmp_ops->ctl_nr == ops->ctl_nr) {
P_ERROR("ctl_nr %i already registered!\n", ops->ctl_nr);
kfree(ops->ctl_table);
- spin_unlock_bh(&appldata_ops_lock);
+ spin_unlock(&appldata_ops_lock);
return -EBUSY;
}
}
list_add(&ops->list, &appldata_ops_list);
- spin_unlock_bh(&appldata_ops_lock);
+ spin_unlock(&appldata_ops_lock);
ops->ctl_table[0].ctl_name = CTL_APPLDATA;
ops->ctl_table[0].procname = appldata_proc_name;
*/
void appldata_unregister_ops(struct appldata_ops *ops)
{
- spin_lock_bh(&appldata_ops_lock);
+ spin_lock(&appldata_ops_lock);
unregister_sysctl_table(ops->sysctl_header);
list_del(&ops->list);
kfree(ops->ctl_table);
ops->ctl_table = NULL;
- spin_unlock_bh(&appldata_ops_lock);
+ spin_unlock(&appldata_ops_lock);
P_INFO("%s-ops unregistered!\n", ops->name);
}
/********************** module-ops management <END> **************************/
init_virt_timer(&per_cpu(appldata_timer, cpu));
per_cpu(appldata_timer, cpu).function = appldata_timer_function;
per_cpu(appldata_timer, cpu).data = (unsigned long)
- &appldata_tasklet_struct;
+ &appldata_work;
atomic_inc(&appldata_expire_count);
spin_lock(&appldata_timer_lock);
__appldata_vtimer_setup(APPLDATA_MOD_TIMER);
del_virt_timer(&per_cpu(appldata_timer, cpu));
if (atomic_dec_and_test(&appldata_expire_count)) {
atomic_set(&appldata_expire_count, num_online_cpus());
- tasklet_schedule(&appldata_tasklet_struct);
+ queue_work(appldata_wq, &appldata_work);
}
spin_lock(&appldata_timer_lock);
__appldata_vtimer_setup(APPLDATA_MOD_TIMER);
/*
* appldata_init()
*
- * init timer and tasklet, register /proc entries
+ * init timer, register /proc entries
*/
static int __init appldata_init(void)
{
P_DEBUG("sizeof(parameter_list) = %lu\n",
sizeof(struct appldata_parameter_list));
+ appldata_wq = create_singlethread_workqueue("appldata");
+ if (!appldata_wq) {
+ P_ERROR("Could not create work queue\n");
+ return -ENOMEM;
+ }
+
for_each_online_cpu(i)
appldata_online_cpu(i);
appldata_table[1].de->owner = THIS_MODULE;
#endif
- tasklet_init(&appldata_tasklet_struct, appldata_tasklet_function, 0);
P_DEBUG("Base interface initialized.\n");
return 0;
}
/*
* appldata_exit()
*
- * stop timer and tasklet, unregister /proc entries
+ * stop timer, unregister /proc entries
*/
static void __exit appldata_exit(void)
{
/*
* ops list should be empty, but just in case something went wrong...
*/
- spin_lock_bh(&appldata_ops_lock);
+ spin_lock(&appldata_ops_lock);
list_for_each(lh, &appldata_ops_list) {
ops = list_entry(lh, struct appldata_ops, list);
rc = appldata_diag(ops->record_nr, APPLDATA_STOP_REC,
"return code: %d\n", ops->name, rc);
}
}
- spin_unlock_bh(&appldata_ops_lock);
+ spin_unlock(&appldata_ops_lock);
for_each_online_cpu(i)
appldata_offline_cpu(i);
unregister_sysctl_table(appldata_sysctl_header);
- tasklet_kill(&appldata_tasklet_struct);
+ destroy_workqueue(appldata_wq);
P_DEBUG("... module unloaded!\n");
}
/**************************** init / exit <END> ******************************/