From patchwork Tue Mar 2 10:08:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 42193 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 106C5385781F; Tue, 2 Mar 2021 10:09:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 106C5385781F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1614679742; bh=3nxwUgO80qtS5JzhfTSBi7Zj2JIuS2YSARjj5VeqHHc=; h=To:Subject:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=SRFEWjJ36mrXjF/6AyUS96Du7ClgqIjHAw8dSwaoTXq4Jgd7pKwVNriwsj9KbFTgl yCN2L2KEqaOZNZE2VFWpVCcWAEh3xM5IG/2cbQdv6lu2MFJPARTphDuwTqkdw9O09Y qU6J4CDo9AmaOXJtfz5Lv4QuKwvibxSYiCEsJzkk= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by sourceware.org (Postfix) with ESMTP id ECF8E3858034 for ; Tue, 2 Mar 2021 10:08:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org ECF8E3858034 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-232-dKufgyvwOp2aIzvvJxGJTw-1; Tue, 02 Mar 2021 05:08:33 -0500 X-MC-Unique: dKufgyvwOp2aIzvvJxGJTw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 56306196632A for ; Tue, 2 Mar 2021 10:08:32 +0000 (UTC) Received: from oldenburg.str.redhat.com (ovpn-112-51.ams2.redhat.com [10.36.112.51]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 30C665945F for ; Tue, 2 Mar 2021 10:08:30 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH v2 2/2] x86: Add CPU-specific diagnostics to ld.so --list-diagnostics References: <871rcx3m3d.fsf@oldenburg.str.redhat.com> Date: Tue, 02 Mar 2021 11:08:33 +0100 In-Reply-To: <871rcx3m3d.fsf@oldenburg.str.redhat.com> (Florian Weimer's message of "Tue, 02 Mar 2021 11:07:34 +0100") Message-ID: <87tupt27ha.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 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-Patchwork-Original-From: Florian Weimer via Libc-alpha From: Florian Weimer Reply-To: Florian Weimer Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" --- v2: Adjustments to generic changes. Add comments to cpu-features.h pointing towards the diagnostics printer. sysdeps/x86/dl-diagnostics-cpu.c | 152 +++++++++++++++++++++++++++++++++++++ sysdeps/x86/include/cpu-features.h | 5 +- 2 files changed, 156 insertions(+), 1 deletion(-) diff --git a/sysdeps/x86/dl-diagnostics-cpu.c b/sysdeps/x86/dl-diagnostics-cpu.c new file mode 100644 index 0000000000..a2d47dd657 --- /dev/null +++ b/sysdeps/x86/dl-diagnostics-cpu.c @@ -0,0 +1,152 @@ +/* Print CPU diagnostics data in ld.so. x86 version. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include + +static void +print_cpu_features_value (const char *label, uint64_t value) +{ + _dl_printf ("x86.cpu_features."); + _dl_diagnostics_print_labeled_value (label, value); +} + +static void +print_cpu_feature_internal (unsigned int index, const char *kind, + unsigned int reg, uint32_t value) +{ + _dl_printf ("x86.cpu_features.features[0x%x].%s[0x%x]=0x%x\n", + index, kind, reg, value); +} + +static void +print_cpu_feature_preferred (const char *label, unsigned int flag) +{ + _dl_printf("x86.cpu_features.preferred.%s=0x%x\n", label, flag); +} + +void +_dl_diagnostics_cpu (void) +{ + const struct cpu_features *cpu_features = __get_cpu_features (); + + print_cpu_features_value ("basic.kind", cpu_features->basic.kind); + print_cpu_features_value ("basic.max_cpuid", cpu_features->basic.max_cpuid); + print_cpu_features_value ("basic.family", cpu_features->basic.family); + print_cpu_features_value ("basic.model", cpu_features->basic.model); + print_cpu_features_value ("basic.stepping", cpu_features->basic.stepping); + + for (unsigned int index = 0; index < CPUID_INDEX_MAX; ++index) + { + /* The index values are part of the ABI via + , so translating them to strings is not + necessary. */ + for (unsigned int reg = 0; reg < 4; ++reg) + print_cpu_feature_internal + (index, "cpuid", reg, + cpu_features->features[index].cpuid_array[reg]); + for (unsigned int reg = 0; reg < 4; ++reg) + print_cpu_feature_internal + (index, "usable", reg, + cpu_features->features[index].usable_array[reg]); + } + + /* The preferred indicators are not part of the ABI and need to be + translated. */ + print_cpu_feature_preferred + ("i586", CPU_FEATURE_PREFERRED_P (cpu_features, I586)); + print_cpu_feature_preferred + ("i686", CPU_FEATURE_PREFERRED_P (cpu_features, I686)); + print_cpu_feature_preferred + ("fast_rep_string", + CPU_FEATURE_PREFERRED_P (cpu_features, Fast_Rep_String)); + print_cpu_feature_preferred + ("fast_copy_backward", + CPU_FEATURE_PREFERRED_P (cpu_features, Fast_Copy_Backward)); + print_cpu_feature_preferred + ("fast_unaligned_load", + CPU_FEATURE_PREFERRED_P (cpu_features, Fast_Unaligned_Load)); + print_cpu_feature_preferred + ("fast_unaligned_copy", + CPU_FEATURE_PREFERRED_P (cpu_features, Fast_Unaligned_Copy)); + print_cpu_feature_preferred + ("slow_bsf", CPU_FEATURE_PREFERRED_P (cpu_features, Slow_BSF)); + print_cpu_feature_preferred + ("slow_sse4_2", CPU_FEATURE_PREFERRED_P (cpu_features, Slow_SSE4_2)); + print_cpu_feature_preferred + ("avx_fast_unaligned_load", + CPU_FEATURE_PREFERRED_P (cpu_features, AVX_Fast_Unaligned_Load)); + print_cpu_feature_preferred + ("prefer_map_32bit_exec", + CPU_FEATURE_PREFERRED_P (cpu_features, Prefer_MAP_32BIT_EXEC)); + print_cpu_feature_preferred + ("prefer_pminub_for_stringop", + CPU_FEATURE_PREFERRED_P (cpu_features, Prefer_PMINUB_for_stringop)); + print_cpu_feature_preferred + ("prefer_no_vzeroupper", + CPU_FEATURE_PREFERRED_P (cpu_features, Prefer_No_VZEROUPPER)); + print_cpu_feature_preferred + ("prefer_erms", CPU_FEATURE_PREFERRED_P (cpu_features, Prefer_ERMS)); + print_cpu_feature_preferred + ("prefer_fsrm", CPU_FEATURE_PREFERRED_P (cpu_features, Prefer_FSRM)); + print_cpu_feature_preferred + ("prefer_no_avx512", + CPU_FEATURE_PREFERRED_P (cpu_features, Prefer_No_AVX512)); + print_cpu_feature_preferred + ("mathvec_prefer_no_avx512", + CPU_FEATURE_PREFERRED_P (cpu_features, MathVec_Prefer_No_AVX512)); + + print_cpu_features_value ("isa_1", cpu_features->isa_1); + print_cpu_features_value ("xsave_state_size", + cpu_features->xsave_state_size); + print_cpu_features_value ("xsave_state_full_size", + cpu_features->xsave_state_full_size); + print_cpu_features_value ("data_cache_size", cpu_features->data_cache_size); + print_cpu_features_value ("shared_cache_size", + cpu_features->shared_cache_size); + print_cpu_features_value ("non_temporal_threshold", + cpu_features->non_temporal_threshold); + print_cpu_features_value ("rep_movsb_threshold", + cpu_features->rep_movsb_threshold); + print_cpu_features_value ("rep_movsb_stop_threshold", + cpu_features->rep_movsb_stop_threshold); + print_cpu_features_value ("rep_stosb_threshold", + cpu_features->rep_stosb_threshold); + print_cpu_features_value ("level1_icache_size", + cpu_features->level1_icache_size); + print_cpu_features_value ("level1_dcache_size", + cpu_features->level1_dcache_size); + print_cpu_features_value ("level1_dcache_assoc", + cpu_features->level1_dcache_assoc); + print_cpu_features_value ("level1_dcache_linesize", + cpu_features->level1_dcache_linesize); + print_cpu_features_value ("level2_cache_size", + cpu_features->level2_cache_size); + print_cpu_features_value ("level2_cache_assoc", + cpu_features->level2_cache_assoc); + print_cpu_features_value ("level2_cache_linesize", + cpu_features->level2_cache_linesize); + print_cpu_features_value ("level3_cache_size", + cpu_features->level3_cache_size); + print_cpu_features_value ("level3_cache_assoc", + cpu_features->level3_cache_assoc); + print_cpu_features_value ("level3_cache_linesize", + cpu_features->level3_cache_linesize); + print_cpu_features_value ("level4_cache_size", + cpu_features->level4_cache_size); +} diff --git a/sysdeps/x86/include/cpu-features.h b/sysdeps/x86/include/cpu-features.h index ae5cb24be5..3646150164 100644 --- a/sysdeps/x86/include/cpu-features.h +++ b/sysdeps/x86/include/cpu-features.h @@ -772,7 +772,8 @@ enum /* EBX. */ #define reg_PTWRITE ebx -/* PREFERRED_FEATURE_INDEX_1. */ +/* PREFERRED_FEATURE_INDEX_1. NB: When adding new bits here, update + sysdeps/x86/dl-diagnostics-cpu.c. */ #define bit_arch_I586 (1u << 0) #define bit_arch_I686 (1u << 1) #define bit_arch_Fast_Rep_String (1u << 2) @@ -856,6 +857,8 @@ struct cpuid_feature_internal }; }; +/* NB: When adding new fields, update sysdeps/x86/dl-diagnostics-cpu.c + to print them. */ struct cpu_features { struct cpu_features_basic basic;