hc
2024-05-10 cde9070d9970eef1f7ec2360586c802a16230ad8
kernel/tools/perf/util/svghelper.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * svghelper.c - helper functions for outputting svg
34 *
....@@ -5,11 +6,6 @@
56 *
67 * Authors:
78 * Arjan van de Ven <arjan@linux.intel.com>
8
- *
9
- * This program is free software; you can redistribute it and/or
10
- * modify it under the terms of the GNU General Public License
11
- * as published by the Free Software Foundation; version 2
12
- * of the License.
139 */
1410
1511 #include <inttypes.h>
....@@ -18,12 +14,14 @@
1814 #include <unistd.h>
1915 #include <string.h>
2016 #include <linux/bitmap.h>
17
+#include <linux/string.h>
2118 #include <linux/time64.h>
19
+#include <linux/zalloc.h>
20
+#include <internal/cpumap.h>
21
+#include <perf/cpumap.h>
2222
23
-#include "perf.h"
23
+#include "env.h"
2424 #include "svghelper.h"
25
-#include "util.h"
26
-#include "cpumap.h"
2725
2826 static u64 first_time, last_time;
2927 static u64 turbo_frequency, max_freq;
....@@ -698,7 +696,8 @@
698696 int sib_thr_nr;
699697 };
700698
701
-static void scan_thread_topology(int *map, struct topology *t, int cpu, int *pos)
699
+static void scan_thread_topology(int *map, struct topology *t, int cpu,
700
+ int *pos, int nr_cpus)
702701 {
703702 int i;
704703 int thr;
....@@ -707,41 +706,37 @@
707706 if (!test_bit(cpu, cpumask_bits(&t->sib_thr[i])))
708707 continue;
709708
710
- for_each_set_bit(thr,
711
- cpumask_bits(&t->sib_thr[i]),
712
- MAX_NR_CPUS)
709
+ for_each_set_bit(thr, cpumask_bits(&t->sib_thr[i]), nr_cpus)
713710 if (map[thr] == -1)
714711 map[thr] = (*pos)++;
715712 }
716713 }
717714
718
-static void scan_core_topology(int *map, struct topology *t)
715
+static void scan_core_topology(int *map, struct topology *t, int nr_cpus)
719716 {
720717 int pos = 0;
721718 int i;
722719 int cpu;
723720
724721 for (i = 0; i < t->sib_core_nr; i++)
725
- for_each_set_bit(cpu,
726
- cpumask_bits(&t->sib_core[i]),
727
- MAX_NR_CPUS)
728
- scan_thread_topology(map, t, cpu, &pos);
722
+ for_each_set_bit(cpu, cpumask_bits(&t->sib_core[i]), nr_cpus)
723
+ scan_thread_topology(map, t, cpu, &pos, nr_cpus);
729724 }
730725
731
-static int str_to_bitmap(char *s, cpumask_t *b)
726
+static int str_to_bitmap(char *s, cpumask_t *b, int nr_cpus)
732727 {
733728 int i;
734729 int ret = 0;
735
- struct cpu_map *m;
730
+ struct perf_cpu_map *m;
736731 int c;
737732
738
- m = cpu_map__new(s);
733
+ m = perf_cpu_map__new(s);
739734 if (!m)
740735 return -1;
741736
742737 for (i = 0; i < m->nr; i++) {
743738 c = m->map[i];
744
- if (c >= MAX_NR_CPUS) {
739
+ if (c >= nr_cpus) {
745740 ret = -1;
746741 break;
747742 }
....@@ -749,29 +744,34 @@
749744 set_bit(c, cpumask_bits(b));
750745 }
751746
752
- cpu_map__put(m);
747
+ perf_cpu_map__put(m);
753748
754749 return ret;
755750 }
756751
757
-int svg_build_topology_map(char *sib_core, int sib_core_nr,
758
- char *sib_thr, int sib_thr_nr)
752
+int svg_build_topology_map(struct perf_env *env)
759753 {
760
- int i;
754
+ int i, nr_cpus;
761755 struct topology t;
756
+ char *sib_core, *sib_thr;
762757
763
- t.sib_core_nr = sib_core_nr;
764
- t.sib_thr_nr = sib_thr_nr;
765
- t.sib_core = calloc(sib_core_nr, sizeof(cpumask_t));
766
- t.sib_thr = calloc(sib_thr_nr, sizeof(cpumask_t));
758
+ nr_cpus = min(env->nr_cpus_online, MAX_NR_CPUS);
759
+
760
+ t.sib_core_nr = env->nr_sibling_cores;
761
+ t.sib_thr_nr = env->nr_sibling_threads;
762
+ t.sib_core = calloc(env->nr_sibling_cores, sizeof(cpumask_t));
763
+ t.sib_thr = calloc(env->nr_sibling_threads, sizeof(cpumask_t));
764
+
765
+ sib_core = env->sibling_cores;
766
+ sib_thr = env->sibling_threads;
767767
768768 if (!t.sib_core || !t.sib_thr) {
769769 fprintf(stderr, "topology: no memory\n");
770770 goto exit;
771771 }
772772
773
- for (i = 0; i < sib_core_nr; i++) {
774
- if (str_to_bitmap(sib_core, &t.sib_core[i])) {
773
+ for (i = 0; i < env->nr_sibling_cores; i++) {
774
+ if (str_to_bitmap(sib_core, &t.sib_core[i], nr_cpus)) {
775775 fprintf(stderr, "topology: can't parse siblings map\n");
776776 goto exit;
777777 }
....@@ -779,8 +779,8 @@
779779 sib_core += strlen(sib_core) + 1;
780780 }
781781
782
- for (i = 0; i < sib_thr_nr; i++) {
783
- if (str_to_bitmap(sib_thr, &t.sib_thr[i])) {
782
+ for (i = 0; i < env->nr_sibling_threads; i++) {
783
+ if (str_to_bitmap(sib_thr, &t.sib_thr[i], nr_cpus)) {
784784 fprintf(stderr, "topology: can't parse siblings map\n");
785785 goto exit;
786786 }
....@@ -788,16 +788,16 @@
788788 sib_thr += strlen(sib_thr) + 1;
789789 }
790790
791
- topology_map = malloc(sizeof(int) * MAX_NR_CPUS);
791
+ topology_map = malloc(sizeof(int) * nr_cpus);
792792 if (!topology_map) {
793793 fprintf(stderr, "topology: no memory\n");
794794 goto exit;
795795 }
796796
797
- for (i = 0; i < MAX_NR_CPUS; i++)
797
+ for (i = 0; i < nr_cpus; i++)
798798 topology_map[i] = -1;
799799
800
- scan_core_topology(topology_map, &t);
800
+ scan_core_topology(topology_map, &t, nr_cpus);
801801
802802 return 0;
803803