From: Jean Delvare <jdelvare@suse.de>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Jani Nikula <jani.nikula@linux.intel.com>,
Daniel Vetter <daniel.vetter@intel.com>,
"Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
Jeff Garzik <jgarzik@redhat.com>,
Hans de Goede <hdegoede@redhat.com>
Subject: [PATCH] firmware: dmi: Optimize dmi_matches
Date: Thu, 27 Jul 2017 08:31:28 +0200 [thread overview]
Message-ID: <20170727083128.7ab14de9@endymion> (raw)
Function dmi_matches can me made a bit faster:
* The documented purpose of dmi_initialized is to catch too early
calls to dmi_check_system(). I'm not fully convinced it justifies
slowing down the initialization of all systems out there, but at
least the check should not have been moved from dmi_check_system()
to dmi_matches(). dmi_matches() is being called for every entry of
the table passed to dmi_check_system(), causing the same redundant
check to be performed again and again. So move it back to
dmi_check_system(), reverting this specific portion of commit
d7b1956fed33 ("DMI: Introduce dmi_first_match to make the interface
more flexible").
* Don't check for the exact_match flag again when we already know its
value.
Signed-off-by: Jean Delvare <jdelvare@suse.de>
Cc: Jani Nikula <jani.nikula@linux.intel.com>
Cc: Daniel Vetter <daniel.vetter@intel.com>
Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Cc: Jeff Garzik <jgarzik@redhat.com>
---
Regarding dmi_initialized, I don't think it makes sense to check for
a possible bad initialization order at run time on every system when
it is all decided at build time. If a developer introduces a new call
to dmi_check_system() and it is too early in the initialization
sequence, I believe he/she would notice upon first testing, and a
comment to his/her intention in the source code would serve the same
purpose without the worldwide performance penalty. Would anyone
object to such a change?
drivers/firmware/dmi_scan.c | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
--- linux-4.12.orig/drivers/firmware/dmi_scan.c 2017-07-27 08:15:38.283519194 +0200
+++ linux-4.12/drivers/firmware/dmi_scan.c 2017-07-27 08:26:23.013053058 +0200
@@ -784,19 +784,20 @@ static bool dmi_matches(const struct dmi
{
int i;
- WARN(!dmi_initialized, KERN_ERR "dmi check: not initialized yet.\n");
-
for (i = 0; i < ARRAY_SIZE(dmi->matches); i++) {
int s = dmi->matches[i].slot;
if (s == DMI_NONE)
break;
if (dmi_ident[s]) {
- if (!dmi->matches[i].exact_match &&
- strstr(dmi_ident[s], dmi->matches[i].substr))
- continue;
- else if (dmi->matches[i].exact_match &&
- !strcmp(dmi_ident[s], dmi->matches[i].substr))
- continue;
+ if (dmi->matches[i].exact_match) {
+ if (!strcmp(dmi_ident[s],
+ dmi->matches[i].substr))
+ continue;
+ } else {
+ if (strstr(dmi_ident[s],
+ dmi->matches[i].substr))
+ continue;
+ }
}
/* No match */
@@ -832,6 +833,8 @@ int dmi_check_system(const struct dmi_sy
int count = 0;
const struct dmi_system_id *d;
+ WARN(!dmi_initialized, KERN_ERR "dmi check: not initialized yet.\n");
+
for (d = list; !dmi_is_end_of_table(d); d++)
if (dmi_matches(d)) {
count++;
--
Jean Delvare
SUSE L3 Support
reply other threads:[~2017-07-27 6:31 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170727083128.7ab14de9@endymion \
--to=jdelvare@suse.de \
--cc=daniel.vetter@intel.com \
--cc=hdegoede@redhat.com \
--cc=jani.nikula@linux.intel.com \
--cc=jgarzik@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=rafael.j.wysocki@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox