aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/tests/builtin-test.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/tests/builtin-test.c')
-rw-r--r--tools/perf/tests/builtin-test.c38
1 files changed, 12 insertions, 26 deletions
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index b5a544d1b381..5d4354e24457 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -605,19 +605,13 @@ out_free_threads:
605#undef nsyscalls 605#undef nsyscalls
606} 606}
607 607
608static int sched__get_first_possible_cpu(pid_t pid, cpu_set_t **maskp, 608static int sched__get_first_possible_cpu(pid_t pid, cpu_set_t *maskp)
609 size_t *sizep)
610{ 609{
611 cpu_set_t *mask;
612 size_t size;
613 int i, cpu = -1, nrcpus = 1024; 610 int i, cpu = -1, nrcpus = 1024;
614realloc: 611realloc:
615 mask = CPU_ALLOC(nrcpus); 612 CPU_ZERO(maskp);
616 size = CPU_ALLOC_SIZE(nrcpus);
617 CPU_ZERO_S(size, mask);
618 613
619 if (sched_getaffinity(pid, size, mask) == -1) { 614 if (sched_getaffinity(pid, sizeof(*maskp), maskp) == -1) {
620 CPU_FREE(mask);
621 if (errno == EINVAL && nrcpus < (1024 << 8)) { 615 if (errno == EINVAL && nrcpus < (1024 << 8)) {
622 nrcpus = nrcpus << 2; 616 nrcpus = nrcpus << 2;
623 goto realloc; 617 goto realloc;
@@ -627,19 +621,14 @@ realloc:
627 } 621 }
628 622
629 for (i = 0; i < nrcpus; i++) { 623 for (i = 0; i < nrcpus; i++) {
630 if (CPU_ISSET_S(i, size, mask)) { 624 if (CPU_ISSET(i, maskp)) {
631 if (cpu == -1) { 625 if (cpu == -1)
632 cpu = i; 626 cpu = i;
633 *maskp = mask; 627 else
634 *sizep = size; 628 CPU_CLR(i, maskp);
635 } else
636 CPU_CLR_S(i, size, mask);
637 } 629 }
638 } 630 }
639 631
640 if (cpu == -1)
641 CPU_FREE(mask);
642
643 return cpu; 632 return cpu;
644} 633}
645 634
@@ -654,8 +643,8 @@ static int test__PERF_RECORD(void)
654 .freq = 10, 643 .freq = 10,
655 .mmap_pages = 256, 644 .mmap_pages = 256,
656 }; 645 };
657 cpu_set_t *cpu_mask = NULL; 646 cpu_set_t cpu_mask;
658 size_t cpu_mask_size = 0; 647 size_t cpu_mask_size = sizeof(cpu_mask);
659 struct perf_evlist *evlist = perf_evlist__new(NULL, NULL); 648 struct perf_evlist *evlist = perf_evlist__new(NULL, NULL);
660 struct perf_evsel *evsel; 649 struct perf_evsel *evsel;
661 struct perf_sample sample; 650 struct perf_sample sample;
@@ -719,8 +708,7 @@ static int test__PERF_RECORD(void)
719 evsel->attr.sample_type |= PERF_SAMPLE_TIME; 708 evsel->attr.sample_type |= PERF_SAMPLE_TIME;
720 perf_evlist__config_attrs(evlist, &opts); 709 perf_evlist__config_attrs(evlist, &opts);
721 710
722 err = sched__get_first_possible_cpu(evlist->workload.pid, &cpu_mask, 711 err = sched__get_first_possible_cpu(evlist->workload.pid, &cpu_mask);
723 &cpu_mask_size);
724 if (err < 0) { 712 if (err < 0) {
725 pr_debug("sched__get_first_possible_cpu: %s\n", strerror(errno)); 713 pr_debug("sched__get_first_possible_cpu: %s\n", strerror(errno));
726 goto out_delete_evlist; 714 goto out_delete_evlist;
@@ -731,9 +719,9 @@ static int test__PERF_RECORD(void)
731 /* 719 /*
732 * So that we can check perf_sample.cpu on all the samples. 720 * So that we can check perf_sample.cpu on all the samples.
733 */ 721 */
734 if (sched_setaffinity(evlist->workload.pid, cpu_mask_size, cpu_mask) < 0) { 722 if (sched_setaffinity(evlist->workload.pid, cpu_mask_size, &cpu_mask) < 0) {
735 pr_debug("sched_setaffinity: %s\n", strerror(errno)); 723 pr_debug("sched_setaffinity: %s\n", strerror(errno));
736 goto out_free_cpu_mask; 724 goto out_delete_evlist;
737 } 725 }
738 726
739 /* 727 /*
@@ -917,8 +905,6 @@ found_exit:
917 } 905 }
918out_err: 906out_err:
919 perf_evlist__munmap(evlist); 907 perf_evlist__munmap(evlist);
920out_free_cpu_mask:
921 CPU_FREE(cpu_mask);
922out_delete_evlist: 908out_delete_evlist:
923 perf_evlist__delete(evlist); 909 perf_evlist__delete(evlist);
924out: 910out: