From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A79D4C4363A for ; Mon, 26 Oct 2020 16:46:02 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1D4742222C for ; Mon, 26 Oct 2020 16:46:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="SruZRHB4" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1D4742222C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 5F1C16B006E; Mon, 26 Oct 2020 12:46:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 59E046B0070; Mon, 26 Oct 2020 12:46:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 48CD06B0071; Mon, 26 Oct 2020 12:46:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0140.hostedemail.com [216.40.44.140]) by kanga.kvack.org (Postfix) with ESMTP id 1CBBF6B006E for ; Mon, 26 Oct 2020 12:46:01 -0400 (EDT) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 94D23180AD807 for ; Mon, 26 Oct 2020 16:46:00 +0000 (UTC) X-FDA: 77414653680.16.room18_2016fae27275 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin16.hostedemail.com (Postfix) with ESMTP id 92EBA100E6935 for ; Mon, 26 Oct 2020 16:45:57 +0000 (UTC) X-HE-Tag: room18_2016fae27275 X-Filterd-Recvd-Size: 3495 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf31.hostedemail.com (Postfix) with ESMTP for ; Mon, 26 Oct 2020 16:45:57 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1603730756; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=kChY8deJI75T79lVGPftJ4ey9Ah/Bxr9MOF++yylAmI=; b=SruZRHB4/2X2tN68C38bbrDleSxEM9/1XPl7zpK3UMO1y3WFzNYzatV+nzV8NadcdHHQxw EaF376ONJgPFsNo0RJ9i+pJb4ScpsYVjrGVzUUVWVHQqycyW9EwB+oJScCLHg8d+UPHzOk rICI4ymhR4Isaxz+2JTlwFsVnMb/8T8= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id D7B56ACD8; Mon, 26 Oct 2020 16:45:55 +0000 (UTC) Date: Mon, 26 Oct 2020 17:45:55 +0100 From: Petr Mladek To: Tejun Heo Cc: qiang.zhang@windriver.com, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH] kthread_worker: re-set CPU affinities if CPU come online Message-ID: <20201026164555.GA7544@alley> References: <20201026065213.30477-1-qiang.zhang@windriver.com> <20201026135011.GC73258@mtj.duckdns.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201026135011.GC73258@mtj.duckdns.org> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon 2020-10-26 09:50:11, Tejun Heo wrote: > On Mon, Oct 26, 2020 at 02:52:13PM +0800, qiang.zhang@windriver.com wrote: > > @@ -737,8 +741,11 @@ __kthread_create_worker(int cpu, unsigned int flags, > > if (IS_ERR(task)) > > goto fail_task; > > > > - if (cpu >= 0) > > + if (cpu >= 0) { > > kthread_bind(task, cpu); > > + worker->bind_cpu = cpu; > > + cpuhp_state_add_instance_nocalls(kworker_online, &worker->cpuhp_node); > > + } > > > > worker->flags = flags; > > worker->task = task; > ... > > +static int kworker_cpu_online(unsigned int cpu, struct hlist_node *node) > > +{ > > + struct kthread_worker *worker = hlist_entry(node, struct kthread_worker, cpuhp_node); > > + struct task_struct *task = worker->task; > > + > > + if (cpu == worker->bind_cpu) > > + WARN_ON_ONCE(set_cpus_allowed_ptr(task, cpumask_of(cpu)) < 0); > > + return 0; > > +} > > I don't think this works. The kthread may have changed its binding while > running using set_cpus_allowed_ptr() as you're doing above. Besides, when a > cpu goes offline, the bound kthread can fall back to other cpus but its cpu > mask isn't cleared, is it? If I get it correctly, select_fallback_rq() calls do_set_cpus_allowed() explicitly or in cpuset_cpus_allowed_fallback(). It seems that the original mask gets lost. It would make sense to assume that kthread_worker API will take care of the affinity when it was set by kthread_create_worker_on_cpu(). But is it safe to assume that the work can be safely proceed also on another CPU? We should probably add a warning into kthread_worker_fn() when it detects wrong CPU. BTW: kthread_create_worker_on_cpu() is currently used only by start_power_clamp_worker(). And it has its own CPU hotplug handling. The kthreads are stopped and started again in powerclamp_cpu_predown() and powerclamp_cpu_online(). I havn't checked all details yet. But in principle, the patch looks sane to me. Best Regards, Petr