Skip to content

Commit 363e941

Browse files
Add CPU info to the speed command summary
Reviewed-by: Richard Levitte <[email protected]> (Merged from openssl#9669)
1 parent 586dd67 commit 363e941

File tree

9 files changed

+122
-19
lines changed

9 files changed

+122
-19
lines changed

apps/info.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
typedef enum OPTION_choice {
1515
OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
1616
OPT_CONFIGDIR, OPT_ENGINESDIR, OPT_MODULESDIR, OPT_DSOEXT, OPT_DIRNAMESEP,
17-
OPT_LISTSEP, OPT_SEEDS
17+
OPT_LISTSEP, OPT_SEEDS, OPT_CPUSETTINGS
1818
} OPTION_CHOICE;
1919

2020
const OPTIONS info_options[] = {
@@ -31,6 +31,7 @@ const OPTIONS info_options[] = {
3131
{"dirnamesep", OPT_DIRNAMESEP, '-', "Directory-filename separator"},
3232
{"listsep", OPT_LISTSEP, '-', "List separator character"},
3333
{"seeds", OPT_SEEDS, '-', "Seed sources"},
34+
{"cpusettings", OPT_CPUSETTINGS, '-', "CPU settings info"},
3435
{NULL}
3536
};
3637

@@ -79,6 +80,10 @@ int info_main(int argc, char **argv)
7980
type = OPENSSL_INFO_SEED_SOURCE;
8081
dirty++;
8182
break;
83+
case OPT_CPUSETTINGS:
84+
type = OPENSSL_INFO_CPU_SETTINGS;
85+
dirty++;
86+
break;
8287
}
8388
}
8489
if (opt_num_rest() != 0) {

apps/speed.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3363,6 +3363,7 @@ int speed_main(int argc, char **argv)
33633363
printf("%s ", BF_options());
33643364
#endif
33653365
printf("\n%s\n", OpenSSL_version(OPENSSL_CFLAGS));
3366+
printf("%s\n", OpenSSL_version(OPENSSL_CPU_INFO));
33663367
}
33673368

