struct event_config {
TAILQ_HEAD(event_configq, event_config_entry) entries;
+ int n_cpus_hint;
enum event_method_feature require_features;
enum event_base_config_flag flags;
};
#ifdef WIN32
if (cfg && (cfg->flags & EVENT_BASE_FLAG_STARTUP_IOCP))
- event_base_start_iocp(base);
+ event_base_start_iocp(base, cfg->n_cpus_hint);
#endif
return (base);
}
int
-event_base_start_iocp(struct event_base *base)
+event_base_start_iocp(struct event_base *base, int n_cpus)
{
#ifdef WIN32
if (base->iocp)
return 0;
- base->iocp = event_iocp_port_launch();
+ base->iocp = event_iocp_port_launch(n_cpus);
if (!base->iocp) {
event_warnx("%s: Couldn't launch IOCP", __func__);
return -1;
return (0);
}
+int
+event_config_set_num_cpus_hint(struct event_config *cfg, int cpus)
+{
+ if (!cfg)
+ return (-1);
+ cfg->n_cpus_hint = cpus;
+ return (0);
+}
+
int
event_priority_init(int npriorities)
{
return &the_extension_fns;
}
+#define N_CPUS_DEFAULT 2
+
struct event_iocp_port *
-event_iocp_port_launch(void)
+event_iocp_port_launch(int n_cpus)
{
struct event_iocp_port *port;
int i;
if (!(port = mm_calloc(1, sizeof(struct event_iocp_port))))
return NULL;
- port->n_threads = 2;
+
+ if (n_cpus <= 0)
+ n_cpus = N_CPUS_DEFAULT;
+ port->n_threads = n_cpus * 2;
port->threads = calloc(port->n_threads, sizeof(HANDLE));
if (!port->threads)
goto err;
- port->port = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0, port->n_threads);
+ port->port = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0,
+ n_cpus);
port->ms = -1;
if (!port->port)
goto err;
* will be initialized, and how they'll work. */
int event_config_set_flag(struct event_config *cfg, int flag);
+/**
+ * Records a hint for the number of CPUs in the system. This is used for
+ * tuning thread pools, etc, for optimal performance.
+ *
+ * @param cfg the event configuration object
+ * @param cpus the number of cpus
+ * @return 0 on success, -1 on failure.
+ */
+int event_config_set_num_cpus_hint(struct event_config *cfg, int cpus);
+
/**
Initialize the event API.
This interface is unstable, and will change.
*/
-struct event_iocp_port *event_iocp_port_launch(void);
+struct event_iocp_port *event_iocp_port_launch(int n_cpus);
/** Associate a file descriptor with an iocp, such that overlapped IO on the
fd will happen on one of the iocp's worker threads.
struct event_iocp_port *event_base_get_iocp(struct event_base *base);
/* FIXME document. */
-int event_base_start_iocp(struct event_base *base);
+int event_base_start_iocp(struct event_base *base, int n_cpus);
void event_base_stop_iocp(struct event_base *base);
/* FIXME document. */
case 'i':
use_iocp = 1;
evthread_use_windows_threads();
- event_base_start_iocp(base);
+ event_base_start_iocp(base, 0);
break;
#endif
default:
event_overlapped_init(&o1.eo, dummy_cb);
event_overlapped_init(&o2.eo, dummy_cb);
- port = event_iocp_port_launch();
+ port = event_iocp_port_launch(0);
tt_assert(port);
tt_assert(!event_iocp_activate_overlapped(port, &o1.eo, 10, 100));
evbuffer_enable_locking(rbuf, NULL);
evbuffer_enable_locking(wbuf, NULL);
- port = event_iocp_port_launch();
+ port = event_iocp_port_launch(0);
tt_assert(port);
tt_assert(rbuf);
tt_assert(wbuf);
char buf[128];
size_t n;
- event_base_start_iocp(data->base);
+ event_base_start_iocp(data->base, 0);
port = event_base_get_iocp(data->base);
tt_assert(port);
exit(1);
}
if (testcase->flags & TT_ENABLE_IOCP_FLAG) {
- if (event_base_start_iocp(base)<0) {
+ if (event_base_start_iocp(base, 0)<0) {
event_base_free(base);
return (void*)TT_SKIP;
}