From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B6463C12002 for ; Wed, 21 Jul 2021 06:59:17 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0A76461029 for ; Wed, 21 Jul 2021 06:59:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0A76461029 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4GV5zR3crGz3bgT for ; Wed, 21 Jul 2021 16:59:15 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=casper.20170209 header.b=t3hopBQT; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=casper.srs.infradead.org (client-ip=2001:8b0:10b:1236::1; helo=casper.infradead.org; envelope-from=batv+75be22767c7c0793244e+6541+infradead.org+hch@casper.srs.infradead.org; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=casper.20170209 header.b=t3hopBQT; dkim-atps=neutral Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4GV5yy2CQdz2yMT for ; Wed, 21 Jul 2021 16:58:50 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=2Tg6rDmREVX1ceiTKGgiYnKUFpoX6FiU/JNm2fWqBkw=; b=t3hopBQTUruM/ENRFxNyEOoUC+ 5oJEQnciSH7H7I8MBiuNHyNhq7XNi/0H9lWN4pG4JSoChs5UkzgXC23DuhuRBWouYCC04xOkyZ1xV rR+ywDmkEKE0nnaaZ5dg8qfF0i8IuE7hW6GwCxdzrrEd18zJIIHurdno+HOqRNXejciU760Nh3WQx 3AOh2nuu5mW+eF0HaQSNswWOgds534d05ahBQ3vI0rR4UkVwl5iObPL+K+tNrdsch3TtjxYoxhGnS hW5Qq+sSJ88nW4YhTG3gLQZhM3cY/AdifCtrpRz3dSoygFIOUXVfb1SJ8YEApxUrgC5VPetggN9c3 7B06dTQQ==; Received: from hch by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1m66BG-008tyJ-Id; Wed, 21 Jul 2021 06:58:13 +0000 Date: Wed, 21 Jul 2021 07:58:10 +0100 From: Christoph Hellwig To: Anson Jacob Subject: Re: [RFC v2 1/2] ppc/fpu: Add generic FPU api similar to x86 Message-ID: References: <20210721044801.840501-1-Anson.Jacob@amd.com> <20210721044801.840501-2-Anson.Jacob@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210721044801.840501-2-Anson.Jacob@amd.com> X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Bhawanpreet.Lakha@amd.com, Harry Wentland , Sunpeng.Li@amd.com, qingqing.zhuo@amd.com, Rodrigo.Siqueira@amd.com, linux-kernel@vger.kernel.org, amd-gfx@lists.freedesktop.org, roman.li@amd.com, Christoph Hellwig , Aurabindo.Pillai@amd.com, paulus@samba.org, linuxppc-dev@lists.ozlabs.org, Christian K??nig , bindu.r@amd.com Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" > + > +/* > + * Use kernel_fpu_begin/end() if you intend to use FPU in kernel context. It > + * disables preemption so be careful if you intend to use it for long periods > + * of time. > + * TODO: If you intend to use the FPU in irq/softirq you need to check first with > + * irq_fpu_usable() if it is possible. Please avoid the overly lone lines comments. > +extern bool kernel_fpu_enabled(void); > +extern void kernel_fpu_begin(void); > +extern void kernel_fpu_end(void); No need for the externs. > +/* > + * Track whether the kernel is using the FPU state > + * currently. This all fits on a single line. > +static bool fpu_support(void) > +{ > + if (cpu_has_feature(CPU_FTR_VSX_COMP)) { > + return true; > + } else if (cpu_has_feature(CPU_FTR_ALTIVEC_COMP)) { > + return true; > + } else if (!cpu_has_feature(CPU_FTR_FPU_UNAVAILABLE)) { > + return true; > + } No need for the braces, or else after a return. In fact this could be simplified down to: return cpu_has_feature(CPU_FTR_VSX_COMP) || cpu_has_feature(CPU_FTR_ALTIVEC_COMP) || cpu_has_feature(CPU_FTR_FPU_UNAVAILABLE)); > + preempt_disable(); > + > +#ifdef CONFIG_VSX > + if (cpu_has_feature(CPU_FTR_VSX_COMP)) { > + enable_kernel_vsx(); > + return; > + } > +#endif > + > +#ifdef CONFIG_ALTIVEC > + if (cpu_has_feature(CPU_FTR_ALTIVEC_COMP)) { > + enable_kernel_altivec(); > + return; > + } > +#endif > + > +#ifdef CONFIG_PPC_FPU > + if (!cpu_has_feature(CPU_FTR_FPU_UNAVAILABLE)) { > + enable_kernel_fp(); > + return; > + } > +#endif All the features are defined away if not supported (and we already rely on that in fpu_support()). So this could become: if (cpu_has_feature(CPU_FTR_VSX_COMP)) enable_kernel_vsx(); else if (cpu_has_feature(CPU_FTR_ALTIVEC_COMP)) enable_kernel_altivec(); else if (!cpu_has_feature(CPU_FTR_FPU_UNAVAILABLE)) enable_kernel_fp(); Same for the disable path.