Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp4266314rwb; Mon, 21 Nov 2022 05:50:25 -0800 (PST) X-Google-Smtp-Source: AA0mqf6ORZ2O4jVzI6S2zj/ZeZ8s+emM4vyYBXHR+YqEEQtD61WdWWYHrKu2r3xqHb+l0GBPhx9f X-Received: by 2002:a17:906:28cd:b0:7a5:a671:8236 with SMTP id p13-20020a17090628cd00b007a5a6718236mr1923122ejd.187.1669038625633; Mon, 21 Nov 2022 05:50:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669038625; cv=none; d=google.com; s=arc-20160816; b=inbLe0p+eQo0/1OQXaaLdaRH6l0RUYRKCcf+yKwZOBr3IwogpnQx0ocF/dEdXbB2Zh U/LYwxpFO3Yb/F4iJxbXe0EZDH3T/KNg4AzMvztD07JZczsu1+NrCejmFczXDaxNeNpX JtrQ1vDW5YkQAeohNVz/O2B57dLIyIdoAVRehDpB3tf39adqMtQy4B62BR4GWLmf3qV8 QB1SE2jyNvWI4mGkSdV8PK2cjgyS5KI6QzUSLHhYw6jKHlxE6n9MpxulCsMicB4NgtJT vECHiMT+lNedrjGTlEapd+Z/b50wN2v+ZxyCYqbvLxLlaXiImjpn2oIzKm0cQ6cqVc/H TlLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:subject:user-agent:mime-version:date:message-id; bh=h2hcgimmHhQ/4PWepqxK2RV7pmOY7B6C1gAQH+wFSHM=; b=QJe7KoKmCdECM2R9A7OsNY8d0HGBhKdQ+w1o/Lb+MYs1wNRBw/hGaSurEpBRUfyboD 1CgNy2s2vQGLBugeDgjthQq8Zf+XzwIHLyzhDxQ7dlmOSoUT3EU7hWuTZR4MCnKhP2KL vQ0DlK1yjm9d+nQBKRAxT9Cf5YQM0I1l3rfXlsStJXHrqv1hkIm2ZA8HJQLUgnKIhitU c18vrXiN3Zr5R54OBNvSTt8VK9nqFf9C0pEcW6C02GQW/RyMI66nLl2uAYV6zDq5ywvk hvjewWf0tjXdGuusd06cp+V35JcsL+RGI32IpxnJH7eNGVQ48sa9TFI8Acq2/rpUtyFI 4daw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id rq4-20020a17090788c400b0077945c44b7fsi8815032ejc.856.2022.11.21.05.50.02; Mon, 21 Nov 2022 05:50:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231131AbiKUNjb (ORCPT + 91 others); Mon, 21 Nov 2022 08:39:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231367AbiKUNjF (ORCPT ); Mon, 21 Nov 2022 08:39:05 -0500 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 184F6636C; Mon, 21 Nov 2022 05:38:22 -0800 (PST) Received: from dggpemm500023.china.huawei.com (unknown [172.30.72.53]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4NG7fq46ZczFqPg; Mon, 21 Nov 2022 21:34:59 +0800 (CST) Received: from dggpemm500001.china.huawei.com (7.185.36.107) by dggpemm500023.china.huawei.com (7.185.36.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 21 Nov 2022 21:38:13 +0800 Received: from [10.67.111.195] (10.67.111.195) by dggpemm500001.china.huawei.com (7.185.36.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 21 Nov 2022 21:38:13 +0800 Message-ID: Date: Mon, 21 Nov 2022 21:38:12 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.3.0 Subject: Re: [PATCH -next] RISC-V: KVM: optimize kvm_arch_hardware_enable() To: Andrew Jones CC: , , , , , , , , References: <20221121003915.2817102-1-chenlifu@huawei.com> <20221121105333.rap67cpmst3odiid@kamzik> From: chenlifu In-Reply-To: <20221121105333.rap67cpmst3odiid@kamzik> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.67.111.195] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 在 2022/11/21 18:53, Andrew Jones 写道: > On Mon, Nov 21, 2022 at 08:39:15AM +0800, Chen Lifu wrote: >> The values of CSR_HEDELEG and CSR_HIDELEG registers are constants, >> so change them from variables to macros. >> >> Signed-off-by: Chen Lifu >> --- >> arch/riscv/kvm/main.c | 31 +++++++++++++------------------ >> 1 file changed, 13 insertions(+), 18 deletions(-) >> >> diff --git a/arch/riscv/kvm/main.c b/arch/riscv/kvm/main.c >> index df2d8716851f..70196b03b6f9 100644 >> --- a/arch/riscv/kvm/main.c >> +++ b/arch/riscv/kvm/main.c >> @@ -12,10 +12,21 @@ >> #include >> #include >> #include >> #include >> >> +#define EXC_HEDELEG ((1UL << EXC_INST_MISALIGNED) | \ >> + (1UL << EXC_BREAKPOINT) | \ >> + (1UL << EXC_SYSCALL) | \ >> + (1UL << EXC_INST_PAGE_FAULT) | \ >> + (1UL << EXC_LOAD_PAGE_FAULT) | \ >> + (1UL << EXC_STORE_PAGE_FAULT)) >> + >> +#define IRQ_HIDELEG ((1UL << IRQ_VS_SOFT) | \ >> + (1UL << IRQ_VS_TIMER) | \ >> + (1UL << IRQ_VS_EXT)) >> + >> long kvm_arch_dev_ioctl(struct file *filp, >> unsigned int ioctl, unsigned long arg) >> { >> return -EINVAL; >> } >> @@ -30,29 +41,13 @@ int kvm_arch_hardware_setup(void *opaque) >> return 0; >> } >> >> int kvm_arch_hardware_enable(void) >> { >> - unsigned long hideleg, hedeleg; >> - >> - hedeleg = 0; >> - hedeleg |= (1UL << EXC_INST_MISALIGNED); >> - hedeleg |= (1UL << EXC_BREAKPOINT); >> - hedeleg |= (1UL << EXC_SYSCALL); >> - hedeleg |= (1UL << EXC_INST_PAGE_FAULT); >> - hedeleg |= (1UL << EXC_LOAD_PAGE_FAULT); >> - hedeleg |= (1UL << EXC_STORE_PAGE_FAULT); >> - csr_write(CSR_HEDELEG, hedeleg); >> - >> - hideleg = 0; >> - hideleg |= (1UL << IRQ_VS_SOFT); >> - hideleg |= (1UL << IRQ_VS_TIMER); >> - hideleg |= (1UL << IRQ_VS_EXT); >> - csr_write(CSR_HIDELEG, hideleg); >> - >> + csr_write(CSR_HEDELEG, EXC_HEDELEG); >> + csr_write(CSR_HIDELEG, IRQ_HIDELEG); >> csr_write(CSR_HCOUNTEREN, -1UL); >> - >> csr_write(CSR_HVIP, 0); >> >> return 0; >> } >> >> -- >> 2.37.1 >> > > I don't think this optimizes anything. I'm pretty sure the compiler will > load the input to csr_write() in the most efficient way it can, regardless > of using a constant or building the input out of constants. This could > maybe be considered a code cleanup, but, in this case, it's really in the > eye of the beholder. > > Thanks, > drew Thanks drew,you're right. I compared two version arch/riscv/kvm/main.o files, they are same.