* [PATCH net v3 1/2] ktime: helpers to convert between ktime and jiffies @ 2018-06-11 13:44 Tejaswi Tanikella 2018-06-11 13:46 ` [PATCH net v3 2/2] ipv4: igmp: use alarmtimer to prevent delayed reports Tejaswi Tanikella 0 siblings, 1 reply; 3+ messages in thread From: Tejaswi Tanikella @ 2018-06-11 13:44 UTC (permalink / raw) To: netdev, f.fainelli; +Cc: andrew, davem Signed-off-by: Tejaswi Tanikella <tejaswit@codeaurora.org> --- v2: use alarmtimer instead of wakelock. v3: add patches in the right order. --- include/linux/ktime.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/linux/ktime.h b/include/linux/ktime.h index 5b9fddb..4881483 100644 --- a/include/linux/ktime.h +++ b/include/linux/ktime.h @@ -96,6 +96,10 @@ static inline ktime_t timeval_to_ktime(struct timeval tv) /* Convert ktime_t to nanoseconds - NOP in the scalar storage format: */ #define ktime_to_ns(kt) (kt) +/* ktime to jiffies and back */ +#define ktime_to_jiffies(kt) nsecs_to_jiffies(kt) +#define jiffies_to_ktime(j) jiffies_to_nsecs(j) + /** * ktime_compare - Compares two ktime_t variables for less, greater or equal * @cmp1: comparable1 -- 1.9.1 ^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH net v3 2/2] ipv4: igmp: use alarmtimer to prevent delayed reports 2018-06-11 13:44 [PATCH net v3 1/2] ktime: helpers to convert between ktime and jiffies Tejaswi Tanikella @ 2018-06-11 13:46 ` Tejaswi Tanikella 2018-06-20 5:09 ` kbuild test robot 0 siblings, 1 reply; 3+ messages in thread From: Tejaswi Tanikella @ 2018-06-11 13:46 UTC (permalink / raw) To: netdev, f.fainelli; +Cc: andrew, davem On receiving a IGMPv2/v3 query, based on max_delay set in the header a timer is started to send out a response after a random time within max_delay. If the system then moves into suspend state, Report is delayed until system wakes up. Use a alarmtimer instead of using a timer. Alarmtimer will wake the system up from suspend to send out the IGMP report. Signed-off-by: Tejaswi Tanikella <tejaswit@codeaurora.org> --- v2: use alarmtimer instead of wakelock. v3: add patches in the right order. --- If these changes are fine, I'll share similar patches for MLD and ARP. --- include/linux/igmp.h | 7 ++++++- net/ipv4/igmp.c | 27 ++++++++++++++++----------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/include/linux/igmp.h b/include/linux/igmp.h index f823185..45852eb 100644 --- a/include/linux/igmp.h +++ b/include/linux/igmp.h @@ -20,6 +20,9 @@ #include <linux/in.h> #include <linux/refcount.h> #include <uapi/linux/igmp.h> +#ifdef CONFIG_IP_MULTICAST +#include <linux/alarmtimer.h> +#endif static inline struct igmphdr *igmp_hdr(const struct sk_buff *skb) { @@ -83,7 +86,9 @@ struct ip_mc_list { struct ip_mc_list __rcu *next_rcu; }; struct ip_mc_list __rcu *next_hash; - struct timer_list timer; +#ifdef CONFIG_IP_MULTICAST + struct alarm alarm; +#endif int users; refcount_t refcnt; spinlock_t lock; diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c index 85b617b..c30b5c4 100644 --- a/net/ipv4/igmp.c +++ b/net/ipv4/igmp.c @@ -199,7 +199,7 @@ static void ip_ma_put(struct ip_mc_list *im) static void igmp_stop_timer(struct ip_mc_list *im) { spin_lock_bh(&im->lock); - if (del_timer(&im->timer)) + if (alarm_cancel(&im->alarm)) refcount_dec(&im->refcnt); im->tm_running = 0; im->reporter = 0; @@ -210,11 +210,11 @@ static void igmp_stop_timer(struct ip_mc_list *im) /* It must be called with locked im->lock */ static void igmp_start_timer(struct ip_mc_list *im, int max_delay) { - int tv = prandom_u32() % max_delay; + ktime_t expiry = jiffies_to_ktime(prandom_u32() % max_delay + 2); im->tm_running = 1; - if (!mod_timer(&im->timer, jiffies+tv+2)) - refcount_inc(&im->refcnt); + alarm_start_relative(&im->alarm, expiry); + refcount_inc(&im->refcnt); } static void igmp_gq_start_timer(struct in_device *in_dev) @@ -241,11 +241,14 @@ static void igmp_ifc_start_timer(struct in_device *in_dev, int delay) static void igmp_mod_timer(struct ip_mc_list *im, int max_delay) { + ktime_t expiry; + spin_lock_bh(&im->lock); im->unsolicit_count = 0; - if (del_timer(&im->timer)) { - if ((long)(im->timer.expires-jiffies) < max_delay) { - add_timer(&im->timer); + expiry = alarm_expires_remaining(&im->alarm); + if (alarm_cancel(&im->alarm)) { + if (ktime_to_jiffies(expiry) < max_delay) { + alarm_start_relative(&im->alarm, expiry); im->tm_running = 1; spin_unlock_bh(&im->lock); return; @@ -812,9 +815,9 @@ static void igmp_ifc_event(struct in_device *in_dev) } -static void igmp_timer_expire(struct timer_list *t) +enum alarmtimer_restart igmp_timer_expire(struct alarm *alarm, ktime_t now) { - struct ip_mc_list *im = from_timer(im, t, timer); + struct ip_mc_list *im = container_of(alarm, struct ip_mc_list, alarm); struct in_device *in_dev = im->interface; spin_lock(&im->lock); @@ -835,6 +838,8 @@ static void igmp_timer_expire(struct timer_list *t) igmp_send_report(in_dev, im, IGMPV3_HOST_MEMBERSHIP_REPORT); ip_ma_put(im); + + return ALARMTIMER_NORESTART; } /* mark EXCLUDE-mode sources */ @@ -1413,7 +1418,7 @@ void ip_mc_inc_group(struct in_device *in_dev, __be32 addr) refcount_set(&im->refcnt, 1); spin_lock_init(&im->lock); #ifdef CONFIG_IP_MULTICAST - timer_setup(&im->timer, igmp_timer_expire, 0); + alarm_init(&im->alarm, ALARM_BOOTTIME, igmp_timer_expire); im->unsolicit_count = net->ipv4.sysctl_igmp_qrv; #endif @@ -2811,7 +2816,7 @@ static int igmp_mc_seq_show(struct seq_file *seq, void *v) state->dev->ifindex, state->dev->name, state->in_dev->mc_count, querier); } - delta = im->timer.expires - jiffies; + delta = ktime_to_jiffies(alarm_expires_remaining(&im->alarm)); seq_printf(seq, "\t\t\t\t%08X %5d %d:%08lX\t\t%d\n", im->multiaddr, im->users, -- 1.9.1 ^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net v3 2/2] ipv4: igmp: use alarmtimer to prevent delayed reports 2018-06-11 13:46 ` [PATCH net v3 2/2] ipv4: igmp: use alarmtimer to prevent delayed reports Tejaswi Tanikella @ 2018-06-20 5:09 ` kbuild test robot 0 siblings, 0 replies; 3+ messages in thread From: kbuild test robot @ 2018-06-20 5:09 UTC (permalink / raw) To: Tejaswi Tanikella; +Cc: kbuild-all, netdev, f.fainelli, andrew, davem [-- Attachment #1: Type: text/plain, Size: 2779 bytes --] Hi Tejaswi, Thank you for the patch! Yet something to improve: [auto build test ERROR on net/master] url: https://github.com/0day-ci/linux/commits/Tejaswi-Tanikella/ktime-helpers-to-convert-between-ktime-and-jiffies/20180611-214916 config: x86_64-randconfig-s4-06200944 (attached as .config) compiler: gcc-7 (Debian 7.3.0-16) 7.3.0 reproduce: # save the attached .config to linux build tree make ARCH=x86_64 All errors (new ones prefixed by >>): In file included from include/linux/timer.h:6:0, from include/linux/workqueue.h:9, from include/linux/srcu.h:34, from include/linux/notifier.h:16, from include/linux/memory_hotplug.h:7, from include/linux/mmzone.h:777, from include/linux/gfp.h:6, from include/linux/umh.h:4, from include/linux/kmod.h:22, from include/linux/module.h:13, from net/ipv4/igmp.c:73: net/ipv4/igmp.c: In function 'igmp_mc_seq_show': >> net/ipv4/igmp.c:2819:28: error: implicit declaration of function 'alarm_expires_remaining'; did you mean 'hrtimer_expires_remaining'? [-Werror=implicit-function-declaration] delta = ktime_to_jiffies(alarm_expires_remaining(&im->alarm)); ^ include/linux/ktime.h:100:48: note: in definition of macro 'ktime_to_jiffies' #define ktime_to_jiffies(kt) nsecs_to_jiffies(kt) ^~ >> net/ipv4/igmp.c:2819:55: error: 'struct ip_mc_list' has no member named 'alarm' delta = ktime_to_jiffies(alarm_expires_remaining(&im->alarm)); ^ include/linux/ktime.h:100:48: note: in definition of macro 'ktime_to_jiffies' #define ktime_to_jiffies(kt) nsecs_to_jiffies(kt) ^~ cc1: some warnings being treated as errors vim +2819 net/ipv4/igmp.c 2813 2814 if (rcu_access_pointer(state->in_dev->mc_list) == im) { 2815 seq_printf(seq, "%d\t%-10s: %5d %7s\n", 2816 state->dev->ifindex, state->dev->name, state->in_dev->mc_count, querier); 2817 } 2818 > 2819 delta = ktime_to_jiffies(alarm_expires_remaining(&im->alarm)); 2820 seq_printf(seq, 2821 "\t\t\t\t%08X %5d %d:%08lX\t\t%d\n", 2822 im->multiaddr, im->users, 2823 im->tm_running, 2824 im->tm_running ? jiffies_delta_to_clock_t(delta) : 0, 2825 im->reporter); 2826 } 2827 return 0; 2828 } 2829 --- 0-DAY kernel test infrastructure Open Source Technology Center https://lists.01.org/pipermail/kbuild-all Intel Corporation [-- Attachment #2: .config.gz --] [-- Type: application/gzip, Size: 25732 bytes --] ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-06-20 5:09 UTC | newest] Thread overview: 3+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2018-06-11 13:44 [PATCH net v3 1/2] ktime: helpers to convert between ktime and jiffies Tejaswi Tanikella 2018-06-11 13:46 ` [PATCH net v3 2/2] ipv4: igmp: use alarmtimer to prevent delayed reports Tejaswi Tanikella 2018-06-20 5:09 ` kbuild test robot
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).