Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp5233698pxv; Wed, 21 Jul 2021 00:03:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwIImu3h7QH9JAGL4x0R2NEh+RkjoKAvELfR0/2TJp2BIykajieaZvpdFXZ4Raa/LbKRc00 X-Received: by 2002:a17:906:6811:: with SMTP id k17mr37050617ejr.280.1626851014454; Wed, 21 Jul 2021 00:03:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626851014; cv=none; d=google.com; s=arc-20160816; b=ZtLAcaTKORtqo7kePNzBnpxFn7rfufLHUlyJc4BighTjat2sGp1Ff8RiiXr0cJ9UbD uvDRaoOoU5i0DaeU1CvxVAfHC98V93P/k6214iGsXacOOTEvHzcGtDBJoRgw4C3YBlcp 5w4XY3JiZLj0Z+vm16DMM4DfxaXSnVNaye+k3Gx3KItnJW99o8z7+kQ/PaGIgKqEY0Eo wj1F/JIvKrzuSkY5kLOANMrTBM3FBFMqBdIskL2Dk2BQR/eKjhbO2vTxF8u3X/vO04hr LvkdgjHscG5z1G1o8wcpyvx5v04W1BMAbfX89O/YqSPzy5BdgxT5x6Y9Hx2sqF+/OOsh JVMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=2Tg6rDmREVX1ceiTKGgiYnKUFpoX6FiU/JNm2fWqBkw=; b=oZZ0RUmG9D/ZeI1Y8rmRrP3j1XUjRvs5QB0oCQOq4+tuCWgokwSks2Iz9+ncD76awn ZgRqV4/+ANvcXiLZg6Tw8zWuuokZ7ZGvmGuEI1U+7qObcN3Y+9Iu2Of2Gotjg91GiPoc k1UTwlhiw/uwnCvTgKbEnuht4kfNUiBM6NJXuy6mnIXtnJO19hJROIKWxR1X0K8pkDk3 9pqq74tb31W2BVcmgx4Kr/ySjPRq8Unl0A3h5woVxlS31jVb17oGlKbDwWQ0LNsyoQ4Y g1oZBGaMzwCWHbO54sv3IfDKZq3DGqMt2JCJvQz8VIiGNNpESw3DtRuSy3d8fZPyXj6G H2XQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=t3hopBQT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i8si33334302ejj.636.2021.07.21.00.03.07; Wed, 21 Jul 2021 00:03:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=@infradead.org header.s=casper.20170209 header.b=t3hopBQT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233874AbhGUGU6 (ORCPT + 99 others); Wed, 21 Jul 2021 02:20:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233590AbhGUGSY (ORCPT ); Wed, 21 Jul 2021 02:18:24 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40932C061574 for ; Tue, 20 Jul 2021 23:58:54 -0700 (PDT) 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 Cc: mpe@ellerman.id.au, benh@kernel.crashing.org, paulus@samba.org, christophe.leroy@csgroup.eu, linuxppc-dev@lists.ozlabs.org, amd-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org, Sunpeng.Li@amd.com, Harry Wentland , qingqing.zhuo@amd.com, Rodrigo.Siqueira@amd.com, roman.li@amd.com, Christoph Hellwig , Aurabindo.Pillai@amd.com, Bhawanpreet.Lakha@amd.com, Christian K??nig , bindu.r@amd.com 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > + > +/* > + * 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.