Received: by 10.223.185.116 with SMTP id b49csp8019680wrg; Thu, 1 Mar 2018 15:35:16 -0800 (PST) X-Google-Smtp-Source: AG47ELuxj/xmoGIPQq1uEDAtYgIynN8hJiXNNBDm3w71CcrJkZFPZc5CUZDxFovIbUqWeo+dLPZq X-Received: by 2002:a17:902:b109:: with SMTP id q9-v6mr3490068plr.340.1519947315901; Thu, 01 Mar 2018 15:35:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519947315; cv=none; d=google.com; s=arc-20160816; b=o4CQgqwR+f8XAwU5Slgo/ekY64zHHI+f3PF+3aBk1q64SF0mlK4vr2zWQJR1xztS0w xk0z50mqQHbzug3KCcJoEEUEGpDKpJk5B1KiEQVmiaRmVO0ochzNj0GAPBS6G2r8T2Dq zXd0UcxUI+1+PLwvwCcc51QTiSnSzEdIx77Ip9PKYwnEX/KhU7Ne/SB/tbn7f1OrdmyX dD8xUc+YQAtUJBfWoe5WSf2fUzMwdjNkja1roEhJh1CirjQ2+Q3aFBT3un07rga4jwY/ vrc0JXA+llZoGdoJDcKBVilb0ZXe75oRUND0AydW88SFIgrof128oWD8nDmn5FGzo8g8 PVYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:cc:subject:date:to :from:arc-authentication-results; bh=l4/cJAbrphNwYViqyUNNP5MOaIkeNFUmSHxcMxpYI30=; b=G/lh306jMpNG6hc7XzFfcBt282U2VGgut89+Zn18XcEpbXD49ottl2QFHbEdQoP7qq p+Jkr8XNZb1/DPsYO91e1o35VJHQARTljNUpMsjsJFBUvcj/fu6x3YlgAlZSTR+nZTPP am8rT9x6N4UEK3N/3WpAhV9EYLAdCdfAfas/VPPB7t8eSI6L3vHuRn4xW6BEv18+ficQ 9IK5GY0I0OxSytMnopRAsFPEFmYi+6Ky/vyo8QUePIlBVs9E/8yB7HwL49jMWAwpiS8f mVVDP68IVPLHgBmcbInQEMErrXUZbpOUPsXwb38zit9FqKxHmQXAKwiG534l6bSfDfdl S0jQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i127si3112498pgc.100.2018.03.01.15.35.01; Thu, 01 Mar 2018 15:35:15 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1163406AbeCAXdv (ORCPT + 99 others); Thu, 1 Mar 2018 18:33:51 -0500 Received: from mx2.suse.de ([195.135.220.15]:54312 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1163391AbeCAXds (ORCPT ); Thu, 1 Mar 2018 18:33:48 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 3DC0BB46D; Thu, 1 Mar 2018 23:33:47 +0000 (UTC) From: NeilBrown To: Oleg Drokin , Greg Kroah-Hartman , James Simmons , Andreas Dilger Date: Fri, 02 Mar 2018 10:31:25 +1100 Subject: [PATCH 13/17] staging: lustre: remove 'ptlrpc_thread usage' for sai_agl_thread Cc: Linux Kernel Mailing List , Lustre Development List Message-ID: <151994708549.7628.13268008928655143336.stgit@noble> In-Reply-To: <151994679573.7628.1024109499321778846.stgit@noble> References: <151994679573.7628.1024109499321778846.stgit@noble> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Lustre has a 'struct ptlrpc_thread' which provides control functionality wrapped around kthreads. None of the functionality used in statahead.c requires ptlrcp_thread - it can all be done directly with kthreads. So discard the ptlrpc_thread and just use a task_struct directly. One particular change worth noting is that in the current code, the thread performs some start-up actions and then signals that it is ready to go. In the new code, the thread is first created, then the startup actions are perform, then the thread is woken up. This means there is no need to wait any more than kthread_create() already waits. Signed-off-by: NeilBrown --- .../staging/lustre/lustre/llite/llite_internal.h | 2 - drivers/staging/lustre/lustre/llite/statahead.c | 78 +++++++------------- 2 files changed, 28 insertions(+), 52 deletions(-) diff --git a/drivers/staging/lustre/lustre/llite/llite_internal.h b/drivers/staging/lustre/lustre/llite/llite_internal.h index f68c2e88f12b..0c2d717fd526 100644 --- a/drivers/staging/lustre/lustre/llite/llite_internal.h +++ b/drivers/staging/lustre/lustre/llite/llite_internal.h @@ -1071,7 +1071,7 @@ struct ll_statahead_info { sai_in_readpage:1;/* statahead in readdir() */ wait_queue_head_t sai_waitq; /* stat-ahead wait queue */ struct ptlrpc_thread sai_thread; /* stat-ahead thread */ - struct ptlrpc_thread sai_agl_thread; /* AGL thread */ + struct task_struct *sai_agl_task; /* AGL thread */ struct list_head sai_interim_entries; /* entries which got async * stat reply, but not * instantiated diff --git a/drivers/staging/lustre/lustre/llite/statahead.c b/drivers/staging/lustre/lustre/llite/statahead.c index ba00881a5745..39241b952bf4 100644 --- a/drivers/staging/lustre/lustre/llite/statahead.c +++ b/drivers/staging/lustre/lustre/llite/statahead.c @@ -383,7 +383,7 @@ static void ll_agl_add(struct ll_statahead_info *sai, } if (added > 0) - wake_up(&sai->sai_agl_thread.t_ctl_waitq); + wake_up_process(sai->sai_agl_task); } /* allocate sai */ @@ -404,7 +404,6 @@ static struct ll_statahead_info *ll_sai_alloc(struct dentry *dentry) sai->sai_index = 1; init_waitqueue_head(&sai->sai_waitq); init_waitqueue_head(&sai->sai_thread.t_ctl_waitq); - init_waitqueue_head(&sai->sai_agl_thread.t_ctl_waitq); INIT_LIST_HEAD(&sai->sai_interim_entries); INIT_LIST_HEAD(&sai->sai_entries); @@ -467,7 +466,7 @@ static void ll_sai_put(struct ll_statahead_info *sai) spin_unlock(&lli->lli_sa_lock); LASSERT(thread_is_stopped(&sai->sai_thread)); - LASSERT(thread_is_stopped(&sai->sai_agl_thread)); + LASSERT(sai->sai_agl_task == NULL); LASSERT(sai->sai_sent == sai->sai_replied); LASSERT(!sa_has_callback(sai)); @@ -861,35 +860,13 @@ static int ll_agl_thread(void *arg) struct inode *dir = d_inode(parent); struct ll_inode_info *plli = ll_i2info(dir); struct ll_inode_info *clli; - struct ll_sb_info *sbi = ll_i2sbi(dir); - struct ll_statahead_info *sai; - struct ptlrpc_thread *thread; + /* We already own this reference, so it is safe to take it without a lock. */ + struct ll_statahead_info *sai = plli->lli_sai; - sai = ll_sai_get(dir); - thread = &sai->sai_agl_thread; - thread->t_pid = current_pid(); CDEBUG(D_READA, "agl thread started: sai %p, parent %pd\n", sai, parent); - atomic_inc(&sbi->ll_agl_total); - spin_lock(&plli->lli_agl_lock); - sai->sai_agl_valid = 1; - if (thread_is_init(thread)) - /* If someone else has changed the thread state - * (e.g. already changed to SVC_STOPPING), we can't just - * blindly overwrite that setting. - */ - thread_set_flags(thread, SVC_RUNNING); - spin_unlock(&plli->lli_agl_lock); - wake_up(&thread->t_ctl_waitq); - - while (1) { - wait_event_idle(thread->t_ctl_waitq, - !list_empty(&sai->sai_agls) || - !thread_is_running(thread)); - - if (!thread_is_running(thread)) - break; + while (!kthread_should_stop()) { spin_lock(&plli->lli_agl_lock); /* The statahead thread maybe help to process AGL entries, @@ -904,6 +881,12 @@ static int ll_agl_thread(void *arg) } else { spin_unlock(&plli->lli_agl_lock); } + + set_current_state(TASK_IDLE); + if (list_empty(&sai->sai_agls) && + !kthread_should_stop()) + schedule(); + __set_current_state(TASK_RUNNING); } spin_lock(&plli->lli_agl_lock); @@ -917,19 +900,16 @@ static int ll_agl_thread(void *arg) iput(&clli->lli_vfs_inode); spin_lock(&plli->lli_agl_lock); } - thread_set_flags(thread, SVC_STOPPED); spin_unlock(&plli->lli_agl_lock); - wake_up(&thread->t_ctl_waitq); - ll_sai_put(sai); CDEBUG(D_READA, "agl thread stopped: sai %p, parent %pd\n", sai, parent); + ll_sai_put(sai); return 0; } /* start agl thread */ static void ll_start_agl(struct dentry *parent, struct ll_statahead_info *sai) { - struct ptlrpc_thread *thread = &sai->sai_agl_thread; struct ll_inode_info *plli; struct task_struct *task; @@ -937,16 +917,22 @@ static void ll_start_agl(struct dentry *parent, struct ll_statahead_info *sai) sai, parent); plli = ll_i2info(d_inode(parent)); - task = kthread_run(ll_agl_thread, parent, "ll_agl_%u", - plli->lli_opendir_pid); + task = kthread_create(ll_agl_thread, parent, "ll_agl_%u", + plli->lli_opendir_pid); if (IS_ERR(task)) { CERROR("can't start ll_agl thread, rc: %ld\n", PTR_ERR(task)); - thread_set_flags(thread, SVC_STOPPED); return; } - wait_event_idle(thread->t_ctl_waitq, - thread_is_running(thread) || thread_is_stopped(thread)); + sai->sai_agl_task = task; + atomic_inc(&ll_i2sbi(d_inode(parent))->ll_agl_total); + spin_lock(&plli->lli_agl_lock); + sai->sai_agl_valid = 1; + spin_unlock(&plli->lli_agl_lock); + /* Get an extra reference that the thread holds */ + ll_sai_get(d_inode(parent)); + + wake_up_process(task); } /* statahead thread main function */ @@ -958,7 +944,6 @@ static int ll_statahead_thread(void *arg) struct ll_sb_info *sbi = ll_i2sbi(dir); struct ll_statahead_info *sai; struct ptlrpc_thread *sa_thread; - struct ptlrpc_thread *agl_thread; struct page *page = NULL; __u64 pos = 0; int first = 0; @@ -967,7 +952,6 @@ static int ll_statahead_thread(void *arg) sai = ll_sai_get(dir); sa_thread = &sai->sai_thread; - agl_thread = &sai->sai_agl_thread; sa_thread->t_pid = current_pid(); CDEBUG(D_READA, "statahead thread starting: sai %p, parent %pd\n", sai, parent); @@ -1129,21 +1113,13 @@ static int ll_statahead_thread(void *arg) sa_handle_callback(sai); } out: - if (sai->sai_agl_valid) { - spin_lock(&lli->lli_agl_lock); - thread_set_flags(agl_thread, SVC_STOPPING); - spin_unlock(&lli->lli_agl_lock); - wake_up(&agl_thread->t_ctl_waitq); + if (sai->sai_agl_task) { + kthread_stop(sai->sai_agl_task); CDEBUG(D_READA, "stop agl thread: sai %p pid %u\n", - sai, (unsigned int)agl_thread->t_pid); - wait_event_idle(agl_thread->t_ctl_waitq, - thread_is_stopped(agl_thread)); - } else { - /* Set agl_thread flags anyway. */ - thread_set_flags(agl_thread, SVC_STOPPED); + sai, (unsigned int)sai->sai_agl_task->pid); + sai->sai_agl_task = NULL; } - /* * wait for inflight statahead RPCs to finish, and then we can free sai * safely because statahead RPC will access sai data