RDMA/rxe: Replace use of system_unbound_wq with system_dfl_wq
Subsystems (2)
PATCH 1/1 RDMA/rxe: Replace use of system_unbound_wq with system_dfl_wq
This patch continues the effort to refactor workqueue APIs, which has begun with the changes introducing new workqueues and a new alloc_workqueue flag:
commit 128ea9f6ccfb ("workqueue: Add system_percpu_wq and system_dfl_wq") commit 930c2ea566af ("workqueue: Add new WQ_PERCPU flag")
The point of the refactoring is to eventually alter the default behavior of workqueues to become unbound by default so that their workload placement is optimized by the scheduler.
Before that to happen, workqueue users must be converted to the better named new workqueues with no intended behaviour changes:
system_wq -> system_percpu_wq
system_unbound_wq -> system_dfl_wq
This way the old obsolete workqueues (system_wq, system_unbound_wq) can be removed in the future.
--- drivers/infiniband/sw/rxe/rxe_odp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/sw/rxe/rxe_odp.c +1 -1
@@ -545,7 +545,7 @@ static int rxe_ib_advise_mr_prefetch(struct ib_pd *ibpd, work->frags[i].mr = mr; } -queue_work (system_unbound_wq, &work->work); +queue_work (system_dfl_wq, &work->work);return 0 ;
Signature · 1 line
2.53.0
Quoted 16 lines · Marco Crivellari
This patch continues the effort to refactor workqueue APIs, which has begun with the changes introducing new workqueues and a new
alloc_workqueueflag:commit
128ea9f6ccfb("workqueue: Addsystem_percpu_wqandsystem_dfl_wq") commit930c2ea566af("workqueue: Add newWQ_PERCPUflag")The point of the refactoring is to eventually alter the default behavior of workqueues to become unbound by default so that their workload placement is optimized by the scheduler.
Before that to happen, workqueue users must be converted to the better named new workqueues with no intended behaviour changes:
system_wq -> system_percpu_wq system_unbound_wq -> system_dfl_wq
Quoted 6 lines
This way the old obsolete workqueues (
system_wq,system_unbound_wq) can be removed in the future.Suggested-by Tejun Heo <[email protected]>Signed-off-by Marco Crivellari <[email protected]>
This patch is part of a broader effort to clarify workqueue semantics. As discussed in the recent thread at https://lore.kernel.org/all/[email protected]/], the move towards system_dfl_wq is not just a renaming exercise; it's about ensuring work items correctly respect the system's housekeeping CPUMASK.
To RXE, it is a software-defined RDMA transport. RXE does not have strict hardware-to-CPU affinity requirements. Specifically for the ODP prefetch path modified here:
1. Prefetching doesn't rely on being executed on the local CPU where the advise_mr was called.
2. The locality benefits of per-cpu execution are negligible compared to the importance of system-wide jitter reduction, especially in NOHZ_FULL environments.
3. By using system_dfl_wq, we allow the scheduler to offload prefetch tasks from isolated CPUs to housekeeping CPUs, which is a desirable behavior for real-time users.
The patch is safe, logically sound, and aligns with the current kernel-wide modernization of workqueue placement.
I have made tests with this commit. It can work well in functionality.
I am fine with this.
Zhu Yanjun
Quoted 17 lines
--- drivers/infiniband/sw/rxe/rxe_odp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/infiniband/sw/rxe/rxe_odp.c +1
-1@@ -545,7 +545,7 @@ static int rxe_ib_advise_mr_prefetch(struct ib_pd *ibpd, work->frags[i].mr = mr; } -queue_work (system_unbound_wq, &work->work); +queue_work (system_dfl_wq, &work->work);return 0 ;
Quoted 10 lines · Marco Crivellari
This patch continues the effort to refactor workqueue APIs, which has begun with the changes introducing new workqueues and a new
alloc_workqueueflag:commit
128ea9f6ccfb("workqueue: Addsystem_percpu_wqandsystem_dfl_wq") commit930c2ea566af("workqueue: Add newWQ_PERCPUflag")The point of the refactoring is to eventually alter the default behavior of workqueues to become unbound by default so that their workload placement is optimized by the scheduler.
Quoted 8 lines
Before that to happen, workqueue users must be converted to the better named new workqueues with no intended behaviour changes:
system_wq -> system_percpu_wq system_unbound_wq -> system_dfl_wqThis way the old obsolete workqueues (
system_wq,system_unbound_wq) can be removed in the future.
I recall earlier efforts to replace system workqueues with per‑driver queues, because unloading a driver forces a flush of the entire system workqueue, which is undesirable for overall system behavior.
Wouldn't it be better to introduce a local workqueue here and use that instead?
Thanks
Quoted 24 lines
Suggested-by Tejun Heo <[email protected]>Signed-off-by Marco Crivellari <[email protected]>--- drivers/infiniband/sw/rxe/rxe_odp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/infiniband/sw/rxe/rxe_odp.c +1
-1@@ -545,7 +545,7 @@ static int rxe_ib_advise_mr_prefetch(struct ib_pd *ibpd, work->frags[i].mr = mr; } -queue_work (system_unbound_wq, &work->work); +queue_work (system_dfl_wq, &work->work);return 0 ;Signature · 1 line
2.53.0
Quoted 8 lines · Leon Romanovsky
[...]
I recall earlier efforts to replace system workqueues with per‑driver queues, because unloading a driver forces a flush of the entire system workqueue, which is undesirable for overall system behavior.Wouldn't it be better to introduce a local workqueue here and use that instead?
Thanks
Hi,
There is only this wq here. But we can do so if needed, no problem.
Where do you think is the most appropriate place for the workqueue struct declaration? Like struct prefetch_mr_work maybe?
Do you have suggestions for an appropriate place to allocate the workqueue?
Thanks!
Signature · 3 lines
Marco Crivellari L3 Support Engineer
Quoted 10 lines · Marco Crivellari
Quoted 8 lines · Leon Romanovsky
[...]
I recall earlier efforts to replace system workqueues with per‑driver queues, because unloading a driver forces a flush of the entire system workqueue, which is undesirable for overall system behavior.Wouldn't it be better to introduce a local workqueue here and use that instead?
Thanks
Quoted 8 lines
Hi,
There is only this wq here. But we can do so if needed, no problem.
Where do you think is the most appropriate place for the workqueue struct declaration? Like
struct prefetch_mr_workmaybe?Do you have suggestions for an appropriate place to allocate the workqueue?
Actually, RXE already have one workqueue in rxe_alloc_wq(), just use it.
Thanks
Quoted 8 lines
Thanks!
Signature · 3 lines
Marco Crivellari L3 Support Engineer
Quoted 4 lines · Leon Romanovsky
[...]
Actually, RXE already have one workqueue inrxe_alloc_wq(), just use it.Thanks
Thanks Leon, I will do as you suggested in the v2.
Signature · 3 lines
Marco Crivellari L3 Support Engineer
Quoted 3 lines · Leon Romanovsky
[...]
Actually, RXE already have one workqueue in
rxe_alloc_wq(), just use it.
Hi Leon,
I noticed the workqueue is declared as static into a C file. So I changed it a bit, tell me if
it's not the right approach.
You can see the diff below:
---
drivers/infiniband/sw/rxe/rxe.h +0 -0
@@ -121,4 +121,6 @@ void rxe_port_up(struct rxe_dev *rxe);
void rxe_port_down(struct rxe_dev *rxe);
void rxe_set_port_state(struct rxe_dev *rxe);
+extern struct workqueue_struct *rxe_wq;
+
#endif /* RXE_H */
(quoted diff) +0 -0
b/drivers/infiniband/sw/rxe/rxe_odp.c
index d440c8cbaea5..ff904d5e54a7 100644
drivers/infiniband/sw/rxe/rxe_odp.c +1 -1
@@ -545,7 +545,7 @@ static int rxe_ib_advise_mr_prefetch(struct ib_pd *ibpd, work->frags[i].mr = mr; } -queue_work (system_dfl_wq, &work->work); +queue_work (rxe_wq, &work->work);return 0 ;
(quoted diff) +0 -0
b/drivers/infiniband/sw/rxe/rxe_task.c
index f522820b950c..801d06c969c9 100644
drivers/infiniband/sw/rxe/rxe_task.c +0 -0
@@ -6,7 +6,7 @@
#include "rxe.h"
-static struct workqueue_struct *rxe_wq;
+struct workqueue_struct *rxe_wq;
int rxe_alloc_wq(void)
{
---
Thanks!
Signature · 3 lines
Marco Crivellari L3 Support Engineer
Quoted 19 lines · Marco Crivellari
Quoted 3 lines · Leon Romanovsky
[...]
Actually, RXE already have one workqueue in
rxe_alloc_wq(), just use it.Hi Leon,
I noticed the workqueue is declared as static into a C file. So I changed it a bit, tell me if
it's not the right approach.
You can see the diff below:---
drivers/infiniband/sw/rxe/rxe.h +0
-0
drivers/infiniband/sw/rxe/rxe.h void rxe_port_up(struct rxe_dev *rxe); · line 124
Quoted 4 lines
drivers/infiniband/sw/rxe/rxe.h +1
-0@@ -121,4 +121,6 @@ void rxe_port_up(struct rxe_dev *rxe);void rxe_port_down (struct rxe_dev *rxe);void rxe_set_port_state (struct rxe_dev *rxe); +extern struct workqueue_struct *rxe_wq;
Hi, Marco
https://patchwork.kernel.org/project/linux-rdma/patch/[email protected]/
Please see the above link. A fix has already been ready for this problem.
Zhu Yanjun
Quoted 35 lines
drivers/infiniband/sw/rxe/rxe.h +1
-0+#endif /* RXE_H */ drivers/infiniband/sw/rxe/rxe_odp.c +1
-1@@ -545,7 +545,7 @@ static int rxe_ib_advise_mr_prefetch(struct ib_pd *ibpd, work->frags[i].mr = mr; } -queue_work (system_dfl_wq, &work->work); +queue_work (rxe_wq, &work->work);return 0 ;drivers/infiniband/sw/rxe/rxe_task.c +1
-2@@ -6,7 +6,7 @@#include "rxe.h" -static struct workqueue_struct *rxe_wq; +struct workqueue_struct *rxe_wq;int rxe_alloc_wq (void ) { ---Thanks!
Quoted 10 lines · Marco Crivellari
Quoted 3 lines · Leon Romanovsky
[...]
Actually, RXE already have one workqueue in
rxe_alloc_wq(), just use it.Hi Leon,
I noticed the workqueue is declared as static into a C file. So I changed it a bit, tell me if
it's not the right approach.
Your fix is the most accurate and technically sound among all proposals.
Thanks
Quoted 53 lines
You can see the diff below:
---
drivers/infiniband/sw/rxe/rxe.h +2
-0@@ -121,4 +121,6 @@ void rxe_port_up(struct rxe_dev *rxe);void rxe_port_down (struct rxe_dev *rxe);void rxe_set_port_state (struct rxe_dev *rxe); +extern struct workqueue_struct *rxe_wq; +#endif /* RXE_H */ drivers/infiniband/sw/rxe/rxe_odp.c +1
-1@@ -545,7 +545,7 @@ static int rxe_ib_advise_mr_prefetch(struct ib_pd *ibpd, work->frags[i].mr = mr; } -queue_work (system_dfl_wq, &work->work); +queue_work (rxe_wq, &work->work);return 0 ;drivers/infiniband/sw/rxe/rxe_task.c +1
-2@@ -6,7 +6,7 @@#include "rxe.h" -static struct workqueue_struct *rxe_wq; +struct workqueue_struct *rxe_wq;int rxe_alloc_wq (void ) { ---Thanks!
Signature · 3 lines
Marco Crivellari L3 Support Engineer
Quoted 8 lines · Leon Romanovsky
[...]
Quoted 3 lines
I noticed the workqueue is declared as static into a C file. So I changed it a bit, tell me if
it's not the right approach.Your fix is the most accurate and technically sound among all proposals.
Thanks
Thanks for your feedback Leon. I will send the v2 with the above code.
Signature · 3 lines
Marco Crivellari L3 Support Engineer
Quoted 17 lines · Leon Romanovsky
Quoted 16 lines · Marco Crivellari
This patch continues the effort to refactor workqueue APIs, which has begun with the changes introducing new workqueues and a new
alloc_workqueueflag:commit
128ea9f6ccfb("workqueue: Addsystem_percpu_wqandsystem_dfl_wq") commit930c2ea566af("workqueue: Add newWQ_PERCPUflag")The point of the refactoring is to eventually alter the default behavior of workqueues to become unbound by default so that their workload placement is optimized by the scheduler.
Before that to happen, workqueue users must be converted to the better named new workqueues with no intended behaviour changes:
system_wq -> system_percpu_wq system_unbound_wq -> system_dfl_wq
Quoted 8 lines
Quoted 2 lines
This way the old obsolete workqueues (
system_wq,system_unbound_wq) can be removed in the future.I recall earlier efforts to replace system workqueues with per‑driver queues, because unloading a driver forces a flush of the entire system workqueue, which is undesirable for overall system behavior.
Wouldn't it be better to introduce a local workqueue here and use that instead?
Thanks.
1.The initialization should be:
my_wq = alloc_workqueue("my_driver_queue", WQ_UNBOUND | WQ_MEM_RECLAIM, 0); if (!my_wq)
return -ENOMEM;
2. The Submission should be:
queue_work(my_wq, &my_work);
3. Destroy should be:
destroy_workqueue()
Thanks,
Zhu Yanjun
Quoted 27 lines
Thanks
Quoted 24 lines
Suggested-by Tejun Heo <[email protected]>Signed-off-by Marco Crivellari <[email protected]>--- drivers/infiniband/sw/rxe/rxe_odp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/infiniband/sw/rxe/rxe_odp.c +1
-1@@ -545,7 +545,7 @@ static int rxe_ib_advise_mr_prefetch(struct ib_pd *ibpd, work->frags[i].mr = mr; } -queue_work (system_unbound_wq, &work->work); +queue_work (system_dfl_wq, &work->work);return 0 ;Signature · 1 line
2.53.0
Quoted 37 lines · Zhu Yanjun
Quoted 17 lines · Leon Romanovsky
Quoted 16 lines · Marco Crivellari
This patch continues the effort to refactor workqueue APIs, which has begun with the changes introducing new workqueues and a new
alloc_workqueueflag:commit
128ea9f6ccfb("workqueue: Addsystem_percpu_wqandsystem_dfl_wq") commit930c2ea566af("workqueue: Add newWQ_PERCPUflag")The point of the refactoring is to eventually alter the default behavior of workqueues to become unbound by default so that their workload placement is optimized by the scheduler.
Before that to happen, workqueue users must be converted to the better named new workqueues with no intended behaviour changes:
system_wq->system_percpu_wq
system_unbound_wq->system_dfl_wqQuoted 8 lines
Quoted 2 lines
This way the old obsolete workqueues (
system_wq,system_unbound_wq) can be removed in the future.I recall earlier efforts to replace system workqueues with per‑driver queues, because unloading a driver forces a flush of the entire system workqueue, which is undesirable for overall system behavior.
Wouldn't it be better to introduce a local workqueue here and use that instead?
Thanks.
1.The initialization should be:
my_wq=alloc_workqueue("my_driver_queue", WQ_UNBOUND | WQ_MEM_RECLAIM, 0); if (!my_wq)
return-ENOMEM;2. The Submission should be:
Quoted 8 lines
queue_work(my_wq, &my_work);3. Destroy should be:
destroy_workqueue()Thanks,
Zhu Yanjun
Hi, Leon
The diff for a new work queue in rxe is as below. Please review it.
drivers/infiniband/sw/rxe/rxe_odp.c +0 -0
@@ -545,7 +545,7 @@ static int rxe_ib_advise_mr_prefetch(struct ib_pd *ibpd,
work->frags[i].mr = mr;
}
- queue_work(system_unbound_wq, &work->work);
+ rxe_queue_aux_work(&work->work);
return 0;
drivers/infiniband/sw/rxe/rxe_task.c +0 -0
@@ -6,19 +6,36 @@
#include "rxe.h"
+/* work for rxe_task */
static struct workqueue_struct *rxe_wq;
+/* work for other rxe jobs */
+static struct workqueue_struct *rxe_aux_wq;
+
int rxe_alloc_wq(void)
{
- rxe_wq = alloc_workqueue("rxe_wq", WQ_UNBOUND, WQ_MAX_ACTIVE); + rxe_wq = alloc_workqueue("rxe_wq", WQ_UNBOUND | WQ_MEM_RECLAIM, + WQ_MAX_ACTIVE);
if (!rxe_wq)
return -ENOMEM;
+ rxe_aux_wq = alloc_workqueue("rxe_aux_wq",
+ WQ_UNBOUND | WQ_MEM_RECLAIM, WQ_MAX_ACTIVE); + if (!rxe_aux_wq) {
+ destroy_workqueue(rxe_wq);
+ return -ENOMEM;
+
+ }
+
return 0;
}
void rxe_destroy_wq(void)
{
+ flush_workqueue(rxe_aux_wq);
+ destroy_workqueue(rxe_aux_wq);
+
+ flush_workqueue(rxe_wq);
destroy_workqueue(rxe_wq);
}
@@ -254,6 +271,14 @@ void rxe_sched_task(struct rxe_task *task) spin_unlock_irqrestore(&task->lock, flags);
}
+/* rxe_wq for rxe tasks. rxe_aux_wq for other rxe jobs.
+ */
+void rxe_queue_aux_work(struct work_struct *work) +{
+ WARN_ON_ONCE(!rxe_aux_wq);
+ queue_work(rxe_aux_wq, work);
+}
+
/* rxe_disable/enable_task are only called from
* rxe_modify_qp in process context. Task is moved
* to the drained state by do_task.
drivers/infiniband/sw/rxe/rxe_task.h +0 -0
@@ -36,6 +36,7 @@ int rxe_alloc_wq(void);
void rxe_destroy_wq(void);
+void rxe_queue_aux_work(struct work_struct *work); /*
* init rxe_task structure
* qp => parameter to pass to func
Zhu Yanjun
Quoted 27 lines
Quoted 26 lines
Thanks
Quoted 22 lines
Suggested-by Tejun Heo <[email protected]>Signed-off-by Marco Crivellari <[email protected]>---
drivers/infiniband/sw/rxe/rxe_odp.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)drivers/infiniband/sw/rxe/rxe_odp.c +1
-0@@ -545,7 +545,7 @@ static int rxe_ib_advise_mr_prefetch(structib_pd *ibpd, work->frags[i].mr = mr; } - queue_work(system_unbound_wq, &work->work); + queue_work(system_dfl_wq, &work->work); return 0;--
2.53.0
Quoted 54 lines · Yanjun.Zhu
Quoted 52 lines · Zhu Yanjun
Quoted 27 lines · Leon Romanovsky
Quoted 19 lines · Marco Crivellari
This patch continues the effort to refactor workqueue APIs, which has begun
with the changes introducing new workqueues and a newalloc_workqueueflag:commit
128ea9f6ccfb("workqueue: Addsystem_percpu_wqandsystem_dfl_wq")
commit930c2ea566af("workqueue: Add newWQ_PERCPUflag")The point of the refactoring is to eventually alter the default behavior of
workqueues to become unbound by default so that their workload placement is
optimized by the scheduler.Before that to happen, workqueue users must be converted to the better named
new workqueues with no intended behaviour changes:Quoted 6 lines
system_wq->system_percpu_wq
system_unbound_wq->system_dfl_wqThis way the old obsolete workqueues (
system_wq,system_unbound_wq) can be
removed in the future.Quoted 8 lines
I recall earlier efforts to replace system workqueues with per‑driver queues,
because unloading a driver forces a flush of the entire system workqueue,
which is undesirable for overall system behavior.Wouldn't it be better to introduce a local workqueue here and use that instead?
Thanks.
1.The initialization should be:
my_wq=alloc_workqueue("my_driver_queue", WQ_UNBOUND | WQ_MEM_RECLAIM, 0);
if (!my_wq)
return-ENOMEM;2. The Submission should be:
queue_work(my_wq, &my_work);3. Destroy should be:
Quoted 8 lines
Quoted 4 lines
destroy_workqueue()Thanks,
Zhu YanjunHi, Leon
The diff for a new work queue in rxe is as below. Please review it.
I'm not sure that you need second workqueue and destroy_workqueue already does flush_workqueue. There is no need to call it explicitly.
Thanks
Quoted 120 lines
drivers/infiniband/sw/rxe/rxe_odp.c +1
-1@@ -545,7 +545,7 @@ static int rxe_ib_advise_mr_prefetch(struct ib_pd *ibpd, work->frags[i].mr = mr; } - queue_work(system_unbound_wq, &work->work); + rxe_queue_aux_work(&work->work); return 0;drivers/infiniband/sw/rxe/rxe_task.c +26
-1@@ -6,19 +6,36 @@ #include "rxe.h" +/* work for rxe_task */ static struct workqueue_struct *rxe_wq; +/* work for other rxe jobs */ +static struct workqueue_struct *rxe_aux_wq; + int rxe_alloc_wq(void) { - rxe_wq = alloc_workqueue("rxe_wq", WQ_UNBOUND, WQ_MAX_ACTIVE); + rxe_wq = alloc_workqueue("rxe_wq", WQ_UNBOUND | WQ_MEM_RECLAIM, + WQ_MAX_ACTIVE); if (!rxe_wq) return -ENOMEM; + rxe_aux_wq = alloc_workqueue("rxe_aux_wq", + WQ_UNBOUND | WQ_MEM_RECLAIM, WQ_MAX_ACTIVE); + if (!rxe_aux_wq) { + destroy_workqueue(rxe_wq); + return -ENOMEM; + + } + return 0; } void rxe_destroy_wq(void) { + flush_workqueue(rxe_aux_wq); + destroy_workqueue(rxe_aux_wq); + + flush_workqueue(rxe_wq); destroy_workqueue(rxe_wq); }@@ -254,6 +271,14 @@ void rxe_sched_task(struct rxe_task *task) spin_unlock_irqrestore(&task->lock, flags); } +/* rxe_wq for rxe tasks. rxe_aux_wq for other rxe jobs. +*/ +void rxe_queue_aux_work (struct work_struct *work) +{ + WARN_ON_ONCE(!rxe_aux_wq); + queue_work(rxe_aux_wq, work); +} + /* rxe_disable/enable_task are only called from* rxe_modify_qp in process context. Task is moved * to the drained state by do_task. drivers/infiniband/sw/rxe/rxe_task.h +1
-0@@ -36,6 +36,7 @@ int rxe_alloc_wq(void); void rxe_destroy_wq(void); +void rxe_queue_aux_work (struct work_struct *work); /** init rxe_task structure * qp => parameter to pass to func Zhu Yanjun
Quoted 29 lines
Quoted 28 lines
Thanks
Quoted 24 lines
Link:
https://lore.kernel.org/all/[email protected]/Suggested-by Tejun Heo <[email protected]>Signed-off-by Marco Crivellari <[email protected]>---
drivers/infiniband/sw/rxe/rxe_odp.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)drivers/infiniband/sw/rxe/rxe_odp.c +1
-0@@ -545,7 +545,7 @@ static int rxe_ib_advise_mr_prefetch(structib_pd *ibpd, work->frags[i].mr = mr; } - queue_work(system_unbound_wq, &work->work); + queue_work(system_dfl_wq, &work->work); return 0;--
2.53.0
Quoted 54 lines · Leon Romanovsky
Quoted 53 lines · Yanjun.Zhu
Quoted 52 lines · Zhu Yanjun
Quoted 26 lines · Leon Romanovsky
Quoted 19 lines · Marco Crivellari
This patch continues the effort to refactor workqueue APIs, which has begun
with the changes introducing new workqueues and a newalloc_workqueueflag:commit
128ea9f6ccfb("workqueue: Addsystem_percpu_wqandsystem_dfl_wq")
commit930c2ea566af("workqueue: Add newWQ_PERCPUflag")The point of the refactoring is to eventually alter the default behavior of
workqueues to become unbound by default so that their workload placement is
optimized by the scheduler.Before that to happen, workqueue users must be converted to the better named
new workqueues with no intended behaviour changes:Quoted 6 lines
system_wq->system_percpu_wq
system_unbound_wq->system_dfl_wqThis way the old obsolete workqueues (
system_wq,system_unbound_wq) can be
removed in the future.Quoted 8 lines
I recall earlier efforts to replace system workqueues with per‑driver queues,
because unloading a driver forces a flush of the entire system workqueue,
which is undesirable for overall system behavior.Wouldn't it be better to introduce a local workqueue here and use that instead?
Thanks.
1.The initialization should be:
my_wq=alloc_workqueue("my_driver_queue", WQ_UNBOUND | WQ_MEM_RECLAIM, 0);
if (!my_wq)
return-ENOMEM;2. The Submission should be:
queue_work(my_wq, &my_work);3. Destroy should be:
destroy_workqueue()
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Thanks,
Zhu YanjunHi, Leon
The diff for a new work queue in rxe is as below. Please review it.
I'm not sure that you need second workqueue and
destroy_workqueuealready doesflush_workqueue. There is no need to call it explicitly.
flush_workqueue() can be removed.
The introduction of the second workqueue is due to rxe_wq being heavily utilized by QP tasks.
The additional workqueue helps offload and distribute the workload, preventing rxe_wq from becoming a bottleneck.
If you believe that the workload on rxe_wq is not significant, I can simplify the design
by removing the second workqueue and using rxe_wq for all work items instead.
Zhu Yanjun
Quoted 117 lines
Thanks
Quoted 114 lines
drivers/infiniband/sw/rxe/rxe_odp.c +1
-1@@ -545,7 +545,7 @@ static int rxe_ib_advise_mr_prefetch(struct ib_pd *ibpd, work->frags[i].mr = mr; } - queue_work(system_unbound_wq, &work->work); + rxe_queue_aux_work(&work->work); return 0;drivers/infiniband/sw/rxe/rxe_task.c +26
-1@@ -6,19 +6,36 @@ #include "rxe.h" +/* work for rxe_task */ static struct workqueue_struct *rxe_wq; +/* work for other rxe jobs */ +static struct workqueue_struct *rxe_aux_wq; + int rxe_alloc_wq(void) { - rxe_wq = alloc_workqueue("rxe_wq", WQ_UNBOUND, WQ_MAX_ACTIVE); + rxe_wq = alloc_workqueue("rxe_wq", WQ_UNBOUND | WQ_MEM_RECLAIM, + WQ_MAX_ACTIVE); if (!rxe_wq) return -ENOMEM; + rxe_aux_wq = alloc_workqueue("rxe_aux_wq", + WQ_UNBOUND | WQ_MEM_RECLAIM, WQ_MAX_ACTIVE); + if (!rxe_aux_wq) { + destroy_workqueue(rxe_wq); + return -ENOMEM; + + } + return 0; } void rxe_destroy_wq(void) { + flush_workqueue(rxe_aux_wq); + destroy_workqueue(rxe_aux_wq); + + flush_workqueue(rxe_wq); destroy_workqueue(rxe_wq); }@@ -254,6 +271,14 @@ void rxe_sched_task(struct rxe_task *task) spin_unlock_irqrestore(&task->lock, flags); } +/* rxe_wq for rxe tasks. rxe_aux_wq for other rxe jobs. +*/ +void rxe_queue_aux_work (struct work_struct *work) +{ + WARN_ON_ONCE(!rxe_aux_wq); + queue_work(rxe_aux_wq, work); +} + /* rxe_disable/enable_task are only called from* rxe_modify_qp in process context. Task is moved * to the drained state by do_task. drivers/infiniband/sw/rxe/rxe_task.h +1
-0@@ -36,6 +36,7 @@ int rxe_alloc_wq(void); void rxe_destroy_wq(void); +void rxe_queue_aux_work (struct work_struct *work); /** init rxe_task structure * qp => parameter to pass to func Zhu Yanjun
Quoted 25 lines
Quoted 25 lines
Thanks
Quoted 23 lines
Link:
https://lore.kernel.org/all/[email protected]/Suggested-by Tejun Heo <[email protected]>Signed-off-by Marco Crivellari <[email protected]>--- drivers/infiniband/sw/rxe/rxe_odp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/infiniband/sw/rxe/rxe_odp.c +1
-0@@ -545,7 +545,7 @@ static int rxe_ib_advise_mr_prefetch(structib_pd *ibpd, work->frags[i].mr = mr; } - queue_work(system_unbound_wq, &work->work); + queue_work(system_dfl_wq, &work->work); return 0; --2.53.0
Quoted 67 lines · Yanjun.Zhu
Quoted 54 lines · Leon Romanovsky
Quoted 53 lines · Yanjun.Zhu
Quoted 52 lines · Zhu Yanjun
Quoted 26 lines · Leon Romanovsky
Quoted 19 lines · Marco Crivellari
This patch continues the effort to refactor workqueue APIs, which has begun
with the changes introducing new workqueues and a newalloc_workqueueflag:commit
128ea9f6ccfb("workqueue: Addsystem_percpu_wqandsystem_dfl_wq")
commit930c2ea566af("workqueue: Add newWQ_PERCPUflag")The point of the refactoring is to eventually alter the default behavior of
workqueues to become unbound by default so that their workload placement is
optimized by the scheduler.Before that to happen, workqueue users must be converted to the better named
new workqueues with no intended behaviour changes:Quoted 6 lines
system_wq->system_percpu_wq
system_unbound_wq->system_dfl_wqThis way the old obsolete workqueues (
system_wq,system_unbound_wq) can be
removed in the future.Quoted 8 lines
I recall earlier efforts to replace system workqueues with per‑driver queues,
because unloading a driver forces a flush of the entire system workqueue,
which is undesirable for overall system behavior.Wouldn't it be better to introduce a local workqueue here and use that instead?
Thanks.
1.The initialization should be:
my_wq=alloc_workqueue("my_driver_queue", WQ_UNBOUND | WQ_MEM_RECLAIM, 0);
if (!my_wq)
return-ENOMEM;2. The Submission should be:
queue_work(my_wq, &my_work);3. Destroy should be:
destroy_workqueue()Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Thanks,
Zhu YanjunHi, Leon
The diff for a new work queue in rxe is as below. Please review it.
I'm not sure that you need second workqueue and
destroy_workqueuealready doesflush_workqueue. There is no need to call it explicitly.
flush_workqueue()can be removed.The introduction of the second workqueue is due to
rxe_wqbeing heavily utilized by QP tasks.
Quoted 7 lines
The additional workqueue helps offload and distribute the workload, preventing
rxe_wqfrom becoming a bottleneck.If you believe that the workload on
rxe_wqis not significant, I can simplify the designby removing the second workqueue and using
rxe_wqfor all work items instead.Zhu Yanjun
Hi, Leon
The latest commit is as below:
drivers/infiniband/sw/rxe/rxe_odp.c +0 -0
@@ -545,7 +545,7 @@ static int rxe_ib_advise_mr_prefetch(struct ib_pd *ibpd,
work->frags[i].mr = mr;
}
- queue_work(system_unbound_wq, &work->work);
+ rxe_queue_work(&work->work);
return 0;
drivers/infiniband/sw/rxe/rxe_task.c +0 -0
@@ -6,11 +6,13 @@
#include "rxe.h"
+/* work for rxe_task */
static struct workqueue_struct *rxe_wq;
int rxe_alloc_wq(void)
{
- rxe_wq = alloc_workqueue("rxe_wq", WQ_UNBOUND, WQ_MAX_ACTIVE); + rxe_wq = alloc_workqueue("rxe_wq", WQ_UNBOUND | WQ_MEM_RECLAIM, + WQ_MAX_ACTIVE);
if (!rxe_wq)
return -ENOMEM;
@@ -254,6 +256,13 @@ void rxe_sched_task(struct rxe_task *task) spin_unlock_irqrestore(&task->lock, flags);
}
+/* Helper to queue auxiliary tasks into rxe_wq.
+ */
+void rxe_queue_work(struct work_struct *work) +{
+ queue_work(rxe_wq, work);
+}
+
/* rxe_disable/enable_task are only called from
* rxe_modify_qp in process context. Task is moved
* to the drained state by do_task.
drivers/infiniband/sw/rxe/rxe_task.h +0 -0
@@ -36,6 +36,7 @@ int rxe_alloc_wq(void);
void rxe_destroy_wq(void);
+void rxe_queue_work(struct work_struct *work);
/*
* init rxe_task structure
* qp => parameter to pass to func
Quoted 119 lines
Quoted 119 lines
Thanks
Quoted 115 lines
drivers/infiniband/sw/rxe/rxe_odp.c +1
-1@@ -545,7 +545,7 @@ static int rxe_ib_advise_mr_prefetch(structib_pd *ibpd, work->frags[i].mr = mr; } - queue_work(system_unbound_wq, &work->work); + rxe_queue_aux_work(&work->work); return 0;drivers/infiniband/sw/rxe/rxe_task.c +26
-1@@ -6,19 +6,36 @@ #include "rxe.h" +/* work for rxe_task */ static struct workqueue_struct *rxe_wq; +/* work for other rxe jobs */ +static struct workqueue_struct *rxe_aux_wq; + int rxe_alloc_wq(void) { - rxe_wq = alloc_workqueue("rxe_wq", WQ_UNBOUND, WQ_MAX_ACTIVE); + rxe_wq = alloc_workqueue("rxe_wq", WQ_UNBOUND | WQ_MEM_RECLAIM, + WQ_MAX_ACTIVE); if (!rxe_wq) return -ENOMEM; + rxe_aux_wq = alloc_workqueue("rxe_aux_wq", + WQ_UNBOUND | WQ_MEM_RECLAIM, WQ_MAX_ACTIVE); + if (!rxe_aux_wq) { + destroy_workqueue(rxe_wq); + return -ENOMEM; + + } + return 0; } void rxe_destroy_wq(void) { + flush_workqueue(rxe_aux_wq); + destroy_workqueue(rxe_aux_wq); + + flush_workqueue(rxe_wq); destroy_workqueue(rxe_wq); }@@ -254,6 +271,14 @@ void rxe_sched_task(struct rxe_task *task) spin_unlock_irqrestore(&task->lock, flags); } +/* rxe_wq for rxe tasks. rxe_aux_wq for other rxe jobs. +*/ +void rxe_queue_aux_work (struct work_struct *work) +{ + WARN_ON_ONCE(!rxe_aux_wq); + queue_work(rxe_aux_wq, work); +} + /* rxe_disable/enable_task are only called from* rxe_modify_qp in process context. Task is moved * to the drained state by do_task. drivers/infiniband/sw/rxe/rxe_task.h +1
-0@@ -36,6 +36,7 @@ int rxe_alloc_wq(void); void rxe_destroy_wq(void); +void rxe_queue_aux_work (struct work_struct *work); /** init rxe_task structure * qp => parameter to pass to func Zhu Yanjun
Quoted 25 lines
Quoted 25 lines
Thanks
Quoted 23 lines
Link:
https://lore.kernel.org/all/[email protected]/Suggested-by Tejun Heo <[email protected]>Signed-off-by Marco Crivellari <[email protected]>---
drivers/infiniband/sw/rxe/rxe_odp.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)drivers/infiniband/sw/rxe/rxe_odp.c +1
-0@@ -545,7 +545,7 @@ static int rxe_ib_advise_mr_prefetch(structib_pd *ibpd, work->frags[i].mr = mr; } - queue_work(system_unbound_wq, &work->work); + queue_work(system_dfl_wq, &work->work); return 0;--
2.53.0