Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp1046760lqt; Tue, 19 Mar 2024 11:04:01 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXyS5+l/4BbrmAv3jXD9XUejVrQjbPgSvTXm2vTFjmIi/RPgwAhOqkOLi8m3Z3iw1jWKAPHwV2NJPPiZQvQs+6ICEMXwfbOjksXz8QtZA== X-Google-Smtp-Source: AGHT+IFC2xS98W0IaV2Bpzt15U5Ptc9YjWHNVjFAN/OUo2bKeJWoSxcslyB1IwxlP5qND1xNgjLH X-Received: by 2002:a2e:be8f:0:b0:2d3:ba98:473 with SMTP id a15-20020a2ebe8f000000b002d3ba980473mr11066157ljr.19.1710871441605; Tue, 19 Mar 2024 11:04:01 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710871441; cv=pass; d=google.com; s=arc-20160816; b=NBgjA1LTXDzKHdTAJMZ8G56pCPJ1Zwi5iV0vpXRIRCuqF48FZemrKLjbB1CwbZy43x KFYqRRv6ys+vFruWZ1mEduJoV7I8gt2xLHxlpMGhWQ5RLYFzlPW+JiMHVy6tKIEHVO21 qIOIrT1BoxKrxTmzSKnMPXUGYPSiAJLn/TowGAqB5zg8Mjlfofzeit8A+SsLK5vIZKY2 zkyxKbKNb/pWj7LXUTjX4z8jYHHMGW8faLy4Pi8wooFg4CAeJ2sFs6HdMsM727vuNXUi MBW937dj0fplCKAXAuw4VRtZs1RN9lZ0JXMcXAMZRsQcwlOkI461H/cCkp5nIB5M6Ry8 cKIQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=vXm1fu9C4vX46h0sj29/lTEeornZUsKUb3fjEsz6jiw=; fh=VxMU6/HQVyTWHx630YIKrkW6c0qoiU2M7kWhHtO6BhU=; b=F2xIIE7a/wsQJczflG3Rm2Xn5jx6H5smJyZpIdywEx9Oly2JorZrhgNSbNgzdH6XZy 1fXySVFEFzAmPz4y70T5DuOmiTHesp8Qh1sIRMDDV/SUMOBnT5LnGBPIi0BiBFlvIY0b Gndc0mVhHkgoQRNqjg5P1J/dTZfSLLnwQWv3hebsTkIgGnX3HOz4LX1d38gwmz8ImrEb KL/eCvN2+bpJx9kJAi3zkklF0fZztXY8dZr38oQoT4DmfFbEAkMFGL2RruN2RPRzA4ZC HMuYWb1IVHCrptI/iljkyH1iFUjZ3BBPilSVatXHs+x/nXbUBNECzJAGVu/xRugojNkS 3Vwg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=WOsHWhXu; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-107968-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-107968-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id u8-20020a50c048000000b00568b392e408si4423909edd.237.2024.03.19.11.04.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 11:04:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-107968-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=WOsHWhXu; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-107968-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-107968-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 670F41F22BF3 for ; Tue, 19 Mar 2024 18:03:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BADDF5FB96; Tue, 19 Mar 2024 18:00:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WOsHWhXu" Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (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 2BF90208D0; Tue, 19 Mar 2024 18:00:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710871258; cv=none; b=eEo3BAA7ndSW7MhBPhEjWi/QIpfjPANHTSenYfnW1sfleRIVbxElrUxWTbbs1J7IZj6IGAF8Ah8niQo6sCjwXp4N1vWb5BpGU3opFJs9KwX6FBXKJdeLv8Men0WxnWZS5mSP+6qqw9K1dt55LDRpQ8R2hBMG7pUpx6EsCDA8H4k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710871258; c=relaxed/simple; bh=B6aRAqV6zp5QyTg3WPpruzaUQrG1xvKUJStbcNeX4Hc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=QdsT3l86t28mc2g5FycbpWll6aEUONdcTfUhLScZj4JFMMMtXTo5kSRSuoIzJshopPbzC7W+BUmGspyuFOOcc0NG8YJEU/QhV2SY/F13CFr+xlWBbtT71tpobPX+TYKn9mhxJnCAbaGlKpeBxT638iSpY0vYu0YN8JCPSrDik9I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=WOsHWhXu; arc=none smtp.client-ip=209.85.214.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-1dd3c6c8dbbso3191895ad.1; Tue, 19 Mar 2024 11:00:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710871256; x=1711476056; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vXm1fu9C4vX46h0sj29/lTEeornZUsKUb3fjEsz6jiw=; b=WOsHWhXukUbB0mi5ivzNGywXZqHcyMWjU3zQDYYMHiQsVQCzgwg9vFpuChxVBc9wTL 9FkNGGaszolwQmd9HooDYcLY+iRHq8hpqEz/Rrsjtl8iu9o5djlykw8+F2SGkzjqcxXX PpIAIwF7VjvyF70cbz08m6J7wfIj2tgcuNDJh5oLqO3uJ6CEpFwMlWrWiuyEK6JxuvFD g70iUYcvhirdy5XChbtI5JCrWmy9Qgae3sLvFzwCEBgW/NWQAWUNbJncJ7GbviYoOWuQ A7o97R78snbOifAt7QbZjpfsTf6U7ZWsaGKBMvcrcipJvJs8ohmUpcI4/aKbvPBMAQ/A xT6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710871256; x=1711476056; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vXm1fu9C4vX46h0sj29/lTEeornZUsKUb3fjEsz6jiw=; b=Kp3LP64uCrSroVH68fg0aiUSzHxvGeuuMQH9E43ffWHaTzXeXV2Lg06hkPAbrqhr5u vayZAJpTe874cZwAL+WDhL6ga3Zw77wJxnG0C/B5z46NGK31X1QBfHIQ7rrb+zNZm5tD v0YuIHKT+LaWOBZc0hM0omJZLAThfybvAalYwxitcf4N59cfCtCbliQjHI+FjwdFamvo sHX0xrgBQ1RnD/OTmLkMJXdYXHpZyeFa+tBqZeXuvWNbT56k5Ndv5jEyTr2qPuH72wGZ f5nx7acZSyeUv0SG5/h6BgWx0wqRNLSrBXR+ECN3yu89wg8culPQU/vcRqtndtyaZRAB xTKA== X-Forwarded-Encrypted: i=1; AJvYcCU7IUXfMGZSprtc1JBJkwK7votJYqvuEZjy0wheFN3KeOUeC4dVNFe0gX3Y44UMc2vye+m5a/4TYRLdbzjofrj+i4fnZsjAD29YNetiQK2lGiTWznqjdMxtMH7nxV8U0vSJle0XLht2UlakbZ9/d1fh4gUnzGRPK3VuTUMFDSpAR1WKACyqhkPZexEaDAY2LhEmJDVO6FnmSIuAFdRwAXv2abwJcWQ1OeOyh045 X-Gm-Message-State: AOJu0Yz1w+fmAZsKIn7X4PQtljamYMBYj9qYv+3ztPL7UVqwyaDndU0E WJm0rLBLmuBcl3qyodMUCPnawLaMAGQBtHwG1OwJT0oGoqX+zaJ1 X-Received: by 2002:a17:902:e84a:b0:1dd:b883:3398 with SMTP id t10-20020a170902e84a00b001ddb8833398mr3095419plg.4.1710871256326; Tue, 19 Mar 2024 11:00:56 -0700 (PDT) Received: from visitorckw-System-Product-Name.. ([140.113.216.168]) by smtp.gmail.com with ESMTPSA id u16-20020a17090341d000b001dd3bee3cd6sm5531359ple.219.2024.03.19.11.00.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 11:00:55 -0700 (PDT) From: Kuan-Wei Chiu To: colyli@suse.de, kent.overstreet@linux.dev, msakai@redhat.com, peterz@infradead.org, mingo@redhat.com, acme@kernel.org, namhyung@kernel.org, akpm@linux-foundation.org Cc: bfoster@redhat.com, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com, jserv@ccns.ncku.edu.tw, linux-bcache@vger.kernel.org, dm-devel@lists.linux.dev, linux-bcachefs@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Kuan-Wei Chiu Subject: [PATCH 09/13] lib min_heap: Update min_heap_push() and min_heap_pop() to return bool values Date: Wed, 20 Mar 2024 02:00:01 +0800 Message-Id: <20240319180005.246930-10-visitorckw@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240319180005.246930-1-visitorckw@gmail.com> References: <20240319180005.246930-1-visitorckw@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Modify the min_heap_push() and min_heap_pop() to return a boolean value. They now return false when the operation fails and true when it succeeds. Signed-off-by: Kuan-Wei Chiu --- include/linux/min_heap.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/include/linux/min_heap.h b/include/linux/min_heap.h index 97d8ba5c32e6..154ac2102114 100644 --- a/include/linux/min_heap.h +++ b/include/linux/min_heap.h @@ -130,18 +130,20 @@ void __min_heapify_all(struct __min_heap *heap, size_t elem_size, /* Remove minimum element from the heap, O(log2(nr)). */ static __always_inline -void __min_heap_pop(struct __min_heap *heap, size_t elem_size, +bool __min_heap_pop(struct __min_heap *heap, size_t elem_size, const struct min_heap_callbacks *func, void *args) { void *data = heap->data; if (WARN_ONCE(heap->nr <= 0, "Popping an empty heap")) - return; + return false; /* Place last element at the root (position 0) and then sift down. */ heap->nr--; memcpy(data, data + (heap->nr * elem_size), elem_size); __min_heapify(heap, 0, elem_size, func, args); + + return true; } #define min_heap_pop(_heap, _func, _args) \ @@ -167,7 +169,7 @@ void __min_heap_pop_push(struct __min_heap *heap, /* Push an element on to the heap, O(log2(nr)). */ static __always_inline -void __min_heap_push(struct __min_heap *heap, const void *element, size_t elem_size, +bool __min_heap_push(struct __min_heap *heap, const void *element, size_t elem_size, const struct min_heap_callbacks *func, void *args) { void *data = heap->data; @@ -175,7 +177,7 @@ void __min_heap_push(struct __min_heap *heap, const void *element, size_t elem_s int pos; if (WARN_ONCE(heap->nr >= heap->size, "Pushing on a full heap")) - return; + return false; /* Place at the end of data. */ pos = heap->nr; @@ -190,6 +192,8 @@ void __min_heap_push(struct __min_heap *heap, const void *element, size_t elem_s break; func->swp(parent, child, args); } + + return true; } #define min_heap_push(_heap, _element, _func, _args) \ -- 2.34.1