Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp2194562lqt; Mon, 22 Apr 2024 04:30:54 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV8PVcgvfY21Q3kxOPQ0EabRm6ou9T0lfWYT6CcJONqXdtKlSNYOK9i6ejedOhSdMm9PxnLC4ByO8A08wgxCyGB5fqpb4YOgpvK5uBuvg== X-Google-Smtp-Source: AGHT+IEVmDwOopDu7+/WzfzZSiq/uNwepclf1Jh0WMM8ysvDqoKih5RMBmofbwKgCO56AGfCTb5q X-Received: by 2002:a05:6a00:4656:b0:6ea:d740:62a4 with SMTP id kp22-20020a056a00465600b006ead74062a4mr14056406pfb.25.1713785454299; Mon, 22 Apr 2024 04:30:54 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713785454; cv=pass; d=google.com; s=arc-20160816; b=ozMTRjRkc5e9/J1QMGalgjjbpjyfIN4eMpBOXNP2XSZnGf3ohQZjqbG/frHN92Xdeq uDzcskrGW9inG2pL5ciJMLIF1EICmis4NqXx2K31eMO5Amtf0OgmWCQoEcEZZ1ZAyO3L 7cFMqU9JV3QfdVYD3/q6AcdoWuc0/AWEhjr1Abwp7AvNqsU7tSZn3GcIykxBuZuvSozr n7LaqAzS5UdF2r1JmgH/K39nCKeKRLVX+Q122inWC0qcUZdvXJtbh+GGTwwis6+KITqm FdMsbYiXtMpbRXHOy7rSKqnqbyE5c1ESmko8cnDCm0hlZrtQrj09kIRpnrBROY7qTOxG tWaA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=/Hd3qJ+RDJxBjZsCV8ojWHCPMSJxCzs0/ihfOaixUf0=; fh=wOhU+RfGR6AETSQpmLn4c4kjE8Q9JmYwekkxN+5ihyo=; b=wc68guZlVk6fk+GBlIGsq5tuihzGvjo2uQH1EZX/rU2BKMkXE1j9um79Da2KNJsTgU SLlFZrpZ8fIOJbZFFAKzXYv39qlkMvGnmfK/rmfrrYKIiUDzjzVfa7SJurE8OdMD+afP QnpKhb4cJc8gdhSRhtuzq/gJOHr3o3zovyF/ClplbKTo3xMR3fu2rvl7zDjNohAq0NBG +WtsZ/ymlf+Ov8RApgscRO3E52xwXepD7VbOcxQR09gHz5q4Z6QASrkGB/kV97KiTyQL XvKNOd5b+RSBP34VQx0Z9W3hqFsM2rCTRMhCjlszCxhKi8uV1LbdbMo1jD9tkFHsrJ0b 3GiA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-153277-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-153277-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id b16-20020a630c10000000b005dc87643cd1si7426134pgl.138.2024.04.22.04.30.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 04:30:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-153277-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-153277-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-153277-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 5C63FB24E51 for ; Mon, 22 Apr 2024 11:15:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C0C6E146A60; Mon, 22 Apr 2024 11:15:08 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CFE5314658F; Mon, 22 Apr 2024 11:15:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713784508; cv=none; b=DHlAZgEfZJ/9bpRKoXh5WGxnUODYrOyyWNYzM1z6PhPqX46NtUsUud7Hux70Egk9C6Bbjc2epq477OPsXyb1X+/btEhMn1hAnGAq7gp+EAZRaStK2OGjaoJW91LKBmst9o0baSHdl7NQGHQ69/J1E/5hAptY6+4ZWFIK9pqqa28= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713784508; c=relaxed/simple; bh=afWU35eQev2NDUVQ0DQmt6zhLxwVAFT56hjj7hhapOw=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=o6GSiN24CG+AFf39zSseHMq7snrJV+yjPeu4X9QtRPmqpWjz8UfQs+KxycMxYMo09huFhN1LQphJfvw5h06AN+oxs9UfQ584Q1y5CedhrxCDrU9N/j1hmklQyXy0Bkb67gB22pPMGygNJ0U0UMmyrtu4lx6O7cg2uB126/1whTw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 82ADF339; Mon, 22 Apr 2024 04:15:34 -0700 (PDT) Received: from [10.57.75.149] (unknown [10.57.75.149]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 570AB3F7BD; Mon, 22 Apr 2024 04:15:05 -0700 (PDT) Message-ID: Date: Mon, 22 Apr 2024 12:15:14 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v1 2/3] thermal/debugfs: Clean up thermal_debug_update_temp() To: "Rafael J. Wysocki" Cc: LKML , Linux PM , "Rafael J. Wysocki" , Daniel Lezcano References: <4918025.31r3eYUQgx@kreacher> <2185763.irdbgypaU6@kreacher> Content-Language: en-US From: Lukasz Luba In-Reply-To: <2185763.irdbgypaU6@kreacher> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 4/17/24 14:10, Rafael J. Wysocki wrote: > From: Rafael J. Wysocki > > Notice that it is not necessary to compute tze in every iteration of the > for () loop in thermal_debug_update_temp() because it is the same for all > trips, so compute it once before the loop starts. > > Also use a trip_stats local variable to make the code in that loop easier > to follow and move the trip_id variable definition into that loop because > it is not used elsewhere in the function. > > While at it, change to order of local variable definitions in the function > to follow the reverse-xmas-tree pattern. > > No intentional functional impact. > > Signed-off-by: Rafael J. Wysocki > --- > drivers/thermal/thermal_debugfs.c | 21 +++++++++++---------- > 1 file changed, 11 insertions(+), 10 deletions(-) > > Index: linux-pm/drivers/thermal/thermal_debugfs.c > =================================================================== > --- linux-pm.orig/drivers/thermal/thermal_debugfs.c > +++ linux-pm/drivers/thermal/thermal_debugfs.c > @@ -679,9 +679,9 @@ out: > void thermal_debug_update_temp(struct thermal_zone_device *tz) > { > struct thermal_debugfs *thermal_dbg = tz->debugfs; > - struct tz_episode *tze; > struct tz_debugfs *tz_dbg; > - int trip_id, i; > + struct tz_episode *tze; > + int i; > > if (!thermal_dbg) > return; > @@ -693,15 +693,16 @@ void thermal_debug_update_temp(struct th > if (!tz_dbg->nr_trips) > goto out; > > + tze = list_first_entry(&tz_dbg->tz_episodes, struct tz_episode, node); > + > for (i = 0; i < tz_dbg->nr_trips; i++) { > - trip_id = tz_dbg->trips_crossed[i]; > - tze = list_first_entry(&tz_dbg->tz_episodes, struct tz_episode, node); > - tze->trip_stats[trip_id].count++; > - tze->trip_stats[trip_id].max = max(tze->trip_stats[trip_id].max, tz->temperature); > - tze->trip_stats[trip_id].min = min(tze->trip_stats[trip_id].min, tz->temperature); > - tze->trip_stats[trip_id].avg = tze->trip_stats[trip_id].avg + > - (tz->temperature - tze->trip_stats[trip_id].avg) / > - tze->trip_stats[trip_id].count; > + int trip_id = tz_dbg->trips_crossed[i]; > + struct trip_stats *trip_stats = &tze->trip_stats[trip_id]; > + > + trip_stats->max = max(trip_stats->max, tz->temperature); > + trip_stats->min = min(trip_stats->min, tz->temperature); > + trip_stats->avg += (tz->temperature - trip_stats->avg) / > + ++trip_stats->count; > } > out: > mutex_unlock(&thermal_dbg->lock); > > > > Reviewed-by: Lukasz Luba