Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp629678lqb; Fri, 24 May 2024 08:32:21 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWwRRc8t4R4HpTCAzKVu3TCe29/iTA+0khHxLzO3J35Uqi2Z6lDNWOLw9z7Q81VmDKdNrYPveP4dMKKt7BhqKDK7lhTSkdkSf8hPH8S7A== X-Google-Smtp-Source: AGHT+IEKoSqexrgBRGCEJc8Tc2YZi+hAh8BL6fvIziAcnevws2El4RtZjKp6Ym+NGfg5HBgTAK4T X-Received: by 2002:a05:6e02:1a24:b0:371:9a33:85df with SMTP id e9e14a558f8ab-3737b31b857mr27589935ab.19.1716564741619; Fri, 24 May 2024 08:32:21 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716564741; cv=pass; d=google.com; s=arc-20160816; b=a14FLf/r7GbxelcPqxYh2z08DcRuHorKXmpRYW5YFj5P7RYEalMQP96QiJFGPmWe5U 0gg3MQaTqpQBOS80Zwq3NsLt0fCAf4YJDI3Co6dL+BMlTu+XQjExbSD/SNUQNg3Wo4HU eHjRUm70tmEu6j0lKmD24rNTOEhb8EaWQeCdCkrcufCqGAtidccuSxiRcYQFqgxBzJZy rxOVkUUab3vSnmPnxWZ8Yc0tlkIrM1K67YqdphvZvy0NwHUTF8LblMxt4YiFkSDXkERG Y5tZS+WJWJVh+I8/hLaO6XFQDQOKZBWBcB3UiWaPJLkUwYQNXJgkst07n5PBffyV3LXX geAg== 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=cYJrwbsUSMlgZtHUd20UudtqnzPzA+Nu3Je7Gypyz6k=; fh=zRZV/KeqYas1US4gjp866B4e6sdqDQ0102wk31okE44=; b=VpxMcLe7enPVg1l8TzZ8s5Z4Yg0j7JwLnzi0s1GvijU1X+e1dTndtJdJe31ewCx/zi 5D58c9qKpJwFF3VBgl3Uv7ASmWt3ZtXQZ/n6pX/nxHDzvVg00kWjFNGlkeT/fmhMHs/Y NOET8zdhCcRMCGab9jhueiA84pZsl2njllfrZzjoi0Lsy0u+7cY3L2DAcgGw2yXYJ0ra NF2ajM5+t4EjaAoA2d3DcPR8b5ZTNUEMbfAgyPUvC8XkjMn2JKHkroDQ8dC17txhhA9c wwqttZaYpdVGeqaEq8yAcFxpXChzjoVgtERT+RFNN6gB4dlv5ZEEE9Bqj2pRiYvAY3XW sygg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=BxoOblvg; 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-188868-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-188868-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id a1e0cc1a2514c-804cbe7bae1si357656241.45.2024.05.24.08.32.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 May 2024 08:32:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-188868-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=BxoOblvg; 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-188868-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-188868-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 1F8AB1C22432 for ; Fri, 24 May 2024 15:32:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C393012E1D4; Fri, 24 May 2024 15:30:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BxoOblvg" Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) (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 B70BD12DDAB; Fri, 24 May 2024 15:30:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716564639; cv=none; b=Hb6LGbmi0VLJgKlvrPO9nuk3dkREOrNVHyj2a46I9IA8aTxdDSV/6ziCluEV8e7TTR10zCQa8Zavws/fI8yv3ZRMGw0hnjJNbggnsyUwJMP2C773Fy29i7dJXBg7jaZoNx9opaPLBmhxuL9CV34U6cd9fazOAlFm3s0vsgF30nI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716564639; c=relaxed/simple; bh=CtmjnUhCovWSsS0eLtHZkP1gRg/+o2/rih6xjavgouM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=tV/WnlX5EkpCIhbl5/MzGX8c5o9DwUijFJbU+c1wbMfbNFrPCk6doiZly7S97hnrHiemNu2uY7Pz6hG29MRnfzj4pdIxxmDro/GxArJ3JpAwdy/OqaZXZaWamal3Ikh8zCoTbFft8b8mo4vpIBTVWg7tKARLPUAqWCJ2l/Vxbjc= 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=BxoOblvg; arc=none smtp.client-ip=209.85.216.49 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-pj1-f49.google.com with SMTP id 98e67ed59e1d1-2bf5baa5b76so103284a91.0; Fri, 24 May 2024 08:30:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716564637; x=1717169437; 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=cYJrwbsUSMlgZtHUd20UudtqnzPzA+Nu3Je7Gypyz6k=; b=BxoOblvgWca93mml1Z8752CixmUuvnRuoFqphVkZnqlGWli8wcNzz+S5faEHTxT/Zw GJxFGG1vInrZgWZYJCewA1Ph3/iSpoaRsFYoi70mx5rvNC7mpqvcAEoiy6YJV+mFtKOm TvymQYjRpOqXZ+7UafNCc9TtOUuO8jQIP7XWjZj2QkM6ZiFMzM/I7jWPuaJOZbRZLibW kyO4oErn2M1aW/+xzx/+tqNurFpff1Pnhs9KKFWRM6IqAqlcKISpfi4BEnFFBcfjqnRk MDQIlzikp59nqpmrtP44i4cTh54gtbOCFmLQFFSpUuw4buTkF/o2zsQ0K79HqKfriZN2 L9FQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716564637; x=1717169437; 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=cYJrwbsUSMlgZtHUd20UudtqnzPzA+Nu3Je7Gypyz6k=; b=N+5Jal0CEyCI83dVF2MR+wu85DH9pznsbWhL0MiyuTtSFDxG6Idg/KeMQY4vBNHTPE l8bJ5ACqZXWiftkpWHIjGVWl6s7J9EEwvIsdxVUTQhMoRQvjW9AXuP4kOYTwJUTa30G2 Awy+XvMJNqOGQdrJ9S5xDpfNh9uo9UHLgkEPMwjlQVidPOUSg3OpOgnOd1DKz3VTMMKD zAWOo6VGkMWrmZG2McmqPW/ayVmlMk+1q2oDOvw6cBkKcV/jY1/gJR2kQKMW8TNF4APW FmfOi2fmJzFo03ier9QUi+swXiZ3cTgYX+/YCGFP+d1+UG+ltqvuempWxYovV2xosOdF OeVg== X-Forwarded-Encrypted: i=1; AJvYcCXLZPXhCH5T9fLBNSJlAFscAp/b7XJ4eQ/2qaiNZRb1kPVnY3ty+7vYWodmgOIXoSmoj3b4UwYjYC0ONbJWE4qUc6z1bS/8KOBV8MeDMvHutyUoDYRa3w3s5V5OjCVBbpihXFhNuIuV3UIqrQRJmQaeTCCSHAxbOyvxyPyy9zblQcSBoZxhb2u1Esci+aJCeKiQdOE5lms6H1/mQhyNZ5azqZ6Q/cddcP3Lf/2r X-Gm-Message-State: AOJu0Yxh2rAQ45AD7DfGCVgGopxLzrPOe2zLP9enaSBg2QZuHZs0wsaG SepotaUxRvjkiwfozhmByMCQHUvWyz9W9gyWSY2LjLV4ZgEXXk0G X-Received: by 2002:a17:90b:2286:b0:2bd:e806:49e4 with SMTP id 98e67ed59e1d1-2bf5f511c5amr2497068a91.4.1716564636772; Fri, 24 May 2024 08:30:36 -0700 (PDT) Received: from visitorckw-System-Product-Name.. ([140.113.216.168]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2bf5f50d294sm1525556a91.20.2024.05.24.08.30.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 May 2024 08:30:36 -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, bagasdotme@gmail.com, jserv@ccns.ncku.edu.tw, linux-bcache@vger.kernel.org, linux-kernel@vger.kernel.org, dm-devel@lists.linux.dev, linux-bcachefs@vger.kernel.org, linux-perf-users@vger.kernel.org, Kuan-Wei Chiu Subject: [PATCH v6 06/16] lib min_heap: Add min_heap_peek() Date: Fri, 24 May 2024 23:29:48 +0800 Message-Id: <20240524152958.919343-7-visitorckw@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240524152958.919343-1-visitorckw@gmail.com> References: <20240524152958.919343-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 Add min_heap_peek() function to retrieve a pointer to the smallest element. The pointer is cast to the appropriate type of heap elements. Signed-off-by: Kuan-Wei Chiu Reviewed-by: Ian Rogers --- include/linux/min_heap.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/linux/min_heap.h b/include/linux/min_heap.h index b384a4ea2afa..d9c4ae7ad0cc 100644 --- a/include/linux/min_heap.h +++ b/include/linux/min_heap.h @@ -53,6 +53,16 @@ void __min_heap_init(min_heap_char *heap, void *data, int size) #define min_heap_init(_heap, _data, _size) \ __min_heap_init((min_heap_char *)_heap, _data, _size) +/* Get the minimum element from the heap. */ +static __always_inline +void *__min_heap_peek(struct min_heap_char *heap) +{ + return heap->nr ? heap->data : NULL; +} + +#define min_heap_peek(_heap) \ + (__minheap_cast(_heap) __min_heap_peek((min_heap_char *)_heap)) + /* Sift the element at pos down the heap. */ static __always_inline void __min_heapify(min_heap_char *heap, int pos, size_t elem_size, -- 2.34.1