From: "Bernatowicz, Marcin" <marcin.bernatowicz@linux.intel.com>
To: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>,
igt-dev@lists.freedesktop.org
Cc: chris.p.wilson@linux.intel.com
Subject: Re: [igt-dev] [PATCH i-g-t 15/17] benchmarks/gem_wsim: for_each_ctx macro
Date: Fri, 6 Oct 2023 12:49:40 +0200 [thread overview]
Message-ID: <cec69707-39f9-2c2e-b0ff-d86f5903f354@linux.intel.com> (raw)
In-Reply-To: <bb4bef4b-a642-df97-2a8c-beeb0e685f2e@linux.intel.com>
Hi,
On 10/6/2023 10:49 AM, Tvrtko Ursulin wrote:
>
> On 05/10/2023 19:57, Marcin Bernatowicz wrote:
>> for_each_ctx_ctx_idx, for_each_ctx macros to easy traverse contexts.
>>
>> Signed-off-by: Marcin Bernatowicz <marcin.bernatowicz@linux.intel.com>
>> ---
>> benchmarks/gem_wsim.c | 46 ++++++++++++++++++++++++-------------------
>> 1 file changed, 26 insertions(+), 20 deletions(-)
>>
>> diff --git a/benchmarks/gem_wsim.c b/benchmarks/gem_wsim.c
>> index 0c360d891..03a86b39c 100644
>> --- a/benchmarks/gem_wsim.c
>> +++ b/benchmarks/gem_wsim.c
>> @@ -231,6 +231,13 @@ struct workload {
>> unsigned int nrequest[NUM_ENGINES];
>> };
>> +#define for_each_ctx_ctx_idx(__ctx, __wrk, __ctx_idx) \
>> + for (typeof((__wrk)->nr_ctxs) __ctx_idx = 0; __ctx_idx <
>> (__wrk)->nr_ctxs && \
>> + (__ctx = &(__wrk)->ctx_list[__ctx_idx]); ++__ctx_idx)
>> +
>
> Is the macro name a typical naming convention for IGT stuff using
> igt_unique? IMO it reads a bit odd and personally I think __for_each_ctx
> + for_each_ctx would read better, but perhaps it is a personal preference.
igt_unique allows to nest the for_each_ctx loops without a warning on
shadowed variable, I see it in macros like igt_subtest_group,
igt_subtest_with_dynamic_f to name variables igt_unique(__tmpint),
igt_unique(__tmpchar) .
I agree __for_each_ctx reads better.
>
>> +#define for_each_ctx(__ctx, __wrk) \
>> + for_each_ctx_ctx_idx(__ctx, __wrk, igt_unique(__ctx_idx))
>> +
>> static unsigned int master_prng;
>> static int verbose = 1;
>> @@ -1804,16 +1811,15 @@ static int prepare_contexts(unsigned int id,
>> struct workload *wrk)
>> {
>> uint32_t share_vm = 0;
>> struct w_step *w;
>> - int i, j;
>> + struct ctx *ctx, *ctx2;
>> + unsigned int i, j;
>> /*
>> * Transfer over engine map configuration from the workload step.
>> */
>> - for (j = 0; j < wrk->nr_ctxs; j++) {
>> - struct ctx *ctx = &wrk->ctx_list[j];
>> -
>> + for_each_ctx_ctx_idx(ctx, wrk, ctx_idx) {
>
> ctx ctx ctx ctx.. yeah it just reads wrong IMO. One ctx less would be
> better. Maybe even as far as s/ctx_idx/idx/ for readability.
>
> __for_each_ctx(ctx, wrk, ctx_idx)
>
> I guess it is passable.
>
>> for (i = 0, w = wrk->steps; i < wrk->nr_steps; i++, w++) {
>> - if (w->context != j)
>> + if (w->context != ctx_idx)
>> continue;
>> if (w->type == ENGINE_MAP) {
>> @@ -1850,32 +1856,32 @@ static int prepare_contexts(unsigned int id,
>> struct workload *wrk)
>> /*
>> * Create and configure contexts.
>> */
>> - for (i = 0; i < wrk->nr_ctxs; i++) {
>> + for_each_ctx(ctx, wrk) {
>> struct drm_i915_gem_context_create_ext_setparam ext = {
>> .base.name = I915_CONTEXT_CREATE_EXT_SETPARAM,
>> .param.param = I915_CONTEXT_PARAM_VM,
>> };
>> struct drm_i915_gem_context_create_ext args = { };
>> - struct ctx *ctx = &wrk->ctx_list[i];
>> uint32_t ctx_id;
>> igt_assert(!ctx->id);
>> /* Find existing context to share ppgtt with. */
>> - for (j = 0; !share_vm && j < wrk->nr_ctxs; j++) {
>> - struct drm_i915_gem_context_param param = {
>> - .param = I915_CONTEXT_PARAM_VM,
>> - .ctx_id = wrk->ctx_list[j].id,
>> - };
>> -
>> - if (!param.ctx_id)
>> - continue;
>> + if (!share_vm)
>> + for_each_ctx(ctx2, wrk) {
>> + struct drm_i915_gem_context_param param = {
>> + .param = I915_CONTEXT_PARAM_VM,
>> + .ctx_id = ctx2->id,
>> + };
>> +
>> + if (!param.ctx_id)
>> + continue;
>> - gem_context_get_param(fd, ¶m);
>> - igt_assert(param.value);
>> - share_vm = param.value;
>> - break;
>> - }
>> + gem_context_get_param(fd, ¶m);
>> + igt_assert(param.value);
>> + share_vm = param.value;
>> + break;
>> + }
>> if (share_vm) {
>> ext.param.value = share_vm;
>
> Conversion looks correct.
>
> Hopefully you agree __for_each_ctx + for_each_ctx is more readable, in
> which case:
Yes, proposed names look much better.
Thank You for review,
marcin
>
> Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
>
> Regards,
>
> Tvrtko
next prev parent reply other threads:[~2023-10-06 10:49 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-05 18:57 [igt-dev] [PATCH i-g-t 00/17] [RFC] benchmarks/gem_wsim: added basic xe support Marcin Bernatowicz
2023-10-05 18:57 ` [igt-dev] [PATCH i-g-t 01/17] lib/igt_device_scan: added functions to get first Xe card Marcin Bernatowicz
2023-10-05 18:57 ` [igt-dev] [PATCH i-g-t 02/17] benchmarks/gem_wsim: reposition the unbound duration boolean Marcin Bernatowicz
2023-10-05 18:57 ` [igt-dev] [PATCH i-g-t 03/17] benchmarks/gem_wsim: fix duration range check Marcin Bernatowicz
2023-10-05 18:57 ` [igt-dev] [PATCH i-g-t 04/17] benchmarks/gem_wsim: extract duration parsing code to new function Marcin Bernatowicz
2023-10-05 18:57 ` [igt-dev] [PATCH i-g-t 05/17] benchmarks/gem_wsim: fix conflicting SSEU #define and enum Marcin Bernatowicz
2023-10-05 18:57 ` [igt-dev] [PATCH i-g-t 06/17] benchmarks/gem_wsim: cleanups Marcin Bernatowicz
2023-10-05 18:57 ` [igt-dev] [PATCH i-g-t 07/17] benchmarks/gem_wsim: reposition repeat_start variable Marcin Bernatowicz
2023-10-05 18:57 ` [igt-dev] [PATCH i-g-t 08/17] benchmarks/gem_wsim: use lib code to query engines Marcin Bernatowicz
2023-10-05 18:57 ` [igt-dev] [PATCH i-g-t 09/17] benchmarks/gem_wsim: allow comments in workload description files Marcin Bernatowicz
2023-10-06 8:37 ` Tvrtko Ursulin
2023-10-05 18:57 ` [igt-dev] [PATCH i-g-t 10/17] benchmarks/gem_wsim: introduce w_step_sync function Marcin Bernatowicz
2023-10-05 18:57 ` [igt-dev] [PATCH i-g-t 11/17] benchmarks/gem_wsim: extract allocate and prepare contexts code to new functions Marcin Bernatowicz
2023-10-05 18:57 ` [igt-dev] [PATCH i-g-t 12/17] benchmarks/gem_wsim: extract prepare working sets code to new function Marcin Bernatowicz
2023-10-05 18:57 ` [igt-dev] [PATCH i-g-t 13/17] benchmarks/gem_wsim: group i915 fields Marcin Bernatowicz
2023-10-05 18:57 ` [igt-dev] [PATCH i-g-t 14/17] benchmarks/gem_wsim: for_each_dep macro Marcin Bernatowicz
2023-10-05 18:57 ` [igt-dev] [PATCH i-g-t 15/17] benchmarks/gem_wsim: for_each_ctx macro Marcin Bernatowicz
2023-10-06 8:49 ` Tvrtko Ursulin
2023-10-06 10:49 ` Bernatowicz, Marcin [this message]
2023-10-05 18:57 ` [igt-dev] [PATCH i-g-t 16/17] benchmarks/gem_wsim: for_each_w_step macro Marcin Bernatowicz
2023-10-06 11:19 ` Tvrtko Ursulin
2023-10-06 12:15 ` Bernatowicz, Marcin
2023-10-06 12:39 ` Tvrtko Ursulin
2023-10-05 18:57 ` [igt-dev] [PATCH i-g-t 17/17] benchmarks/gem_wsim: added basic xe support Marcin Bernatowicz
2023-10-06 14:12 ` Tvrtko Ursulin
2023-10-06 15:43 ` Bernatowicz, Marcin
2023-10-09 8:38 ` Tvrtko Ursulin
2023-10-05 22:03 ` [igt-dev] ✓ Fi.CI.BAT: success for benchmarks/gem_wsim: added basic xe support (rev6) Patchwork
2023-10-06 0:10 ` [igt-dev] ✓ CI.xeBAT: " Patchwork
2023-10-06 12:23 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork
-- strict thread matches above, loose matches on Subject: below --
2023-10-06 16:06 [igt-dev] [PATCH i-g-t 00/17] [RFC] benchmarks/gem_wsim: added basic xe support Marcin Bernatowicz
2023-10-06 16:06 ` [igt-dev] [PATCH i-g-t 15/17] benchmarks/gem_wsim: for_each_ctx macro Marcin Bernatowicz
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=cec69707-39f9-2c2e-b0ff-d86f5903f354@linux.intel.com \
--to=marcin.bernatowicz@linux.intel.com \
--cc=chris.p.wilson@linux.intel.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=tvrtko.ursulin@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