Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp1570951lqt; Wed, 20 Mar 2024 07:56:44 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVRFBy61vUN/9vy17/xs4an98bAA8r3XYxCqV9JxHeY0AQckSOO2wzUhOpVTy3qq4Yb1m2hYHsK7HygLxikG8/pUO7vv/W4mzt5qN54LA== X-Google-Smtp-Source: AGHT+IG/7egu6te11gbZdgxobr9aK06nr2lvKVf+O4R1IvSbiUIhIflOJ1j+NnHKr5Dd+83apT5s X-Received: by 2002:a05:622a:345:b0:430:b437:a8ab with SMTP id r5-20020a05622a034500b00430b437a8abmr19335965qtw.19.1710946604562; Wed, 20 Mar 2024 07:56:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710946604; cv=pass; d=google.com; s=arc-20160816; b=pb3AyAInE6/yG/3/AE+B4Nu7LcZFTq2bgoRxg3p+1JqpgQzH55b7nqAm8GaoJExDfV 46oT5mPMfPTOFqL4RqwyqVu7TJnP1sMLUpaIV/a6OfJaQSx95sPMZAshKk9vhnGHVVSh t7+d1O+8tJhSK86JZbS/NxDfVnLqaf2c3dDuKhuQRu9hXxPyUsjWg7B5DK73fG57wMNN tzG1AG9hhhr9XHsTwYnJDXBOcII2x7SynGZ/CWVGBUneKSgPzZdnrWjVPFQIuUj6DrQ5 Ue2D+5hHkwsDMZdE8vDKqTsSxVOXJVXNO0KQePhwvRs3eXMyJhp+ej6uK9hmNaiaK6Tg fYvg== 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=g5/a5el4a61wFJIBzCgWNmWU3XZlSJ2PCR5OhDq59lw=; fh=5GX4GCAqd5Z8lZIGTZSRtSRNaAmqeEzu+kFyoA+rOqI=; b=qvciqnqinn3IDmDeDtgELhEdPwLbnaLCpZzzyXe5mZsKKhN3tUCYQ0sHPln6ZRpWJN bU3wZtw/XHteYHyKFg8Fwy64JVuLKQLRQUyaYEqxUdhoUrxZLklAnGQ5/zQAo2SzdFCZ H91geWUy44B6XeJKUDnsie5eqFF5hpvRLnD5Cm0ySr8+Vxw3i5flCiEmnnindNQPteCX crqo0Wy38H923UZhlRKhYztwnzlN02cmjHg5MAZUHrmW8pp2FO68iWcJU+deW5VTlwq4 T1N9Jgoq7TLhQYmkEg1NyYtk3XpPWYpeqFXOYQjyTEeVl0t5pZuM3IVO7y8x2FyS2l0u h3qA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=RQYiSXJo; 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-109040-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-109040-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 y15-20020a05622a164f00b004310d308467si1103570qtj.584.2024.03.20.07.56.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Mar 2024 07:56:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-109040-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=RQYiSXJo; 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-109040-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-109040-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 215D91C22B92 for ; Wed, 20 Mar 2024 14:56:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D11975646D; Wed, 20 Mar 2024 14:54:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RQYiSXJo" Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (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 8F0DC5645B; Wed, 20 Mar 2024 14:54:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710946495; cv=none; b=Q2IPkiT2zBhcDT83ML8gMD7xL8KWZZdb+YM4rt0XBSaZNJJccFhiz8e2xQyn+VfrsJMO/8AqRKRncKkKOdVmMv2bcpatVpFEKatFsTVcuy1m/gCTkLBV20CqxygzRL6AIwYd+zipWMx2R6LWXfEct5aP1yFEfnUrD0I5fQi+Uqk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710946495; c=relaxed/simple; bh=8a68K+W3qZD++KgYqdJ8QFpXlGJ3ofQ9m/5i3nVK9u0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Xjar9W0Dp6Dc6GldK1R94zhZc8Tn4T4d5EXHSDnVEhzq2rBT0FjWsBa1HqRz/zIzMUqol4wDPm6/f9MgbHUtFlrA36JRJwGd+k9Qpu/vIZBtuUmlE2PMY2hGmcAIqdKXCOK3mEJ64XoN5+8NquAu21XMn/2Tbw2T2ShfjqaHBSs= 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=RQYiSXJo; arc=none smtp.client-ip=209.85.214.179 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-f179.google.com with SMTP id d9443c01a7336-1dee6672526so6079185ad.1; Wed, 20 Mar 2024 07:54:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710946493; x=1711551293; 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=g5/a5el4a61wFJIBzCgWNmWU3XZlSJ2PCR5OhDq59lw=; b=RQYiSXJoNzrTFJNriCDqofrrD38NwTxRhNaAAPZXA1Z1OTGi0oNAP18rp4rhWwLVHp fYNfKEry/ywdPVw5bv3Cv8mnSNSOxqCrUlGVTEh6Mi9rJOdd6TGC3kLZsoEDFMtLSPHd frfWsNRrv2Ep31Ie9uYxmVmcHSvUQDd1D2amVMu7WpLgVO9+NJZM5xzRbQyEon0dKg0m X8KdTHPswAOGV1WxcS+gu4YTRQmXLaJOvgyXadUNpUadeW6qW9lRF4jyTYzuVkeyg0zt hkEobPWyu4ktMP3PbRBsu7fbhnBRfA7+pqY/XwOKltBwPI1khifmIn0uk3iJ/WdCtngo VL1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710946493; x=1711551293; 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=g5/a5el4a61wFJIBzCgWNmWU3XZlSJ2PCR5OhDq59lw=; b=Af1kq0kmaqOSQfuoEQg3L40+ZfMAA7CBQNWZE/gQSyUYBS/A4TLNneZnv1YpD02JTb ZtVYgpfRS7M2nvVB/EJNf1sT9ypmzO/ehWzP6tswQQFdxyCtlv1jMnD6+o5FmN2ikDKl abKsWJKhzlSoPUgAxrX/UvOGrYVhvafV1ZIj7I7yQQO9BhwiBlIxdr+K2CX3yJU7JTkk 9JrOaosd74JV+UkX5neAvL3eDY81Vj1Yv1G6he7FbbcKtGm6MURVjcDO1iCWK/AvH8Nh RrlS6LHPu9jUUtOmDrfwoMH7+rqObGEW8Pad9HhaoE/WLEcniYKC4vyOIH9pC2WOdUaR WtlA== X-Forwarded-Encrypted: i=1; AJvYcCVL3fb4p6SfDaSOj/R2a7rl9j4kP32ouvTMey3pvrpqjYJuVr7L2f1okzMmQmnwyIB5fMHTCkANDXhr3HNz4S54dPMlhp3RnfDDRKV00SrLhYFpUqG5gtK2Ii6snI7J9mMhAnmkkQ/c4AY1RdVQIe0Tt1MngwwzenZrxKlxEwYwioYXn+ve4M77uPWqDqBEvF0CkkhhxO3SC5nFc+1b+piKpzRVVVpJXUqlDzEe X-Gm-Message-State: AOJu0YxHya9CNCFjtJT15OUaBHqpbTXAs0AZbm8Y0oU87N99i35qthmR 4tGnqb6+tn/PPmRVMpQDxh7bBe4M746d5nd7G0SFr7TVirGXDgZd X-Received: by 2002:a17:902:ce91:b0:1dc:df03:ad86 with SMTP id f17-20020a170902ce9100b001dcdf03ad86mr20347899plg.2.1710946492946; Wed, 20 Mar 2024 07:54:52 -0700 (PDT) Received: from visitorckw-System-Product-Name.. ([140.113.216.168]) by smtp.gmail.com with ESMTPSA id la11-20020a170902fa0b00b001dc30f13e6asm13719989plb.137.2024.03.20.07.54.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Mar 2024 07:54:52 -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, dm-devel@lists.linux.dev, linux-bcache@vger.kernel.org, linux-kernel@vger.kernel.org, linux-bcachefs@vger.kernel.org, linux-perf-users@vger.kernel.org, Kuan-Wei Chiu Subject: [PATCH v2 06/15] lib min_heap: Add min_heap_peek() Date: Wed, 20 Mar 2024 22:54:08 +0800 Message-Id: <20240320145417.336208-7-visitorckw@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240320145417.336208-1-visitorckw@gmail.com> References: <20240320145417.336208-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 ed462f194b88..7c1fd1ddc71a 100644 --- a/include/linux/min_heap.h +++ b/include/linux/min_heap.h @@ -56,6 +56,16 @@ void __min_heap_init(struct __min_heap *heap, void *data, int size) #define min_heap_init(_heap, _data, _size) \ __min_heap_init(&(_heap)->heap, _data, _size) +/* Get the minimum element from the heap. */ +static __always_inline +void *__min_heap_peek(struct __min_heap *heap) +{ + return heap->nr ? heap->data : NULL; +} + +#define min_heap_peek(_heap) \ + (__minheap_cast(_heap) __min_heap_peek(&(_heap)->heap)) + /* Sift the element at pos down the heap. */ static __always_inline void __min_heapify(struct __min_heap *heap, int pos, size_t elem_size, -- 2.34.1