Skip to content

Commit

Permalink
thunderbolt: Reduce footprint with CONFIG_PM=n
Browse files Browse the repository at this point in the history
Add #ifdefs to reduce the Thunderbolt driver's footprint if CONFIG_PM is
disabled.  I've chosen to also exclude dev_pm_ops structs on such
configs as this can be achieved without increasing the LoC count by
using a ternary operator.

I've left some code untouched which is only relevant with CONFIG_PM=y
(e.g. initilization and cancelling of the rescan_work in icm.c) to avoid
negatively impacting readability.  I've also left pointers in structs
which are only relevant with CONFIG_PM=y for the same reason (e.g. the
PM function pointers in struct tb_cm_ops)

A desired side effect is that the driver's dev_pm_ops callbacks may now
access members of struct dev_pm_info which are only available with
CONFIG_PM=y.

Size of thunderbolt.ko on x86_64 with CONFIG_PM=n:
252832 bytes before, 240912 bytes after

Signed-off-by: Lukas Wunner <lukas@wunner.de>
  • Loading branch information
l1k committed Jan 5, 2019
1 parent e9a6f9b commit 15bb943
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 16 deletions.
2 changes: 2 additions & 0 deletions drivers/thunderbolt/domain.c
Expand Up @@ -515,6 +515,7 @@ int tb_domain_suspend_noirq(struct tb *tb)
return ret;
}

#ifdef CONFIG_PM
/**
* tb_domain_resume_noirq() - Resume a domain
* @tb: Domain to resume
Expand Down Expand Up @@ -567,6 +568,7 @@ int tb_domain_runtime_resume(struct tb *tb)
}
return 0;
}
#endif /* CONFIG_PM */

/**
* tb_domain_approve_switch() - Approve switch
Expand Down
12 changes: 12 additions & 0 deletions drivers/thunderbolt/icm.c
Expand Up @@ -297,10 +297,14 @@ static int icm_fr_get_route(struct tb *tb, u8 link, u8 depth, u64 *route)
return ret;
}

#ifdef CONFIG_PM
static void icm_fr_save_devices(struct tb *tb)
{
nhi_mailbox_cmd(tb->nhi, NHI_MAILBOX_SAVE_DEVS, 0);
}
#else
#define icm_fr_save_devices NULL
#endif /* CONFIG_PM */

static int
icm_fr_driver_ready(struct tb *tb, enum tb_security_level *security_level,
Expand Down Expand Up @@ -1691,6 +1695,7 @@ static int icm_driver_ready(struct tb *tb)
return 0;
}

#ifdef CONFIG_PM
static int icm_suspend(struct tb *tb)
{
struct icm *icm = tb_priv(tb);
Expand Down Expand Up @@ -1808,6 +1813,13 @@ static int icm_runtime_resume(struct tb *tb)
icm_complete(tb);
return 0;
}
#else
#define icm_suspend NULL
#define icm_rescan_work NULL
#define icm_complete NULL
#define icm_runtime_suspend NULL
#define icm_runtime_resume NULL
#endif /* CONFIG_PM */

static int icm_start(struct tb *tb)
{
Expand Down
25 changes: 16 additions & 9 deletions drivers/thunderbolt/nhi.c
Expand Up @@ -845,14 +845,6 @@ static irqreturn_t nhi_msi(int irq, void *data)
return IRQ_HANDLED;
}

static int nhi_suspend_noirq(struct device *dev)
{
struct pci_dev *pdev = to_pci_dev(dev);
struct tb *tb = pci_get_drvdata(pdev);

return tb_domain_suspend_noirq(tb);
}

static void nhi_enable_int_throttling(struct tb_nhi *nhi)
{
/* Throttling is specified in 256ns increments */
Expand All @@ -869,6 +861,15 @@ static void nhi_enable_int_throttling(struct tb_nhi *nhi)
}
}

#ifdef CONFIG_PM
static int nhi_suspend_noirq(struct device *dev)
{
struct pci_dev *pdev = to_pci_dev(dev);
struct tb *tb = pci_get_drvdata(pdev);

return tb_domain_suspend_noirq(tb);
}

static int nhi_resume_noirq(struct device *dev)
{
struct pci_dev *pdev = to_pci_dev(dev);
Expand Down Expand Up @@ -927,6 +928,7 @@ static int nhi_runtime_resume(struct device *dev)
nhi_enable_int_throttling(tb->nhi);
return tb_domain_runtime_resume(tb);
}
#endif /* CONFIG_PM */

static void nhi_shutdown(struct tb_nhi *nhi)
{
Expand Down Expand Up @@ -1095,6 +1097,7 @@ static void nhi_remove(struct pci_dev *pdev)
nhi_shutdown(nhi);
}

#ifdef CONFIG_PM
/*
* The tunneled pci bridges are siblings of us. Use resume_noirq to reenable
* the tunnels asap. Device links block the downstream bridges' resume_noirq
Expand All @@ -1116,6 +1119,10 @@ static const struct dev_pm_ops nhi_pm_ops = {
.runtime_suspend = nhi_runtime_suspend,
.runtime_resume = nhi_runtime_resume,
};
#define NHI_PM_OPS &nhi_pm_ops
#else
#define NHI_PM_OPS NULL
#endif /* CONFIG_PM */

