platform/x86: TPMI: clean up CPU mappings on offline
PATCH 1/1 platform/x86: TPMI: clean up CPU mappings on offline
From: Li RongQing <[email protected]>
The TPMI power domain driver adds each online CPU to a hash table and its power domain mask, but does not remove either entry when the CPU goes offline. Bringing a CPU back online can therefore insert the same hlist node again and leave stale CPU mask state.
Register an offline callback that removes the hash entry and clears the CPU from its power domain mask.
--- drivers/platform/x86/intel/tpmi_power_domains.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)
drivers/platform/x86/intel/tpmi_power_domains.c +18 -1
@@ -220,6 +220,23 @@ static int tpmi_cpu_online(unsigned int cpu)return 0 ; } +static int tpmi_cpu_offline (unsigned int cpu) +{ +struct tpmi_cpu_info *info = &per_cpu (tpmi_cpu_info, cpu); +int index; + +if (hlist_unhashed (&info->hnode) || !tpmi_domain_is_valid (info)) +return 0 ; + + index = info->pkg_id *MAX_POWER_DOMAINS + info->punit_domain_id; + +guard (mutex)(&tpmi_lock); +cpumask_clear_cpu (cpu, &tpmi_power_domain_mask[index]); +hash_del (&info->hnode); + +return 0 ; +} +static int __init tpmi_init (void ) {const struct x86_cpu_id *id;
@@ -249,7 +266,7 @@ static int __init tpmi_init(void) ret =cpuhp_setup_state (CPUHP_AP_ONLINE_DYN ,"platform/x86/tpmi_power_domains:online" , - tpmi_cpu_online,NULL ); + tpmi_cpu_online, tpmi_cpu_offline);if (ret <0 ) goto free_domain_map;
Signature · 1 line
2.9.4
Quoted 8 lines · lirongqing
From: Li RongQing <[email protected]>
The TPMI power domain driver adds each online CPU to a hash table and its power domain mask, but does not remove either entry when the CPU goes offline. Bringing a CPU back online can therefore insert the same
hlist node again and leave stale CPU mask state.
Quoted 4 lines
Register an offline callback that removes the hash entry and clears the
CPU from its power domain mask.
Hi RonQing,
Thanks for the patch.
TPMI feature doesn't depend on CPU online/offline and can update MMIO while CPU is offline.
Instead of adding a offline callback, can we just do the below if the cost of search is not high?
(quoted diff) +0 -0
b/drivers/platform/x86/intel/tpmi_power_domains.c
index d89b9894c42a..dadd5fc5719f 100644
drivers/platform/x86/intel/tpmi_power_domains.c +0 -0
@@ -201,6 +201,8 @@ static int tpmi_get_logical_id(unsigned int cpu,
struct tpmi_cpu_info *info)
static int tpmi_cpu_online(unsigned int cpu)
{
struct tpmi_cpu_info *info = &per_cpu(tpmi_cpu_info, cpu);
+ struct tpmi_cpu_info *entry;
+ bool found = false;
int ret, index;
/* Don't fail CPU online for some bad mapping of CPUs */@@ -212,7 +214,14 @@ static int tpmi_cpu_online(unsigned int cpu)
guard(mutex)(&tpmi_lock);
cpumask_set_cpu(cpu, &tpmi_power_domain_mask[index]);- hash_add(tpmi_cpu_hash, &info->hnode, info->punit_core_id);
+ hash_for_each_possible(tpmi_cpu_hash, entry, hnode, info-
Quoted 1 line
punit_core_id) {
+ if (entry == info) {
+ found = true;
+ break;
+ }
+ }
+ if (!found)
+ hash_add(tpmi_cpu_hash, &info->hnode, info-
Quoted 1 line
punit_core_id);
domain_die_map[info->pkg_id * MAX_POWER_DOMAINS + info-
Quoted 1 line
punit_domain_id] =
topology_die_id(cpu);
Thanks,
Srinivas
Quoted 49 lines
Fixes 17ca2780458c ("platform/x86/intel: TPMI domain id and CPUmapping")
Signed-off-by Li RongQing <[email protected]>---
drivers/platform/x86/intel/tpmi_power_domains.c | 19
++++++++++++++++++-1 file changed, 18 insertions(+), 1 deletion(-)drivers/platform/x86/intel/tpmi_power_domains.c +0
-0@@ -220,6 +220,23 @@ static int tpmi_cpu_online(unsigned int cpu) return 0; }drivers/platform/x86/intel/tpmi_power_domains.c +6
-0+static int tpmi_cpu_offline (unsigned int cpu) +{ +struct tpmi_cpu_info *info = &per_cpu (tpmi_cpu_info, cpu); +int index; + + if (hlist_unhashed(&info->hnode) ||!tpmi_domain_is_valid(info))
drivers/platform/x86/intel/tpmi_power_domains.c +3
-0+return 0 ; + + index = info->pkg_id * MAX_POWER_DOMAINS + info-Quoted 1 line
punit_domain_id;drivers/platform/x86/intel/tpmi_power_domains.c +8
-0+ +guard (mutex)(&tpmi_lock); +cpumask_clear_cpu (cpu, &tpmi_power_domain_mask[index]); +hash_del (&info->hnode); + +return 0 ; +} +static int
__inittpmi_init(void)
{
const structx86_cpu_id*id;drivers/platform/x86/intel/tpmi_power_domains.c +0
-0@@ -249,7 +266,7 @@ static int __init tpmi_init(void)
ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "platform/x86/tpmi_power_domains:onl ine",drivers/platform/x86/intel/tpmi_power_domains.c +1
-1- tpmi_cpu_online, NULL); + tpmi_cpu_online, tpmi_cpu_offline);if (ret < 0)
gotofree_domain_map;
Quoted 13 lines · lirongqing
Quoted 10 lines
From: Li RongQing <[email protected]>
The TPMI power domain driver adds each online CPU to a hash table and its power domain mask, but does not remove either entry when the CPU goes offline. Bringing a CPU back online can therefore insert the same hlist node again and leave stale CPU mask state.
Register an offline callback that removes the hash entry and clears the CPU from its power domain mask.
Quoted 7 lines
Hi RonQing,
Thanks for the patch.
TPMI feature doesn't depend on CPU online/offline and can update MMIO while CPU is offline.
However, could you clarify why we need the CPU online callback in this case?
Quoted 24 lines
Instead of adding a offline callback, can we just do the below if the cost of search is not high?
drivers/platform/x86/intel/tpmi_power_domains.c +2
-0@@ -201,6 +201,8 @@ static int tpmi_get_logical_id(unsigned int cpu, struct tpmi_cpu_info *info)static int tpmi_cpu_online (unsigned int cpu) {struct tpmi_cpu_info *info = &per_cpu (tpmi_cpu_info, cpu); +struct tpmi_cpu_info *entry; +bool found = false;int ret, index;/* Don't fail CPU online for some bad mapping of CPUs */drivers/platform/x86/intel/tpmi_power_domains.c +1
-1@@ -212,7 +214,14 @@ static int tpmi_cpu_online(unsigned int cpu)guard (mutex)(&tpmi_lock);cpumask_set_cpu (cpu, &tpmi_power_domain_mask[index]); -hash_add (tpmi_cpu_hash, &info->hnode, info->punit_core_id); + hash_for_each_possible(tpmi_cpu_hash, entry, hnode, info-
drivers/platform/x86/intel/tpmi_power_domains.c static int tpmi_cpu_online(unsigned int cpu) · line 227
Quoted 10 lines
drivers/platform/x86/intel/tpmi_power_domains.c +7
-0>punit_core_id) { +if (entry == info) { + found = true; +break ; + } + } +if (!found) +hash_add (tpmi_cpu_hash, &info->hnode, info- >punit_core_id);
Your proposed change prevents duplicate hash entries, but it does not address stale CPU entries in tpmi_power_domain_mask after a CPU goes offline. Could you also fix this issue?
Thanks
[Li,Rongqing]
Quoted 55 lines
domain_die_map[info->pkg_id * MAX_POWER_DOMAINS + info-Quoted 1 line
punit_domain_id] =topology_die_id(cpu);Thanks,
SrinivasQuoted 49 lines
Fixes 17ca2780458c ("platform/x86/intel: TPMI domain id and CPUmapping")
Signed-off-by Li RongQing <[email protected]>---
drivers/platform/x86/intel/tpmi_power_domains.c | 19
++++++++++++++++++-1 file changed, 18 insertions(+), 1 deletion(-)drivers/platform/x86/intel/tpmi_power_domains.c +17
-0@@ -220,6 +220,23 @@ static int tpmi_cpu_online(unsigned int cpu) return 0; } +static int tpmi_cpu_offline (unsigned int cpu) +{ +struct tpmi_cpu_info *info = &per_cpu (tpmi_cpu_info, cpu); +int index; + +if (hlist_unhashed (&info->hnode) || !tpmi_domain_is_valid (info)) +return 0 ; + + index = info->pkg_id *MAX_POWER_DOMAINS + info- >punit_domain_id; + +guard (mutex)(&tpmi_lock); +cpumask_clear_cpu (cpu, &tpmi_power_domain_mask[index]); +hash_del (&info->hnode); + +return 0 ; +} + static int __init tpmi_init(void){
const structx86_cpu_id*id;drivers/platform/x86/intel/tpmi_power_domains.c +0
-0@@ -249,7 +266,7 @@ static int __init tpmi_init(void) ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN,"platform/x86/tpmi_power_domains:onl ine",
drivers/platform/x86/intel/tpmi_power_domains.c +1
-1- tpmi_cpu_online, NULL); + tpmi_cpu_online, tpmi_cpu_offline);if (ret < 0)
gotofree_domain_map;
Quoted 21 lines · Li,Rongqing
Quoted 21 lines · lirongqing
Quoted 10 lines
From: Li RongQing <[email protected]>
The TPMI power domain driver adds each online CPU to a hash table and
its power domain mask, but does not remove either entry when the CPU
goes offline. Bringing a CPU back online can therefore insert the same
hlist node again and leave stale CPU mask state.Quoted 4 lines
Register an offline callback that removes the hash entry and clears
the CPU from its power domain mask.Hi RonQing,
Thanks for the patch.
Quoted 7 lines
Quoted 4 lines
TPMI feature doesn't depend on CPU online/offline and can update MMIO
while CPU is offline.However, could you clarify why we need the CPU online callback in this case?
When online we read the PM logical ID on that CPU and store it. This PM logical ID doesn't change after offline/online.
Thanks,
Srinivas
Quoted 104 lines
Quoted 27 lines
Instead of adding a offline callback, can we just do the below if the
cost of search is not high?drivers/platform/x86/intel/tpmi_power_domains.c +2
-0@@ -201,6 +201,8 @@ static int tpmi_get_logical_id(unsigned int cpu, struct tpmi_cpu_info *info) static int tpmi_cpu_online(unsigned int cpu) { struct tpmi_cpu_info *info = &per_cpu(tpmi_cpu_info, cpu); + struct tpmi_cpu_info *entry; + bool found = false; int ret, index;/* Don't fail CPU online for some bad mapping of CPUs */
drivers/platform/x86/intel/tpmi_power_domains.c +1
-1@@ -212,7 +214,14 @@ static int tpmi_cpu_online(unsigned int cpu) guard(mutex)(&tpmi_lock); cpumask_set_cpu(cpu, &tpmi_power_domain_mask[index]); - hash_add(tpmi_cpu_hash, &info->hnode, info->punit_core_id); + hash_for_each_possible(tpmi_cpu_hash, entry, hnode, info-drivers/platform/x86/intel/tpmi_power_domains.c static int tpmi_cpu_online(unsigned int cpu) · line 227
Quoted 10 lines
drivers/platform/x86/intel/tpmi_power_domains.c +7
-0> punit_core_id) { + if (entry == info) { + found = true; + break; + } + } + if (!found) + hash_add(tpmi_cpu_hash, &info->hnode, info- > punit_core_id);Your proposed change prevents duplicate hash entries, but it does not address stale CPU entries in
tpmi_power_domain_maskafter a CPU goes offline. Could you also fix this issue?Thanks
[Li,Rongqing]
Quoted 58 lines
domain_die_map[info->pkg_id *
MAX_POWER_DOMAINS+ info-Quoted 1 line
punit_domain_id] =
topology_die_id(cpu);
Thanks,
SrinivasQuoted 52 lines
Fixes 17ca2780458c ("platform/x86/intel: TPMI domain id and CPUmapping")
Signed-off-by Li RongQing <[email protected]>---
drivers/platform/x86/intel/tpmi_power_domains.c | 19
++++++++++++++++++-1 file changed, 18 insertions(+), 1 deletion(-)drivers/platform/x86/intel/tpmi_power_domains.c +17
-0@@ -220,6 +220,23 @@ static int tpmi_cpu_online(unsigned int cpu) return 0; } +static int tpmi_cpu_offline (unsigned int cpu) +{ +struct tpmi_cpu_info *info = &per_cpu (tpmi_cpu_info, cpu); +int index; + +if (hlist_unhashed (&info->hnode) || !tpmi_domain_is_valid (info)) +return 0 ; + + index = info->pkg_id *MAX_POWER_DOMAINS + info- > punit_domain_id; + +guard (mutex)(&tpmi_lock); +cpumask_clear_cpu (cpu, &tpmi_power_domain_mask[index]); +hash_del (&info->hnode); + +return 0 ; +} +static int
__inittpmi_init(void)
{
const structx86_cpu_id*id;drivers/platform/x86/intel/tpmi_power_domains.c +0
-0@@ -249,7 +266,7 @@ static int __init tpmi_init(void) ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN,"platform/x86/tpmi_power_domains :onl
ine",drivers/platform/x86/intel/tpmi_power_domains.c +1
-1- tpmi_cpu_online, NULL); + tpmi_cpu_online,
tpmi_cpu_offline);
if (ret < 0)
gotofree_domain_map;
Quoted 8 lines · lirongqing
The TPMI power domain driver adds each online CPU to a hash table and its power domain mask, but does not remove either entry when the CPU goes offline. Bringing a CPU back online can therefore insert the same hlist node again and leave stale CPU mask state.
Register an offline callback that removes the hash entry and clears the CPU from its power domain mask.
...
drivers/platform/x86/intel/tpmi_power_domains.c static int tpmi_cpu_online(unsigned int cpu) · line 233
Quoted 11 lines
drivers/platform/x86/intel/tpmi_power_domains.c +11
-0+static int tpmi_cpu_offline (unsigned int cpu) +{ +struct tpmi_cpu_info *info = &per_cpu (tpmi_cpu_info, cpu); +int index; + +if (hlist_unhashed (&info->hnode) || !tpmi_domain_is_valid (info)) +return 0 ; + + index = info->pkg_id *MAX_POWER_DOMAINS + info->punit_domain_id; + +guard (mutex)(&tpmi_lock);
+ Blank line, so we can see at glance the lock usage.
No need to resend just for this, unless Ilpo asks for it.
Quoted 5 lines
drivers/platform/x86/intel/tpmi_power_domains.c +5
-0+cpumask_clear_cpu (cpu, &tpmi_power_domain_mask[index]); +hash_del (&info->hnode); + +return 0 ; +}
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 8 lines · lirongqing
From: Li RongQing <[email protected]>
The TPMI power domain driver adds each online CPU to a hash table and its power domain mask, but does not remove either entry when the CPU goes offline. Bringing a CPU back online can therefore insert the same
hlist node again and leave stale CPU mask state.
Quoted 7 lines
Register an offline callback that removes the hash entry and clears the
CPU from its power domain mask.Fixes 17ca2780458c ("platform/x86/intel: TPMI domain id and CPUmapping")
Signed-off-by Li RongQing <[email protected]>
We have no case currently to get offlined CPU's data. So will add when we need.
As a convention we capitalize the first letter after "TPMI:" in this driver, so consider changing that.
Otherwise
Quoted 46 lines
---
drivers/platform/x86/intel/tpmi_power_domains.c | 19
++++++++++++++++++-1 file changed, 18 insertions(+), 1 deletion(-)drivers/platform/x86/intel/tpmi_power_domains.c +0
-0@@ -220,6 +220,23 @@ static int tpmi_cpu_online(unsigned int cpu) return 0; }drivers/platform/x86/intel/tpmi_power_domains.c +6
-0+static int tpmi_cpu_offline (unsigned int cpu) +{ +struct tpmi_cpu_info *info = &per_cpu (tpmi_cpu_info, cpu); +int index; + + if (hlist_unhashed(&info->hnode) ||!tpmi_domain_is_valid(info))
drivers/platform/x86/intel/tpmi_power_domains.c +3
-0+return 0 ; + + index = info->pkg_id * MAX_POWER_DOMAINS + info-Quoted 1 line
punit_domain_id;drivers/platform/x86/intel/tpmi_power_domains.c +8
-0+ +guard (mutex)(&tpmi_lock); +cpumask_clear_cpu (cpu, &tpmi_power_domain_mask[index]); +hash_del (&info->hnode); + +return 0 ; +} +static int
__inittpmi_init(void)
{
const structx86_cpu_id*id;drivers/platform/x86/intel/tpmi_power_domains.c +0
-0@@ -249,7 +266,7 @@ static int __init tpmi_init(void)
ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "platform/x86/tpmi_power_domains:onl ine",drivers/platform/x86/intel/tpmi_power_domains.c +1
-1- tpmi_cpu_online, NULL); + tpmi_cpu_online, tpmi_cpu_offline);if (ret < 0)
gotofree_domain_map;