lkml.org 
[lkml]   [2023]   [Feb]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
Subject[PATCH v1 37/51] perf expr: More explicit NAN handling
From
Comparison and logical operations on NAN won't ensure the result is
NAN. Ensure NANs are propogated so that threshold expressions like
"tma_fetch_latency > 0.1 & tma_frontend_bound > 0.15" don't yield a
number when the components are NAN.

Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/util/expr.y | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/expr.y b/tools/perf/util/expr.y
index 635e562350c5..250e444bf032 100644
--- a/tools/perf/util/expr.y
+++ b/tools/perf/util/expr.y
@@ -127,7 +127,11 @@ static struct ids handle_id(struct expr_parse_ctx *ctx, char *id,
if (!compute_ids || (is_const(LHS.val) && is_const(RHS.val))) { \
assert(LHS.ids == NULL); \
assert(RHS.ids == NULL); \
- RESULT.val = (long)LHS.val OP (long)RHS.val; \
+ if (isnan(LHS.val) || isnan(RHS.val)) { \
+ RESULT.val = NAN; \
+ } else { \
+ RESULT.val = (long)LHS.val OP (long)RHS.val; \
+ } \
RESULT.ids = NULL; \
} else { \
RESULT = union_expr(LHS, RHS); \
@@ -137,7 +141,11 @@ static struct ids handle_id(struct expr_parse_ctx *ctx, char *id,
if (!compute_ids || (is_const(LHS.val) && is_const(RHS.val))) { \
assert(LHS.ids == NULL); \
assert(RHS.ids == NULL); \
- RESULT.val = LHS.val OP RHS.val; \
+ if (isnan(LHS.val) || isnan(RHS.val)) { \
+ RESULT.val = NAN; \
+ } else { \
+ RESULT.val = LHS.val OP RHS.val; \
+ } \
RESULT.ids = NULL; \
} else { \
RESULT = union_expr(LHS, RHS); \
--
2.39.2.637.g21b0678d19-goog
\
 
 \ /
  Last update: 2023-03-27 00:28    [W:0.296 / U:0.576 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site