pthread_t thread;
int id;
atomic_uint change_seq;
- char *name;
};
/* Interface to netdev-based datapath. */
int poll_cnt;
int i;
- f->name = xasprintf("pmd_%u", ovsthread_id_self());
- set_subprogram_name("%s", f->name);
poll_cnt = 0;
poll_list = NULL;
}
free(poll_list);
- free(f->name);
return NULL;
}
/* Each thread will distribute all devices rx-queues among
* themselves. */
- xpthread_create(&f->thread, NULL, pmd_thread_main, f);
+ f->thread = ovs_thread_create("pmd", pmd_thread_main, f);
}
}
static struct list dpdk_mp_list OVS_GUARDED_BY(dpdk_mutex)
= LIST_INITIALIZER(&dpdk_mp_list);
-static pthread_t watchdog_thread;
-
struct dpdk_mp {
struct rte_mempool *mp;
int mtu;
"[netdev] up|down", 1, 2,
netdev_dpdk_set_admin_state, NULL);
- xpthread_create(&watchdog_thread, NULL, dpdk_watchdog, NULL);
+ ovs_thread_create("dpdk_watchdog", dpdk_watchdog, NULL);
return 0;
}
} else {
static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER;
if (ovsthread_once_start(&once)) {
- xpthread_create(NULL, NULL, ovsrcu_postpone_thread, NULL);
+ ovs_thread_create("urcu", ovsrcu_postpone_thread, NULL);
ovsthread_once_done(&once);
}
}
static void *
ovsrcu_postpone_thread(void *arg OVS_UNUSED)
{
- set_subprogram_name("urcu");
pthread_detach(pthread_self());
for (;;) {
struct ovsthread_aux {
void *(*start)(void *);
void *arg;
+ char name[16];
};
static void *
aux = *auxp;
free(auxp);
+ set_subprogram_name("%s%u", aux.name, id);
+
ovsrcu_quiesce_end();
return aux.start(aux.arg);
}
-void
-xpthread_create(pthread_t *threadp, pthread_attr_t *attr,
- void *(*start)(void *), void *arg)
+/* Starts a thread that calls 'start(arg)'. Sets the thread's name to 'name'
+ * (suffixed by its ovsthread_id()). Returns the new thread's pthread_t. */
+pthread_t
+ovs_thread_create(const char *name, void *(*start)(void *), void *arg)
{
struct ovsthread_aux *aux;
pthread_t thread;
aux = xmalloc(sizeof *aux);
aux->start = start;
aux->arg = arg;
+ ovs_strlcpy(aux->name, name, sizeof aux->name);
- error = pthread_create(threadp ? threadp : &thread, attr,
- ovsthread_wrapper, aux);
+ error = pthread_create(&thread, NULL, ovsthread_wrapper, aux);
if (error) {
ovs_abort(error, "pthread_create failed");
}
+ return thread;
}
\f
bool
void xpthread_key_delete(pthread_key_t);
void xpthread_setspecific(pthread_key_t, const void *);
-void xpthread_create(pthread_t *, pthread_attr_t *, void *(*)(void *), void *);
+pthread_t ovs_thread_create(const char *name, void *(*)(void *), void *);
void xpthread_join(pthread_t, void **);
\f
/* Per-thread data.
static void *
monitor_main(void * args OVS_UNUSED)
{
- set_subprogram_name("monitor");
VLOG_INFO("monitor thread created");
while (!latch_is_set(&monitor_exit_latch)) {
monitor_run();
* terminates it. */
if (!monitor_running && !hmap_is_empty(&monitor_hmap)) {
latch_init(&monitor_exit_latch);
- xpthread_create(&monitor_tid, NULL, monitor_main, NULL);
+ monitor_tid = ovs_thread_create("monitor", monitor_main, NULL);
monitor_running = true;
} else if (monitor_running && hmap_is_empty(&monitor_hmap)) {
latch_set(&monitor_exit_latch);
struct handler {
struct udpif *udpif; /* Parent udpif. */
pthread_t thread; /* Thread ID. */
- char *name; /* Thread name. */
uint32_t handler_id; /* Handler id. */
};
* updates or removes them if necessary. */
struct revalidator {
struct udpif *udpif; /* Parent udpif. */
- char *name; /* Thread name. */
-
pthread_t thread; /* Thread ID. */
+ unsigned int id; /* ovsthread_id_self(). */
struct hmap *ukeys; /* Points into udpif->ukeys for this
revalidator. Used for GC phase. */
};
/* Delete ukeys, and delete all flows from the datapath to prevent
* double-counting stats. */
revalidator_purge(revalidator);
- free(revalidator->name);
hmap_destroy(&udpif->ukeys[i].hmap);
ovs_mutex_destroy(&udpif->ukeys[i].mutex);
}
- for (i = 0; i < udpif->n_handlers; i++) {
- free(udpif->handlers[i].name);
- }
latch_poll(&udpif->exit_latch);
xpthread_barrier_destroy(&udpif->reval_barrier);
handler->udpif = udpif;
handler->handler_id = i;
- xpthread_create(&handler->thread, NULL, udpif_upcall_handler,
- handler);
+ handler->thread = ovs_thread_create(
+ "handler", udpif_upcall_handler, handler);
}
xpthread_barrier_init(&udpif->reval_barrier, NULL,
hmap_init(&udpif->ukeys[i].hmap);
ovs_mutex_init(&udpif->ukeys[i].mutex);
revalidator->ukeys = &udpif->ukeys[i].hmap;
- xpthread_create(&revalidator->thread, NULL, udpif_revalidator,
- revalidator);
+ revalidator->thread = ovs_thread_create(
+ "revalidator", udpif_revalidator, revalidator);
}
}
}
struct udpif *udpif = handler->udpif;
struct hmap misses = HMAP_INITIALIZER(&misses);
- handler->name = xasprintf("handler_%u", ovsthread_id_self());
- set_subprogram_name("%s", handler->name);
-
while (!latch_is_set(&handler->udpif->exit_latch)) {
struct upcall upcalls[FLOW_MISS_MAX_BATCH];
struct flow_miss miss_buf[FLOW_MISS_MAX_BATCH];
unsigned int flow_limit = 0;
size_t n_flows = 0;
- revalidator->name = xasprintf("revalidator_%u", ovsthread_id_self());
- set_subprogram_name("%s", revalidator->name);
+ revalidator->id = ovsthread_id_self();
for (;;) {
if (leader) {
uint64_t reval_seq;
struct revalidator *revalidator = &udpif->revalidators[i];
ovs_mutex_lock(&udpif->ukeys[i].mutex);
- ds_put_format(&ds, "\t%s: (keys %"PRIuSIZE")\n", revalidator->name,
- hmap_count(&udpif->ukeys[i].hmap));
+ ds_put_format(&ds, "\t%u: (keys %"PRIuSIZE")\n",
+ revalidator->id, hmap_count(&udpif->ukeys[i].hmap));
ovs_mutex_unlock(&udpif->ukeys[i].mutex);
}
}
ovs_mutex_lock(&mutex);
if (enable) {
if (!started) {
- xpthread_create(NULL, NULL, system_stats_thread_func, NULL);
+ ovs_thread_create("system_stats",
+ system_stats_thread_func, NULL);
latch_init(&latch);
started = true;
}