Skip to content

Commit 3c728e0

Browse files
tamaszarmSuzuki K Poulose
authored andcommitted
coresight: etm4x: add CPU hotplug support for probing
etm4x devices cannot be successfully probed when their CPU is offline. For example, when booting with maxcpus=n, ETM probing will fail on CPUs >n, and the probing won't be reattempted once the CPUs come online. This will leave those CPUs unable to make use of ETM. This change adds a mechanism to delay the probing if the corresponding CPU is offline, and to try it again when the CPU comes online. Signed-off-by: Tamas Zsoldos <[email protected]> Signed-off-by: Suzuki K Poulose <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 30a0b95 commit 3c728e0

File tree

1 file changed

+113
-40
lines changed

1 file changed

+113
-40
lines changed

drivers/hwtracing/coresight/coresight-etm4x-core.c

Lines changed: 113 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,13 @@ static enum cpuhp_state hp_online;
6666

6767
struct etm4_init_arg {
6868
unsigned int pid;
69-
struct etmv4_drvdata *drvdata;
69+
struct device *dev;
7070
struct csdev_access *csa;
7171
};
7272

73+
static DEFINE_PER_CPU(struct etm4_init_arg *, delayed_probe);
74+
static int etm4_probe_cpu(unsigned int cpu);
75+
7376
/*
7477
* Check if TRCSSPCICRn(i) is implemented for a given instance.
7578
*
@@ -1085,7 +1088,7 @@ static void etm4_init_arch_data(void *info)
10851088
struct csdev_access *csa;
10861089
int i;
10871090

1088-
drvdata = init_arg->drvdata;
1091+
drvdata = dev_get_drvdata(init_arg->dev);
10891092
csa = init_arg->csa;
10901093

10911094
/*
@@ -1528,7 +1531,7 @@ void etm4_config_trace_mode(struct etmv4_config *config)
15281531
static int etm4_online_cpu(unsigned int cpu)
15291532
{
15301533
if (!etmdrvdata[cpu])
1531-
return 0;
1534+
return etm4_probe_cpu(cpu);
15321535

15331536
if (etmdrvdata[cpu]->boot_enable && !etmdrvdata[cpu]->sticky_enable)
15341537
coresight_enable(etmdrvdata[cpu]->csdev);
@@ -1904,48 +1907,20 @@ static void etm4_pm_clear(void)
19041907
}
19051908
}
19061909

1907-
static int etm4_probe(struct device *dev, void __iomem *base, u32 etm_pid)
1910+
static int etm4_add_coresight_dev(struct etm4_init_arg *init_arg)
19081911
{
19091912
int ret;
19101913
struct coresight_platform_data *pdata = NULL;
1911-
struct etmv4_drvdata *drvdata;
1914+
struct device *dev = init_arg->dev;
1915+
struct etmv4_drvdata *drvdata = dev_get_drvdata(dev);
19121916
struct coresight_desc desc = { 0 };
1913-
struct etm4_init_arg init_arg = { 0 };
19141917
u8 major, minor;
19151918
char *type_name;
19161919

1917-
drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
19181920
if (!drvdata)
1919-
return -ENOMEM;
1920-
1921-
dev_set_drvdata(dev, drvdata);
1922-
1923-
if (pm_save_enable == PARAM_PM_SAVE_FIRMWARE)
1924-
pm_save_enable = coresight_loses_context_with_cpu(dev) ?
1925-
PARAM_PM_SAVE_SELF_HOSTED : PARAM_PM_SAVE_NEVER;
1926-
1927-
if (pm_save_enable != PARAM_PM_SAVE_NEVER) {
1928-
drvdata->save_state = devm_kmalloc(dev,
1929-
sizeof(struct etmv4_save_state), GFP_KERNEL);
1930-
if (!drvdata->save_state)
1931-
return -ENOMEM;
1932-
}
1933-
1934-
drvdata->base = base;
1935-
1936-
spin_lock_init(&drvdata->spinlock);
1937-
1938-
drvdata->cpu = coresight_get_cpu(dev);
1939-
if (drvdata->cpu < 0)
1940-
return drvdata->cpu;
1941-
1942-
init_arg.drvdata = drvdata;
1943-
init_arg.csa = &desc.access;
1944-
init_arg.pid = etm_pid;
1921+
return -EINVAL;
19451922

1946-
if (smp_call_function_single(drvdata->cpu,
1947-
etm4_init_arch_data, &init_arg, 1))
1948-
dev_err(dev, "ETM arch init failed\n");
1923+
desc.access = *init_arg->csa;
19491924

19501925
if (!drvdata->arch)
19511926
return -EINVAL;
@@ -2016,6 +1991,68 @@ static int etm4_probe(struct device *dev, void __iomem *base, u32 etm_pid)
20161991
return 0;
20171992
}
20181993

1994+
static int etm4_probe(struct device *dev, void __iomem *base, u32 etm_pid)
1995+
{
1996+
struct etmv4_drvdata *drvdata;
1997+
struct csdev_access access = { 0 };
1998+
struct etm4_init_arg init_arg = { 0 };
1999+
struct etm4_init_arg *delayed;
2000+
2001+
drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
2002+
if (!drvdata)
2003+
return -ENOMEM;
2004+
2005+
dev_set_drvdata(dev, drvdata);
2006+
2007+
if (pm_save_enable == PARAM_PM_SAVE_FIRMWARE)
2008+
pm_save_enable = coresight_loses_context_with_cpu(dev) ?
2009+
PARAM_PM_SAVE_SELF_HOSTED : PARAM_PM_SAVE_NEVER;
2010+
2011+
if (pm_save_enable != PARAM_PM_SAVE_NEVER) {
2012+
drvdata->save_state = devm_kmalloc(dev,
2013+
sizeof(struct etmv4_save_state), GFP_KERNEL);
2014+
if (!drvdata->save_state)
2015+
return -ENOMEM;
2016+
}
2017+
2018+
drvdata->base = base;
2019+
2020+
spin_lock_init(&drvdata->spinlock);
2021+
2022+
drvdata->cpu = coresight_get_cpu(dev);
2023+
if (drvdata->cpu < 0)
2024+
return drvdata->cpu;
2025+
2026+
init_arg.dev = dev;
2027+
init_arg.csa = &access;
2028+
init_arg.pid = etm_pid;
2029+
2030+
/*
2031+
* Serialize against CPUHP callbacks to avoid race condition
2032+
* between the smp call and saving the delayed probe.
2033+
*/
2034+
cpus_read_lock();
2035+
if (smp_call_function_single(drvdata->cpu,
2036+
etm4_init_arch_data, &init_arg, 1)) {
2037+
/* The CPU was offline, try again once it comes online. */
2038+
delayed = devm_kmalloc(dev, sizeof(*delayed), GFP_KERNEL);
2039+
if (!delayed) {
2040+
cpus_read_unlock();
2041+
return -ENOMEM;
2042+
}
2043+
2044+
*delayed = init_arg;
2045+
2046+
per_cpu(delayed_probe, drvdata->cpu) = delayed;
2047+
2048+
cpus_read_unlock();
2049+
return 0;
2050+
}
2051+
cpus_read_unlock();
2052+
2053+
return etm4_add_coresight_dev(&init_arg);
2054+
}
2055+
20192056
static int etm4_probe_amba(struct amba_device *adev, const struct amba_id *id)
20202057
{
20212058
void __iomem *base;
@@ -2054,6 +2091,35 @@ static int etm4_probe_platform_dev(struct platform_device *pdev)
20542091
return ret;
20552092
}
20562093

2094+
static int etm4_probe_cpu(unsigned int cpu)
2095+
{
2096+
int ret;
2097+
struct etm4_init_arg init_arg;
2098+
struct csdev_access access = { 0 };
2099+
struct etm4_init_arg *iap = *this_cpu_ptr(&delayed_probe);
2100+
2101+
if (!iap)
2102+
return 0;
2103+
2104+
init_arg = *iap;
2105+
devm_kfree(init_arg.dev, iap);
2106+
*this_cpu_ptr(&delayed_probe) = NULL;
2107+
2108+
ret = pm_runtime_resume_and_get(init_arg.dev);
2109+
if (ret < 0) {
2110+
dev_err(init_arg.dev, "Failed to get PM runtime!\n");
2111+
return 0;
2112+
}
2113+
2114+
init_arg.csa = &access;
2115+
etm4_init_arch_data(&init_arg);
2116+
2117+
etm4_add_coresight_dev(&init_arg);
2118+
2119+
pm_runtime_put(init_arg.dev);
2120+
return 0;
2121+
}
2122+
20572123
static struct amba_cs_uci_id uci_id_etm4[] = {
20582124
{
20592125
/* ETMv4 UCI data */
@@ -2068,29 +2134,36 @@ static void clear_etmdrvdata(void *info)
20682134
int cpu = *(int *)info;
20692135

20702136
etmdrvdata[cpu] = NULL;
2137+
per_cpu(delayed_probe, cpu) = NULL;
20712138
}
20722139

20732140
static int __exit etm4_remove_dev(struct etmv4_drvdata *drvdata)
20742141
{
2075-
etm_perf_symlink(drvdata->csdev, false);
2142+
bool had_delayed_probe;
20762143
/*
20772144
* Taking hotplug lock here to avoid racing between etm4_remove_dev()
20782145
* and CPU hotplug call backs.
20792146
*/
20802147
cpus_read_lock();
2148+
2149+
had_delayed_probe = per_cpu(delayed_probe, drvdata->cpu);
2150+
20812151
/*
20822152
* The readers for etmdrvdata[] are CPU hotplug call backs
20832153
* and PM notification call backs. Change etmdrvdata[i] on
20842154
* CPU i ensures these call backs has consistent view
20852155
* inside one call back function.
20862156
*/
20872157
if (smp_call_function_single(drvdata->cpu, clear_etmdrvdata, &drvdata->cpu, 1))
2088-
etmdrvdata[drvdata->cpu] = NULL;
2158+
clear_etmdrvdata(&drvdata->cpu);
20892159

20902160
cpus_read_unlock();
20912161

2092-
cscfg_unregister_csdev(drvdata->csdev);
2093-
coresight_unregister(drvdata->csdev);
2162+
if (!had_delayed_probe) {
2163+
etm_perf_symlink(drvdata->csdev, false);
2164+
cscfg_unregister_csdev(drvdata->csdev);
2165+
coresight_unregister(drvdata->csdev);
2166+
}
20942167

20952168
return 0;
20962169
}

0 commit comments

Comments
 (0)