-
Notifications
You must be signed in to change notification settings - Fork 127
/
corefreq-cli.c
6618 lines (5874 loc) · 186 KB
/
corefreq-cli.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* CoreFreq
* Copyright (C) 2015-2017 CYRIL INGENIERIE
* Licenses: GPL2
*/
#define _GNU_SOURCE
#include <math.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <time.h>
#include <poll.h>
#include <termios.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <libgen.h>
#include <sched.h>
#include "bitasm.h"
#include "coretypes.h"
#include "corefreq.h"
static Bit64 Shutdown __attribute__ ((aligned (64))) = 0x0;
void Emergency(int caught)
{
switch (caught) {
case SIGINT:
case SIGQUIT:
case SIGTERM:
case SIGTSTP:
BITSET(LOCKLESS, Shutdown, 0);
break;
}
}
void TrapSignal(void)
{
signal(SIGINT, Emergency);
signal(SIGQUIT, Emergency);
signal(SIGTERM, Emergency);
signal(SIGTSTP, Emergency); // [CTRL] + [Z]
}
// VT100 requirements.
#define SCP "\033[s"
#define RCP "\033[u"
#define HIDE "\033[?25l"
#define SHOW "\033[?25h"
#define RESET "\033c"
#define SCR1 "\033[?47h"
#define SCR0 "\033[?47l"
#define CLS "\033[J"
#define CUH "\033[H"
#define CUP(col, row) "\033["#row";"#col"H"
#define BLACK 0
#define RED 1
#define GREEN 2
#define YELLOW 3
#define BLUE 4
#define MAGENTA 5
#define CYAN 6
#define WHITE 7
#define _COLOR(_mod, _fg, _bg) "\033["#_mod";3"#_fg";4"#_bg"m"
#define COLOR(mod, fg, bg) _COLOR(mod, fg, bg)
#define AoK COLOR(0, WHITE, BLACK)
#define DoK COLOR(1, BLACK, BLACK)
#define RoK COLOR(1, RED, BLACK)
#define GoK COLOR(1, GREEN, BLACK)
#define YoK COLOR(1, YELLOW, BLACK)
#define BoK COLOR(1, BLUE, BLACK)
#define MoK COLOR(1, MAGENTA, BLACK)
#define CoK COLOR(1, CYAN, BLACK)
#define WoK COLOR(1, WHITE, BLACK)
const char lcd[10][3][3] = {
{// 0
" _ ",
"| |",
"|_|"
},
{// 1
" ",
" | ",
" | "
},
{// 2
" _ ",
" _|",
"|_ "
},
{// 3
" _ ",
" _|",
" _|"
},
{// 4
" ",
"|_|",
" |"
},
{// 5
" _ ",
"|_ ",
" _|"
},
{// 6
" _ ",
"|_ ",
"|_|"
},
{// 7
" _ ",
" |",
" |"
},
{// 8
" _ ",
"|_|",
"|_|"
},
{// 9
" _ ",
"|_|",
" _|"
}
};
#define TOP_HEADER_ROW 3
#define TOP_FOOTER_ROW 2
#define TOP_SEPARATOR 3
#define MAX_CPU_ROW 48
#define MAX_HEIGHT ((2 * MAX_CPU_ROW) \
+ TOP_HEADER_ROW \
+ TOP_SEPARATOR \
+ TOP_FOOTER_ROW)
#define MAX_WIDTH 132
#define MIN_WIDTH 80
#define LEADING_LEFT 1
#define LEADING_TOP 1
#define MARGIN_WIDTH 2
#define MARGIN_HEIGHT 1
#define INTER_WIDTH 3
#define INTER_HEIGHT (3 + 1)
char hSpace[] = " "" "" "" "" " \
" "" "" "" "" " \
" "" "" "" "" " \
" "" ";
char hBar[] = "||||||||""||||||||""||||||||""||||||||""||||||||" \
"||||||||""||||||||""||||||||""||||||||""||||||||" \
"||||||||""||||||||""||||||||""||||||||""||||||||" \
"||||||||""||||";
char hLine[] = "--------""--------""--------""--------""--------" \
"--------""--------""--------""--------""--------" \
"--------""--------""--------""--------""--------" \
"--------""----";
typedef union {
unsigned long long key;
unsigned char code[8];
} SCANKEY;
#define SCANKEY_VOID 0x8000000000000000
#define SCANKEY_NULL 0x0000000000000000
#define SCANKEY_TAB 0x0000000000000009
#define SCANKEY_ENTER 0x000000000000000a
#define SCANKEY_ESC 0x000000000000001b
#define SCANKEY_PLUS 0x000000000000002b
#define SCANKEY_MINUS 0x000000000000002d
#define SCANKEY_UP 0x0000000000415b1b
#define SCANKEY_DOWN 0x0000000000425b1b
#define SCANKEY_RIGHT 0x0000000000435b1b
#define SCANKEY_LEFT 0x0000000000445b1b
#define SCANKEY_HOME 0x0000000000485b1b
#define SCANKEY_END 0x0000000000465b1b
#define SCANKEY_F1 0x0000000000504f1b
#define SCANKEY_F2 0x0000000000514f1b
#define SCANKEY_F3 0x0000000000524f1b
#define SCANKEY_F4 0x0000000000534f1b
#define SCANKEY_F10 0x0000000031325b1b
#define SCANKEY_SHIFT_TAB 0x00000000005a5b1b
#define SCANKEY_PGUP 0x000000007e355b1b
#define SCANKEY_PGDW 0x000000007e365b1b
#define SCANKEY_PERCENT 0x0000000000000025
#define SCANKEY_SHIFT_a 0x0000000000000041
#define SCANKEY_SHIFT_d 0x0000000000000044
#define SCANKEY_SHIFT_i 0x0000000000000049
#define SCANKEY_SHIFT_m 0x000000000000004d
#define SCANKEY_SHIFT_q 0x0000000000000051
#define SCANKEY_SHIFT_s 0x0000000000000053
#define SCANKEY_SHIFT_v 0x0000000000000056
#define SCANKEY_SHIFT_w 0x0000000000000057
#define SCANKEY_SHIFT_z 0x000000000000005a
#define SCANKEY_a 0x0000000000000061
#define SCANKEY_b 0x0000000000000062
#define SCANKEY_c 0x0000000000000063
#define SCANKEY_d 0x0000000000000064
#define SCANKEY_e 0x0000000000000065
#define SCANKEY_f 0x0000000000000066
#define SCANKEY_g 0x0000000000000067
#define SCANKEY_h 0x0000000000000068
#define SCANKEY_i 0x0000000000000069
#define SCANKEY_k 0x000000000000006b
#define SCANKEY_l 0x000000000000006c
#define SCANKEY_m 0x000000000000006d
#define SCANKEY_n 0x000000000000006e
#define SCANKEY_o 0x000000000000006f
#define SCANKEY_p 0x0000000000000070
#define SCANKEY_q 0x0000000000000071
#define SCANKEY_r 0x0000000000000072
#define SCANKEY_s 0x0000000000000073
#define SCANKEY_t 0x0000000000000074
#define SCANKEY_u 0x0000000000000075
#define SCANKEY_v 0x0000000000000076
#define SCANKEY_w 0x0000000000000077
#define SCANKEY_x 0x0000000000000078
#define SCANKEY_z 0x000000000000007a
#define SCANCON_HOME 0x000000007e315b1b
#define SCANCON_END 0x000000007e345b1b
#define SCANCON_F1 0x00000000415b5b1b
#define SCANCON_F2 0x00000000425b5b1b
#define SCANCON_F3 0x00000000435b5b1b
#define SCANCON_F4 0x00000000445b5b1b
#define SCANCON_SHIFT_TAB 0x000000000000091b
#define SORTBY_STATE 0x400000000000000e
#define SORTBY_RTIME 0x400000000000000d
#define SORTBY_UTIME 0x400000000000000c
#define SORTBY_STIME 0x400000000000000b
#define SORTBY_PID 0x400000000000000a
#define SORTBY_COMM 0x4000000000000009
#define BOXKEY_EIST 0x3000000000000004
#define BOXKEY_EIST_OFF 0x3000000000000005
#define BOXKEY_EIST_ON 0x3000000000000006
#define BOXKEY_C1E 0x3000000000000008
#define BOXKEY_C1E_OFF 0x3000000000000009
#define BOXKEY_C1E_ON 0x300000000000000a
#define BOXKEY_TURBO 0x3000000000000010
#define BOXKEY_TURBO_OFF 0x3000000000000011
#define BOXKEY_TURBO_ON 0x3000000000000012
#define BOXKEY_C1A 0x3000000000000020
#define BOXKEY_C1A_OFF 0x3000000000000021
#define BOXKEY_C1A_ON 0x3000000000000022
#define BOXKEY_C3A 0x3000000000000040
#define BOXKEY_C3A_OFF 0x3000000000000041
#define BOXKEY_C3A_ON 0x3000000000000042
#define BOXKEY_C1U 0x3000000000000080
#define BOXKEY_C1U_OFF 0x3000000000000081
#define BOXKEY_C1U_ON 0x3000000000000082
#define BOXKEY_C3U 0x3000000000000100
#define BOXKEY_C3U_OFF 0x3000000000000101
#define BOXKEY_C3U_ON 0x3000000000000102
#define BOXKEY_PKGCST 0x3000000000000200
#define BOXKEY_PKGCST_C0 0x3000000000000201
#define BOXKEY_PKGCST_C1 0x3000000000000211
#define BOXKEY_PKGCST_C2 0x3000000000000221
#define BOXKEY_PKGCST_C3 0x3000000000000231
#define BOXKEY_PKGCST_C6 0x3000000000000261
#define BOXKEY_PKGCST_C7 0x3000000000000271
#define BOXKEY_IOMWAIT 0x3000000000000400
#define BOXKEY_IOMWAIT_OFF 0x3000000000000401
#define BOXKEY_IOMWAIT_ON 0x3000000000000402
#define BOXKEY_IORCST 0x3000000000000800
#define BOXKEY_IORCST_C0 0x3000000000000801
#define BOXKEY_IORCST_C3 0x3000000000000831
#define BOXKEY_IORCST_C4 0x3000000000000841
#define BOXKEY_IORCST_C6 0x3000000000000861
#define BOXKEY_IORCST_C7 0x3000000000000871
#define BOXKEY_ODCM 0x3000000000001000
#define BOXKEY_ODCM_OFF 0x3000000000001001
#define BOXKEY_ODCM_ON 0x3000000000001002
#define BOXKEY_DUTYCYCLE 0x3000000000002000
#define BOXKEY_ODCM_DC00 0x3000000000002001
#define BOXKEY_ODCM_DC01 0x3000000000002011
#define BOXKEY_ODCM_DC02 0x3000000000002021
#define BOXKEY_ODCM_DC03 0x3000000000002031
#define BOXKEY_ODCM_DC04 0x3000000000002041
#define BOXKEY_ODCM_DC05 0x3000000000002051
#define BOXKEY_ODCM_DC06 0x3000000000002061
#define BOXKEY_ODCM_DC07 0x3000000000002071
#define BOXKEY_ODCM_DC08 0x3000000000002081
#define BOXKEY_ODCM_DC09 0x3000000000002091
#define BOXKEY_ODCM_DC10 0x30000000000020a1
#define BOXKEY_ODCM_DC11 0x30000000000020b1
#define BOXKEY_ODCM_DC12 0x30000000000020c1
#define BOXKEY_ODCM_DC13 0x30000000000020d1
#define BOXKEY_ODCM_DC14 0x30000000000020e1
#define TRACK_TASK 0x2000000000000000
#define TRACK_MASK 0x0000000000007fff
int GetKey(SCANKEY *scan, struct timespec *tsec)
{
struct pollfd fds = {.fd = STDIN_FILENO, .events = POLLIN};
int rp = 0, rz = 0;
if ((rp=ppoll(&fds, 1, tsec, NULL)) > 0)
if (fds.revents == POLLIN) {
size_t lc = fread(&scan->key, 1, 8, stdin);
for (rz = lc; rz < 8; rz++)
scan->code[rz] = 0;
}
return(rp);
}
typedef struct {
int width,
height;
} SCREEN_SIZE;
SCREEN_SIZE GetScreenSize(void)
{
SCREEN_SIZE _screenSize = {.width = 0, .height = 0};
struct winsize ts;
ioctl(STDIN_FILENO, TIOCGWINSZ, &ts);
_screenSize.width = (int) ts.ws_col;
_screenSize.height = (int) ts.ws_row;
return(_screenSize);
}
unsigned int Dec2Digit(unsigned int decimal, unsigned int thisDigit[])
{
memset(thisDigit, 0, 9 * sizeof(unsigned int));
unsigned int j = 9;
while (decimal > 0) {
thisDigit[--j] = decimal % 10;
decimal /= 10;
}
return(9 - j);
}
void printv( void(*OutFunc)(unsigned long long key, char *output),
unsigned long long key, CUINT width, int tab, char *fmt, ...)
{
const char *indent[2][4] = {
{"", "|", "|- ", " |- "},
{"", " ", " ", " "}
};
char *line = malloc(width + 1);
va_list ap;
va_start(ap, fmt);
vsprintf(line, fmt, ap);
if (OutFunc == NULL)
printf("%s%s%.*s\n", indent[0][tab], line,
(int)(width - strlen(line) - strlen(indent[0][tab])), hSpace);
else {
char *output = malloc(width + 1);
sprintf(output, "%s%s%.*s", indent[1][tab], line,
(int)(width - strlen(line) - strlen(indent[1][tab])), hSpace);
OutFunc(key, output);
free(output);
}
va_end(ap);
free(line);
}
void SysInfoCPUID(SHM_STRUCT *Shm, CUINT width,
void(*OutFunc)(unsigned long long key, char *output) )
{
char format[] = "%08x:%08x%.*s%08x %08x %08x %08x";
unsigned int cpu;
for (cpu = 0; cpu < Shm->Proc.CPU.Count; cpu++) {
if (OutFunc == NULL) {
printv(OutFunc, SCANKEY_NULL, width, 0,
"CPU #%-2u function" \
" EAX EBX ECX EDX",
cpu);
} else {
printv(OutFunc, SCANKEY_NULL, width, 0, "CPU #%-2u", cpu);
}
printv(OutFunc, SCANKEY_NULL, width, 2, format,
0x00000000, 0x00000000,
4, hSpace,
Shm->Cpu[cpu].Query.StdFunc.LargestStdFunc,
Shm->Cpu[cpu].Query.StdFunc.BX,
Shm->Cpu[cpu].Query.StdFunc.CX,
Shm->Cpu[cpu].Query.StdFunc.DX);
printv(OutFunc, SCANKEY_NULL, width, 3,
"Largest Standard Function=%08x",
Shm->Cpu[cpu].Query.StdFunc.LargestStdFunc);
printv(OutFunc, SCANKEY_NULL, width, 2, format,
0x80000000, 0x00000000,
4, hSpace,
Shm->Cpu[cpu].Query.ExtFunc.LargestExtFunc,
Shm->Cpu[cpu].Query.ExtFunc.EBX,
Shm->Cpu[cpu].Query.ExtFunc.ECX,
Shm->Cpu[cpu].Query.ExtFunc.EDX);
printv(OutFunc, SCANKEY_NULL, width, 3,
"Largest Extended Function=%08x",
Shm->Cpu[cpu].Query.ExtFunc.LargestExtFunc);
int i;
for (i = 0; i < CPUID_MAX_FUNC; i++)
if (Shm->Cpu[cpu].CpuID[i].func) {
printv(OutFunc, SCANKEY_NULL, width, 2, format,
Shm->Cpu[cpu].CpuID[i].func,
Shm->Cpu[cpu].CpuID[i].sub,
4, hSpace,
Shm->Cpu[cpu].CpuID[i].reg[0],
Shm->Cpu[cpu].CpuID[i].reg[1],
Shm->Cpu[cpu].CpuID[i].reg[2],
Shm->Cpu[cpu].CpuID[i].reg[3]);
}
}
}
void SysInfoProc(SHM_STRUCT *Shm,
CUINT width,
void(*OutFunc)(unsigned long long key, char *output))
{
char *str = malloc(width + 1), symb[2][2] = {{'[', ']'}, {'<', '>'}};
int activeCores, boost = 0;
void PrintBoost(char *pfx, int _boost, int syc, unsigned long long _key)
{
if (Shm->Proc.Boost[_boost] > 0) {
sprintf(str, "%.*s""%s""%.*s""%7.2f""%.*s""%c%4d %c",
17, hSpace, pfx, 3, hSpace,
(double) ( Shm->Proc.Boost[_boost]
* Shm->Cpu[0].Clock.Hz) / 1000000.0,
20, hSpace,
symb[syc][0],
Shm->Proc.Boost[_boost],
symb[syc][1]);
printv(OutFunc, _key, width, 0, str);
}
}
printv(OutFunc, SCANKEY_NULL, width, 0, "Processor%.*s[%s]",
width - 11 - strlen(Shm->Proc.Brand), hSpace, Shm->Proc.Brand);
printv(OutFunc, SCANKEY_NULL, width, 2, "Architecture%.*s[%s]",
width - 17 - strlen(Shm->Proc.Architecture), hSpace,
Shm->Proc.Architecture);
printv(OutFunc, SCANKEY_NULL, width, 2, "Vendor ID%.*s[%s]",
width - 14 - strlen(Shm->Proc.Features.Info.Vendor.ID), hSpace,
Shm->Proc.Features.Info.Vendor.ID);
printv(OutFunc, SCANKEY_NULL, width, 2, "Signature%.*s[%1X%1X_%1X%1X]",
width - 19, hSpace,
Shm->Proc.Features.Std.EAX.ExtFamily,
Shm->Proc.Features.Std.EAX.Family,
Shm->Proc.Features.Std.EAX.ExtModel,
Shm->Proc.Features.Std.EAX.Model);
printv(OutFunc, SCANKEY_NULL, width, 2, "Stepping%.*s[%5u]",
width - 18, hSpace, Shm->Proc.Features.Std.EAX.Stepping);
printv(OutFunc, SCANKEY_NULL, width, 2, "Microcode%.*s[%5u]",
width - 19, hSpace, Shm->Cpu[0].Query.Microcode);
printv(OutFunc, SCANKEY_NULL, width, 2, "Online CPU%.*s[%2u/%-2u]",
width - 20, hSpace, Shm->Proc.CPU.OnLine, Shm->Proc.CPU.Count);
printv(OutFunc, SCANKEY_NULL, width, 2, "Base Clock%.*s[%5.1f]",
width - 20, hSpace, Shm->Cpu[0].Clock.Hz / 1000000.0);
printv(OutFunc, SCANKEY_NULL, width, 2, "TDP Limited%.*s[%6s]",
width - 22, hSpace,
Shm->Proc.Features.TDP_Unlock ? "UNLOCK" : "LOCK");
printv(OutFunc, SCANKEY_NULL, width, 2, "Ratio Limited%.*s[%6s]",
width - 24, hSpace,
Shm->Proc.Features.Ratio_Unlock ? "UNLOCK" : "LOCK");
printv(OutFunc, SCANKEY_NULL, width, 2, "Frequency%.*s(Mhz)%.*sRatio",
12, hSpace, 23 - (OutFunc == NULL), hSpace);
PrintBoost("Min", 0, 0, SCANKEY_NULL);
PrintBoost("Max", 1, 0, SCANKEY_NULL);
printv(OutFunc, SCANKEY_NULL, width, 2, "Turbo Boost");
for (boost = LAST_BOOST, activeCores = 1;
boost > LAST_BOOST - Shm->Proc.Features.SpecTurboRatio;
boost--, activeCores++)
{
char pfx[4];
sprintf(pfx, "%2dC", activeCores);
PrintBoost(pfx,boost,Shm->Proc.Features.Ratio_Unlock,SCANKEY_NULL);
}
free(str);
}
void SysInfoISA(SHM_STRUCT *Shm,
CUINT width,
void(*OutFunc)(unsigned long long key, char *output))
{
size_t len = 0;
char *row[2] = {malloc(width + 1), malloc(width + 1)},
*str = malloc(width + 1),
*pad = NULL;
/* Row Mark */
len = 3;
len += sprintf(str, "3DNow!/Ext [%c,%c]",
Shm->Proc.Features.ExtInfo.EDX._3DNow ? 'Y' : 'N',
Shm->Proc.Features.ExtInfo.EDX._3DNowEx ? 'Y' : 'N');
strcpy(row[0], str);
len += sprintf(str, "%.*s", 11, hSpace);
strcat(row[0], str);
len += sprintf(str, "AES [%c]",
Shm->Proc.Features.Std.ECX.AES ? 'Y' : 'N');
strcat(row[0], str);
len += sprintf(str, "%.*s", 6, hSpace);
strcat(row[0], str);
len += sprintf(str, "AVX/AVX2 [%c/%c]",
Shm->Proc.Features.Std.ECX.AVX ? 'Y' : 'N',
Shm->Proc.Features.ExtFeature.EBX.AVX2 ? 'Y' : 'N');
strcat(row[0], str);
len += sprintf(str, "BMI1/BMI2 [%c/%c]",
Shm->Proc.Features.ExtFeature.EBX.BMI1 ? 'Y' : 'N',
Shm->Proc.Features.ExtFeature.EBX.BMI2 ? 'Y' : 'N');
pad = realloc(pad, (width - len) + 1);
sprintf(pad, "%.*s", (int)(width - len), hSpace);
strcat(row[0], pad);
strcat(row[0], str);
printv(OutFunc, SCANKEY_NULL, width, 2, row[0]);
/* Row Mark */
len = 3;
len += sprintf(str, "CLFSH [%c]",
Shm->Proc.Features.Std.EDX.CLFSH ? 'Y' : 'N');
strcpy(row[0], str);
len += sprintf(str, "%.*s", 10, hSpace);
strcat(row[0], str);
len += sprintf(str, "CMOV [%c]",
Shm->Proc.Features.Std.EDX.CMOV ? 'Y' : 'N');
strcat(row[0], str);
len += sprintf(str, "%.*s", 7, hSpace);
strcat(row[0], str);
len += sprintf(str, "CMPXCH8 [%c]",
Shm->Proc.Features.Std.EDX.CMPXCH8 ? 'Y' : 'N');
strcat(row[0], str);
len += sprintf(str, "CMPXCH16 [%c]",
Shm->Proc.Features.Std.ECX.CMPXCH16 ? 'Y' : 'N');
pad = realloc(pad, (width - len) + 1);
sprintf(pad, "%.*s", (int)(width - len), hSpace);
strcat(row[0], pad);
strcat(row[0], str);
printv(OutFunc, SCANKEY_NULL, width, 2, row[0]);
/* Row Mark */
len = 3;
len += sprintf(str, "F16C [%c]",
Shm->Proc.Features.Std.ECX.F16C ? 'Y' : 'N');
strcpy(row[0], str);
len += sprintf(str, "%.*s", 11, hSpace);
strcat(row[0], str);
len += sprintf(str, "FPU [%c]",
Shm->Proc.Features.Std.EDX.FPU ? 'Y' : 'N');
strcat(row[0], str);
len += sprintf(str, "%.*s", 10, hSpace);
strcat(row[0], str);
len += sprintf(str, "FXSR [%c]",
Shm->Proc.Features.Std.EDX.FXSR ? 'Y' : 'N');
strcat(row[0], str);
len += sprintf(str, "LAHF/SAHF [%c]",
Shm->Proc.Features.ExtInfo.ECX.LAHFSAHF ? 'Y' : 'N');
pad = realloc(pad, (width - len) + 1);
sprintf(pad, "%.*s", (int)(width - len), hSpace);
strcat(row[0], pad);
strcat(row[0], str);
printv(OutFunc, SCANKEY_NULL, width, 2, row[0]);
/* Row Mark */
len = 3;
len += sprintf(str, "MMX/Ext [%c/%c]",
Shm->Proc.Features.Std.EDX.MMX ? 'Y' : 'N',
Shm->Proc.Features.ExtInfo.EDX.MMX_Ext ? 'Y' : 'N');
strcpy(row[0], str);
len += sprintf(str, "%.*s", 7, hSpace);
strcat(row[0], str);
len += sprintf(str, "MONITOR [%c]",
Shm->Proc.Features.Std.ECX.MONITOR ? 'Y' : 'N');
strcat(row[0], str);
len += sprintf(str, "%.*s", 9, hSpace);
strcat(row[0], str);
len += sprintf(str, "MOVBE [%c]",
Shm->Proc.Features.Std.ECX.MOVBE ? 'Y' : 'N');
strcat(row[0], str);
len += sprintf(str, "PCLMULDQ [%c]",
Shm->Proc.Features.Std.ECX.PCLMULDQ ? 'Y' : 'N');
pad = realloc(pad, (width - len) + 1);
sprintf(pad, "%.*s", (int)(width - len), hSpace);
strcat(row[0], pad);
strcat(row[0], str);
printv(OutFunc, SCANKEY_NULL, width, 2, row[0]);
/* Row Mark */
len = 3;
len += sprintf(str, "POPCNT [%c]",
Shm->Proc.Features.Std.ECX.POPCNT ? 'Y' : 'N');
strcpy(row[0], str);
len += sprintf(str, "%.*s", 8, hSpace);
strcat(row[0], str);
len += sprintf(str, "RDRAND [%c]",
Shm->Proc.Features.Std.ECX.RDRAND ? 'Y' : 'N');
strcat(row[0], str);
len += sprintf(str, "%.*s", 8, hSpace);
strcat(row[0], str);
len += sprintf(str, "RDTSCP [%c]",
Shm->Proc.Features.ExtInfo.EDX.RDTSCP ? 'Y' : 'N');
strcat(row[0], str);
len += sprintf(str, "SEP [%c]",
Shm->Proc.Features.Std.EDX.SEP ? 'Y' : 'N');
pad = realloc(pad, (width - len) + 1);
sprintf(pad, "%.*s", (int)(width - len), hSpace);
strcat(row[0], pad);
strcat(row[0], str);
printv(OutFunc, SCANKEY_NULL, width, 2, row[0]);
/* Row Mark */
len = 3;
len += sprintf(str, "SSE [%c]",
Shm->Proc.Features.Std.EDX.SSE ? 'Y' : 'N');
strcpy(row[0], str);
len += sprintf(str, "%.*s", 10, hSpace);
strcat(row[0], str);
len += sprintf(str, "SSE2 [%c]",
Shm->Proc.Features.Std.EDX.SSE2 ? 'Y' : 'N');
strcat(row[0], str);
len += sprintf(str, "%.*s", 10, hSpace);
strcat(row[0], str);
len += sprintf(str, "SSE3 [%c]",
Shm->Proc.Features.Std.ECX.SSE3 ? 'Y' : 'N');
strcat(row[0], str);
len += sprintf(str, "SSSE3 [%c]",
Shm->Proc.Features.Std.ECX.SSSE3 ? 'Y' : 'N');
pad = realloc(pad, (width - len) + 1);
sprintf(pad, "%.*s", (int)(width - len), hSpace);
strcat(row[0], pad);
strcat(row[0], str);
printv(OutFunc, SCANKEY_NULL, width, 2, row[0]);
/* Row Mark */
len = 3;
len += sprintf(str, "SSE4.1/4A [%c/%c]",
Shm->Proc.Features.Std.ECX.SSE41 ? 'Y' : 'N',
Shm->Proc.Features.ExtInfo.ECX.SSE4A ? 'Y' : 'N');
strcpy(row[0], str);
len += sprintf(str, "%.*s", 8, hSpace);
strcat(row[0], str);
len += sprintf(str, "SSE4.2 [%c]",
Shm->Proc.Features.Std.ECX.SSE42 ? 'Y' : 'N');
strcat(row[0], str);
len += sprintf(str, "%.*s", 7, hSpace);
strcat(row[0], str);
len += sprintf(str, "SYSCALL [%c]",
Shm->Proc.Features.ExtInfo.EDX.SYSCALL ? 'Y' : 'N');
pad = realloc(pad, (width - len) + 1);
sprintf(pad, "%.*s", (int)(width - len), hSpace);
strcat(row[0], str);
strcat(row[0], pad);
printv(OutFunc, SCANKEY_NULL, width, 2, row[0]);
free(row[0]);
free(row[1]);
free(str);
free(pad);
}
void SysInfoFeatures( SHM_STRUCT *Shm, CUINT width,
void(*OutFunc)(unsigned long long key, char *output) )
{
/* Section Mark */
const char *TSC[] = {
"Missing",
"Variant",
"Invariant"
};
const char *x2APIC[] = {
"Missing",
" xAPIC",
" x2APIC"
};
/* Section Mark */
printv(OutFunc, SCANKEY_NULL, width, 2,
"1 GB Pages Support%.*s1GB-PAGES [%7s]",
width - 42, hSpace,
powered(Shm->Proc.Features.ExtInfo.EDX.PG_1GB));
printv(OutFunc, SCANKEY_NULL, width, 2,
"100 MHz multiplier Control%.*s100MHzSteps [%7s]",
width - 52, hSpace,
powered(Shm->Proc.Features.AdvPower.EDX._100MHz));
printv(OutFunc, SCANKEY_NULL, width, 2,
"Advanced Configuration & Power Interface" \
"%.*sACPI [%7s]",
width - 59, hSpace,
powered(Shm->Proc.Features.Std.EDX.ACPI // Intel
| Shm->Proc.Features.AdvPower.EDX.HwPstate) ); // AMD
printv(OutFunc, SCANKEY_NULL, width, 2,
"Advanced Programmable Interrupt Controller" \
"%.*sAPIC [%7s]",
width - 61, hSpace, powered(Shm->Proc.Features.Std.EDX.APIC));
printv(OutFunc, SCANKEY_NULL, width, 2,
"Core Multi-Processing%.*sCMP Legacy [%7s]",
width - 46, hSpace,
powered(Shm->Proc.Features.ExtInfo.ECX.MP_Mode));
printv(OutFunc, SCANKEY_NULL, width, 2,
"L1 Data Cache Context ID%.*sCNXT-ID [%7s]",
width - 46,hSpace, powered(Shm->Proc.Features.Std.ECX.CNXT_ID));
printv(OutFunc, SCANKEY_NULL, width, 2,
"Direct Cache Access%.*sDCA [%7s]",
width - 37, hSpace, powered(Shm->Proc.Features.Std.ECX.DCA));
printv(OutFunc, SCANKEY_NULL, width, 2,
"Debugging Extension%.*sDE [%7s]",
width - 36, hSpace, powered(Shm->Proc.Features.Std.EDX.DE));
printv(OutFunc, SCANKEY_NULL, width, 2,
"Debug Store & Precise Event Based Sampling" \
"%.*sDS, PEBS [%7s]",
width - 65,hSpace, powered(Shm->Proc.Features.Std.EDX.DS_PEBS));
printv(OutFunc, SCANKEY_NULL, width, 2,
"CPL Qualified Debug Store%.*sDS-CPL [%7s]",
width - 46, hSpace, powered(Shm->Proc.Features.Std.ECX.DS_CPL));
printv(OutFunc, SCANKEY_NULL, width, 2,
"64-Bit Debug Store%.*sDTES64 [%7s]",
width - 39, hSpace, powered(Shm->Proc.Features.Std.ECX.DTES64));
printv(OutFunc, SCANKEY_NULL, width, 2,
"Fast-String Operation%.*sFast-Strings [%7s]",
width - 48,hSpace,
powered(Shm->Proc.Features.ExtFeature.EBX.FastStrings));
printv(OutFunc, SCANKEY_NULL, width, 2,
"Fused Multiply Add%.*sFMA|FMA4 [%7s]",
width - 41, hSpace,
powered( Shm->Proc.Features.Std.ECX.FMA
| Shm->Proc.Features.ExtInfo.ECX.FMA4 ));
printv(OutFunc, SCANKEY_NULL, width, 2,
"Hardware Lock Elision%.*sHLE [%7s]",
width - 39, hSpace,
powered(Shm->Proc.Features.ExtFeature.EBX.HLE));
printv(OutFunc, SCANKEY_NULL, width, 2,
"Long Mode 64 bits%.*sIA64|LM [%7s]",
width - 39, hSpace,
powered(Shm->Proc.Features.ExtInfo.EDX.IA64));
printv(OutFunc, SCANKEY_NULL, width, 2,
"LightWeight Profiling%.*sLWP [%7s]",
width - 39, hSpace,
powered(Shm->Proc.Features.ExtInfo.ECX.LWP));
printv(OutFunc, SCANKEY_NULL, width, 2,
"Machine-Check Architecture%.*sMCA [%7s]",
width - 44, hSpace,
powered(Shm->Proc.Features.Std.EDX.MCA));
printv(OutFunc, SCANKEY_NULL, width, 2,
"Model Specific Registers%.*sMSR [%7s]",
width - 42, hSpace, powered(Shm->Proc.Features.Std.EDX.MSR));
printv(OutFunc, SCANKEY_NULL, width, 2,
"Memory Type Range Registers%.*sMTRR [%7s]",
width - 46, hSpace, powered(Shm->Proc.Features.Std.EDX.MTRR));
printv(OutFunc, SCANKEY_NULL, width, 2,
"OS-Enabled Ext. State Management%.*sOSXSAVE [%7s]",
width - 54,hSpace, powered(Shm->Proc.Features.Std.ECX.OSXSAVE));
printv(OutFunc, SCANKEY_NULL, width, 2,
"Physical Address Extension%.*sPAE [%7s]",
width - 44, hSpace, powered(Shm->Proc.Features.Std.EDX.PAE));
printv(OutFunc, SCANKEY_NULL, width, 2,
"Page Attribute Table%.*sPAT [%7s]",
width - 38, hSpace, powered(Shm->Proc.Features.Std.EDX.PAT));
printv(OutFunc, SCANKEY_NULL, width, 2,
"Pending Break Enable%.*sPBE [%7s]",
width - 38, hSpace, powered(Shm->Proc.Features.Std.EDX.PBE));
printv(OutFunc, SCANKEY_NULL, width, 2,
"Process Context Identifiers%.*sPCID [%7s]",
width - 46, hSpace, powered(Shm->Proc.Features.Std.ECX.PCID));
printv(OutFunc, SCANKEY_NULL, width, 2,
"Perfmon and Debug Capability%.*sPDCM [%7s]",
width - 47, hSpace, powered(Shm->Proc.Features.Std.ECX.PDCM));
printv(OutFunc, SCANKEY_NULL, width, 2,
"Page Global Enable%.*sPGE [%7s]",
width - 36, hSpace, powered(Shm->Proc.Features.Std.EDX.PGE));
printv(OutFunc, SCANKEY_NULL, width, 2,
"Page Size Extension%.*sPSE [%7s]",
width - 37, hSpace, powered(Shm->Proc.Features.Std.EDX.PSE));
printv(OutFunc, SCANKEY_NULL, width, 2,
"36-bit Page Size Extension%.*sPSE36 [%7s]",
width - 46, hSpace, powered(Shm->Proc.Features.Std.EDX.PSE36));
printv(OutFunc, SCANKEY_NULL, width, 2,
"Processor Serial Number%.*sPSN [%7s]",
width - 41, hSpace, powered(Shm->Proc.Features.Std.EDX.PSN));
printv(OutFunc, SCANKEY_NULL, width, 2,
"Restricted Transactional Memory%.*sRTM [%7s]",
width - 49, hSpace,
powered(Shm->Proc.Features.ExtFeature.EBX.RTM));
printv(OutFunc, SCANKEY_NULL, width, 2,
"Safer Mode Extensions%.*sSMX [%7s]",
width - 39, hSpace, powered(Shm->Proc.Features.Std.ECX.SMX));
printv(OutFunc, SCANKEY_NULL, width, 2,
"Self-Snoop%.*sSS [%7s]",
width - 27, hSpace, powered(Shm->Proc.Features.Std.EDX.SS));
printv(OutFunc, SCANKEY_NULL, width, 2,
"Time Stamp Counter%.*sTSC [%9s]",
width - 36, hSpace, TSC[Shm->Proc.Features.InvariantTSC]);
printv(OutFunc, SCANKEY_NULL, width, 2,
"Time Stamp Counter Deadline%.*sTSC-DEADLINE [%7s]",
width - 54,hSpace, powered(Shm->Proc.Features.Std.ECX.TSCDEAD));
printv(OutFunc, SCANKEY_NULL, width, 2,
"Virtual Mode Extension%.*sVME [%7s]",
width - 40, hSpace, powered(Shm->Proc.Features.Std.EDX.VME));
printv(OutFunc, SCANKEY_NULL, width, 2,
"Virtual Machine Extensions%.*sVMX [%7s]",
width - 44, hSpace, powered(Shm->Proc.Features.Std.ECX.VMX));
printv(OutFunc, SCANKEY_NULL, width, 2,
"Extended xAPIC Support%.*sx2APIC [%7s]",
width - 43, hSpace, x2APIC[Shm->Cpu[0].Topology.MP.x2APIC]);
printv(OutFunc, SCANKEY_NULL, width, 2,
"Execution Disable Bit Support%.*sXD-Bit [%7s]",
width - 50, hSpace,
powered(Shm->Proc.Features.ExtInfo.EDX.XD_Bit));
printv(OutFunc, SCANKEY_NULL, width, 2,
"XSAVE/XSTOR States%.*sXSAVE [%7s]",
width - 38, hSpace, powered(Shm->Proc.Features.Std.ECX.XSAVE));
printv(OutFunc, SCANKEY_NULL, width, 2,
"xTPR Update Control%.*sxTPR [%7s]",
width - 38, hSpace, powered(Shm->Proc.Features.Std.ECX.xTPR));
}
void SysInfoTech(SHM_STRUCT *Shm, CUINT width,
void(*OutFunc)(unsigned long long key, char *output) )
{
const unsigned int
isTurbo = !BITWISEXOR(LOCKLESS, Shm->Proc.TurboBoost,
Shm->Proc.TurboBoost_Mask),
isEIST = !BITWISEXOR(LOCKLESS, Shm->Proc.SpeedStep,
Shm->Proc.SpeedStep_Mask);
/* Section Mark */
printv(OutFunc, SCANKEY_NULL, width, 2,
"Hyper-Threading%.*sHTT [%3s]", width - 33, hSpace,
enabled(Shm->Proc.Features.HyperThreading));
printv(OutFunc, BOXKEY_EIST, width, 2,
"SpeedStep%.*sEIST <%3s>", width - 28, hSpace,
enabled(isEIST));
printv(OutFunc, SCANKEY_NULL, width, 2,
"PowerNow!%.*sPowerNow [%3s]", width - 32, hSpace,
enabled(Shm->Proc.PowerNow == 0b11)); // VID + FID
printv(OutFunc, SCANKEY_NULL, width, 2,
"Dynamic Acceleration%.*sIDA [%3s]", width - 38, hSpace,
enabled(Shm->Proc.Features.Power.EAX.TurboIDA));
printv(OutFunc, BOXKEY_TURBO, width, 2,
"Turbo Boost/CPB%.*sTURBO <%3s>", width - 35, hSpace,
enabled(isTurbo|Shm->Proc.Features.AdvPower.EDX.CPB));
printv(OutFunc, SCANKEY_NULL, width, 2,
"Virtualization%.*sHYPERVISOR [%3s]", width - 39, hSpace,
enabled(Shm->Proc.Features.Std.ECX.Hyperv));
}
void SysInfoPerfMon( SHM_STRUCT *Shm, CUINT width,
void(*OutFunc)(unsigned long long key, char *output) )
{
const unsigned int
isC1E = !BITWISEXOR(LOCKLESS,Shm->Proc.C1E, Shm->Proc.C1E_Mask),
isC3A = !BITWISEXOR(LOCKLESS,Shm->Proc.C3A, Shm->Proc.C3A_Mask),
isC1A = !BITWISEXOR(LOCKLESS,Shm->Proc.C1A, Shm->Proc.C1A_Mask),
isC3U = !BITWISEXOR(LOCKLESS,Shm->Proc.C3U, Shm->Proc.C3U_Mask),
isC1U = !BITWISEXOR(LOCKLESS,Shm->Proc.C1U, Shm->Proc.C1U_Mask);
/* Section Mark */
printv(OutFunc, SCANKEY_NULL, width, 2,
"Version%.*sPM [%3d]",
width - 24, hSpace, Shm->Proc.PM_version);