Received: by 10.192.165.148 with SMTP id m20csp451702imm; Wed, 2 May 2018 03:14:31 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqUxKhiImBe0qLd3C+7IuNWI4kI0Hy0B0Cl7b+6CiuXb2XG9PDu9ezi+kZuLSbj/QS94KPB X-Received: by 2002:a17:902:6505:: with SMTP id b5-v6mr19409162plk.147.1525256070983; Wed, 02 May 2018 03:14:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525256070; cv=none; d=google.com; s=arc-20160816; b=XVeqz9vgjSafnMHIFzeyVJ3NXRSsVwle4WBPvB9ZkcQniY/5Pb61PRFCJQzfizLuMR JCJIavI4ulUPcmx165aCkFL1/wf5VkUz6vBl8iS3goshqGr/YvlJcrBFtWRcRyIlgzlu jcBEMX1fTsooWlbCzqtr8S4LZRFxK/CW//L5Ok/Lzw4Bmurcz18yTSC3cErjsHhwgqVK JvWxHp0CyWzPAHW/hVvxhqAOzznwszJM9IyoMNLHDUjmIoSEzvqBg06aVWqc0byb7ky8 J+Qub/54vFLFsSheqhP6ZCGpgDP3JXyj8alYPPBkSxmY9GNaGJ57cjF6rzvAy88SIAkC I6vw== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dmarc-filter :dkim-signature:dkim-signature:arc-authentication-results; bh=w/V/6Tb1BVRTAr1oo5EM51Hucv99kanEbB4ctsvmr/s=; b=p2ZEGTvNxEgWq9Jt9EAXTwrDnpEpc2AFRsVZMXKW0e/NcSEdUrMobmpaQLRU1VCD8U fckwkSJzqJ5hIsFi0yvrtmrU5s6AMNa7FPRw5QHNub2Z07jFszRKqmwkmFinysiTkg7t WmXEme9JNTHMoMosCC7cwjJTazJHuTNov65IDimK++F9HT3AUGl0LVzS0U38Jq9qUJID Yej29Npl+jpqOYuSCPx7NYa/nq2KcFsEWIsIsMaCBnfaYi/bxTxNeMOS7PLZPJWKvOwN 9enKb5qoyPH3L1WnG5uzecVgsYEU4O1c0KrCXDC4WRJvFDWglIeBwEJnVBWLk3D2Cq42 ki5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=ek5pDc/b; dkim=pass header.i=@codeaurora.org header.s=default header.b=mPqVCro2; 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 m140si2470801pfd.16.2018.05.02.03.14.16; Wed, 02 May 2018 03:14:30 -0700 (PDT) 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; dkim=pass header.i=@codeaurora.org header.s=default header.b=ek5pDc/b; dkim=pass header.i=@codeaurora.org header.s=default header.b=mPqVCro2; 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 S1751324AbeEBKOJ (ORCPT + 99 others); Wed, 2 May 2018 06:14:09 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:40146 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750942AbeEBKOE (ORCPT ); Wed, 2 May 2018 06:14:04 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 9E37460710; Wed, 2 May 2018 10:14:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1525256043; bh=7sowgLZur207Nmk1Iz+As0rnU7SIMqe/9cErmxqgIL0=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=ek5pDc/b9tS1WErtAVVYPi3Y/w0H4GqBejlDvEUtHC8+y9Y1dUNa2gFdI9vSTPwkv P0EV6u1uPFvXNztYCe3rQqIa2qPMWt7xWXgQSsA/DceIrfiqP/p2zl4IDJG6Hc0wJX FSy7HEeIAIgREbOCMSgIiYVBwdFc71OEFR0ntcj0= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from [10.204.78.254] (blr-c-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.19.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: gkohli@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 12B3F6028D; Wed, 2 May 2018 10:13:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1525256042; bh=7sowgLZur207Nmk1Iz+As0rnU7SIMqe/9cErmxqgIL0=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=mPqVCro2YRk0x2fuB8VVAhNOhcm9p5rKWpauUSPGS6CIdZcXJNwhoIEHfJmbZfOlU d9bHmGt+UDmiX6MHM3sqGH2AfBc2gYEy3XTejmLlo647BhV3vfy1ysAST1W1stezlR 6K5q6KW2acLFIdsS4wOlvwfwfmmA177uXDFY/XxQ= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 12B3F6028D Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=gkohli@codeaurora.org Subject: Re: [PATCH v1] kthread/smpboot: Serialize kthread parking against wakeup To: Peter Zijlstra Cc: tglx@linutronix.de, mpe@ellerman.id.au, mingo@kernel.org, bigeasy@linutronix.de, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Neeraj Upadhyay , Will Deacon , Oleg Nesterov References: <20180426085719.GW4129@hirez.programming.kicks-ass.net> <4d3f68f8-e599-6b27-a2e8-9e96b401d57a@codeaurora.org> <20180430111744.GE4082@hirez.programming.kicks-ass.net> <3af3365b-4e3f-e388-8e90-45a3bd4120fd@codeaurora.org> <20180501101845.GE12217@hirez.programming.kicks-ass.net> <20180501113132.GF12217@hirez.programming.kicks-ass.net> <745d762d-9ab3-0749-9b87-9bb03d913071@codeaurora.org> <20180501131904.GG12217@hirez.programming.kicks-ass.net> <9b289790-9b3a-73bd-7166-bf39f32cefd8@codeaurora.org> <20180502082011.GB12180@hirez.programming.kicks-ass.net> From: "Kohli, Gaurav" Message-ID: <830d7225-af90-a55a-991a-bb2023d538f1@codeaurora.org> Date: Wed, 2 May 2018 15:43:52 +0530 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <20180502082011.GB12180@hirez.programming.kicks-ass.net> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 5/2/2018 1:50 PM, Peter Zijlstra wrote: > On Wed, May 02, 2018 at 10:45:52AM +0530, Kohli, Gaurav wrote: >> On 5/1/2018 6:49 PM, Peter Zijlstra wrote: > >>> - complete(&kthread->parked), which we can do inside schedule(); this >>> solves the problem because then kthread_park() will not return early >>> and the task really is blocked. >> >> I think complete will not help, as problem is like below : >> >> Control Thread CPUHP thread >> >> cpuhp_thread_fun >> Wake control thread >> complete(&st->done); >> >> takedown_cpu >> kthread_park >> set_bit(KTHREAD_SHOULD_PARK >> >> Here cpuhp is looping, >> //success case >> Generally when issue is not >> coming >> it schedule out by below : >> ht->thread_should_run(td->cpu >> scheduler >> //failure case >> before schedule >> loop check >> (kthread_should_park() >> enter here as PARKED set >> >> wake_up_process(k) > > If k has TASK_PARKED, then wake_up_process() which uses TASK_NORMAL will > no-op, because: > > TASK_PARKED & TASK_NORMAL == 0 > >> __kthread_parkme >> complete(&self->parked); >> SETS RUNNING >> schedule > > But suppose, you do get that store, and we get to schedule with > TASK_RUNNING, then schedule will no-op and we'll go around the loop and > not complete. > > See also: lkml.kernel.org/r/20180430111744.GE4082@hirez.programming.kicks-ass.net > > Either TASK_RUNNING gets set before we do schedule() and we go around > again, re-set TASK_PARKED, resched the condition and re-call schedule(), > or we schedule() first and ttwu() will not issue the TASK_RUNNING store. > > In either case, we'll eventually hit schedule() with TASK_PARKED. Then, > and only then will the complete() happen. > >> wait_for_completion(&kthread->parked); > > The point is, we'll only ever complete ^ that completion when we've > scheduled out the task in TASK_PARKED state. If the task didn't get > parked, no completion. Thanks for the detailed explanation, yes in all cases unpark will observe parked state only. > > > And that is the reason I like this approach above the others. It > guarantees the task really is parked when we ask for it. We don't have > to deal with the task still running and getting migrated to another CPU > nonsense. > -- Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.