static struct pci_device_id nhi_ids[] = {
/*
Expand Down Expand Up @@ -1170,7 +1177,7 @@ static struct pci_driver nhi_driver = {
.id_table = nhi_ids,
.probe = nhi_probe,
.remove = nhi_remove,
.driver.pm = &nhi_pm_ops,
.driver.pm = NHI_PM_OPS,
};

static int __init nhi_init(void)
Expand Down
15 changes: 12 additions & 3 deletions drivers/thunderbolt/switch.c
Expand Up @@ -632,6 +632,7 @@ static void tb_dump_switch(struct tb *tb, struct tb_regs_switch_header *sw)
sw->__unknown1, sw->__unknown4);
}

#ifdef CONFIG_PM
/**
* reset_switch() - reconfigure route, enable and send TB_CFG_PKG_RESET
*
Expand All @@ -655,6 +656,7 @@ int tb_switch_reset(struct tb *tb, u64 route)
return -EIO;
return res.err;
}
#endif /* CONFIG_PM */

struct tb_switch *get_switch_at_route(struct tb_switch *sw, u64 route)
{
Expand Down Expand Up @@ -1087,16 +1089,17 @@ static void tb_switch_release(struct device *dev)
kfree(sw);
}

#ifdef CONFIG_PM
/*
* Currently only need to provide the callbacks. Everything else is handled
* in the connection manager.
*/
static int __maybe_unused tb_switch_runtime_suspend(struct device *dev)
static int tb_switch_runtime_suspend(struct device *dev)
{
return 0;
}

static int __maybe_unused tb_switch_runtime_resume(struct device *dev)
static int tb_switch_runtime_resume(struct device *dev)
{
return 0;
}
Expand All @@ -1105,11 +1108,15 @@ static const struct dev_pm_ops tb_switch_pm_ops = {
SET_RUNTIME_PM_OPS(tb_switch_runtime_suspend, tb_switch_runtime_resume,
NULL)
};
#define TB_SWITCH_PM_OPS &tb_switch_pm_ops
#else
#define TB_SWITCH_PM_OPS NULL
#endif /* CONFIG_PM */

struct device_type tb_switch_type = {
.name = "thunderbolt_device",
.release = tb_switch_release,
.pm = &tb_switch_pm_ops,
.pm = TB_SWITCH_PM_OPS,
};

static int tb_switch_get_generation(struct tb_switch *sw)
Expand Down Expand Up @@ -1537,6 +1544,7 @@ void tb_sw_set_unplugged(struct tb_switch *sw)
}
}

#ifdef CONFIG_PM
int tb_switch_resume(struct tb_switch *sw)
{
int i, err;
Expand Down Expand Up @@ -1604,6 +1612,7 @@ void tb_switch_suspend(struct tb_switch *sw)
* effect?
*/
}
#endif /* CONFIG_PM */

struct tb_sw_lookup {
struct tb *tb;
Expand Down
8 changes: 7 additions & 1 deletion drivers/thunderbolt/tb.c
Expand Up @@ -93,6 +93,7 @@ static void tb_free_invalid_tunnels(struct tb *tb)
}
}

#ifdef CONFIG_PM
/**
* tb_free_unplugged_children() - traverse hierarchy and free unplugged switches
*/
Expand All @@ -113,7 +114,7 @@ static void tb_free_unplugged_children(struct tb_switch *sw)
}
}
}

#endif /* CONFIG_PM */

/**
* find_pci_up_port() - return the first PCIe up port on @sw or NULL
Expand Down Expand Up @@ -426,6 +427,7 @@ static int tb_start(struct tb *tb)
return 0;
}

#ifdef CONFIG_PM
static int tb_suspend_noirq(struct tb *tb)
{
struct tb_cm *tcm = tb_priv(tb);
Expand Down Expand Up @@ -467,6 +469,10 @@ static int tb_resume_noirq(struct tb *tb)

return 0;
}
#else
#define tb_suspend_noirq NULL
#define tb_resume_noirq NULL
#endif /* CONFIG_PM */

static const struct tb_cm_ops tb_cm_ops = {
.start = tb_start,
Expand Down
11 changes: 8 additions & 3 deletions drivers/thunderbolt/xdomain.c
Expand Up @@ -1051,13 +1051,14 @@ static void stop_handshake(struct tb_xdomain *xd)
cancel_delayed_work_sync(&xd->properties_changed_work);
}

static int __maybe_unused tb_xdomain_suspend(struct device *dev)
#ifdef CONFIG_PM
static int tb_xdomain_suspend(struct device *dev)
{
stop_handshake(tb_to_xdomain(dev));
return 0;
}

static int __maybe_unused tb_xdomain_resume(struct device *dev)
static int tb_xdomain_resume(struct device *dev)
{
struct tb_xdomain *xd = tb_to_xdomain(dev);

Expand All @@ -1074,11 +1075,15 @@ static int __maybe_unused tb_xdomain_resume(struct device *dev)
static const struct dev_pm_ops tb_xdomain_pm_ops = {
SET_SYSTEM_SLEEP_PM_OPS(tb_xdomain_suspend, tb_xdomain_resume)
};
#define TB_XDOMAIN_PM_OPS &tb_xdomain_pm_ops
#else
#define TB_XDOMAIN_PM_OPS NULL
#endif /* CONFIG_PM */

struct device_type tb_xdomain_type = {
.name = "thunderbolt_xdomain",
.release = tb_xdomain_release,
.pm = &tb_xdomain_pm_ops,
.pm = TB_XDOMAIN_PM_OPS,
};
EXPORT_SYMBOL_GPL(tb_xdomain_type);

Expand Down

0 comments on commit 15bb943

Please sign in to comment.