Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: Substitute poll APIs with epoll APIs in thread management routine #18126

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

donaldsharp
Copy link
Member

This commit substitutes poll APIs with epoll APIs for better performace. Note that epoll APIs are only available for Linux platforms. For BSD platforms which do not support epoll APIs, poll APIs are still used.

@donaldsharp
Copy link
Member Author

This is a bring forward of #12862 as that we should really get this in. I'm not the original author and I don't want to mess with the original PR so we have this one.

lib/event.c Outdated
@@ -60,7 +64,7 @@ DECLARE_HEAP(event_timer_list, struct event, timeritem, event_timer_cmp);
#define AWAKEN(m) \
do { \
const unsigned char wakebyte = 0x01; \
write(m->io_pipe[1], &wakebyte, 1); \
write((m)->io_pipe[1], &wakebyte, 1); \
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the () around m? Donald to investigate

lib/event.c Outdated
@@ -124,8 +128,7 @@ static void cpu_records_free(struct cpu_event_history **p)
static void vty_out_cpu_event_history(struct vty *vty,
struct cpu_event_history *a)
{
vty_out(vty,
"%5zu %10zu.%03zu %9zu %8zu %9zu %8zu %9zu %9zu %9zu %10zu",
vty_out(vty, "%5zu %10zu.%03zu %9zu %8zu %9zu %8zu %9zu %9zu %9zu %10zu",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whitespace changes need to be removed

lib/event.c Outdated
atomic_load_explicit(&a->total_cpu_warn, memory_order_seq_cst);
copy.total_wall_warn =
atomic_load_explicit(&a->total_wall_warn, memory_order_seq_cst);
copy.total_active = atomic_load_explicit(&a->total_active,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more white space chagnes?

lib/event.c Outdated
"Set up miscellaneous service\n"
"Warn for tasks exceeding CPU usage threshold\n"
"Warning threshold in milliseconds\n")
DEFPY(service_cputime_warning, service_cputime_warning_cmd,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more white space

lib/event.c Outdated
"Set up miscellaneous service\n"
"Warn for tasks exceeding total wallclock threshold\n"
"Warning threshold in milliseconds\n")
DEFPY(service_walltime_warning, service_walltime_warning_cmd,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more whitespace?

thread = m->read[ev->data.fd];

if (!thread)
vty_out(vty, "ERROR ");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make ERROR meaningful

lib/event.c Outdated
SHOW_STR
"Event information\n"
"Event Poll Information\n")
DEFUN_NOSH(show_event_poll, show_event_poll_cmd, "show event poll",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more whitespace

lib/event.c Outdated
SHOW_STR
"Event information\n"
"Show all timers and how long they have in the system\n")
DEFPY_NOSH(show_event_timers, show_event_timers_cmd, "show event timers",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whitespace

@@ -515,11 +573,63 @@ static void initializer(void)
pthread_key_create(&thread_current, NULL);
}

#if EPOLL_ENABLED
static struct epoll_event *epoll_event_new(int fd, uint32_t events)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note for donald -> Check to see if we leak this new memory

*fd_closed = true;
return;
}
zlog_debug("[!] In %s, fstat failed unexpectedly, fd: %d, errno: %d)",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should not be a debug

set_ev.events =
(dir == EVENT_READ
? EPOLLIN
: EPOLLOUT); // reset .events of new set_ev
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix double slash comment

@@ -877,17 +1040,20 @@ static int fd_poll(struct event_loop *m, const struct timeval *timer_wait,
/* Don't make any changes for the non-main pthreads */
pthread_sigmask(SIG_SETMASK, NULL, &origsigs);
}

#if defined(HAVE_PPOLL)
struct timespec ts, *tsp;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If using poll we still need to figure out how long to wait

This commit substitutes poll APIs with epoll APIs for better performace. Note that epoll APIs are only available for Linux platforms. For BSD platforms which do not support epoll APIs, poll APIs are still used.

Signed-off-by: Kaifei Peng <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants