Skip to content

Commit ebf8449

Browse files
Patryk Wlazlynlenb
authored andcommitted
tools/power turbostat: Add proper re-initialization for perf file descriptors
Signed-off-by: Patryk Wlazlyn <[email protected]> Signed-off-by: Len Brown <[email protected]>
1 parent 4a1bb4d commit ebf8449

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tools/power/x86/turbostat/turbostat.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3669,18 +3669,25 @@ void free_fd_percpu(void)
36693669
{
36703670
int i;
36713671

3672+
if (!fd_percpu)
3673+
return;
3674+
36723675
for (i = 0; i < topo.max_cpu_num + 1; ++i) {
36733676
if (fd_percpu[i] != 0)
36743677
close(fd_percpu[i]);
36753678
}
36763679

36773680
free(fd_percpu);
3681+
fd_percpu = NULL;
36783682
}
36793683

36803684
void free_fd_amperf_percpu(void)
36813685
{
36823686
int i;
36833687

3688+
if (!fd_amperf_percpu)
3689+
return;
3690+
36843691
for (i = 0; i < topo.max_cpu_num + 1; ++i) {
36853692
if (fd_amperf_percpu[i].mperf != 0)
36863693
close(fd_amperf_percpu[i].mperf);
@@ -3690,6 +3697,21 @@ void free_fd_amperf_percpu(void)
36903697
}
36913698

36923699
free(fd_amperf_percpu);
3700+
fd_amperf_percpu = NULL;
3701+
}
3702+
3703+
void free_fd_instr_count_percpu(void)
3704+
{
3705+
if (!fd_instr_count_percpu)
3706+
return;
3707+
3708+
for (int i = 0; i < topo.max_cpu_num + 1; ++i) {
3709+
if (fd_instr_count_percpu[i] != 0)
3710+
close(fd_instr_count_percpu[i]);
3711+
}
3712+
3713+
free(fd_instr_count_percpu);
3714+
fd_instr_count_percpu = NULL;
36933715
}
36943716

36953717
void free_all_buffers(void)
@@ -3733,6 +3755,7 @@ void free_all_buffers(void)
37333755
outp = NULL;
37343756

37353757
free_fd_percpu();
3758+
free_fd_instr_count_percpu();
37363759
free_fd_amperf_percpu();
37373760

37383761
free(irq_column_2_cpu);
@@ -4067,10 +4090,13 @@ static void update_effective_set(bool startup)
40674090
err(1, "%s: cpu str malformat %s\n", PATH_EFFECTIVE_CPUS, cpu_effective_str);
40684091
}
40694092

4093+
void linux_perf_init(void);
4094+
40704095
void re_initialize(void)
40714096
{
40724097
free_all_buffers();
40734098
setup_all_buffers(false);
4099+
linux_perf_init();
40744100
fprintf(outf, "turbostat: re-initialized with num_cpus %d, allowed_cpus %d\n", topo.num_cpus,
40754101
topo.allowed_cpus);
40764102
}

0 commit comments

Comments
 (0)