Re: [PATCH v4] io-wq: simplify code in __io_worker_busy

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 06/04/2021 04:08, Hao Xu wrote:
> leverage xor to simplify code in __io_worker_busy
> 
> Signed-off-by: Hao Xu <haoxu@xxxxxxxxxxxxxxxxx>
> ---
> 
> Sorry, typo by mistake...
> 
>  fs/io-wq.c | 15 ++++++---------
>  1 file changed, 6 insertions(+), 9 deletions(-)
> 
> diff --git a/fs/io-wq.c b/fs/io-wq.c
> index 2dd2d4b1e538..fa2383cb4d50 100644
> --- a/fs/io-wq.c
> +++ b/fs/io-wq.c
> @@ -329,6 +329,8 @@ static void __io_worker_busy(struct io_wqe *wqe, struct io_worker *worker,
>  {
>  	bool worker_bound, work_bound;
>  
> +	BUILD_BUG_ON((IO_WQ_ACCT_UNBOUND ^ IO_WQ_ACCT_BOUND) != 1);
> +
>  	if (worker->flags & IO_WORKER_F_FREE) {
>  		worker->flags &= ~IO_WORKER_F_FREE;
>  		hlist_nulls_del_init_rcu(&worker->nulls_node);
> @@ -341,16 +343,11 @@ static void __io_worker_busy(struct io_wqe *wqe, struct io_worker *worker,
>  	worker_bound = (worker->flags & IO_WORKER_F_BOUND) != 0;
>  	work_bound = (work->flags & IO_WQ_WORK_UNBOUND) == 0;
>  	if (worker_bound != work_bound) {
> +		int index = work_bound ? IO_WQ_ACCT_UNBOUND : IO_WQ_ACCT_BOUND;

Jens, if you'll be at it, can you fold in \n here?
Let's keep static analysis happy

>  		io_wqe_dec_running(worker);
> -		if (work_bound) {
> -			worker->flags |= IO_WORKER_F_BOUND;
> -			wqe->acct[IO_WQ_ACCT_UNBOUND].nr_workers--;
> -			wqe->acct[IO_WQ_ACCT_BOUND].nr_workers++;
> -		} else {
> -			worker->flags &= ~IO_WORKER_F_BOUND;
> -			wqe->acct[IO_WQ_ACCT_UNBOUND].nr_workers++;
> -			wqe->acct[IO_WQ_ACCT_BOUND].nr_workers--;
> -		}
> +		worker->flags ^= IO_WORKER_F_BOUND;
> +		wqe->acct[index].nr_workers--;
> +		wqe->acct[index ^ 1].nr_workers++;
>  		io_wqe_inc_running(worker);
>  	 }
>  }
> 

-- 
Pavel Begunkov



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux