From: Jani Nikula <jani.nikula@linux.intel.com>
To: "Ville Syrjälä" <ville.syrjala@linux.intel.com>
Cc: intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH 05/12] drm/i915: Add DEFINE_SNPRINTF_ARRAY()
Date: Thu, 11 Oct 2018 19:07:46 +0300 [thread overview]
Message-ID: <87efcwwjot.fsf@intel.com> (raw)
In-Reply-To: <20181011124715.GH9144@intel.com>
On Thu, 11 Oct 2018, Ville Syrjälä <ville.syrjala@linux.intel.com> wrote:
> On Thu, Oct 11, 2018 at 03:14:41PM +0300, Jani Nikula wrote:
>> On Wed, 10 Oct 2018, Ville Syrjala <ville.syrjala@linux.intel.com> wrote:
>> > From: Ville Syrjälä <ville.syrjala@linux.intel.com>
>> >
>> > Templatize snprintf_int_array() to allow us to print
>> > different kinds of arrays without having to type all
>> > the boilerplate for the snprintf() loop.
>>
>> I might just feel happier about duplicating the boilerplate...
>
> How about when the third user appears? :)
>
> Not sure I have a third user for this actually.
> snprintf_output_types() is pretty close, and there are other
> bitmask I'd probably like to decode. But I couldn't immediately
> think of a nice way to handle bitmasks and arrays in the same
> function.
So here's the non-macro generic approach. It's not perfect, it just has
different wrinkles:
static int snprintf_int(char *str, size_t len, const void *elem)
{
return snprintf(str, len, "%d", *((const int *)elem));
}
static void snprintf_array(char *str, size_t len, const void *array, int nelem,
size_t size, const char *sep,
int (*print)(char *str, size_t len, const void *elem))
{
int i, r;
if (len)
str[0] = '\0';
for (i = 0; i < nelem; i++) {
const void *elem = array + i * size;
if (i) {
r = snprintf(str, len, "%s", sep);
if (r >= len)
return;
str += r;
len -= r;
}
r = print(str, len, elem);
if (r >= len)
return;
str += r;
len -= r;
}
}
static void snprintf_int_array(char *str, size_t len, const int *array, int nelem)
{
snprintf_array(str, len, array, nelem, sizeof(array[0]), ", ",
snprintf_int);
}
Of course, this doesn't help with bitmasks either. You'd first have to
split the bitmask into an array.
BR,
Jani.
>
>>
>> BR,
>> Jani.
>>
>>
>>
>> >
>> > Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
>> > ---
>> > drivers/gpu/drm/i915/i915_utils.h | 16 ++++++++++++++++
>> > drivers/gpu/drm/i915/intel_dp.c | 17 ++---------------
>> > 2 files changed, 18 insertions(+), 15 deletions(-)
>> >
>> > diff --git a/drivers/gpu/drm/i915/i915_utils.h b/drivers/gpu/drm/i915/i915_utils.h
>> > index 5858a43e19da..079aefa20bee 100644
>> > --- a/drivers/gpu/drm/i915/i915_utils.h
>> > +++ b/drivers/gpu/drm/i915/i915_utils.h
>> > @@ -161,4 +161,20 @@ static inline const char *enableddisabled(bool v)
>> > return v ? "enabled" : "disabled";
>> > }
>> >
>> > +#define DEFINE_SNPRINTF_ARRAY(name, type, values, index, fmt, ...) \
>> > +void name(char *_str, size_t _len, const type *values, int _nelems) \
>> > +{ \
>> > + int index; \
>> > + if (_len) \
>> > + _str[0] = '\0'; \
>> > + for (index = 0; index < _nelems; index++) { \
>> > + int _r = snprintf(_str, _len, "%s" fmt, \
>> > + index ? ", " : "", __VA_ARGS__); \
>> > + if (_r >= _len) \
>> > + return; \
>> > + _str += _r; \
>> > + _len -= _r; \
>> > + } \
>> > +}
>> > +
>> > #endif /* !__I915_UTILS_H */
>> > diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
>> > index 13ff89be6ad6..dd8634b40179 100644
>> > --- a/drivers/gpu/drm/i915/intel_dp.c
>> > +++ b/drivers/gpu/drm/i915/intel_dp.c
>> > @@ -1774,21 +1774,8 @@ intel_dp_set_clock(struct intel_encoder *encoder,
>> > }
>> > }
>> >
>> > -static void snprintf_int_array(char *str, size_t len,
>> > - const int *array, int nelem)
>> > -{
>> > - int i;
>> > -
>> > - str[0] = '\0';
>> > -
>> > - for (i = 0; i < nelem; i++) {
>> > - int r = snprintf(str, len, "%s%d", i ? ", " : "", array[i]);
>> > - if (r >= len)
>> > - return;
>> > - str += r;
>> > - len -= r;
>> > - }
>> > -}
>> > +static DEFINE_SNPRINTF_ARRAY(snprintf_int_array,
>> > + int, array, i, "%d", array[i]);
>> >
>> > static void intel_dp_print_rates(struct intel_dp *intel_dp)
>> > {
>>
>> --
>> Jani Nikula, Intel Open Source Graphics Center
--
Jani Nikula, Intel Open Source Graphics Center
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
next prev parent reply other threads:[~2018-10-11 16:07 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-10 13:04 [PATCH 00/12] drm/i915: Clean up the wm mem latency stuff Ville Syrjala
2018-10-10 13:04 ` [PATCH 01/12] drm/i915: Store all wm memory latency values in .1 usec units Ville Syrjala
2018-10-10 13:12 ` Chris Wilson
2018-10-10 15:35 ` Ville Syrjälä
2018-10-26 18:14 ` [PATCH v2 " Ville Syrjala
2018-10-10 13:04 ` [PATCH 02/12] drm/i915: Use the spr/cur latencies on vlv/chv/g4x Ville Syrjala
2018-10-10 13:04 ` [PATCH 03/12] drm/i915: Eliminate skl_latency[] Ville Syrjala
2018-10-10 13:04 ` [PATCH 04/12] drm/i915: Add dev_priv->wm.num_levels and use it everywhere Ville Syrjala
2018-10-26 18:27 ` [PATCH v2 " Ville Syrjala
2018-10-10 13:04 ` [PATCH 05/12] drm/i915: Add DEFINE_SNPRINTF_ARRAY() Ville Syrjala
2018-10-11 12:14 ` Jani Nikula
2018-10-11 12:47 ` Ville Syrjälä
2018-10-11 16:07 ` Jani Nikula [this message]
2018-10-10 13:04 ` [PATCH 06/12] drm/i915: Make the WM memory latency print more compact Ville Syrjala
2018-10-10 13:04 ` [PATCH 07/12] drm/i915: Eliminate redundant ilk sprite/cursor wm fixup code Ville Syrjala
2018-10-10 13:04 ` [PATCH 08/12] drm/i915: Split skl+ and ilk+ read_wm_latency() Ville Syrjala
2018-10-26 18:45 ` [PATCH v2 " Ville Syrjala
2018-10-10 13:04 ` [PATCH 09/12] drm/i915: Sanitize wm latency values for ilk+ Ville Syrjala
2018-10-26 19:11 ` [PATCH v2 " Ville Syrjala
2018-10-10 13:04 ` [PATCH 10/12] drm/i915: Drop the funky ilk wm setup Ville Syrjala
2018-10-10 13:04 ` [PATCH 11/12] drm/i915: Allow LP3 watermarks on ILK Ville Syrjala
2018-10-10 13:04 ` [PATCH 12/12] drm/i915: Remove the remnants of the ilk+ LP0 wm hack Ville Syrjala
2018-10-10 14:34 ` ✗ Fi.CI.CHECKPATCH: warning for drm/i915: Clean up the wm mem latency stuff Patchwork
2018-10-10 14:38 ` ✗ Fi.CI.SPARSE: " Patchwork
2018-10-10 14:50 ` ✗ Fi.CI.BAT: failure " Patchwork
2018-10-26 18:17 ` ✗ Fi.CI.BAT: failure for drm/i915: Clean up the wm mem latency stuff (rev2) Patchwork
2018-10-26 18:37 ` ✗ Fi.CI.BAT: failure for drm/i915: Clean up the wm mem latency stuff (rev3) Patchwork
2018-10-26 19:01 ` ✗ Fi.CI.BAT: failure for drm/i915: Clean up the wm mem latency stuff (rev4) Patchwork
2018-10-26 19:29 ` ✗ Fi.CI.CHECKPATCH: warning for drm/i915: Clean up the wm mem latency stuff (rev5) Patchwork
2018-10-26 19:34 ` ✗ Fi.CI.SPARSE: " Patchwork
2018-10-26 19:47 ` ✓ Fi.CI.BAT: success " Patchwork
2018-10-27 5:17 ` ✓ Fi.CI.IGT: " Patchwork
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=87efcwwjot.fsf@intel.com \
--to=jani.nikula@linux.intel.com \
--cc=intel-gfx@lists.freedesktop.org \
--cc=ville.syrjala@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