Skip to content

Commit ccf8a05

Browse files
committed
tools/power/turbostat: Obey allowed CPUs for primary thread/core detection
Thread_id doesn't tell if a CPU is allowed or not. Detect allowed CPUs only and use the first detected thread/core as the primary thread/core of a core/package. Signed-off-by: Zhang Rui <[email protected]>
1 parent 74318ad commit ccf8a05

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

tools/power/x86/turbostat/turbostat.c

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -926,12 +926,11 @@ struct thread_data {
926926
unsigned int x2apic_id;
927927
unsigned int flags;
928928
bool is_atom;
929-
#define CPU_IS_FIRST_THREAD_IN_CORE 0x2
930-
#define CPU_IS_FIRST_CORE_IN_PACKAGE 0x4
931929
unsigned long long counter[MAX_ADDED_THREAD_COUNTERS];
932930
} *thread_even, *thread_odd;
933931

934932
struct core_data {
933+
int base_cpu;
935934
unsigned long long c3;
936935
unsigned long long c6;
937936
unsigned long long c7;
@@ -944,6 +943,7 @@ struct core_data {
944943
} *core_even, *core_odd;
945944

946945
struct pkg_data {
946+
int base_cpu;
947947
unsigned long long pc2;
948948
unsigned long long pc3;
949949
unsigned long long pc6;
@@ -1200,26 +1200,21 @@ int for_all_cpus(int (func) (struct thread_data *, struct core_data *, struct pk
12001200

12011201
int is_cpu_first_thread_in_core(struct thread_data *t, struct core_data *c, struct pkg_data *p)
12021202
{
1203-
UNUSED(c);
12041203
UNUSED(p);
12051204

1206-
return (t->flags & CPU_IS_FIRST_THREAD_IN_CORE);
1205+
return ((int)t->cpu_id == c->base_cpu || c->base_cpu < 0);
12071206
}
12081207

12091208
int is_cpu_first_core_in_package(struct thread_data *t, struct core_data *c, struct pkg_data *p)
12101209
{
12111210
UNUSED(c);
1212-
UNUSED(p);
12131211

1214-
return (t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE);
1212+
return ((int)t->cpu_id == p->base_cpu || p->base_cpu < 0);
12151213
}
12161214

12171215
int is_cpu_first_thread_in_package(struct thread_data *t, struct core_data *c, struct pkg_data *p)
12181216
{
1219-
UNUSED(c);
1220-
UNUSED(p);
1221-
1222-
return (t->flags & CPU_IS_FIRST_THREAD_IN_CORE) && (t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE);
1217+
return is_cpu_first_thread_in_core(t, c, p) && is_cpu_first_core_in_package(t, c, p);
12231218
}
12241219

12251220
int cpu_migrate(int cpu)
@@ -2263,9 +2258,6 @@ void clear_counters(struct thread_data *t, struct core_data *c, struct pkg_data
22632258
t->irq_count = 0;
22642259
t->smi_count = 0;
22652260

2266-
/* tells format_counters to dump all fields from this set */
2267-
t->flags = CPU_IS_FIRST_THREAD_IN_CORE | CPU_IS_FIRST_CORE_IN_PACKAGE;
2268-
22692261
c->c3 = 0;
22702262
c->c6 = 0;
22712263
c->c7 = 0;
@@ -5872,15 +5864,19 @@ void allocate_counters(struct thread_data **t, struct core_data **c, struct pkg_
58725864
if (*c == NULL)
58735865
goto error;
58745866

5875-
for (i = 0; i < num_cores; i++)
5867+
for (i = 0; i < num_cores; i++) {
58765868
(*c)[i].core_id = -1;
5869+
(*c)[i].base_cpu = -1;
5870+
}
58775871

58785872
*p = calloc(topo.num_packages, sizeof(struct pkg_data));
58795873
if (*p == NULL)
58805874
goto error;
58815875

5882-
for (i = 0; i < topo.num_packages; i++)
5876+
for (i = 0; i < topo.num_packages; i++) {
58835877
(*p)[i].package_id = i;
5878+
(*p)[i].base_cpu = -1;
5879+
}
58845880

58855881
return;
58865882
error:
@@ -5913,10 +5909,11 @@ void init_counter(struct thread_data *thread_base, struct core_data *core_base,
59135909
p = GET_PKG(pkg_base, pkg_id);
59145910

59155911
t->cpu_id = cpu_id;
5916-
if (thread_id == 0) {
5917-
t->flags |= CPU_IS_FIRST_THREAD_IN_CORE;
5918-
if (cpu_is_first_core_in_package(cpu_id))
5919-
t->flags |= CPU_IS_FIRST_CORE_IN_PACKAGE;
5912+
if (!cpu_is_not_allowed(cpu_id)) {
5913+
if (c->base_cpu < 0)
5914+
c->base_cpu = t->cpu_id;
5915+
if (p->base_cpu < 0)
5916+
p->base_cpu = t->cpu_id;
59205917
}
59215918

59225919
c->core_id = core_id;

0 commit comments

Comments
 (0)