From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2813AC52D7C for ; Tue, 13 Aug 2024 08:27:33 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A289910E1CF; Tue, 13 Aug 2024 08:27:31 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="AABL3Y+g"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) by gabe.freedesktop.org (Postfix) with ESMTPS id DB9CD10E1BC; Tue, 13 Aug 2024 08:27:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1723537650; x=1755073650; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=RyDHZHG1qM+4Ggl8UqXwMYT3dj0QzqQytYDcJf5gWcw=; b=AABL3Y+g6WUARhf0QFyO4tiQabJ+vuzdQCFHJa9x63ultWNjVDsysvUq JwRK+2kDMcHx1+/ggiZMLDDkSvro9+C9vG8q/FkSutvVI9I+F7hatA3aa jP38ftBSAhCIaFHKQ/JGfF0nk7/xn6vlAjnsx/uXIrTSJMmM3RAYHui6S FHPJQMsAT5PtcH9V29kbJM3KWZoLKTtlZVnt1M81jPXPAki7rc8RWtA5e 5SUZJA+US10ceaaYui5fl4n/WldjWQ6ozetFSFsOcJEnKMiaycS6FMLjP SGiyQn1R8Yo3BqYo6Gg7j81+jZrX+6IVABS3g6J8FxPbk2UK+EmJwZGJK g==; X-CSE-ConnectionGUID: XMBJhdC9SiSziC2v3qc13A== X-CSE-MsgGUID: YHdqdhzISJqcaKbPu6IqWQ== X-IronPort-AV: E=McAfee;i="6700,10204,11162"; a="44206969" X-IronPort-AV: E=Sophos;i="6.09,285,1716274800"; d="scan'208";a="44206969" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Aug 2024 01:27:30 -0700 X-CSE-ConnectionGUID: V9r30wDxRkWwvgSwb20/Qw== X-CSE-MsgGUID: PUr0OWqzQleZMmjieiro2A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,285,1716274800"; d="scan'208";a="63432409" Received: from smile.fi.intel.com ([10.237.72.54]) by orviesa003.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Aug 2024 01:27:26 -0700 Received: from andy by smile.fi.intel.com with local (Exim 4.98) (envelope-from ) id 1sdmsE-0000000Eeuo-1cOg; Tue, 13 Aug 2024 11:27:22 +0300 Date: Tue, 13 Aug 2024 11:27:22 +0300 From: Andy Shevchenko To: Raag Jadav Cc: jani.nikula@linux.intel.com, joonas.lahtinen@linux.intel.com, rodrigo.vivi@intel.com, tursulin@ursulin.net, airlied@gmail.com, daniel@ffwll.ch, linux@roeck-us.net, andi.shyti@linux.intel.com, intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, anshuman.gupta@intel.com, badal.nilawar@intel.com, riana.tauro@intel.com, ashutosh.dixit@intel.com, karthik.poosa@intel.com Subject: Re: [PATCH v5] drm/i915/hwmon: expose fan speed Message-ID: References: <20240812081538.1457396-1-raag.jadav@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" On Tue, Aug 13, 2024 at 08:45:19AM +0300, Raag Jadav wrote: > On Mon, Aug 12, 2024 at 04:15:14PM +0300, Andy Shevchenko wrote: > > On Mon, Aug 12, 2024 at 01:45:38PM +0530, Raag Jadav wrote: ... > > > +static int > > > +hwm_fan_read(struct hwm_drvdata *ddat, u32 attr, long *val) > > > +{ > > > + struct i915_hwmon *hwmon = ddat->hwmon; > > > + struct hwm_fan_info *fi = &ddat->fi; > > > + u64 rotations, time_now, time; > > > + intel_wakeref_t wakeref; > > > + u32 reg_val, pulses; > > > + int ret = 0; > > > + > > > + if (attr != hwmon_fan_input) > > > + return -EOPNOTSUPP; > > > + > > > + wakeref = intel_runtime_pm_get(ddat->uncore->rpm); > > > + mutex_lock(&hwmon->hwmon_lock); > > > + > > > + reg_val = intel_uncore_read(ddat->uncore, hwmon->rg.fan_speed); > > > + time_now = get_jiffies_64(); > > > > > + /* Handle HW register overflow */ > > > + if (reg_val >= fi->reg_val_prev) > > > + pulses = reg_val - fi->reg_val_prev; > > > + else > > > + pulses = UINT_MAX - fi->reg_val_prev + reg_val; > > > > Isn't it the abs_diff() reimplementation? > > Not exactly. This is specific to 32 bit register overflow, so we count > from max value. I see. But since you have the both variables of u32, why: 1) UINT_MAX? 2) Not simply using pulses = reg_val - fi->reg_val_prev; which will wrap over correctly? Note, in your case (in comparison to the wrap over variant) the off-by-one is present. Is it on purpose? -- With Best Regards, Andy Shevchenko