From patchwork Thu Mar 15 17:08:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zubin Mithra X-Patchwork-Id: 10285389 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 875C060386 for ; Thu, 15 Mar 2018 17:28:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 764C528B82 for ; Thu, 15 Mar 2018 17:28:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 69DE628BA3; Thu, 15 Mar 2018 17:28:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D745728B82 for ; Thu, 15 Mar 2018 17:28:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=DAAcvM3E5bqoh7DH8FMXpNY+lJ3LydydAFJ7FxXHl40=; b=h3sm+q2dyans0ltVE273BQxIpY ngkFsJvHFcX6gLIW8urhZJOHfMF9YhcLLUb8M+d9HGkVF6XISFIC+uXSnqpHJwSrYClt7x3P7IblN WAXcSJkiQEmXHggN33jlEvV0f3R5/U62aF8Ho9k3h+NDMMiMu972JbKC8vn51OPMZ5C/UrgHV9F0x jRqXEXkIIf6ehAYATe/0fh6Ce6TeQk2TQusZXPmGNkDZC6WM9LJWrze16VzW+Vf3f0cmSEqgrVtzH yIlatZPmP61uIkpN6P/OXTYiun6+MNtfyD4TwS9yMzpJD7/ffYXIUd+kvQEpNh8IMmLeTpuN+6nnE mPXoLDXA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1ewWg4-0001pw-Pv; Thu, 15 Mar 2018 17:28:32 +0000 Received: from casper.infradead.org ([85.118.1.10]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1ewWc0-00063p-8T for linux-arm-kernel@bombadil.infradead.org; Thu, 15 Mar 2018 17:24:20 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=/g58cPSmhSmUcuFwyHPxHn4BtkpHE0PXxl2C66VdeQM=; b=EhCFRpBaqaMD+kJZoat6qcyMf qwMau5LsY3tQ4J63m7/rAMBYNFWwOLyEh8rPM33ET88PGrhUBx5+LjXqg64WY3g842vFK8vjCd8sC MNlxCiPARwLWUOYEpGfD1TVOMhA9y0CjNulIGIi0DU3EM/aiTV9ZyZMtOYFl5mYVDWvgf2A8YWaTz efDccXONW8UVNkGxdlWsZV2dPn/LZpfZ8jNIsFcVxLkP30tJr1WPMOQpCK/CJQHYV/k6hCmoVjjqD RG6bYmSW8Mzp9bP1TvP+ADfqWM+/6DSJf3c9z4zSurP5GLaMerKBSPXheSTG7BJtA4y8M5IKjIQxe n9ioLo7uw==; Received: from mail-wr0-x242.google.com ([2a00:1450:400c:c0c::242]) by casper.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1ewWNz-0005TS-3J for linux-arm-kernel@lists.infradead.org; Thu, 15 Mar 2018 17:09:52 +0000 Received: by mail-wr0-x242.google.com with SMTP id l8so9071245wrg.5 for ; Thu, 15 Mar 2018 10:09:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=/g58cPSmhSmUcuFwyHPxHn4BtkpHE0PXxl2C66VdeQM=; b=jadu+9OflrwUcU5rWqzi8iT5DVy4k3UTBi4IzulTBlGUpI+QKAIhTVATa2CWeSqePt 6LY/1LBH6WDln6JixGTMRcSxMLFRezIeOyjtHyNGjlfeQkAJS551VNXQgvE+kjmgNGRy es6RmTx8itLlmRicG5nrWk8PTX0DblrIpuLf8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=/g58cPSmhSmUcuFwyHPxHn4BtkpHE0PXxl2C66VdeQM=; b=t0lmz9jKrAj36PzNl1VFu0WSEalb8nTHZbUY8RUJa+XKQZY3VMhLc5HR3kGgZlh6wS er0l5bga4fpdDqb6jqZkqoFWOWi1XDIv/khiOxGOnRpAMofm1tEnU9kPT7eZZNcZO5St PMIw1fH01ABsUoBzYnKywFhYBeuqbbkgm5inyPeqALLsP1kfiRK08K3BaFdm+Tm0wmBu u+kdi2irN4V57ghLyNGuhzJrpoPIxqGpmYf23uCRWKFxHVfxSlzY8e1rhD0feDbfysUT xvY7BGlL0YleooFL0vI7JRYFmg/XfiMJXKV5esuKYoabr204Wlk1on4B6v6uwAjFeI+5 42Zw== X-Gm-Message-State: AElRT7GoO6qbh2YnSdsZz0CmmFkSISzjsyW9asc5orBqDfMULU2odhSK Ya5SEE4VjaaplAuRFGLcJUrflMlI44g= X-Google-Smtp-Source: AG47ELtpAvEhJLIB5mWVVth+GcGz+TRFz6eJsFH3OiZQsSOTlJsXGTeEEdhBS+w2gQTNisusKSaNhQ== X-Received: by 10.223.169.215 with SMTP id b81mr7018900wrd.48.1521133779586; Thu, 15 Mar 2018 10:09:39 -0700 (PDT) Received: from zsm1.lan (host-2-98-223-64.as13285.net. [2.98.223.64]) by smtp.googlemail.com with ESMTPSA id j21sm7273460wrb.49.2018.03.15.10.09.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Mar 2018 10:09:38 -0700 (PDT) From: Zubin Mithra To: linux-arm-kernel@lists.infradead.org Subject: [RFC 2/3] arm: make cpu a percpu variable Date: Thu, 15 Mar 2018 17:08:58 +0000 Message-Id: <20180315170859.93893-3-zsm@chromium.org> X-Mailer: git-send-email 2.16.2.804.g6dcf76e118-goog In-Reply-To: <20180315170859.93893-1-zsm@chromium.org> References: <20180315170859.93893-1-zsm@chromium.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180315_170951_128974_A7919DAD X-CRM114-Status: GOOD ( 18.25 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, keescook@chromium.org, Zubin Mithra , ard.biesheuvel@linaro.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Without CONFIG_THREAD_INFO_IN_TASK, core code maintains thread_info::cpu and arch specific code can use this to build raw_smp_processor_id(). With CONFIG_THREAD_INFO_IN_TASK, core code maintains task_struct::cpu, and arch specific code cannot access this due to header file circular dependency. Instead, we can maintain a percpu variable containing the cpu number. This also means that cpu numbers obtained using smp_processor_id cannot be used to set_my_cpu_offset. Use task_cpu(current) instead to get the cpu in those cases. Earlier raw_smp_processor_id() was current_thread_info()->cpu :- mov r3, sp bic r3, r3, #8128 bic r3, r3, #63 ldr r0, [r3, #16] Now it is *raw_cpu_ptr(&cpu_number) :- movw r3, #57344 movt r3, #32917 mrc 15, 0, r0, cr13, cr0, {4} ldr r0, [r3, r0] Signed-off-by: Zubin Mithra --- arch/arm/include/asm/cputype.h | 3 +++ arch/arm/include/asm/smp.h | 3 ++- arch/arm/kernel/setup.c | 2 +- arch/arm/kernel/smp.c | 5 +++-- arch/arm/kernel/topology.c | 5 +++++ 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/arch/arm/include/asm/cputype.h b/arch/arm/include/asm/cputype.h index cb546425da8a..10148c7af12f 100644 --- a/arch/arm/include/asm/cputype.h +++ b/arch/arm/include/asm/cputype.h @@ -2,6 +2,9 @@ #ifndef __ASM_ARM_CPUTYPE_H #define __ASM_ARM_CPUTYPE_H +#include +DECLARE_PER_CPU(int, cpu_number); + #include #include diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h index 709a55989cb0..7e7b198174d6 100644 --- a/arch/arm/include/asm/smp.h +++ b/arch/arm/include/asm/smp.h @@ -18,7 +18,8 @@ # error " included in non-SMP build" #endif -#define raw_smp_processor_id() (current_thread_info()->cpu) +#include +#define raw_smp_processor_id() (*raw_cpu_ptr(&cpu_number)) struct seq_file; diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c index fc40a2b40595..6323b4d80306 100644 --- a/arch/arm/kernel/setup.c +++ b/arch/arm/kernel/setup.c @@ -521,7 +521,7 @@ static void __init elf_hwcap_fixup(void) void notrace cpu_init(void) { #ifndef CONFIG_CPU_V7M - unsigned int cpu = smp_processor_id(); + unsigned int cpu = task_cpu(current); struct stack *stk = &stacks[cpu]; if (cpu >= NR_CPUS) { diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c index 2da087926ebe..9584a52eb156 100644 --- a/arch/arm/kernel/smp.c +++ b/arch/arm/kernel/smp.c @@ -372,7 +372,8 @@ asmlinkage void secondary_start_kernel(void) * All kernel threads share the same mm context; grab a * reference and switch to it. */ - cpu = smp_processor_id(); + cpu = task_cpu(current); + set_my_cpu_offset(per_cpu_offset(cpu)); mmgrab(mm); current->active_mm = mm; cpumask_set_cpu(cpu, mm_cpumask(mm)); @@ -436,7 +437,7 @@ void __init smp_cpus_done(unsigned int max_cpus) void __init smp_prepare_boot_cpu(void) { - set_my_cpu_offset(per_cpu_offset(smp_processor_id())); + set_my_cpu_offset(per_cpu_offset(task_cpu(current))); } void __init smp_prepare_cpus(unsigned int max_cpus) diff --git a/arch/arm/kernel/topology.c b/arch/arm/kernel/topology.c index 24ac3cab411d..34b2136deab6 100644 --- a/arch/arm/kernel/topology.c +++ b/arch/arm/kernel/topology.c @@ -30,6 +30,9 @@ #include #include +DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number); +EXPORT_PER_CPU_SYMBOL(cpu_number); + /* * cpu capacity scale management */ @@ -310,6 +313,8 @@ void __init init_cpu_topology(void) for_each_possible_cpu(cpu) { struct cputopo_arm *cpu_topo = &(cpu_topology[cpu]); + per_cpu(cpu_number, cpu) = cpu; + cpu_topo->thread_id = -1; cpu_topo->core_id = -1; cpu_topo->socket_id = -1;