From: Donald Sharp Date: Wed, 20 May 2015 00:24:43 +0000 (-0700) Subject: Modified the number of writes to service at most X-Git-Tag: frr-2.0-rc1~1558 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=e8f45e82d49a5075443669324d43a287fd73156d;p=mirror%2Ffrr.git Modified the number of writes to service at most 20 interfaces. Signed-off-by: Ayan Banerjee Reviewed-by: Dinesh G Dutt --- diff --git a/ospfd/ospf_packet.c b/ospfd/ospf_packet.c index 43a237cf55..ff1bdae59f 100644 --- a/ospfd/ospf_packet.c +++ b/ospfd/ospf_packet.c @@ -640,6 +640,7 @@ ospf_write (struct thread *thread) { struct ospf *ospf = THREAD_ARG (thread); struct ospf_interface *oi; + struct ospf_interface *last_serviced_oi = NULL; struct ospf_packet *op; struct sockaddr_in sa_dst; struct ip iph; @@ -669,16 +670,21 @@ ospf_write (struct thread *thread) ipid = (time(NULL) & 0xffff); #endif /* WANT_OSPF_WRITE_FRAGMENT */ - /* convenience - max OSPF data per packet, - * and reliability - not more data, than our - * socket can accept - */ - maxdatasize = MIN (oi->ifp->mtu, ospf->maxsndbuflen) - - sizeof (struct ip); - - while ((pkt_count < ospf->write_multiplier) && ospf_fifo_count(oi->obuf)) + while ((pkt_count < ospf->write_oi_count) && oi && (last_serviced_oi != oi)) { + /* If there is only packet in the queue, the oi is removed from + write-q, so fix up the last interface that was serviced */ + if (last_serviced_oi == NULL) { + last_serviced_oi = oi; + } pkt_count++; + /* convenience - max OSPF data per packet, + * and reliability - not more data, than our + * socket can accept + */ + maxdatasize = MIN (oi->ifp->mtu, ospf->maxsndbuflen) - + sizeof (struct ip); + /* Get one packet from queue. */ op = ospf_fifo_head (oi->obuf); assert (op); @@ -804,19 +810,30 @@ ospf_write (struct thread *thread) /* Now delete packet from queue. */ ospf_packet_delete (oi); - } - /* Move this interface to the tail of write_q to - serve everyone in a round robin fashion */ - list_delete_node (ospf->oi_write_q, node); - if (ospf_fifo_head (oi->obuf) == NULL) - { - oi->on_write_q = 0; - } - else - { - listnode_add (ospf->oi_write_q, oi); - } + /* Move this interface to the tail of write_q to + serve everyone in a round robin fashion */ + list_delete_node (ospf->oi_write_q, node); + if (ospf_fifo_head (oi->obuf) == NULL) + { + oi->on_write_q = 0; + last_serviced_oi = NULL; + oi = NULL; + } + else + { + listnode_add (ospf->oi_write_q, oi); + } + + /* Setup to service from the head of the queue again */ + if (!list_isempty (ospf->oi_write_q)) + { + node = listhead (ospf->oi_write_q); + assert (node); + oi = listgetdata (node); + assert (oi); + } + } /* If packets still remain in queue, call write thread. */ if (!list_isempty (ospf->oi_write_q)) diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c index b9c99b1dbd..839a2b6997 100644 --- a/ospfd/ospf_vty.c +++ b/ospfd/ospf_vty.c @@ -2533,35 +2533,50 @@ DEFUN (no_ospf_auto_cost_reference_bandwidth, DEFUN (ospf_write_multiplier, ospf_write_multiplier_cmd, - "write-multiplier <1-50>", - "Number of writes per thread callback\n") + "ospf write-multiplier <1-100>", + "OSPF specific commands\n" + "Write multiplier\n" + "Maximum number of interface serviced per write\n") { struct ospf *ospf = vty->index; - u_int32_t write_multiplier; + u_int32_t write_oi_count; - write_multiplier = strtol (argv[0], NULL, 10); - if (write_multiplier < 1 || write_multiplier > 50) + write_oi_count = strtol (argv[0], NULL, 10); + if (write_oi_count < 1 || write_oi_count > 100) { vty_out (vty, "write-multiplier value is invalid%s", VTY_NEWLINE); return CMD_WARNING; } - ospf->write_multiplier = write_multiplier; + ospf->write_oi_count = write_oi_count; return CMD_SUCCESS; } +ALIAS (ospf_write_multiplier, + write_multiplier_cmd, + "write-multiplier <1-100>", + "Write multiplier\n" + "Maximum number of interface serviced per write\n") + DEFUN (no_ospf_write_multiplier, no_ospf_write_multiplier_cmd, - "no write-multiplier", + "no ospf write-multiplier", NO_STR - "Number of writes per thread callback\n") + "OSPF specific commands\n" + "Write multiplier\n") { struct ospf *ospf = vty->index; - ospf->write_multiplier = OSPF_WRITE_MULTIPLIER_DEFAULT; + ospf->write_oi_count = OSPF_WRITE_INTERFACE_COUNT_DEFAULT; return CMD_SUCCESS; } +ALIAS (no_ospf_write_multiplier, + no_write_multiplier_cmd, + "no write-multiplier", + NO_STR + "Write multiplier\n") + const char *ospf_abr_type_descr_str[] = { "Unknown", @@ -2793,7 +2808,7 @@ DEFUN (show_ip_ospf, /* Show write multiplier values */ vty_out (vty, " Write Multiplier set to %d %s", - ospf->write_multiplier, VTY_NEWLINE); + ospf->write_oi_count, VTY_NEWLINE); /* Show refresh parameters. */ vty_out (vty, " Refresh timer %d secs%s", @@ -7323,9 +7338,9 @@ ospf_config_write (struct vty *vty) ospf->spf_max_holdtime, VTY_NEWLINE); /* Write multiplier print. */ - if (ospf->write_multiplier != OSPF_WRITE_MULTIPLIER_DEFAULT) + if (ospf->write_oi_count != OSPF_WRITE_INTERFACE_COUNT_DEFAULT) vty_out (vty, " ospf write-multiplier %d%s", - ospf->write_multiplier, VTY_NEWLINE); + ospf->write_oi_count, VTY_NEWLINE); /* Max-metric router-lsa print */ config_write_stub_router (vty, ospf); @@ -7766,6 +7781,8 @@ ospf_vty_init (void) /* write multiplier commands */ install_element (OSPF_NODE, &ospf_write_multiplier_cmd); install_element (OSPF_NODE, &no_ospf_write_multiplier_cmd); + install_element (OSPF_NODE, &write_multiplier_cmd); + install_element (OSPF_NODE, &no_write_multiplier_cmd); /* Init interface related vty commands. */ ospf_vty_if_init (); diff --git a/ospfd/ospfd.c b/ospfd/ospfd.c index 09f3a14247..4cddca67d2 100644 --- a/ospfd/ospfd.c +++ b/ospfd/ospfd.c @@ -233,7 +233,7 @@ ospf_new (void) } new->t_read = thread_add_read (master, ospf_read, new, new->fd); new->oi_write_q = list_new (); - new->write_multiplier = OSPF_WRITE_MULTIPLIER_DEFAULT; + new->write_oi_count = OSPF_WRITE_INTERFACE_COUNT_DEFAULT; return new; } diff --git a/ospfd/ospfd.h b/ospfd/ospfd.h index 3e8b52e9e3..9920a6e2ef 100644 --- a/ospfd/ospfd.h +++ b/ospfd/ospfd.h @@ -219,8 +219,8 @@ struct ospf struct thread *t_deferred_shutdown; /* deferred/stub-router shutdown timer*/ struct thread *t_write; -#define OSPF_WRITE_MULTIPLIER_DEFAULT 3 - int write_multiplier; /* Num of packets sent per thread invocation */ +#define OSPF_WRITE_INTERFACE_COUNT_DEFAULT 20 + int write_oi_count; /* Num of packets sent per thread invocation */ struct thread *t_read; int fd; unsigned int maxsndbuflen;