Skip to content

Commit

Permalink
*: Convert a bunch of thread_XX to event_XX
Browse files Browse the repository at this point in the history
Convert these functions:

thread_getrusage
thread_cmd_init
thread_consumed_time
thread_timer_to_hhmmss
thread_is_scheduled
thread_ignore_late_timer

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
  • Loading branch information
donaldsharp committed Mar 24, 2023
1 parent 70c35c1 commit 5f6eaa9
Show file tree
Hide file tree
Showing 22 changed files with 107 additions and 112 deletions.
2 changes: 1 addition & 1 deletion bgpd/bgp_conditional_adv.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ void bgp_conditional_adv_enable(struct peer *peer, afi_t afi, safi_t safi)
}

/* Register for conditional routes polling timer */
if (!thread_is_scheduled(bgp->t_condition_check))
if (!event_is_scheduled(bgp->t_condition_check))
event_add_timer(bm->master, bgp_conditional_adv_timer, bgp, 0,
&bgp->t_condition_check);
}
Expand Down
8 changes: 4 additions & 4 deletions bgpd/bgp_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -13460,7 +13460,7 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
json_neigh,
"bgpTimerConfiguredConditionalAdvertisementsSec",
bgp->condition_check_period);
if (thread_is_scheduled(bgp->t_condition_check))
if (event_is_scheduled(bgp->t_condition_check))
json_object_int_add(
json_neigh,
"bgpTimerUntilConditionalAdvertisementsSec",
Expand Down Expand Up @@ -13541,7 +13541,7 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
vty_out(vty,
" Configured conditional advertisements interval is %d seconds\n",
bgp->condition_check_period);
if (thread_is_scheduled(bgp->t_condition_check))
if (event_is_scheduled(bgp->t_condition_check))
vty_out(vty,
" Time until conditional advertisements begin is %lu seconds\n",
event_timer_remain_second(
Expand Down Expand Up @@ -18768,7 +18768,7 @@ static struct event *t_bgp_cfg;

bool bgp_config_inprocess(void)
{
return thread_is_scheduled(t_bgp_cfg);
return event_is_scheduled(t_bgp_cfg);
}

static void bgp_config_finish(struct event *t)
Expand Down Expand Up @@ -18797,7 +18797,7 @@ static void bgp_config_end(void)
{
#define BGP_POST_CONFIG_DELAY_SECONDS 1
uint32_t bgp_post_config_delay =
thread_is_scheduled(bm->t_rmap_update)
event_is_scheduled(bm->t_rmap_update)
? event_timer_remain_second(bm->t_rmap_update)
: BGP_POST_CONFIG_DELAY_SECONDS;

Expand Down
2 changes: 1 addition & 1 deletion isisd/isis_lsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1372,7 +1372,7 @@ int lsp_generate(struct isis_area *area, int level)
return ISIS_ERROR;

/* Check if config is still being processed */
if (thread_is_scheduled(t_isis_cfg))
if (event_is_scheduled(t_isis_cfg))
return ISIS_OK;

memset(&lspid, 0, ISIS_SYS_ID_LEN + 2);
Expand Down
2 changes: 1 addition & 1 deletion isisd/isis_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ static void isis_config_end(void)
/* If ISIS config processing thread isn't running, then
* we can return and rely it's properly handled.
*/
if (!thread_is_scheduled(t_isis_cfg))
if (!event_is_scheduled(t_isis_cfg))
return;

THREAD_OFF(t_isis_cfg);
Expand Down
2 changes: 1 addition & 1 deletion lib/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -2542,7 +2542,7 @@ void cmd_init(int terminal)

install_default(CONFIG_NODE);

thread_cmd_init();
event_cmd_init();
workqueue_cmd_init();
hash_cmd_init();
}
Expand Down
14 changes: 7 additions & 7 deletions lib/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ DEFPY_NOSH (show_thread_timers,
return CMD_SUCCESS;
}

void thread_cmd_init(void)
void event_cmd_init(void)
{
install_element(VIEW_NODE, &show_thread_cpu_cmd);
install_element(VIEW_NODE, &show_thread_poll_cmd);
Expand Down Expand Up @@ -737,7 +737,7 @@ unsigned long event_timer_remain_msec(struct event *thread)
{
int64_t remain;

if (!thread_is_scheduled(thread))
if (!event_is_scheduled(thread))
return 0;

frr_with_mutex (&thread->mtx) {
Expand Down Expand Up @@ -780,7 +780,7 @@ static int time_hhmmss(char *buf, int buf_size, long sec)
return wr != 8;
}

char *thread_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) {
time_hhmmss(buf, buf_size, event_timer_remain_second(t_timer));
Expand Down Expand Up @@ -1865,8 +1865,8 @@ static unsigned long timeval_elapsed(struct timeval a, struct timeval b)
+ (a.tv_usec - b.tv_usec));
}

unsigned long thread_consumed_time(RUSAGE_T *now, RUSAGE_T *start,
unsigned long *cputime)
unsigned long event_consumed_time(RUSAGE_T *now, RUSAGE_T *start,
unsigned long *cputime)
{
#ifdef HAVE_CLOCK_THREAD_CPUTIME_ID

Expand Down Expand Up @@ -1927,7 +1927,7 @@ void event_set_yield_time(struct event *thread, unsigned long yield_time)
}
}

void thread_getrusage(RUSAGE_T *r)
void event_getrusage(RUSAGE_T *r)
{
monotime(&r->real);
if (!cputime_enabled) {
Expand Down Expand Up @@ -1993,7 +1993,7 @@ void event_call(struct event *thread)
unsigned long walltime, cputime;
unsigned long exp;

walltime = thread_consumed_time(&after, &before, &cputime);
walltime = event_consumed_time(&after, &before, &cputime);

/* update walltime */
atomic_fetch_add_explicit(&thread->hist->real.total, walltime,
Expand Down
18 changes: 9 additions & 9 deletions lib/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct rusage_t {
};
#define RUSAGE_T struct rusage_t

#define GETRUSAGE(X) thread_getrusage(X)
#define GETRUSAGE(X) event_getrusage(X)

PREDECL_LIST(thread_list);
PREDECL_HEAP(thread_timer_list);
Expand Down Expand Up @@ -259,19 +259,19 @@ extern int event_should_yield(struct event *event);
extern void event_set_yield_time(struct event *event, unsigned long);

/* Internal libfrr exports */
extern void thread_getrusage(RUSAGE_T *);
extern void thread_cmd_init(void);
extern void event_getrusage(RUSAGE_T *);
extern void event_cmd_init(void);

/* Returns elapsed real (wall clock) time. */
extern unsigned long thread_consumed_time(RUSAGE_T *after, RUSAGE_T *before,
unsigned long *cpu_time_elapsed);
extern unsigned long event_consumed_time(RUSAGE_T *after, RUSAGE_T *before,
unsigned long *cpu_time_elapsed);

/* only for use in logging functions! */
extern pthread_key_t thread_current;
extern char *thread_timer_to_hhmmss(char *buf, int buf_size,
struct event *t_timer);
extern char *event_timer_to_hhmmss(char *buf, int buf_size,
struct event *t_timer);

static inline bool thread_is_scheduled(struct event *thread)
static inline bool event_is_scheduled(struct event *thread)
{
if (thread)
return true;
Expand All @@ -282,7 +282,7 @@ static inline bool thread_is_scheduled(struct event *thread)
/* Debug signal mask */
void debug_signals(const sigset_t *sigs);

static inline void thread_ignore_late_timer(struct event *event)
static inline void event_ignore_late_timer(struct event *event)
{
event->ignore_timer_late = true;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ static int vty_command(struct vty *vty, char *buf)

GETRUSAGE(&after);

walltime = thread_consumed_time(&after, &before, &cputime);
walltime = event_consumed_time(&after, &before, &cputime);

if (cputime_enabled_here && cputime_enabled && cputime_threshold
&& cputime > cputime_threshold)
Expand Down
8 changes: 4 additions & 4 deletions lib/workqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,27 +106,27 @@ void work_queue_free_and_null(struct work_queue **wqp)

bool work_queue_is_scheduled(struct work_queue *wq)
{
return thread_is_scheduled(wq->thread);
return event_is_scheduled(wq->thread);
}

static int work_queue_schedule(struct work_queue *wq, unsigned int delay)
{
/* if appropriate, schedule work queue thread */
if (CHECK_FLAG(wq->flags, WQ_UNPLUGGED) &&
!thread_is_scheduled(wq->thread) && !work_queue_empty(wq)) {
!event_is_scheduled(wq->thread) && !work_queue_empty(wq)) {
/* Schedule timer if there's a delay, otherwise just schedule
* as an 'event'
*/
if (delay > 0) {
event_add_timer_msec(wq->master, work_queue_run, wq,
delay, &wq->thread);
thread_ignore_late_timer(wq->thread);
event_ignore_late_timer(wq->thread);
} else
event_add_event(wq->master, work_queue_run, wq, 0,
&wq->thread);

/* set thread yield time, if needed */
if (thread_is_scheduled(wq->thread) &&
if (event_is_scheduled(wq->thread) &&
wq->spec.yield != EVENT_YIELD_TIME_SLOT)
event_set_yield_time(wq->thread, wq->spec.yield);
return 1;
Expand Down
4 changes: 2 additions & 2 deletions ospf6d/ospf6_asbr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1104,7 +1104,7 @@ void ospf6_asbr_distribute_list_update(struct ospf6 *ospf6,
{
SET_FLAG(red->flag, OSPF6_IS_RMAP_CHANGED);

if (thread_is_scheduled(ospf6->t_distribute_update))
if (event_is_scheduled(ospf6->t_distribute_update))
return;

if (IS_OSPF6_DEBUG_ASBR)
Expand Down Expand Up @@ -3363,7 +3363,7 @@ ospf6_start_asbr_summary_delay_timer(struct ospf6 *ospf6,
{
aggr->action = operation;

if (thread_is_scheduled(ospf6->t_external_aggr)) {
if (event_is_scheduled(ospf6->t_external_aggr)) {
if (ospf6->aggr_action == OSPF6_ROUTE_AGGR_ADD) {

if (IS_OSPF6_DEBUG_AGGR)
Expand Down
28 changes: 13 additions & 15 deletions ospf6d/ospf6_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -1140,7 +1140,7 @@ static int ospf6_interface_show(struct vty *vty, struct interface *ifp,

if (use_json) {
timerclear(&res);
if (thread_is_scheduled(oi->thread_send_lsupdate))
if (event_is_scheduled(oi->thread_send_lsupdate))
timersub(&oi->thread_send_lsupdate->u.sands, &now,
&res);
timerstring(&res, duration, sizeof(duration));
Expand All @@ -1150,9 +1150,8 @@ static int ospf6_interface_show(struct vty *vty, struct interface *ifp,
duration);
json_object_string_add(
json_obj, "lsUpdateSendThread",
(thread_is_scheduled(oi->thread_send_lsupdate)
? "on"
: "off"));
(event_is_scheduled(oi->thread_send_lsupdate) ? "on"
: "off"));

json_arr = json_object_new_array();
for (ALL_LSDB(oi->lsupdate_list, lsa, lsanext))
Expand All @@ -1162,7 +1161,7 @@ static int ospf6_interface_show(struct vty *vty, struct interface *ifp,
json_arr);

timerclear(&res);
if (thread_is_scheduled(oi->thread_send_lsack))
if (event_is_scheduled(oi->thread_send_lsack))
timersub(&oi->thread_send_lsack->u.sands, &now, &res);
timerstring(&res, duration, sizeof(duration));

Expand All @@ -1172,8 +1171,8 @@ static int ospf6_interface_show(struct vty *vty, struct interface *ifp,
duration);
json_object_string_add(
json_obj, "lsAckSendThread",
(thread_is_scheduled(oi->thread_send_lsack) ? "on"
: "off"));
(event_is_scheduled(oi->thread_send_lsack) ? "on"
: "off"));

json_arr = json_object_new_array();
for (ALL_LSDB(oi->lsack_list, lsa, lsanext))
Expand All @@ -1183,28 +1182,27 @@ static int ospf6_interface_show(struct vty *vty, struct interface *ifp,

} else {
timerclear(&res);
if (thread_is_scheduled(oi->thread_send_lsupdate))
if (event_is_scheduled(oi->thread_send_lsupdate))
timersub(&oi->thread_send_lsupdate->u.sands, &now,
&res);
timerstring(&res, duration, sizeof(duration));
vty_out(vty,
" %d Pending LSAs for LSUpdate in Time %s [thread %s]\n",
oi->lsupdate_list->count, duration,
(thread_is_scheduled(oi->thread_send_lsupdate)
? "on"
: "off"));
(event_is_scheduled(oi->thread_send_lsupdate) ? "on"
: "off"));
for (ALL_LSDB(oi->lsupdate_list, lsa, lsanext))
vty_out(vty, " %s\n", lsa->name);

timerclear(&res);
if (thread_is_scheduled(oi->thread_send_lsack))
if (event_is_scheduled(oi->thread_send_lsack))
timersub(&oi->thread_send_lsack->u.sands, &now, &res);
timerstring(&res, duration, sizeof(duration));
vty_out(vty,
" %d Pending LSAs for LSAck in Time %s [thread %s]\n",
oi->lsack_list->count, duration,
(thread_is_scheduled(oi->thread_send_lsack) ? "on"
: "off"));
(event_is_scheduled(oi->thread_send_lsack) ? "on"
: "off"));
for (ALL_LSDB(oi->lsack_list, lsa, lsanext))
vty_out(vty, " %s\n", lsa->name);
}
Expand Down Expand Up @@ -2107,7 +2105,7 @@ DEFUN (ipv6_ospf6_hellointerval,
/*
* If the thread is scheduled, send the new hello now.
*/
if (thread_is_scheduled(oi->thread_send_hello)) {
if (event_is_scheduled(oi->thread_send_hello)) {
THREAD_OFF(oi->thread_send_hello);

event_add_timer(master, ospf6_hello_send, oi, 0,
Expand Down
Loading

0 comments on commit 5f6eaa9

Please sign in to comment.