tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Problem with i2c bus rescan - iic_search()



While working on another problem, I've noticed that rescanning an i2c bus (such as when loading an i2c device's driver module) cause an awful lot of redundant calls to driver *_match() funtion. In particular, when the spdmem(4) driver with its 8 possible attachments is loaded, each possible spdmem instance is match()'d 8 times, for a total of 64 iterations.

iic_search() (in src/sys/dev/i2c/i2c.c) currently calls the match() function before validating that any matching device could be attached

        if (config_match(parent, cf, &ia) > 0) {
                if (ia.ia_addr != (i2c_addr_t)-1 &&
                    ia.ia_addr <= I2C_MAX_ADDR &&
                    !sc->sc_devices[ia.ia_addr])
                        sc->sc_devices[ia.ia_addr] =
                            config_attach(parent, cf, &ia, iic_print);
        }
        return 0;

In my opinion, if the ia.ia_addr checks (or the check for "a device is already attached") will fail, one should not bother checking for a match for that set of i2c_attach_args. Thus the above could be rewritten as

        if (ia.ia_addr != (i2c_addr_t)-1 &&
            ia.ia_addr <= I2C_MAX_ADDR &&
            sc->sc_devices[ia.ia_addr] == NULL)
                if (config_match(parent, cf, &ia) > 0)
                        sc-sc_devices[ia.ia_addr] =
                            config_attach(parent, cf, &ia, iic_print);

        return 0;


Comments?



-------------------------------------------------------------------------
| Paul Goyette     | PGP Key fingerprint:     | E-mail addresses:       |
| Customer Service | FA29 0E3B 35AF E8AE 6651 | paul at whooppee.com    |
| Network Engineer | 0786 F758 55DE 53BA 7731 | pgoyette at juniper.net |
| Kernel Developer |                          | pgoyette at netbsd.org  |
-------------------------------------------------------------------------


Home | Main Index | Thread Index | Old Index