From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by sourceware.org (Postfix) with ESMTPS id 97E17393F815 for ; Mon, 28 Jun 2021 19:09:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 97E17393F815 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: sourceware.org; spf=none smtp.mailfrom=infradead.org 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=Gb8FkkfiAI/E5kFp62oWoJRN3P7rxKjZgqkGxjBVBqI=; b=W6VOkGRKcqRzZZICet4Vi1GmE8 EnY7Q8NV4pBmx7kyAK2KB+gCbFFBWAkBYLAG0SUjTWSqTPBYc7eBBEpUyt/O1pFJNrdNZLtpEMPRr gwwbjHuuvqGLZTkfjCJN99+zvacXp1mYbMSEeAFANSgEP2tbzerpV2qRqlGSJycZCijozXlG0Xah7 LfEW5HKabdlSn61Se3uLQhw9SghmI9WQUyzlBAdOj+5S/ZqPEhaVKU8brOKB5m9W6WEt57njuDGMm 8UTpEdP5Ju5y7XDS8aYreGcBNLyvziR80eE3kCqvJJvkn8oio+l7i36F+gvXBm8n2KmJ4IC7ywcWO sUTRgtRg==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=worktop.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1lxwcF-003MZY-Gw; Mon, 28 Jun 2021 19:08:28 +0000 Received: by worktop.programming.kicks-ass.net (Postfix, from userid 1000) id 37DD8982D9E; Mon, 28 Jun 2021 21:08:17 +0200 (CEST) Date: Mon, 28 Jun 2021 21:08:16 +0200 From: Peter Zijlstra To: Thiago Macieira Cc: fweimer@redhat.com, "Enrico Weigelt, metux IT consult" , hjl.tools@gmail.com, libc-alpha@sourceware.org, linux-api@vger.kernel.org, linux-arch@vger.kernel.org, x86@kernel.org Subject: Re: x86 CPU features detection for applications (and AMX) Message-ID: <20210628190816.GC13401@worktop.programming.kicks-ass.net> References: <22261946.eFiGugXE7Z@tjmaciei-mobl1> <2094802.S4rhTtsRBG@tjmaciei-mobl1> <20210628171115.GA13401@worktop.programming.kicks-ass.net> <7968759.t5oPhm3B3B@tjmaciei-mobl1> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <7968759.t5oPhm3B3B@tjmaciei-mobl1> X-Spam-Status: No, score=2.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_ABUSEAT, RCVD_IN_DNSWL_NONE, RCVD_IN_SBL_CSS, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=no autolearn_force=no version=3.4.2 X-Spam-Level: ** X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 Jun 2021 19:09:18 -0000 On Mon, Jun 28, 2021 at 10:23:47AM -0700, Thiago Macieira wrote: > On Monday, 28 June 2021 10:11:16 PDT Peter Zijlstra wrote: > > > Consequence: CPU feature checking is done *very* early, often before > > > main(). > > For the linker based ones, yes. IIRC the ifunc() attribute is > > particularly useful here. > > Exactly. ifunc was designed for this exact purpose. And hence the fact that > CPUID initialisation will be done very, very early. > > Anyway, if the AMX state is a sticky "set once per process", it's likely going > to get set early for every process that *may* use AMX. And this is assuming we > do the library right and only set it if has AMX code at all, instead of all > the time. This, AFAIU. If the ifunc() resolver finds we haz AMX it can do the prctl() and on success pick the AMX routine. Assuming of course, that if a program links with a library that supports AMX, it will actually end up using it.