workqueue: Add new function mod_fwd_delayed_work()
Subsystems (2)
PATCH 1/2 workqueue: Add new function mod_fwd_delayed_work()
Drivers calling queue_delayed_work() or mod_delayed_work() multiple times on the same work without coordination get undefined behaviour. Add a new function, which is easier to use.
--- include/linux/workqueue.h | 17 +++++++++++++++++ kernel/workqueue.c | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+)
include/linux/workqueue.h +17 -0
@@ -433,6 +433,8 @@ extern bool queue_delayed_work_on(int cpu, struct workqueue_struct *wq, struct delayed_work *work, unsigned long delay);extern bool mod_delayed_work_on (int cpu,struct workqueue_struct *wq,struct delayed_work *dwork,unsigned long delay); +extern bool mod_fwd_delayed_work_on (int cpu,struct workqueue_struct *wq, +struct delayed_work *dwork,unsigned long delay);extern void flush_workqueue (struct workqueue_struct *wq);extern void drain_workqueue (struct workqueue_struct *wq);
@@ -505,6 +507,21 @@ static inline bool mod_delayed_work(struct workqueue_struct *wq, }/** +* mod_fwd_delayed_work - queue a delayed work or increase delay +* @wq: workqueue to use +* @dwork: work to queue +* @delay: number of jiffies to wait before queueing +* +* mod_fwd_delayed_work_on() on local CPU. +*/ +static inline bool mod_fwd_delayed_work (struct workqueue_struct *wq, +struct delayed_work *dwork, +unsigned long delay) +{ +return mod_fwd_delayed_work_on (WORK_CPU_UNBOUND , wq, dwork, delay); +} + +/** * schedule_work_on - put work task on a specific cpu * @cpu: cpu to put the work task on * @work: job to be done
kernel/workqueue.c +41 -0
47 lines not on this page · raw message
Signature · 1 line
2.1.4
PATCH 2/2 regulator: core: Fix race on multiple calls to regulator_disable_deferred()
The old code has two issues:
1) When multiple consumers call regulator_disable_deferred() close in time, always the delay requested in the first call is used.
2) When a consumer calls regulator_disable_deferred(), but enables and calls regulator_disable_deferred() again before the timer fires, the timer isn't reset.
Both issues can cause the regulator to get disabled early.
--- drivers/regulator/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/regulator/core.c +2 -2
@@ -2449,8 +2449,8 @@ int regulator_disable_deferred(struct regulator *regulator, int ms) rdev->deferred_disables++;mutex_unlock (&rdev->mutex); -queue_delayed_work (system_power_efficient_wq, &rdev->disable_work, -msecs_to_jiffies (ms)); +mod_fwd_delayed_work (system_power_efficient_wq, &rdev->disable_work, +msecs_to_jiffies (ms));return 0 ; }EXPORT_SYMBOL_GPL (regulator_disable_deferred);
Signature · 1 line
2.1.4
Mark Brown
maintainerQuoted 3 lines · Harald Geyer
Drivers calling
queue_delayed_work()ormod_delayed_work()multiple times on the same work without coordination get undefined behaviour. Add a new function, which is easier to use.
The obvious question here, especially in the case of mod_delayed_work(), is why not fix the existing functions to have the expected behaviour?
Quoted 7 lines · Mark Brown
Quoted 3 lines · Harald Geyer
Drivers calling
queue_delayed_work()ormod_delayed_work()multiple times on the same work without coordination get undefined behaviour. Add a new function, which is easier to use.The obvious question here, especially in the case of
mod_delayed_work(), is why not fix the existing functions to have the expected behaviour?
AFAICS the existing functions behave as documented. I don't feel to be an authority to decide that the documented behaviour is not right. Actually I think that what mod_delayed_work() does, is a valid operation, even if many current users probably don't want it.
I guess many users don't care, because they are calling mod_delayed_work() from only a single place with a constant delay. However reviewing all 107 use cases in 58 files to check if we can safely change the behaviour, would be quite a lot of work.
I was suprised when I found that no function like mod_fwd_delayed_work() existed, so you have a point there.
Harald
Signature · 4 lines
If you want to support my work: see http://friends.ccbib.org/harald/supporting/ or donate via CLAM to xASPBtezLNqj4cUe8MT5nZjthRSEjrRQXN or via peercoin to P98LRdhit3gZbHDBe7ta5jtXrMJUms4p7w
Mark Brown
maintainerQuoted 6 lines · Harald Geyer
Quoted 4 lines · Mark Brown
Quoted 3 lines · Harald Geyer
Drivers calling
queue_delayed_work()ormod_delayed_work()multiple times on the same work without coordination get undefined behaviour. Add a new function, which is easier to use.
Quoted 7 lines
Quoted 2 lines
The obvious question here, especially in the case of
mod_delayed_work(), is why not fix the existing functions to have the expected behaviour?AFAICS the existing functions behave as documented. I don't feel to be an authority to decide that the documented behaviour is not right. Actually I think that what
mod_delayed_work()does, is a valid operation, even if many current users probably don't want it.
It is *very* non-obvious that mod_delayed_work() will have a problem from the documentation, there's "mod_delayed_work_on() on local CPU" as the body of the description but honestly I'm struggling to tell if that's even there intentionally or anything other than an implementation detail. I'd expect to see some words describing the situations where it can be used or something, both the name and the lack of any information about issues suggest it's the default thing and will work safely.
Quoted 2 lines
I was suprised when I found that no function like
mod_fwd_delayed_work()existed, so you have a point there.
I suspect people are just using mod_delayed_work(), not realising that there are restrictions. I'm thinking that perhaps it should be fixed to be safe for calling from different contexts and a new function with the existing behaviour added, that seems less error prone.
Quoted 9 lines · Mark Brown
Quoted 8 lines
Quoted 3 lines
The obvious question here, especially in the case of
mod_delayed_work(), is why not fix the existing functions to have the expected behaviour?AFAICS the existing functions behave as documented. I don't feel to be an authority to decide that the documented behaviour is not right. Actually I think that what
mod_delayed_work()does, is a valid operation, even if many current users probably don't want it.
Quoted 7 lines
It is *very* non-obvious that
mod_delayed_work()will have a problem from the documentation, there's "mod_delayed_work_on()on local CPU" as the body of the description but honestly I'm struggling to tell if that's even there intentionally or anything other than an implementation detail. I'd expect to see some words describing the situations where it can be used or something, both the name and the lack of any information about issues suggest it's the default thing and will work safely.
It was obvious enough for me, so that I proposed a new function instead of just switching the regulator code from queue_delayed_work() to mod_delayed_work(). If it's not obvious to you, I suggest that you supply a patch improving the documentation.
Quoted 7 lines
Quoted 2 lines
I was suprised when I found that no function like
mod_fwd_delayed_work()existed, so you have a point there.I suspect people are just using
mod_delayed_work(), not realising that there are restrictions. I'm thinking that perhaps it should be fixed to be safe for calling from different contexts and a new function with the existing behaviour added, that seems less error prone.
As I already wrote in my last message: To go that path means to review 107 uses of mod_delayed_work(). Maybe you have somebody you can assign that task to?
Harald
Signature · 4 lines
If you want to support my work: see http://friends.ccbib.org/harald/supporting/ or donate via CLAM to xASPBtezLNqj4cUe8MT5nZjthRSEjrRQXN or via peercoin to P98LRdhit3gZbHDBe7ta5jtXrMJUms4p7w
Mark Brown
maintainerQuoted 10 lines · Harald Geyer
Quoted 3 lines · Mark Brown
detail. I'd expect to see some words describing the situations where it can be used or something, both the name and the lack of any information about issues suggest it's the default thing and will work safely.
It was obvious enough for me, so that I proposed a new function instead of just switching the regulator code from
queue_delayed_work()tomod_delayed_work(). If it's not obvious to you, I suggest that you supply a patch improving the documentation.
I'd need to figure out exactly what the restrictions are and like I say the name of the function itself is confusing, I suspect because it predates SMP.
Quoted 8 lines
Quoted 4 lines
I suspect people are just using
mod_delayed_work(), not realising that there are restrictions. I'm thinking that perhaps it should be fixed to be safe for calling from different contexts and a new function with the existing behaviour added, that seems less error prone.As I already wrote in my last message: To go that path means to review 107 uses of
mod_delayed_work(). Maybe you have somebody you can assign that task to?
Actually yes, though not immediately. Another option is to just rename the current function and all the callers en masse then add a new, safe mod_delayed_work().
Quoted 7 lines · Mark Brown
Quoted 5 lines · Harald Geyer
Quoted 3 lines · Mark Brown
detail. I'd expect to see some words describing the situations where it can be used or something, both the name and the lack of any information about issues suggest it's the default thing and will work safely.
Quoted 8 lines
Quoted 4 lines
It was obvious enough for me, so that I proposed a new function instead of just switching the regulator code from
queue_delayed_work()tomod_delayed_work(). If it's not obvious to you, I suggest that you supply a patch improving the documentation.I'd need to figure out exactly what the restrictions are and like I say the name of the function itself is confusing, I suspect because it predates SMP.
I guess you know that, but just to avoid any confusion: The bug in the regulator code is not related to SMP at all.
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
I suspect people are just using
mod_delayed_work(), not realising that there are restrictions. I'm thinking that perhaps it should be fixed to be safe for calling from different contexts and a new function with the existing behaviour added, that seems less error prone.
Quoted 7 lines
Quoted 3 lines
As I already wrote in my last message: To go that path means to review 107 uses of
mod_delayed_work(). Maybe you have somebody you can assign that task to?Actually yes, though not immediately. Another option is to just rename the current function and all the callers en masse then add a new, safe
mod_delayed_work().
Okay by me. I'm removing the issue from my todo list and hand it over to you and your minions ... :)
thanks,
Harald
Signature · 4 lines
If you want to support my work: see http://friends.ccbib.org/harald/supporting/ or donate via CLAM to xASPBtezLNqj4cUe8MT5nZjthRSEjrRQXN or via peercoin to P98LRdhit3gZbHDBe7ta5jtXrMJUms4p7w
Mark Brown
maintainerQuoted 8 lines · Harald Geyer
Quoted 3 lines · Mark Brown
I'd need to figure out exactly what the restrictions are and like I say the name of the function itself is confusing, I suspect because it predates SMP.
I guess you know that, but just to avoid any confusion: The bug in the regulator code is not related to SMP at all.
It's not? Oh. I had formed the impression that this was a race condition.
Quoted 6 lines
Quoted 3 lines
Actually yes, though not immediately. Another option is to just rename the current function and all the callers en masse then add a new, safe
mod_delayed_work().Okay by me. I'm removing the issue from my todo list and hand it over to you and your minions ... :)
Well, we need to figure out what the desired solution is!
Quoted 7 lines · Mark Brown
Quoted 5 lines · Harald Geyer
Quoted 3 lines · Mark Brown
I'd need to figure out exactly what the restrictions are and like I say the name of the function itself is confusing, I suspect because it predates SMP.
Quoted 5 lines
Quoted 2 lines
I guess you know that, but just to avoid any confusion: The bug in the regulator code is not related to SMP at all.
It's not? Oh. I had formed the impression that this was a race condition.
I have used the word "race" in the description of patch 2/2 - sorry if that was the wrong word, I'm trained in physics not computer science. The description of patch 2/2 was:
Quoted 10 lines
regulator: core: Fix race on multiple calls to
regulator_disable_deferred()The old code has two issues:
1) When multiple consumers callregulator_disable_deferred()close in time, always the delay requested in the first call is used.
2) When a consumer callsregulator_disable_deferred(), but enables and callsregulator_disable_deferred()again before the timer fires, the timer isn't reset.Both issues can cause the regulator to get disabled early.
Issue (1) is what I had thought of a race - not in multiprocessing but in multitasking. Please educate me, if this is not the case or if you can think of a way how I could have expressed the idea more clearly.
Quoted 1 line
Well, we need to figure out what the desired solution is!
Do we have reached consensus on what to do? Do people wait for me to do some work? Based on the comments in this thread it seems one way forward is, that I'm resending the series with mod_fwd_delayed_work() renamed to postpone_delayed_work(). Please let me know if you still consider alternative approaches or need more time to evaluate the situation.
TIA,
Harald
Signature · 4 lines
If you want to support my work: see http://friends.ccbib.org/harald/supporting/ or donate via CLAM to xASPBtezLNqj4cUe8MT5nZjthRSEjrRQXN or via peercoin to P98LRdhit3gZbHDBe7ta5jtXrMJUms4p7w
Tejun Heo
maintainerHello,
Quoted 7 lines · Mark Brown
It is *very* non-obvious that
mod_delayed_work()will have a problem from the documentation, there's "mod_delayed_work_on()on local CPU" as the body of the description but honestly I'm struggling to tell if that's even there intentionally or anything other than an implementation detail. I'd expect to see some words describing the situations where it can be used or something, both the name and the lack of any information about issues suggest it's the default thing and will work safely.
What the mod function is implemneting is "whoever wins (runs the last) determines the timeout". It is a bit unwiedly because unlike the timer, workqueue delay takes duration instead of the absoulte time making coordinating from the user side trickier.
Quoted 7 lines
Quoted 2 lines
I was suprised when I found that no function like
mod_fwd_delayed_work()existed, so you have a point there.I suspect people are just using
mod_delayed_work(), not realising that there are restrictions. I'm thinking that perhaps it should be fixed to be safe for calling from different contexts and a new function with the existing behaviour added, that seems less error prone.
I don't think it's a matter of "fixing" the existing mod_delayed_work(). What the new function is implementing wouldn't fit use cases where the timeout should only be shortened (IIRC, writeback code does that).
I'm not against adding new interface to handle it better but I think it makes more sense to add both directions. How about adding expedite_delayed_work_on() and postpone_delayed_work_on()?
Thanks.
Signature · 1 line
tejun
Quoted 8 lines · Tejun Heo
I don't think it's a matter of "fixing" the existing
mod_delayed_work(). What the new function is implementing wouldn't fit use cases where the timeout should only be shortened (IIRC, writeback code does that).I'm not against adding new interface to handle it better but I think it makes more sense to add both directions. How about adding
expedite_delayed_work_on()andpostpone_delayed_work_on()?
I think such a function should only be added if there is actually code using it. So I'd wait for the survey of existing mod_delayed_work() users Mark has promised to actually find some bugs that would be fixed by the function before adding it.
The names you are proposing feel less clear to me then mod_fwd/mod_bwd, but english is not my native tongue, so my feeling is probably no strong evidence ... :)
Otherwise I agree with your comments.
Harald
Signature · 4 lines
If you want to support my work: see http://friends.ccbib.org/harald/supporting/ or donate via peercoin to P98LRdhit3gZbHDBe7ta5jtXrMJUms4p7w or CLAM xASPBtezLNqj4cUe8MT5nZjthRSEjrRQXN
Tejun Heo
maintainerHello,
Quoted 6 lines · Harald Geyer
Quoted 5 lines · Tejun Heo
I don't think it's a matter of "fixing" the existing
mod_delayed_work(). What the new function is implementing wouldn't fit use cases where the timeout should only be shortened (IIRC, writeback code does that).
Quoted 8 lines
Quoted 3 lines
I'm not against adding new interface to handle it better but I think it makes more sense to add both directions. How about adding
expedite_delayed_work_on()andpostpone_delayed_work_on()?I think such a function should only be added if there is actually code using it. So I'd wait for the survey of existing
mod_delayed_work()users Mark has promised to actually find some bugs that would be fixed by the function before adding it.
I clearly remember writing code to work around that. Unfortunately, I can't find it right now. :( Note that these cases may use cancel, update timeout, requeue sequence rather then mod_delayed_work(). But yeah, we can add the other direction when we find and can convert the users.
Quoted 3 lines
The names you are proposing feel less clear to me then mod_fwd/mod_bwd, but english is not my native tongue, so my feeling is probably no strong evidence ... :)
Forward and backward aren't necessarily time related. It can be interpreted as relative position from now too - pulling a work item forward or pushing it backward. The orientation isn't explicit in the name.
Thanks.
Signature · 1 line
tejun
Mark Brown
maintainerQuoted 10 lines · Tejun Heo
Quoted 7 lines · Mark Brown
It is *very* non-obvious that
mod_delayed_work()will have a problem from the documentation, there's "mod_delayed_work_on()on local CPU" as the body of the description but honestly I'm struggling to tell if that's even there intentionally or anything other than an implementation detail. I'd expect to see some words describing the situations where it can be used or something, both the name and the lack of any information about issues suggest it's the default thing and will work safely.
Quoted 4 lines
What the mod function is implemneting is "whoever wins (runs the last) determines the timeout". It is a bit unwiedly because unlike the timer, workqueue delay takes duration instead of the absoulte time making coordinating from the user side trickier.
Ah, OK. That's what the regulator API was looking for (the timeout is always the same, we just want to kick the starting point into the future). We're not trying to reduce timeouts, only increase them.
Quoted 5 lines
Quoted 4 lines
I suspect people are just using
mod_delayed_work(), not realising that there are restrictions. I'm thinking that perhaps it should be fixed to be safe for calling from different contexts and a new function with the existing behaviour added, that seems less error prone.
Quoted 8 lines
I don't think it's a matter of "fixing" the existing
mod_delayed_work(). What the new function is implementing wouldn't fit use cases where the timeout should only be shortened (IIRC, writeback code does that).I'm not against adding new interface to handle it better but I think it makes more sense to add both directions. How about adding
expedite_delayed_work_on()andpostpone_delayed_work_on()?
That works for me.