(3/6) ipvs -- use list_for_each_entry macro's
Subsystems (2)
PATCH 1/1 (3/6) ipvs -- use list_for_each_entry macro's
There are many places where list_for_each_entry macro can be used in IPVS code.
net/ipv4/ipvs/ip_vs_app.c +14 -23
@@ -214,18 +214,14 @@*/ void unregister_ip_vs_app (struct ip_vs_app *app) { -struct ip_vs_app *inc; -struct list_head *l = &app->incs_list; +struct ip_vs_app *inc, *nxt;down (&__ip_vs_app_mutex); -while (l->next != l) { - inc = list_entry(l->next, struct ip_vs_app, a_list); +list_for_each_entry_safe (inc, nxt, &app->incs_list, a_list) {ip_vs_app_inc_release (inc); } -list_del (&app->a_list); -up (&__ip_vs_app_mutex);/* decrease the module use count */
@@ -239,13 +235,11 @@*/ struct ip_vs_app *ip_vs_app_get_by_name (char *appname) { -struct list_head *p;struct ip_vs_app *app, *a =NULL ;down (&__ip_vs_app_mutex); - list_for_each (p, &ip_vs_app_list) { - app = list_entry(p, struct ip_vs_app, a_list); +list_for_each_entry (ent, &ip_vs_app_list, a_list) {if (strcmp (app->name, appname))continue ;
@@ -485,18 +479,15 @@/* * /proc/net/ip_vs_app entry function */ +static struct ip_vs_app *ip_vs_app_idx (loff_t pos) { -loff_t off =0 ; -struct list_head *e, *i; +struct ip_vs_app *app, *inc; -list_for_each (e, &ip_vs_app_list) { -struct ip_vs_app *app - = list_entry(e, struct ip_vs_app, a_list); - list_for_each (i, &app->incs_list) { -if (off == pos) - return list_entry(i, struct ip_vs_app, a_list); - ++off; +list_for_each_entry (app, &ip_vs_app_list, a_list) { +list_for_each_entry (inc, &app->incs_list, a_list) { +if (pos-- ==0 ) +return inc; } }return NULL ;
@@ -513,7 +504,7 @@static void *ip_vs_app_seq_next (struct seq_file *seq,void *v,loff_t *pos) {struct ip_vs_app *inc, *app; -struct list_head *i, *e; +struct list_head *e; ++*pos;if (v ==SEQ_START_TOKEN )
@@ -522,14 +513,14 @@ inc = v; app = inc->app; -if ((i = inc->a_list.next) != &app->incs_list) - return list_entry(i, struct ip_vs_app, a_list); +if ((e = inc->a_list.next) != &app->incs_list) + return list_entry(e, struct ip_vs_app, a_list);/* go on to next application */ for (e = app->a_list.next; e != &ip_vs_app_list; e = e->next) { app = list_entry(e, struct ip_vs_app, a_list); - list_for_each (i, &app->incs_list) { - return list_entry(i, struct ip_vs_app, a_list); +list_for_each_entry (inc, &app->incs_list, a_list) { +return inc; } }return NULL ;
net/ipv4/ipvs/ip_vs_conn.c +11 -21
@@ -189,14 +189,12 @@ {unsigned hash;struct ip_vs_conn *cp; -struct list_head *e; hash =ip_vs_conn_hashkey (protocol, s_addr, s_port);ct_read_lock (hash); -list_for_each (e, &ip_vs_conn_tab[hash]) { - cp = list_entry(e, struct ip_vs_conn, c_list); +list_for_each_entry (cp, &ip_vs_conn_tab[hash], c_list) {if (s_addr==cp->caddr && s_port==cp->cport && d_port==cp->vport && d_addr==cp->vaddr && protocol==cp->protocol) {
@@ -242,7 +240,6 @@ {unsigned hash;struct ip_vs_conn *cp, *ret=NULL ; -struct list_head *e;/* * Check for "full" addressed entries
@@ -251,8 +248,7 @@ct_read_lock (hash); -list_for_each (e, &ip_vs_conn_tab[hash]) { - cp = list_entry(e, struct ip_vs_conn, c_list); +list_for_each_entry (cp, &ip_vs_conn_tab[hash], c_list) {if (d_addr == cp->caddr && d_port == cp->cport && s_port == cp->dport && s_addr == cp->daddr && protocol == cp->protocol) {
@@ -618,19 +614,17 @@static void *ip_vs_conn_array (struct seq_file *seq,loff_t pos) { -struct list_head *e;int idx; -loff_t off =0 ; +struct ip_vs_conn *cp;for (idx =0 ; idx <IP_VS_CONN_TAB_SIZE ; idx++) {ct_read_lock_bh (idx); -list_for_each (e, &ip_vs_conn_tab[idx]) { -if (off == pos) { +list_for_each_entry (cp, &ip_vs_conn_tab[idx], c_list) { +if (pos-- ==0 ) { seq->private = &ip_vs_conn_tab[idx]; - return list_entry(e, struct ip_vs_conn, c_list); +return cp; } - ++off; - } + }ct_read_unlock_bh (idx); }
@@ -662,9 +656,9 @@while (++idx <IP_VS_CONN_TAB_SIZE ) {ct_read_lock_bh (idx); -list_for_each (e, &ip_vs_conn_tab[idx]) { +list_for_each_entry (cp, &ip_vs_conn_tab[idx], c_list) { seq->private = &ip_vs_conn_tab[idx]; - return list_entry(e, struct ip_vs_conn, c_list); +return cp; }ct_read_unlock_bh (idx); }
@@ -769,7 +763,6 @@ {int idx;struct ip_vs_conn *cp; -struct list_head *e;struct ip_vs_conn *ct;/*
@@ -783,8 +776,7 @@*/ ct_write_lock (hash); -list_for_each (e, &ip_vs_conn_tab[hash]) { - cp = list_entry(e, struct ip_vs_conn, c_list); +list_for_each_entry (cp, &ip_vs_conn_tab[hash], c_list) {if (!cp->cport && !(cp->flags &IP_VS_CONN_F_NO_CPORT ))/* connection template */ continue ;
@@ -836,7 +828,6 @@ {int idx;struct ip_vs_conn *cp; -struct list_head *e;struct ip_vs_conn *ct; flush_again:
@@ -846,8 +837,7 @@*/ ct_write_lock_bh (idx); -list_for_each (e, &ip_vs_conn_tab[idx]) { - cp = list_entry(e, struct ip_vs_conn, c_list); +list_for_each_entry (cp, &ip_vs_conn_tab[idx], c_list) {atomic_inc (&cp->refcnt);ct_write_unlock (idx);
net/ipv4/ipvs/ip_vs_ctl.c +34 -71
298 lines not on this page · raw message
net/ipv4/ipvs/ip_vs_lblc.c +16 -39
127 lines not on this page · raw message
net/ipv4/ipvs/ip_vs_lblcr.c +17 -42
159 lines not on this page · raw message
net/ipv4/ipvs/ip_vs_lc.c +2 -6
@@ -65,7 +65,6 @@static struct ip_vs_dest *ip_vs_lc_schedule (struct ip_vs_service *svc,struct iphdr *iph) { -struct list_head *l, *e;struct ip_vs_dest *dest, *least;unsigned int loh, doh;
@@ -80,9 +79,7 @@* served, but no new connection is assigned to the server. */ - l = &svc->destinations; -for (e=l->next; e!=l; e=e->next) { - least = list_entry (e, struct ip_vs_dest, n_list); +list_for_each_entry (least, &svc->destinations, n_list) {if (least->flags &IP_VS_DEST_F_OVERLOAD )continue ;if (atomic_read (&least->weight) >0 ) {
@@ -96,8 +93,7 @@* Find the destination with the least load. */ nextstage: -for (e=e->next; e!=l; e=e->next) { - dest = list_entry(e, struct ip_vs_dest, n_list); +list_for_each_entry (dest, &svc->destinations, n_list) {if ((dest->flags &IP_VS_DEST_F_OVERLOAD ) ||atomic_read (&dest->weight) ==0 )continue ;
net/ipv4/ipvs/ip_vs_nq.c +2 -6
@@ -81,7 +81,6 @@static struct ip_vs_dest *ip_vs_nq_schedule (struct ip_vs_service *svc,struct iphdr *iph) { - registerstruct list_head *l, *e;struct ip_vs_dest *dest, *least;unsigned int loh, doh;
@@ -100,9 +99,7 @@* new connections. */ - l = &svc->destinations; -for (e=l->next; e!=l; e=e->next) { - least = list_entry(e, struct ip_vs_dest, n_list); +list_for_each_entry (least, &svc->destinations, n_list) {if (!(least->flags &IP_VS_DEST_F_OVERLOAD ) &&atomic_read (&least->weight) >0 ) { loh =ip_vs_nq_dest_overhead (least);
@@ -120,8 +117,7 @@* Find the destination with the least load. */ nextstage: -for (e=e->next; e!=l; e=e->next) { - dest = list_entry(e, struct ip_vs_dest, n_list); +list_for_each_entry (dest, &svc->destinations, n_list) {if (dest->flags &IP_VS_DEST_F_OVERLOAD )continue ;
net/ipv4/ipvs/ip_vs_proto_tcp.c +3 -9
@@ -479,22 +479,19 @@static int tcp_register_app (struct ip_vs_app *inc) {struct ip_vs_app *i; -struct list_head *t, *p;__u16 hash, port = inc->port;int ret =0 ; hash =tcp_app_hashkey (port); - t = &tcp_apps[hash];spin_lock_bh (&tcp_app_lock); -for (p = t->next; p != t; p = p->next) { - i = list_entry(p, struct ip_vs_app, p_list); +list_for_each_entry (i, &tcp_apps[hash], p_list) {if (i->port == port) { ret = -EEXIST ; goto out; } } -list_add (&inc->p_list, t); +list_add (&inc->p_list, &tcp_apps[hash]);atomic_inc (&ip_vs_protocol_tcp.appcnt); out:
@@ -516,7 +513,6 @@static int tcp_app_conn_bind (struct ip_vs_conn *cp) { -struct list_head *t, *p;int hash;struct ip_vs_app *inc;int result =0 ;
@@ -527,11 +523,9 @@/* Lookup application incarnations and bind the right one */ hash =tcp_app_hashkey (cp->vport); - t = &tcp_apps[hash];spin_lock (&tcp_app_lock); -for (p = t->next; p != t; p = p->next) { - inc = list_entry(p, struct ip_vs_app, p_list); +list_for_each_entry (inc, &tcp_apps[hash], p_list) {if (inc->port == cp->vport) {if (unlikely (!ip_vs_app_inc_get (inc)))break ;
net/ipv4/ipvs/ip_vs_proto_udp.c +4 -9
@@ -245,22 +245,20 @@static int udp_register_app (struct ip_vs_app *inc) {struct ip_vs_app *i; -struct list_head *t, *p;__u16 hash, port = inc->port;int ret =0 ; hash =udp_app_hashkey (port); - t = &udp_apps[hash]; +spin_lock_bh (&udp_app_lock); -for (p = t->next; p != t; p = p->next) { - i = list_entry(p, struct ip_vs_app, p_list); +list_for_each_entry (i, &udp_apps[hash], p_list) {if (i->port == port) { ret = -EEXIST ; goto out; } } -list_add (&inc->p_list, t); +list_add (&inc->p_list, &udp_apps[hash]);atomic_inc (&ip_vs_protocol_udp.appcnt); out:
@@ -281,7 +279,6 @@static int udp_app_conn_bind (struct ip_vs_conn *cp) { -struct list_head *t, *p;int hash;struct ip_vs_app *inc;int result =0 ;
@@ -292,11 +289,9 @@/* Lookup application incarnations and bind the right one */ hash =udp_app_hashkey (cp->vport); - t = &udp_apps[hash];spin_lock (&udp_app_lock); -for (p = t->next; p != t; p = p->next) { - inc = list_entry(p, struct ip_vs_app, p_list); +list_for_each_entry (inc, &udp_apps[hash], p_list) {if (inc->port == cp->vport) {if (unlikely (!ip_vs_app_inc_get (inc)))break ;
net/ipv4/ipvs/ip_vs_rr.c +2 -2
@@ -57,7 +57,7 @@static struct ip_vs_dest *ip_vs_rr_schedule (struct ip_vs_service *svc,struct iphdr *iph) { - registerstruct list_head *p, *q; +struct list_head *p, *q;struct ip_vs_dest *dest;IP_VS_DBG (6 ,"ip_vs_rr_schedule(): Scheduling...\n" );
@@ -73,12 +73,12 @@continue ; } + dest = list_entry(q, struct ip_vs_dest, n_list);if (!(dest->flags &IP_VS_DEST_F_OVERLOAD ) &&atomic_read (&dest->weight) >0 )/* HIT */ goto out; - q = q->next; }while (q != p);write_unlock (&svc->sched_lock);return NULL ;
net/ipv4/ipvs/ip_vs_sched.c +1 -6
@@ -106,18 +106,13 @@static struct ip_vs_scheduler *ip_vs_sched_getbyname (const char *sched_name) {struct ip_vs_scheduler *sched; -struct list_head *l, *e;IP_VS_DBG (2 ,"ip_vs_sched_getbyname(): sched_name \"%s\"\n" , sched_name); - l = &ip_vs_schedulers; -read_lock_bh (&__ip_vs_sched_lock); -for (e=l->next; e!=l; e=e->next) { - sched = list_entry(e, struct ip_vs_scheduler, n_list); - +list_for_each_entry (sched, &ip_vs_schedulers, n_list) {/* * Test and get the modules atomically */
net/ipv4/ipvs/ip_vs_sed.c +2 -7
@@ -85,7 +85,6 @@static struct ip_vs_dest *ip_vs_sed_schedule (struct ip_vs_service *svc,struct iphdr *iph) { - registerstruct list_head *l, *e;struct ip_vs_dest *dest, *least;unsigned int loh, doh;
@@ -104,9 +103,7 @@* new connections. */ - l = &svc->destinations; -for (e=l->next; e!=l; e=e->next) { - least = list_entry(e, struct ip_vs_dest, n_list); +list_for_each_entry (least, &svc->destinations, n_list) {if (!(least->flags &IP_VS_DEST_F_OVERLOAD ) &&atomic_read (&least->weight) >0 ) { loh =ip_vs_sed_dest_overhead (least);
@@ -119,9 +116,7 @@* Find the destination with the least load. */ nextstage: -for (e=e->next; e!=l; e=e->next) { - dest = list_entry(e, struct ip_vs_dest, n_list); - +list_for_each_entry (dest, &svc->destinations, n_list) {if (dest->flags &IP_VS_DEST_F_OVERLOAD )continue ; doh =ip_vs_sed_dest_overhead (dest);
net/ipv4/ipvs/ip_vs_wlc.c +2 -7
@@ -73,7 +73,6 @@static struct ip_vs_dest *ip_vs_wlc_schedule (struct ip_vs_service *svc,struct iphdr *iph) { - registerstruct list_head *l, *e;struct ip_vs_dest *dest, *least;unsigned int loh, doh;
@@ -92,9 +91,7 @@* new connections. */ - l = &svc->destinations; -for (e=l->next; e!=l; e=e->next) { - least = list_entry(e, struct ip_vs_dest, n_list); +list_for_each_entry (least, &svc->destinations, n_list) {if (!(least->flags &IP_VS_DEST_F_OVERLOAD ) &&atomic_read (&least->weight) >0 ) { loh =ip_vs_wlc_dest_overhead (least);
@@ -107,9 +104,7 @@* Find the destination with the least load. */ nextstage: -for (e=e->next; e!=l; e=e->next) { - dest = list_entry(e, struct ip_vs_dest, n_list); - +list_for_each_entry (dest, &svc->destinations, n_list) {if (dest->flags &IP_VS_DEST_F_OVERLOAD )continue ; doh =ip_vs_wlc_dest_overhead (dest);
net/ipv4/ipvs/ip_vs_wrr.c +7 -13
@@ -56,25 +56,22 @@static int ip_vs_wrr_gcd_weight (struct ip_vs_service *svc) { - registerstruct list_head *l, *e;struct ip_vs_dest *dest;int weight;int g =1 ; - l = &svc->destinations; -for (e=l->next; e!=l; e=e->next) { - dest = list_entry(e, struct ip_vs_dest, n_list); +list_for_each_entry (dest, &svc->destinations, n_list) { weight =atomic_read (&dest->weight);if (weight >0 ) { g = weight; -break ; + goto search_gcd; } } -if (e == l) -return g; -for (e=e->next; e!=l; e=e->next) { - dest = list_entry(e, struct ip_vs_dest, n_list); +return g; + + search_gcd: +list_for_each_entry (dest, &svc->destinations, n_list) { weight =atomic_read (&dest->weight);if (weight >0 ) g =gcd (weight, g);
@@ -89,13 +86,10 @@*/ static int ip_vs_wrr_max_weight (struct ip_vs_service *svc) { - registerstruct list_head *l, *e;struct ip_vs_dest *dest;int weight =0 ; - l = &svc->destinations; -for (e=l->next; e!=l; e=e->next) { - dest = list_entry(e, struct ip_vs_dest, n_list); +list_for_each_entry (dest, &svc->destinations, n_list) {if (atomic_read (&dest->weight) > weight) weight =atomic_read (&dest->weight); }
Quoted 2 lines · On Tue, 16 Sep 2003 14:17:50 -0700 Stephen Hemminger <[email protected]>…
There are many places where
list_for_each_entrymacro can be used in IPVS code.
Looks fine to me, applied thanks.
Hello,
It seems some places become inefficient. May be we have
to introduce list_for_each_entry_continue?:
* list_for_each_entry_continue - iterate over list of given type
* continuing after existing point
* @pos: the type * to use as a loop counter.
* @head: the head for your list.
* @member: the name of the list_struct within the struct.
*/
#define list_for_each_entry_continue(pos, head, member) \ for (pos = list_entry(pos->member.next, typeof(*pos), member), \ prefetch(pos->member.next); \ &pos->member != (head); \ pos = list_entry(pos->member.next, typeof(*pos), member), \ prefetch(pos->member.next))
below are some comments, there are some strange changes:
Quoted 8 lines · Stephen Hemminger
diff -Nru
a/net/ipv4/ipvs/ip_vs_app.cb/net/ipv4/ipvs/ip_vs_app.cnet/ipv4/ipvs/ip_vs_app.c +0
-1@@ -214,18 +214,14 @@*/ void unregister_ip_vs_app (struct ip_vs_app *app) { -struct ip_vs_app *inc;
net/ipv4/ipvs/ip_vs_app.c line 223
Quoted 10 lines
net/ipv4/ipvs/ip_vs_app.c +2
-3-struct list_head *l = &app->incs_list; +struct ip_vs_app *inc, *nxt;down (&__ip_vs_app_mutex); -while (l->next != l) { - inc = list_entry(l->next, struct ip_vs_app, a_list); +list_for_each_entry_safe (inc, nxt, &app->incs_list, a_list) {ip_vs_app_inc_release (inc); }
What happens with this list_del?:
Quoted 20 lines
net/ipv4/ipvs/ip_vs_app.c +0
-2-list_del (&app->a_list); -up (&__ip_vs_app_mutex);/* decrease the module use count */ diff -Nru
a/net/ipv4/ipvs/ip_vs_rr.cb/net/ipv4/ipvs/ip_vs_rr.cnet/ipv4/ipvs/ip_vs_rr.c +1
-1@@ -57,7 +57,7 @@static struct ip_vs_dest *ip_vs_rr_schedule (struct ip_vs_service *svc,struct iphdr *iph) { - registerstruct list_head *p, *q; +struct list_head *p, *q;struct ip_vs_dest *dest;IP_VS_DBG (6 ,"ip_vs_rr_schedule(): Scheduling...\n" );
net/ipv4/ipvs/ip_vs_rr.c line 74
Quoted 2 lines
net/ipv4/ipvs/ip_vs_rr.c +0
-0@@ -73,12 +73,12 @@continue ; }
new empty line, may be your changes to ip_vs_rr.c are
not completed/actual? :) :
net/ipv4/ipvs/ip_vs_rr.c line 81
Quoted 7 lines
net/ipv4/ipvs/ip_vs_rr.c +1
-0+ dest = list_entry(q, struct ip_vs_dest, n_list);if (!(dest->flags &IP_VS_DEST_F_OVERLOAD ) &&atomic_read (&dest->weight) >0 )/* HIT */ goto out;
Why this line is deleted?:
Quoted 29 lines
net/ipv4/ipvs/ip_vs_rr.c +0
-1- q = q->next; }while (q != p);write_unlock (&svc->sched_lock);return NULL ;diff -Nru
a/net/ipv4/ipvs/ip_vs_sed.cb/net/ipv4/ipvs/ip_vs_sed.cnet/ipv4/ipvs/ip_vs_sed.c +1
-4@@ -85,7 +85,6 @@static struct ip_vs_dest *ip_vs_sed_schedule (struct ip_vs_service *svc,struct iphdr *iph) { - registerstruct list_head *l, *e;struct ip_vs_dest *dest, *least;unsigned int loh, doh;@@ -104,9 +103,7 @@* new connections. */ - l = &svc->destinations; -for (e=l->next; e!=l; e=e->next) { - least = list_entry(e, struct ip_vs_dest, n_list); +list_for_each_entry (least, &svc->destinations, n_list) {if (!(least->flags &IP_VS_DEST_F_OVERLOAD ) &&atomic_read (&least->weight) >0 ) { loh =ip_vs_sed_dest_overhead (least);
net/ipv4/ipvs/ip_vs_sed.c line 117
Quoted 2 lines
net/ipv4/ipvs/ip_vs_sed.c +0
-0@@ -119,9 +116,7 @@* Find the destination with the least load. */
Inefficient, list_for_each_entry_continue?:
Quoted 33 lines
net/ipv4/ipvs/ip_vs_sed.c +1
-3nextstage: -for (e=e->next; e!=l; e=e->next) { - dest = list_entry(e, struct ip_vs_dest, n_list); - +list_for_each_entry (dest, &svc->destinations, n_list) {if (dest->flags &IP_VS_DEST_F_OVERLOAD )continue ; doh =ip_vs_sed_dest_overhead (dest);diff -Nru
a/net/ipv4/ipvs/ip_vs_wlc.cb/net/ipv4/ipvs/ip_vs_wlc.cnet/ipv4/ipvs/ip_vs_wlc.c +1
-4@@ -73,7 +73,6 @@static struct ip_vs_dest *ip_vs_wlc_schedule (struct ip_vs_service *svc,struct iphdr *iph) { - registerstruct list_head *l, *e;struct ip_vs_dest *dest, *least;unsigned int loh, doh;@@ -92,9 +91,7 @@* new connections. */ - l = &svc->destinations; -for (e=l->next; e!=l; e=e->next) { - least = list_entry(e, struct ip_vs_dest, n_list); +list_for_each_entry (least, &svc->destinations, n_list) {if (!(least->flags &IP_VS_DEST_F_OVERLOAD ) &&atomic_read (&least->weight) >0 ) { loh =ip_vs_wlc_dest_overhead (least);
net/ipv4/ipvs/ip_vs_wlc.c line 105
Quoted 2 lines
net/ipv4/ipvs/ip_vs_wlc.c +0
-0@@ -107,9 +104,7 @@* Find the destination with the least load. */
Shorter, not broken but inefficient, list_for_each_entry_continue?:
Quoted 29 lines
net/ipv4/ipvs/ip_vs_wlc.c +1
-3nextstage: -for (e=e->next; e!=l; e=e->next) { - dest = list_entry(e, struct ip_vs_dest, n_list); - +list_for_each_entry (dest, &svc->destinations, n_list) {if (dest->flags &IP_VS_DEST_F_OVERLOAD )continue ; doh =ip_vs_wlc_dest_overhead (dest);diff -Nru
a/net/ipv4/ipvs/ip_vs_wrr.cb/net/ipv4/ipvs/ip_vs_wrr.cnet/ipv4/ipvs/ip_vs_wrr.c +1
-5@@ -56,25 +56,22 @@static int ip_vs_wrr_gcd_weight (struct ip_vs_service *svc) { - registerstruct list_head *l, *e;struct ip_vs_dest *dest;int weight;int g =1 ; - l = &svc->destinations; -for (e=l->next; e!=l; e=e->next) { - dest = list_entry(e, struct ip_vs_dest, n_list); +list_for_each_entry (dest, &svc->destinations, n_list) { weight =atomic_read (&dest->weight);if (weight >0 ) { g = weight; -break ;
net/ipv4/ipvs/ip_vs_wrr.c line 72
Quoted 10 lines
net/ipv4/ipvs/ip_vs_wrr.c +3
-4+ goto search_gcd; } } -if (e == l) -return g; -for (e=e->next; e!=l; e=e->next) { - dest = list_entry(e, struct ip_vs_dest, n_list); +return g; +
It still does not look good:
net/ipv4/ipvs/ip_vs_wrr.c
Quoted 6 lines
net/ipv4/ipvs/ip_vs_wrr.c +2
-0+ search_gcd: +list_for_each_entry (dest, &svc->destinations, n_list) { weight =atomic_read (&dest->weight);if (weight >0 ) g =gcd (weight, g);@@ -89,13 +86,10 @@
What about such version?:
static int ip_vs_wrr_gcd_weight(struct ip_vs_service *svc)
{
struct ip_vs_dest *dest;
int weight;
int g = 0;
list_for_each_entry(dest, &svc->destinations, n_list) {
weight = atomic_read(&dest->weight);
if (weight > 0) {
if (g > 0)
g = gcd(weight, g);
else
g = weight;
}
}
return g?: 1;
}Regards
--
Julian Anastasov <[email protected]>
Thank you for your observations. Here are my comments. Followup message is a patch to restore the missing pieces.
Why don't you make up a patch with your changes to gcd and list_for_each_entry_continue?
Quoted 9 lines
It seems some places become inefficient. May be we have
to introducelist_for_each_entry_continue?:*
list_for_each_entry_continue- iterate over list of given type
* continuing after existing point
* @pos: the type * to use as a loop counter.
* @head: the head for your list.
* @member: the name of thelist_structwithin the struct.
*/
Quoted 7 lines
#define list_for_each_entry_continue(pos, head, member) \ for (pos = list_entry(pos->member.next, typeof(*pos), member), \ prefetch(pos->member.next); \ &pos->member != (head); \ pos = list_entry(pos->member.next, typeof(*pos), member), \ prefetch(pos->member.next))
That looks good.
Quoted 17 lines
below are some comments, there are some strange changes:
Quoted 13 lines · Stephen Hemminger
diff -Nru
a/net/ipv4/ipvs/ip_vs_app.cb/net/ipv4/ipvs/ip_vs_app.cnet/ipv4/ipvs/ip_vs_app.c +1
-2@@ -214,18 +214,14 @@*/ void unregister_ip_vs_app (struct ip_vs_app *app) { -struct ip_vs_app *inc; -struct list_head *l = &app->incs_list; +struct ip_vs_app *inc, *nxt;down (&__ip_vs_app_mutex);
Quoted 7 lines
net/ipv4/ipvs/ip_vs_app.c line 223
Quoted 5 lines
net/ipv4/ipvs/ip_vs_app.c +1
-2-while (l->next != l) { - inc = list_entry(l->next, struct ip_vs_app, a_list); +list_for_each_entry_safe (inc, nxt, &app->incs_list, a_list) {ip_vs_app_inc_release (inc); }What happens with this
list_del?:
That got accidentally dropped. Will send patch out to restore.
Quoted 18 lines
Quoted 18 lines
net/ipv4/ipvs/ip_vs_app.c +0
-2-list_del (&app->a_list); -up (&__ip_vs_app_mutex);/* decrease the module use count */ diff -Nru
a/net/ipv4/ipvs/ip_vs_rr.cb/net/ipv4/ipvs/ip_vs_rr.cnet/ipv4/ipvs/ip_vs_rr.c +1
-1@@ -57,7 +57,7 @@static struct ip_vs_dest *ip_vs_rr_schedule (struct ip_vs_service *svc,struct iphdr *iph) { - registerstruct list_head *p, *q; +struct list_head *p, *q;struct ip_vs_dest *dest;
Quoted 7 lines
net/ipv4/ipvs/ip_vs_rr.c line 74
Quoted 4 lines
net/ipv4/ipvs/ip_vs_rr.c +0
-0IP_VS_DBG (6 ,"ip_vs_rr_schedule(): Scheduling...\n" );@@ -73,12 +73,12 @@continue ; }new empty line, may be your changes to
ip_vs_rr.care
not completed/actual? :) :
Another accidental screw-up... I tried to use list_for_each somehow in the RR code, but it got too messy and backed out back to the original, and lost some stuff.
Quoted 31 lines
net/ipv4/ipvs/ip_vs_rr.c line 81
Quoted 7 lines
net/ipv4/ipvs/ip_vs_rr.c +1
-0+ dest = list_entry(q, struct ip_vs_dest, n_list);if (!(dest->flags &IP_VS_DEST_F_OVERLOAD ) &&atomic_read (&dest->weight) >0 )/* HIT */ goto out;Why this line is deleted?:
Quoted 21 lines
net/ipv4/ipvs/ip_vs_rr.c +0
-1- q = q->next; }while (q != p);write_unlock (&svc->sched_lock);return NULL ;diff -Nru
a/net/ipv4/ipvs/ip_vs_sed.cb/net/ipv4/ipvs/ip_vs_sed.cnet/ipv4/ipvs/ip_vs_sed.c +0
-1@@ -85,7 +85,6 @@static struct ip_vs_dest *ip_vs_sed_schedule (struct ip_vs_service *svc,struct iphdr *iph) { - registerstruct list_head *l, *e;struct ip_vs_dest *dest, *least;unsigned int loh, doh;@@ -104,9 +103,7 @@* new connections. */
Quoted 12 lines
net/ipv4/ipvs/ip_vs_sed.c line 117
Quoted 10 lines
net/ipv4/ipvs/ip_vs_sed.c +1
-3- l = &svc->destinations; -for (e=l->next; e!=l; e=e->next) { - least = list_entry(e, struct ip_vs_dest, n_list); +list_for_each_entry (least, &svc->destinations, n_list) {if (!(least->flags &IP_VS_DEST_F_OVERLOAD ) &&atomic_read (&least->weight) >0 ) { loh =ip_vs_sed_dest_overhead (least);@@ -119,9 +116,7 @@* Find the destination with the least load. */ Inefficient,
list_for_each_entry_continue?:
As inefficient as the original though.
Quoted 90 lines
Quoted 33 lines
net/ipv4/ipvs/ip_vs_sed.c +1
-3nextstage: -for (e=e->next; e!=l; e=e->next) { - dest = list_entry(e, struct ip_vs_dest, n_list); - +list_for_each_entry (dest, &svc->destinations, n_list) {if (dest->flags &IP_VS_DEST_F_OVERLOAD )continue ; doh =ip_vs_sed_dest_overhead (dest);diff -Nru
a/net/ipv4/ipvs/ip_vs_wlc.cb/net/ipv4/ipvs/ip_vs_wlc.cnet/ipv4/ipvs/ip_vs_wlc.c +1
-4@@ -73,7 +73,6 @@static struct ip_vs_dest *ip_vs_wlc_schedule (struct ip_vs_service *svc,struct iphdr *iph) { - registerstruct list_head *l, *e;struct ip_vs_dest *dest, *least;unsigned int loh, doh;@@ -92,9 +91,7 @@* new connections. */ - l = &svc->destinations; -for (e=l->next; e!=l; e=e->next) { - least = list_entry(e, struct ip_vs_dest, n_list); +list_for_each_entry (least, &svc->destinations, n_list) {if (!(least->flags &IP_VS_DEST_F_OVERLOAD ) &&atomic_read (&least->weight) >0 ) { loh =ip_vs_wlc_dest_overhead (least);net/ipv4/ipvs/ip_vs_wlc.c line 105
Quoted 2 lines
net/ipv4/ipvs/ip_vs_wlc.c +0
-0@@ -107,9 +104,7 @@* Find the destination with the least load. */ Shorter, not broken but inefficient,
list_for_each_entry_continue?:Quoted 29 lines
net/ipv4/ipvs/ip_vs_wlc.c +1
-3nextstage: -for (e=e->next; e!=l; e=e->next) { - dest = list_entry(e, struct ip_vs_dest, n_list); - +list_for_each_entry (dest, &svc->destinations, n_list) {if (dest->flags &IP_VS_DEST_F_OVERLOAD )continue ; doh =ip_vs_wlc_dest_overhead (dest);diff -Nru
a/net/ipv4/ipvs/ip_vs_wrr.cb/net/ipv4/ipvs/ip_vs_wrr.cnet/ipv4/ipvs/ip_vs_wrr.c +1
-5@@ -56,25 +56,22 @@static int ip_vs_wrr_gcd_weight (struct ip_vs_service *svc) { - registerstruct list_head *l, *e;struct ip_vs_dest *dest;int weight;int g =1 ; - l = &svc->destinations; -for (e=l->next; e!=l; e=e->next) { - dest = list_entry(e, struct ip_vs_dest, n_list); +list_for_each_entry (dest, &svc->destinations, n_list) { weight =atomic_read (&dest->weight);if (weight >0 ) { g = weight; -break ;net/ipv4/ipvs/ip_vs_wrr.c line 72
Quoted 10 lines
net/ipv4/ipvs/ip_vs_wrr.c +3
-4+ goto search_gcd; } } -if (e == l) -return g; -for (e=e->next; e!=l; e=e->next) { - dest = list_entry(e, struct ip_vs_dest, n_list); +return g; +It still does not look good:
net/ipv4/ipvs/ip_vs_wrr.c
Quoted 6 lines
net/ipv4/ipvs/ip_vs_wrr.c +2
-0+ search_gcd: +list_for_each_entry (dest, &svc->destinations, n_list) { weight =atomic_read (&dest->weight);if (weight >0 ) g =gcd (weight, g);@@ -89,13 +86,10 @@What about such version?:
static int
ip_vs_wrr_gcd_weight(struct ip_vs_service *svc)
Quoted 16 lines
{
struct ip_vs_dest *dest;
int weight;
int g = 0;
list_for_each_entry(dest, &svc->destinations, n_list) {
weight = atomic_read(&dest->weight);
if (weight > 0) {
if (g > 0)
g = gcd(weight, g);
else
g = weight;
}
}
return g?: 1;The null ?: is a gcc extension that confuses people.
Hello,
Quoted 2 lines · Stephen Hemminger
Thank you for your observations. Here are my comments. Followup message is a patch to restore the missing pieces.
I see it, it looks good, thank you.
Quoted 1 line
Why don't you make up a patch with your changes to gcd and
list_for_each_entry_continue?
Yes, I'll do it in the following days.
Regards
--
Julian Anastasov <[email protected]>
PATCH 1/1 ipvs -- fix error's in list_for_each changes.
In reply to Julian AnastasovThe earlier list_for_each changes introduced a couple of bugs where lines got dropped. This restores them.
net/ipv4/ipvs/ip_vs_app.c +2 -0
@@ -222,6 +222,8 @@ip_vs_app_inc_release (inc); } +list_del (&app->a_list); +up (&__ip_vs_app_mutex);/* decrease the module use count */
net/ipv4/ipvs/ip_vs_rr.c +1 -1
@@ -73,12 +73,12 @@continue ; } - dest = list_entry(q, struct ip_vs_dest, n_list);if (!(dest->flags &IP_VS_DEST_F_OVERLOAD ) &&atomic_read (&dest->weight) >0 )/* HIT */ goto out; + q = q->next; }while (q != p);write_unlock (&svc->sched_lock);return NULL ;
David S. Miller
AppliedRe: [PATCH] ipvs -- fix error's in list_for_each changes.
Quoted 2 lines · On Mon, 22 Sep 2003 11:22:04 -0700 Stephen Hemminger <[email protected]>…
The earlier
list_for_eachchanges introduced a couple of bugs where lines got dropped. This restores them.
Applied, thanks Stephen.