Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp2874382rdb; Fri, 22 Sep 2023 10:36:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHMtXRFwFK4vvUN1B2nMf+wjFR1pBz7Ku/hxsDZZdz+emyerWEuzBnT9w8wF0vh/kJfNgqO X-Received: by 2002:a17:90b:17ce:b0:274:922d:4b35 with SMTP id me14-20020a17090b17ce00b00274922d4b35mr392257pjb.1.1695404165998; Fri, 22 Sep 2023 10:36:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695404165; cv=none; d=google.com; s=arc-20160816; b=ihAimsfvyhSN4Pn8Fkob2QpUZtYGzjgKceYrpn3o3vw2zZOXby6qKD3cs7w87NfVJD QNykeKpb481GtCtGWAF3GzgZsk2pGOvj/NrtqwiGkc1ASlZYQkgHW5kRyINyLiGOAtqp DIjWFuPlWLc+In+L9tg4XxwYD2B9vCAmYcT4bQyLgH+05eChFjaMsURUp9bbVTGeQWDY dYP2DgYsGmCOil8bXW/UidqR8P67Ed5H6XF78O38QSHJZE83u17yQLDtLX9wJgvdmjql qwU/CGR6aAraDeZ6O09zwR2i/s/AIDJnQt9xpZeW1gZLU4zO0gCZXgmRJE7LvNF2tu5p 4/bg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=cIAB6MpcjuuKqpe+1Lhuap6hKVsOivGLkNwO83oo9k0=; fh=+XkJcXOKJ4Dl6AYTln3UzvhZHjSiM5yCnDKdoCP8e7U=; b=xCtKzVzYFbZ3AlXiFxJbhzjXqmGaU6ESXGT72r9DjtT07zJilds/UyCo52Pik3Eb33 G6BTZaZ1QCXnbVuL9bGsImEOfuwCFI04wNSZ5IPtW53ozAoGJ3m5detFE8fkEjn9EtpG w94q4M+2+zegjjn8M3qiNukWPTjbQni17P4OPHH2CQhaxTGhrVaUtQiR9xu2iqHrz3zE KiX2pIi1Q3TeQdqGbGRhnSTxkLhCZnERiOtcwIFsGryXe9UnTVZgoKezMAf4orqsQrDS ggqPZhYYXj6QOzy4yPLR+VM0HYEaLg/TUaBCYhJVAdRh8/iYVTEEZmGQSVQaji3nH9Mf fhqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=DdXYddpV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id ds12-20020a17090b08cc00b00263d00e1c54si4287162pjb.54.2023.09.22.10.36.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 10:36:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=DdXYddpV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 0A9A281DF25C; Fri, 22 Sep 2023 04:18:29 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229800AbjIVLSG (ORCPT + 99 others); Fri, 22 Sep 2023 07:18:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230156AbjIVLSF (ORCPT ); Fri, 22 Sep 2023 07:18:05 -0400 Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [IPv6:2a00:1450:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A866AF; Fri, 22 Sep 2023 04:17:59 -0700 (PDT) Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-50437f39c9dso1036218e87.3; Fri, 22 Sep 2023 04:17:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695381477; x=1695986277; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=cIAB6MpcjuuKqpe+1Lhuap6hKVsOivGLkNwO83oo9k0=; b=DdXYddpVAz5TSDVu2S7BpvGzts8SN4rn2NVYUSpgm1KVA3cPLCCzb83ukZes6s0P9s Rje2sFAV7pmqKCg3vzlQ95AjtaGajZQVQYYpVxDzS/qgZ89usx9LBbjMQcUthrsDQEaF 9/3mup9+mZGXcWL1enfi2ZgksElk4prlBE3gBqMXBMUImcDcYIHjP9mKi9gdHP40OShs 5u80suFrU+AaZlipgLFB8Nui2cKoiiyIs3JwOBGe5gX6ntrBw9Qx/+4DHPKRudkjU/Jl LDAKLSbRhfpzO4DTsfBUA+mL/5lhq62eaDr0mmLqesOyK8nLkAZ3HX3Y/5qp/cXzeFWy GqtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695381477; x=1695986277; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=cIAB6MpcjuuKqpe+1Lhuap6hKVsOivGLkNwO83oo9k0=; b=szRwBVhqiZvOcNR1FUge2ByEvQnkwzVvzJZ03Jj57nBl/XMGm0VOBbChskdRobCn8s Ed2CyCkgBu41UEP+OeWHrYRc/qbcz62r4U1WltuK4gQhLWNVe7v1F0Z1tW18mln1FEtT lRQ1IcWIsN5A1UcbUgX9zAF/00gBNKnWUKAP/JBmhTUrM2wqvGsBGnOqqo4f1kslXcpG Zuj0fwpE1qYpiU9nKLEwQv7mPlSe+f2pmAfk4bjEM6tX7yLss2eqX5uHgy/HjxMxwsQ3 H/2kOOKy7kEjUr2YNH6cIXy5WsEzC98xlmFpkAY9z0rwQeMEVaYWJOrV7amoLmqaF2yq jwBQ== X-Gm-Message-State: AOJu0Yw/aysW0+YcjzcElcYq8/1Wp5MAEu9X2sli3p32h0UVqBp6OUFj uWW/WOnpChJXIGayhsRdCmI= X-Received: by 2002:a05:6512:2356:b0:504:35a1:31ce with SMTP id p22-20020a056512235600b0050435a131cemr2576998lfu.30.1695381477520; Fri, 22 Sep 2023 04:17:57 -0700 (PDT) Received: from dc78bmyyyyyyyyyyyyyyt-3.rev.dnainternet.fi (dc78bmyyyyyyyyyyyyyyt-3.rev.dnainternet.fi. [2001:14ba:16f8:1500::1]) by smtp.gmail.com with ESMTPSA id u2-20020a056512040200b005030a35019dsm692099lfk.178.2023.09.22.04.17.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 04:17:56 -0700 (PDT) Date: Fri, 22 Sep 2023 14:17:49 +0300 From: Matti Vaittinen To: Matti Vaittinen , Matti Vaittinen Cc: Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Matti Vaittinen , Andy Shevchenko , Angel Iglesias , Andreas Klinger , Christophe JAILLET , Benjamin Bara , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 3/6] iio: try searching for exact scan_mask Message-ID: <24a577e6e157e1199817ab36631cec51675ef3ca.1695380366.git.mazziesaccount@gmail.com> References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="7R35CQ0ZLI6pqD5C" Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Fri, 22 Sep 2023 04:18:29 -0700 (PDT) --7R35CQ0ZLI6pqD5C Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable When IIO goes through the available scan masks in order to select the best suiting one, it will just accept the first listed subset of channels which meets the user's requirements. This works great for most of the drivers as they can sort the list of channels in the order where the 'least costy' channel selections come first. It may be that in some cases the ordering of the list of available scan masks is not thoroughly considered. We can't really try outsmarting the drivers by selecting the smallest supported subset - as this might not be the 'least costy one' - but we can at least try searching through the list to see if we have an exactly matching mask. It should be sane assumption that if the device can support reading only the exact channels user is interested in, then this should be also the least costy selection - and if it is not and optimization is important, then the driver could consider omitting setting the 'available_scan_mask' and doing demuxing - or just omitting the 'costy exact match' and providing only the more efficient broader selection of channels. Signed-off-by: Matti Vaittinen --- drivers/iio/industrialio-buffer.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-b= uffer.c index 176d31d9f9d8..e97396623373 100644 --- a/drivers/iio/industrialio-buffer.c +++ b/drivers/iio/industrialio-buffer.c @@ -411,19 +411,32 @@ static const unsigned long *iio_scan_mask_match(const= unsigned long *av_masks, const unsigned long *mask, bool strict) { + const unsigned long *first_subset =3D NULL; + if (bitmap_empty(mask, masklength)) return NULL; - while (*av_masks) { - if (strict) { + + if (strict) { + while (*av_masks) { if (bitmap_equal(mask, av_masks, masklength)) return av_masks; - } else { - if (bitmap_subset(mask, av_masks, masklength)) - return av_masks; + + av_masks +=3D BITS_TO_LONGS(masklength); } + + return NULL; + } + while (*av_masks) { + if (bitmap_equal(mask, av_masks, masklength)) + return av_masks; + + if (!first_subset && bitmap_subset(mask, av_masks, masklength)) + first_subset =3D av_masks; + av_masks +=3D BITS_TO_LONGS(masklength); } - return NULL; + + return first_subset; } =20 static bool iio_validate_scan_mask(struct iio_dev *indio_dev, --=20 2.41.0 --=20 Matti Vaittinen, Linux device drivers ROHM Semiconductors, Finland SWDC Kiviharjunlenkki 1E 90220 OULU FINLAND ~~~ "I don't think so," said Rene Descartes. Just then he vanished ~~~ Simon says - in Latin please. ~~~ "non cogito me" dixit Rene Descarte, deinde evanescavit ~~~ Thanks to Simon Glass for the translation =3D]=20 --7R35CQ0ZLI6pqD5C Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEIx+f8wZb28fLKEhTeFA3/03aocUFAmUNd90ACgkQeFA3/03a ocU2WQf6Auw4pqbkWyR7JsNtuC7v1QjKz5jrZegmivTs0dL1j1z10SwoAHvS0A9W asnYKWnIeu4+JapN1nQsg/oSmhMIB155kvieyIywiOmMRONTkw1TS34ldE4jpYAd osVM3JnM8tXCqXKjFJRB69OuRSXXr3+S6h3QGGdnKeTvsJLv4FonQmEuPtKZTp7u 8Xo6CZSOzG8gXGrG6D6G/Mafq9Y9/Fl8lhURwk/Ri2CdjG7laXZk2/JjKoq1Mb7t vHY51PbtMB+W/wnSY8ictXAn5OXV4zuFvL+aa0IRzIgKzRejkZpWIVZhZIJAUM0P bPF3yRpfUKlaAj/5pAsZkUjeFR0T+A== =pMvn -----END PGP SIGNATURE----- --7R35CQ0ZLI6pqD5C--