mld: convert from timer to delayed work
Subsystems (3)
PATCH v2 1/7 mld: convert from timer to delayed work
mcast.c has several timers for delaying works.
Timer's expire handler is working under atomic context so it can't use sleepable things such as GFP_KERNEL, mutex, etc.
In order to use sleepable APIs, it converts from timers to delayed work. But there are some critical sections, which is used by both process and BH context. So that it still uses spin_lock_bh() and rwlock.
---
v1 -> v2:
- Separated from previous big one patch.
include/net/if_inet6.h | 8 +-- net/ipv6/mcast.c | 148 ++++++++++++++++++++++++----------------- 2 files changed, 91 insertions(+), 65 deletions(-)
include/net/if_inet6.h +4 -4
@@ -120,7 +120,7 @@ struct ifmcaddr6 {unsigned int mca_sfmode;unsigned char mca_crcount;unsigned long mca_sfcount[2 ]; -struct timer_list mca_timer; +struct delayed_work mca_work;unsigned int mca_flags;int mca_users;refcount_t mca_refcnt;
@@ -179,9 +179,9 @@ struct inet6_dev {unsigned long mc_qri;/* Query Response Interval */ unsigned long mc_maxdelay; -struct timer_list mc_gq_timer;/* general query timer */ -struct timer_list mc_ifc_timer;/* interface change timer */ -struct timer_list mc_dad_timer;/* dad complete mc timer */ +struct delayed_work mc_gq_work;/* general query work */ +struct delayed_work mc_ifc_work;/* interface change work */ +struct delayed_work mc_dad_work;/* dad complete mc work */ struct ifacaddr6 *ac_list;rwlock_t lock;
net/ipv6/mcast.c +87 -61
360 lines not on this page · raw message
Signature · 1 line
2.17.1
net/ipv6/mcast.c bool ipv6_chk_mcast_addr(struct net_device *dev, const struct in6_addr *group, · line 1064
Quoted 7 lines · Taehee Yoo
net/ipv6/mcast.c +2
-2-static void mld_dad_start_timer (struct inet6_dev *idev,unsigned long delay) +static void mld_dad_start_work (struct inet6_dev *idev,unsigned long delay) {unsigned long tv =prandom_u32 () % delay; -if (!mod_timer (&idev->mc_dad_timer, jiffies+tv+2 )) +if (!mod_delayed_work (mld_wq, &idev->mc_dad_work,msecs_to_jiffies (tv +2 )))
IIUC, before this patch 'delay' is in jiffies, after this patch it is in msecs?
[...]
net/ipv6/mcast.c void ipv6_mc_dad_complete(struct inet6_dev *idev) · line 2115
Quoted 9 lines
net/ipv6/mcast.c +5
-2-static void mld_dad_timer_expire (struct timer_list *t) +static void mld_dad_work (struct work_struct *work) { -struct inet6_dev *idev =from_timer (idev, t, mc_dad_timer); +struct inet6_dev *idev =container_of (to_delayed_work (work), + struct inet6_dev, + mc_dad_work); +rtnl_lock ();
Any reason why we need RTNL after converting the timer to delayed work?
Thanks.
Quoted 11 lines · Cong Wang
net/ipv6/mcast.c bool ipv6_chk_mcast_addr(struct net_device *dev, const struct in6_addr *group, · line 1064
Quoted 7 lines · Taehee Yoo
net/ipv6/mcast.c +2
-2-static void mld_dad_start_timer (struct inet6_dev *idev,unsigned long delay) +static void mld_dad_start_work (struct inet6_dev *idev,unsigned long delay) {unsigned long tv =prandom_u32 () % delay; -if (!mod_timer (&idev->mc_dad_timer, jiffies+tv+2 )) +if (!mod_delayed_work (mld_wq, &idev->mc_dad_work,msecs_to_jiffies (tv +2 )))IIUC, before this patch 'delay' is in jiffies, after this patch it is in msecs?
Ah, I understand, It's my mistake.
I didn't change the behavior of 'delay' in this patchset. So, 'delay' is still in jiffies, not msecs.
Therefore, msecs_to_jiffies() should not be used in this patchset. I will send a v3 patch, which doesn't use msecs_to_jiffies(). Thanks!
By the way, I think the 'delay' is from the unsolicited_report_interval() and it just return value of idev->cnf.mldv{1 | 2}_unsolicited_report_interval. I think this value is msecs, not jiffies.
So, It should be converted to use msecs_to_jiffies(), I think.
How do you think about it?
Quoted 10 lines
[...]
Quoted 8 lines
net/ipv6/mcast.c +4
-2-static void mld_dad_timer_expire (struct timer_list *t) +static void mld_dad_work (struct work_struct *work) { -struct inet6_dev *idev =from_timer (idev, t, mc_dad_timer); +struct inet6_dev *idev =container_of (to_delayed_work (work), + struct inet6_dev, + mc_dad_work);
Quoted 5 lines
Quoted 1 line
+
rtnl_lock();Any reason why we need RTNL after converting the timer to delayed work?
For the moment, RTNL is not needed.
But the Resources, which are used by delayed_work will be protected by RTNL instead of other locks. So, It just pre-adds RTNL and the following patches will delete other locks.
Quoted 2 lines
Thanks.
Quoted 27 lines · Taehee Yoo
Quoted 2 lines · Cong Wang
Quoted 1 line · Taehee Yoo
-static void mld_dad_start_timer(struct
inet6_dev*idev, unsignedlong delay)
Quoted 1 line
Quoted 1 line
+static void mld_dad_start_work(struct
inet6_dev*idev, unsignedlong delay)
Quoted 5 lines
Review
Quoted 5 lines
{ unsigned long tv = prandom_u32() % delay;(quoted diff) +1
-1- if (!mod_timer(&idev->mc_dad_timer, jiffies+tv+2)) + if (!mod_delayed_work(mld_wq, &idev->mc_dad_work,
msecs_to_jiffies(tv + 2)))Quoted 2 lines
IIUC, before this patch 'delay' is in jiffies, after this patch it is
in msecs?
Quoted 1 line
Ah, I understand, It's my mistake.
I didn't change the behavior of 'delay' in this patchset. So, 'delay' is still in jiffies, not msecs.
Therefore,msecs_to_jiffies()should not be used in this patchset. I will send a v3 patch, which doesn't usemsecs_to_jiffies(). Thanks!
Quoted 6 lines
By the way, I think the 'delay' is from the
unsolicited_report_interval()and it just return value of idev->cnf.mldv{1 | 2}_unsolicited_report_interval.
I think this value is msecs, not jiffies.
So, It should be converted to usemsecs_to_jiffies(), I think. How do you think about it?
Hmm? I think it is in jiffies:
.mldv1_unsolicited_report_interval = 10 * HZ, .mldv2_unsolicited_report_interval = HZ,
Quoted 17 lines
Quoted 11 lines
[...]
Quoted 8 lines
net/ipv6/mcast.c +4
-2-static void mld_dad_timer_expire (struct timer_list *t) +static void mld_dad_work (struct work_struct *work) { -struct inet6_dev *idev =from_timer (idev, t, mc_dad_timer); +struct inet6_dev *idev =container_of (to_delayed_work (work), + struct inet6_dev, + mc_dad_work);Quoted 5 lines
Quoted 1 line
+
rtnl_lock();Any reason why we need RTNL after converting the timer to delayed work?
Quoted 4 lines
For the moment, RTNL is not needed.
But the Resources, which are used bydelayed_workwill be protected by RTNL instead of other locks.
So, It just pre-adds RTNL and the following patches will delete other locks.
Sounds like this change does not belong to this patch. ;) If so, please move it to where ever more appropriate.
Thanks.
[...]
Quoted 7 lines
Quoted 6 lines
By the way, I think the 'delay' is from the
unsolicited_report_interval()and it just return value of idev->cnf.mldv{1 | 2}_unsolicited_report_interval.
I think this value is msecs, not jiffies.
So, It should be converted to usemsecs_to_jiffies(), I think. How do you think about it?
Quoted 5 lines
Hmm? I think it is in jiffies:
.mldv1_unsolicited_report_interval = 10 * HZ, .mldv2_unsolicited_report_interval = HZ,
Ah, yes, you're right!
Thanks,
Quoted 18 lines
Quoted 18 lines
Quoted 17 lines
[...]
net/ipv6/mcast.c void ipv6_mc_dad_complete(struct inet6_dev *idev) · line 2115
Quoted 9 lines
net/ipv6/mcast.c +5
-2-static void mld_dad_timer_expire (struct timer_list *t) +static void mld_dad_work (struct work_struct *work) { -struct inet6_dev *idev =from_timer (idev, t, mc_dad_timer); +struct inet6_dev *idev =container_of (to_delayed_work (work), + struct inet6_dev, + mc_dad_work); +rtnl_lock ();Any reason why we need RTNL after converting the timer to delayed work?
Quoted 8 lines
Quoted 4 lines
For the moment, RTNL is not needed.
But the Resources, which are used bydelayed_workwill be protected by RTNL instead of other locks.
So, It just pre-adds RTNL and the following patches will delete other locks.Sounds like this change does not belong to this patch. ;) If so, please move it to where ever more appropriate.
Yes, I will do that,
I will rearrange it then I will send a v3 patch.
Thank you so much for your review!