Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3BD7B6A8DB for ; Wed, 20 Mar 2024 18:37:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710959844; cv=none; b=nOix0C1/wsxmw9vkreNEPEqCxktKmVhmJwQ1gE5FpPNZ/8hbCKgJNs0yxUsp1VKQ0KgVVPQhSjWS0P+2xL3VPvKKd18I7n+NKgA1ShbpBCSo5ugHoXyEt+Zqf1+u3DwU+HQrDf9yU8JdrxUKKNg77u/hhB2ekVmVQQQuARHH3DU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710959844; c=relaxed/simple; bh=yDc8tNDwFNroHeQ0EpCiQBTb8+TT/FREzEH0aQtoTgU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=pJkyfD4GEZAlHUnj5zt9HxJ4yBmVo91UFcmF5FtsLZMESRaI07A6fQ58MY57MUMGDsmDN8xFkJyBk/ls3MlHh8aunVRltm0osyBcsPLTH6e0XZHdzLY4qgd9NbvOPx9svO4jSEnd9i+wXw9y6NZ+ukKPqnzNpKokfhYdYp0YZ6Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz; spf=pass smtp.mailfrom=suse.cz; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b=DhlxoRdG; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b=nTcoYbtA; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b=DhlxoRdG; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b=nTcoYbtA; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.cz Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="DhlxoRdG"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="nTcoYbtA"; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="DhlxoRdG"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="nTcoYbtA" Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 3534C3477E; Wed, 20 Mar 2024 18:37:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1710959839; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=wd7aTUC/EUpn4D8PiUn0ClWDDAIGnL7jlqKkK2avD0A=; b=DhlxoRdGMArKzsmtXP4lNhIGpzkCrH+yqYRiRLA1ZeuENLKdsw7eeW5E6x3z57MRtFOZ3W Urx6Lz4Kq3qNjvSI8Hg72XRScCO7MuLAlTyYuyqqxQDYpzephdBnls3sefUx6EnnRiOgc2 umL6/QqQ6uu/ylRYHsiOHfrTy2H90YE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1710959839; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=wd7aTUC/EUpn4D8PiUn0ClWDDAIGnL7jlqKkK2avD0A=; b=nTcoYbtAKqgXc1wuZpuc02W1FK1tZP0lCrpoiWlS1ZcrwJXSiyFCQAi/9+Q7hIeKNp1pwH mVAwcV6SJ3dMYiBw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1710959839; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=wd7aTUC/EUpn4D8PiUn0ClWDDAIGnL7jlqKkK2avD0A=; b=DhlxoRdGMArKzsmtXP4lNhIGpzkCrH+yqYRiRLA1ZeuENLKdsw7eeW5E6x3z57MRtFOZ3W Urx6Lz4Kq3qNjvSI8Hg72XRScCO7MuLAlTyYuyqqxQDYpzephdBnls3sefUx6EnnRiOgc2 umL6/QqQ6uu/ylRYHsiOHfrTy2H90YE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1710959839; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=wd7aTUC/EUpn4D8PiUn0ClWDDAIGnL7jlqKkK2avD0A=; b=nTcoYbtAKqgXc1wuZpuc02W1FK1tZP0lCrpoiWlS1ZcrwJXSiyFCQAi/9+Q7hIeKNp1pwH mVAwcV6SJ3dMYiBw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 1B16E136D6; Wed, 20 Mar 2024 18:37:19 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id +f+YBt8s+2VhEwAAD6G6ig (envelope-from ); Wed, 20 Mar 2024 18:37:19 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id B0760A080F; Wed, 20 Mar 2024 19:37:14 +0100 (CET) Date: Wed, 20 Mar 2024 19:37:14 +0100 From: Jan Kara To: Luis Chamberlain Cc: mgorman@suse.de, jack@suse.cz, vbabka@suse.cz, dave@stgolabs.net, ziy@nvidia.com, ryan.roberts@arm.com, kdevops@lists.linux.dev, p.raghav@samsung.com, da.gomez@samsung.com Subject: Re: [RFT 1/2] MMTests::Stat: replace List::BinarySearch Message-ID: <20240320183714.bp7hgrxgn5tm4bm3@quack3> References: <20240319044621.2682968-1-mcgrof@kernel.org> <20240319044621.2682968-2-mcgrof@kernel.org> Precedence: bulk X-Mailing-List: kdevops@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240319044621.2682968-2-mcgrof@kernel.org> Authentication-Results: smtp-out1.suse.de; none X-Spam-Level: X-Spam-Score: -3.80 X-Spamd-Result: default: False [-3.80 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; MIME_GOOD(-0.10)[text/plain]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-0.987]; RCPT_COUNT_SEVEN(0.00)[10]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; MID_RHS_NOT_FQDN(0.50)[]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] X-Spam-Flag: NO On Mon 18-03-24 21:46:19, Luis Chamberlain wrote: > List::BinarySearch is ancient and has a few issues: > > a) The project hasnt't received any updates since 2018 > b) It's licensed under GPLv1 or Artistica v1 license which are > not compatible with GPLv2 > c) Some distributions don't carry a package for it > > Debian in particular doesn't have it anymore. I looked at the code > and was bewildered with the amount of insane hacks to support ancient > versions of perl and to also support running our custom comparison > routine. > > All the above challenges seem silly to deal with on users if we can > just implement what we need and call it a day. So let's do that, and > also add unit tests for mmtests while at it, setting a set of a few > examples we can easily grow. > > While at it use SPDX license identifiers to simplify license clarity > just as we have in the kernel. The same SPDX tag is already upstream > on Linux. We can expand on this to keep things simpler later. > > Signed-off-by: Luis Chamberlain I agree the module is probably not worth the hassle so I agree with replacing it. But given we need this only from Stat module, I just would not bother with BinarySearch.pm you introduce and place the two functions directly in Stat. Also I'm not sure we really need a testing framework for this :) (I'll defer to Mel for final decision on this though). > diff --git a/bin/lib/MMTests/BinarySearch.pm b/bin/lib/MMTests/BinarySearch.pm > new file mode 100644 > index 000000000000..2189ab4176d5 > --- /dev/null > +++ b/bin/lib/MMTests/BinarySearch.pm > @@ -0,0 +1,70 @@ > +# Copyright Luis Chamberlain , 2024 > +# // SPDX-License-Identifier: GPL-2.0-or-later OR copyleft-next-0.3.1 > +# > +# Simple List::BinarySearch numeric BinarySearch.pm replacement. > +# > +# This is a re-write of our own binary search, reducing the scope to support > +# only the spaceship "<=>" operator as that's all we need. We also provide tests > +# under t/*.t to ensure compatibility and a larger list of examples and test > +# cases. > +# > +# This uses perl v5.20 subroutine signatures to let us be pedantic about the > +# arguments used. > + > +package MMTests::BinarySearch; > + > +use strict; > +use warnings; > +use feature 'signatures'; > +no warnings 'experimental::signatures'; > +use Scalar::Util qw(looks_like_number); > + > +require Exporter; > +use vars qw (@ISA @EXPORT); > + > +@ISA = qw(Exporter); > +@EXPORT = qw(&binsearch_pos_num &binsearch_range_num); > + > +sub binsearch_pos_num($target, $aref) { > + die "Only numbers allowed" unless looks_like_number($target); > + die "Expected an array reference!" unless ref $aref eq 'ARRAY'; > + > + my ($low, $high) = (0, scalar @{$aref}); > + > + while ($low < $high) { > + my $mid = int(($low + $high) / 2); > + my $result = $aref->[$mid] <=> $target; > + if ($result < 0) { > + $low = $mid + 1; > + } else { > + $high = $mid - 1; > + } > + } So IMHO this binsearch_pos_num() implementation has a bug - if 'target' is in the array, we will not return pointer to it but rather one element before it if I'm reading the code right. To replicate the functionality of the original module, it should return the first index equal to 'target' in this case. Otherwise the patch looks good... > + > + return $low; > +} Honza -- Jan Kara SUSE Labs, CR