*: Fixup formatting issues due to reordering

All the event changes exposed a bunch of places where
we were not properly following our standards.  Just
clean them up in one big fell swoop.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
This commit is contained in:
Donald Sharp 2023-03-23 07:37:28 -04:00
parent 24a58196dd
commit 02e701e49e
7 changed files with 66 additions and 50 deletions

View file

@ -517,6 +517,7 @@ void rfapiPrintBi(void *stream, struct bgp_path_info *bpi)
if (CHECK_FLAG(bpi->flags, BGP_PATH_REMOVED) && bpi->extra if (CHECK_FLAG(bpi->flags, BGP_PATH_REMOVED) && bpi->extra
&& bpi->extra->vnc.import.timer) { && bpi->extra->vnc.import.timer) {
struct event *t = (struct event *)bpi->extra->vnc.import.timer; struct event *t = (struct event *)bpi->extra->vnc.import.timer;
r = snprintf(p, REMAIN, " [%4lu] ", r = snprintf(p, REMAIN, " [%4lu] ",
event_timer_remain_second(t)); event_timer_remain_second(t));
INCP; INCP;
@ -1172,6 +1173,7 @@ static int rfapiPrintRemoteRegBi(struct bgp *bgp, void *stream,
} }
if (tun_type != BGP_ENCAP_TYPE_MPLS && bpi->extra) { if (tun_type != BGP_ENCAP_TYPE_MPLS && bpi->extra) {
uint32_t l = decode_label(&bpi->extra->label[0]); uint32_t l = decode_label(&bpi->extra->label[0]);
if (!MPLS_LABEL_IS_NULL(l)) { if (!MPLS_LABEL_IS_NULL(l)) {
fp(out, " Label: %d", l); fp(out, " Label: %d", l);
if (nlines == 1) if (nlines == 1)

View file

@ -64,7 +64,7 @@ DECLARE_HEAP(event_timer_list, struct event, timeritem, event_timer_cmp);
do { \ do { \
const unsigned char wakebyte = 0x01; \ const unsigned char wakebyte = 0x01; \
write(m->io_pipe[1], &wakebyte, 1); \ write(m->io_pipe[1], &wakebyte, 1); \
} while (0); } while (0)
/* control variable for initializer */ /* control variable for initializer */
static pthread_once_t init_once = PTHREAD_ONCE_INIT; static pthread_once_t init_once = PTHREAD_ONCE_INIT;
@ -105,6 +105,7 @@ static bool cpu_record_hash_cmp(const struct cpu_event_history *a,
static void *cpu_record_hash_alloc(struct cpu_event_history *a) static void *cpu_record_hash_alloc(struct cpu_event_history *a)
{ {
struct cpu_event_history *new; struct cpu_event_history *new;
new = XCALLOC(MTYPE_EVENT_STATS, sizeof(struct cpu_event_history)); new = XCALLOC(MTYPE_EVENT_STATS, sizeof(struct cpu_event_history));
new->func = a->func; new->func = a->func;
new->funcname = a->funcname; new->funcname = a->funcname;
@ -203,8 +204,8 @@ static void cpu_record_print(struct vty *vty, uint8_t filter)
frr_with_mutex (&masters_mtx) { frr_with_mutex (&masters_mtx) {
for (ALL_LIST_ELEMENTS_RO(masters, ln, m)) { for (ALL_LIST_ELEMENTS_RO(masters, ln, m)) {
const char *name = m->name ? m->name : "main"; const char *name = m->name ? m->name : "main";
char underline[strlen(name) + 1]; char underline[strlen(name) + 1];
memset(underline, '-', sizeof(underline)); memset(underline, '-', sizeof(underline));
underline[sizeof(underline) - 1] = '\0'; underline[sizeof(underline) - 1] = '\0';
@ -270,6 +271,7 @@ static void cpu_record_clear(uint8_t filter)
for (ALL_LIST_ELEMENTS_RO(masters, ln, m)) { for (ALL_LIST_ELEMENTS_RO(masters, ln, m)) {
frr_with_mutex (&m->mtx) { frr_with_mutex (&m->mtx) {
void *args[2] = {tmp, m->cpu_record}; void *args[2] = {tmp, m->cpu_record};
hash_iterate( hash_iterate(
m->cpu_record, m->cpu_record,
(void (*)(struct hash_bucket *, (void (*)(struct hash_bucket *,
@ -447,9 +449,8 @@ DEFUN_NOSH (show_thread_poll,
struct event_loop *m; struct event_loop *m;
frr_with_mutex (&masters_mtx) { frr_with_mutex (&masters_mtx) {
for (ALL_LIST_ELEMENTS_RO(masters, node, m)) { for (ALL_LIST_ELEMENTS_RO(masters, node, m))
show_thread_poll_helper(vty, m); show_thread_poll_helper(vty, m);
}
} }
return CMD_SUCCESS; return CMD_SUCCESS;
@ -577,6 +578,7 @@ struct event_loop *event_master_create(const char *name)
sizeof(struct event *) * rv->fd_limit); sizeof(struct event *) * rv->fd_limit);
char tmhashname[strlen(name) + 32]; char tmhashname[strlen(name) + 32];
snprintf(tmhashname, sizeof(tmhashname), "%s - threadmaster event hash", snprintf(tmhashname, sizeof(tmhashname), "%s - threadmaster event hash",
name); name);
rv->cpu_record = hash_create_size( rv->cpu_record = hash_create_size(
@ -691,6 +693,7 @@ void event_master_free_unused(struct event_loop *m)
{ {
frr_with_mutex (&m->mtx) { frr_with_mutex (&m->mtx) {
struct event *t; struct event *t;
while ((t = event_list_pop(&m->unuse))) while ((t = event_list_pop(&m->unuse)))
thread_free(m, t); thread_free(m, t);
} }
@ -703,9 +706,8 @@ void event_master_free(struct event_loop *m)
frr_with_mutex (&masters_mtx) { frr_with_mutex (&masters_mtx) {
listnode_delete(masters, m); listnode_delete(masters, m);
if (masters->count == 0) { if (masters->count == 0)
list_delete(&masters); list_delete(&masters);
}
} }
thread_array_free(m, m->read); thread_array_free(m, m->read);
@ -754,6 +756,7 @@ unsigned long event_timer_remain_second(struct event *thread)
struct timeval event_timer_remain(struct event *thread) struct timeval event_timer_remain(struct event *thread)
{ {
struct timeval remain; struct timeval remain;
frr_with_mutex (&thread->mtx) { frr_with_mutex (&thread->mtx) {
monotime_until(&thread->u.sands, &remain); monotime_until(&thread->u.sands, &remain);
} }
@ -780,11 +783,11 @@ static int time_hhmmss(char *buf, int buf_size, long sec)
char *event_timer_to_hhmmss(char *buf, int buf_size, struct event *t_timer) char *event_timer_to_hhmmss(char *buf, int buf_size, struct event *t_timer)
{ {
if (t_timer) { if (t_timer)
time_hhmmss(buf, buf_size, event_timer_remain_second(t_timer)); time_hhmmss(buf, buf_size, event_timer_remain_second(t_timer));
} else { else
snprintf(buf, buf_size, "--:--:--"); snprintf(buf, buf_size, "--:--:--");
}
return buf; return buf;
} }
@ -869,15 +872,17 @@ static int fd_poll(struct event_loop *m, const struct timeval *timer_wait,
/* number of file descriptors with events */ /* number of file descriptors with events */
int num; int num;
if (timer_wait != NULL if (timer_wait != NULL && m->selectpoll_timeout == 0) {
&& m->selectpoll_timeout == 0) // use the default value /* use the default value */
timeout = (timer_wait->tv_sec * 1000) timeout = (timer_wait->tv_sec * 1000)
+ (timer_wait->tv_usec / 1000); + (timer_wait->tv_usec / 1000);
else if (m->selectpoll_timeout > 0) // use the user's timeout } else if (m->selectpoll_timeout > 0) {
/* use the user's timeout */
timeout = m->selectpoll_timeout; timeout = m->selectpoll_timeout;
else if (m->selectpoll_timeout } else if (m->selectpoll_timeout < 0) {
< 0) // effect a poll (return immediately) /* effect a poll (return immediately) */
timeout = 0; timeout = 0;
}
zlog_tls_buffer_flush(); zlog_tls_buffer_flush();
rcu_read_unlock(); rcu_read_unlock();
@ -967,8 +972,8 @@ void _event_add_read_write(const struct xref_eventsched *xref,
assert(!"Number of FD's open is greater than FRR currently configured to handle, aborting"); assert(!"Number of FD's open is greater than FRR currently configured to handle, aborting");
frr_with_mutex (&m->mtx) { frr_with_mutex (&m->mtx) {
/* Thread is already scheduled; don't reschedule */
if (t_ptr && *t_ptr) if (t_ptr && *t_ptr)
// thread is already scheduled; don't reschedule
break; break;
/* default to a new pollfd */ /* default to a new pollfd */
@ -979,8 +984,10 @@ void _event_add_read_write(const struct xref_eventsched *xref,
else else
thread_array = m->write; thread_array = m->write;
/* if we already have a pollfd for our file descriptor, find and /*
* use it */ * if we already have a pollfd for our file descriptor, find and
* use it
*/
for (nfds_t i = 0; i < m->handler.pfdcount; i++) for (nfds_t i = 0; i < m->handler.pfdcount; i++)
if (m->handler.pfds[i].fd == fd) { if (m->handler.pfds[i].fd == fd) {
queuepos = i; queuepos = i;
@ -1209,8 +1216,10 @@ static void event_cancel_rw(struct event_loop *master, int fd, short state,
master->handler.pfds[master->handler.pfdcount].events = 0; master->handler.pfds[master->handler.pfdcount].events = 0;
} }
/* If we have the same pollfd in the copy, perform the same operations, /*
* otherwise return. */ * If we have the same pollfd in the copy, perform the same operations,
* otherwise return.
*/
if (i >= master->handler.copycount) if (i >= master->handler.copycount)
return; return;
@ -1222,7 +1231,7 @@ static void event_cancel_rw(struct event_loop *master, int fd, short state,
* sizeof(struct pollfd)); * sizeof(struct pollfd));
master->handler.copycount--; master->handler.copycount--;
master->handler.copy[master->handler.copycount].fd = 0; master->handler.copy[master->handler.copycount].fd = 0;
master->handler.copy[master->handler.copycount].events = 0; master->handler.copy[master->handler.copycount].events = 0;
} }
} }
@ -1381,11 +1390,10 @@ static void do_event_cancel(struct event_loop *master)
break; break;
} }
if (list) { if (list)
event_list_del(list, thread); event_list_del(list, thread);
} else if (thread_array) { else if (thread_array)
thread_array[thread->u.fd] = NULL; thread_array[thread->u.fd] = NULL;
}
if (thread->ref) if (thread->ref)
*thread->ref = NULL; *thread->ref = NULL;
@ -1561,6 +1569,7 @@ static struct timeval *thread_timer_wait(struct event_timer_list_head *timers,
return NULL; return NULL;
struct event *next_timer = event_timer_list_first(timers); struct event *next_timer = event_timer_list_first(timers);
monotime_until(&next_timer->u.sands, timer_val); monotime_until(&next_timer->u.sands, timer_val);
return timer_val; return timer_val;
} }
@ -1654,9 +1663,10 @@ static void thread_process_io(struct event_loop *m, unsigned int num)
thread_process_io_helper(m, m->write[pfds[i].fd], thread_process_io_helper(m, m->write[pfds[i].fd],
POLLOUT, pfds[i].revents, i); POLLOUT, pfds[i].revents, i);
/* if one of our file descriptors is garbage, remove the same /*
* from * if one of our file descriptors is garbage, remove the same
* both pfds + update sizes and index */ * from both pfds + update sizes and index
*/
if (pfds[i].revents & POLLNVAL) { if (pfds[i].revents & POLLNVAL) {
memmove(m->handler.pfds + i, m->handler.pfds + i + 1, memmove(m->handler.pfds + i, m->handler.pfds + i + 1,
(m->handler.pfdcount - i - 1) (m->handler.pfdcount - i - 1)
@ -1895,19 +1905,22 @@ unsigned long event_consumed_time(RUSAGE_T *now, RUSAGE_T *start,
return timeval_elapsed(now->real, start->real); return timeval_elapsed(now->real, start->real);
} }
/* We should aim to yield after yield milliseconds, which defaults /*
to EVENT_YIELD_TIME_SLOT . * We should aim to yield after yield milliseconds, which defaults
Note: we are using real (wall clock) time for this calculation. * to EVENT_YIELD_TIME_SLOT .
It could be argued that CPU time may make more sense in certain * Note: we are using real (wall clock) time for this calculation.
contexts. The things to consider are whether the thread may have * It could be argued that CPU time may make more sense in certain
blocked (in which case wall time increases, but CPU time does not), * contexts. The things to consider are whether the thread may have
or whether the system is heavily loaded with other processes competing * blocked (in which case wall time increases, but CPU time does not),
for CPU time. On balance, wall clock time seems to make sense. * or whether the system is heavily loaded with other processes competing
Plus it has the added benefit that gettimeofday should be faster * for CPU time. On balance, wall clock time seems to make sense.
than calling getrusage. */ * Plus it has the added benefit that gettimeofday should be faster
* than calling getrusage.
*/
int event_should_yield(struct event *thread) int event_should_yield(struct event *thread)
{ {
int result; int result;
frr_with_mutex (&thread->mtx) { frr_with_mutex (&thread->mtx) {
result = monotime_since(&thread->real, NULL) result = monotime_since(&thread->real, NULL)
> (int64_t)thread->yield; > (int64_t)thread->yield;

View file

@ -110,7 +110,7 @@ struct event {
struct event_timer_list_item timeritem; struct event_timer_list_item timeritem;
struct event **ref; /* external reference (if given) */ struct event **ref; /* external reference (if given) */
struct event_loop *master; /* pointer to the struct event_loop */ struct event_loop *master; /* pointer to the struct event_loop */
void (*func)(struct event *); /* event function */ void (*func)(struct event *e); /* event function */
void *arg; /* event argument */ void *arg; /* event argument */
union { union {
int val; /* second argument of the event. */ int val; /* second argument of the event. */
@ -130,7 +130,7 @@ struct event {
#endif #endif
struct cpu_event_history { struct cpu_event_history {
void (*func)(struct event *); void (*func)(struct event *e);
atomic_size_t total_cpu_warn; atomic_size_t total_cpu_warn;
atomic_size_t total_wall_warn; atomic_size_t total_wall_warn;
atomic_size_t total_starv_warn; atomic_size_t total_starv_warn;

View file

@ -205,6 +205,7 @@ void spf_backoff_show(struct spf_backoff *backoff, struct vty *vty,
backoff->holddown); backoff->holddown);
if (backoff->t_holddown) { if (backoff->t_holddown) {
struct timeval remain = event_timer_remain(backoff->t_holddown); struct timeval remain = event_timer_remain(backoff->t_holddown);
vty_out(vty, "%s Still runs for %lld msec\n", vty_out(vty, "%s Still runs for %lld msec\n",
prefix, prefix,
(long long)remain.tv_sec * 1000 (long long)remain.tv_sec * 1000

View file

@ -136,15 +136,15 @@ extern unsigned long term_debug_ospf_client_api;
extern char *ospf_lsa_type_str[]; extern char *ospf_lsa_type_str[];
/* Prototypes. */ /* Prototypes. */
extern const char *ospf_area_name_string(struct ospf_area *); extern const char *ospf_area_name_string(struct ospf_area *area);
extern const char *ospf_area_desc_string(struct ospf_area *); extern const char *ospf_area_desc_string(struct ospf_area *area);
extern const char *ospf_if_name_string(struct ospf_interface *); extern const char *ospf_if_name_string(struct ospf_interface *oip);
extern int ospf_nbr_ism_state(struct ospf_neighbor *nbr); extern int ospf_nbr_ism_state(struct ospf_neighbor *nbr);
extern void ospf_nbr_ism_state_message(struct ospf_neighbor *nbr, char *buf, extern void ospf_nbr_ism_state_message(struct ospf_neighbor *nbr, char *buf,
size_t size); size_t size);
extern const char *ospf_timer_dump(struct event *, char *, size_t); extern const char *ospf_timer_dump(struct event *e, char *buf, size_t size);
extern const char *ospf_timeval_dump(struct timeval *, char *, size_t); extern const char *ospf_timeval_dump(struct timeval *t, char *buf, size_t size);
extern void ospf_packet_dump(struct stream *); extern void ospf_packet_dump(struct stream *s);
extern void ospf_debug_init(void); extern void ospf_debug_init(void);
/* Appropriate buffer size to use with ospf_timer_dump and ospf_timeval_dump: */ /* Appropriate buffer size to use with ospf_timer_dump and ospf_timeval_dump: */

View file

@ -52,11 +52,11 @@
event_execute(master, ospf_nsm_event, (N), (E)) event_execute(master, ospf_nsm_event, (N), (E))
/* Prototypes. */ /* Prototypes. */
extern void ospf_nsm_event(struct event *); extern void ospf_nsm_event(struct event *e);
extern void ospf_check_nbr_loading(struct ospf_neighbor *); extern void ospf_check_nbr_loading(struct ospf_neighbor *nbr);
extern int ospf_db_summary_isempty(struct ospf_neighbor *); extern int ospf_db_summary_isempty(struct ospf_neighbor *nbr);
extern int ospf_db_summary_count(struct ospf_neighbor *); extern int ospf_db_summary_count(struct ospf_neighbor *nbr);
extern void ospf_db_summary_clear(struct ospf_neighbor *); extern void ospf_db_summary_clear(struct ospf_neighbor *nbr);
extern int nsm_should_adj(struct ospf_neighbor *nbr); extern int nsm_should_adj(struct ospf_neighbor *nbr);
DECLARE_HOOK(ospf_nsm_change, DECLARE_HOOK(ospf_nsm_change,
(struct ospf_neighbor * on, int state, int oldstate), (struct ospf_neighbor * on, int state, int oldstate),

View file

@ -418,7 +418,7 @@ extern void rip_if_init(void);
extern void rip_route_map_init(void); extern void rip_route_map_init(void);
extern void rip_zebra_vrf_register(struct vrf *vrf); extern void rip_zebra_vrf_register(struct vrf *vrf);
extern void rip_zebra_vrf_deregister(struct vrf *vrf); extern void rip_zebra_vrf_deregister(struct vrf *vrf);
extern void rip_zclient_init(struct event_loop *); extern void rip_zclient_init(struct event_loop *e);
extern void rip_zclient_stop(void); extern void rip_zclient_stop(void);
extern int if_check_address(struct rip *rip, struct in_addr addr); extern int if_check_address(struct rip *rip, struct in_addr addr);
extern struct rip *rip_lookup_by_vrf_id(vrf_id_t vrf_id); extern struct rip *rip_lookup_by_vrf_id(vrf_id_t vrf_id);