OMAP3430SDP: Enable config options CONFIG_OMAP_RESET_CLOCKS and CONFIG_SUSPEND
[linux-ginger.git] / net / ipv4 / ipvs / ip_vs_wlc.c
blob8a9d913261d87546b4414290f01f63b803ae2127
1 /*
2 * IPVS: Weighted Least-Connection Scheduling module
4 * Version: $Id: ip_vs_wlc.c,v 1.13 2003/04/18 09:03:16 wensong Exp $
6 * Authors: Wensong Zhang <wensong@linuxvirtualserver.org>
7 * Peter Kese <peter.kese@ijs.si>
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version
12 * 2 of the License, or (at your option) any later version.
14 * Changes:
15 * Wensong Zhang : changed the ip_vs_wlc_schedule to return dest
16 * Wensong Zhang : changed to use the inactconns in scheduling
17 * Wensong Zhang : changed some comestics things for debugging
18 * Wensong Zhang : changed for the d-linked destination list
19 * Wensong Zhang : added the ip_vs_wlc_update_svc
20 * Wensong Zhang : added any dest with weight=0 is quiesced
24 #include <linux/module.h>
25 #include <linux/kernel.h>
27 #include <net/ip_vs.h>
30 static int
31 ip_vs_wlc_init_svc(struct ip_vs_service *svc)
33 return 0;
37 static int
38 ip_vs_wlc_done_svc(struct ip_vs_service *svc)
40 return 0;
44 static int
45 ip_vs_wlc_update_svc(struct ip_vs_service *svc)
47 return 0;
51 static inline unsigned int
52 ip_vs_wlc_dest_overhead(struct ip_vs_dest *dest)
55 * We think the overhead of processing active connections is 256
56 * times higher than that of inactive connections in average. (This
57 * 256 times might not be accurate, we will change it later) We
58 * use the following formula to estimate the overhead now:
59 * dest->activeconns*256 + dest->inactconns
61 return (atomic_read(&dest->activeconns) << 8) +
62 atomic_read(&dest->inactconns);
67 * Weighted Least Connection scheduling
69 static struct ip_vs_dest *
70 ip_vs_wlc_schedule(struct ip_vs_service *svc, const struct sk_buff *skb)
72 struct ip_vs_dest *dest, *least;
73 unsigned int loh, doh;
75 IP_VS_DBG(6, "ip_vs_wlc_schedule(): Scheduling...\n");
78 * We calculate the load of each dest server as follows:
79 * (dest overhead) / dest->weight
81 * Remember -- no floats in kernel mode!!!
82 * The comparison of h1*w2 > h2*w1 is equivalent to that of
83 * h1/w1 > h2/w2
84 * if every weight is larger than zero.
86 * The server with weight=0 is quiesced and will not receive any
87 * new connections.
90 list_for_each_entry(dest, &svc->destinations, n_list) {
91 if (!(dest->flags & IP_VS_DEST_F_OVERLOAD) &&
92 atomic_read(&dest->weight) > 0) {
93 least = dest;
94 loh = ip_vs_wlc_dest_overhead(least);
95 goto nextstage;
98 return NULL;
101 * Find the destination with the least load.
103 nextstage:
104 list_for_each_entry_continue(dest, &svc->destinations, n_list) {
105 if (dest->flags & IP_VS_DEST_F_OVERLOAD)
106 continue;
107 doh = ip_vs_wlc_dest_overhead(dest);
108 if (loh * atomic_read(&dest->weight) >
109 doh * atomic_read(&least->weight)) {
110 least = dest;
111 loh = doh;
115 IP_VS_DBG(6, "WLC: server %u.%u.%u.%u:%u "
116 "activeconns %d refcnt %d weight %d overhead %d\n",
117 NIPQUAD(least->addr), ntohs(least->port),
118 atomic_read(&least->activeconns),
119 atomic_read(&least->refcnt),
120 atomic_read(&least->weight), loh);
122 return least;
126 static struct ip_vs_scheduler ip_vs_wlc_scheduler =
128 .name = "wlc",
129 .refcnt = ATOMIC_INIT(0),
130 .module = THIS_MODULE,
131 .init_service = ip_vs_wlc_init_svc,
132 .done_service = ip_vs_wlc_done_svc,
133 .update_service = ip_vs_wlc_update_svc,
134 .schedule = ip_vs_wlc_schedule,
138 static int __init ip_vs_wlc_init(void)
140 INIT_LIST_HEAD(&ip_vs_wlc_scheduler.n_list);
141 return register_ip_vs_scheduler(&ip_vs_wlc_scheduler);
144 static void __exit ip_vs_wlc_cleanup(void)
146 unregister_ip_vs_scheduler(&ip_vs_wlc_scheduler);
149 module_init(ip_vs_wlc_init);
150 module_exit(ip_vs_wlc_cleanup);
151 MODULE_LICENSE("GPL");