-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathTurionPowerControl.cpp
1592 lines (1290 loc) · 45.6 KB
/
TurionPowerControl.cpp
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
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <assert.h>
//This program is supposed to compile with GCC under Linux x86/x86-64 platforms
//and with Microsoft Visual C++ 2005/2008 under Windows x86/x86-64 platforms
#include <string.h>
//Main include for processor definitions:
#include "Processor.h"
//Include for processor families:
#include "Griffin.h"
#include "K10Processor.h"
#include "Brazos.h"
#include "Llano.h"
#include "Interlagos.h"
#include "config.h"
#include "scaler.h"
#include "source_version.h"
#include "version.h"
#include "sysdep.h"
//Checks for all modules available and returns the right Processor object
//for current system. If there isn't a valid module, returns null
Processor *getSupportedProcessor () {
if (K10Processor::isProcessorSupported()) {
return (class Processor *)new K10Processor ();
}
if (Griffin::isProcessorSupported()) {
return (class Processor *)new Griffin();
}
if (Brazos::isProcessorSupported()) {
return (class Processor *)new Brazos();
}
if (Llano::isProcessorSupported()) {
return (class Processor *)new Llano();
}
if (Interlagos::isProcessorSupported()) {
return (class Processor *)new Interlagos();
}
/*TODO: This code should be moved somewhere else than here:
*
#ifdef _WIN32
printf ("-> Check that you are running the program with administrative privileges.\n");
#endif
#ifdef __GNUC__
printf ("-> Check that you are running the program as root\n");
printf ("-> Also check that cpuid and msr modules are properly loaded\n");
printf ("-> and and functioning (see the included manual, Chapter 5)\n");
#endif
*/
return NULL;
}
void processorStatus (Processor *p) {
PState ps(0);
int i,k,j;
int cores=p->getProcessorCores();
int pstates=p->getPowerStates();
int nodes=p->getProcessorNodes();
int boost = p->getBoostStates();
printf ("Main processor is %s\n",p->getProcessorStrId());
printf ("\tFamily: 0x%x\t\tModel: 0x%x\t\tStepping: 0x%x\n",p->getSpecFamilyBase(),p->getSpecModel(),p->getSpecStepping());
printf ("\tExtended Family: 0x%x\tExtended Model: 0x%x\n",p->getSpecFamilyExtended(),p->getSpecModelExtended());
printf ("\tPackage Type: 0x%x\tBrandId: 0x%x\t\n",p->getSpecPkgType(),p->getSpecBrandId());
printf ("Machine has %d nodes\n",p->getProcessorNodes());
printf ("Processor has %d cores\n",cores);
printf ("Processor has %d p-states\n",pstates);
printf ("Processor has %d boost states\n",boost);
printf ("\nPower States table:\n");
for (j = 0; j < nodes; j++)
{
for (i = 0; i < cores; i++)
{
printf("-- Node: %d Core %d\n", j, i);
for (k = 0; k < pstates; k++)
{
ps.setPState(k);
p->setCore(i);
p->setNode(j);
printf("core %d ", i);
printf("pstate %d ", k);
if (boost > 0 && k < boost)
printf("(pb%d) - ",k);
else if (boost > 0 && k >= boost)
printf("(p%d) - ",(k - boost));
else
printf("(p%d) - ",k);
if (!(p->getBoost()) && k < boost)
{
printf ("Boost PState Disabled");
}
else
{
printf("En:%d ", p->pStateEnabled(ps.getPState()));
printf("VID:%d ", p->getVID(ps.getPState()));
if (p->getFID(ps.getPState())!=-1) printf("FID:%0.0f ", p->getFID(ps.getPState()));
if (p->getDID(ps.getPState())!=-1) printf("DID:%0.2f ", p->getDID(ps.getPState()));
printf("Freq:%d ", p->getFrequency(ps.getPState()));
printf("VCore:%0.4f", p->getVCore(ps.getPState()));
}
printf("\n");
}
}
}
for (j=0;j<p->getProcessorNodes();j++)
{
p->setNode (j);
p->setCore (0);
printf ("\n --- Node %u:\n", p->getNode());
printf ("Processor Maximum PState: ");
if (p->getMaximumPState().getPState() == 0 )
printf ("unsupported feature\n");
else
printf ("%d\n",p->getMaximumPState().getPState());
printf ("Processor Startup PState: %d\n", p->startupPState());
printf ("Processor Maximum Operating Frequency: ");
if (p->maxCPUFrequency()==0)
printf ("No maximum defined. Unlocked multiplier.\n");
else
printf ("%d MHz\n", p->maxCPUFrequency());
printf ("\nMinimum allowed VID: %d (%0.4fV) - Maximum allowed VID %d (%0.4fV)\n", p->minVID(),
p->convertVIDtoVcore(p->minVID()),p->maxVID(),p->convertVIDtoVcore(p->maxVID()));
if (p->getAltVID() != -1) {
printf ("Processor AltVID: %d (%0.4fV)\n",p->getAltVID(),p->convertVIDtoVcore(p->getAltVID()));
}
}
}
void processorTempMonitoring (Processor *p) {
unsigned int node, core;
unsigned int nexttick;
printf("Detected processor: %s\n", p->getProcessorStrId());
printf("Machine has %d nodes\n", p->getProcessorNodes());
printf("Processor has %d cores\n", p->getProcessorCores());
printf("Processor has %d p-states\n", p->getPowerStates());
printf("Processor has %d boost states\n", p->getBoostStates());
printf("Processor temperature slew rate:");
switch (p->getTctlMaxDiff()) {
case 0:
printf("slewing disabled\n");
break;
case 1:
printf("1.0°C\n");
break;
case 2:
printf("3.0°C\n");
break;
case 3:
printf("9.0°C\n");
break;
default:
printf("unknown\n");
break;
}
printf ("\nTemperature table (monitoring):\n");
nexttick = GetTickCount();
while (1)
{
int sleepval;
for (node = 0; node < p->getProcessorNodes(); node++)
{
printf("\nNode %d\t", node);
for (core = 0; core < p->getProcessorCores(); core++)
{
p->setNode(node);
p->setCore(core);
printf("C%d:%d\t", core, p->getTctlRegister());
}
}
printf("\n");
if (fflush(stdout) == EOF) {
break;
}
nexttick += 1000;
sleepval = nexttick - GetTickCount();
if (sleepval < 0) {
nexttick -= sleepval;
sleepval = 0;
}
Sleep(sleepval);
};
return;
}
void processorTempStatus(Processor *p) {
unsigned int node, core;
printf("Detected processor: %s\n", p->getProcessorStrId());
printf("Machine has %d nodes\n", p->getProcessorNodes());
printf("Processor has %d cores\n", p->getProcessorCores());
printf("Processor has %d p-states\n", p->getPowerStates());
printf("Processor has %d boost states\n", p->getBoostStates());
printf("Processor temperature slew rate:");
switch (p->getTctlMaxDiff()) {
case 0:
printf("slewing disabled\n");
break;
case 1:
printf("1.0°C\n");
break;
case 2:
printf("3.0°C\n");
break;
case 3:
printf("9.0°C\n");
break;
default:
printf("unknown\n");
break;
}
printf ("\nTemperature table:\n");
for (node = 0; node < p->getProcessorNodes(); node++) {
printf("Node %d\t", node);
for (core = 0; core < p->getProcessorCores(); core++) {
p->setNode(node);
p->setCore(core);
printf("C%d:%d\t", core, p->getTctlRegister());
}
printf("\n");
}
return;
}
void printUsage (const char *name) {
printf ("\nUsage: %s [options]\n", name);
printf ("Options:\n\n");
printf ("\t ----- Various information about processor states\n\n");
printf (" -l\n\tLists power states\n\n");
printf (" -spec\n\tLists detailed processor family specifications\n\n");
printf (" -dram\n\tLists detailed DRAM timings\n\n");
printf (" -htc\n\tShows Hardware Thermal Control status\n\n");
printf (" -htstatus\n\tShows Hypertransport status\n\n");
printf ("\t ----- PState VID, FID, DID manipulation -----\n\n");
printf (" -node <nodeId>\n\tSet the active operating node. Use \"all\" to affect all nodes\n\tin the system. "
"By default all nodes in the system are selected.\n\tIf your system has a single processor you can safely ignore\n\t"
"this switch\n\n");
printf (" -core <coreId>\n\tSet the active operating core. Use \"all\" to affect all cores\n\tin the current node.\n\t"
"By default all cores in the system are selected.\n\n");
printf (" -en <pstateId>\n\tEnables a specified (pStateId) for active cores and active nodes\n\n");
printf (" -di <pstateId>\n\tDisables a specified (pStateId) for active cores and active nodes\n\n");
printf (" -fo <pstateId>\n\tForce a pstate transition to specified (pStateId) for active cores\n\tand active nodes\n\n");
printf (" -psmax <pstateMaxId>\n\tSet maximum Power State for active nodes\n\n");
printf (" -bst <numBoostStates>\n\tSet the number of boosted states in an unlocked processor\n\n");
printf (" -set <commands>\n\tUseful switch to set frequency and voltage without manual\n");
printf ("\tmanipulation of FID, DID and VID values. Check the documentation\n");
printf ("\tfor some easy example usages\n\n");
printf ("\t ----- Voltage control -----\n\n");
printf (" -slamtime <value>\n -altvidslamtime <value>\n\tSet, on active nodes, vsSlamTime or vsAltVIDSlamTime for transitions \n");
printf ("\tto AltVID state. It is the the stabilization time between\n");
printf ("\ta SVI Voltage command and a FID change. Values range from 0 to 7 \n");
printf ("\tand corresponds to:\n\n");
printf ("\t\t0=10us\n\t\t1=20us\n\t\t2=30us\n\t\t3=40us\n\t\t4=60us\n\t\t5=100us\n\t\t6=200us\n\t\t7=500us\n\n");
printf (" -gettdp\n\tReturns the current TDP for the processor\n\n");
printf (" -rampuptime <value>\n -rampdowntime <value>\n\tSet, on active nodes, the StepUpTime or StepDownTime. \n");
printf ("\tIt is not documented in Turion (Family 11h) datasheet, but only in\n");
printf ("\tPhenom datasheet (Family 10h) with referring to desktop and mobile\n");
printf ("\tprocessors. Values range from 0 to 15 and corresponds to:\n\n");
printf ("\t\t0=400ns\t1=300ns\t2=200ns\t3=100ns\n\t\t4=90ns\t5=80ns\t6=70ns\t7=60ns\n\t\t8=50ns\t9=45ns\t10=40ns\t11=35ns\n\t\t");
printf ("12=30ns\t13=25ns\t14=20ns\t15=15ns\n\n");
printf ("\t ----- Northbridge (IMC) features -----\n\n");
printf ("\t For family 11h processors:\n");
printf (" -nbvid <vidId>\n\tSet Northbridge VID for active nodes\n\n");
printf ("\t For family 10h processors:\n");
printf (" -nbvid <pstateId> <vidId>\n\tSet Northbridge VID to pstateId for all cores on active nodes\n\n");
printf (" -nbdid <pstateId> <didId>\n\tSet divisor didID to northbridge for all cores on active nodes.\n\t");
printf ("Usually causes the processor to lock to slowest pstate. Accepted\n\tvalues are 0 and 1)\n\n");
printf (" -nbfid <fidId>\n\tSet northbridge frequency ID to fidId\n\n");
printf ("\t ----- Processor Temperature monitoring -----\n\n");
printf (" -temp \n\tShow temperature registers data\n\n");
printf (" -mtemp \n\tCostantly monitors processor temperatures\n\n");
printf ("\t ----- Hardware Thermal Control -----\n\n");
printf (" -htc\n\tShow information about Hardware Thermal Control status for\n\tactive nodes\n\n");
printf (" -htcenable\n\tEnables HTC features for active nodes\n\n");
printf (" -htcdisable\n\tDisables HTC features for active nodes\n\n");
printf (" -htctemplimit <degrees>\n\tSet HTC high temperature limit for active nodes\n\n");
printf (" -htchystlimit <degrees>\n\tSet HTC hysteresis (exits from HTC state) temperature\n\tlimit for active nodes\n\n");
printf (" -altvid <vid>\n\tSet voltage identifier for AltVID status for active nodes, invoked in \n\tlow-consumption mode or during HTC active status\n\n");
printf ("\t ----- PSI_L bit -----\n\n");
printf (" -psienable\n\tEnables PSI_L bit for active nodes for improved Power Regulation\n\twith low loads\n\n");
printf (" -psidisable\n\tDisables PSI_L bit for active nodes\n\n");
printf (" -psithreshold <vid>\n\tSets a specified VID as a threshold for active nodes.\n\tWhen processor goes ");
printf ("in a pstate with higher or equal vid, \n\tVRM is instructed");
printf (" to go in power management mode\n\n");
printf ("\t ----- Hypertransport Link -----\n\n");
printf (" -htstatus\n\tShows Hypertransport status\n\n");
printf (" -htset <link> <speedReg>\n\tSet the hypertransport link frequency register\n\n");
printf ("\t ----- Various and others -----\n\n");
printf (" -c1eenable\n\tSets C1E on Cmp Halt bit enabled for active nodes and active cores\n\n");
printf (" -c1edisable\n\tSets C1E on Cmp Halt bit disabled for active nodes and active cores\n\n");
printf (" -boostenable\n\tEnable Boost for supported processors\n\n");
printf (" -boostdisable\n\tDisable Boost for supported processors\n\n");
printf ("\t ----- Performance Counters -----\n\n");
printf (" -pcgetinfo\n\tShows various informations about Performance Counters\n\n");
printf (" -pcgetvalue <counter>\n\tShows the raw value of a specific performance counter\n\tslot of a specific core\n\n");
printf (" -perf-cpuusage\n\tCostantly monitors CPU Usage using performance counters\n\n");
printf (" -perf-fpuusage\n\tCostantly monitors FPU Usage using performance counters\n\n");
printf (" -perf-dcma\n\tCostantly monitors Data Cache Misaligned Accesses\n\n");
printf ("\t ----- Daemon Mode -----\n\n");
printf (" -autorecall\n\tSet up daemon mode, autorecalling command line parameters\n\tevery 60 seconds\n\n");
printf (" -scaler\n\tSet up CPU Scaler mode. In this mode TurionPowerControl takes\n\t");
printf ("care of CPU power management and power state transitions.\n\t");
printf ("OS Scaler must be disable for reliable operation\n\n");
printf (" -CM\n\tEnabled Costant Monitor of frequency, voltage and pstate. Also will\n\t");
printf ("show every anomalous transition over pstate maximum register (useful to\n\t");
printf ("report pstate 6/7 anomalous transitions)\n\n");
printf ("\t ----- Configuration File -----\n\n");
printf (" -cfgfile <file.cfg>\n\tImports configuration from a text based configuration file\n\t");
printf ("(see the attached example configuration file for details)\n\n");
}
//Function used by parseSetCommand to obtain a valid integer.
//The integer is put in output pointer if the function returns false (false
//means no error)
//Instead, if there is an error (no valid integer, a string where there
//should be a value, ...) , the function returns true.
static bool requireInteger (int argc, const char **argv, int offset, int *output) {
const char *argument;
long value;
char *end;
if (offset >= argc)
return true;
argument = argv[offset];
if (argument[0] == '\0')
return true;
value = strtol(argument, &end, 0);
if (end[0] != '\0')
return true;
if (value < INT_MIN)
return true;
if (value > INT_MAX)
return true;
*output = value;
return false;
}
//Equal as above, but with unsigned integer values
static bool requireUnsignedInteger (int argc, const char **argv, int offset, unsigned int *output) {
int value;
if (requireInteger(argc, argv, offset, &value))
return true;
if (value < 0)
return true;
*output = value;
return false;
}
//Function used by parseSetCommand to obtain a valid float.
//The float is put in output pointer if the function returns false (false
//means no error)
//Instead, if there is an error (no valid float, a string where there
//should be a value, ...) , the function returns true.
bool requireFloat (int argc, const char **argv, int offset, float *output) {
const char *argument;
double value;
char *end;
if (offset >= argc)
return true;
argument = argv[offset];
if (argument[0] == '\0')
return true;
value = strtod(argument, &end);
if (end[0] != '\0')
return true;
*output = value;
return false;
}
//Simple method used by parseSetCommand to show some useful and tidy informations.
#define PRINT_STAT_FLAG_NONE 0x00
#define PRINT_STAT_FLAG_CORE 0x01
#define PRINT_STAT_FLAG_NODE 0x02
#define PRINT_STAT_FLAG_PSTATE 0x04
#define PRINT_STAT_FLAG_ALL 0x07
void print_stat(Processor *p, PState ps, const char *what, float value, int flags)
{
if (flags & PRINT_STAT_FLAG_NODE) {
if (p->getNode() == p->ALL_NODES)
printf("All nodes ");
else
printf("Node: %d ", p->getNode());
}
if (flags & PRINT_STAT_FLAG_CORE) {
if (p->getCore() == p->ALL_CORES)
printf("all cores ");
else
printf("core: %d ", p->getCore());
}
if (flags & PRINT_STAT_FLAG_PSTATE) {
printf("pstate: %d ", ps.getPState());
}
printf("-- set %s to %0.4f", what, value);
}
#define PARSE_WRONG_FORMAT -1 /* known argument but used incorrectly */
#define PARSE_UNEXPECTED_ARGUMENT -2 /* unexpected argument -- relieve control*/
#define PARSE_UNKNOWN_ARGUMENT -3 /* unknown argument */
static int parseSingleSetSubcommand(Processor *p, int argc, const char **argv, int argcOffset, int consume_dash, PState *ps)
{
const char *currentCommand = argv[argcOffset];
assert(consume_dash == 1 || consume_dash == 0);
if (consume_dash) {
if (currentCommand[0] != '-') {
return PARSE_UNEXPECTED_ARGUMENT;
}
currentCommand++;
} else {
if (currentCommand[0] == '-') {
return PARSE_UNEXPECTED_ARGUMENT;
}
}
/*
* Following section will alter operating pstate. By default, pstate 0 is set
*/
if (strcmp (currentCommand, "pstate") == 0 ||
strcmp (currentCommand, "ps") == 0) {
unsigned int pstate;
argcOffset++;
if (argv[argcOffset] == NULL) {
printf("ERROR: %s requires an argument\n", currentCommand - consume_dash);
return PARSE_WRONG_FORMAT;
}
if (requireUnsignedInteger(argc, argv, argcOffset, &pstate)) {
printf("ERROR: invalid pstate -- %s\n", argv[argcOffset]);
return PARSE_WRONG_FORMAT;
}
if (pstate >= p->getPowerStates()) {
printf("ERROR: pstate must be in 0-%u range\n", p->getPowerStates() - 1);
return PARSE_WRONG_FORMAT;
}
ps->setPState(pstate);
argcOffset++;
return argcOffset;
}
/*
* Following section will alter operating core. Default setting is core=all
*/
if (strcmp(currentCommand, "core") == 0) {
unsigned int core;
argcOffset++;
if (argv[argcOffset] == NULL) {
printf("ERROR: %s requires an argument\n", currentCommand - consume_dash);
return PARSE_WRONG_FORMAT;
}
if (strcmp(argv[argcOffset], "all") != 0) {
if (requireUnsignedInteger(argc, argv, argcOffset, &core)) {
printf("ERROR: invalid core -- %s\n", argv[argcOffset]);
return PARSE_WRONG_FORMAT;
}
if (core >= p->getProcessorCores()) {
printf("ERROR: core must be in 0-%u range\n", p->getProcessorCores() - 1);
return PARSE_WRONG_FORMAT;
}
p->setCore(core);
} else {
p->setCore(p->ALL_CORES);
}
argcOffset++;
return argcOffset;
}
/*
* Following section will alter operating node. Default setting is node=all
*/
if (strcmp(currentCommand, "node") == 0) {
unsigned int node;
argcOffset++;
if (argv[argcOffset] == NULL) {
printf("ERROR: %s requires an argument\n", currentCommand - consume_dash);
return PARSE_WRONG_FORMAT;
}
if (strcmp(argv[argcOffset], "all") != 0) {
if (requireUnsignedInteger(argc, argv, argcOffset, &node)) {
printf("ERROR: invalid node -- %s\n", argv[argcOffset]);
return PARSE_WRONG_FORMAT;
}
if (node >= p->getProcessorNodes()) {
printf("ERROR: node must be in 0-%u range\n", p->getProcessorNodes() - 1);
return PARSE_WRONG_FORMAT;
}
p->setNode(node);
} else {
p->setNode(p->ALL_NODES);
}
argcOffset++;
return argcOffset;
}
/*
* Following section will set a new frequency for selected pstate/core/node
*/
if (strcmp(currentCommand, "freq") == 0 ||
strcmp(currentCommand, "f") == 0 ||
strcmp(currentCommand, "frequency") == 0) {
unsigned int frequency;
argcOffset++;
if (argv[argcOffset] == NULL) {
printf("ERROR: %s requires an argument\n", currentCommand - consume_dash);
return PARSE_WRONG_FORMAT;
}
if (requireUnsignedInteger(argc, argv, argcOffset, &frequency)) {
printf("ERROR: invalid frequency -- %s\n", argv[argcOffset]);
return PARSE_WRONG_FORMAT;
}
p->setFrequency(*ps, frequency);
print_stat(p, *ps, "frequency", frequency, PRINT_STAT_FLAG_ALL);
if (p->getFrequency(*ps) != frequency)
printf(" (actual: %d)", p->getFrequency(*ps));
printf("\n");
argcOffset++;
return argcOffset;
}
/*
* Following section will set a new core voltage for operating pstate/core/node
*/
if (strcmp(currentCommand, "vcore") == 0 ||
strcmp(currentCommand, "vc") == 0 ||
strcmp(currentCommand, "voltage") == 0) {
float voltage;
argcOffset++;
if (argv[argcOffset] == NULL) {
printf("ERROR: %s requires an argument\n", currentCommand - consume_dash);
return PARSE_WRONG_FORMAT;
}
if (requireFloat(argc, argv, argcOffset, &voltage)) {
printf("ERROR: invalid vcore -- %s\n", argv[argcOffset]);
return PARSE_WRONG_FORMAT;
}
p->setVCore(*ps, voltage);
print_stat(p, *ps, "core voltage", voltage, PRINT_STAT_FLAG_ALL);
if (p->getVCore(*ps) != voltage)
printf(" (actual: %0.4fV)", p->getVCore(*ps));
printf("\n");
argcOffset++;
return argcOffset;
}
/*
* Following section will set a new northbirdge voltage for operating
* core on operating node
*/
if (strcmp(currentCommand, "nbvoltage") == 0 ||
strcmp(currentCommand, "nbv") == 0 ||
strcmp(currentCommand, "nbvolt") == 0) {
float nbvoltage;
argcOffset++;
if (argv[argcOffset] == NULL) {
printf("ERROR: %s requires an argument\n", currentCommand - consume_dash);
return PARSE_WRONG_FORMAT;
}
if (requireFloat(argc, argv, argcOffset, &nbvoltage)) {
printf("ERROR: invald nbvoltage -- %s\n", argv[argcOffset]);
return PARSE_WRONG_FORMAT;
}
//Since family 10h and family 11h differs on northbridge voltage handling, we have to make a difference
//here. On family 10h changing northbridge voltage changes just to the pstate the user is manipulating
//instead on family 11h it changes the northbridge voltage independently of the pstate the user is
//manipulating
if (p->getProcessorIdentifier() == PROCESSOR_10H_FAMILY) {
p->setNBVid(*ps, p->convertVcoretoVID(nbvoltage));
print_stat(p, *ps, "nbvoltage", nbvoltage, PRINT_STAT_FLAG_NODE | PRINT_STAT_FLAG_PSTATE);
if (p->convertVIDtoVcore(p->getNBVid(*ps)) != nbvoltage)
printf(" (actual: %0.4fV)", p->convertVIDtoVcore(p->getNBVid(*ps)));
printf("\n");
argcOffset++;
return argcOffset;
}
if (p->getProcessorIdentifier() == TURION_ULTRA_ZM_FAMILY ||
p->getProcessorIdentifier() == TURION_X2_RM_FAMILY ||
p->getProcessorIdentifier() == ATHLON_X2_QL_FAMILY ||
p->getProcessorIdentifier() == SEMPRON_SI_FAMILY) {
p->setNBVid(p->convertVcoretoVID(nbvoltage));
print_stat(p, *ps, "nbvoltage", nbvoltage, PRINT_STAT_FLAG_NODE);
if (p->convertVIDtoVcore(p->getNBVid()) != nbvoltage)
printf (" (actual: %0.4fV)", p->convertVIDtoVcore(p->getNBVid()));
printf("\n");
argcOffset++;
return argcOffset;
}
printf("ERROR: %s -- not supported\n", currentCommand - consume_dash);
return PARSE_WRONG_FORMAT;
}
if (strcmp(currentCommand, "fid") == 0) {
float fid;
argcOffset++;
if (argv[argcOffset] == NULL) {
printf("ERROR: %s requires an argument\n", currentCommand - consume_dash);
return PARSE_WRONG_FORMAT;
}
if (requireFloat(argc, argv, argcOffset, &fid)) {
printf("ERROR: invald fid -- %s\n", argv[argcOffset]);
return PARSE_WRONG_FORMAT;
}
p->setFID(*ps, fid);
print_stat(p, *ps, "FID", fid, PRINT_STAT_FLAG_ALL);
if (p->getFID(*ps) != fid)
printf (" (actual: %0.0f)", p->getFID(*ps));
printf("\n");
argcOffset++;
return argcOffset;
}
if (strcmp(currentCommand, "did") == 0) {
float did;
argcOffset++;
if (argv[argcOffset] == NULL) {
printf("ERROR: %s requires an argument\n", currentCommand - consume_dash);
return PARSE_WRONG_FORMAT;
}
if (requireFloat(argc, argv, argcOffset, &did)) {
printf("ERROR: invald did -- %s\n", argv[argcOffset]);
return PARSE_WRONG_FORMAT;
}
p->setDID(*ps, did);
print_stat(p, *ps, "DID", did, PRINT_STAT_FLAG_ALL);
if (p->getDID(*ps) != did)
printf (" (actual: %0.2f)", p->getDID(*ps));
printf("\n");
argcOffset++;
return argcOffset;
}
if (strcmp(currentCommand, "vid") == 0) {
unsigned int vid;
argcOffset++;
if (argv[argcOffset] == NULL) {
printf("ERROR: %s requires an argument\n", currentCommand - consume_dash);
return PARSE_WRONG_FORMAT;
}
if (requireUnsignedInteger(argc, argv, argcOffset, &vid)) {
printf("ERROR: invalid frequency -- %s\n", argv[argcOffset]);
return PARSE_WRONG_FORMAT;
}
p->setVID(*ps, vid);
print_stat(p, *ps, "VID", vid, PRINT_STAT_FLAG_ALL);
if (p->getVID(*ps) != vid)
printf (" (actual: %d)", p->getVID(*ps));
printf("\n");
argcOffset++;
return argcOffset;
}
return PARSE_UNKNOWN_ARGUMENT;
}
//This procedure parse the -set switch
int parseSetCommand (Processor *p, int argc, const char **argv, int argcOffset) {
PState ps(0);
const char *currentCommand;
int rv;
p->setCore(p->ALL_CORES);
p->setNode(p->ALL_NODES);
do {
//If we exceed the commands, get out of the loop
if (argcOffset>=argc) break;
currentCommand=argv[argcOffset];
rv = parseSingleSetSubcommand(p, argc, argv, argcOffset, 0, &ps);
if (rv == PARSE_UNKNOWN_ARGUMENT) {
printf("ERROR: unknown set sub-command -- %s\n", currentCommand);
return PARSE_WRONG_FORMAT;
}
if (rv == PARSE_WRONG_FORMAT) {
return PARSE_WRONG_FORMAT;
}
if (rv == PARSE_UNEXPECTED_ARGUMENT) {
break;
}
argcOffset = rv;
} while (true);
return argcOffset;
}
#ifdef _WIN32
# ifdef _WIN64
# define _TARGET_OS "Windows 64-bit"
# else
# define _TARGET_OS "Windows 32-bit"
# endif
#else
# ifdef __amd64
# define _TARGET_OS "Linux 64-bit"
# else
# define _TARGET_OS "Linux 32-bit"
# endif
#endif
int main (int argc,const char **argv) {
int argvStep;
unsigned int currentNode;
unsigned int currentCore;
Processor *processor;
PState ps(0);
bool autoRecall=false;
int autoRecallTimer=60;
CfgManager *cfgInstance;
int errorLine;
Scaler *scaler;
int rv;
int parsed = 0;
int parsed_set = 0;
printf ("TurionPowerControl %s (%s) %s\n", _VERSION, _SOURCE_VERSION, _TARGET_OS);
printf ("Turion Power States Optimization and Control - by blackshard\n\n");
if (argc<2) {
printUsage(argv[0]);
return 0;
}
if (initializeCore() == false) {
return -1;
}
processor=getSupportedProcessor ();
if (processor==NULL) {
printf ("No supported processor detected, sorry.\n");
return -2;
}
//Initializes currentNode and currentCore
currentNode=processor->ALL_NODES;
currentCore=processor->ALL_CORES;
//Initializes the scaler based on the processor found in the system
scaler=new Scaler (processor);
for (argvStep = 1; ; argvStep++) {
if (argvStep == argc) {
if (!autoRecall)
break;
//Autorecall feature set argvStep back to 1 when it reaches end
printf("Autorecall activated. Timeout: %d seconds\n", autoRecallTimer);
Sleep(autoRecallTimer * 1000);
printf("Autorecalling...\n");
argvStep = 1;
}
//Reinitializes the processor object for active node and core in the system
processor->setNode(currentNode);
processor->setCore(currentCore);
//printf ("Parsing argument %d %s\n",argvStep,argv[argvStep]);
if (parsed_set) {
printf("ERROR: -set can only be used exclusively\n");
break;
}
parsed++;
//List power states action
if (strcmp(argv[argvStep], "-l") == 0) {
processorStatus (processor);
continue;
}
//Set the current operational node
if (strcmp(argv[argvStep], "-node") == 0) {
unsigned int thisNode;
const char *arg = argv[argvStep + 1];
if (arg == NULL) {
printf("-node requires an argument\n");
break;
}
if (strcmp(arg, "all") != 0) {
if (requireUnsignedInteger(argc, argv, argvStep + 1, &thisNode)) {
printf("ERROR: invalid -node -- %s\n", arg);
break;
}
if (thisNode >= processor->getProcessorNodes()) {
printf("ERROR: node must be in 0-%u range\n", processor->getProcessorNodes() - 1);
break;
}
currentNode = thisNode;
} else {
currentNode = processor->ALL_NODES;
}
argvStep++;
continue;
}
//Set the current operational core
if (strcmp(argv[argvStep], "-core") == 0) {
unsigned int thisCore;
const char *arg = argv[argvStep + 1];
if (arg == NULL) {
printf("ERROR: -core requires an argument\n");
break;
}
if (strcmp(arg, "all") != 0) {
if (requireUnsignedInteger(argc, argv, argvStep + 1, &thisCore)) {
printf("ERROR: invalid -core -- %s\n", arg);
break;
}
if (thisCore >= processor->getProcessorCores()) {
printf("ERROR: core must be in 0-%u range\n", processor->getProcessorCores() - 1);
break;
}
currentCore = thisCore;
} else {
currentCore = processor->ALL_CORES;
}
argvStep++;
continue;
}
rv = parseSingleSetSubcommand(processor, argc, argv, argvStep, 1, &ps);
if (rv >= 0) {
printf("\n");
argvStep = rv - 1;
continue;
}
if (rv == PARSE_WRONG_FORMAT) {
break;
}
if (strcmp(argv[argvStep], "-nbvid") == 0) {
unsigned int nbvid;
if (argv[argvStep + 1] == NULL) {
printf ("ERROR: -nbvid requires an argument\n");
break;
}
if (requireUnsignedInteger(argc, argv, argvStep + 1, &nbvid)) {
printf("ERROR: invalid NBVid -- %s\n", argv[argvStep + 1]);
break;
}
if (processor->getProcessorIdentifier() == PROCESSOR_10H_FAMILY) {
processor->setNBVid (ps, nbvid);
print_stat(processor, ps, "nbvid", nbvid, PRINT_STAT_FLAG_NODE | PRINT_STAT_FLAG_PSTATE);
if (processor->getNBVid(ps) != nbvid)
printf(" (actual: %d)", processor->getNBVid(ps));
printf("\n\n");
} else {
processor->setNBVid (nbvid);
print_stat(processor, ps, "nbvid", nbvid, PRINT_STAT_FLAG_NODE);
if (processor->getNBVid() != nbvid)
printf(" (actual: %d)", processor->getNBVid());
printf("\n\n");
}
argvStep = argvStep + 1;
continue;
}
if (strcmp(argv[argvStep], "-nbdid") == 0) {
if (processor->getProcessorIdentifier() == PROCESSOR_10H_FAMILY) {
unsigned int nbdid;
if (argv[argvStep + 1] == NULL) {
printf("ERROR: -nbdid requires an argument\n");
break;