dm: iothread: rename the thread for better readability

This patch renames the iothread for better readability. For instance,
the new name of the iothread for virtio-blk device looks like `iothr-0-blk9:0`.

It could be helpful when tuning the performance and the CPU utilization.

v1 -> v2:
 * add `const` qualifier for the input parameter of `iothread_create`

Tracked-On: #8612

Signed-off-by: Shiqing Gao <shiqing.gao@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
This commit is contained in:
Shiqing Gao 2023-10-27 18:28:54 +08:00 committed by acrnsi-robot
parent 14c20fa31c
commit a90aa4fd26
3 changed files with 25 additions and 8 deletions

View File

@ -63,7 +63,6 @@ io_thread(void *arg)
static int
iothread_start(struct iothread_ctx *ioctx_x)
{
char tname[MAXCOMLEN + 1];
pthread_mutex_lock(&ioctx_x->mtx);
if (ioctx_x->started) {
@ -78,10 +77,9 @@ iothread_start(struct iothread_ctx *ioctx_x)
}
ioctx_x->started = true;
snprintf(tname, sizeof(tname), "iothread_%d", ioctx_x->idx);
pthread_setname_np(ioctx_x->tid, tname);
pthread_setname_np(ioctx_x->tid, ioctx_x->name);
pthread_mutex_unlock(&ioctx_x->mtx);
pr_info("iothread_%d started\n", ioctx_x->idx);
pr_info("%s started\n", ioctx_x->name);
return 0;
}
@ -158,7 +156,7 @@ iothread_deinit(void)
ioctx_x->epfd = -1;
}
pthread_mutex_destroy(&ioctx_x->mtx);
pr_info("iothread_%d stop \n", i);
pr_info("%s stop \n", ioctx_x->name);
}
ioctx_active_cnt = 0;
pthread_mutex_unlock(&ioctxes_mutex);
@ -169,7 +167,7 @@ iothread_deinit(void)
* Return NULL if fails. Otherwise, return the base of those iothread context instances.
*/
struct iothread_ctx *
iothread_create(int ioctx_num)
iothread_create(int ioctx_num, const char *ioctx_tag)
{
pthread_mutexattr_t attr;
int i, ret, base, end;
@ -199,6 +197,11 @@ iothread_create(int ioctx_num)
ioctx_x->started = false;
ioctx_x->epfd = epoll_create1(0);
if (snprintf(ioctx_x->name, PTHREAD_NAME_MAX_LEN,
"iothr-%d-%s", ioctx_x->idx, ioctx_tag) >= PTHREAD_NAME_MAX_LEN) {
pr_err("%s: iothread name too long \n", __func__);
}
if (ioctx_x->epfd < 0) {
ret = -1;
pr_err("%s: failed to create epoll fd, error is %d\r\n",

View File

@ -469,6 +469,7 @@ virtio_blk_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
{
bool dummy_bctxt;
char bident[16];
char ioctx_tag[16];
struct blockif_ctxt *bctxt;
char *opts_tmp = NULL;
char *opts_start = NULL;
@ -585,7 +586,11 @@ virtio_blk_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
num_iothread = num_vqs;
}
ioctx_base = iothread_create(num_iothread);
if (snprintf(ioctx_tag, sizeof(ioctx_tag), "blk%s", bident) >= sizeof(ioctx_tag)) {
pr_err("%s: virtio-blk ioctx_tag too long \n", __func__);
}
ioctx_base = iothread_create(num_iothread, ioctx_tag);
if (ioctx_base == NULL) {
pr_err("%s: Fails to create iothread context instance \n", __func__);
return -1;

View File

@ -9,6 +9,14 @@
#define IOTHREAD_NUM 40
/*
* The pthread_setname_np() function can be used to set a unique name for a thread,
* which can be useful for debugging multithreaded applications.
* The thread name is a meaningful C language string,
* whose length is restricted to 16 characters, including the terminating null byte ('\0').
*/
#define PTHREAD_NAME_MAX_LEN 16
struct iothread_mevent {
void (*run)(void *);
void *arg;
@ -21,6 +29,7 @@ struct iothread_ctx {
bool started;
pthread_mutex_t mtx;
int idx;
char name[PTHREAD_NAME_MAX_LEN];
};
struct iothreads_info {
@ -31,6 +40,6 @@ struct iothreads_info {
int iothread_add(struct iothread_ctx *ioctx_x, int fd, struct iothread_mevent *aevt);
int iothread_del(struct iothread_ctx *ioctx_x, int fd);
void iothread_deinit(void);
struct iothread_ctx *iothread_create(int ioctx_num);
struct iothread_ctx *iothread_create(int ioctx_num, const char *ioctx_tag);
#endif