Commit 149ba66a authored by Gavin Shan's avatar Gavin Shan Committed by Michael Ellerman

drivers/pci/hotplug: Remove likely() and unlikely() in powernv driver

This removes likely() and unlikely() in pnv_php.c as the code isn't
running in hot path. Those macros to affect CPU's branch stream don't
help a lot for performance. I used them to identify the cases are
likely or unlikely to happen. No logical changes introduced.
Signed-off-by: default avatarGavin Shan <gwshan@linux.vnet.ibm.com>
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
parent 313483dd
...@@ -122,7 +122,7 @@ static void pnv_php_detach_device_nodes(struct device_node *parent) ...@@ -122,7 +122,7 @@ static void pnv_php_detach_device_nodes(struct device_node *parent)
of_node_put(dn); of_node_put(dn);
refcount = atomic_read(&dn->kobj.kref.refcount); refcount = atomic_read(&dn->kobj.kref.refcount);
if (unlikely(refcount != 1)) if (refcount != 1)
pr_warn("Invalid refcount %d on <%s>\n", pr_warn("Invalid refcount %d on <%s>\n",
refcount, of_node_full_name(dn)); refcount, of_node_full_name(dn));
...@@ -184,11 +184,11 @@ static int pnv_php_populate_changeset(struct of_changeset *ocs, ...@@ -184,11 +184,11 @@ static int pnv_php_populate_changeset(struct of_changeset *ocs,
for_each_child_of_node(dn, child) { for_each_child_of_node(dn, child) {
ret = of_changeset_attach_node(ocs, child); ret = of_changeset_attach_node(ocs, child);
if (unlikely(ret)) if (ret)
break; break;
ret = pnv_php_populate_changeset(ocs, child); ret = pnv_php_populate_changeset(ocs, child);
if (unlikely(ret)) if (ret)
break; break;
} }
...@@ -201,7 +201,7 @@ static void *pnv_php_add_one_pdn(struct device_node *dn, void *data) ...@@ -201,7 +201,7 @@ static void *pnv_php_add_one_pdn(struct device_node *dn, void *data)
struct pci_dn *pdn; struct pci_dn *pdn;
pdn = pci_add_device_node_info(hose, dn); pdn = pci_add_device_node_info(hose, dn);
if (unlikely(!pdn)) if (!pdn)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
return NULL; return NULL;
...@@ -224,21 +224,21 @@ static int pnv_php_add_devtree(struct pnv_php_slot *php_slot) ...@@ -224,21 +224,21 @@ static int pnv_php_add_devtree(struct pnv_php_slot *php_slot)
* fits the real size. * fits the real size.
*/ */
fdt1 = kzalloc(0x10000, GFP_KERNEL); fdt1 = kzalloc(0x10000, GFP_KERNEL);
if (unlikely(!fdt1)) { if (!fdt1) {
ret = -ENOMEM; ret = -ENOMEM;
dev_warn(&php_slot->pdev->dev, "Cannot alloc FDT blob\n"); dev_warn(&php_slot->pdev->dev, "Cannot alloc FDT blob\n");
goto out; goto out;
} }
ret = pnv_pci_get_device_tree(php_slot->dn->phandle, fdt1, 0x10000); ret = pnv_pci_get_device_tree(php_slot->dn->phandle, fdt1, 0x10000);
if (unlikely(ret)) { if (ret) {
dev_warn(&php_slot->pdev->dev, "Error %d getting FDT blob\n", dev_warn(&php_slot->pdev->dev, "Error %d getting FDT blob\n",
ret); ret);
goto free_fdt1; goto free_fdt1;
} }
fdt = kzalloc(fdt_totalsize(fdt1), GFP_KERNEL); fdt = kzalloc(fdt_totalsize(fdt1), GFP_KERNEL);
if (unlikely(!fdt)) { if (!fdt) {
ret = -ENOMEM; ret = -ENOMEM;
dev_warn(&php_slot->pdev->dev, "Cannot %d bytes memory\n", dev_warn(&php_slot->pdev->dev, "Cannot %d bytes memory\n",
fdt_totalsize(fdt1)); fdt_totalsize(fdt1));
...@@ -248,7 +248,7 @@ static int pnv_php_add_devtree(struct pnv_php_slot *php_slot) ...@@ -248,7 +248,7 @@ static int pnv_php_add_devtree(struct pnv_php_slot *php_slot)
/* Unflatten device tree blob */ /* Unflatten device tree blob */
memcpy(fdt, fdt1, fdt_totalsize(fdt1)); memcpy(fdt, fdt1, fdt_totalsize(fdt1));
dt = of_fdt_unflatten_tree(fdt, php_slot->dn, NULL); dt = of_fdt_unflatten_tree(fdt, php_slot->dn, NULL);
if (unlikely(!dt)) { if (!dt) {
ret = -EINVAL; ret = -EINVAL;
dev_warn(&php_slot->pdev->dev, "Cannot unflatten FDT\n"); dev_warn(&php_slot->pdev->dev, "Cannot unflatten FDT\n");
goto free_fdt; goto free_fdt;
...@@ -258,7 +258,7 @@ static int pnv_php_add_devtree(struct pnv_php_slot *php_slot) ...@@ -258,7 +258,7 @@ static int pnv_php_add_devtree(struct pnv_php_slot *php_slot)
of_changeset_init(&php_slot->ocs); of_changeset_init(&php_slot->ocs);
pnv_php_reverse_nodes(php_slot->dn); pnv_php_reverse_nodes(php_slot->dn);
ret = pnv_php_populate_changeset(&php_slot->ocs, php_slot->dn); ret = pnv_php_populate_changeset(&php_slot->ocs, php_slot->dn);
if (unlikely(ret)) { if (ret) {
pnv_php_reverse_nodes(php_slot->dn); pnv_php_reverse_nodes(php_slot->dn);
dev_warn(&php_slot->pdev->dev, "Error %d populating changeset\n", dev_warn(&php_slot->pdev->dev, "Error %d populating changeset\n",
ret); ret);
...@@ -267,7 +267,7 @@ static int pnv_php_add_devtree(struct pnv_php_slot *php_slot) ...@@ -267,7 +267,7 @@ static int pnv_php_add_devtree(struct pnv_php_slot *php_slot)
php_slot->dn->child = NULL; php_slot->dn->child = NULL;
ret = of_changeset_apply(&php_slot->ocs); ret = of_changeset_apply(&php_slot->ocs);
if (unlikely(ret)) { if (ret) {
dev_warn(&php_slot->pdev->dev, "Error %d applying changeset\n", dev_warn(&php_slot->pdev->dev, "Error %d applying changeset\n",
ret); ret);
goto destroy_changeset; goto destroy_changeset;
...@@ -301,7 +301,7 @@ int pnv_php_set_slot_power_state(struct hotplug_slot *slot, ...@@ -301,7 +301,7 @@ int pnv_php_set_slot_power_state(struct hotplug_slot *slot,
int ret; int ret;
ret = pnv_pci_set_power_state(php_slot->id, state, &msg); ret = pnv_pci_set_power_state(php_slot->id, state, &msg);
if (likely(ret > 0)) { if (ret > 0) {
if (be64_to_cpu(msg.params[1]) != php_slot->dn->phandle || if (be64_to_cpu(msg.params[1]) != php_slot->dn->phandle ||
be64_to_cpu(msg.params[2]) != state || be64_to_cpu(msg.params[2]) != state ||
be64_to_cpu(msg.params[3]) != OPAL_SUCCESS) { be64_to_cpu(msg.params[3]) != OPAL_SUCCESS) {
...@@ -311,7 +311,7 @@ int pnv_php_set_slot_power_state(struct hotplug_slot *slot, ...@@ -311,7 +311,7 @@ int pnv_php_set_slot_power_state(struct hotplug_slot *slot,
be64_to_cpu(msg.params[3])); be64_to_cpu(msg.params[3]));
return -ENOMSG; return -ENOMSG;
} }
} else if (unlikely(ret < 0)) { } else if (ret < 0) {
dev_warn(&php_slot->pdev->dev, "Error %d powering %s\n", dev_warn(&php_slot->pdev->dev, "Error %d powering %s\n",
ret, (state == OPAL_PCI_SLOT_POWER_ON) ? "on" : "off"); ret, (state == OPAL_PCI_SLOT_POWER_ON) ? "on" : "off");
return ret; return ret;
...@@ -338,7 +338,7 @@ static int pnv_php_get_power_state(struct hotplug_slot *slot, u8 *state) ...@@ -338,7 +338,7 @@ static int pnv_php_get_power_state(struct hotplug_slot *slot, u8 *state)
* be on. * be on.
*/ */
ret = pnv_pci_get_power_state(php_slot->id, &power_state); ret = pnv_pci_get_power_state(php_slot->id, &power_state);
if (unlikely(ret)) { if (ret) {
dev_warn(&php_slot->pdev->dev, "Error %d getting power status\n", dev_warn(&php_slot->pdev->dev, "Error %d getting power status\n",
ret); ret);
} else { } else {
...@@ -360,7 +360,7 @@ static int pnv_php_get_adapter_state(struct hotplug_slot *slot, u8 *state) ...@@ -360,7 +360,7 @@ static int pnv_php_get_adapter_state(struct hotplug_slot *slot, u8 *state)
* get that, it will fail back to be empty. * get that, it will fail back to be empty.
*/ */
ret = pnv_pci_get_presence_state(php_slot->id, &presence); ret = pnv_pci_get_presence_state(php_slot->id, &presence);
if (likely(ret >= 0)) { if (ret >= 0) {
*state = presence; *state = presence;
slot->info->adapter_status = presence; slot->info->adapter_status = presence;
ret = 0; ret = 0;
...@@ -393,7 +393,7 @@ static int pnv_php_enable(struct pnv_php_slot *php_slot, bool rescan) ...@@ -393,7 +393,7 @@ static int pnv_php_enable(struct pnv_php_slot *php_slot, bool rescan)
/* Retrieve slot presence status */ /* Retrieve slot presence status */
ret = pnv_php_get_adapter_state(slot, &presence); ret = pnv_php_get_adapter_state(slot, &presence);
if (unlikely(ret)) if (ret)
return ret; return ret;
/* Proceed if there have nothing behind the slot */ /* Proceed if there have nothing behind the slot */
...@@ -414,7 +414,7 @@ static int pnv_php_enable(struct pnv_php_slot *php_slot, bool rescan) ...@@ -414,7 +414,7 @@ static int pnv_php_enable(struct pnv_php_slot *php_slot, bool rescan)
php_slot->power_state_check = true; php_slot->power_state_check = true;
ret = pnv_php_get_power_state(slot, &power_status); ret = pnv_php_get_power_state(slot, &power_status);
if (unlikely(ret)) if (ret)
return ret; return ret;
if (power_status != OPAL_PCI_SLOT_POWER_ON) if (power_status != OPAL_PCI_SLOT_POWER_ON)
...@@ -423,7 +423,7 @@ static int pnv_php_enable(struct pnv_php_slot *php_slot, bool rescan) ...@@ -423,7 +423,7 @@ static int pnv_php_enable(struct pnv_php_slot *php_slot, bool rescan)
/* Check the power status. Scan the slot if it is already on */ /* Check the power status. Scan the slot if it is already on */
ret = pnv_php_get_power_state(slot, &power_status); ret = pnv_php_get_power_state(slot, &power_status);
if (unlikely(ret)) if (ret)
return ret; return ret;
if (power_status == OPAL_PCI_SLOT_POWER_ON) if (power_status == OPAL_PCI_SLOT_POWER_ON)
...@@ -431,7 +431,7 @@ static int pnv_php_enable(struct pnv_php_slot *php_slot, bool rescan) ...@@ -431,7 +431,7 @@ static int pnv_php_enable(struct pnv_php_slot *php_slot, bool rescan)
/* Power is off, turn it on and then scan the slot */ /* Power is off, turn it on and then scan the slot */
ret = pnv_php_set_slot_power_state(slot, OPAL_PCI_SLOT_POWER_ON); ret = pnv_php_set_slot_power_state(slot, OPAL_PCI_SLOT_POWER_ON);
if (unlikely(ret)) if (ret)
return ret; return ret;
scan: scan:
...@@ -515,27 +515,27 @@ static struct pnv_php_slot *pnv_php_alloc_slot(struct device_node *dn) ...@@ -515,27 +515,27 @@ static struct pnv_php_slot *pnv_php_alloc_slot(struct device_node *dn)
uint64_t id; uint64_t id;
label = of_get_property(dn, "ibm,slot-label", NULL); label = of_get_property(dn, "ibm,slot-label", NULL);
if (unlikely(!label)) if (!label)
return NULL; return NULL;
if (pnv_pci_get_slot_id(dn, &id)) if (pnv_pci_get_slot_id(dn, &id))
return NULL; return NULL;
bus = pci_find_bus_by_node(dn); bus = pci_find_bus_by_node(dn);
if (unlikely(!bus)) if (!bus)
return NULL; return NULL;
php_slot = kzalloc(sizeof(*php_slot), GFP_KERNEL); php_slot = kzalloc(sizeof(*php_slot), GFP_KERNEL);
if (unlikely(!php_slot)) if (!php_slot)
return NULL; return NULL;
php_slot->name = kstrdup(label, GFP_KERNEL); php_slot->name = kstrdup(label, GFP_KERNEL);
if (unlikely(!php_slot->name)) { if (!php_slot->name) {
kfree(php_slot); kfree(php_slot);
return NULL; return NULL;
} }
if (likely(dn->child && PCI_DN(dn->child))) if (dn->child && PCI_DN(dn->child))
php_slot->slot_no = PCI_SLOT(PCI_DN(dn->child)->devfn); php_slot->slot_no = PCI_SLOT(PCI_DN(dn->child)->devfn);
else else
php_slot->slot_no = -1; /* Placeholder slot */ php_slot->slot_no = -1; /* Placeholder slot */
...@@ -567,7 +567,7 @@ static int pnv_php_register_slot(struct pnv_php_slot *php_slot) ...@@ -567,7 +567,7 @@ static int pnv_php_register_slot(struct pnv_php_slot *php_slot)
/* Check if the slot is registered or not */ /* Check if the slot is registered or not */
parent = pnv_php_find_slot(php_slot->dn); parent = pnv_php_find_slot(php_slot->dn);
if (unlikely(parent)) { if (parent) {
pnv_php_put_slot(parent); pnv_php_put_slot(parent);
return -EEXIST; return -EEXIST;
} }
...@@ -575,7 +575,7 @@ static int pnv_php_register_slot(struct pnv_php_slot *php_slot) ...@@ -575,7 +575,7 @@ static int pnv_php_register_slot(struct pnv_php_slot *php_slot)
/* Register PCI slot */ /* Register PCI slot */
ret = pci_hp_register(&php_slot->slot, php_slot->bus, ret = pci_hp_register(&php_slot->slot, php_slot->bus,
php_slot->slot_no, php_slot->name); php_slot->slot_no, php_slot->name);
if (unlikely(ret)) { if (ret) {
dev_warn(&php_slot->pdev->dev, "Error %d registering slot\n", dev_warn(&php_slot->pdev->dev, "Error %d registering slot\n",
ret); ret);
return ret; return ret;
...@@ -625,15 +625,15 @@ static int pnv_php_register_one(struct device_node *dn) ...@@ -625,15 +625,15 @@ static int pnv_php_register_one(struct device_node *dn)
return -ENXIO; return -ENXIO;
php_slot = pnv_php_alloc_slot(dn); php_slot = pnv_php_alloc_slot(dn);
if (unlikely(!php_slot)) if (!php_slot)
return -ENODEV; return -ENODEV;
ret = pnv_php_register_slot(php_slot); ret = pnv_php_register_slot(php_slot);
if (unlikely(ret)) if (ret)
goto free_slot; goto free_slot;
ret = pnv_php_enable(php_slot, false); ret = pnv_php_enable(php_slot, false);
if (unlikely(ret)) if (ret)
goto unregister_slot; goto unregister_slot;
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment