From: Zhang Rui <rui.zhang@intel.com>
To: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: rjw@rjwysocki.net, daniel.lezcano@linaro.org,
linux-pm@vger.kernel.org, srinivas.pandruvada@linux.intel.com
Subject: Re: [PATCH 1/6] thermal/intel: Introduce Intel TCC library
Date: Tue, 13 Dec 2022 09:38:17 +0800 [thread overview]
Message-ID: <10cae7a3db86278c39ecb8837ec000b054c51ebc.camel@intel.com> (raw)
In-Reply-To: <CAJZ5v0j=x6ofgTFcoRw1bsoCbsbA7uAqQNddXVeXXOuwQzcNBQ@mail.gmail.com>
On Mon, 2022-12-12 at 13:11 +0100, Rafael J. Wysocki wrote:
> On Sun, Dec 11, 2022 at 8:24 AM Zhang Rui <rui.zhang@intel.com>
> wrote:
> >
> > > > > + if (err)
> > > > > + return err;
> > > > > +
> > > > > + *tjmax = (eax >> 16) & 0xff;
> > > >
> > > > This means that the tjmax value cannot be negative.
> > > >
> > > > > +
> > > > > + return *tjmax ? 0 : -EINVAL;
> > > >
> > > > So the return value of this function could be tjmax if positive
> > > > or
> > > > a
> > > > negative error code otherwise. No return pointers needed.
> > >
> > > I tried both. And I think I chose this solution just because it
> > > makes
> > > the following cleanup patches in this series looks prettier.
> > >
> > > I will try your suggestion, and if there is any other reason I
> > > wrote
> > > it
> > > in this way, I will find it out again. :p
> >
> > I see.
> > Say, we have to use
> >
> > intel_tcc_get_temp(int cpu, int *temp)
>
> Do we?
temp = tjmax - digital_readout
tjmax and digital_readout are from MSR and they are both positive
values, but temp can be negative in theory.
so are you suggesting that we should treat the negative CPU temperature
as an error because this won't happen in real world?
thanks,
rui
>
> > so I keep the same format for all the intel_tcc_get_XXX APIs
> >
> > intel_tcc_get_tjmax(int cpu, int *tjmax)
> > intel_tcc_get_offset(int cpu, int *offset)
> >
> > so that the return value is decoded in the same way. This helps
> > avoid
> > return value check mistakes for the callers.
> >
> > surely I can remove the return pointer if you still prefer that. :p
>
> Using a function value directly is very much preferred unless there
> really are two values to return.
>
> In these particular cases a negative return value can be clearly
> interpreted as an error condition, so using the return value directly
> is sufficient.
>
> > > > > +
> > > > > + return 0;
> > > > > +}
> > > > > +EXPORT_SYMBOL_NS_GPL(intel_tcc_get_offset, INTEL_TCC);
> > > > > +
> > > > > +/**
> > > > > + * intel_tcc_set_offset() - set the TCC offset value to
> > > > > Tjmax
> > > > > + * @cpu: cpu that the MSR should be run on.
> > > > > + * @offset: TCC offset value in degree C
> > > >
> > > > I think that this cannot be negative, so maybe say "in K"
> > > > instead
> > > > of
> > > > "in degree C"?
> > >
> > > degree C is the unit used in the Intel SDM, so better to keep
> > > this
> > > comment aligned.
> > >
> > > > And maybe it's better to pass u8 here?
> > >
> > > sounds good, will do in next version.
> > >
> > to keep consistent, we can use either
> > int intel_tcc_get_offset(int cpu)
> > int intel_tcc_set_offset(int cpu, int offset)
>
> What about intel_tcc_set_offset(int cpu, u8 offset)?
>
> > or
> > int intel_tcc_get_offset(int cpu, u8 *offset)
> > int intel_tcc_set_offset(int cpu, u8 offset)
> >
> > or else callers need to declare 'offset' but with different type,
> > when
> > getting and setting it, which looks strange.
>
> Well, one can surely pass an int as a u8 argument and assign a u8
> return value to an int variable.
next prev parent reply other threads:[~2022-12-13 1:39 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-08 3:33 [PATCH 0/6] thermal/intel: Introduce intel-tcc lib and enhance tjmax handling Zhang Rui
2022-11-08 3:33 ` [PATCH 1/6] thermal/intel: Introduce Intel TCC library Zhang Rui
2022-12-08 13:49 ` Rafael J. Wysocki
2022-12-08 14:07 ` Rafael J. Wysocki
2022-12-09 13:57 ` Zhang Rui
2022-12-08 16:49 ` Zhang Rui
2022-12-08 17:00 ` Rafael J. Wysocki
2022-12-09 13:32 ` Zhang Rui
2022-12-09 16:28 ` srinivas pandruvada
2022-12-11 7:50 ` Zhang Rui
2022-12-12 12:15 ` Rafael J. Wysocki
2022-12-11 7:23 ` Zhang Rui
2022-12-12 12:11 ` Rafael J. Wysocki
2022-12-13 1:38 ` Zhang Rui [this message]
2022-12-13 15:34 ` Rafael J. Wysocki
2022-12-14 16:15 ` Zhang Rui
2022-12-14 16:17 ` Rafael J. Wysocki
2022-12-14 16:19 ` Rafael J. Wysocki
2022-11-08 3:33 ` [PATCH 2/6] thermal/int340x/processor_thermal: Use " Zhang Rui
2022-11-08 3:33 ` [PATCH 3/6] thermal/intel/intel_soc_dts_iosf: " Zhang Rui
2022-11-08 3:33 ` [PATCH 4/6] thermal/intel/intel_tcc_cooling: " Zhang Rui
2022-11-08 3:33 ` [PATCH 5/6] thermal/x86_pkg_temp_thermal: " Zhang Rui
2022-11-08 3:33 ` [PATCH 6/6] thermal/x86_pkg_temp_thermal: Add support for handling dynamic tjmax Zhang Rui
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=10cae7a3db86278c39ecb8837ec000b054c51ebc.camel@intel.com \
--to=rui.zhang@intel.com \
--cc=daniel.lezcano@linaro.org \
--cc=linux-pm@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=rjw@rjwysocki.net \
--cc=srinivas.pandruvada@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox