Received: by 10.223.185.116 with SMTP id b49csp209831wrg; Thu, 8 Mar 2018 15:55:10 -0800 (PST) X-Google-Smtp-Source: AG47ELto/WWK2MUzwEEXKZ005Oih/0FQ/nn8PY32ZK2Ip6rPy0vPs9Szndh8/Xin5oyXe0SdCRcL X-Received: by 10.101.101.5 with SMTP id x5mr22302609pgv.195.1520553310455; Thu, 08 Mar 2018 15:55:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520553310; cv=none; d=google.com; s=arc-20160816; b=yu7EKhnT3N0dFcEBfgByeKshhFOdz4z7KPMVWjewtMX+o+oZOApqmc0GhItFLmM2on Nd94oZELGBg0KXavch8/upMkU0+VDcfQXqIcjySkuQ9pNkMbgfofiFZ/f7Yk9DHQZFd6 BrsjitkysaHIFz0qTV+b2vqHw55JT/yzumRgsd1TDPhtpVIaeXpHkl9dJIzxAOp5yGR6 p4srTbjktsTzOZHR/+NMRxW75wcpB6mshJTW1nM++ECsS5a2evNmnS/um+yQr3E6g/Zl 2k5zAhZhu0n4Bcg0LsAuESqE+EjOZ+TBheJopv2fKHkRhfjaePWSztOES52vxylOQINM De+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :content-id:content-language:accept-language:in-reply-to:references :message-id:date:thread-index:thread-topic:subject:cc:to:from :arc-authentication-results; bh=9fGKyBSVKDpqVwPL/VtYAh65K8fuQ7YlyXqccHxFaJ8=; b=nk/RCpjhPqMqAIWHl8lXCKBcK7wVbvv6phtxRUDcl+LWpHr+qKAd/9i0cSIZc7TM8c wCEd6A5YYpPX8EOEgXsmkByJjRRQxEus2kw/VBDrtLuirJ0HsVg0UMUYa0cGTiG7A8tM e2zvuA8yZ5EWrWxTEOpRjw48ugZuu21mxRFB8+T5aKS3Sex8YlDCPQcTe0sR1JRttrGA jVuHLZdDqpGGdLzGK9u77H+obZWJnnlxUJ8S5w++vqFnmN58JKCXaQa5OncmVOiW3x1z GT46po0zcoFOaCWvqw2VuWxSN8k6mapaqNUO6SBvbq98ONUnpQ0eaSV/ooLMho3Wmuqq v1eA== 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 33-v6si15717137plu.426.2018.03.08.15.54.55; Thu, 08 Mar 2018 15:55:10 -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 S1751371AbeCHXxu convert rfc822-to-8bit (ORCPT + 99 others); Thu, 8 Mar 2018 18:53:50 -0500 Received: from mga02.intel.com ([134.134.136.20]:64444 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751235AbeCHXxr (ORCPT ); Thu, 8 Mar 2018 18:53:47 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 08 Mar 2018 15:53:46 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,443,1515484800"; d="scan'208";a="36651749" Received: from fmsmsx108.amr.corp.intel.com ([10.18.124.206]) by fmsmga001.fm.intel.com with ESMTP; 08 Mar 2018 15:53:44 -0800 Received: from fmsmsx116.amr.corp.intel.com (10.18.116.20) by FMSMSX108.amr.corp.intel.com (10.18.124.206) with Microsoft SMTP Server (TLS) id 14.3.319.2; Thu, 8 Mar 2018 15:53:44 -0800 Received: from FMSMSX109.amr.corp.intel.com ([169.254.15.144]) by fmsmsx116.amr.corp.intel.com ([169.254.2.104]) with mapi id 14.03.0319.002; Thu, 8 Mar 2018 15:53:43 -0800 From: "Dilger, Andreas" To: NeilBrown CC: "Drokin, Oleg" , Greg Kroah-Hartman , James Simmons , "Linux Kernel Mailing List" , Lustre Development List Subject: Re: [PATCH 11/17] staging: lustre: ptlrpc: use workqueue for pinger Thread-Topic: [PATCH 11/17] staging: lustre: ptlrpc: use workqueue for pinger Thread-Index: AQHTsbW6JZmkx7V2MkqTbIRpCUMUgKPHlA+A Date: Thu, 8 Mar 2018 23:53:42 +0000 Message-ID: <63D7C945-5CBC-4434-BAF1-F3EBA912CDEF@intel.com> References: <151994679573.7628.1024109499321778846.stgit@noble> <151994708541.7628.5813099904100247526.stgit@noble> In-Reply-To: <151994708541.7628.5813099904100247526.stgit@noble> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.254.37.249] Content-Type: text/plain; charset="us-ascii" Content-ID: <47B5DA3C1F83414487EBADB38E753B14@intel.com> Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mar 1, 2018, at 16:31, NeilBrown wrote: > > lustre has a "Pinger" kthread which periodically pings peers > to ensure all hosts are functioning. > > This can more easily be done using a work queue. > > As maintaining contact with other peers is import for > keeping the filesystem running, and as the filesystem might > be involved in freeing memory, it is safest to have a > separate WQ_MEM_RECLAIM workqueue. > > The SVC_EVENT functionality to wake up the thread can be > replaced with mod_delayed_work(). > > Also use round_jiffies_up_relative() rather than setting a > minimum of 1 second delay. The PING_INTERVAL is measured in > seconds so this meets the need is allow the workqueue to > keep wakeups synchronized. > > Signed-off-by: NeilBrown Looks reasonable. Fortunately, pinging the server does not need to be very accurate since it is only done occasionally when the client is otherwise idle, so it shouldn't matter if the workqueue operation is delayed by a few seconds. Reviewed-by: Andreas Dilger > --- > drivers/staging/lustre/lustre/ptlrpc/pinger.c | 81 +++++++------------------ > 1 file changed, 24 insertions(+), 57 deletions(-) > > diff --git a/drivers/staging/lustre/lustre/ptlrpc/pinger.c b/drivers/staging/lustre/lustre/ptlrpc/pinger.c > index b5f3cfee8e75..0775b7a048bb 100644 > --- a/drivers/staging/lustre/lustre/ptlrpc/pinger.c > +++ b/drivers/staging/lustre/lustre/ptlrpc/pinger.c > @@ -217,21 +217,18 @@ static void ptlrpc_pinger_process_import(struct obd_import *imp, > } > } > > -static int ptlrpc_pinger_main(void *arg) > -{ > - struct ptlrpc_thread *thread = arg; > - > - /* Record that the thread is running */ > - thread_set_flags(thread, SVC_RUNNING); > - wake_up(&thread->t_ctl_waitq); > +static struct workqueue_struct *pinger_wq; > +static void ptlrpc_pinger_main(struct work_struct *ws); > +static DECLARE_DELAYED_WORK(ping_work, ptlrpc_pinger_main); > > - /* And now, loop forever, pinging as needed. */ > - while (1) { > - unsigned long this_ping = cfs_time_current(); > - long time_to_next_wake; > - struct timeout_item *item; > - struct obd_import *imp; > +static void ptlrpc_pinger_main(struct work_struct *ws) > +{ > + unsigned long this_ping = cfs_time_current(); > + long time_to_next_wake; > + struct timeout_item *item; > + struct obd_import *imp; > > + do { > mutex_lock(&pinger_mutex); > list_for_each_entry(item, &timeout_list, ti_chain) { > item->ti_cb(item, item->ti_cb_data); > @@ -260,50 +257,24 @@ static int ptlrpc_pinger_main(void *arg) > time_to_next_wake, > cfs_time_add(this_ping, > PING_INTERVAL * HZ)); > - if (time_to_next_wake > 0) { > - wait_event_idle_timeout(thread->t_ctl_waitq, > - thread_is_stopping(thread) || > - thread_is_event(thread), > - max_t(long, time_to_next_wake, HZ)); > - if (thread_test_and_clear_flags(thread, SVC_STOPPING)) > - break; > - /* woken after adding import to reset timer */ > - thread_test_and_clear_flags(thread, SVC_EVENT); > - } > - } > + } while (time_to_next_wake <= 0); > > - thread_set_flags(thread, SVC_STOPPED); > - wake_up(&thread->t_ctl_waitq); > - > - CDEBUG(D_NET, "pinger thread exiting, process %d\n", current_pid()); > - return 0; > + queue_delayed_work(pinger_wq, &ping_work, > + round_jiffies_up_relative(time_to_next_wake)); > } > > -static struct ptlrpc_thread pinger_thread; > - > int ptlrpc_start_pinger(void) > { > - struct task_struct *task; > - int rc; > - > - if (!thread_is_init(&pinger_thread) && > - !thread_is_stopped(&pinger_thread)) > + if (pinger_wq) > return -EALREADY; > > - init_waitqueue_head(&pinger_thread.t_ctl_waitq); > - > - strcpy(pinger_thread.t_name, "ll_ping"); > - > - task = kthread_run(ptlrpc_pinger_main, &pinger_thread, > - pinger_thread.t_name); > - if (IS_ERR(task)) { > - rc = PTR_ERR(task); > - CERROR("cannot start pinger thread: rc = %d\n", rc); > - return rc; > + pinger_wq = alloc_workqueue("ptlrpc_pinger", WQ_MEM_RECLAIM, 1); > + if (!pinger_wq) { > + CERROR("cannot start pinger workqueue\n"); > + return -ENOMEM; > } > - wait_event_idle(pinger_thread.t_ctl_waitq, > - thread_is_running(&pinger_thread)); > > + queue_delayed_work(pinger_wq, &ping_work, 0); > return 0; > } > > @@ -313,16 +284,13 @@ int ptlrpc_stop_pinger(void) > { > int rc = 0; > > - if (thread_is_init(&pinger_thread) || > - thread_is_stopped(&pinger_thread)) > + if (!pinger_wq) > return -EALREADY; > > ptlrpc_pinger_remove_timeouts(); > - thread_set_flags(&pinger_thread, SVC_STOPPING); > - wake_up(&pinger_thread.t_ctl_waitq); > - > - wait_event_idle(pinger_thread.t_ctl_waitq, > - thread_is_stopped(&pinger_thread)); > + cancel_delayed_work_sync(&ping_work); > + destroy_workqueue(pinger_wq); > + pinger_wq = NULL; > > return rc; > } > @@ -505,6 +473,5 @@ static int ptlrpc_pinger_remove_timeouts(void) > > void ptlrpc_pinger_wake_up(void) > { > - thread_add_flags(&pinger_thread, SVC_EVENT); > - wake_up(&pinger_thread.t_ctl_waitq); > + mod_delayed_work(pinger_wq, &ping_work, 0); > } > > Cheers, Andreas -- Andreas Dilger Lustre Principal Architect Intel Corporation