Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp536194pxx; Mon, 26 Oct 2020 14:34:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzQ/KQhoamgvP0wTFNRJuTbnTFuPpnchDGMoqnp1VzYvv1q/plbwDT1BOVs9IIDN2t3cQ2m X-Received: by 2002:a50:c04e:: with SMTP id u14mr17923947edd.134.1603748082437; Mon, 26 Oct 2020 14:34:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603748082; cv=none; d=google.com; s=arc-20160816; b=eGiY59tldzNPMAHA499WMLb3334q1KO5kuJS5C+klGtlAjYERhRYDNLJ4vQjwaH6YR a9EwGW96/w4Wrq8VLUImkZbOCqPgr7ldX/SyVJyHTguHJgpPFFjQxmnMGZnXexI3rTxv EsbmbMs9K/+xUdo5aXUF0JxP/6BILTXMapZnYw93lFlAQhtimkAEUFch5mf2I3URJoDW WlkTdI9G8OhsK1CmhIsVuv0PLIw+8Aq8UYk1yvj8e7HfI74RDQ/4hdlNh8gYnNL+FmyB M6v/XsgAKL0mBF83kH4OFAzTkbzIVw66h+HJtD7Qgt6MnjjtuAoCy+rz5UhW0JXr83K7 tQoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=kChY8deJI75T79lVGPftJ4ey9Ah/Bxr9MOF++yylAmI=; b=kAflSfhlgrmGhpIrUoZvwixJ4tDqPncE4EPtQOPDgQtdct587hZrwgAGP/1EpQv5rl c/Q8igF1p0c/BLu8pkwwTEVaMRTpgl4JFhQEZlUVIzT+eV+1FKCGoHUcB45VLB3earpW /BMbjCzYhxm8I+3a/D/Iz3X0vwAaAgEIWumbPxMpjumPUeuJ/0/0rXwMnMTV5yFIMSyj kbDIoeLdvNCBevO0tDsiwEOBXmB9uydlyOta3UZPgHm6D+uXaRHDkC8fMHSlj012iMUi dK5Gp+AowRt/fnAeoCJHJqGWqWQtM3j27nvuWm4Bh7xNMV7EZZI8aa0btP+2+pCsmbsH zqLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=SruZRHB4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f15si8249261ejr.2.2020.10.26.14.34.20; Mon, 26 Oct 2020 14:34:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=SruZRHB4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1786316AbgJZQqS (ORCPT + 99 others); Mon, 26 Oct 2020 12:46:18 -0400 Received: from mx2.suse.de ([195.135.220.15]:42392 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1780572AbgJZQp5 (ORCPT ); Mon, 26 Oct 2020 12:45:57 -0400 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> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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