Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
To: Lucas De Marchi <lucas.demarchi@intel.com>,
	Kamil Konieczny <kamil.konieczny@linux.intel.com>,
	igt-dev@lists.freedesktop.org
Subject: Re: [PATCH i-g-t 1/2] lib/igt_drm_fdinfo: Use longest match first
Date: Wed, 7 Feb 2024 10:32:24 +0000	[thread overview]
Message-ID: <75d148b4-7227-4757-9e67-5558b087c1fb@linux.intel.com> (raw)
In-Reply-To: <4givrfsdv4rnga6f4ezqp27huz5dvlgxkb65wmr2j3hx5yh3vk@wbi7soq6dihy>


On 01/02/2024 14:09, Lucas De Marchi wrote:
> On Thu, Feb 01, 2024 at 01:43:21PM +0100, Kamil Konieczny wrote:
>> Hi Lucas,
>> On 2024-01-31 at 16:46:24 -0800, Lucas De Marchi wrote:
>>> Instead of checking twice the match, just use longest match first.
>>
>> Nice catch, LGTM.
>>
>> Reviewed-by: Kamil Konieczny <kamil.konieczny@linux.intel.com>

+1 looks like that was a confused change I did when adding capacity.

Going forward feel free to copy me when changing this code, given I 
mostly wrote it after all..

>>
>>>
>>> Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
>>> ---
>>>  lib/igt_drm_fdinfo.c | 19 +++++++++----------
>>>  1 file changed, 9 insertions(+), 10 deletions(-)
>>>
>>> diff --git a/lib/igt_drm_fdinfo.c b/lib/igt_drm_fdinfo.c
>>> index 222ccbfb1..5c0ccf624 100644
>>> --- a/lib/igt_drm_fdinfo.c
>>> +++ b/lib/igt_drm_fdinfo.c
>>> @@ -239,8 +239,15 @@ __igt_parse_drm_fdinfo(int dir, const char *fd, 
>>> struct drm_client_fdinfo *info,
>>>                       strlen("drm-client-id")))) {
>>>              info->id = atol(v);
>>>              good++;
>>> -        } else if (!strncmp(l, "drm-engine-", 11) &&
>>> -               strncmp(l, "drm-engine-capacity-", 20)) {
>>> +        } else if (!strncmp(l, "drm-engine-capacity-", 20)) {
>>
>> One more thing to eventually fix is removing "20" which is exact
>> len of string, with something like
>>
>> bool str_begins(char *src, char *pattern)
>>
>> One source of errors is counting letters in strings or changing
>> string itself without changing corresponding len. This can be
>> done in separate patch.
> 
> I had a patch for something similar. I usually use a strstartswith()
> that's commonly used in other projects and also matches the python name.
> 
> However I decided to drop that for now. I may have a bigger refactor in
> this function soon reworking parse_engine() and other functions: Worse
> than manually counting the chars for the strncmp() is to call strlen()
> in the same string just in the line below that to feed to parse_engine()
> :-/. As I said, still undecided what to change here and if it's worth
> it.

AFAIR hardcoded strlens were because strangely const strings fail to be 
evaluated at compile time and when I tested it and strlen was showing in 
the profile. Given how gputop sucked with CPU usage quite badly 
(relative to top) I was motivated to improve it.

The "top-level" strncmp checks are the more expensive ones because they 
all run for all lines in a given fdinfo file, while the inside the 
branch strlen runs fewer times.

Nevertheless some cleanup of this function would probably be good, just 
while doing so keep in mind how bad gputop looks compared to top in the 
profiles, not to make it much worse.

Regards,

Tvrtko

> 
> 
> Lucas De Marchi
> 
>>
>> Regards,
>> Kamil
>>
>>> +            idx = parse_engine(l, info,
>>> +                       strlen("drm-engine-capacity-"),
>>> +                       name_map, map_entries, &val);
>>> +            if (idx >= 0) {
>>> +                info->capacity[idx] = val;
>>> +                num_capacity++;
>>> +            }
>>> +        } else if (!strncmp(l, "drm-engine-", 11)) {
>>>              idx = parse_engine(l, info, strlen("drm-engine-"),
>>>                         name_map, map_entries, &val);
>>>              if (idx >= 0) {
>>> @@ -251,14 +258,6 @@ __igt_parse_drm_fdinfo(int dir, const char *fd, 
>>> struct drm_client_fdinfo *info,
>>>                  if (idx > info->last_engine_index)
>>>                      info->last_engine_index = idx;
>>>              }
>>> -        } else if (!strncmp(l, "drm-engine-capacity-", 20)) {
>>> -            idx = parse_engine(l, info,
>>> -                       strlen("drm-engine-capacity-"),
>>> -                       name_map, map_entries, &val);
>>> -            if (idx >= 0) {
>>> -                info->capacity[idx] = val;
>>> -                num_capacity++;
>>> -            }
>>>          } else if (!strncmp(l, "drm-total-", 10)) {
>>>              idx = parse_region(l, info, strlen("drm-total-"),
>>>                         region_map, region_entries, &val);
>>> -- 
>>> 2.43.0
>>>

  reply	other threads:[~2024-02-07 10:32 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-01  0:46 [PATCH i-g-t 0/2] fdinfo: drive-by changes Lucas De Marchi
2024-02-01  0:46 ` [PATCH i-g-t 1/2] lib/igt_drm_fdinfo: Use longest match first Lucas De Marchi
2024-02-01 12:43   ` Kamil Konieczny
2024-02-01 14:09     ` Lucas De Marchi
2024-02-07 10:32       ` Tvrtko Ursulin [this message]
2024-02-07 17:50         ` Lucas De Marchi
2024-02-07 18:57           ` Tvrtko Ursulin
2024-02-01  0:46 ` [PATCH i-g-t 2/2] lib/igt_drm_fdinfo: Mandatory drm-fields first Lucas De Marchi
2024-02-01 12:45   ` Kamil Konieczny
2024-02-07 10:38   ` Tvrtko Ursulin
2024-02-01  2:22 ` ✓ Fi.CI.BAT: success for fdinfo: drive-by changes Patchwork
2024-02-01  2:44 ` ✓ CI.xeBAT: " Patchwork
2024-02-01  3:48 ` ✗ Fi.CI.IGT: failure " Patchwork
2024-02-01 20:35   ` Lucas De Marchi

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=75d148b4-7227-4757-9e67-5558b087c1fb@linux.intel.com \
    --to=tvrtko.ursulin@linux.intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=kamil.konieczny@linux.intel.com \
    --cc=lucas.demarchi@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