mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-04 20:18:54 +00:00
Merge pull request #2754 from chiragshah6/mdev1
*: pthread set name abstraction
This commit is contained in:
commit
53acd58416
@ -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);
|
||||
|
@ -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()
|
||||
|
@ -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;
|
||||
|
@ -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.
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user