Skip to content

Commit 19a8432

Browse files
committed
Merge pull request intel#4 from kanojs/fix-all-option
Fix -a option for rdmsr/wrmsr.
2 parents d9a630d + f2502a1 commit 19a8432

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

rdmsr.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ static const struct option long_options[] = {
5050
{0, 0, 0, 0}
5151
};
5252
static const char short_options[] = "hVxXdoruc0ap:f:";
53+
static int doing_for_all = 0;
5354

5455
/* Number of decimal digits for a certain number of bits */
5556
/* (int) ceil(log(2^n)/log(10)) */
@@ -196,6 +197,7 @@ int main(int argc, char *argv[])
196197
reg = strtoul(argv[optind], NULL, 0);
197198

198199
if (cpu == -1) {
200+
doing_for_all = 1;
199201
rdmsr_on_all_cpus(reg);
200202
}
201203
else
@@ -216,6 +218,8 @@ void rdmsr_on_cpu(uint32_t reg, int cpu)
216218
fd = open(msr_file_name, O_RDONLY);
217219
if (fd < 0) {
218220
if (errno == ENXIO) {
221+
if (doing_for_all)
222+
return;
219223
fprintf(stderr, "rdmsr: No CPU %d\n", cpu);
220224
exit(2);
221225
} else if (errno == EIO) {
@@ -350,7 +354,10 @@ void rdmsr_on_cpu(uint32_t reg, int cpu)
350354
if (width < 1)
351355
width = 1;
352356

353-
if (pat)
357+
if (pat) {
358+
if (doing_for_all)
359+
printf("CPU %d: ", cpu);
354360
printf(pat, width, data);
361+
}
355362
return;
356363
}

wrmsr.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ static const struct option long_options[] = {
3939
{0, 0, 0, 0}
4040
};
4141
static const char short_options[] = "hVap:";
42+
static int doing_for_all = 0;
4243

4344
const char *program;
4445

@@ -123,6 +124,7 @@ int main(int argc, char *argv[])
123124
reg = strtoul(argv[optind++], NULL, 0);
124125

125126
if (cpu == -1) {
127+
doing_for_all = 1;
126128
wrmsr_on_all_cpus(reg, argc - optind, &argv[optind]);
127129
} else {
128130
wrmsr_on_cpu(reg, cpu, argc - optind, &argv[optind]);
@@ -141,6 +143,8 @@ void wrmsr_on_cpu(uint32_t reg, int cpu, int valcnt, char *regvals[])
141143
fd = open(msr_file_name, O_WRONLY);
142144
if (fd < 0) {
143145
if (errno == ENXIO) {
146+
if (doing_for_all)
147+
return;
144148
fprintf(stderr, "wrmsr: No CPU %d\n", cpu);
145149
exit(2);
146150
} else if (errno == EIO) {

0 commit comments

Comments
 (0)