Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp1054310lqp; Fri, 22 Mar 2024 04:26:49 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVtGYo2CKnm5rbTFLKslNrPsGfmT24rays6L9SspWvUgA9hF2RqHL9hgONPnKO4JsTIcRF8AiZnDuS0GTviB/oID4M81dsp4oFth3pkFA== X-Google-Smtp-Source: AGHT+IHX/QL1x58ZYWZR/fV13nuldQtsZSlOegE2QY9mf1DMICQtsikdMrrz81MP7JTGBiSLEFXO X-Received: by 2002:a0d:e307:0:b0:610:f669:b72c with SMTP id m7-20020a0de307000000b00610f669b72cmr1950636ywe.2.1711106809364; Fri, 22 Mar 2024 04:26:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711106809; cv=pass; d=google.com; s=arc-20160816; b=eXAmb1W3Oz1r41obQwG7nu3uE6yX2g83WRUcCxxpcVUzLoOmahz6jRgQ7S+5DoJ81C bh3R5tngzX0BLF1MoKt1IzHqws3DsNkiTuIk528KVJLzQcOc4W4UUUhoKdkXHxKLMZRL AtgtLkHAYC3Ci/ibHkVlcR7b4vHK56b7iVV3TTC+htsqQipKlNhK54oZuQl7gJMu29Eb jkMx4Z9sm2E/T2f7cjMUjOKKRa29h4elL+CZIaMfKIBbiSeiN+W24ThEuBcdjQPRIGtN nBWGfpvQhu8WPfGjm2oaRJtTJlAme56oRt/1EiRHt7fyEYp+hErpk0kDDhiquEYa8hsg fblQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=XNHkQfXINaqTHPg7WbnoP37edMIj0CzWXuWpl1CeMi4=; fh=K3XmlNSgtOJMuXdH73tTZmV8W9kf1teW2fEY8RFztXs=; b=ZWQyev483/0akARqMMqCTlK26h+jsyXu/NXACDCCxY3GBIzS4Mrv+t2D4myseNOgpc AOuh/E9kP6ref/P7dYmlYgfLnZOlDILTW9buinJSEgc9TMDPHeRXtcQSGhY1P8VjsWam 94SEPG4gV3MOA/PPyFiqs5rUFtY7vjaV2FFKT/T4bGNOqMwzwQhV7HO/LBYcaIJbZisO z3Ue+BaLJhxxVGu8aYJrxCe0QUZkDlQN/w7FovGl2+Nu0Bb8w/EjteAJ1ZVBTTsud8nn HkzLhoCYnpN2VSrYjP03CM6/ozcaCJ+E5hKCKTEiuB/6zMmeDO2Th0mXPqKkNFFL6d0n OqTQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b="uAM/RFbB"; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-111364-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-111364-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id g9-20020a05620a218900b00789edd5d29csi1802659qka.571.2024.03.22.04.26.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 04:26:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-111364-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b="uAM/RFbB"; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-111364-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-111364-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 1F12D1C21BE4 for ; Fri, 22 Mar 2024 11:26:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 440B23F8C0; Fri, 22 Mar 2024 11:26:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="uAM/RFbB" Received: from mail-lf1-f50.google.com (mail-lf1-f50.google.com [209.85.167.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B7E44224F2 for ; Fri, 22 Mar 2024 11:26:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711106796; cv=none; b=Rl+6zBpk9MNmH/oe7YpR5ZBFGPHo+4NnAr8WWbnjsuxfXwp0FYL1OYfyZVncvXnNt7/zRV30T34k1dRGg1TrvIbCI2/FsuGPaEQ/h/zh9nM4wYjenVnd2gGcnacodMeRFsql/EKzOe6mbCYQpVWxTiJ/J4+2iI5hUFDLU8C10cA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711106796; c=relaxed/simple; bh=IlHTDSMEWpoOg/OvTtf8nCD2S7XZ5hN8s2L8Abe+sXY=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=NrkJ6BanUFpjGqMoXoj/T+p6rCmGeupEF1GbgkmHoG/p7rm2jszmPdUnguSLXV7oGgnuQFCxELnFbc1i+1nu9Gkp6APt24t2dQNQne0v7FQ9jhzM0rygY8t6fs9gW178jSN61XYRMceycNDjV8VS1WFJ1yxUPjeRKT41WGDg7bo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=uAM/RFbB; arc=none smtp.client-ip=209.85.167.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-lf1-f50.google.com with SMTP id 2adb3069b0e04-513e14b2bd9so2413233e87.2 for ; Fri, 22 Mar 2024 04:26:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1711106792; x=1711711592; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=XNHkQfXINaqTHPg7WbnoP37edMIj0CzWXuWpl1CeMi4=; b=uAM/RFbBeE9jP6iuUnDYK37fr0kd+2e5B0B3CZVI2gC+k4zErPjF7TfMxw4kBRbD6F 6tbI2dGP8nFfwbI3smIoU9l7yS9tlHTLu8VZky/AAylUy8YajRM8/Lp9uR6ZFzSNm88Q AbBUUpOPHNk6Ob2z6GS8kjUgjijMxoo4FLIaF6ITNEqLXbL52T5W6pfvOmq7bpg6L5pB yu4mVzDOGu7zFNGbNtK/uwtXZQ1f1ebcWwZgOiQq1U9GPCIfDoYTVEyKztSShdOgBCyu vdPhsmxEcxeZ8q5j7nT03ISMTSfAGcpA7tS+bTCrB4+3pws5CAymyHEWNelAojOB6jD2 hiNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711106792; x=1711711592; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=XNHkQfXINaqTHPg7WbnoP37edMIj0CzWXuWpl1CeMi4=; b=JOgfpbtUxfVbZJUCy5Lf5VI/ENyIeO+w8iLYU55oRKilQSGzDZJ50gHo+da2V0ff6Z x4U1OJuAFqYMZnFbahpE5dCxfeRK85LTMUU+qmSEFpsu7E387VCVujERCHdHqSl0mP3v U3gtj/NIzQA4EhNZT5mcFcj87UiLhROhMp6qcziZi+ye+KITjFulxP5Ah8BRAN6L1iRG fBgDtSXnbMgWZ9EyGRT4nPlBr/quJ3v+MAGQ4a9DS6buQwUTPYZx7ANM8j2ydXbgtkzT OZT7RfAfiyslVIjEKbCWm4htOIsSnyME+lw+AMSPQ2pPw08JMmyvEKKNtoe5N0geKEhg n8rA== X-Forwarded-Encrypted: i=1; AJvYcCX6HObFMnQG3sIwp95c5lMCylVq5tRWFG/HvOSwnoC7ah/y49MrW3m/aeh3NeI1vj3X9HJpVrcezpMPquoovZBVqcbb8rEh5WlRP5FL X-Gm-Message-State: AOJu0YzG3rIUfM1OxdXiwTyhykSwudSgdhDPfy0pMoD1R3pXswnICs4v MYUNshVQuJHTeCZ2+Lskel9N6zw7LeyXc/TQJL7EoTnq6W7ay1tr2zPAMSmYwvk= X-Received: by 2002:a19:6910:0:b0:513:2992:bd92 with SMTP id e16-20020a196910000000b005132992bd92mr1311861lfc.11.1711106791828; Fri, 22 Mar 2024 04:26:31 -0700 (PDT) Received: from alex-rivos.ba.rivosinc.com (amontpellier-656-1-456-62.w92-145.abo.wanadoo.fr. [92.145.124.62]) by smtp.gmail.com with ESMTPSA id q12-20020a19430c000000b00513d82a8003sm317965lfa.160.2024.03.22.04.26.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 04:26:31 -0700 (PDT) From: Alexandre Ghiti To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Samuel Holland , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Alexandre Ghiti Subject: [PATCH] riscv: Improve sbi_ecall() code generation by reordering arguments Date: Fri, 22 Mar 2024 12:26:29 +0100 Message-Id: <20240322112629.68170-1-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.39.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The sbi_ecall() function arguments are not in the same order as the ecall arguments, so we end up re-ordering the registers before the ecall which is useless and costly. So simply reorder the arguments in the same way as expected by ecall. Instead of reordering directly the arguments of sbi_ecall(), use a proxy macro since the current ordering is more natural. Before: Dump of assembler code for function sbi_ecall: 0xffffffff800085e0 <+0>: add sp,sp,-32 0xffffffff800085e2 <+2>: sd s0,24(sp) 0xffffffff800085e4 <+4>: mv t1,a0 0xffffffff800085e6 <+6>: add s0,sp,32 0xffffffff800085e8 <+8>: mv t3,a1 0xffffffff800085ea <+10>: mv a0,a2 0xffffffff800085ec <+12>: mv a1,a3 0xffffffff800085ee <+14>: mv a2,a4 0xffffffff800085f0 <+16>: mv a3,a5 0xffffffff800085f2 <+18>: mv a4,a6 0xffffffff800085f4 <+20>: mv a5,a7 0xffffffff800085f6 <+22>: mv a6,t3 0xffffffff800085f8 <+24>: mv a7,t1 0xffffffff800085fa <+26>: ecall 0xffffffff800085fe <+30>: ld s0,24(sp) 0xffffffff80008600 <+32>: add sp,sp,32 0xffffffff80008602 <+34>: ret After: Dump of assembler code for function __sbi_ecall: 0xffffffff8000b6b2 <+0>: add sp,sp,-32 0xffffffff8000b6b4 <+2>: sd s0,24(sp) 0xffffffff8000b6b6 <+4>: add s0,sp,32 0xffffffff8000b6b8 <+6>: ecall 0xffffffff8000b6bc <+10>: ld s0,24(sp) 0xffffffff8000b6be <+12>: add sp,sp,32 0xffffffff8000b6c0 <+14>: ret Signed-off-by: Alexandre Ghiti --- arch/riscv/include/asm/sbi.h | 10 ++++++---- arch/riscv/kernel/sbi.c | 10 +++++----- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h index 6e68f8dff76b..9041b009d3b5 100644 --- a/arch/riscv/include/asm/sbi.h +++ b/arch/riscv/include/asm/sbi.h @@ -292,10 +292,12 @@ struct sbiret { }; void sbi_init(void); -struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0, - unsigned long arg1, unsigned long arg2, - unsigned long arg3, unsigned long arg4, - unsigned long arg5); +struct sbiret __sbi_ecall(unsigned long arg0, unsigned long arg1, + unsigned long arg2, unsigned long arg3, + unsigned long arg4, unsigned long arg5, + int fid, int ext); +#define sbi_ecall(e, f, a0, a1, a2, a3, a4, a5) \ + __sbi_ecall(a0, a1, a2, a3, a4, a5, f, e) #ifdef CONFIG_RISCV_SBI_V01 void sbi_console_putchar(int ch); diff --git a/arch/riscv/kernel/sbi.c b/arch/riscv/kernel/sbi.c index e66e0999a800..5719fa03c3d1 100644 --- a/arch/riscv/kernel/sbi.c +++ b/arch/riscv/kernel/sbi.c @@ -24,10 +24,10 @@ static int (*__sbi_rfence)(int fid, const struct cpumask *cpu_mask, unsigned long start, unsigned long size, unsigned long arg4, unsigned long arg5) __ro_after_init; -struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0, - unsigned long arg1, unsigned long arg2, - unsigned long arg3, unsigned long arg4, - unsigned long arg5) +struct sbiret __sbi_ecall(unsigned long arg0, unsigned long arg1, + unsigned long arg2, unsigned long arg3, + unsigned long arg4, unsigned long arg5, + int fid, int ext) { struct sbiret ret; @@ -48,7 +48,7 @@ struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0, return ret; } -EXPORT_SYMBOL(sbi_ecall); +EXPORT_SYMBOL(__sbi_ecall); int sbi_err_map_linux_errno(int err) { -- 2.39.2