OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [LINUX_2_4_26_OR32/] [linux/] [linux-2.4/] [net/] [ipv4/] [ipvs/] [ip_vs_wlc.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1275 phoenix
/*
2
 * IPVS:        Weighted Least-Connection Scheduling module
3
 *
4
 * Version:     $Id: ip_vs_wlc.c,v 1.1.1.1 2004-04-15 01:14:05 phoenix Exp $
5
 *
6
 * Authors:     Wensong Zhang <wensong@linuxvirtualserver.org>
7
 *              Peter Kese <peter.kese@ijs.si>
8
 *
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.
13
 *
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
21
 *
22
 */
23
 
24
#include <linux/module.h>
25
#include <linux/kernel.h>
26
 
27
#include <net/ip_vs.h>
28
 
29
 
30
static int
31
ip_vs_wlc_init_svc(struct ip_vs_service *svc)
32
{
33
        return 0;
34
}
35
 
36
 
37
static int
38
ip_vs_wlc_done_svc(struct ip_vs_service *svc)
39
{
40
        return 0;
41
}
42
 
43
 
44
static int
45
ip_vs_wlc_update_svc(struct ip_vs_service *svc)
46
{
47
        return 0;
48
}
49
 
50
 
51
static inline unsigned int
52
ip_vs_wlc_dest_overhead(struct ip_vs_dest *dest)
53
{
54
        /*
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
60
         */
61
        return (atomic_read(&dest->activeconns) << 8) +
62
                atomic_read(&dest->inactconns);
63
}
64
 
65
 
66
/*
67
 *    Weighted Least Connection scheduling
68
 */
69
static struct ip_vs_dest *
70
ip_vs_wlc_schedule(struct ip_vs_service *svc, struct iphdr *iph)
71
{
72
        register struct list_head *l, *e;
73
        struct ip_vs_dest *dest, *least;
74
        unsigned int loh, doh;
75
 
76
        IP_VS_DBG(6, "ip_vs_wlc_schedule(): Scheduling...\n");
77
 
78
        /*
79
         * We calculate the load of each dest server as follows:
80
         *                (dest overhead) / dest->weight
81
         *
82
         * Remember -- no floats in kernel mode!!!
83
         * The comparison of h1*w2 > h2*w1 is equivalent to that of
84
         *                h1/w1 > h2/w2
85
         * if every weight is larger than zero.
86
         *
87
         * The server with weight=0 is quiesced and will not receive any
88
         * new connections.
89
         */
90
 
91
        l = &svc->destinations;
92
        for (e=l->next; e!=l; e=e->next) {
93
                least = list_entry(e, struct ip_vs_dest, n_list);
94
                if (atomic_read(&least->weight) > 0) {
95
                        loh = ip_vs_wlc_dest_overhead(least);
96
                        goto nextstage;
97
                }
98
        }
99
        return NULL;
100
 
101
        /*
102
         *    Find the destination with the least load.
103
         */
104
  nextstage:
105
        for (e=e->next; e!=l; e=e->next) {
106
                dest = list_entry(e, struct ip_vs_dest, n_list);
107
 
108
                doh = ip_vs_wlc_dest_overhead(dest);
109
                if (loh * atomic_read(&dest->weight) >
110
                    doh * atomic_read(&least->weight)) {
111
                        least = dest;
112
                        loh = doh;
113
                }
114
        }
115
 
116
        IP_VS_DBG(6, "WLC: server %u.%u.%u.%u:%u "
117
                  "activeconns %d refcnt %d weight %d overhead %d\n",
118
                  NIPQUAD(least->addr), ntohs(least->port),
119
                  atomic_read(&least->activeconns),
120
                  atomic_read(&least->refcnt),
121
                  atomic_read(&least->weight), loh);
122
 
123
        return least;
124
}
125
 
126
 
127
static struct ip_vs_scheduler ip_vs_wlc_scheduler =
128
{
129
        {0},                     /* n_list */
130
        "wlc",                  /* name */
131
        ATOMIC_INIT(0),         /* refcnt */
132
        THIS_MODULE,            /* this module */
133
        ip_vs_wlc_init_svc,     /* service initializer */
134
        ip_vs_wlc_done_svc,     /* service done */
135
        ip_vs_wlc_update_svc,   /* service updater */
136
        ip_vs_wlc_schedule,     /* select a server from the destination list */
137
};
138
 
139
 
140
static int __init ip_vs_wlc_init(void)
141
{
142
        INIT_LIST_HEAD(&ip_vs_wlc_scheduler.n_list);
143
        return register_ip_vs_scheduler(&ip_vs_wlc_scheduler);
144
}
145
 
146
static void __exit ip_vs_wlc_cleanup(void)
147
{
148
        unregister_ip_vs_scheduler(&ip_vs_wlc_scheduler);
149
}
150
 
151
module_init(ip_vs_wlc_init);
152
module_exit(ip_vs_wlc_cleanup);
153
MODULE_LICENSE("GPL");

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.