trusty: move async works off system workqueue
Trusty async works might be very CPU intensive, move
all Trusty works to separate workqueues.
Change-Id: I918ff90206e6c80ce20819b76bc2852f3aff2eb6
Signed-off-by: Michael Ryleev <[email protected]>
diff --git a/drivers/trusty/trusty-irq.c b/drivers/trusty/trusty-irq.c
index 8d6e8af..155122a 100644
--- a/drivers/trusty/trusty-irq.c
+++ b/drivers/trusty/trusty-irq.c
@@ -54,6 +54,7 @@
struct trusty_irq_irqset __percpu *percpu_irqs;
struct notifier_block trusty_call_notifier;
struct notifier_block cpu_notifier;
+ struct workqueue_struct *wq;
};
static void trusty_irq_enable_pending_irqs(struct trusty_irq_state *is,
@@ -216,7 +217,7 @@
}
spin_unlock(&is->normal_irqs_lock);
- schedule_work_on(raw_smp_processor_id(), &trusty_irq_work->work);
+ queue_work_on(raw_smp_processor_id(), is->wq, &trusty_irq_work->work);
dev_dbg(is->dev, "%s: irq %d done\n", __func__, irq);
@@ -524,6 +525,12 @@
goto err_alloc_is;
}
+ is->wq = alloc_workqueue("trusty-irq-wq", WQ_CPU_INTENSIVE, 0);
+ if (!is->wq) {
+ ret = -ENOMEM;
+ goto err_alloc_wq;
+ }
+
is->dev = &pdev->dev;
is->trusty_dev = is->dev->parent;
is->irq_work = alloc_percpu(struct trusty_irq_work);
@@ -602,6 +609,8 @@
}
free_percpu(is->irq_work);
err_alloc_irq_work:
+ destroy_workqueue(is->wq);
+err_alloc_wq:
kfree(is);
err_alloc_is:
return ret;
@@ -636,6 +645,7 @@
flush_work(&trusty_irq_work->work);
}
free_percpu(is->irq_work);
+ destroy_workqueue(is->wq);
kfree(is);
return 0;
diff --git a/drivers/trusty/trusty-virtio.c b/drivers/trusty/trusty-virtio.c
index fabbf29..9a42656 100644
--- a/drivers/trusty/trusty-virtio.c
+++ b/drivers/trusty/trusty-virtio.c
@@ -46,6 +46,8 @@
struct notifier_block call_notifier;
struct list_head vdev_list;
struct mutex mlock; /* protects vdev_list */
+ struct workqueue_struct *kick_wq;
+ struct workqueue_struct *check_wq;
};
struct trusty_vring {
@@ -97,7 +99,7 @@
return NOTIFY_DONE;
tctx = container_of(nb, struct trusty_ctx, call_notifier);
- schedule_work(&tctx->check_vqs);
+ queue_work(tctx->check_wq, &tctx->check_vqs);
return NOTIFY_OK;
}
@@ -143,7 +145,7 @@
struct trusty_ctx *tctx = tvdev->tctx;
atomic_set(&tvr->needs_kick, 1);
- schedule_work(&tctx->kick_vqs);
+ queue_work(tctx->kick_wq, &tctx->kick_vqs);
return true;
}
@@ -633,6 +635,21 @@
INIT_WORK(&tctx->kick_vqs, kick_vqs);
platform_set_drvdata(pdev, tctx);
+ tctx->check_wq = alloc_workqueue("trusty-check-wq", WQ_UNBOUND, 0);
+ if (!tctx->check_wq) {
+ ret = -ENODEV;
+ dev_err(&pdev->dev, "Failed create trusty-check-wq\n");
+ goto err_create_check_wq;
+ }
+
+ tctx->kick_wq = alloc_workqueue("trusty-kick-wq",
+ WQ_UNBOUND | WQ_CPU_INTENSIVE, 0);
+ if (!tctx->kick_wq) {
+ ret = -ENODEV;
+ dev_err(&pdev->dev, "Failed create trusty-kick-wq\n");
+ goto err_create_kick_wq;
+ }
+
ret = trusty_virtio_add_devices(tctx);
if (ret) {
dev_err(&pdev->dev, "Failed to add virtio devices\n");
@@ -643,6 +660,10 @@
return 0;
err_add_devices:
+ destroy_workqueue(tctx->kick_wq);
+err_create_kick_wq:
+ destroy_workqueue(tctx->check_wq);
+err_create_check_wq:
kfree(tctx);
return ret;
}
@@ -662,6 +683,10 @@
trusty_virtio_remove_devices(tctx);
cancel_work_sync(&tctx->kick_vqs);
+ /* destroy workqueues */
+ destroy_workqueue(tctx->kick_wq);
+ destroy_workqueue(tctx->check_wq);
+
/* notify remote that shared area goes away */
trusty_virtio_stop(tctx, tctx->shared_va, tctx->shared_sz);