Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp2939685ybl; Sun, 11 Aug 2019 11:48:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqwME6T87LykYueCpnb3BQf8J9CmWtii/e9zlIP8crnr9ZDgDRmkVcrDoM4s5I/cyn9TJJn0 X-Received: by 2002:a17:90a:3321:: with SMTP id m30mr6411203pjb.2.1565549304090; Sun, 11 Aug 2019 11:48:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565549304; cv=none; d=google.com; s=arc-20160816; b=xDL2wJsz4WWNHtpQ561mkp2F8ePuWbLSceRcFLvFfzpFr+7CuuteoiODnzbenjQ3E3 sl1LybwQqjwk9oV6dCZjluxBT0oli5bABivVk7ohjxxLFyf3B94Bzlc8fWMPD9ug23/s +7sEx0eNbSfiYCZcKwodJDy0RSZ1HS5AxVnmRtAZlmr6ufzqvtE8bNV8Dm0Xjvna4pSx C9uVwMTC98LLXejroYZahgNwWBcIzIwc/wPvTJ60CTkR4HI+xH9HcyN/M71rhxDr0ums 8GeFca5d+FVjwkKaAoGpjsqlN0oHQ8TbVckOJD7yrCH3ZyOZGOWSlvRL9nlMKXzJjUC1 E53w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=aELALDrW+i7a5BlA42yQNpA9Z5Hpp50rNx+gjusAsXA=; b=TaeEuWhc4FmKxEm4AzklEbwNwoS33+VkiOaNN7R8ANByNh/fkM4rXfq/a0YIP8lRV6 2hlXh+WdDwND8q95XmfvxakvqE6TgHoo09B7LReLwfBXQ8zhDUKtmDUlC/NcGzaEn/1s n1JpdyZN0N0IsL0HOxjB9ZjxIS488P7QfqtSUjDBlbTiuy3fqYVllJIy+WfIroRpCA9s 7oJ2uCBktnda1q7eSkIiqVHH90uBV4/EiQzK/klrE84s/XUEwXfK3jn1HGIjhSg9lv/h Eio/QGhXsrjoSzJzTQhX7iUXsUBVzdSp/Tc6oqjq75FybKWkBh31J7/HfluoTGady/bA V2PQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=FUL8J4xo; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h194si3754451pfe.144.2019.08.11.11.48.09; Sun, 11 Aug 2019 11:48:24 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=FUL8J4xo; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726358AbfHKSq3 (ORCPT + 99 others); Sun, 11 Aug 2019 14:46:29 -0400 Received: from mail-lj1-f195.google.com ([209.85.208.195]:46394 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725847AbfHKSq3 (ORCPT ); Sun, 11 Aug 2019 14:46:29 -0400 Received: by mail-lj1-f195.google.com with SMTP id h13so970239ljc.13 for ; Sun, 11 Aug 2019 11:46:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=aELALDrW+i7a5BlA42yQNpA9Z5Hpp50rNx+gjusAsXA=; b=FUL8J4xo9QZASNM+Q7L0aom2WHHhWfOxknUEy5OCnQtrPp5he5ltWr2I5kKtWCn0Dl vZbzkU09dMuu+vgVh23QERoxSS+hfSt2FN6Y2994xh7u6J8+VHjPpUITALSYyZvWmB73 TYQY33HI0vOk7xIJWLgaQDxCD5+TqTMyWSUPC1zcMfRlmn/bvMwfAnoUzJkXYiv6rDtx mGeIAmngp97FIufCmJpDAHRfvAbNghmzxq27XVb9nV3yLsJu7SfyAlzgY4rkLxRZS+tg jZTxrzZoDvZvyyjXnwqUOdtOVKOxac4FmC26rS5Hi+MKICsgyCVoJSP8QbC+FQwgeZnY PrLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=aELALDrW+i7a5BlA42yQNpA9Z5Hpp50rNx+gjusAsXA=; b=k75ClGXExb9suzs7wGX014K/vtu8p26oWZRxvsu/Yj+X8YpsxOxOAEAQizOuT+CHSJ AELXVlzCgj901T68tuSOefPsobVvh5SpviRl5z8+io2icglqCdM8XwFmzjBAtGGhGjsK sKASB3Md4m9QAjRwqPxDYhzpKXIh64ccw/2db1L+q33fFs3mXhkPKI3du0Q6XcaAwUTZ 0jrNgDeuzxBa/xUVmJNdvSb9Vpm1LpFGeY+GUXD6AveU+UPtHhQielu5TSlhm0y4yQQd DbLHz9i4yF0+Xca90+xWSHQJ7/IapEbfzAZspSwCoLroRre3IL5ktKIlmBf7BROYJP34 FRcg== X-Gm-Message-State: APjAAAUZgAiQcHDYCQ/M+WgkuUOZXTAvcLluQcU/zsCOIW5Vt+ZqrPCo ImOXovezC+TytG4MAWaIbxI= X-Received: by 2002:a2e:9f02:: with SMTP id u2mr1933631ljk.4.1565549186050; Sun, 11 Aug 2019 11:46:26 -0700 (PDT) Received: from localhost.localdomain ([37.212.199.11]) by smtp.gmail.com with ESMTPSA id t66sm1536425lje.66.2019.08.11.11.46.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 11 Aug 2019 11:46:25 -0700 (PDT) From: "Uladzislau Rezki (Sony)" To: Andrew Morton , Michel Lespinasse Cc: linux-mm@kvack.org, LKML , Peter Zijlstra , Roman Gushchin , Uladzislau Rezki , Hillf Danton , Michal Hocko , Matthew Wilcox , Oleksiy Avramchenko , Steven Rostedt Subject: [PATCH 1/2] augmented rbtree: use max3() in the *_compute_max() function Date: Sun, 11 Aug 2019 20:46:12 +0200 Message-Id: <20190811184613.20463-2-urezki@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190811184613.20463-1-urezki@gmail.com> References: <20190811184613.20463-1-urezki@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Recently there was introduced RB_DECLARE_CALLBACKS_MAX template. One of the callback, to be more specific *_compute_max(), calculates a maximum scalar value of node against its left/right sub-tree. To simplify the code and improve readability we can switch and make use of max3() macro that makes the code more transparent. Signed-off-by: Uladzislau Rezki (Sony) --- include/linux/rbtree_augmented.h | 40 +++++++++++++++++----------------- tools/include/linux/rbtree_augmented.h | 40 +++++++++++++++++----------------- 2 files changed, 40 insertions(+), 40 deletions(-) diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h index fdd421b8d9ae..fb29d6627646 100644 --- a/include/linux/rbtree_augmented.h +++ b/include/linux/rbtree_augmented.h @@ -119,26 +119,26 @@ RBSTATIC const struct rb_augment_callbacks RBNAME = { \ #define RB_DECLARE_CALLBACKS_MAX(RBSTATIC, RBNAME, RBSTRUCT, RBFIELD, \ RBTYPE, RBAUGMENTED, RBCOMPUTE) \ -static inline bool RBNAME ## _compute_max(RBSTRUCT *node, bool exit) \ -{ \ - RBSTRUCT *child; \ - RBTYPE max = RBCOMPUTE(node); \ - if (node->RBFIELD.rb_left) { \ - child = rb_entry(node->RBFIELD.rb_left, RBSTRUCT, RBFIELD); \ - if (child->RBAUGMENTED > max) \ - max = child->RBAUGMENTED; \ - } \ - if (node->RBFIELD.rb_right) { \ - child = rb_entry(node->RBFIELD.rb_right, RBSTRUCT, RBFIELD); \ - if (child->RBAUGMENTED > max) \ - max = child->RBAUGMENTED; \ - } \ - if (exit && node->RBAUGMENTED == max) \ - return true; \ - node->RBAUGMENTED = max; \ - return false; \ -} \ -RB_DECLARE_CALLBACKS(RBSTATIC, RBNAME, \ +static inline RBTYPE RBNAME ## _get_max(struct rb_node *node) \ +{ \ + RBSTRUCT *tmp; \ + \ + tmp = rb_entry_safe(node, RBSTRUCT, RBFIELD); \ + return tmp ? tmp->RBAUGMENTED : 0; \ +} \ + \ +static inline bool RBNAME ## _compute_max(RBSTRUCT *node, bool exit) \ +{ \ + RBTYPE max = max3(RBCOMPUTE(node), \ + RBNAME ## _get_max(node->RBFIELD.rb_left), \ + RBNAME ## _get_max(node->RBFIELD.rb_right)); \ + \ + if (exit && node->RBAUGMENTED == max) \ + return true; \ + node->RBAUGMENTED = max; \ + return false; \ +} \ +RB_DECLARE_CALLBACKS(RBSTATIC, RBNAME, \ RBSTRUCT, RBFIELD, RBAUGMENTED, RBNAME ## _compute_max) diff --git a/tools/include/linux/rbtree_augmented.h b/tools/include/linux/rbtree_augmented.h index 381aa948610d..3b8284479e98 100644 --- a/tools/include/linux/rbtree_augmented.h +++ b/tools/include/linux/rbtree_augmented.h @@ -121,26 +121,26 @@ RBSTATIC const struct rb_augment_callbacks RBNAME = { \ #define RB_DECLARE_CALLBACKS_MAX(RBSTATIC, RBNAME, RBSTRUCT, RBFIELD, \ RBTYPE, RBAUGMENTED, RBCOMPUTE) \ -static inline bool RBNAME ## _compute_max(RBSTRUCT *node, bool exit) \ -{ \ - RBSTRUCT *child; \ - RBTYPE max = RBCOMPUTE(node); \ - if (node->RBFIELD.rb_left) { \ - child = rb_entry(node->RBFIELD.rb_left, RBSTRUCT, RBFIELD); \ - if (child->RBAUGMENTED > max) \ - max = child->RBAUGMENTED; \ - } \ - if (node->RBFIELD.rb_right) { \ - child = rb_entry(node->RBFIELD.rb_right, RBSTRUCT, RBFIELD); \ - if (child->RBAUGMENTED > max) \ - max = child->RBAUGMENTED; \ - } \ - if (exit && node->RBAUGMENTED == max) \ - return true; \ - node->RBAUGMENTED = max; \ - return false; \ -} \ -RB_DECLARE_CALLBACKS(RBSTATIC, RBNAME, \ +static inline RBTYPE RBNAME ## _get_max(struct rb_node *node) \ +{ \ + RBSTRUCT *tmp; \ + \ + tmp = rb_entry_safe(node, RBSTRUCT, RBFIELD); \ + return tmp ? tmp->RBAUGMENTED : 0; \ +} \ + \ +static inline bool RBNAME ## _compute_max(RBSTRUCT *node, bool exit) \ +{ \ + RBTYPE max = max3(RBCOMPUTE(node), \ + RBNAME ## _get_max(node->RBFIELD.rb_left), \ + RBNAME ## _get_max(node->RBFIELD.rb_right)); \ + \ + if (exit && node->RBAUGMENTED == max) \ + return true; \ + node->RBAUGMENTED = max; \ + return false; \ +} \ +RB_DECLARE_CALLBACKS(RBSTATIC, RBNAME, \ RBSTRUCT, RBFIELD, RBAUGMENTED, RBNAME ## _compute_max) -- 2.11.0