Add CPU info to the speed command summary

Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9669)
This commit is contained in:
Bernd Edlinger 2019-08-22 14:28:23 +02:00
parent 586dd674f5
commit 363e941ed4
9 changed files with 122 additions and 19 deletions

View File

@ -14,7 +14,7 @@
typedef enum OPTION_choice {
OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
OPT_CONFIGDIR, OPT_ENGINESDIR, OPT_MODULESDIR, OPT_DSOEXT, OPT_DIRNAMESEP,
OPT_LISTSEP, OPT_SEEDS
OPT_LISTSEP, OPT_SEEDS, OPT_CPUSETTINGS
} OPTION_CHOICE;
const OPTIONS info_options[] = {
@ -31,6 +31,7 @@ const OPTIONS info_options[] = {
{"dirnamesep", OPT_DIRNAMESEP, '-', "Directory-filename separator"},
{"listsep", OPT_LISTSEP, '-', "List separator character"},
{"seeds", OPT_SEEDS, '-', "Seed sources"},
{"cpusettings", OPT_CPUSETTINGS, '-', "CPU settings info"},
{NULL}
};
@ -79,6 +80,10 @@ opthelp:
type = OPENSSL_INFO_SEED_SOURCE;
dirty++;
break;
case OPT_CPUSETTINGS:
type = OPENSSL_INFO_CPU_SETTINGS;
dirty++;
break;
}
}
if (opt_num_rest() != 0) {

View File

@ -3363,6 +3363,7 @@ int speed_main(int argc, char **argv)
printf("%s ", BF_options());
#endif
printf("\n%s\n", OpenSSL_version(OPENSSL_CFLAGS));
printf("%s\n", OpenSSL_version(OPENSSL_CPU_INFO));
}
if (pr_header) {

View File

@ -33,7 +33,7 @@
typedef enum OPTION_choice {
OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
OPT_B, OPT_D, OPT_E, OPT_M, OPT_F, OPT_O, OPT_P, OPT_V, OPT_A, OPT_R
OPT_B, OPT_D, OPT_E, OPT_M, OPT_F, OPT_O, OPT_P, OPT_V, OPT_A, OPT_R, OPT_C
} OPTION_CHOICE;
const OPTIONS version_options[] = {
@ -48,24 +48,15 @@ const OPTIONS version_options[] = {
{"p", OPT_P, '-', "Show target build platform"},
{"r", OPT_R, '-', "Show random seeding options"},
{"v", OPT_V, '-', "Show library version"},
{"c", OPT_C, '-', "Show CPU settings info"},
{NULL}
};
#if defined(OPENSSL_RAND_SEED_DEVRANDOM) || defined(OPENSSL_RAND_SEED_EGD)
static void printlist(const char *prefix, const char **dev)
{
printf("%s (", prefix);
for ( ; *dev != NULL; dev++)
printf(" \"%s\"", *dev);
printf(" )");
}
#endif
int version_main(int argc, char **argv)
{
int ret = 1, dirty = 0, seed = 0;
int cflags = 0, version = 0, date = 0, options = 0, platform = 0, dir = 0;
int engdir = 0, moddir = 0;
int engdir = 0, moddir = 0, cpuinfo = 0;
char *prog;
OPTION_CHOICE o;
@ -108,9 +99,12 @@ opthelp:
case OPT_V:
dirty = version = 1;
break;
case OPT_C:
dirty = cpuinfo = 1;
break;
case OPT_A:
seed = options = cflags = version = date = platform
= dir = engdir = moddir
= dir = engdir = moddir = cpuinfo
= 1;
break;
}
@ -157,8 +151,12 @@ opthelp:
printf("%s\n", OpenSSL_version(OPENSSL_ENGINES_DIR));
if (moddir)
printf("%s\n", OpenSSL_version(OPENSSL_MODULES_DIR));
if (seed)
printf("Seeding source: %s\n", OPENSSL_info(OPENSSL_INFO_SEED_SOURCE));
if (seed) {
const char *src = OPENSSL_info(OPENSSL_INFO_SEED_SOURCE);
printf("Seeding source: %s\n", src ? src : "N/A");
}
if (cpuinfo)
printf("%s\n", OpenSSL_version(OPENSSL_CPU_INFO));
ret = 0;
end:
return ret;

View File

@ -43,6 +43,8 @@ const char *OPENSSL_version_build_metadata(void)
return OPENSSL_VERSION_BUILD_METADATA_STR;
}
extern char ossl_cpu_info_str[];
const char *OpenSSL_version(int t)
{
switch (t) {
@ -76,6 +78,11 @@ const char *OpenSSL_version(int t)
#else
return "MODULESDIR: N/A";
#endif
case OPENSSL_CPU_INFO:
if (OPENSSL_info(OPENSSL_INFO_CPU_SETTINGS) != NULL)
return ossl_cpu_info_str;
else
return "CPUINFO: N/A";
}
return "not available";
}

View File

@ -7,18 +7,57 @@
* https://www.openssl.org/source/license.html
*/
#include <stddef.h>
#include <openssl/crypto.h>
#include "internal/dso_conf.h"
#include "internal/thread_once.h"
#include "internal/cryptlib.h"
#include "e_os.h"
#include "buildinf.h"
#include "internal/thread_once.h"
#if defined(__arm__) || defined(__arm) || defined(__aarch64__)
# include "arm_arch.h"
#endif
/* extern declaration to avoid warning */
extern char ossl_cpu_info_str[];
static char *seed_sources = NULL;
char ossl_cpu_info_str[128] = "";
#define CPUINFO_PREFIX "CPUINFO: "
static CRYPTO_ONCE init_info = CRYPTO_ONCE_STATIC_INIT;
DEFINE_RUN_ONCE_STATIC(init_info_strings)
{
#if defined(OPENSSL_CPUID_OBJ)
# if defined(__i386) || defined(__i386__) || defined(_M_IX86) || \
defined(__x86_64) || defined(__x86_64__) || \
defined(_M_AMD64) || defined(_M_X64)
const char *env;
BIO_snprintf(ossl_cpu_info_str, sizeof(ossl_cpu_info_str),
CPUINFO_PREFIX "OPENSSL_ia32cap=0x%llx:0x%llx",
(long long)OPENSSL_ia32cap_P[0] |
(long long)OPENSSL_ia32cap_P[1] << 32,
(long long)OPENSSL_ia32cap_P[2] |
(long long)OPENSSL_ia32cap_P[3] << 32);
if ((env = getenv("OPENSSL_ia32cap")) != NULL)
BIO_snprintf(ossl_cpu_info_str + strlen(ossl_cpu_info_str),
sizeof(ossl_cpu_info_str) - strlen(ossl_cpu_info_str),
" env:%s", env);
# elif defined(__arm__) || defined(__arm) || defined(__aarch64__)
const char *env;
BIO_snprintf(ossl_cpu_info_str, sizeof(ossl_cpu_info_str),
CPUINFO_PREFIX "OPENSSL_armcap=0x%x", OPENSSL_armcap_P);
if ((env = getenv("OPENSSL_armcap")) != NULL)
BIO_snprintf(ossl_cpu_info_str + strlen(ossl_cpu_info_str),
sizeof(ossl_cpu_info_str) - strlen(ossl_cpu_info_str),
" env:%s", env);
# endif
#endif
{
static char seeds[512] = "";
@ -107,6 +146,15 @@ const char *OPENSSL_info(int t)
}
case OPENSSL_INFO_SEED_SOURCE:
return seed_sources;
case OPENSSL_INFO_CPU_SETTINGS:
/*
* If successfully initialized, ossl_cpu_info_str will start
* with CPUINFO_PREFIX, if failed it will be an empty string.
* Strip away the CPUINFO_PREFIX which we don't need here.
*/
if (ossl_cpu_info_str[0] != '\0')
return ossl_cpu_info_str + strlen(CPUINFO_PREFIX);
break;
default:
break;
}

View File

@ -15,6 +15,7 @@ B<openssl info>
[B<-dirfilesep>]
[B<-listsep]>
[B<-seeds]>
[B<-cpusettings]>
=head1 DESCRIPTION
@ -67,6 +68,10 @@ style lists.
Outputs the randomness seed sources.
=item B<-cpusettings>
Outputs the OpenSSL CPU settings info.
=back
=head1 HISTORY

View File

@ -16,6 +16,9 @@ B<openssl version>
[B<-p>]
[B<-d>]
[B<-e>]
[B<-m>]
[B<-r>]
[B<-c>]
=head1 DESCRIPTION
@ -61,6 +64,18 @@ OPENSSLDIR setting.
ENGINESDIR settings.
=item B<-m>
MODULESDIR settings.
=item B<-r>
The random number generator source settings.
=item B<-c>
The OpenSSL CPU settings info.
=back
=head1 NOTES

View File

@ -125,6 +125,20 @@ if available or "OPENSSLDIR: N/A" otherwise.
The "ENGINESDIR" setting of the library build in the form "ENGINESDIR: "...""
if available or "ENGINESDIR: N/A" otherwise.
=item OPENSSL_MODULES_DIR
The "MODULESDIR" setting of the library build in the form "MODULESDIR: "...""
if available or "MODULESDIR: N/A" otherwise.
=item OPENSSL_CPU_INFO
The current OpenSSL cpu settings.
This is the current setting of the cpu capability flags. It is usually
automatically configured but may be set via an environment variable.
The value has the same syntax as the environment variable.
For x86 the string looks like "CPUINFO: OPENSSL_ia32cap=0x123:0x456".
Or "CPUINFO: N/A" if not available, e.g. no-asm build.
=back
For an unknown B<t>, the text "not available" is returned.
@ -166,6 +180,14 @@ value of the environment variable C<$PATH> on Unix (where the
separator is ":") or C<%PATH%> on Windows (where the separator is
";").
=item OPENSSL_INFO_CPU_SETTINGS
The current OpenSSL cpu settings.
This is the current setting of the cpu capability flags. It is usually
automatically configured but may be set via an environment variable.
The value has the same syntax as the environment variable.
For x86 the string looks like "OPENSSL_ia32cap=0x123:0x456".
=back
For an unknown B<t>, NULL is returned.
@ -224,7 +246,7 @@ with the exception of the L</BACKWARD COMPATIBILITY> ones.
=head1 COPYRIGHT
Copyright 2018 The OpenSSL Project Authors. All Rights Reserved.
Copyright 2018-2019 The OpenSSL Project Authors. All Rights Reserved.
Licensed under the Apache License 2.0 (the "License"). You may not use
this file except in compliance with the License. You can obtain a copy

View File

@ -169,6 +169,7 @@ const char *OpenSSL_version(int type);
# define OPENSSL_VERSION_STRING 6
# define OPENSSL_FULL_VERSION_STRING 7
# define OPENSSL_MODULES_DIR 8
# define OPENSSL_CPU_INFO 9
const char *OPENSSL_info(int type);
/*
@ -182,6 +183,7 @@ const char *OPENSSL_info(int type);
# define OPENSSL_INFO_DIR_FILENAME_SEPARATOR 1005
# define OPENSSL_INFO_LIST_SEPARATOR 1006
# define OPENSSL_INFO_SEED_SOURCE 1007
# define OPENSSL_INFO_CPU_SETTINGS 1008
int OPENSSL_issetugid(void);