Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2495900pxj; Mon, 10 May 2021 04:30:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz6kvkVYAog8z2XgFrkaDlrr+rayG9Pk5KdjDZm7wbLQ3rGlMcct3To/4d0wlgi6gS80hvC X-Received: by 2002:a05:6402:524d:: with SMTP id t13mr28992634edd.209.1620646243716; Mon, 10 May 2021 04:30:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620646243; cv=none; d=google.com; s=arc-20160816; b=XyM7mSRmfbfMqaLZOvWDexMkfuQ2fBrdQcvr5ny1SN2wKBXUJvjUCtL70u8qlAMzug kGkQMiFH5S+HOXARwM6CnPtoG9yu7IzsLOMkBi6Kx46DUz/0ETDODVR2YDNcL/yX7cff d2j6rb1AbRs0hk9Dbj7tWF8MymXEgGwjdZA2WJ5D51VwM8MDL+c8kL5NFmKp2bDUQFdJ 8su+VkBxVafVT4EcSnLWgKNktBA+Lvyj7O5LGA+XRcRo6TZZ6nhH3LHYX6PbWhG8Q6VL Y6Jug8agvO3bnG49HJyVcCxMAFBFva8ypWTsYb4p1i/j82hWmPUcedKhABQzcWv7LgeD 1qDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from; bh=SleWcFFaLip++vJuoRQ/UFNtyzLDQGCzTq1eiPPhsUQ=; b=RTX08C+/AOClu2mbTqts7iZP+VzS3ZTG5Ny4RO7/IJb999R14cH52VFOxBNFMTUalY 8Mu5oDFOTwoY8dAUuq8JGTxGq18DgU07/GgJDkY9zbeOJkEOPXpUGjaLk6IBJ7u2EcPr NBKrxENgrgQp0zYj3Srh5tAzwzKe1gn6bI0hlCtv0ZEUdVR4jI3DndlyzSGFLPKAMLCR Lng/0ifDEyJsm7jEgWdqyh1gLgvFbeCYYQcQO5XX6OpLRgokG6m5C5tblGVOyPpl22kp PWalhBDbPN2gWLkv/gvnlXLM3BFiUfTD3fsjgAdSb6VU3Dz4oe5ro4C/lVu0Vsqg/Pvy bupg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d24si12965237ejd.49.2021.05.10.04.30.20; Mon, 10 May 2021 04:30:43 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238004AbhEJLZj (ORCPT + 99 others); Mon, 10 May 2021 07:25:39 -0400 Received: from foss.arm.com ([217.140.110.172]:54394 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234314AbhEJK4L (ORCPT ); Mon, 10 May 2021 06:56:11 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3ECAC15BE; Mon, 10 May 2021 03:55:06 -0700 (PDT) Received: from e113632-lin (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 56C163F719; Mon, 10 May 2021 03:55:05 -0700 (PDT) From: Valentin Schneider To: Yejune Deng , peterz@infradead.org, tglx@linutronix.de, bristot@redhat.com Cc: linux-kernel@vger.kernel.org, Yejune Deng Subject: Re: [PATCH] lib/smp_processor_id: Use is_percpu_thread() instead of nr_cpus_allowed In-Reply-To: <1620458722-13026-1-git-send-email-yejunedeng@gmail.com> References: <1620458722-13026-1-git-send-email-yejunedeng@gmail.com> Date: Mon, 10 May 2021 11:54:56 +0100 Message-ID: <87pmxyj1tr.mognet@arm.com> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 08/05/21 15:25, Yejune Deng wrote: > Use is_percpu_thread() instead of 'current->nr_cpus_allowed == 1', > is_percpu_thread() is includes boths SMP and SP. It also more readable. > The comments are no needed. > > Signed-off-by: Yejune Deng > --- > lib/smp_processor_id.c | 6 +----- > 1 file changed, 1 insertion(+), 5 deletions(-) > > diff --git a/lib/smp_processor_id.c b/lib/smp_processor_id.c > index 1c1dbd3..046ac62 100644 > --- a/lib/smp_processor_id.c > +++ b/lib/smp_processor_id.c > @@ -19,11 +19,7 @@ unsigned int check_preemption_disabled(const char *what1, const char *what2) > if (irqs_disabled()) > goto out; > > - /* > - * Kernel threads bound to a single CPU can safely use > - * smp_processor_id(): > - */ > - if (current->nr_cpus_allowed == 1) > + if (is_percpu_thread()) > goto out; That's not entirely equivalent as this adds (p->flags & PF_NO_SETAFFINITY) to the condition. Per-CPU kthreads will have it set, so that at least matches the existing comment, but it's not an innocent change. I'm thinking this might actually be something we want, as not having this flag + having preemption enabled means this could race with sched_setaffinity(), and it would be nice to detect this regardless of the current affinity. I ran this on my Juno and the idle thread gets in the way as it only has PF_KTHREAD | PF_IDLE So you'd need something like the below (which is purely for instrumentation / assertion purposes). --- diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 4a0668acd876..2a6fdf3e7061 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -7445,7 +7445,7 @@ void init_idle(struct task_struct *idle, int cpu) idle->state = TASK_RUNNING; idle->se.exec_start = sched_clock(); - idle->flags |= PF_IDLE; + idle->flags |= PF_IDLE | PF_NO_SETAFFINITY; scs_task_reset(idle); kasan_unpoison_task_stack(idle);