From patchwork Mon Jun 18 15:30:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zubin Mithra X-Patchwork-Id: 10472123 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 E79196029B for ; Mon, 18 Jun 2018 15:37:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D6B72289DD for ; Mon, 18 Jun 2018 15:37:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CAF4E28B06; Mon, 18 Jun 2018 15:37:19 +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=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI 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 551F228B05 for ; Mon, 18 Jun 2018 15:37:19 +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=qJF4jY2wPzc7JvhQ3KWGdY55Ryh/c7pvMhSwQgVsIF8=; b=nmdybPKPnxLoIjZkpbWpbF/ZPL OwfxOFbSH3eXYetG7IjB9QF9khxG3OXAHCxhHer6Gx0rHVh4m+vo7sbXsIgv0STm2/J1OWqDHQ/0E 58zWbYxYQpPr5ClBT7oSQRYBNcto6CKMSCI6Zg1dN3zncvGxjkG7vSd99tD8f45nnP/P83KNZwrpm jR0edYd0MjmQn48IPR7UdAcQdKch4p3My0L4UJBmdOduWEj+zCM9Z9Qbh6Z7EZiTs7aRIDLAG151H sG8SH9ByAwQk+pUWqloxVnkciyTVBc3h2HgE03h9fqZyElPJGdoAPVHlRbB3C307zdVBKvMKRLY4W W3rgLiyw==; 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 1fUwDK-0004zJ-Ad; Mon, 18 Jun 2018 15:37:06 +0000 Received: from mail-pg0-x241.google.com ([2607:f8b0:400e:c05::241]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fUw7d-0000W8-W0 for linux-arm-kernel@lists.infradead.org; Mon, 18 Jun 2018 15:31:18 +0000 Received: by mail-pg0-x241.google.com with SMTP id d2-v6so7688739pga.13 for ; Mon, 18 Jun 2018 08:31:08 -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=f0ejzv23s8whUCXKekpvVvRJmmC8IfjE2ZqyNaQ/FVA=; b=gv497+40b6nMw+UC58vfimn/JU0xtMHNGZUfOxSHFPhrQQqwYMQ7QJVWrwVqPhz5xI fwKelcZvEUxM29HPAMSsZ5ThVTuHL7FIE/7Q+UN9FmSCdZCb/kPGGROXGK4RhrD6QLGM PBpMKTw9RExpZGcKbS4XFyz7jSx4KfsWRbHGw= 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=f0ejzv23s8whUCXKekpvVvRJmmC8IfjE2ZqyNaQ/FVA=; b=uCVGVccQxJKZG8uj3sSO35N+IOxX/BnlQDqZiyNcJFWDH3lpUCUzE13EwQrXvmwZXv P8q7jjRiN/youG3vv5VnQXBmHuruGr7bMz0tHOOus5zj/vce5EAoHg6yQkMM8OCToRMG row2A7UJgvxvwbFg8q3UpyAhB/XZiwwwxB1CZOGEX00W3sQmkc42n6LmKNI8kLmXu1LK E9cHGmhvGjv1TVHGU2VeMafvSrUF0lBGKhEh+d1G2BXG5dInjjJ4KtSDRdF2oBYvNIMd UMtGCkPFEdcQzL4P7k2L5ZdxO/SXnUSSVd6V/GkegAufq/VAXo3ZE+Wbiw8x9cH7npmE bnYA== X-Gm-Message-State: APt69E3Dq1u9VvbuMyyohaw1GBKh61yCt6sBUYCR4V5NR5J6tm7aF230 uWJqwwhKDwBOrJKC9HxI2GXcSahsCbg= X-Google-Smtp-Source: ADUXVKJdsxgUyK2SGL0sJMo365yAUZCPLJDnQIftdXrFufBlELtp+UpCsfjf+e7TbX/+eyCiQ+au5w== X-Received: by 2002:a62:221a:: with SMTP id i26-v6mr14178521pfi.240.1529335867713; Mon, 18 Jun 2018 08:31:07 -0700 (PDT) Received: from zsm1.corp.google.com ([2620:0:1000:1610:f9fa:7119:2984:84b5]) by smtp.googlemail.com with ESMTPSA id j10-v6sm32138359pfj.158.2018.06.18.08.31.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Jun 2018 08:31:06 -0700 (PDT) From: Zubin Mithra To: linux-arm-kernel@lists.infradead.org, mark.rutland@arm.com, ard.biesheuvel@linaro.org, keescook@google.com, groeck@chromium.org Subject: [RFC v2 3/4] arm: make cpu a percpu variable Date: Mon, 18 Jun 2018 08:30:52 -0700 Message-Id: <20180618153053.186224-4-zsm@chromium.org> X-Mailer: git-send-email 2.18.0.rc1.244.gcf134e6275-goog In-Reply-To: <20180618153053.186224-1-zsm@chromium.org> References: <20180618153053.186224-1-zsm@chromium.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180618_083114_064522_0A19A66F X-CRM114-Status: GOOD ( 16.77 ) 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: zsm@chromium.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. Without any patches in this patchset, raw_smp_processor_id() was :- mov r3, sp bic r3, r3, #8128 bic r3, r3, #63 ldr r0, [r3, #16] When thread_info is stored in sp^ as per the first patch in this series, it becomes :- sub sp, sp, #4 stmia sp, {sp}^ ldr r2, [sp] add sp, sp, #4 ldr r2, [r2, #16] Finally, when cpu is made a percpu variable and fetched using raw_cpu_ptr() :- movw r2, #4096 ; 0x1000 movt r2, #32918 ; 0x8096 mrc 15, 0, r0, cr13, cr0, {4} ldr r2, [r2, r0] Note that once the thread_info is moved off of the stack, the sequence of instructions used to fetch the cpu number would be the third sequence using raw_cpu_ptr(). Signed-off-by: Zubin Mithra --- arch/arm/include/asm/smp.h | 11 ++++++++++- arch/arm/kernel/setup.c | 2 +- arch/arm/kernel/smp.c | 13 +++++++++++-- arch/arm/kernel/topology.c | 2 ++ 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h index 709a55989cb0..cf366dd6e9f1 100644 --- a/arch/arm/include/asm/smp.h +++ b/arch/arm/include/asm/smp.h @@ -10,6 +10,8 @@ #ifndef __ASM_ARM_SMP_H #define __ASM_ARM_SMP_H +#include + #include #include #include @@ -18,7 +20,14 @@ # error " included in non-SMP build" #endif -#define raw_smp_processor_id() (current_thread_info()->cpu) +DECLARE_PER_CPU(int, cpu_number); + +/* + * to avoid implicit writes to preempt_count, compiler barriers in + * preempt_enable_notrace and preempt_disable_notrace, use *raw_cpu_ptr + * instead of this_cpu_read. + */ +#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 35ca494c028c..be3f5603dcac 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 0978282d5fc2..dbb1eabf7912 100644 --- a/arch/arm/kernel/smp.c +++ b/arch/arm/kernel/smp.c @@ -54,6 +54,9 @@ #define CREATE_TRACE_POINTS #include +DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number); +EXPORT_PER_CPU_SYMBOL(cpu_number); + /* * as from 2.5, kernels no longer have an init_tasks structure * so we need some other way of telling a new secondary core @@ -372,7 +375,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)); @@ -439,15 +443,20 @@ 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) { unsigned int ncores = num_possible_cpus(); + unsigned int cpu; init_cpu_topology(); + for_each_possible_cpu(cpu) { + per_cpu(cpu_number, cpu) = cpu; + } + smp_store_cpu_info(smp_processor_id()); /* diff --git a/arch/arm/kernel/topology.c b/arch/arm/kernel/topology.c index 24ac3cab411d..6e05217106ac 100644 --- a/arch/arm/kernel/topology.c +++ b/arch/arm/kernel/topology.c @@ -310,6 +310,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;