target: add iscsi/cpus_allowed_list in configfs
Subsystems (2)
PATCH 1/1 target: add iscsi/cpus_allowed_list in configfs
From: Mingzhe Zou <[email protected]>
The RX/TX threads for iSCSI connection can be scheduled to any online cpus, and will not be rescheduled.
If bind other heavy load threads with iSCSI connection RX/TX thread to the same cpu, the iSCSI performance will be worse.
This patch add iscsi/cpus_allowed_list in configfs. The available cpus set of iSCSI connection RX/TX threads is allowed_cpus & online_cpus. If it is modified, all RX/TX threads will be rescheduled.
--- drivers/target/iscsi/iscsi_target.c | 21 ++++++++++-- drivers/target/iscsi/iscsi_target.h | 17 ++++++++++ drivers/target/iscsi/iscsi_target_configfs.c | 34 ++++++++++++++++++++ drivers/target/iscsi/iscsi_target_login.c | 7 ++++ include/target/iscsi/iscsi_target_core.h | 1 + 5 files changed, 78 insertions(+), 2 deletions(-)
drivers/target/iscsi/iscsi_target.c +19 -2
@@ -693,6 +693,11 @@ static int __init iscsi_target_init_module(void)mutex_init (&auth_id_lock);idr_init (&tiqn_idr); +/* +* allow all cpus run iscsi_ttx and iscsi_trx +*/ +cpumask_setall (&__iscsi_allowed_cpumask); + ret =target_register_template (&iscsi_ops);if (ret) goto out;
@@ -3587,6 +3592,15 @@ static int iscsit_send_reject(void iscsit_thread_get_cpumask (struct iscsi_conn *conn) {int ord, cpu; +cpumask_t conn_allowed_cpumask; + +/* +* The available cpus set of iSCSI connection's RX/TX threads +*/ +cpumask_and (&conn_allowed_cpumask, + &__iscsi_allowed_cpumask, + cpu_online_mask); +/* * bitmap_id is assigned from iscsit_global->ts_bitmap from * within iscsit_start_kthreads()
@@ -3595,8 +3609,9 @@ void iscsit_thread_get_cpumask(struct iscsi_conn *conn)* iSCSI connection's RX/TX threads will be scheduled to * execute upon. */ - ord = conn->bitmap_id %cpumask_weight (cpu_online_mask); -for_each_online_cpu (cpu) { +cpumask_clear (conn->conn_cpumask); + ord = conn->bitmap_id %cpumask_weight (&conn_allowed_cpumask); +for_each_cpu (cpu, &conn_allowed_cpumask) {if (ord-- ==0 ) {cpumask_set_cpu (cpu, conn->conn_cpumask);return ;
@@ -3821,6 +3836,7 @@ int iscsi_target_tx_thread(void *arg)* Ensure that both TX and RX per connection kthreads * are scheduled to run on the same CPU. */ +iscsit_thread_reschedule (conn);iscsit_thread_check_cpumask (conn, current,1 ); wait_event_interruptible(conn->queues_wq,
@@ -3966,6 +3982,7 @@ static void iscsit_get_rx_pdu(struct iscsi_conn *conn)* Ensure that both TX and RX per connection kthreads * are scheduled to run on the same CPU. */ +iscsit_thread_reschedule (conn);iscsit_thread_check_cpumask (conn, current,0 );memset (&iov,0 ,sizeof (struct kvec ));
drivers/target/iscsi/iscsi_target.h +17 -0
@@ -57,4 +57,21 @@ extern struct kmem_cache *lio_r2t_cache;extern struct ida sess_ida;extern struct mutex auth_id_lock; +extern cpumask_t __iscsi_allowed_cpumask; + +static inline void iscsit_thread_reschedule (struct iscsi_conn *conn) +{ +/* +* If __iscsi_allowed_cpumask modified, reschedule iSCSI connection's +* RX/TX threads update conn->allowed_cpumask. +*/ +if (!cpumask_equal (&__iscsi_allowed_cpumask, conn->allowed_cpumask)) { +iscsit_thread_get_cpumask (conn); + conn->conn_tx_reset_cpumask =1 ; + conn->conn_rx_reset_cpumask =1 ; +cpumask_copy (conn->allowed_cpumask, + &__iscsi_allowed_cpumask); + } +} +#endif /*** ISCSI_TARGET_H ***/
drivers/target/iscsi/iscsi_target_configfs.c +34 -0
@@ -1127,8 +1127,42 @@ static ssize_t lio_target_wwn_lio_version_show(struct config_item *item,CONFIGFS_ATTR_RO (lio_target_wwn_, lio_version); +cpumask_t __iscsi_allowed_cpumask; + +static ssize_t lio_target_wwn_cpus_allowed_list_show ( +struct config_item *item,char *page) +{ +return sprintf (page,"%*pbl\n" , +cpumask_pr_args (&__iscsi_allowed_cpumask)); +} + +static ssize_t lio_target_wwn_cpus_allowed_list_store ( +struct config_item *item,const char *page,size_t count) +{ +int ret; +char *orig; +cpumask_t new_allowed_cpumask; + + orig =kstrdup (page,GFP_KERNEL ); +if (!orig) +return -ENOMEM ; + +cpumask_clear (&new_allowed_cpumask); + ret =cpulist_parse (orig, &new_allowed_cpumask); + +kfree (orig); +if (ret !=0 ) +return ret; + +cpumask_copy (&__iscsi_allowed_cpumask, &new_allowed_cpumask); +return count; +} + +CONFIGFS_ATTR (lio_target_wwn_, cpus_allowed_list); +static struct configfs_attribute *lio_target_wwn_attrs[] = { &lio_target_wwn_attr_lio_version, + &lio_target_wwn_attr_cpus_allowed_list,NULL , };
drivers/target/iscsi/iscsi_target_login.c +7 -0
@@ -1129,8 +1129,15 @@ static struct iscsi_conn *iscsit_alloc_conn(struct iscsi_np *np) goto free_conn_ops; } +if (!zalloc_cpumask_var (&conn->allowed_cpumask,GFP_KERNEL )) { +pr_err ("Unable to allocate conn->allowed_cpumask\n" ); + goto free_conn_cpumask; + } +return conn; +free_conn_cpumask: +free_cpumask_var (conn->allowed_cpumask); free_conn_ops:kfree (conn->conn_ops); put_transport:
include/target/iscsi/iscsi_target_core.h +1 -0
@@ -580,6 +580,7 @@ struct iscsi_conn {struct ahash_request *conn_tx_hash;/* Used for scheduling TX and RX connection kthreads */ cpumask_var_t conn_cpumask; +cpumask_var_t allowed_cpumask; unsigned int conn_rx_reset_cpumask:1; unsigned int conn_tx_reset_cpumask:1;/* list_head of struct iscsi_cmd for this connection */
Signature · 1 line
2.17.1
Quoted 28 lines · On 1/25/22 2:38 AM, [email protected] wrote:
From: Mingzhe Zou <[email protected]>
The RX/TX threads for iSCSI connection can be scheduled to any online cpus, and will not be rescheduled.
If bind other heavy load threads with iSCSI connection RX/TX thread to the same cpu, the iSCSI performance will be worse.
This patch add iscsi/cpus_allowed_list in configfs. The available cpus set of iSCSI connection RX/TX threads is
allowed_cpus&online_cpus. If it is modified, all RX/TX threads will be rescheduled.Signed-off-by Mingzhe Zou <[email protected]>--- drivers/target/iscsi/iscsi_target.c | 21 ++++++++++-- drivers/target/iscsi/iscsi_target.h | 17 ++++++++++ drivers/target/iscsi/iscsi_target_configfs.c | 34 ++++++++++++++++++++ drivers/target/iscsi/iscsi_target_login.c | 7 ++++ include/target/iscsi/iscsi_target_core.h | 1 + 5 files changed, 78 insertions(+), 2 deletions(-)drivers/target/iscsi/iscsi_target.c +0
-0
drivers/target/iscsi/iscsi_target.c static int __init iscsi_target_init_module(void) · line 697
Quoted 5 lines
drivers/target/iscsi/iscsi_target.c +2
-0@@ -693,6 +693,11 @@ static int __init iscsi_target_init_module(void)mutex_init (&auth_id_lock);idr_init (&tiqn_idr); +/* +* allow all cpus run iscsi_ttx and iscsi_trx
I would just drop the comment. The "setall" in the function name is pretty clear already.
Quoted 7 lines
drivers/target/iscsi/iscsi_target.c +3
-0+*/ +cpumask_setall (&__iscsi_allowed_cpumask); + ret =target_register_template (&iscsi_ops);if (ret) goto out;
drivers/target/iscsi/iscsi_target.c static int iscsit_send_reject( · line 3599
Quoted 8 lines
drivers/target/iscsi/iscsi_target.c +5
-0@@ -3587,6 +3592,15 @@ static int iscsit_send_reject(void iscsit_thread_get_cpumask (struct iscsi_conn *conn) {int ord, cpu; +cpumask_t conn_allowed_cpumask; + +/* +* The available cpus set of iSCSI connection's RX/TX threads +*/
Probably can drop the comment too since the variable names make it known what we are doing.
drivers/target/iscsi/iscsi_target.c static int iscsit_send_reject( · line 3602
Quoted 3 lines
drivers/target/iscsi/iscsi_target.c +3
-0+cpumask_and (&conn_allowed_cpumask, + &__iscsi_allowed_cpumask, + cpu_online_mask);
The formatting needs some fix ups. I think __iscsi_allowed_cpumask can fit on the line above it and then cpu_online_mask should be moved over a couple spaces to align with the opening "(".
Quoted 17 lines
drivers/target/iscsi/iscsi_target.c +4
-2+/* * bitmap_id is assigned from iscsit_global->ts_bitmap from * within iscsit_start_kthreads() @@ -3595,8 +3609,9 @@ void iscsit_thread_get_cpumask(struct iscsi_conn *conn)* iSCSI connection's RX/TX threads will be scheduled to * execute upon. */ - ord = conn->bitmap_id %cpumask_weight (cpu_online_mask); -for_each_online_cpu (cpu) { +cpumask_clear (conn->conn_cpumask); + ord = conn->bitmap_id %cpumask_weight (&conn_allowed_cpumask); +for_each_cpu (cpu, &conn_allowed_cpumask) {if (ord-- ==0 ) {cpumask_set_cpu (cpu, conn->conn_cpumask);return ;
drivers/target/iscsi/iscsi_target.c int iscsi_target_tx_thread(void *arg) · line 3839
Quoted 4 lines
drivers/target/iscsi/iscsi_target.c +1
-0@@ -3821,6 +3836,7 @@ int iscsi_target_tx_thread(void *arg)* Ensure that both TX and RX per connection kthreads * are scheduled to run on the same CPU. */ +iscsit_thread_reschedule (conn);
If we have multiple sessions to the same portal, could we end up racing where session0's tx/rx threads call iscsit_thread_reschedule and iscsit_thread_check_cpumask at the same time as session1's threads and they end up taking the same cpus. They both could be running iscsit_thread_get_cpumask at the same time, see he same masks values and in the for_each_cpu loop think the same cpu is free.
Quoted 16 lines
drivers/target/iscsi/iscsi_target.c +1
-0iscsit_thread_check_cpumask (conn, current,1 ); wait_event_interruptible(conn->queues_wq,@@ -3966,6 +3982,7 @@ static void iscsit_get_rx_pdu(struct iscsi_conn *conn)* Ensure that both TX and RX per connection kthreads * are scheduled to run on the same CPU. */ +iscsit_thread_reschedule (conn);iscsit_thread_check_cpumask (conn, current,0 );memset (&iov,0 ,sizeof (struct kvec ));drivers/target/iscsi/iscsi_target.h +0
-0
drivers/target/iscsi/iscsi_target.h extern struct kmem_cache *lio_r2t_cache; · line 60
Quoted 4 lines
drivers/target/iscsi/iscsi_target.h +1
-0@@ -57,4 +57,21 @@ extern struct kmem_cache *lio_r2t_cache;extern struct ida sess_ida;extern struct mutex auth_id_lock; +extern cpumask_t __iscsi_allowed_cpumask;
I would rename to:
iscsit_allowed_cpumask
drivers/target/iscsi/iscsi_target.h extern struct kmem_cache *lio_r2t_cache; · line 73
Quoted 13 lines
drivers/target/iscsi/iscsi_target.h +13
-0+ +static inline void iscsit_thread_reschedule (struct iscsi_conn *conn) +{ +/* +* If __iscsi_allowed_cpumask modified, reschedule iSCSI connection's +* RX/TX threads update conn->allowed_cpumask. +*/ +if (!cpumask_equal (&__iscsi_allowed_cpumask, conn->allowed_cpumask)) { +iscsit_thread_get_cpumask (conn); + conn->conn_tx_reset_cpumask =1 ; + conn->conn_rx_reset_cpumask =1 ; +cpumask_copy (conn->allowed_cpumask, + &__iscsi_allowed_cpumask);
Fix up formatting like above.
drivers/target/iscsi/iscsi_target_configfs.c static ssize_t lio_target_wwn_lio_version_show(struct config_item *item, · line 1130
Quoted 13 lines
drivers/target/iscsi/iscsi_target.h +3
-0+ } +} +#endif /*** ISCSI_TARGET_H ***/ drivers/target/iscsi/iscsi_target_configfs.c +1
-0@@ -1127,8 +1127,42 @@ static ssize_t lio_target_wwn_lio_version_show(struct config_item *item,CONFIGFS_ATTR_RO (lio_target_wwn_, lio_version); +cpumask_t __iscsi_allowed_cpumask;
Maybe better to put this in iscsi_target.c with the other vars like it.
drivers/target/iscsi/iscsi_target_configfs.c static ssize_t lio_target_wwn_lio_version_show(struct config_item *item, · line 1136
Quoted 6 lines
drivers/target/iscsi/iscsi_target_configfs.c +6
-0+ +static ssize_t lio_target_wwn_cpus_allowed_list_show ( +struct config_item *item,char *page) +{ +return sprintf (page,"%*pbl\n" , +cpumask_pr_args (&__iscsi_allowed_cpumask));
Formatting like above.
Quoted 5 lines
drivers/target/iscsi/iscsi_target_configfs.c +5
-0+} + +static ssize_t lio_target_wwn_cpus_allowed_list_store ( +struct config_item *item,const char *page,size_t count) +{
drivers/target/iscsi/iscsi_target_configfs.c static ssize_t lio_target_wwn_lio_version_show(struct config_item *item, · line 1151
Quoted 10 lines
drivers/target/iscsi/iscsi_target_configfs.c +10
-0+int ret; +char *orig; +cpumask_t new_allowed_cpumask; + + orig =kstrdup (page,GFP_KERNEL ); +if (!orig) +return -ENOMEM ; + +cpumask_clear (&new_allowed_cpumask); + ret =cpulist_parse (orig, &new_allowed_cpumask);
Are you supposed to do a zalloc_cpumask_var/free_cpumask_var before using new_allowed_cpumask? It looks like other callers are doing it.
Quoted 22 lines
drivers/target/iscsi/iscsi_target_configfs.c +12
-0+ +kfree (orig); +if (ret !=0 ) +return ret; + +cpumask_copy (&__iscsi_allowed_cpumask, &new_allowed_cpumask); +return count; +} + +CONFIGFS_ATTR (lio_target_wwn_, cpus_allowed_list); +static struct configfs_attribute *lio_target_wwn_attrs[] = { &lio_target_wwn_attr_lio_version, + &lio_target_wwn_attr_cpus_allowed_list,NULL , };drivers/target/iscsi/iscsi_target_login.c +0
-0
drivers/target/iscsi/iscsi_target_login.c static struct iscsi_conn *iscsit_alloc_conn(struct iscsi_np *np) · line 1135
Quoted 7 lines
drivers/target/iscsi/iscsi_target_login.c +4
-0@@ -1129,8 +1129,15 @@ static struct iscsi_conn *iscsit_alloc_conn(struct iscsi_np *np) goto free_conn_ops; } +if (!zalloc_cpumask_var (&conn->allowed_cpumask,GFP_KERNEL )) { +pr_err ("Unable to allocate conn->allowed_cpumask\n" ); + goto free_conn_cpumask; + }
I think in iscsit_free_conn you need a:
free_cpumask_var(conn->allowed_cpumask);
to go with this allocation.
drivers/target/iscsi/iscsi_target_login.c static struct iscsi_conn *iscsit_alloc_conn(struct iscsi_np *np) · line 1140
Quoted 5 lines
drivers/target/iscsi/iscsi_target_login.c +3
-0+return conn; +free_conn_cpumask: +free_cpumask_var (conn->allowed_cpumask);
I think you wanted conn->conn_cpumask here.
Quoted 15 lines
drivers/target/iscsi/iscsi_target_login.c +0
-0free_conn_ops:kfree (conn->conn_ops); put_transport:include/target/iscsi/iscsi_target_core.h +1
-0@@ -580,6 +580,7 @@ struct iscsi_conn {struct ahash_request *conn_tx_hash;/* Used for scheduling TX and RX connection kthreads */ cpumask_var_t conn_cpumask; +cpumask_var_t allowed_cpumask; unsigned int conn_rx_reset_cpumask:1; unsigned int conn_tx_reset_cpumask:1;/* list_head of struct iscsi_cmd for this connection */
Quoted 32 lines · Mike Christie
Quoted 31 lines · On 1/25/22 2:38 AM, [email protected] wrote:
From: Mingzhe Zou <[email protected]>
The RX/TX threads for iSCSI connection can be scheduled to any online cpus, and will not be rescheduled.
If bind other heavy load threads with iSCSI connection RX/TX thread to the same cpu, the iSCSI performance will be worse.
This patch add iscsi/cpus_allowed_list in configfs. The available cpus set of iSCSI connection RX/TX threads is
allowed_cpus&online_cpus. If it is modified, all RX/TX threads will be rescheduled.Signed-off-by Mingzhe Zou <[email protected]>--- drivers/target/iscsi/iscsi_target.c | 21 ++++++++++-- drivers/target/iscsi/iscsi_target.h | 17 ++++++++++ drivers/target/iscsi/iscsi_target_configfs.c | 34 ++++++++++++++++++++ drivers/target/iscsi/iscsi_target_login.c | 7 ++++ include/target/iscsi/iscsi_target_core.h | 1 + 5 files changed, 78 insertions(+), 2 deletions(-)drivers/target/iscsi/iscsi_target.c +0
-0@@ -693,6 +693,11 @@ static int __init iscsi_target_init_module(void)mutex_init (&auth_id_lock);idr_init (&tiqn_idr);
Quoted 4 lines
drivers/target/iscsi/iscsi_target.c static int __init iscsi_target_init_module(void) · line 697
Quoted 2 lines
drivers/target/iscsi/iscsi_target.c +2
-0+/* +* allow all cpus run iscsi_ttx and iscsi_trx I would just drop the comment. The "setall" in the function name is pretty clear already.
I will remove it.
Quoted 11 lines
Quoted 11 lines
drivers/target/iscsi/iscsi_target.c +3
-0+*/ +cpumask_setall (&__iscsi_allowed_cpumask); + ret =target_register_template (&iscsi_ops);if (ret) goto out;@@ -3587,6 +3592,15 @@ static int iscsit_send_reject(void iscsit_thread_get_cpumask (struct iscsi_conn *conn) {
Quoted 8 lines
drivers/target/iscsi/iscsi_target.c static int iscsit_send_reject( · line 3599
Quoted 6 lines
drivers/target/iscsi/iscsi_target.c +5
-0int ord, cpu; +cpumask_t conn_allowed_cpumask; + +/* +* The available cpus set of iSCSI connection's RX/TX threads +*/ Probably can drop the comment too since the variable names make it known what we are doing.
I will remove it.
Quoted 8 lines
drivers/target/iscsi/iscsi_target.c static int iscsit_send_reject( · line 3602
Quoted 5 lines
drivers/target/iscsi/iscsi_target.c +3
-0+cpumask_and (&conn_allowed_cpumask, + &__iscsi_allowed_cpumask, + cpu_online_mask);The formatting needs some fix ups. I think
__iscsi_allowed_cpumaskcan fit on the line above it and thencpu_online_maskshould be moved over a couple spaces to align with the opening "(".
I will reformat.
Quoted 22 lines
Quoted 22 lines
drivers/target/iscsi/iscsi_target.c +4
-2+/* * bitmap_id is assigned from iscsit_global->ts_bitmap from * within iscsit_start_kthreads() @@ -3595,8 +3609,9 @@ void iscsit_thread_get_cpumask(struct iscsi_conn *conn)* iSCSI connection's RX/TX threads will be scheduled to * execute upon. */ - ord = conn->bitmap_id %cpumask_weight (cpu_online_mask); -for_each_online_cpu (cpu) { +cpumask_clear (conn->conn_cpumask); + ord = conn->bitmap_id %cpumask_weight (&conn_allowed_cpumask); +for_each_cpu (cpu, &conn_allowed_cpumask) {if (ord-- ==0 ) {cpumask_set_cpu (cpu, conn->conn_cpumask);return ;@@ -3821,6 +3836,7 @@ int iscsi_target_tx_thread(void *arg)* Ensure that both TX and RX per connection kthreads * are scheduled to run on the same CPU. */
Quoted 8 lines
drivers/target/iscsi/iscsi_target.c int iscsi_target_tx_thread(void *arg) · line 3839
Quoted 1 line
drivers/target/iscsi/iscsi_target.c +1
-0+iscsit_thread_reschedule (conn);If we have multiple sessions to the same portal, could we end up racing where session0's tx/rx threads call
iscsit_thread_rescheduleandiscsit_thread_check_cpumaskat the same time as session1's threads and they end up taking the same cpus. They both could be runningiscsit_thread_get_cpumaskat the same time, see he same masks values and in thefor_each_cpuloop think the same cpu is free.
Simply, this patch just adds a config item to skip some CPUs that are bound to other threads,
not to change the calculation method of cpumask.
When the cpus_allowed_list in sysfs is modified, the tx/rx threads of all sessions will clear current
cpumask and call iscsit_thread_reschedule and iscsit_thread_check_cpumask to get a new value.
Because each session is allocated a unique bitmap_id in advance, then calculate the cpumask
via bitmap_id. So the tx/rx threads of different sessions will be scheduled to different CPUs (when
the number of CPUs is sufficient).
Quoted 21 lines
Quoted 21 lines
drivers/target/iscsi/iscsi_target.c +1
-0iscsit_thread_check_cpumask (conn, current,1 ); wait_event_interruptible(conn->queues_wq,@@ -3966,6 +3982,7 @@ static void iscsit_get_rx_pdu(struct iscsi_conn *conn)* Ensure that both TX and RX per connection kthreads * are scheduled to run on the same CPU. */ +iscsit_thread_reschedule (conn);iscsit_thread_check_cpumask (conn, current,0 );memset (&iov,0 ,sizeof (struct kvec ));drivers/target/iscsi/iscsi_target.h +0
-0@@ -57,4 +57,21 @@ extern struct kmem_cache *lio_r2t_cache;extern struct ida sess_ida;extern struct mutex auth_id_lock;
Quoted 5 lines
drivers/target/iscsi/iscsi_target.h extern struct kmem_cache *lio_r2t_cache; · line 60
Quoted 1 line
drivers/target/iscsi/iscsi_target.h +1
-0+extern cpumask_t __iscsi_allowed_cpumask;I would rename to:
iscsit_allowed_cpumask
I will rename to iscsit_allowed_cpumas.
Quoted 6 lines
Quoted 6 lines
drivers/target/iscsi/iscsi_target.h +6
-0+ +static inline void iscsit_thread_reschedule (struct iscsi_conn *conn) +{ +/* +* If __iscsi_allowed_cpumask modified, reschedule iSCSI connection's +* RX/TX threads update conn->allowed_cpumask.
Quoted 8 lines
drivers/target/iscsi/iscsi_target.h extern struct kmem_cache *lio_r2t_cache; · line 73
Quoted 7 lines
drivers/target/iscsi/iscsi_target.h +7
-0+*/ +if (!cpumask_equal (&__iscsi_allowed_cpumask, conn->allowed_cpumask)) { +iscsit_thread_get_cpumask (conn); + conn->conn_tx_reset_cpumask =1 ; + conn->conn_rx_reset_cpumask =1 ; +cpumask_copy (conn->allowed_cpumask, + &__iscsi_allowed_cpumask);Fix up formatting like above.
I will reformat.
Quoted 11 lines
Quoted 11 lines
drivers/target/iscsi/iscsi_target.h +3
-0+ } +} +#endif /*** ISCSI_TARGET_H ***/ drivers/target/iscsi/iscsi_target_configfs.c +0
-0@@ -1127,8 +1127,42 @@ static ssize_t lio_target_wwn_lio_version_show(struct config_item *item,
Quoted 5 lines
drivers/target/iscsi/iscsi_target_configfs.c static ssize_t lio_target_wwn_lio_version_show(struct config_item *item, · line 1130
Quoted 3 lines
drivers/target/iscsi/iscsi_target_configfs.c +1
-0CONFIGFS_ATTR_RO (lio_target_wwn_, lio_version); +cpumask_t __iscsi_allowed_cpumask;Maybe better to put this in
iscsi_target.cwith the other vars like it.
Originally I wanted to put it in struct iscsit_global and use it in iscsit_thread_check_cpumask.
However iscsit_thread_check_cpumask is also called in cxgbit_target.c. I don't know if I also
need to modify cxgbit at the same time, and I only modified two calls in iscsi_target.c. I would
like to know how to handle in cxgbit_target.c?
I want to move 'static inline void iscsit_thread_check_cpumask' from iscsi_target_core.h to
iscsi_target.c and EXPORT_SYMBOL(iscsit_thread_check_cpumask). Do you agree it?
Quoted 8 lines
drivers/target/iscsi/iscsi_target_configfs.c static ssize_t lio_target_wwn_lio_version_show(struct config_item *item, · line 1136
Quoted 7 lines
drivers/target/iscsi/iscsi_target_configfs.c +6
-0+ +static ssize_t lio_target_wwn_cpus_allowed_list_show ( +struct config_item *item,char *page) +{ +return sprintf (page,"%*pbl\n" , +cpumask_pr_args (&__iscsi_allowed_cpumask));Formatting like above.
I will reformat.
Quoted 10 lines
Quoted 10 lines
drivers/target/iscsi/iscsi_target_configfs.c +9
-0+} + +static ssize_t lio_target_wwn_cpus_allowed_list_store ( +struct config_item *item,const char *page,size_t count) +{ +int ret; +char *orig; +cpumask_t new_allowed_cpumask; +
Quoted 8 lines
drivers/target/iscsi/iscsi_target_configfs.c static ssize_t lio_target_wwn_lio_version_show(struct config_item *item, · line 1151
Quoted 6 lines
drivers/target/iscsi/iscsi_target_configfs.c +6
-0+ orig =kstrdup (page,GFP_KERNEL ); +if (!orig) +return -ENOMEM ; + +cpumask_clear (&new_allowed_cpumask); + ret =cpulist_parse (orig, &new_allowed_cpumask);Are you supposed to do a before
usingnew_allowed_cpumask? It looks like other callers are doing it.
Other callers used cpumask_var_t, but the new_allowed_cpumask is cpumask_t.
I think just call cpumask_clear(&new_allowed_cpumask).
typedef struct cpumask { DECLARE_BITMAP(bits, NR_CPUS); } cpumask_t;
typedef struct cpumask cpumask_var_t[1];
Quoted 32 lines
Quoted 23 lines
drivers/target/iscsi/iscsi_target_configfs.c +12
-0+ +kfree (orig); +if (ret !=0 ) +return ret; + +cpumask_copy (&__iscsi_allowed_cpumask, &new_allowed_cpumask); +return count; +} + +CONFIGFS_ATTR (lio_target_wwn_, cpus_allowed_list); +static struct configfs_attribute *lio_target_wwn_attrs[] = { &lio_target_wwn_attr_lio_version, + &lio_target_wwn_attr_cpus_allowed_list,NULL , };drivers/target/iscsi/iscsi_target_login.c +0
-0drivers/target/iscsi/iscsi_target_login.c static struct iscsi_conn *iscsit_alloc_conn(struct iscsi_np *np) · line 1135
Quoted 7 lines
drivers/target/iscsi/iscsi_target_login.c +4
-0@@ -1129,8 +1129,15 @@ static struct iscsi_conn *iscsit_alloc_conn(struct iscsi_np *np) goto free_conn_ops; } +if (!zalloc_cpumask_var (&conn->allowed_cpumask,GFP_KERNEL )) { +pr_err ("Unable to allocate conn->allowed_cpumask\n" ); + goto free_conn_cpumask; + }I think in
iscsit_free_connyou need a:
Quoted 3 lines
free_cpumask_var(conn->allowed_cpumask);to go with this allocation.
This is bug. I will fix up in v2.
Quoted 7 lines
drivers/target/iscsi/iscsi_target_login.c static struct iscsi_conn *iscsit_alloc_conn(struct iscsi_np *np) · line 1140
Quoted 6 lines
drivers/target/iscsi/iscsi_target_login.c +3
-0+return conn; +free_conn_cpumask: +free_cpumask_var (conn->allowed_cpumask);I think you wanted
conn->conn_cpumaskhere.
This is bug. I will fix up in v2.
Quoted 16 lines
Quoted 15 lines
drivers/target/iscsi/iscsi_target_login.c +0
-0free_conn_ops:kfree (conn->conn_ops); put_transport:include/target/iscsi/iscsi_target_core.h +1
-0@@ -580,6 +580,7 @@ struct iscsi_conn {struct ahash_request *conn_tx_hash;/* Used for scheduling TX and RX connection kthreads */ cpumask_var_t conn_cpumask; +cpumask_var_t allowed_cpumask; unsigned int conn_rx_reset_cpumask:1; unsigned int conn_tx_reset_cpumask:1;/* list_head of struct iscsi_cmd for this connection */
Quoted 10 lines · Zou Mingzhe
Quoted 3 lines
Quoted 1 line
+cpumask_t
__iscsi_allowed_cpumask;Maybe better to put this in
iscsi_target.cwith the other vars like it.Originally I wanted to put it in struct
iscsit_globaland use it iniscsit_thread_check_cpumask.However
iscsit_thread_check_cpumaskis also called incxgbit_target.c. I don't know if I alsoneed to modify cxgbit at the same time, and I only modified two calls in
iscsi_target.c. I would
The new configfs file shows up for software iscsi and cxgb right? If so I think you need to modify both, or you end up with a file that returns success but doesn't do anything and it's confusing to users. It's also a simple change to cxgb.
Quoted 6 lines
like to know how to handle in
cxgbit_target.c?I want to move 'static inline void
iscsit_thread_check_cpumask' fromiscsi_target_core.hto
iscsi_target.candEXPORT_SYMBOL(iscsit_thread_check_cpumask). Do you agree it?
I think that is ok.
PATCH v2 1/1 target: add iscsi/cpus_allowed_list in configfs
In reply to [email protected]From: Mingzhe Zou <[email protected]>
The RX/TX threads for iSCSI connection can be scheduled to any online cpus, and will not be rescheduled.
If bind other heavy load threads with iSCSI connection RX/TX thread to the same cpu, the iSCSI performance will be worse.
This patch add iscsi/cpus_allowed_list in configfs. The available cpus set of iSCSI connection RX/TX threads is allowed_cpus & online_cpus. If it is modified, all RX/TX threads will be rescheduled.
--- drivers/target/iscsi/iscsi_target.c | 66 +++++++++++++++++++- drivers/target/iscsi/iscsi_target_configfs.c | 32 ++++++++++ drivers/target/iscsi/iscsi_target_login.c | 8 +++ include/target/iscsi/iscsi_target_core.h | 31 ++------- 4 files changed, 109 insertions(+), 28 deletions(-)
drivers/target/iscsi/iscsi_target.c +63 -3
@@ -702,13 +702,19 @@ static int __init iscsi_target_init_module(void)if (!iscsit_global->ts_bitmap) goto configfs_out; +if (!zalloc_cpumask_var (&iscsit_global->allowed_cpumask,GFP_KERNEL )) { +pr_err ("Unable to allocate iscsit_global->allowed_cpumask\n" ); + goto bitmap_out; + } +cpumask_setall (iscsit_global->allowed_cpumask); + lio_qr_cache =kmem_cache_create ("lio_qr_cache" ,sizeof (struct iscsi_queue_req ), __alignof__(struct iscsi_queue_req ),0 ,NULL );if (!lio_qr_cache) {pr_err ("Unable to kmem_cache_create() for" " lio_qr_cache\n" ); - goto bitmap_out; + goto cpumask_out; } lio_dr_cache = kmem_cache_create("lio_dr_cache",
@@ -753,6 +759,8 @@ static int __init iscsi_target_init_module(void)kmem_cache_destroy (lio_dr_cache); qr_out:kmem_cache_destroy (lio_qr_cache); +cpumask_out: +free_cpumask_var (iscsit_global->allowed_cpumask); bitmap_out:vfree (iscsit_global->ts_bitmap); configfs_out:
@@ -782,6 +790,7 @@ static void __exit iscsi_target_cleanup_module(void)target_unregister_template (&iscsi_ops); +free_cpumask_var (iscsit_global->allowed_cpumask);vfree (iscsit_global->ts_bitmap);kfree (iscsit_global); }
@@ -3587,6 +3596,11 @@ static int iscsit_send_reject(void iscsit_thread_get_cpumask (struct iscsi_conn *conn) {int ord, cpu; +cpumask_t conn_allowed_cpumask; + +cpumask_and (&conn_allowed_cpumask, iscsit_global->allowed_cpumask, + cpu_online_mask); +/* * bitmap_id is assigned from iscsit_global->ts_bitmap from * within iscsit_start_kthreads()
@@ -3595,8 +3609,9 @@ void iscsit_thread_get_cpumask(struct iscsi_conn *conn)* iSCSI connection's RX/TX threads will be scheduled to * execute upon. */ - ord = conn->bitmap_id %cpumask_weight (cpu_online_mask); -for_each_online_cpu (cpu) { +cpumask_clear (conn->conn_cpumask); + ord = conn->bitmap_id %cpumask_weight (&conn_allowed_cpumask); +for_each_cpu (cpu, &conn_allowed_cpumask) {if (ord-- ==0 ) {cpumask_set_cpu (cpu, conn->conn_cpumask);return ;
@@ -3609,6 +3624,51 @@ void iscsit_thread_get_cpumask(struct iscsi_conn *conn)cpumask_setall (conn->conn_cpumask); } +static void iscsit_thread_reschedule (struct iscsi_conn *conn) +{ +/* +* If iscsit_global->allowed_cpumask modified, reschedule iSCSI +* connection's RX/TX threads update conn->allowed_cpumask. +*/ +if (!cpumask_equal (iscsit_global->allowed_cpumask, + conn->allowed_cpumask)) { +iscsit_thread_get_cpumask (conn); + conn->conn_tx_reset_cpumask =1 ; + conn->conn_rx_reset_cpumask =1 ; +cpumask_copy (conn->allowed_cpumask, + iscsit_global->allowed_cpumask); + } +} + +void iscsit_thread_check_cpumask ( +struct iscsi_conn *conn, +struct task_struct *p, +int mode) +{ +iscsit_thread_reschedule (conn); + +/* +* mode == 1 signals iscsi_target_tx_thread() usage. +* mode == 0 signals iscsi_target_rx_thread() usage. +*/ +if (mode ==1 ) { +if (!conn->conn_tx_reset_cpumask) +return ; + conn->conn_tx_reset_cpumask =0 ; + }else { +if (!conn->conn_rx_reset_cpumask) +return ; + conn->conn_rx_reset_cpumask =0 ; + } +/* +* Update the CPU mask for this single kthread so that +* both TX and RX kthreads are scheduled to run on the +* same CPU. +*/ +set_cpus_allowed_ptr (p, conn->conn_cpumask); +} +EXPORT_SYMBOL (iscsit_thread_check_cpumask); +int iscsit_immediate_queue (struct iscsi_conn *conn,struct iscsi_cmd *cmd,int state) {
drivers/target/iscsi/iscsi_target_configfs.c +32 -0
@@ -1127,8 +1127,40 @@ static ssize_t lio_target_wwn_lio_version_show(struct config_item *item,CONFIGFS_ATTR_RO (lio_target_wwn_, lio_version); +static ssize_t lio_target_wwn_cpus_allowed_list_show ( +struct config_item *item,char *page) +{ +return sprintf (page,"%*pbl\n" , +cpumask_pr_args (iscsit_global->allowed_cpumask)); +} + +static ssize_t lio_target_wwn_cpus_allowed_list_store ( +struct config_item *item,const char *page,size_t count) +{ +int ret; +char *orig; +cpumask_t new_allowed_cpumask; + + orig =kstrdup (page,GFP_KERNEL ); +if (!orig) +return -ENOMEM ; + +cpumask_clear (&new_allowed_cpumask); + ret =cpulist_parse (orig, &new_allowed_cpumask); + +kfree (orig); +if (ret !=0 ) +return ret; + +cpumask_copy (iscsit_global->allowed_cpumask, &new_allowed_cpumask); +return count; +} + +CONFIGFS_ATTR (lio_target_wwn_, cpus_allowed_list); +static struct configfs_attribute *lio_target_wwn_attrs[] = { &lio_target_wwn_attr_lio_version, + &lio_target_wwn_attr_cpus_allowed_list,NULL , };
drivers/target/iscsi/iscsi_target_login.c +8 -0
@@ -1129,8 +1129,15 @@ static struct iscsi_conn *iscsit_alloc_conn(struct iscsi_np *np) goto free_conn_ops; } +if (!zalloc_cpumask_var (&conn->allowed_cpumask,GFP_KERNEL )) { +pr_err ("Unable to allocate conn->allowed_cpumask\n" ); + goto free_conn_cpumask; + } +return conn; +free_conn_cpumask: +free_cpumask_var (conn->conn_cpumask); free_conn_ops:kfree (conn->conn_ops); put_transport:
@@ -1142,6 +1149,7 @@ static struct iscsi_conn *iscsit_alloc_conn(struct iscsi_np *np)void iscsit_free_conn (struct iscsi_conn *conn) { +free_cpumask_var (conn->allowed_cpumask);free_cpumask_var (conn->conn_cpumask);kfree (conn->conn_ops);iscsit_put_transport (conn->conn_transport);
include/target/iscsi/iscsi_target_core.h +6 -25
@@ -580,6 +580,7 @@ struct iscsi_conn {struct ahash_request *conn_tx_hash;/* Used for scheduling TX and RX connection kthreads */ cpumask_var_t conn_cpumask; +cpumask_var_t allowed_cpumask; unsigned int conn_rx_reset_cpumask:1; unsigned int conn_tx_reset_cpumask:1;/* list_head of struct iscsi_cmd for this connection */
@@ -878,6 +879,7 @@ struct iscsit_global {/* Thread Set bitmap pointer */ unsigned long *ts_bitmap;spinlock_t ts_bitmap_lock; +cpumask_var_t allowed_cpumask;/* Used for iSCSI discovery session authentication */ struct iscsi_node_acl discovery_acl;struct iscsi_portal_group *discovery_tpg;
@@ -898,29 +900,8 @@ static inline u32 session_get_next_ttt(struct iscsi_session *session)extern struct iscsi_cmd *iscsit_find_cmd_from_itt (struct iscsi_conn *,itt_t ); -static inline void iscsit_thread_check_cpumask ( -struct iscsi_conn *conn, -struct task_struct *p, -int mode) -{ -/* -* mode == 1 signals iscsi_target_tx_thread() usage. -* mode == 0 signals iscsi_target_rx_thread() usage. -*/ -if (mode ==1 ) { -if (!conn->conn_tx_reset_cpumask) -return ; - conn->conn_tx_reset_cpumask =0 ; - }else { -if (!conn->conn_rx_reset_cpumask) -return ; - conn->conn_rx_reset_cpumask =0 ; - } -/* -* Update the CPU mask for this single kthread so that -* both TX and RX kthreads are scheduled to run on the -* same CPU. -*/ -set_cpus_allowed_ptr (p, conn->conn_cpumask); -} +extern void iscsit_thread_check_cpumask (struct iscsi_conn *conn, +struct task_struct *p, +int mode); +#endif /* ISCSI_TARGET_CORE_H */
Signature · 1 line
2.17.1
Hi, christie
Can you help me review v2
Thanks
Quoted 267 lines · 在 2022/2/17 15:45, [email protected] 写道:
From: Mingzhe Zou <[email protected]>
The RX/TX threads for iSCSI connection can be scheduled to any online cpus, and will not be rescheduled.
If bind other heavy load threads with iSCSI connection RX/TX thread to the same cpu, the iSCSI performance will be worse.
This patch add iscsi/cpus_allowed_list in configfs. The available cpus set of iSCSI connection RX/TX threads is
allowed_cpus&online_cpus. If it is modified, all RX/TX threads will be rescheduled.Signed-off-by Mingzhe Zou <[email protected]>--- drivers/target/iscsi/iscsi_target.c | 66 +++++++++++++++++++- drivers/target/iscsi/iscsi_target_configfs.c | 32 ++++++++++ drivers/target/iscsi/iscsi_target_login.c | 8 +++ include/target/iscsi/iscsi_target_core.h | 31 ++------- 4 files changed, 109 insertions(+), 28 deletions(-)drivers/target/iscsi/iscsi_target.c +63
-3@@ -702,13 +702,19 @@ static int __init iscsi_target_init_module(void)if (!iscsit_global->ts_bitmap) goto configfs_out; +if (!zalloc_cpumask_var (&iscsit_global->allowed_cpumask,GFP_KERNEL )) { +pr_err ("Unable to allocate iscsit_global->allowed_cpumask\n" ); + goto bitmap_out; + } +cpumask_setall (iscsit_global->allowed_cpumask); + lio_qr_cache =kmem_cache_create ("lio_qr_cache" ,sizeof (struct iscsi_queue_req ), __alignof__(struct iscsi_queue_req ),0 ,NULL );if (!lio_qr_cache) {pr_err ("Unable to kmem_cache_create() for" " lio_qr_cache\n" ); - goto bitmap_out; + goto cpumask_out; } lio_dr_cache = kmem_cache_create("lio_dr_cache",@@ -753,6 +759,8 @@ static int __init iscsi_target_init_module(void)kmem_cache_destroy (lio_dr_cache); qr_out:kmem_cache_destroy (lio_qr_cache); +cpumask_out: +free_cpumask_var (iscsit_global->allowed_cpumask); bitmap_out:vfree (iscsit_global->ts_bitmap); configfs_out:@@ -782,6 +790,7 @@ static void __exit iscsi_target_cleanup_module(void)target_unregister_template (&iscsi_ops); +free_cpumask_var (iscsit_global->allowed_cpumask);vfree (iscsit_global->ts_bitmap);kfree (iscsit_global); }@@ -3587,6 +3596,11 @@ static int iscsit_send_reject(void iscsit_thread_get_cpumask (struct iscsi_conn *conn) {int ord, cpu; +cpumask_t conn_allowed_cpumask; + +cpumask_and (&conn_allowed_cpumask, iscsit_global->allowed_cpumask, + cpu_online_mask); +/* * bitmap_id is assigned from iscsit_global->ts_bitmap from * within iscsit_start_kthreads() @@ -3595,8 +3609,9 @@ void iscsit_thread_get_cpumask(struct iscsi_conn *conn)* iSCSI connection's RX/TX threads will be scheduled to * execute upon. */ - ord = conn->bitmap_id %cpumask_weight (cpu_online_mask); -for_each_online_cpu (cpu) { +cpumask_clear (conn->conn_cpumask); + ord = conn->bitmap_id %cpumask_weight (&conn_allowed_cpumask); +for_each_cpu (cpu, &conn_allowed_cpumask) {if (ord-- ==0 ) {cpumask_set_cpu (cpu, conn->conn_cpumask);return ;@@ -3609,6 +3624,51 @@ void iscsit_thread_get_cpumask(struct iscsi_conn *conn)cpumask_setall (conn->conn_cpumask); } +static void iscsit_thread_reschedule (struct iscsi_conn *conn) +{ +/* +* If iscsit_global->allowed_cpumask modified, reschedule iSCSI +* connection's RX/TX threads update conn->allowed_cpumask. +*/ +if (!cpumask_equal (iscsit_global->allowed_cpumask, + conn->allowed_cpumask)) { +iscsit_thread_get_cpumask (conn); + conn->conn_tx_reset_cpumask =1 ; + conn->conn_rx_reset_cpumask =1 ; +cpumask_copy (conn->allowed_cpumask, + iscsit_global->allowed_cpumask); + } +} + +void iscsit_thread_check_cpumask ( +struct iscsi_conn *conn, +struct task_struct *p, +int mode) +{ +iscsit_thread_reschedule (conn); + +/* +* mode == 1 signals iscsi_target_tx_thread() usage. +* mode == 0 signals iscsi_target_rx_thread() usage. +*/ +if (mode ==1 ) { +if (!conn->conn_tx_reset_cpumask) +return ; + conn->conn_tx_reset_cpumask =0 ; + }else { +if (!conn->conn_rx_reset_cpumask) +return ; + conn->conn_rx_reset_cpumask =0 ; + } +/* +* Update the CPU mask for this single kthread so that +* both TX and RX kthreads are scheduled to run on the +* same CPU. +*/ +set_cpus_allowed_ptr (p, conn->conn_cpumask); +} +EXPORT_SYMBOL (iscsit_thread_check_cpumask); +int iscsit_immediate_queue (struct iscsi_conn *conn,struct iscsi_cmd *cmd,int state) {drivers/target/iscsi/iscsi_target_configfs.c +32
-0@@ -1127,8 +1127,40 @@ static ssize_t lio_target_wwn_lio_version_show(struct config_item *item,CONFIGFS_ATTR_RO (lio_target_wwn_, lio_version); +static ssize_t lio_target_wwn_cpus_allowed_list_show ( +struct config_item *item,char *page) +{ +return sprintf (page,"%*pbl\n" , +cpumask_pr_args (iscsit_global->allowed_cpumask)); +} + +static ssize_t lio_target_wwn_cpus_allowed_list_store ( +struct config_item *item,const char *page,size_t count) +{ +int ret; +char *orig; +cpumask_t new_allowed_cpumask; + + orig =kstrdup (page,GFP_KERNEL ); +if (!orig) +return -ENOMEM ; + +cpumask_clear (&new_allowed_cpumask); + ret =cpulist_parse (orig, &new_allowed_cpumask); + +kfree (orig); +if (ret !=0 ) +return ret; + +cpumask_copy (iscsit_global->allowed_cpumask, &new_allowed_cpumask); +return count; +} + +CONFIGFS_ATTR (lio_target_wwn_, cpus_allowed_list); +static struct configfs_attribute *lio_target_wwn_attrs[] = { &lio_target_wwn_attr_lio_version, + &lio_target_wwn_attr_cpus_allowed_list,NULL , };drivers/target/iscsi/iscsi_target_login.c +8
-0@@ -1129,8 +1129,15 @@ static struct iscsi_conn *iscsit_alloc_conn(struct iscsi_np *np) goto free_conn_ops; } +if (!zalloc_cpumask_var (&conn->allowed_cpumask,GFP_KERNEL )) { +pr_err ("Unable to allocate conn->allowed_cpumask\n" ); + goto free_conn_cpumask; + } +return conn; +free_conn_cpumask: +free_cpumask_var (conn->conn_cpumask); free_conn_ops:kfree (conn->conn_ops); put_transport:@@ -1142,6 +1149,7 @@ static struct iscsi_conn *iscsit_alloc_conn(struct iscsi_np *np)void iscsit_free_conn (struct iscsi_conn *conn) { +free_cpumask_var (conn->allowed_cpumask);free_cpumask_var (conn->conn_cpumask);kfree (conn->conn_ops);iscsit_put_transport (conn->conn_transport);include/target/iscsi/iscsi_target_core.h +6
-25@@ -580,6 +580,7 @@ struct iscsi_conn {struct ahash_request *conn_tx_hash;/* Used for scheduling TX and RX connection kthreads */ cpumask_var_t conn_cpumask; +cpumask_var_t allowed_cpumask; unsigned int conn_rx_reset_cpumask:1; unsigned int conn_tx_reset_cpumask:1;/* list_head of struct iscsi_cmd for this connection */ @@ -878,6 +879,7 @@ struct iscsit_global {/* Thread Set bitmap pointer */ unsigned long *ts_bitmap;spinlock_t ts_bitmap_lock; +cpumask_var_t allowed_cpumask;/* Used for iSCSI discovery session authentication */ struct iscsi_node_acl discovery_acl;struct iscsi_portal_group *discovery_tpg;@@ -898,29 +900,8 @@ static inline u32 session_get_next_ttt(struct iscsi_session *session)extern struct iscsi_cmd *iscsit_find_cmd_from_itt (struct iscsi_conn *,itt_t ); -static inline void iscsit_thread_check_cpumask ( -struct iscsi_conn *conn, -struct task_struct *p, -int mode) -{ -/* -* mode == 1 signals iscsi_target_tx_thread() usage. -* mode == 0 signals iscsi_target_rx_thread() usage. -*/ -if (mode ==1 ) { -if (!conn->conn_tx_reset_cpumask) -return ; - conn->conn_tx_reset_cpumask =0 ; - }else { -if (!conn->conn_rx_reset_cpumask) -return ; - conn->conn_rx_reset_cpumask =0 ; - } -/* -* Update the CPU mask for this single kthread so that -* both TX and RX kthreads are scheduled to run on the -* same CPU. -*/ -set_cpus_allowed_ptr (p, conn->conn_cpumask); -} +extern void iscsit_thread_check_cpumask (struct iscsi_conn *conn, +struct task_struct *p, +int mode); +#endif /* ISCSI_TARGET_CORE_H */
Quoted 4 lines · Zou Mingzhe
Hi, christie
Can you help me review v2
I'm working on it.
It looks like is a window where we can have the recv and xmit thread on different CPUs. I thought there might be some iscsi target code that relied on them being on the same CPU so I'm just trying to review the iscsi target code paths related to that to make sure.
Quoted 257 lines
Thanks
Quoted 254 lines · 在 2022/2/17 15:45, [email protected] 写道:
From: Mingzhe Zou <[email protected]>
The RX/TX threads for iSCSI connection can be scheduled to any online cpus, and will not be rescheduled.
If bind other heavy load threads with iSCSI connection RX/TX thread to the same cpu, the iSCSI performance will be worse.
This patch add iscsi/cpus_allowed_list in configfs. The available cpus set of iSCSI connection RX/TX threads is
allowed_cpus&online_cpus. If it is modified, all RX/TX threads will be rescheduled.Signed-off-by Mingzhe Zou <[email protected]>---
drivers/target/iscsi/iscsi_target.c | 66 +++++++++++++++++++-drivers/target/iscsi/iscsi_target_configfs.c| 32 ++++++++++ drivers/target/iscsi/iscsi_target_login.c | 8 +++ include/target/iscsi/iscsi_target_core.h | 31 ++-------4 files changed, 109 insertions(+), 28 deletions(-)drivers/target/iscsi/iscsi_target.c +5
-0@@ -702,13 +702,19 @@ static int __init iscsi_target_init_module(void) if (!iscsit_global->ts_bitmap) goto configfs_out; + if (!zalloc_cpumask_var(&iscsit_global->allowed_cpumask, GFP_KERNEL)) { + pr_err("Unable to allocate iscsit_global->allowed_cpumask\n"); + goto bitmap_out; + } + cpumask_setall(iscsit_global->allowed_cpumask); + lio_qr_cache = kmem_cache_create("lio_qr_cache", sizeof(struct iscsi_queue_req), __alignof__(struct iscsi_queue_req), 0, NULL); if (!lio_qr_cache) {
pr_err("Unable to kmem_cache_create() for" " lio_qr_cache\n");
- gotobitmap_out;
+ gotocpumask_out;
}
lio_dr_cache= kmem_cache_create("lio_dr_cache",drivers/target/iscsi/iscsi_target.c +0
-0@@ -753,6 +759,8 @@ static int __init iscsi_target_init_module(void) kmem_cache_destroy(lio_dr_cache);
qr_out:
kmem_cache_destroy(lio_qr_cache); +cpumask_out:
+free_cpumask_var(iscsit_global->allowed_cpumask);bitmap_out:
vfree(iscsit_global->ts_bitmap);configfs_out:drivers/target/iscsi/iscsi_target.c +52
-2@@ -782,6 +790,7 @@ static void __exit iscsi_target_cleanup_module(void) target_unregister_template(&iscsi_ops); + free_cpumask_var(iscsit_global->allowed_cpumask); vfree(iscsit_global->ts_bitmap); kfree(iscsit_global); }@@ -3587,6 +3596,11 @@ static int iscsit_send_reject( void iscsit_thread_get_cpumask(struct iscsi_conn *conn) { int ord, cpu; + cpumask_t conn_allowed_cpumask; + + cpumask_and(&conn_allowed_cpumask, iscsit_global->allowed_cpumask, + cpu_online_mask); + /** bitmap_id is assigned from iscsit_global->ts_bitmap from * within iscsit_start_kthreads() @@ -3595,8 +3609,9 @@ void iscsit_thread_get_cpumask(struct iscsi_conn *conn)* iSCSI connection's RX/TX threads will be scheduled to * execute upon. */ - ord = conn->bitmap_id % cpumask_weight(cpu_online_mask); - for_each_online_cpu(cpu) { + cpumask_clear(conn->conn_cpumask); + ord = conn->bitmap_id % cpumask_weight(&conn_allowed_cpumask); + for_each_cpu(cpu, &conn_allowed_cpumask) { if (ord-- == 0) { cpumask_set_cpu(cpu, conn->conn_cpumask); return;@@ -3609,6 +3624,51 @@ void iscsit_thread_get_cpumask(struct iscsi_conn *conn) cpumask_setall(conn->conn_cpumask); } +static void iscsit_thread_reschedule(struct iscsi_conn *conn) +{ + /* + * If iscsit_global->allowed_cpumask modified, reschedule iSCSI + * connection's RX/TX threads update conn->allowed_cpumask. + */ + if (!cpumask_equal(iscsit_global->allowed_cpumask, + conn->allowed_cpumask)) { + iscsit_thread_get_cpumask(conn); + conn->conn_tx_reset_cpumask = 1; + conn->conn_rx_reset_cpumask = 1; + cpumask_copy(conn->allowed_cpumask, + iscsit_global->allowed_cpumask); + } +} + +void iscsit_thread_check_cpumask ( + struct iscsi_conn *conn, + struct task_struct *p, + int mode) +{ + iscsit_thread_reschedule(conn); + + /* + * mode == 1 signals iscsi_target_tx_thread() usage. + * mode == 0 signals iscsi_target_rx_thread() usage. + */ + if (mode == 1) { + if (!conn->conn_tx_reset_cpumask) + return; + conn->conn_tx_reset_cpumask = 0; + } else { + if (!conn->conn_rx_reset_cpumask) + return; + conn->conn_rx_reset_cpumask = 0; + } + /* + * Update the CPU mask for this single kthread so that + * both TX and RX kthreads are scheduled to run on the + * same CPU. + */ + set_cpus_allowed_ptr(p, conn->conn_cpumask); +} +EXPORT_SYMBOL (iscsit_thread_check_cpumask); +int
iscsit_immediate_queue(struct iscsi_conn *conn, struct iscsi_cmd *cmd, int state){drivers/target/iscsi/iscsi_target_configfs.c +0
-0@@ -1127,8 +1127,40 @@ static ssize_t lio_target_wwn_lio_version_show(struct config_item *item, CONFIGFS_ATTR_RO(lio_target_wwn_, lio_version);+static
ssize_tlio_target_wwn_cpus_allowed_list_show( + struct config_item *item, char *page)drivers/target/iscsi/iscsi_target_configfs.c +29
-0+{ + return sprintf(page, "%*pbl\n", + cpumask_pr_args(iscsit_global->allowed_cpumask)); +} + +static ssize_t lio_target_wwn_cpus_allowed_list_store ( + struct config_item *item, const char *page, size_t count) +{ + int ret; + char *orig; + cpumask_t new_allowed_cpumask; + + orig = kstrdup(page, GFP_KERNEL); + if (!orig) + return -ENOMEM; + + cpumask_clear(&new_allowed_cpumask); + ret = cpulist_parse(orig, &new_allowed_cpumask); + + kfree(orig); + if (ret != 0) + return ret; + + cpumask_copy(iscsit_global->allowed_cpumask, &new_allowed_cpumask); + return count; +} + +CONFIGFS_ATTR (lio_target_wwn_, cpus_allowed_list); +static struct
configfs_attribute*lio_target_wwn_attrs[] = {&lio_target_wwn_attr_lio_version,
+&lio_target_wwn_attr_cpus_allowed_list,
NULL,
};
diff --gita/drivers/target/iscsi/iscsi_target_login.cb/drivers/target/iscsi/iscsi_target_login.cindex1a9c50401bdb..9c01fb864585100644drivers/target/iscsi/iscsi_target_login.c +4
-0@@ -1129,8 +1129,15 @@ static struct iscsi_conn *iscsit_alloc_conn(struct iscsi_np *np) goto free_conn_ops; } + if (!zalloc_cpumask_var(&conn->allowed_cpumask, GFP_KERNEL)) { + pr_err("Unable to allocate conn->allowed_cpumask\n"); + goto free_conn_cpumask; + } + return conn;+free_conn_cpumask:
+free_cpumask_var(conn->conn_cpumask);
free_conn_ops:
kfree(conn->conn_ops);
put_transport:drivers/target/iscsi/iscsi_target_login.c +1
-0@@ -1142,6 +1149,7 @@ static struct iscsi_conn *iscsit_alloc_conn(struct iscsi_np *np) void iscsit_free_conn(struct iscsi_conn *conn) { + free_cpumask_var(conn->allowed_cpumask); free_cpumask_var(conn->conn_cpumask); kfree(conn->conn_ops); iscsit_put_transport(conn->conn_transport);include/target/iscsi/iscsi_target_core.h +2
-0@@ -580,6 +580,7 @@ struct iscsi_conn { struct ahash_request *conn_tx_hash; /* Used for scheduling TX and RX connection kthreads */ cpumask_var_t conn_cpumask; + cpumask_var_t allowed_cpumask; unsigned int conn_rx_reset_cpumask:1; unsigned int conn_tx_reset_cpumask:1; /* list_head of struct iscsi_cmd for this connection */@@ -878,6 +879,7 @@ struct iscsit_global { /* Thread Set bitmap pointer */ unsigned long *ts_bitmap; spinlock_t ts_bitmap_lock; + cpumask_var_t allowed_cpumask; /* Used for iSCSI discovery session authentication */ struct iscsi_node_acl discovery_acl; struct iscsi_portal_group *discovery_tpg;@@ -898,29 +900,8 @@ static inline u32 session_get_next_ttt(struct iscsi_session *session) extern struct iscsi_cmd *iscsit_find_cmd_from_itt(struct iscsi_conn *, itt_t);-static inline void iscsit_thread_check_cpumask( - struct
iscsi_conn*conn,
- structtask_struct*p,
- int mode)include/target/iscsi/iscsi_target_core.h +4
-21-{ - /* - * mode == 1 signals iscsi_target_tx_thread() usage. - * mode == 0 signals iscsi_target_rx_thread() usage. - */ - if (mode == 1) { - if (!conn->conn_tx_reset_cpumask) - return; - conn->conn_tx_reset_cpumask = 0; - } else { - if (!conn->conn_rx_reset_cpumask) - return; - conn->conn_rx_reset_cpumask = 0; - } - /* - * Update the CPU mask for this single kthread so that - * both TX and RX kthreads are scheduled to run on the - * same CPU. - */ - set_cpus_allowed_ptr(p, conn->conn_cpumask); -} +extern void iscsit_thread_check_cpumask (struct iscsi_conn *conn, + struct task_struct *p, + int mode); +#endif /*
ISCSI_TARGET_CORE_H*/
Quoted 125 lines · On 2/17/22 1:45 AM, [email protected] wrote:
From: Mingzhe Zou <[email protected]>
The RX/TX threads for iSCSI connection can be scheduled to any online cpus, and will not be rescheduled.
If bind other heavy load threads with iSCSI connection RX/TX thread to the same cpu, the iSCSI performance will be worse.
This patch add iscsi/cpus_allowed_list in configfs. The available cpus set of iSCSI connection RX/TX threads is
allowed_cpus&online_cpus. If it is modified, all RX/TX threads will be rescheduled.Signed-off-by Mingzhe Zou <[email protected]>--- drivers/target/iscsi/iscsi_target.c | 66 +++++++++++++++++++- drivers/target/iscsi/iscsi_target_configfs.c | 32 ++++++++++ drivers/target/iscsi/iscsi_target_login.c | 8 +++ include/target/iscsi/iscsi_target_core.h | 31 ++------- 4 files changed, 109 insertions(+), 28 deletions(-)drivers/target/iscsi/iscsi_target.c +51
-3@@ -702,13 +702,19 @@ static int __init iscsi_target_init_module(void)if (!iscsit_global->ts_bitmap) goto configfs_out; +if (!zalloc_cpumask_var (&iscsit_global->allowed_cpumask,GFP_KERNEL )) { +pr_err ("Unable to allocate iscsit_global->allowed_cpumask\n" ); + goto bitmap_out; + } +cpumask_setall (iscsit_global->allowed_cpumask); + lio_qr_cache =kmem_cache_create ("lio_qr_cache" ,sizeof (struct iscsi_queue_req ), __alignof__(struct iscsi_queue_req ),0 ,NULL );if (!lio_qr_cache) {pr_err ("Unable to kmem_cache_create() for" " lio_qr_cache\n" ); - goto bitmap_out; + goto cpumask_out; } lio_dr_cache = kmem_cache_create("lio_dr_cache",@@ -753,6 +759,8 @@ static int __init iscsi_target_init_module(void)kmem_cache_destroy (lio_dr_cache); qr_out:kmem_cache_destroy (lio_qr_cache); +cpumask_out: +free_cpumask_var (iscsit_global->allowed_cpumask); bitmap_out:vfree (iscsit_global->ts_bitmap); configfs_out:@@ -782,6 +790,7 @@ static void __exit iscsi_target_cleanup_module(void)target_unregister_template (&iscsi_ops); +free_cpumask_var (iscsit_global->allowed_cpumask);vfree (iscsit_global->ts_bitmap);kfree (iscsit_global); }@@ -3587,6 +3596,11 @@ static int iscsit_send_reject(void iscsit_thread_get_cpumask (struct iscsi_conn *conn) {int ord, cpu; +cpumask_t conn_allowed_cpumask; + +cpumask_and (&conn_allowed_cpumask, iscsit_global->allowed_cpumask, + cpu_online_mask); +/* * bitmap_id is assigned from iscsit_global->ts_bitmap from * within iscsit_start_kthreads() @@ -3595,8 +3609,9 @@ void iscsit_thread_get_cpumask(struct iscsi_conn *conn)* iSCSI connection's RX/TX threads will be scheduled to * execute upon. */ - ord = conn->bitmap_id %cpumask_weight (cpu_online_mask); -for_each_online_cpu (cpu) { +cpumask_clear (conn->conn_cpumask); + ord = conn->bitmap_id %cpumask_weight (&conn_allowed_cpumask); +for_each_cpu (cpu, &conn_allowed_cpumask) {if (ord-- ==0 ) {cpumask_set_cpu (cpu, conn->conn_cpumask);return ;@@ -3609,6 +3624,51 @@ void iscsit_thread_get_cpumask(struct iscsi_conn *conn)cpumask_setall (conn->conn_cpumask); } +static void iscsit_thread_reschedule (struct iscsi_conn *conn) +{ +/* +* If iscsit_global->allowed_cpumask modified, reschedule iSCSI +* connection's RX/TX threads update conn->allowed_cpumask. +*/ +if (!cpumask_equal (iscsit_global->allowed_cpumask, + conn->allowed_cpumask)) { +iscsit_thread_get_cpumask (conn); + conn->conn_tx_reset_cpumask =1 ; + conn->conn_rx_reset_cpumask =1 ; +cpumask_copy (conn->allowed_cpumask, + iscsit_global->allowed_cpumask); + } +} + +void iscsit_thread_check_cpumask ( +struct iscsi_conn *conn, +struct task_struct *p, +int mode) +{ +iscsit_thread_reschedule (conn); + +/* +* mode == 1 signals iscsi_target_tx_thread() usage. +* mode == 0 signals iscsi_target_rx_thread() usage. +*/ +if (mode ==1 ) { +if (!conn->conn_tx_reset_cpumask) +return ; + conn->conn_tx_reset_cpumask =0 ; + }else { +if (!conn->conn_rx_reset_cpumask)
drivers/target/iscsi/iscsi_target.c void iscsit_thread_get_cpumask(struct iscsi_conn *conn) · line 3669
Quoted 10 lines
drivers/target/iscsi/iscsi_target.c +10
-0+return ; + conn->conn_rx_reset_cpumask =0 ; + } +/* +* Update the CPU mask for this single kthread so that +* both TX and RX kthreads are scheduled to run on the +* same CPU. +*/ +set_cpus_allowed_ptr (p, conn->conn_cpumask); +}
We can hit a race where we call this twice for the same CPU right?
The rx and tx thread both call iscsit_thread_reschedule and cpumask_equal and it returns false for them. The rx thread might be faster and return from iscsit_thread_reschedule and is setting conn_rx_reset_cpumask to 0. Then the tx thread is sets it back to 1. The next time the rx thread loops it sees conn_rx_reset_cpumask set to 1 and calls set_cpus_allowed_ptr.
Is that the only possible race? If so it seems ok. Maybe just add a comment, so later when someone else is looking at the code they don't waste time and think it's broken and know it was intentional or at least we didn't care.
Quoted 129 lines · Mike Christie
Quoted 128 lines · On 2/17/22 1:45 AM, [email protected] wrote:
From: Mingzhe Zou <[email protected]>
The RX/TX threads for iSCSI connection can be scheduled to any online cpus, and will not be rescheduled.
If bind other heavy load threads with iSCSI connection RX/TX thread to the same cpu, the iSCSI performance will be worse.
This patch add iscsi/cpus_allowed_list in configfs. The available cpus set of iSCSI connection RX/TX threads is
allowed_cpus&online_cpus. If it is modified, all RX/TX threads will be rescheduled.Signed-off-by Mingzhe Zou <[email protected]>--- drivers/target/iscsi/iscsi_target.c | 66 +++++++++++++++++++- drivers/target/iscsi/iscsi_target_configfs.c | 32 ++++++++++ drivers/target/iscsi/iscsi_target_login.c | 8 +++ include/target/iscsi/iscsi_target_core.h | 31 ++------- 4 files changed, 109 insertions(+), 28 deletions(-)drivers/target/iscsi/iscsi_target.c +54
-3@@ -702,13 +702,19 @@ static int __init iscsi_target_init_module(void)if (!iscsit_global->ts_bitmap) goto configfs_out; +if (!zalloc_cpumask_var (&iscsit_global->allowed_cpumask,GFP_KERNEL )) { +pr_err ("Unable to allocate iscsit_global->allowed_cpumask\n" ); + goto bitmap_out; + } +cpumask_setall (iscsit_global->allowed_cpumask); + lio_qr_cache =kmem_cache_create ("lio_qr_cache" ,sizeof (struct iscsi_queue_req ), __alignof__(struct iscsi_queue_req ),0 ,NULL );if (!lio_qr_cache) {pr_err ("Unable to kmem_cache_create() for" " lio_qr_cache\n" ); - goto bitmap_out; + goto cpumask_out; } lio_dr_cache = kmem_cache_create("lio_dr_cache",@@ -753,6 +759,8 @@ static int __init iscsi_target_init_module(void)kmem_cache_destroy (lio_dr_cache); qr_out:kmem_cache_destroy (lio_qr_cache); +cpumask_out: +free_cpumask_var (iscsit_global->allowed_cpumask); bitmap_out:vfree (iscsit_global->ts_bitmap); configfs_out:@@ -782,6 +790,7 @@ static void __exit iscsi_target_cleanup_module(void)target_unregister_template (&iscsi_ops); +free_cpumask_var (iscsit_global->allowed_cpumask);vfree (iscsit_global->ts_bitmap);kfree (iscsit_global); }@@ -3587,6 +3596,11 @@ static int iscsit_send_reject(void iscsit_thread_get_cpumask (struct iscsi_conn *conn) {int ord, cpu; +cpumask_t conn_allowed_cpumask; + +cpumask_and (&conn_allowed_cpumask, iscsit_global->allowed_cpumask, + cpu_online_mask); +/* * bitmap_id is assigned from iscsit_global->ts_bitmap from * within iscsit_start_kthreads() @@ -3595,8 +3609,9 @@ void iscsit_thread_get_cpumask(struct iscsi_conn *conn)* iSCSI connection's RX/TX threads will be scheduled to * execute upon. */ - ord = conn->bitmap_id %cpumask_weight (cpu_online_mask); -for_each_online_cpu (cpu) { +cpumask_clear (conn->conn_cpumask); + ord = conn->bitmap_id %cpumask_weight (&conn_allowed_cpumask); +for_each_cpu (cpu, &conn_allowed_cpumask) {if (ord-- ==0 ) {cpumask_set_cpu (cpu, conn->conn_cpumask);return ;@@ -3609,6 +3624,51 @@ void iscsit_thread_get_cpumask(struct iscsi_conn *conn)cpumask_setall (conn->conn_cpumask); } +static void iscsit_thread_reschedule (struct iscsi_conn *conn) +{ +/* +* If iscsit_global->allowed_cpumask modified, reschedule iSCSI +* connection's RX/TX threads update conn->allowed_cpumask. +*/ +if (!cpumask_equal (iscsit_global->allowed_cpumask, + conn->allowed_cpumask)) { +iscsit_thread_get_cpumask (conn); + conn->conn_tx_reset_cpumask =1 ; + conn->conn_rx_reset_cpumask =1 ; +cpumask_copy (conn->allowed_cpumask, + iscsit_global->allowed_cpumask); + } +} + +void iscsit_thread_check_cpumask ( +struct iscsi_conn *conn, +struct task_struct *p, +int mode) +{ +iscsit_thread_reschedule (conn); + +/* +* mode == 1 signals iscsi_target_tx_thread() usage. +* mode == 0 signals iscsi_target_rx_thread() usage. +*/ +if (mode ==1 ) { +if (!conn->conn_tx_reset_cpumask) +return ; + conn->conn_tx_reset_cpumask =0 ; + }else { +if (!conn->conn_rx_reset_cpumask) +return ; + conn->conn_rx_reset_cpumask =0 ; + }
Quoted 8 lines
drivers/target/iscsi/iscsi_target.c void iscsit_thread_get_cpumask(struct iscsi_conn *conn) · line 3669
Quoted 7 lines
drivers/target/iscsi/iscsi_target.c +7
-0+/* +* Update the CPU mask for this single kthread so that +* both TX and RX kthreads are scheduled to run on the +* same CPU. +*/ +set_cpus_allowed_ptr (p, conn->conn_cpumask); +}We can hit a race where we call this twice for the same CPU right?
Yes, it should be safe to call twice set_cpus_allowed_ptr() with the same CPU for the same task.
Quoted 6 lines
The rx and tx thread both call
iscsit_thread_rescheduleandcpumask_equaland it returns false for them. The rx thread might be faster and return fromiscsit_thread_rescheduleand is settingconn_rx_reset_cpumaskto 0. Then the tx thread is sets it back to 1. The next time the rx thread loops it seesconn_rx_reset_cpumaskset to 1 and callsset_cpus_allowed_ptr.
You are right. But we can call set_cpus_allowed_ptr() first, then set conn_rx_reset_cpumask to 1.
This will reduce such problems. I will modify it in v3.
Quoted 4 lines
Is that the only possible race? If so it seems ok. Maybe just add a comment, so later when someone else is looking at the code they don't waste time and think it's broken and know it was intentional or at least we didn't care.
OK. I will add a comment in v3.
Quoted 1 line
PATCH v3 1/1 target: add iscsi/cpus_allowed_list in configfs
In reply to [email protected]From: Mingzhe Zou <[email protected]>
The RX/TX threads for iSCSI connection can be scheduled to any online cpus, and will not be rescheduled.
If bind other heavy load threads with iSCSI connection RX/TX thread to the same cpu, the iSCSI performance will be worse.
This patch add iscsi/cpus_allowed_list in configfs. The available cpus set of iSCSI connection RX/TX threads is allowed_cpus & online_cpus. If it is modified, all RX/TX threads will be rescheduled.
--- drivers/target/iscsi/iscsi_target.c | 77 +++++++++++++++++++- drivers/target/iscsi/iscsi_target_configfs.c | 32 ++++++++ drivers/target/iscsi/iscsi_target_login.c | 8 ++ include/target/iscsi/iscsi_target_core.h | 31 ++------ 4 files changed, 120 insertions(+), 28 deletions(-)
drivers/target/iscsi/iscsi_target.c +74 -3
@@ -702,13 +702,19 @@ static int __init iscsi_target_init_module(void)if (!iscsit_global->ts_bitmap) goto configfs_out; +if (!zalloc_cpumask_var (&iscsit_global->allowed_cpumask,GFP_KERNEL )) { +pr_err ("Unable to allocate iscsit_global->allowed_cpumask\n" ); + goto bitmap_out; + } +cpumask_setall (iscsit_global->allowed_cpumask); + lio_qr_cache =kmem_cache_create ("lio_qr_cache" ,sizeof (struct iscsi_queue_req ), __alignof__(struct iscsi_queue_req ),0 ,NULL );if (!lio_qr_cache) {pr_err ("Unable to kmem_cache_create() for" " lio_qr_cache\n" ); - goto bitmap_out; + goto cpumask_out; } lio_dr_cache = kmem_cache_create("lio_dr_cache",
@@ -753,6 +759,8 @@ static int __init iscsi_target_init_module(void)kmem_cache_destroy (lio_dr_cache); qr_out:kmem_cache_destroy (lio_qr_cache); +cpumask_out: +free_cpumask_var (iscsit_global->allowed_cpumask); bitmap_out:vfree (iscsit_global->ts_bitmap); configfs_out:
@@ -782,6 +790,7 @@ static void __exit iscsi_target_cleanup_module(void)target_unregister_template (&iscsi_ops); +free_cpumask_var (iscsit_global->allowed_cpumask);vfree (iscsit_global->ts_bitmap);kfree (iscsit_global); }
@@ -3587,6 +3596,11 @@ static int iscsit_send_reject(void iscsit_thread_get_cpumask (struct iscsi_conn *conn) {int ord, cpu; +cpumask_t conn_allowed_cpumask; + +cpumask_and (&conn_allowed_cpumask, iscsit_global->allowed_cpumask, + cpu_online_mask); +/* * bitmap_id is assigned from iscsit_global->ts_bitmap from * within iscsit_start_kthreads()
@@ -3595,8 +3609,9 @@ void iscsit_thread_get_cpumask(struct iscsi_conn *conn)* iSCSI connection's RX/TX threads will be scheduled to * execute upon. */ - ord = conn->bitmap_id %cpumask_weight (cpu_online_mask); -for_each_online_cpu (cpu) { +cpumask_clear (conn->conn_cpumask); + ord = conn->bitmap_id %cpumask_weight (&conn_allowed_cpumask); +for_each_cpu (cpu, &conn_allowed_cpumask) {if (ord-- ==0 ) {cpumask_set_cpu (cpu, conn->conn_cpumask);return ;
@@ -3609,6 +3624,62 @@ void iscsit_thread_get_cpumask(struct iscsi_conn *conn)cpumask_setall (conn->conn_cpumask); } +static void iscsit_thread_reschedule (struct iscsi_conn *conn) +{ +/* +* If iscsit_global->allowed_cpumask modified, reschedule iSCSI +* connection's RX/TX threads update conn->allowed_cpumask. +*/ +if (!cpumask_equal (iscsit_global->allowed_cpumask, + conn->allowed_cpumask)) { +iscsit_thread_get_cpumask (conn); + conn->conn_tx_reset_cpumask =1 ; + conn->conn_rx_reset_cpumask =1 ; +cpumask_copy (conn->allowed_cpumask, + iscsit_global->allowed_cpumask); + } +} + +void iscsit_thread_check_cpumask ( +struct iscsi_conn *conn, +struct task_struct *p, +int mode) +{ +/* +* The TX and RX threads maybe call iscsit_thread_check_cpumask() +* at the same time. The RX thread might be faster and return from +* iscsit_thread_reschedule() with conn_rx_reset_cpumask set to 0. +* Then the TX thread sets it back to 1. +* The next time the RX thread loops, it sees conn_rx_reset_cpumask +* set to 1 and calls set_cpus_allowed_ptr() again and set it to 0. +*/ +iscsit_thread_reschedule (conn); + +/* +* mode == 1 signals iscsi_target_tx_thread() usage. +* mode == 0 signals iscsi_target_rx_thread() usage. +*/ +if (mode ==1 ) { +if (!conn->conn_tx_reset_cpumask) +return ; + }else { +if (!conn->conn_rx_reset_cpumask) +return ; + } + +/* +* Update the CPU mask for this single kthread so that +* both TX and RX kthreads are scheduled to run on the +* same CPU. +*/ +set_cpus_allowed_ptr (p, conn->conn_cpumask); +if (mode ==1 ) + conn->conn_tx_reset_cpumask =0 ; +else + conn->conn_rx_reset_cpumask =0 ; +} +EXPORT_SYMBOL (iscsit_thread_check_cpumask); +int iscsit_immediate_queue (struct iscsi_conn *conn,struct iscsi_cmd *cmd,int state) {
drivers/target/iscsi/iscsi_target_configfs.c +32 -0
@@ -1127,8 +1127,40 @@ static ssize_t lio_target_wwn_lio_version_show(struct config_item *item,CONFIGFS_ATTR_RO (lio_target_wwn_, lio_version); +static ssize_t lio_target_wwn_cpus_allowed_list_show ( +struct config_item *item,char *page) +{ +return sprintf (page,"%*pbl\n" , +cpumask_pr_args (iscsit_global->allowed_cpumask)); +} + +static ssize_t lio_target_wwn_cpus_allowed_list_store ( +struct config_item *item,const char *page,size_t count) +{ +int ret; +char *orig; +cpumask_t new_allowed_cpumask; + + orig =kstrdup (page,GFP_KERNEL ); +if (!orig) +return -ENOMEM ; + +cpumask_clear (&new_allowed_cpumask); + ret =cpulist_parse (orig, &new_allowed_cpumask); + +kfree (orig); +if (ret !=0 ) +return ret; + +cpumask_copy (iscsit_global->allowed_cpumask, &new_allowed_cpumask); +return count; +} + +CONFIGFS_ATTR (lio_target_wwn_, cpus_allowed_list); +static struct configfs_attribute *lio_target_wwn_attrs[] = { &lio_target_wwn_attr_lio_version, + &lio_target_wwn_attr_cpus_allowed_list,NULL , };
drivers/target/iscsi/iscsi_target_login.c +8 -0
@@ -1129,8 +1129,15 @@ static struct iscsi_conn *iscsit_alloc_conn(struct iscsi_np *np) goto free_conn_ops; } +if (!zalloc_cpumask_var (&conn->allowed_cpumask,GFP_KERNEL )) { +pr_err ("Unable to allocate conn->allowed_cpumask\n" ); + goto free_conn_cpumask; + } +return conn; +free_conn_cpumask: +free_cpumask_var (conn->conn_cpumask); free_conn_ops:kfree (conn->conn_ops); put_transport:
@@ -1142,6 +1149,7 @@ static struct iscsi_conn *iscsit_alloc_conn(struct iscsi_np *np)void iscsit_free_conn (struct iscsi_conn *conn) { +free_cpumask_var (conn->allowed_cpumask);free_cpumask_var (conn->conn_cpumask);kfree (conn->conn_ops);iscsit_put_transport (conn->conn_transport);
include/target/iscsi/iscsi_target_core.h +6 -25
@@ -580,6 +580,7 @@ struct iscsi_conn {struct ahash_request *conn_tx_hash;/* Used for scheduling TX and RX connection kthreads */ cpumask_var_t conn_cpumask; +cpumask_var_t allowed_cpumask; unsigned int conn_rx_reset_cpumask:1; unsigned int conn_tx_reset_cpumask:1;/* list_head of struct iscsi_cmd for this connection */
@@ -878,6 +879,7 @@ struct iscsit_global {/* Thread Set bitmap pointer */ unsigned long *ts_bitmap;spinlock_t ts_bitmap_lock; +cpumask_var_t allowed_cpumask;/* Used for iSCSI discovery session authentication */ struct iscsi_node_acl discovery_acl;struct iscsi_portal_group *discovery_tpg;
@@ -898,29 +900,8 @@ static inline u32 session_get_next_ttt(struct iscsi_session *session)extern struct iscsi_cmd *iscsit_find_cmd_from_itt (struct iscsi_conn *,itt_t ); -static inline void iscsit_thread_check_cpumask ( -struct iscsi_conn *conn, -struct task_struct *p, -int mode) -{ -/* -* mode == 1 signals iscsi_target_tx_thread() usage. -* mode == 0 signals iscsi_target_rx_thread() usage. -*/ -if (mode ==1 ) { -if (!conn->conn_tx_reset_cpumask) -return ; - conn->conn_tx_reset_cpumask =0 ; - }else { -if (!conn->conn_rx_reset_cpumask) -return ; - conn->conn_rx_reset_cpumask =0 ; - } -/* -* Update the CPU mask for this single kthread so that -* both TX and RX kthreads are scheduled to run on the -* same CPU. -*/ -set_cpus_allowed_ptr (p, conn->conn_cpumask); -} +extern void iscsit_thread_check_cpumask (struct iscsi_conn *conn, +struct task_struct *p, +int mode); +#endif /* ISCSI_TARGET_CORE_H */
Signature · 1 line
2.17.1
Hi, christie
Have you started reviewing this patch?
Mingzhe
Quoted 278 lines · 在 2022/3/1 15:55, [email protected] 写道:
From: Mingzhe Zou <[email protected]>
The RX/TX threads for iSCSI connection can be scheduled to any online cpus, and will not be rescheduled.
If bind other heavy load threads with iSCSI connection RX/TX thread to the same cpu, the iSCSI performance will be worse.
This patch add iscsi/cpus_allowed_list in configfs. The available cpus set of iSCSI connection RX/TX threads is
allowed_cpus&online_cpus. If it is modified, all RX/TX threads will be rescheduled.Signed-off-by Mingzhe Zou <[email protected]>--- drivers/target/iscsi/iscsi_target.c | 77 +++++++++++++++++++- drivers/target/iscsi/iscsi_target_configfs.c | 32 ++++++++ drivers/target/iscsi/iscsi_target_login.c | 8 ++ include/target/iscsi/iscsi_target_core.h | 31 ++------ 4 files changed, 120 insertions(+), 28 deletions(-)drivers/target/iscsi/iscsi_target.c +74
-3@@ -702,13 +702,19 @@ static int __init iscsi_target_init_module(void)if (!iscsit_global->ts_bitmap) goto configfs_out; +if (!zalloc_cpumask_var (&iscsit_global->allowed_cpumask,GFP_KERNEL )) { +pr_err ("Unable to allocate iscsit_global->allowed_cpumask\n" ); + goto bitmap_out; + } +cpumask_setall (iscsit_global->allowed_cpumask); + lio_qr_cache =kmem_cache_create ("lio_qr_cache" ,sizeof (struct iscsi_queue_req ), __alignof__(struct iscsi_queue_req ),0 ,NULL );if (!lio_qr_cache) {pr_err ("Unable to kmem_cache_create() for" " lio_qr_cache\n" ); - goto bitmap_out; + goto cpumask_out; } lio_dr_cache = kmem_cache_create("lio_dr_cache",@@ -753,6 +759,8 @@ static int __init iscsi_target_init_module(void)kmem_cache_destroy (lio_dr_cache); qr_out:kmem_cache_destroy (lio_qr_cache); +cpumask_out: +free_cpumask_var (iscsit_global->allowed_cpumask); bitmap_out:vfree (iscsit_global->ts_bitmap); configfs_out:@@ -782,6 +790,7 @@ static void __exit iscsi_target_cleanup_module(void)target_unregister_template (&iscsi_ops); +free_cpumask_var (iscsit_global->allowed_cpumask);vfree (iscsit_global->ts_bitmap);kfree (iscsit_global); }@@ -3587,6 +3596,11 @@ static int iscsit_send_reject(void iscsit_thread_get_cpumask (struct iscsi_conn *conn) {int ord, cpu; +cpumask_t conn_allowed_cpumask; + +cpumask_and (&conn_allowed_cpumask, iscsit_global->allowed_cpumask, + cpu_online_mask); +/* * bitmap_id is assigned from iscsit_global->ts_bitmap from * within iscsit_start_kthreads() @@ -3595,8 +3609,9 @@ void iscsit_thread_get_cpumask(struct iscsi_conn *conn)* iSCSI connection's RX/TX threads will be scheduled to * execute upon. */ - ord = conn->bitmap_id %cpumask_weight (cpu_online_mask); -for_each_online_cpu (cpu) { +cpumask_clear (conn->conn_cpumask); + ord = conn->bitmap_id %cpumask_weight (&conn_allowed_cpumask); +for_each_cpu (cpu, &conn_allowed_cpumask) {if (ord-- ==0 ) {cpumask_set_cpu (cpu, conn->conn_cpumask);return ;@@ -3609,6 +3624,62 @@ void iscsit_thread_get_cpumask(struct iscsi_conn *conn)cpumask_setall (conn->conn_cpumask); } +static void iscsit_thread_reschedule (struct iscsi_conn *conn) +{ +/* +* If iscsit_global->allowed_cpumask modified, reschedule iSCSI +* connection's RX/TX threads update conn->allowed_cpumask. +*/ +if (!cpumask_equal (iscsit_global->allowed_cpumask, + conn->allowed_cpumask)) { +iscsit_thread_get_cpumask (conn); + conn->conn_tx_reset_cpumask =1 ; + conn->conn_rx_reset_cpumask =1 ; +cpumask_copy (conn->allowed_cpumask, + iscsit_global->allowed_cpumask); + } +} + +void iscsit_thread_check_cpumask ( +struct iscsi_conn *conn, +struct task_struct *p, +int mode) +{ +/* +* The TX and RX threads maybe call iscsit_thread_check_cpumask() +* at the same time. The RX thread might be faster and return from +* iscsit_thread_reschedule() with conn_rx_reset_cpumask set to 0. +* Then the TX thread sets it back to 1. +* The next time the RX thread loops, it sees conn_rx_reset_cpumask +* set to 1 and calls set_cpus_allowed_ptr() again and set it to 0. +*/ +iscsit_thread_reschedule (conn); + +/* +* mode == 1 signals iscsi_target_tx_thread() usage. +* mode == 0 signals iscsi_target_rx_thread() usage. +*/ +if (mode ==1 ) { +if (!conn->conn_tx_reset_cpumask) +return ; + }else { +if (!conn->conn_rx_reset_cpumask) +return ; + } + +/* +* Update the CPU mask for this single kthread so that +* both TX and RX kthreads are scheduled to run on the +* same CPU. +*/ +set_cpus_allowed_ptr (p, conn->conn_cpumask); +if (mode ==1 ) + conn->conn_tx_reset_cpumask =0 ; +else + conn->conn_rx_reset_cpumask =0 ; +} +EXPORT_SYMBOL (iscsit_thread_check_cpumask); +int iscsit_immediate_queue (struct iscsi_conn *conn,struct iscsi_cmd *cmd,int state) {drivers/target/iscsi/iscsi_target_configfs.c +32
-0@@ -1127,8 +1127,40 @@ static ssize_t lio_target_wwn_lio_version_show(struct config_item *item,CONFIGFS_ATTR_RO (lio_target_wwn_, lio_version); +static ssize_t lio_target_wwn_cpus_allowed_list_show ( +struct config_item *item,char *page) +{ +return sprintf (page,"%*pbl\n" , +cpumask_pr_args (iscsit_global->allowed_cpumask)); +} + +static ssize_t lio_target_wwn_cpus_allowed_list_store ( +struct config_item *item,const char *page,size_t count) +{ +int ret; +char *orig; +cpumask_t new_allowed_cpumask; + + orig =kstrdup (page,GFP_KERNEL ); +if (!orig) +return -ENOMEM ; + +cpumask_clear (&new_allowed_cpumask); + ret =cpulist_parse (orig, &new_allowed_cpumask); + +kfree (orig); +if (ret !=0 ) +return ret; + +cpumask_copy (iscsit_global->allowed_cpumask, &new_allowed_cpumask); +return count; +} + +CONFIGFS_ATTR (lio_target_wwn_, cpus_allowed_list); +static struct configfs_attribute *lio_target_wwn_attrs[] = { &lio_target_wwn_attr_lio_version, + &lio_target_wwn_attr_cpus_allowed_list,NULL , };drivers/target/iscsi/iscsi_target_login.c +8
-0@@ -1129,8 +1129,15 @@ static struct iscsi_conn *iscsit_alloc_conn(struct iscsi_np *np) goto free_conn_ops; } +if (!zalloc_cpumask_var (&conn->allowed_cpumask,GFP_KERNEL )) { +pr_err ("Unable to allocate conn->allowed_cpumask\n" ); + goto free_conn_cpumask; + } +return conn; +free_conn_cpumask: +free_cpumask_var (conn->conn_cpumask); free_conn_ops:kfree (conn->conn_ops); put_transport:@@ -1142,6 +1149,7 @@ static struct iscsi_conn *iscsit_alloc_conn(struct iscsi_np *np)void iscsit_free_conn (struct iscsi_conn *conn) { +free_cpumask_var (conn->allowed_cpumask);free_cpumask_var (conn->conn_cpumask);kfree (conn->conn_ops);iscsit_put_transport (conn->conn_transport);include/target/iscsi/iscsi_target_core.h +6
-25@@ -580,6 +580,7 @@ struct iscsi_conn {struct ahash_request *conn_tx_hash;/* Used for scheduling TX and RX connection kthreads */ cpumask_var_t conn_cpumask; +cpumask_var_t allowed_cpumask; unsigned int conn_rx_reset_cpumask:1; unsigned int conn_tx_reset_cpumask:1;/* list_head of struct iscsi_cmd for this connection */ @@ -878,6 +879,7 @@ struct iscsit_global {/* Thread Set bitmap pointer */ unsigned long *ts_bitmap;spinlock_t ts_bitmap_lock; +cpumask_var_t allowed_cpumask;/* Used for iSCSI discovery session authentication */ struct iscsi_node_acl discovery_acl;struct iscsi_portal_group *discovery_tpg;@@ -898,29 +900,8 @@ static inline u32 session_get_next_ttt(struct iscsi_session *session)extern struct iscsi_cmd *iscsit_find_cmd_from_itt (struct iscsi_conn *,itt_t ); -static inline void iscsit_thread_check_cpumask ( -struct iscsi_conn *conn, -struct task_struct *p, -int mode) -{ -/* -* mode == 1 signals iscsi_target_tx_thread() usage. -* mode == 0 signals iscsi_target_rx_thread() usage. -*/ -if (mode ==1 ) { -if (!conn->conn_tx_reset_cpumask) -return ; - conn->conn_tx_reset_cpumask =0 ; - }else { -if (!conn->conn_rx_reset_cpumask) -return ; - conn->conn_rx_reset_cpumask =0 ; - } -/* -* Update the CPU mask for this single kthread so that -* both TX and RX kthreads are scheduled to run on the -* same CPU. -*/ -set_cpus_allowed_ptr (p, conn->conn_cpumask); -} +extern void iscsit_thread_check_cpumask (struct iscsi_conn *conn, +struct task_struct *p, +int mode); +#endif /* ISCSI_TARGET_CORE_H */
Quoted 5 lines · On 3/1/22 1:55 AM, [email protected] wrote:
From: Mingzhe Zou <[email protected]>
The RX/TX threads for iSCSI connection can be scheduled to any online cpus, and will not be rescheduled.
Quoted 9 lines
If bind other heavy load threads with iSCSI connection RX/TX thread to the same cpu, the iSCSI performance will be worse.
This patch add iscsi/cpus_allowed_list in configfs. The available cpus set of iSCSI connection RX/TX threads is
allowed_cpus&online_cpus. If it is modified, all RX/TX threads will be rescheduled.
Martin K. Petersen
AppliedMingzhe,
Quoted 9 lines
The RX/TX threads for iSCSI connection can be scheduled to any online cpus, and will not be rescheduled.
If bind other heavy load threads with iSCSI connection RX/TX thread to the same cpu, the iSCSI performance will be worse.
This patch add iscsi/cpus_allowed_list in configfs. The available cpus set of iSCSI connection RX/TX threads is
allowed_cpus&online_cpus. If it is modified, all RX/TX threads will be rescheduled.
Applied to 5.18/scsi-staging, thanks!
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering
Martin K. Petersen
AppliedQuoted 10 lines · On Tue, 1 Mar 2022 15:55:00 +0800, [email protected] wrote:
From: Mingzhe Zou <[email protected]>
The RX/TX threads for iSCSI connection can be scheduled to any online cpus, and will not be rescheduled.
If bind other heavy load threads with iSCSI connection RX/TX thread to the same cpu, the iSCSI performance will be worse.
[...]
Applied to 5.18/scsi-queue, thanks!
[1/1] target: add iscsi/cpus_allowed_list in configfs
https://git.kernel.org/mkp/scsi/c/d72d827f2f26
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering