From patchwork Thu Oct 4 10:21:17 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Vorontsov X-Patchwork-Id: 11981 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 432F624146 for ; Thu, 4 Oct 2012 10:24:17 +0000 (UTC) Received: from mail-ie0-f180.google.com (mail-ie0-f180.google.com [209.85.223.180]) by fiordland.canonical.com (Postfix) with ESMTP id BFD98A18621 for ; Thu, 4 Oct 2012 10:24:16 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id e10so567866iej.11 for ; Thu, 04 Oct 2012 03:24:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=mP4IyqirEsUfnQJkjqCjqbGSjJVX3gV85GRNsoIYFeA=; b=Sci6vFeSTlVxezRNX4KRk/ZZaE4BIX2eMvHbndGKcXjuTRTfXNxh7cxZ1RoJTJackG /Qe+nCudKdBRYZhvx746LfEN/GB8yllM0PfAm/G9NkTwF5u+4H0aBE+xUTP3SvWx8Xco TumRCxMmWXIddi00ZpVW8krPU96Z/z64Q4/dTcF8lhVpS0hxqPa//clUN3R5c3PB2ZkU Hw/JcU3Z4BGkEyA7JiAlXKWwHTkgcRt0ueik2m99iF/yLfnzllFICfSDirVUaZI69TBr G93khRqZLYjb6rXI6KWitLcFLmtUmgZ1c+j9cjPfByurWjnW5RKz2wFvN81YChXM4j2s UPNw== Received: by 10.50.154.137 with SMTP id vo9mr14300960igb.28.1349346256545; Thu, 04 Oct 2012 03:24:16 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.50.184.232 with SMTP id ex8csp58553igc; Thu, 4 Oct 2012 03:24:16 -0700 (PDT) Received: by 10.68.220.104 with SMTP id pv8mr20542141pbc.119.1349346256016; Thu, 04 Oct 2012 03:24:16 -0700 (PDT) Received: from mail-pb0-f50.google.com (mail-pb0-f50.google.com [209.85.160.50]) by mx.google.com with ESMTPS id qd9si13286319pbb.211.2012.10.04.03.24.15 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 04 Oct 2012 03:24:16 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.160.50 is neither permitted nor denied by best guess record for domain of anton.vorontsov@linaro.org) client-ip=209.85.160.50; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.160.50 is neither permitted nor denied by best guess record for domain of anton.vorontsov@linaro.org) smtp.mail=anton.vorontsov@linaro.org Received: by mail-pb0-f50.google.com with SMTP id md4so531942pbc.37 for ; Thu, 04 Oct 2012 03:24:15 -0700 (PDT) Received: by 10.68.233.136 with SMTP id tw8mr20746392pbc.133.1349346255770; Thu, 04 Oct 2012 03:24:15 -0700 (PDT) Received: from localhost (c-71-204-165-222.hsd1.ca.comcast.net. [71.204.165.222]) by mx.google.com with ESMTPS id qa4sm4133687pbb.70.2012.10.04.03.24.14 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 04 Oct 2012 03:24:15 -0700 (PDT) From: Anton Vorontsov To: Pekka Enberg Cc: John Stultz , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linaro-kernel@lists.linaro.org, patches@linaro.org Subject: [PATCH 2/3] vmevent: Factor vmevent_match_attr() out of vmevent_match() Date: Thu, 4 Oct 2012 03:21:17 -0700 Message-Id: <1349346078-24874-2-git-send-email-anton.vorontsov@linaro.org> X-Mailer: git-send-email 1.7.12.1 In-Reply-To: <20121004102013.GA23284@lizard> References: <20121004102013.GA23284@lizard> X-Gm-Message-State: ALoCoQkUR+4ZDsqm56YxJaezPaN2SwHPbkxc/6JQUEo4KvZBOu43sjeTdqtOTCKN6fPQdlnQanO8 Soon we'll use this new function for other code; plus this makes code less indented. Signed-off-by: Anton Vorontsov --- mm/vmevent.c | 107 +++++++++++++++++++++++++++++++---------------------------- 1 file changed, 57 insertions(+), 50 deletions(-) diff --git a/mm/vmevent.c b/mm/vmevent.c index 39ef786..d434c11 100644 --- a/mm/vmevent.c +++ b/mm/vmevent.c @@ -77,6 +77,59 @@ enum { VMEVENT_ATTR_STATE_VALUE_WAS_GT = (1UL << 31), }; +static bool vmevent_match_attr(struct vmevent_attr *attr, u64 value) +{ + u32 state = attr->state; + bool attr_lt = state & VMEVENT_ATTR_STATE_VALUE_LT; + bool attr_gt = state & VMEVENT_ATTR_STATE_VALUE_GT; + bool attr_eq = state & VMEVENT_ATTR_STATE_VALUE_EQ; + bool edge = state & VMEVENT_ATTR_STATE_EDGE_TRIGGER; + u32 was_lt_mask = VMEVENT_ATTR_STATE_VALUE_WAS_LT; + u32 was_gt_mask = VMEVENT_ATTR_STATE_VALUE_WAS_GT; + bool lt = value < attr->value; + bool gt = value > attr->value; + bool eq = value == attr->value; + bool was_lt = state & was_lt_mask; + bool was_gt = state & was_gt_mask; + bool was_eq = was_lt && was_gt; + bool ret = false; + + if (!state) + return false; + + if (!attr_lt && !attr_gt && !attr_eq) + return false; + + if (((attr_lt && lt) || (attr_gt && gt) || (attr_eq && eq)) && !edge) + return true; + + if (attr_eq && eq && was_eq) { + return false; + } else if (attr_lt && lt && was_lt && !was_eq) { + return false; + } else if (attr_gt && gt && was_gt && !was_eq) { + return false; + } else if (eq) { + state |= was_lt_mask; + state |= was_gt_mask; + if (attr_eq) + ret = true; + } else if (lt) { + state |= was_lt_mask; + state &= ~was_gt_mask; + if (attr_lt) + ret = true; + } else if (gt) { + state |= was_gt_mask; + state &= ~was_lt_mask; + if (attr_gt) + ret = true; + } + + attr->state = state; + return ret; +} + static bool vmevent_match(struct vmevent_watch *watch) { struct vmevent_config *config = &watch->config; @@ -84,57 +137,11 @@ static bool vmevent_match(struct vmevent_watch *watch) for (i = 0; i < config->counter; i++) { struct vmevent_attr *attr = &config->attrs[i]; - u32 state = attr->state; - bool attr_lt = state & VMEVENT_ATTR_STATE_VALUE_LT; - bool attr_gt = state & VMEVENT_ATTR_STATE_VALUE_GT; - bool attr_eq = state & VMEVENT_ATTR_STATE_VALUE_EQ; - - if (!state) - continue; + u64 val; - if (attr_lt || attr_gt || attr_eq) { - bool edge = state & VMEVENT_ATTR_STATE_EDGE_TRIGGER; - u32 was_lt_mask = VMEVENT_ATTR_STATE_VALUE_WAS_LT; - u32 was_gt_mask = VMEVENT_ATTR_STATE_VALUE_WAS_GT; - u64 value = vmevent_sample_attr(watch, attr); - bool lt = value < attr->value; - bool gt = value > attr->value; - bool eq = value == attr->value; - bool was_lt = state & was_lt_mask; - bool was_gt = state & was_gt_mask; - bool was_eq = was_lt && was_gt; - bool ret = false; - - if (((attr_lt && lt) || (attr_gt && gt) || - (attr_eq && eq)) && !edge) - return true; - - if (attr_eq && eq && was_eq) { - return false; - } else if (attr_lt && lt && was_lt && !was_eq) { - return false; - } else if (attr_gt && gt && was_gt && !was_eq) { - return false; - } else if (eq) { - state |= was_lt_mask; - state |= was_gt_mask; - if (attr_eq) - ret = true; - } else if (lt) { - state |= was_lt_mask; - state &= ~was_gt_mask; - if (attr_lt) - ret = true; - } else if (gt) { - state |= was_gt_mask; - state &= ~was_lt_mask; - if (attr_gt) - ret = true; - } - - attr->state = state; - return ret; - } + val = vmevent_sample_attr(watch, attr); + if (vmevent_match_attr(attr, val)) + return true; } return false;