linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mathieu Poirier <mathieu.poirier@linaro.org>
To: James Clark <james.clark@arm.com>
Cc: suzuki.poulose@arm.com, coresight@lists.linaro.org,
	mike.leach@linaro.org, leo.yan@linaro.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1 2/4] coresight: Simplify sysfs accessors by using csdev_access abstraction
Date: Thu, 25 Aug 2022 10:54:47 -0600	[thread overview]
Message-ID: <20220825165447.GA1910926@p14s> (raw)
In-Reply-To: <f6623ca8-227f-9f92-5b7b-5dbb151b0fb1@arm.com>

[...]

> >>  
> >>  static struct attribute *coresight_tmc_mgmt_attrs[] = {
> >>  	&dev_attr_rsz.attr,
> >> diff --git a/include/linux/coresight.h b/include/linux/coresight.h
> >> index 9f445f09fcfe..c1bb93c7c1de 100644
> >> --- a/include/linux/coresight.h
> >> +++ b/include/linux/coresight.h
> >> @@ -372,6 +372,24 @@ static inline u32 csdev_access_relaxed_read32(struct csdev_access *csa,
> >>  	return csa->read(offset, true, false);
> >>  }
> >>  
> >> +static inline u64 csdev_access_relaxed_read_pair(struct csdev_access *csa,
> >> +						 u32 lo_offset, u32 hi_offset)
> > 
> > Parameters lo_offset and hi_offset are s32 in coresight_read_reg_pair()...
> 
> Hi Mathieu,
> 
> I probably should have mentioned this in the commit message. You're
> right that the previous version used signed values, but the csdev
> accessors in include/linux/coresight.h all use u32 and I had to add a
> new one in there for 'csdev_access_relaxed_read_pair()' which would have
> looked very out of place if it was the only one to used signed values.
> 
> Because of this I also changed the 'not set' test for hi_offset from '<
> -1' to '== -1' which would also work with unsigned values. So although
> it looks different, it is still working the same way as before.
> 
> I can think of some possible options to make it better:
> 
>   * Have csdev_access_relaxed_read_pair() be the only csdev_access_
>     function to take signed values

That part is not a big deal for me.

> 
>   * Keep the unsigned type but change the unset value of -1 to be
>     UINT_MAX

I find this counterintuitive and error prone.  And sparse will likely yell
at you profusely.  

> 
>   * Split the accessors into ones that are 64 bit pairs, and ones that
>     are a single read. It's always known when it's defined whether it's
>     a 'pair' or not, so technically this if statement with the 'not set'
>     value isn't actually needed, you just use a different accessor type
> 

That would work.

> I was tempted to do the 3rd one during the refactor, but I wanted to
> keep it more like the original than not. I'm not a fan of the first
> option, I think that would be confusing to read the code and would look
> like a mistake. So I'm more in favour of 2 or 3. What are your thoughts?

Let's meet in the middle and go with option 3.

Thanks,
Mathieu

> 
> > 
> >> +{
> >> +	u64 val;
> >> +
> >> +	if (likely(csa->io_mem)) {
> >> +		val = readl_relaxed(csa->base + lo_offset);
> >> +		val |= (hi_offset == -1) ? 0 :
> >> +		       (u64)readl_relaxed(csa->base + hi_offset) << 32;
> >> +		return val;
> >> +	}
> >> +
> >> +	val = csa->read(lo_offset, true, false);
> >> +	val |= (hi_offset == -1) ? 0 :
> > 
> > ... and hi_offset can't take on a negative value.
> 
> This is just shorthand for UINT_MAX. I could change it to be more
> explicit (option 2 above)?
> 
> > 
> >> +	       (u64)csa->read(hi_offset, true, false) << 32;
> >> +	return val;
> >> +}
> >> +
> >>  static inline u32 csdev_access_read32(struct csdev_access *csa, u32 offset)
> >>  {
> >>  	if (likely(csa->io_mem))
> >> -- 
> >> 2.28.0
> >>

  reply	other threads:[~2022-08-25 16:54 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-25 14:52 [PATCH v1 0/4] coresight: Reduce duplicated sysfs accessors James Clark
2022-07-25 14:52 ` [PATCH v1 1/4] coresight: Remove unused function parameter James Clark
2022-07-25 15:07   ` German Gomez
2022-07-25 14:52 ` [PATCH v1 2/4] coresight: Simplify sysfs accessors by using csdev_access abstraction James Clark
2022-08-22 17:37   ` Mathieu Poirier
2022-08-23 12:28     ` James Clark
2022-08-25 16:54       ` Mathieu Poirier [this message]
2022-07-25 14:52 ` [PATCH v1 3/4] coresight: Re-use same function for similar sysfs register accessors James Clark
2022-08-22 17:43   ` Mathieu Poirier
2022-07-25 14:52 ` [PATCH v1 4/4] coresight: cti-sysfs: Re-use same functions " James Clark
2022-08-22 17:45 ` [PATCH v1 0/4] coresight: Reduce duplicated sysfs accessors Mathieu Poirier

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=20220825165447.GA1910926@p14s \
    --to=mathieu.poirier@linaro.org \
    --cc=coresight@lists.linaro.org \
    --cc=james.clark@arm.com \
    --cc=leo.yan@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mike.leach@linaro.org \
    --cc=suzuki.poulose@arm.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;
as well as URLs for NNTP newsgroup(s).