Module: Mesa Branch: staging/20.1 Commit: 7452d369b6f4176a77778c5b53be64e83e14e824 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=7452d369b6f4176a77778c5b53be64e83e14e824
Author: Rob Clark <[email protected]> Date: Sun Jul 5 11:35:01 2020 -0700 freedreno/fdperf: better compatible string matching Previously we would match the start of the compatible string, in a couple of cases, in order to match compatible strings like "qcom,adreno-630.2". But these cases would always list a more generic compatible (ie. "qcom,adreno") as a later choice. So if we parse all the compatible strings, we can do a more precise exact match. This avoids us accidentially matching on "qcom,adreno-smmu" and the hilarity that ensues. Fixes: 5a13507164a ("freedreno/perfcntrs: add fdperf") Signed-off-by: Rob Clark <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5762> (cherry picked from commit 385d036f5836714bc59937369fdc3447fc0da5fb) --- .pick_status.json | 2 +- src/freedreno/perfcntrs/fdperf.c | 36 ++++++++++++++++++++++++++++++++---- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index e13e2681338..f758284ea3a 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -76,7 +76,7 @@ "description": "freedreno/fdperf: better compatible string matching", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "master_sha": null, "because_sha": "5a13507164a26fc796f02c57a24468b834254b4d" }, diff --git a/src/freedreno/perfcntrs/fdperf.c b/src/freedreno/perfcntrs/fdperf.c index e86595ae967..25c1a6b7f81 100644 --- a/src/freedreno/perfcntrs/fdperf.c +++ b/src/freedreno/perfcntrs/fdperf.c @@ -276,6 +276,37 @@ find_freqs(void) free(path); } +static const char * compatibles[] = { + "qcom,adreno-3xx", + "qcom,kgsl-3d0", + "amd,imageon", + "qcom,adreno", +}; + +/** + * compatstrs is a list of compatible strings separated by null, ie. + * + * compatible = "qcom,adreno-630.2", "qcom,adreno"; + * + * would result in "qcom,adreno-630.2\0qcom,adreno\0" + */ +static bool match_compatible(char *compatstrs, int sz) +{ + while (sz > 0) { + char *compatible = compatstrs; + + for (unsigned i = 0; i < ARRAY_SIZE(compatibles); i++) { + if (strcmp(compatible, compatibles[i]) == 0) { + return true; + } + } + + compatstrs += strlen(compatible) + 1; + sz -= strlen(compatible) + 1; + } + return false; +} + static int find_device_fn(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf) { @@ -284,10 +315,7 @@ find_device_fn(const char *fpath, const struct stat *sb, int typeflag, struct FT if (strcmp(fname, "compatible") == 0) { char *str = readfile(fpath, &sz); - if ((strcmp(str, "qcom,adreno-3xx") == 0) || - (strcmp(str, "qcom,kgsl-3d0") == 0) || - (strstr(str, "amd,imageon") == str) || - (strstr(str, "qcom,adreno") == str)) { + if (match_compatible(str, sz)) { int dlen = strlen(fpath) - strlen("/compatible"); dev.dtnode = malloc(dlen + 1); memcpy(dev.dtnode, fpath, dlen); _______________________________________________ mesa-commit mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/mesa-commit
