net/sched: taprio: fix build without 64bit div
authorJakub Kicinski <jakub.kicinski@netronome.com>
Wed, 17 Apr 2019 20:51:57 +0000 (13:51 -0700)
committerDavid S. Miller <davem@davemloft.net>
Fri, 19 Apr 2019 00:06:15 +0000 (17:06 -0700)
Recent changes to taprio did not use the correct div64 helpers,
leading to:

net/sched/sch_taprio.o: In function `taprio_dequeue':
sch_taprio.c:(.text+0x34a): undefined reference to `__divdi3'
net/sched/sch_taprio.o: In function `advance_sched':
sch_taprio.c:(.text+0xa0b): undefined reference to `__divdi3'
net/sched/sch_taprio.o: In function `taprio_init':
sch_taprio.c:(.text+0x1450): undefined reference to `__divdi3'
/home/jkicinski/devel/linux/Makefile:1032: recipe for target 'vmlinux' failed

Use math64 helpers.

Fixes: 7b9eba7ba0c1 ("net/sched: taprio: fix picos_per_byte miscalculation")
Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: Dirk van der Merwe <dirk.vandermerwe@netronome.com>
Acked-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/sched/sch_taprio.c

index 1b0fb80162e6076b7d2e1c29b9ba73ed8bfd9c4e..001182aa395910acbbac47150c6b346a7d71acd7 100644 (file)
@@ -13,6 +13,7 @@
 #include <linux/list.h>
 #include <linux/errno.h>
 #include <linux/skbuff.h>
+#include <linux/math64.h>
 #include <linux/module.h>
 #include <linux/spinlock.h>
 #include <net/netlink.h>
@@ -121,7 +122,14 @@ static struct sk_buff *taprio_peek(struct Qdisc *sch)
 
 static inline int length_to_duration(struct taprio_sched *q, int len)
 {
-       return (len * atomic64_read(&q->picos_per_byte)) / 1000;
+       return div_u64(len * atomic64_read(&q->picos_per_byte), 1000);
+}
+
+static void taprio_set_budget(struct taprio_sched *q, struct sched_entry *entry)
+{
+       atomic_set(&entry->budget,
+                  div64_u64((u64)entry->interval * 1000,
+                            atomic64_read(&q->picos_per_byte)));
 }
 
 static struct sk_buff *taprio_dequeue(struct Qdisc *sch)
@@ -241,8 +249,7 @@ static enum hrtimer_restart advance_sched(struct hrtimer *timer)
        close_time = ktime_add_ns(entry->close_time, next->interval);
 
        next->close_time = close_time;
-       atomic_set(&next->budget,
-                  (next->interval * 1000) / atomic64_read(&q->picos_per_byte));
+       taprio_set_budget(q, next);
 
 first_run:
        rcu_assign_pointer(q->current_entry, next);
@@ -575,9 +582,7 @@ static void taprio_start_sched(struct Qdisc *sch, ktime_t start)
                                 list);
 
        first->close_time = ktime_add_ns(start, first->interval);
-       atomic_set(&first->budget,
-                  (first->interval * 1000) /
-                  atomic64_read(&q->picos_per_byte));
+       taprio_set_budget(q, first);
        rcu_assign_pointer(q->current_entry, NULL);
 
        spin_unlock_irqrestore(&q->current_entry_lock, flags);