diff options
author | Jiri Pirko <jiri@resnulli.us> | 2013-02-11 19:12:03 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2013-02-12 18:59:45 -0500 |
commit | 292f1c7ff6cc10516076ceeea45ed11833bb71c7 (patch) | |
tree | 14e97f023e75d908cbebc183ce3b07fcb0233d05 /net/sched/sch_generic.c | |
parent | b9a7afdefdf90dc9e64902b2565170b8b017aa75 (diff) |
sch: make htb_rate_cfg and functions around that generic
As it is going to be used in tbf as well, push these to generic code.
Signed-off-by: Jiri Pirko <jiri@resnulli.us>
Acked-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/sched/sch_generic.c')
-rw-r--r-- | net/sched/sch_generic.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c index 5d81a4478514..ffad48109a22 100644 --- a/net/sched/sch_generic.c +++ b/net/sched/sch_generic.c | |||
@@ -25,6 +25,7 @@ | |||
25 | #include <linux/rcupdate.h> | 25 | #include <linux/rcupdate.h> |
26 | #include <linux/list.h> | 26 | #include <linux/list.h> |
27 | #include <linux/slab.h> | 27 | #include <linux/slab.h> |
28 | #include <net/sch_generic.h> | ||
28 | #include <net/pkt_sched.h> | 29 | #include <net/pkt_sched.h> |
29 | #include <net/dst.h> | 30 | #include <net/dst.h> |
30 | 31 | ||
@@ -896,3 +897,39 @@ void dev_shutdown(struct net_device *dev) | |||
896 | 897 | ||
897 | WARN_ON(timer_pending(&dev->watchdog_timer)); | 898 | WARN_ON(timer_pending(&dev->watchdog_timer)); |
898 | } | 899 | } |
900 | |||
901 | void psched_ratecfg_precompute(struct psched_ratecfg *r, u32 rate) | ||
902 | { | ||
903 | u64 factor; | ||
904 | u64 mult; | ||
905 | int shift; | ||
906 | |||
907 | r->rate_bps = rate << 3; | ||
908 | r->shift = 0; | ||
909 | r->mult = 1; | ||
910 | /* | ||
911 | * Calibrate mult, shift so that token counting is accurate | ||
912 | * for smallest packet size (64 bytes). Token (time in ns) is | ||
913 | * computed as (bytes * 8) * NSEC_PER_SEC / rate_bps. It will | ||
914 | * work as long as the smallest packet transfer time can be | ||
915 | * accurately represented in nanosec. | ||
916 | */ | ||
917 | if (r->rate_bps > 0) { | ||
918 | /* | ||
919 | * Higher shift gives better accuracy. Find the largest | ||
920 | * shift such that mult fits in 32 bits. | ||
921 | */ | ||
922 | for (shift = 0; shift < 16; shift++) { | ||
923 | r->shift = shift; | ||
924 | factor = 8LLU * NSEC_PER_SEC * (1 << r->shift); | ||
925 | mult = div64_u64(factor, r->rate_bps); | ||
926 | if (mult > UINT_MAX) | ||
927 | break; | ||
928 | } | ||
929 | |||
930 | r->shift = shift - 1; | ||
931 | factor = 8LLU * NSEC_PER_SEC * (1 << r->shift); | ||
932 | r->mult = div64_u64(factor, r->rate_bps); | ||
933 | } | ||
934 | } | ||
935 | EXPORT_SYMBOL(psched_ratecfg_precompute); | ||