Received: by 10.223.176.5 with SMTP id f5csp835824wra; Fri, 2 Feb 2018 06:57:16 -0800 (PST) X-Google-Smtp-Source: AH8x226/C+bZHgQT3W+J7NlqAhQvZBzOkGOHlPMCNMV0EhkZKL5ipm84I4x7JytCEskcTvqHaW1g X-Received: by 10.98.30.1 with SMTP id e1mr40597206pfe.37.1517583436518; Fri, 02 Feb 2018 06:57:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517583436; cv=none; d=google.com; s=arc-20160816; b=UXLpJ8m8sLVBeCwnpR4HJugWGJyu+fPOHFNsdYd0EEFuOdgha5hUKw9V99K6ilGwj7 Hpz9Rhdqwbcbya8gUKCHimhuBlSJ97ClW2NZXIqJK/8HLHwGp1eKSKmj1EQXYdwdpw/C Do3wwCfIV9lJD1/FhW45xQdi2RyT5NsvCwPdOV9zO/irg0Gf8Kyr4PhZaYNciQ30bHIw +SKqObuykJOuWo/tmHzL62D1gyJ3LFggm9x4pKaKQZ1gqHEVmIOnrzjx9EaRQpbD94qh 8GDrgA9uSNqc2zlSv/ijI5h9LCt13p3WAuYo9iaQEskJZndO/9GKb8k4IFOlr9fl9X0C 6KZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dmarc-filter:arc-authentication-results; bh=ISA1Q/l3lrbl1Kq1ftA1bKJ7zJNrwcnaewiShUT8eJ0=; b=dtx+oOhnk9JcMl8FjtmMYFCQoeYkkSg03WNbLAhg99RvTbPuo84MUUq7Mj13cSh77e 1YnXyIX/BWQzsQQXZ3P7iaXyEVQ560Dy5SOjnSNkOLesb1jfN2HaC/t8C3p4MFiy86XO wxeak2LolkidEYKuwNJqS9RAuJQS56DxBzBp7OcK4iCYm8j7hPQrILnM3rlmti6ZMEiW feGrUkY8E8WZQITnBO9AGESjmU1l9+pxuB8ClnYcYI1WehM+mmXVMDiFsE4n+K3Xlz30 OHIv86AFaxWO99P6tMe39kZaQ4QwHQiQgSrcmMnzl8QyxpXd2+DmPXxeHsWdq1A/iv6N +cIg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q11-v6si1385323pli.790.2018.02.02.06.57.01; Fri, 02 Feb 2018 06:57:16 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752341AbeBBOzC (ORCPT + 99 others); Fri, 2 Feb 2018 09:55:02 -0500 Received: from mail.kernel.org ([198.145.29.99]:53194 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752282AbeBBOyw (ORCPT ); Fri, 2 Feb 2018 09:54:52 -0500 Received: from jouet.infradead.org (unknown [179.97.41.186]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4D7C02178E; Fri, 2 Feb 2018 14:54:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4D7C02178E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=acme@kernel.org Received: by jouet.infradead.org (Postfix, from userid 1000) id 83D38141E4A; Fri, 2 Feb 2018 11:54:48 -0300 (-03) Date: Fri, 2 Feb 2018 11:54:48 -0300 From: Arnaldo Carvalho de Melo To: Matthew Whitehead Cc: peterz@infradead.org, mingo@redhat.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH] x86/perf : Add check for CPUID instruction before using Message-ID: <20180202145448.GD26905@kernel.org> References: <1517581851-6600-1-git-send-email-tedheadster@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1517581851-6600-1-git-send-email-tedheadster@gmail.com> X-Url: http://acmel.wordpress.com User-Agent: Mutt/1.9.1 (2017-09-22) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Fri, Feb 02, 2018 at 09:30:51AM -0500, Matthew Whitehead escreveu: > We still officially support the ancient i486 cpu. First generation > versions of this processor do not have the CPUID instruction, though > later versions do. Therefore you must check that the cpu supports > it before using it. At present it fails with an "Illegal Instruction" > signal on the early processors. > > This code was based on similar code in the gcc package. Can you provide an URL for the code used as a reference, please? - Arnaldo > Signed-off-by: Matthew Whitehead > --- > tools/perf/arch/x86/util/header.c | 51 +++++++++++++++++++++++++++++++++++++++ > tools/perf/util/header.h | 2 ++ > 2 files changed, 53 insertions(+) > > diff --git a/tools/perf/arch/x86/util/header.c b/tools/perf/arch/x86/util/header.c > index fb0d71afee8b..d4d12894c64d 100644 > --- a/tools/perf/arch/x86/util/header.c > +++ b/tools/perf/arch/x86/util/header.c > @@ -7,6 +7,54 @@ > > #include "../../util/header.h" > > +/* This code based on gcc cpuid.h __get_cpuid_max() */ > +unsigned int have_cpuid(void) > +{ > + unsigned int __eax, __ebx; > + > +#ifndef __x86_64__ > +/* See if we can use cpuid. On AMD64 we always can. */ > +#if __GNUC__ >= 3 > + __asm__ ("pushf{l|d}\n\t" > + "pushf{l|d}\n\t" > + "pop{l}\t%0\n\t" > + "mov{l}\t{%0, %1|%1, %0}\n\t" > + "xor{l}\t{%2, %0|%0, %2}\n\t" > + "push{l}\t%0\n\t" > + "popf{l|d}\n\t" > + "pushf{l|d}\n\t" > + "pop{l}\t%0\n\t" > + "popf{l|d}\n\t" > + : "=&r" (__eax), "=&r" (__ebx) > + : "i" (0x00200000)); > +#else > +/* Host GCCs older than 3.0 weren't supporting Intel asm syntax > + * nor alternatives in i386 code. > + */ > + __asm__ ("pushfl\n\t" > + "pushfl\n\t" > + "popl\t%0\n\t" > + "movl\t%0, %1\n\t" > + "xorl\t%2, %0\n\t" > + "pushl\t%0\n\t" > + "popfl\n\t" > + "pushfl\n\t" > + "popl\t%0\n\t" > + "popfl\n\t" > + : "=&r" (__eax), "=&r" (__ebx) > + : "i" (0x00200000)); > +#endif > + > + if (!((__eax ^ __ebx) & 0x00200000)) > + return 0; > + else > + return 1; > +#endif > + > +/* All x86_64 support cpuid */ > + return 1; > +} > + > static inline void > cpuid(unsigned int op, unsigned int *a, unsigned int *b, unsigned int *c, > unsigned int *d) > @@ -28,6 +76,9 @@ __get_cpuid(char *buffer, size_t sz, const char *fmt) > int nb; > char vendor[16]; > > + if (!have_cpuid()) > + return -1; > + > cpuid(0, &lvl, &b, &c, &d); > strncpy(&vendor[0], (char *)(&b), 4); > strncpy(&vendor[4], (char *)(&d), 4); > diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h > index f28aaaa3a440..ce31fca36077 100644 > --- a/tools/perf/util/header.h > +++ b/tools/perf/util/header.h > @@ -171,6 +171,8 @@ int write_padded(struct feat_fd *fd, const void *bf, > /* > * arch specific callback > */ > +unsigned int have_cpuid(void); > + > int get_cpuid(char *buffer, size_t sz); > > char *get_cpuid_str(struct perf_pmu *pmu __maybe_unused); > -- > 2.13.6