33683369
if (pr_header) {

apps/version.c

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
typedef enum OPTION_choice {
3535
OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
36-
OPT_B, OPT_D, OPT_E, OPT_M, OPT_F, OPT_O, OPT_P, OPT_V, OPT_A, OPT_R
36+
OPT_B, OPT_D, OPT_E, OPT_M, OPT_F, OPT_O, OPT_P, OPT_V, OPT_A, OPT_R, OPT_C
3737
} OPTION_CHOICE;
3838

3939
const OPTIONS version_options[] = {
@@ -48,24 +48,15 @@ const OPTIONS version_options[] = {
4848
{"p", OPT_P, '-', "Show target build platform"},
4949
{"r", OPT_R, '-', "Show random seeding options"},
5050
{"v", OPT_V, '-', "Show library version"},
51+
{"c", OPT_C, '-', "Show CPU settings info"},
5152
{NULL}
5253
};
5354

54-
#if defined(OPENSSL_RAND_SEED_DEVRANDOM) || defined(OPENSSL_RAND_SEED_EGD)
55-
static void printlist(const char *prefix, const char **dev)
56-
{
57-
printf("%s (", prefix);
58-
for ( ; *dev != NULL; dev++)
59-
printf(" \"%s\"", *dev);
60-
printf(" )");
61-
}
62-
#endif
63-
6455
int version_main(int argc, char **argv)
6556
{
6657
int ret = 1, dirty = 0, seed = 0;
6758
int cflags = 0, version = 0, date = 0, options = 0, platform = 0, dir = 0;
68-
int engdir = 0, moddir = 0;
59+
int engdir = 0, moddir = 0, cpuinfo = 0;
6960
char *prog;
7061
OPTION_CHOICE o;
7162

@@ -108,9 +99,12 @@ int version_main(int argc, char **argv)
10899
case OPT_V:
109100
dirty = version = 1;
110101
break;
102+
case OPT_C:
103+
dirty = cpuinfo = 1;
104+
break;
111105
case OPT_A:
112106
seed = options = cflags = version = date = platform
113-
= dir = engdir = moddir
107+
= dir = engdir = moddir = cpuinfo
114108
= 1;
115109
break;
116110
}
@@ -157,8 +151,12 @@ int version_main(int argc, char **argv)
157151
printf("%s\n", OpenSSL_version(OPENSSL_ENGINES_DIR));
158152
if (moddir)
159153
printf("%s\n", OpenSSL_version(OPENSSL_MODULES_DIR));
160-
if (seed)
161-
printf("Seeding source: %s\n", OPENSSL_info(OPENSSL_INFO_SEED_SOURCE));
154+
if (seed) {
155+
const char *src = OPENSSL_info(OPENSSL_INFO_SEED_SOURCE);
156+
printf("Seeding source: %s\n", src ? src : "N/A");
157+
}
158+
if (cpuinfo)
159+
printf("%s\n", OpenSSL_version(OPENSSL_CPU_INFO));
162160
ret = 0;
163161
end:
164162
return ret;

crypto/cversion.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ const char *OPENSSL_version_build_metadata(void)
4343
return OPENSSL_VERSION_BUILD_METADATA_STR;
4444
}
4545

46+
extern char ossl_cpu_info_str[];
47+
4648
const char *OpenSSL_version(int t)
4749
{
4850
switch (t) {
@@ -76,6 +78,11 @@ const char *OpenSSL_version(int t)
7678
#else
7779
return "MODULESDIR: N/A";
7880
#endif
81+
case OPENSSL_CPU_INFO:
82+
if (OPENSSL_info(OPENSSL_INFO_CPU_SETTINGS) != NULL)
83+
return ossl_cpu_info_str;
84+
else
85+
return "CPUINFO: N/A";
7986
}
8087
return "not available";
8188
}

crypto/info.c

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,57 @@
77
* https://www.openssl.org/source/license.html
88
*/
99

10-
#include <stddef.h>
1110
#include <openssl/crypto.h>
1211
#include "internal/dso_conf.h"
12+
#include "internal/thread_once.h"
13+
#include "internal/cryptlib.h"
1314
#include "e_os.h"
1415
#include "buildinf.h"
15-
#include "internal/thread_once.h"
16+
17+
#if defined(__arm__) || defined(__arm) || defined(__aarch64__)
18+
# include "arm_arch.h"
19+
#endif
20+
21+
/* extern declaration to avoid warning */
22+
extern char ossl_cpu_info_str[];
1623

1724
static char *seed_sources = NULL;
25+
26+
char ossl_cpu_info_str[128] = "";
27+
#define CPUINFO_PREFIX "CPUINFO: "
28+
1829
static CRYPTO_ONCE init_info = CRYPTO_ONCE_STATIC_INIT;
1930

2031
DEFINE_RUN_ONCE_STATIC(init_info_strings)
2132
{
33+
#if defined(OPENSSL_CPUID_OBJ)
34+
# if defined(__i386) || defined(__i386__) || defined(_M_IX86) || \
35+
defined(__x86_64) || defined(__x86_64__) || \
36+
defined(_M_AMD64) || defined(_M_X64)
37+
const char *env;
38+
39+
BIO_snprintf(ossl_cpu_info_str, sizeof(ossl_cpu_info_str),
40+
CPUINFO_PREFIX "OPENSSL_ia32cap=0x%llx:0x%llx",
41+
(long long)OPENSSL_ia32cap_P[0] |
42+
(long long)OPENSSL_ia32cap_P[1] << 32,
43+
(long long)OPENSSL_ia32cap_P[2] |
44+
(long long)OPENSSL_ia32cap_P[3] << 32);
45+
if ((env = getenv("OPENSSL_ia32cap")) != NULL)
46+
BIO_snprintf(ossl_cpu_info_str + strlen(ossl_cpu_info_str),
47+
sizeof(ossl_cpu_info_str) - strlen(ossl_cpu_info_str),
48+
" env:%s", env);
49+
# elif defined(__arm__) || defined(__arm) || defined(__aarch64__)
50+
const char *env;
51+
52+
BIO_snprintf(ossl_cpu_info_str, sizeof(ossl_cpu_info_str),
53+
CPUINFO_PREFIX "OPENSSL_armcap=0x%x", OPENSSL_armcap_P);
54+
if ((env = getenv("OPENSSL_armcap")) != NULL)
55+
BIO_snprintf(ossl_cpu_info_str + strlen(ossl_cpu_info_str),
56+
sizeof(ossl_cpu_info_str) - strlen(ossl_cpu_info_str),
57+
" env:%s", env);
58+
# endif
59+
#endif
60+
2261
{
2362
static char seeds[512] = "";
2463

@@ -107,6 +146,15 @@ const char *OPENSSL_info(int t)
107146
}
108147
case OPENSSL_INFO_SEED_SOURCE:
109148
return seed_sources;
149+
case OPENSSL_INFO_CPU_SETTINGS:
150+
/*
151+
* If successfully initialized, ossl_cpu_info_str will start
152+
* with CPUINFO_PREFIX, if failed it will be an empty string.
153+
* Strip away the CPUINFO_PREFIX which we don't need here.
154+
*/
155+
if (ossl_cpu_info_str[0] != '\0')
156+
return ossl_cpu_info_str + strlen(CPUINFO_PREFIX);
157+
break;
110158
default:
111159
break;
112160
}

doc/man1/openssl-info.pod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ B<openssl info>
1515
[B<-dirfilesep>]
1616
[B<-listsep]>
1717
[B<-seeds]>
18+
[B<-cpusettings]>
1819

1920
=head1 DESCRIPTION
2021

@@ -67,6 +68,10 @@ style lists.
6768

6869
Outputs the randomness seed sources.
6970

71+
=item B<-cpusettings>
72+
73+
Outputs the OpenSSL CPU settings info.
74+
7075
=back
7176

7277
=head1 HISTORY

doc/man1/openssl-version.pod

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ B<openssl version>
1616
[B<-p>]
1717
[B<-d>]
1818
[B<-e>]
19+
[B<-m>]
20+
[B<-r>]
21+
[B<-c>]
1922

2023
=head1 DESCRIPTION
2124

@@ -61,6 +64,18 @@ OPENSSLDIR setting.
6164

6265
ENGINESDIR settings.
6366

67+
=item B<-m>
68+
69+
MODULESDIR settings.
70+
71+
=item B<-r>
72+
73+
The random number generator source settings.
74+
75+
=item B<-c>
76+
77+
The OpenSSL CPU settings info.
78+
6479
=back
6580

6681
=head1 NOTES

doc/man3/OpenSSL_version.pod

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,20 @@ if available or "OPENSSLDIR: N/A" otherwise.
125125
The "ENGINESDIR" setting of the library build in the form "ENGINESDIR: "...""
126126
if available or "ENGINESDIR: N/A" otherwise.
127127

128+
=item OPENSSL_MODULES_DIR
129+
130+
The "MODULESDIR" setting of the library build in the form "MODULESDIR: "...""
131+
if available or "MODULESDIR: N/A" otherwise.
132+
133+
=item OPENSSL_CPU_INFO
134+
135+
The current OpenSSL cpu settings.
136+
This is the current setting of the cpu capability flags. It is usually
137+
automatically configured but may be set via an environment variable.
138+
The value has the same syntax as the environment variable.
139+
For x86 the string looks like "CPUINFO: OPENSSL_ia32cap=0x123:0x456".
140+
Or "CPUINFO: N/A" if not available, e.g. no-asm build.
141+
128142
=back
129143

130144
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
166180
separator is ":") or C<%PATH%> on Windows (where the separator is
167181
";").
168182

