Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'tools-release' of git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux-idle-2.6

* 'tools-release' of git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux-idle-2.6:
tools: turbostat: style updates
tools: turbostat: fix bitwise and operand

+98 -102
+98 -102
tools/power/x86/turbostat/turbostat.c
··· 72 72 73 73 int num_cpus; 74 74 75 - typedef struct per_cpu_counters { 75 + struct counters { 76 76 unsigned long long tsc; /* per thread */ 77 77 unsigned long long aperf; /* per thread */ 78 78 unsigned long long mperf; /* per thread */ ··· 88 88 int pkg; 89 89 int core; 90 90 int cpu; 91 - struct per_cpu_counters *next; 92 - } PCC; 91 + struct counters *next; 92 + }; 93 93 94 - PCC *pcc_even; 95 - PCC *pcc_odd; 96 - PCC *pcc_delta; 97 - PCC *pcc_average; 94 + struct counters *cnt_even; 95 + struct counters *cnt_odd; 96 + struct counters *cnt_delta; 97 + struct counters *cnt_average; 98 98 struct timeval tv_even; 99 99 struct timeval tv_odd; 100 100 struct timeval tv_delta; ··· 125 125 return msr; 126 126 } 127 127 128 - void print_header() 128 + void print_header(void) 129 129 { 130 130 if (show_pkg) 131 131 fprintf(stderr, "pkg "); ··· 160 160 putc('\n', stderr); 161 161 } 162 162 163 - void dump_pcc(PCC *pcc) 163 + void dump_cnt(struct counters *cnt) 164 164 { 165 - fprintf(stderr, "package: %d ", pcc->pkg); 166 - fprintf(stderr, "core:: %d ", pcc->core); 167 - fprintf(stderr, "CPU: %d ", pcc->cpu); 168 - fprintf(stderr, "TSC: %016llX\n", pcc->tsc); 169 - fprintf(stderr, "c3: %016llX\n", pcc->c3); 170 - fprintf(stderr, "c6: %016llX\n", pcc->c6); 171 - fprintf(stderr, "c7: %016llX\n", pcc->c7); 172 - fprintf(stderr, "aperf: %016llX\n", pcc->aperf); 173 - fprintf(stderr, "pc2: %016llX\n", pcc->pc2); 174 - fprintf(stderr, "pc3: %016llX\n", pcc->pc3); 175 - fprintf(stderr, "pc6: %016llX\n", pcc->pc6); 176 - fprintf(stderr, "pc7: %016llX\n", pcc->pc7); 177 - fprintf(stderr, "msr0x%x: %016llX\n", extra_msr_offset, pcc->extra_msr); 165 + fprintf(stderr, "package: %d ", cnt->pkg); 166 + fprintf(stderr, "core:: %d ", cnt->core); 167 + fprintf(stderr, "CPU: %d ", cnt->cpu); 168 + fprintf(stderr, "TSC: %016llX\n", cnt->tsc); 169 + fprintf(stderr, "c3: %016llX\n", cnt->c3); 170 + fprintf(stderr, "c6: %016llX\n", cnt->c6); 171 + fprintf(stderr, "c7: %016llX\n", cnt->c7); 172 + fprintf(stderr, "aperf: %016llX\n", cnt->aperf); 173 + fprintf(stderr, "pc2: %016llX\n", cnt->pc2); 174 + fprintf(stderr, "pc3: %016llX\n", cnt->pc3); 175 + fprintf(stderr, "pc6: %016llX\n", cnt->pc6); 176 + fprintf(stderr, "pc7: %016llX\n", cnt->pc7); 177 + fprintf(stderr, "msr0x%x: %016llX\n", extra_msr_offset, cnt->extra_msr); 178 178 } 179 179 180 - void dump_list(PCC *pcc) 180 + void dump_list(struct counters *cnt) 181 181 { 182 - printf("dump_list 0x%p\n", pcc); 182 + printf("dump_list 0x%p\n", cnt); 183 183 184 - for (; pcc; pcc = pcc->next) 185 - dump_pcc(pcc); 184 + for (; cnt; cnt = cnt->next) 185 + dump_cnt(cnt); 186 186 } 187 187 188 - void print_pcc(PCC *p) 188 + void print_cnt(struct counters *p) 189 189 { 190 190 double interval_float; 191 191 192 192 interval_float = tv_delta.tv_sec + tv_delta.tv_usec/1000000.0; 193 193 194 194 /* topology columns, print blanks on 1st (average) line */ 195 - if (p == pcc_average) { 195 + if (p == cnt_average) { 196 196 if (show_pkg) 197 197 fprintf(stderr, " "); 198 198 if (show_core) ··· 262 262 putc('\n', stderr); 263 263 } 264 264 265 - void print_counters(PCC *cnt) 265 + void print_counters(struct counters *counters) 266 266 { 267 - PCC *pcc; 267 + struct counters *cnt; 268 268 269 269 print_header(); 270 270 271 271 if (num_cpus > 1) 272 - print_pcc(pcc_average); 272 + print_cnt(cnt_average); 273 273 274 - for (pcc = cnt; pcc != NULL; pcc = pcc->next) 275 - print_pcc(pcc); 274 + for (cnt = counters; cnt != NULL; cnt = cnt->next) 275 + print_cnt(cnt); 276 276 277 277 } 278 278 279 279 #define SUBTRACT_COUNTER(after, before, delta) (delta = (after - before), (before > after)) 280 280 281 - 282 - int compute_delta(PCC *after, PCC *before, PCC *delta) 281 + int compute_delta(struct counters *after, 282 + struct counters *before, struct counters *delta) 283 283 { 284 284 int errors = 0; 285 285 int perf_err = 0; ··· 391 391 delta->extra_msr = after->extra_msr; 392 392 if (errors) { 393 393 fprintf(stderr, "ERROR cpu%d before:\n", before->cpu); 394 - dump_pcc(before); 394 + dump_cnt(before); 395 395 fprintf(stderr, "ERROR cpu%d after:\n", before->cpu); 396 - dump_pcc(after); 396 + dump_cnt(after); 397 397 errors = 0; 398 398 } 399 399 } 400 400 return 0; 401 401 } 402 402 403 - void compute_average(PCC *delta, PCC *avg) 403 + void compute_average(struct counters *delta, struct counters *avg) 404 404 { 405 - PCC *sum; 405 + struct counters *sum; 406 406 407 - sum = calloc(1, sizeof(PCC)); 407 + sum = calloc(1, sizeof(struct counters)); 408 408 if (sum == NULL) { 409 409 perror("calloc sum"); 410 410 exit(1); ··· 438 438 free(sum); 439 439 } 440 440 441 - void get_counters(PCC *pcc) 441 + void get_counters(struct counters *cnt) 442 442 { 443 - for ( ; pcc; pcc = pcc->next) { 444 - pcc->tsc = get_msr(pcc->cpu, MSR_TSC); 443 + for ( ; cnt; cnt = cnt->next) { 444 + cnt->tsc = get_msr(cnt->cpu, MSR_TSC); 445 445 if (do_nhm_cstates) 446 - pcc->c3 = get_msr(pcc->cpu, MSR_CORE_C3_RESIDENCY); 446 + cnt->c3 = get_msr(cnt->cpu, MSR_CORE_C3_RESIDENCY); 447 447 if (do_nhm_cstates) 448 - pcc->c6 = get_msr(pcc->cpu, MSR_CORE_C6_RESIDENCY); 448 + cnt->c6 = get_msr(cnt->cpu, MSR_CORE_C6_RESIDENCY); 449 449 if (do_snb_cstates) 450 - pcc->c7 = get_msr(pcc->cpu, MSR_CORE_C7_RESIDENCY); 450 + cnt->c7 = get_msr(cnt->cpu, MSR_CORE_C7_RESIDENCY); 451 451 if (has_aperf) 452 - pcc->aperf = get_msr(pcc->cpu, MSR_APERF); 452 + cnt->aperf = get_msr(cnt->cpu, MSR_APERF); 453 453 if (has_aperf) 454 - pcc->mperf = get_msr(pcc->cpu, MSR_MPERF); 454 + cnt->mperf = get_msr(cnt->cpu, MSR_MPERF); 455 455 if (do_snb_cstates) 456 - pcc->pc2 = get_msr(pcc->cpu, MSR_PKG_C2_RESIDENCY); 456 + cnt->pc2 = get_msr(cnt->cpu, MSR_PKG_C2_RESIDENCY); 457 457 if (do_nhm_cstates) 458 - pcc->pc3 = get_msr(pcc->cpu, MSR_PKG_C3_RESIDENCY); 458 + cnt->pc3 = get_msr(cnt->cpu, MSR_PKG_C3_RESIDENCY); 459 459 if (do_nhm_cstates) 460 - pcc->pc6 = get_msr(pcc->cpu, MSR_PKG_C6_RESIDENCY); 460 + cnt->pc6 = get_msr(cnt->cpu, MSR_PKG_C6_RESIDENCY); 461 461 if (do_snb_cstates) 462 - pcc->pc7 = get_msr(pcc->cpu, MSR_PKG_C7_RESIDENCY); 462 + cnt->pc7 = get_msr(cnt->cpu, MSR_PKG_C7_RESIDENCY); 463 463 if (extra_msr_offset) 464 - pcc->extra_msr = get_msr(pcc->cpu, extra_msr_offset); 464 + cnt->extra_msr = get_msr(cnt->cpu, extra_msr_offset); 465 465 } 466 466 } 467 467 468 - 469 - void print_nehalem_info() 468 + void print_nehalem_info(void) 470 469 { 471 470 unsigned long long msr; 472 471 unsigned int ratio; ··· 513 514 514 515 } 515 516 516 - void free_counter_list(PCC *list) 517 + void free_counter_list(struct counters *list) 517 518 { 518 - PCC *p; 519 + struct counters *p; 519 520 520 521 for (p = list; p; ) { 521 - PCC *free_me; 522 + struct counters *free_me; 522 523 523 524 free_me = p; 524 525 p = p->next; 525 526 free(free_me); 526 527 } 527 - return; 528 528 } 529 529 530 530 void free_all_counters(void) 531 531 { 532 - free_counter_list(pcc_even); 533 - pcc_even = NULL; 532 + free_counter_list(cnt_even); 533 + cnt_even = NULL; 534 534 535 - free_counter_list(pcc_odd); 536 - pcc_odd = NULL; 535 + free_counter_list(cnt_odd); 536 + cnt_odd = NULL; 537 537 538 - free_counter_list(pcc_delta); 539 - pcc_delta = NULL; 538 + free_counter_list(cnt_delta); 539 + cnt_delta = NULL; 540 540 541 - free_counter_list(pcc_average); 542 - pcc_average = NULL; 541 + free_counter_list(cnt_average); 542 + cnt_average = NULL; 543 543 } 544 544 545 - void insert_cpu_counters(PCC **list, PCC *new) 545 + void insert_counters(struct counters **list, 546 + struct counters *new) 546 547 { 547 - PCC *prev; 548 + struct counters *prev; 548 549 549 550 /* 550 551 * list was empty ··· 593 594 */ 594 595 new->next = prev->next; 595 596 prev->next = new; 596 - 597 - return; 598 597 } 599 598 600 - void alloc_new_cpu_counters(int pkg, int core, int cpu) 599 + void alloc_new_counters(int pkg, int core, int cpu) 601 600 { 602 - PCC *new; 601 + struct counters *new; 603 602 604 603 if (verbose > 1) 605 604 printf("pkg%d core%d, cpu%d\n", pkg, core, cpu); 606 605 607 - new = (PCC *)calloc(1, sizeof(PCC)); 606 + new = (struct counters *)calloc(1, sizeof(struct counters)); 608 607 if (new == NULL) { 609 608 perror("calloc"); 610 609 exit(1); ··· 610 613 new->pkg = pkg; 611 614 new->core = core; 612 615 new->cpu = cpu; 613 - insert_cpu_counters(&pcc_odd, new); 616 + insert_counters(&cnt_odd, new); 614 617 615 - new = (PCC *)calloc(1, sizeof(PCC)); 618 + new = (struct counters *)calloc(1, 619 + sizeof(struct counters)); 616 620 if (new == NULL) { 617 621 perror("calloc"); 618 622 exit(1); ··· 621 623 new->pkg = pkg; 622 624 new->core = core; 623 625 new->cpu = cpu; 624 - insert_cpu_counters(&pcc_even, new); 626 + insert_counters(&cnt_even, new); 625 627 626 - new = (PCC *)calloc(1, sizeof(PCC)); 628 + new = (struct counters *)calloc(1, sizeof(struct counters)); 627 629 if (new == NULL) { 628 630 perror("calloc"); 629 631 exit(1); ··· 631 633 new->pkg = pkg; 632 634 new->core = core; 633 635 new->cpu = cpu; 634 - insert_cpu_counters(&pcc_delta, new); 636 + insert_counters(&cnt_delta, new); 635 637 636 - new = (PCC *)calloc(1, sizeof(PCC)); 638 + new = (struct counters *)calloc(1, sizeof(struct counters)); 637 639 if (new == NULL) { 638 640 perror("calloc"); 639 641 exit(1); ··· 641 643 new->pkg = pkg; 642 644 new->core = core; 643 645 new->cpu = cpu; 644 - pcc_average = new; 646 + cnt_average = new; 645 647 } 646 648 647 649 int get_physical_package_id(int cpu) ··· 717 719 { 718 720 printf("turbostat: topology changed, re-initializing.\n"); 719 721 free_all_counters(); 720 - num_cpus = for_all_cpus(alloc_new_cpu_counters); 722 + num_cpus = for_all_cpus(alloc_new_counters); 721 723 need_reinitialize = 0; 722 724 printf("num_cpus is now %d\n", num_cpus); 723 725 } ··· 726 728 /* 727 729 * check to see if a cpu came on-line 728 730 */ 729 - void verify_num_cpus() 731 + void verify_num_cpus(void) 730 732 { 731 733 int new_num_cpus; 732 734 ··· 738 740 num_cpus, new_num_cpus); 739 741 need_reinitialize = 1; 740 742 } 741 - 742 - return; 743 743 } 744 744 745 745 void turbostat_loop() 746 746 { 747 747 restart: 748 - get_counters(pcc_even); 748 + get_counters(cnt_even); 749 749 gettimeofday(&tv_even, (struct timezone *)NULL); 750 750 751 751 while (1) { ··· 753 757 goto restart; 754 758 } 755 759 sleep(interval_sec); 756 - get_counters(pcc_odd); 760 + get_counters(cnt_odd); 757 761 gettimeofday(&tv_odd, (struct timezone *)NULL); 758 762 759 - compute_delta(pcc_odd, pcc_even, pcc_delta); 763 + compute_delta(cnt_odd, cnt_even, cnt_delta); 760 764 timersub(&tv_odd, &tv_even, &tv_delta); 761 - compute_average(pcc_delta, pcc_average); 762 - print_counters(pcc_delta); 765 + compute_average(cnt_delta, cnt_average); 766 + print_counters(cnt_delta); 763 767 if (need_reinitialize) { 764 768 re_initialize(); 765 769 goto restart; 766 770 } 767 771 sleep(interval_sec); 768 - get_counters(pcc_even); 772 + get_counters(cnt_even); 769 773 gettimeofday(&tv_even, (struct timezone *)NULL); 770 - compute_delta(pcc_even, pcc_odd, pcc_delta); 774 + compute_delta(cnt_even, cnt_odd, cnt_delta); 771 775 timersub(&tv_even, &tv_odd, &tv_delta); 772 - compute_average(pcc_delta, pcc_average); 773 - print_counters(pcc_delta); 776 + compute_average(cnt_delta, cnt_average); 777 + print_counters(cnt_delta); 774 778 } 775 779 } 776 780 ··· 888 892 * this check is valid for both Intel and AMD 889 893 */ 890 894 asm("cpuid" : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx) : "a" (0x80000007)); 891 - has_invariant_tsc = edx && (1 << 8); 895 + has_invariant_tsc = edx & (1 << 8); 892 896 893 897 if (!has_invariant_tsc) { 894 898 fprintf(stderr, "No invariant TSC\n"); ··· 901 905 */ 902 906 903 907 asm("cpuid" : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx) : "a" (0x6)); 904 - has_aperf = ecx && (1 << 0); 908 + has_aperf = ecx & (1 << 0); 905 909 if (!has_aperf) { 906 910 fprintf(stderr, "No APERF MSR\n"); 907 911 exit(1); ··· 948 952 check_dev_msr(); 949 953 check_super_user(); 950 954 951 - num_cpus = for_all_cpus(alloc_new_cpu_counters); 955 + num_cpus = for_all_cpus(alloc_new_counters); 952 956 953 957 if (verbose) 954 958 print_nehalem_info(); ··· 958 962 { 959 963 int retval; 960 964 pid_t child_pid; 961 - get_counters(pcc_even); 965 + get_counters(cnt_even); 962 966 gettimeofday(&tv_even, (struct timezone *)NULL); 963 967 964 968 child_pid = fork(); ··· 981 985 exit(1); 982 986 } 983 987 } 984 - get_counters(pcc_odd); 988 + get_counters(cnt_odd); 985 989 gettimeofday(&tv_odd, (struct timezone *)NULL); 986 - retval = compute_delta(pcc_odd, pcc_even, pcc_delta); 990 + retval = compute_delta(cnt_odd, cnt_even, cnt_delta); 987 991 988 992 timersub(&tv_odd, &tv_even, &tv_delta); 989 - compute_average(pcc_delta, pcc_average); 993 + compute_average(cnt_delta, cnt_average); 990 994 if (!retval) 991 - print_counters(pcc_delta); 995 + print_counters(cnt_delta); 992 996 993 997 fprintf(stderr, "%.6f sec\n", tv_delta.tv_sec + tv_delta.tv_usec/1000000.0);; 994 998