From patchwork Wed Aug 19 12:13:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 247959 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:522:0:0:0:0 with SMTP id h2csp404601ils; Wed, 19 Aug 2020 05:14:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwe07xzttOPnxS177CvBEwCxmzWT+KARIjTPd0OcjGtkiAElT7j7qbNGoV2+TX3pHqcpGP6 X-Received: by 2002:a50:c38b:: with SMTP id h11mr24547657edf.308.1597839252793; Wed, 19 Aug 2020 05:14:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597839252; cv=none; d=google.com; s=arc-20160816; b=QZYiNH2zmWuo5Eti/RpmvAPnu81kuGvzEYQ+6fI2A1Pd6N2Fogzb2jy3Z2QL62Tn3o +TxAcMwBK+zzI2D9bpiQGqzVO5fuHMvBRWGxXIyGPKF+sFYhNrBV0y1SfpppjhJg31YU e8DKMyZJUdpXIM0I+LnfFxtcXh2V197LysR2L/lwmyL84UMVHPSZTmIK+kZ1q9rTOTNW HlM82H8X7AYX4V+mae8QCZpQg/TD0D9pkLUwVCbynb3uiYtpKLG4l83xq0kH8QYAT3yO 0SxMj8RD6IgQ0JQMi2/hH457iHCeCZog+02OvGd7P9Lt5LuBK/rddcl5KJ/LSB7ScJKl KNrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=JRTD0E1USqv27tKpmxT7DLVTgpP9KsLIGpqLmzJk6dc=; b=Bl7K35nZYuN0IiOz3kcDmDpADG/4G1fghoffAaUbQqHW1DygCu8vPjAhhOC1/CAl+B gkoERk0erHF4i5ktloBERl5DGzZusz992XLcf563D6/RB6EWwAgV+xjNj6kYQ3R1mAai 51Wz0AFMerlPztRsRzjF/oS0BVEQoAIuNqawoGOqgjz0Rx/fW8mqLxRcPe36ayBjEt0o mpbXDmGSstmXXfjy+/XnFZVvUXaM5JMdvi7Nlsp1AnTafxUa8n3XsUdgFQSNapz6ZSYQ Haqu0fjmf5mJ42Ds8n9fC5sHtPAdhZhJbi7L42L7/ARNUbbXWC2m8Wm4XMFdy1UPJsDN mQog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=eTeToc67; spf=pass (google.com: domain of linux-kselftest-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kselftest-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b6si16772273eja.559.2020.08.19.05.14.12; Wed, 19 Aug 2020 05:14:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kselftest-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=@kernel.org header.s=default header.b=eTeToc67; spf=pass (google.com: domain of linux-kselftest-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kselftest-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726952AbgHSMOK (ORCPT + 6 others); Wed, 19 Aug 2020 08:14:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:51404 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726752AbgHSMOJ (ORCPT ); Wed, 19 Aug 2020 08:14:09 -0400 Received: from localhost (fw-tnat.cambridge.arm.com [217.140.96.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1B60720738; Wed, 19 Aug 2020 12:14:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597839248; bh=KV4mnGXGCrFRun+EDN9OxgHUnFqbU7ZkJMYyr+CEL94=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eTeToc67nVsh1gRKfuZxYg5Scyvc3Cr2zYdt+z2Q+WGLVMhzFeHmNU1s/qZSPTazs z0aAmBdhWsef0uqrpoauI/XkedNz8KOetq9wjnE7nR9P3ywxWUXJpp6t3Q8rtQ4RDW K/nrRyxQcW6z/jwcN8oXmds0QwkErAfmeo9c4gTI= From: Mark Brown To: Catalin Marinas , Will Deacon Cc: linux-arm-kernel@lists.infradead.org, Vincenzo Frascino , linux-kselftest@vger.kernel.org, Shuah Khan , Mark Brown Subject: [PATCH v3 4/5] arm64: vdso: Add getcpu() implementation Date: Wed, 19 Aug 2020 13:13:17 +0100 Message-Id: <20200819121318.52158-5-broonie@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200819121318.52158-1-broonie@kernel.org> References: <20200819121318.52158-1-broonie@kernel.org> MIME-Version: 1.0 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Some applications, especially trace ones, benefit from avoiding the syscall overhead on getcpu() calls so provide a vDSO implementation of it. Signed-off-by: Mark Brown --- arch/arm64/kernel/vdso/Makefile | 2 +- arch/arm64/kernel/vdso/vdso.lds.S | 1 + arch/arm64/kernel/vdso/vgetcpu.c | 48 +++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 arch/arm64/kernel/vdso/vgetcpu.c -- 2.20.1 diff --git a/arch/arm64/kernel/vdso/Makefile b/arch/arm64/kernel/vdso/Makefile index 88cf0f0b91ed..ff350e69b8b6 100644 --- a/arch/arm64/kernel/vdso/Makefile +++ b/arch/arm64/kernel/vdso/Makefile @@ -11,7 +11,7 @@ ARCH_REL_TYPE_ABS := R_AARCH64_JUMP_SLOT|R_AARCH64_GLOB_DAT|R_AARCH64_ABS64 include $(srctree)/lib/vdso/Makefile -obj-vdso := vgettimeofday.o note.o sigreturn.o +obj-vdso := vgettimeofday.o note.o sigreturn.o vgetcpu.o # Build rules targets := $(obj-vdso) vdso.so vdso.so.dbg diff --git a/arch/arm64/kernel/vdso/vdso.lds.S b/arch/arm64/kernel/vdso/vdso.lds.S index d808ad31e01f..ef3fb80e0349 100644 --- a/arch/arm64/kernel/vdso/vdso.lds.S +++ b/arch/arm64/kernel/vdso/vdso.lds.S @@ -80,6 +80,7 @@ VERSION __kernel_gettimeofday; __kernel_clock_gettime; __kernel_clock_getres; + __kernel_getcpu; local: *; }; } diff --git a/arch/arm64/kernel/vdso/vgetcpu.c b/arch/arm64/kernel/vdso/vgetcpu.c new file mode 100644 index 000000000000..e8972e561e08 --- /dev/null +++ b/arch/arm64/kernel/vdso/vgetcpu.c @@ -0,0 +1,48 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * ARM64 userspace implementations of getcpu() + * + * Copyright (C) 2020 ARM Limited + * + */ + +#include +#include + +struct getcpucache; + +static __always_inline +int getcpu_fallback(unsigned int *_cpu, unsigned int *_node, + struct getcpucache *_c) +{ + register unsigned int *cpu asm("x0") = _cpu; + register unsigned int *node asm("x1") = _node; + register struct getcpucache *c asm("x2") = _c; + register long ret asm ("x0"); + register long nr asm("x8") = __NR_getcpu; + + asm volatile( + " svc #0\n" + : "=r" (ret) + : "r" (cpu), "r" (node), "r" (c), "r" (nr) + : "memory"); + + return ret; +} + +int __kernel_getcpu(unsigned int *cpu, unsigned int *node, + struct getcpucache *c) +{ + struct vdso_cpu_data *cpu_data = __vdso_cpu_data(); + + if (cpu_data) { + if (cpu) + *cpu = cpu_data->cpu; + if (node) + *node = cpu_data->node; + + return 0; + } + + return getcpu_fallback(cpu, node, c); +}