diff options
author | David Lamparter <equinox@diac24.net> | 2018-08-30 08:00:25 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-30 08:00:25 +0200 |
commit | 53acd58416639a0d79dba7dac7ed7732e8f122e8 (patch) | |
tree | f36321071410a60a4df64d33bd19039421408f09 | |
parent | Merge pull request #2938 from pguibert6WIND/spurious_message (diff) | |
parent | *: pthread set name abstraction (diff) | |
download | frr-53acd58416639a0d79dba7dac7ed7732e8f122e8.tar.xz frr-53acd58416639a0d79dba7dac7ed7732e8f122e8.zip |
Merge pull request #2754 from chiragshah6/mdev1
*: pthread set name abstraction
-rw-r--r-- | bgpd/bgp_keepalives.c | 6 | ||||
-rw-r--r-- | bgpd/bgpd.c | 4 | ||||
-rw-r--r-- | lib/frr_pthread.c | 42 | ||||
-rw-r--r-- | lib/frr_pthread.h | 14 | ||||
-rw-r--r-- | zebra/zserv.c | 3 |
5 files changed, 50 insertions, 19 deletions
diff --git a/bgpd/bgp_keepalives.c b/bgpd/bgp_keepalives.c index f81836cc8..aeb95f91b 100644 --- a/bgpd/bgp_keepalives.c +++ b/bgpd/bgp_keepalives.c @@ -180,11 +180,7 @@ void *bgp_keepalives_start(void *arg) pthread_cond_init(peerhash_cond, &attrs); pthread_condattr_destroy(&attrs); -#ifdef GNU_LINUX - pthread_setname_np(fpt->thread, "bgpd_ka"); -#elif defined(OPEN_BSD) - pthread_set_name_np(fpt->thread, "bgpd_ka"); -#endif + frr_pthread_set_name(fpt, NULL, "bgpd_ka"); /* initialize peer hashtable */ peerhash = hash_create_size(2048, peer_hash_key, peer_hash_cmp, NULL); diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index 5d258a765..e6c517a9f 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -7765,8 +7765,8 @@ static void bgp_pthreads_init() .start = bgp_keepalives_start, .stop = bgp_keepalives_stop, }; - frr_pthread_new(&io, "BGP I/O thread"); - frr_pthread_new(&ka, "BGP Keepalives thread"); + frr_pthread_new(&io, "BGP I/O thread", "bgpd_io"); + frr_pthread_new(&ka, "BGP Keepalives thread", "bgpd_ka"); } void bgp_pthreads_run() diff --git a/lib/frr_pthread.c b/lib/frr_pthread.c index f5a6383f4..eb6587a35 100644 --- a/lib/frr_pthread.c +++ b/lib/frr_pthread.c @@ -85,7 +85,7 @@ void frr_pthread_finish() } struct frr_pthread *frr_pthread_new(struct frr_pthread_attr *attr, - const char *name) + const char *name, const char *os_name) { static struct frr_pthread holder = {}; struct frr_pthread *fpt = NULL; @@ -107,6 +107,9 @@ struct frr_pthread *frr_pthread_new(struct frr_pthread_attr *attr, fpt->attr = *attr; name = (name ? name : "Anonymous thread"); fpt->name = XSTRDUP(MTYPE_FRR_PTHREAD, name); + if (os_name) + snprintf(fpt->os_name, OS_THREAD_NAMELEN, + "%s", os_name); if (attr == &frr_pthread_attr_default) fpt->attr.id = frr_pthread_get_id(); /* initialize startup synchronization primitives */ @@ -140,16 +143,34 @@ void frr_pthread_destroy(struct frr_pthread *fpt) XFREE(MTYPE_FRR_PTHREAD, fpt); } -void frr_pthread_set_name(struct frr_pthread *fpt, const char *name) +int frr_pthread_set_name(struct frr_pthread *fpt, const char *name, + const char *os_name) { - pthread_mutex_lock(&fpt->mtx); - { - if (fpt->name) - XFREE(MTYPE_FRR_PTHREAD, fpt->name); - fpt->name = XSTRDUP(MTYPE_FRR_PTHREAD, name); + int ret = 0; + + if (name) { + pthread_mutex_lock(&fpt->mtx); + { + if (fpt->name) + XFREE(MTYPE_FRR_PTHREAD, fpt->name); + fpt->name = XSTRDUP(MTYPE_FRR_PTHREAD, name); + } + pthread_mutex_unlock(&fpt->mtx); + thread_master_set_name(fpt->master, name); } - pthread_mutex_unlock(&fpt->mtx); - thread_master_set_name(fpt->master, name); + + if (os_name) { + pthread_mutex_lock(&fpt->mtx); + snprintf(fpt->os_name, OS_THREAD_NAMELEN, "%s", os_name); + pthread_mutex_unlock(&fpt->mtx); +#ifdef GNU_LINUX + ret = pthread_setname_np(fpt->thread, fpt->os_name); +#elif defined(OPEN_BSD) + ret = pthread_set_name_np(fpt->thread, fpt->os_name); +#endif + } + + return ret; } struct frr_pthread *frr_pthread_get(uint32_t id) @@ -311,6 +332,9 @@ static void *fpt_run(void *arg) fpt->master->handle_signals = false; + if (fpt->os_name) + frr_pthread_set_name(fpt, NULL, fpt->os_name); + frr_pthread_notify_running(fpt); struct thread task; diff --git a/lib/frr_pthread.h b/lib/frr_pthread.h index 91002dd8e..cc4fc7433 100644 --- a/lib/frr_pthread.h +++ b/lib/frr_pthread.h @@ -28,6 +28,8 @@ DECLARE_MTYPE(FRR_PTHREAD); DECLARE_MTYPE(PTHREAD_PRIM); +#define OS_THREAD_NAMELEN 16 + struct frr_pthread; struct frr_pthread_attr; @@ -89,6 +91,9 @@ struct frr_pthread { * Requires: mtx */ char *name; + + /* Used in pthread_set_name max 16 characters */ + char os_name[OS_THREAD_NAMELEN]; }; extern struct frr_pthread_attr frr_pthread_attr_default; @@ -122,18 +127,23 @@ void frr_pthread_finish(void); * * @param attr - the thread attributes * @param name - Human-readable name + * @param os_name - 16 characters (including '\0') thread name to set in os, * @return the created frr_pthread upon success, or NULL upon failure */ struct frr_pthread *frr_pthread_new(struct frr_pthread_attr *attr, - const char *name); + const char *name, const char *os_name); /* * Changes the name of the frr_pthread. * * @param fpt - the frr_pthread to operate on * @param name - Human-readable name + * @param os_name - 16 characters thread name , including the null + * terminator ('\0') to set in os. + * @return - on success returns 0 otherwise nonzero error number. */ -void frr_pthread_set_name(struct frr_pthread *fpt, const char *name); +int frr_pthread_set_name(struct frr_pthread *fpt, const char *name, + const char *os_name); /* * Destroys an frr_pthread. diff --git a/zebra/zserv.c b/zebra/zserv.c index 174e01074..4a341bfe1 100644 --- a/zebra/zserv.c +++ b/zebra/zserv.c @@ -705,7 +705,8 @@ static struct zserv *zserv_client_create(int sock) .stop = frr_pthread_attr_default.stop }; client->pthread = - frr_pthread_new(&zclient_pthr_attrs, "Zebra API client thread"); + frr_pthread_new(&zclient_pthr_attrs, "Zebra API client thread", + "zebra_apic"); zebra_vrf_update_all(client); |