183+
=item OPENSSL_INFO_CPU_SETTINGS
184+
185+
The current OpenSSL cpu settings.
186+
This is the current setting of the cpu capability flags. It is usually
187+
automatically configured but may be set via an environment variable.
188+
The value has the same syntax as the environment variable.
189+
For x86 the string looks like "OPENSSL_ia32cap=0x123:0x456".
190+
169191
=back
170192

171193
For an unknown B<t>, NULL is returned.
@@ -224,7 +246,7 @@ with the exception of the L</BACKWARD COMPATIBILITY> ones.
224246

225247
=head1 COPYRIGHT
226248

227-
Copyright 2018 The OpenSSL Project Authors. All Rights Reserved.
249+
Copyright 2018-2019 The OpenSSL Project Authors. All Rights Reserved.
228250

229251
Licensed under the Apache License 2.0 (the "License"). You may not use
230252
this file except in compliance with the License. You can obtain a copy

include/openssl/crypto.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ const char *OpenSSL_version(int type);
169169
# define OPENSSL_VERSION_STRING 6
170170
# define OPENSSL_FULL_VERSION_STRING 7
171171
# define OPENSSL_MODULES_DIR 8
172+
# define OPENSSL_CPU_INFO 9
172173

173174
const char *OPENSSL_info(int type);
174175
/*
@@ -182,6 +183,7 @@ const char *OPENSSL_info(int type);
182183
# define OPENSSL_INFO_DIR_FILENAME_SEPARATOR 1005
183184
# define OPENSSL_INFO_LIST_SEPARATOR 1006
184185
# define OPENSSL_INFO_SEED_SOURCE 1007
186+
# define OPENSSL_INFO_CPU_SETTINGS 1008
185187

186188
int OPENSSL_issetugid(void);
187189

0 commit comments

Comments
 (0)