From: Thomas Zimmermann <tzimmermann@suse.de>
To: Lucas De Marchi <lucas.demarchi@intel.com>
Cc: "Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
intel-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org,
dri-devel@lists.freedesktop.org,
"Christian König" <christian.koenig@amd.com>
Subject: Re: [Intel-gfx] [PATCH 03/19] iosys-map: Add a few more helpers
Date: Mon, 7 Feb 2022 09:36:12 +0100 [thread overview]
Message-ID: <f9fd1bca-0404-e14c-c129-a4114215f156@suse.de> (raw)
In-Reply-To: <20220204194442.5slql7ustz5ftger@ldmartin-desk2>
[-- Attachment #1.1: Type: text/plain, Size: 9517 bytes --]
Hi
Am 04.02.22 um 20:44 schrieb Lucas De Marchi:
[...]
> I only came up with such a macro after doing the rest of the patches and
> noticing a pattern that is hard to debug otherwise. I expanded the
> explanation in the doc above this macro.
>
> Maybe something like:
>
> #define IOSYS_MAP_INIT_OFFSET(map_, offset_) ({ \
> struct iosys_map copy = *(map_); \
> iosys_map_incr(©, offset_); \
> copy; \
> })
>
> Hopefully the compiler elides the additional copy, but I need to check.
I would accept this implementation of the macro. Don't worry about
possible extra copies.
>
>
>>
>> However, you won't need the offset'ed iosys_map because the
>> memcpy_to/from helpers now have the offset parameter.
>
> I can't see how the offset would help. The idea is to use a shallow copy
> of the map so another function or even compilation unit can be
> designated to read/write part of the struct overlayed in the map... not
> even have knowledge of the outer struct.
I totally see your point. I still don't think it's something you should
do. These functions don't operate on data types, but on raw memory that
has to be unpacked into memory that has a data type assigned. Types are
concepts of C, the I/O memory only knows reads and writes of different
sizes.
>
>>
>>
>>
>>> +
>>> /**
>>> * iosys_map_set_vaddr_iomem - Sets a iosys mapping structure to an
>>> address in I/O memory
>>> * @map: The iosys_map structure
>>> @@ -220,7 +260,7 @@ static inline void iosys_map_clear(struct
>>> iosys_map *map)
>>> }
>>> /**
>>> - * iosys_map_memcpy_to_offset - Memcpy into offset of iosys_map
>>> + * iosys_map_memcpy_to - Memcpy into iosys_map
>>
>> That's the fix for the other patch. :)
>
> yep :-/
>
>>
>>> * @dst: The iosys_map structure
>>> * @dst_offset: The offset from which to copy
>>> * @src: The source buffer
>>> @@ -239,6 +279,26 @@ static inline void iosys_map_memcpy_to(struct
>>> iosys_map *dst, size_t dst_offset,
>>> memcpy(dst->vaddr + dst_offset, src, len);
>>> }
>>> +/**
>>> + * iosys_map_memcpy_from - Memcpy from iosys_map into system memory
>>> + * @dst: Destination in system memory
>>> + * @src: The iosys_map structure
>>> + * @src_offset: The offset from which to copy
>>> + * @len: The number of byte in src
>>> + *
>>> + * Copies data from a iosys_map with an offset. The dest buffer is in
>>> + * system memory. Depending on the mapping location, the helper
>>> picks the
>>> + * correct method of accessing the memory.
>>> + */
>>> +static inline void iosys_map_memcpy_from(void *dst, const struct
>>> iosys_map *src,
>>> + size_t src_offset, size_t len)
>>> +{
>>> + if (src->is_iomem)
>>> + memcpy_fromio(dst, src->vaddr_iomem + src_offset, len);
>>> + else
>>> + memcpy(dst, src->vaddr + src_offset, len);
>>> +}
>>> +
>>> /**
>>> * iosys_map_incr - Increments the address stored in a iosys mapping
>>> * @map: The iosys_map structure
>>> @@ -255,4 +315,96 @@ static inline void iosys_map_incr(struct
>>> iosys_map *map, size_t incr)
>>> map->vaddr += incr;
>>> }
>>> +/**
>>> + * iosys_map_memset - Memset iosys_map
>>> + * @dst: The iosys_map structure
>>> + * @offset: Offset from dst where to start setting value
>>> + * @value: The value to set
>>> + * @len: The number of bytes to set in dst
>>> + *
>>> + * Set value in iosys_map. Depending on the buffer's location, the
>>> helper
>>> + * picks the correct method of accessing the memory.
>>> + */
>>> +static inline void iosys_map_memset(struct iosys_map *dst, size_t
>>> offset,
>>> + int value, size_t len)
>>> +{
>>> + if (dst->is_iomem)
>>> + memset_io(dst->vaddr_iomem + offset, value, len);
>>> + else
>>> + memset(dst->vaddr + offset, value, len);
>>> +}
>>
>> I've found that memset32() and memset64() can significantly faster. If
>> ever needed, we can add variants here as well.
>>
>>> +
>>> +/**
>>> + * iosys_map_rd - Read a C-type value from the iosys_map
>>> + *
>>> + * @map__: The iosys_map structure
>>> + * @offset__: The offset from which to read
>>> + * @type__: Type of the value being read
>>> + *
>>> + * Read a C type value from iosys_map, handling possible un-aligned
>>> accesses to
>>> + * the mapping.
>>> + *
>>> + * Returns:
>>> + * The value read from the mapping.
>>> + */
>>> +#define iosys_map_rd(map__, offset__, type__) ({ \
>>> + type__ val; \
>>> + iosys_map_memcpy_from(&val, map__, offset__, sizeof(val)); \
>>> + val; \
>>> +})
>>> +
>>> +/**
>>> + * iosys_map_wr - Write a C-type value to the iosys_map
>>> + *
>>> + * @map__: The iosys_map structure
>>> + * @offset__: The offset from the mapping to write to
>>> + * @type__: Type of the value being written
>>> + * @val__: Value to write
>>> + *
>>> + * Write a C-type value to the iosys_map, handling possible
>>> un-aligned accesses
>>> + * to the mapping.
>>> + */
>>> +#define iosys_map_wr(map__, offset__, type__, val__) ({ \
>>> + type__ val = (val__); \
>>> + iosys_map_memcpy_to(map__, offset__, &val, sizeof(val)); \
>>> +})
>>> +
>>> +/**
>>> + * iosys_map_rd_field - Read a member from a struct in the iosys_map
>>> + *
>>> + * @map__: The iosys_map structure
>>> + * @struct_type__: The struct describing the layout of the mapping
>>> + * @field__: Member of the struct to read
>>> + *
>>> + * Read a value from iosys_map assuming its layout is described by a
>>> struct,
>>> + * passed as argument. The offset and size to the struct member is
>>> calculated
>>> + * and possible un-aligned accesses to the mapping handled.
>>> + *
>>> + * Returns:
>>> + * The value read from the mapping.
>>> + */
>>> +#define iosys_map_rd_field(map__, struct_type__, field__)
>>> ({ \
>>
>> This macro should also have an offset__ parameter and forward it to
>> iosys_map_rd.
>
> offset is actually this macro helps calculating:
>
> struct foo {
> struct bla { ... };
> struct bla2 { ... };
> int something_else;
> };
>
>
> iosys_map_rd_field(&map, struct foo, bla.x);
>
> I feel an offset to the map, where struct foo would be located, would be
> redundant if you delegated a function to update, say, struct bla and
> that part alone.
It's not redundant, it's easy to add, consistent with the overall
interface and the next user of this code might have use for it. And as I
said above, you're not operating on struct types here. It's raw memory
that has to be packed/unpacked. The wr and rd macros are bending the
rules already. Using them carelessly can make the code behave
differently on different types of memory.
Anyway, please add the offset parameter to these macros.
Best regards
Thomas
>
> This pattern happens in patch "drm/i915/guc: Convert engine record to
> iosys_map" if it helps as an example.
>
>
> thanks
> Lucas De Marchi
>
>>
>>> + struct_type__ *s; \
>>> + iosys_map_rd(map__, offsetof(struct_type__, field__), \
>>> + typeof(s->field__)); \
>>> +})
>>> +
>>> +/**
>>> + * iosys_map_wr_field - Write to a member of a struct in the iosys_map
>>> + *
>>> + * @map__: The iosys_map structure
>>> + * @struct_type__: The struct describing the layout of the mapping
>>> + * @field__: Member of the struct to read
>>> + * @val__: Value to write
>>> + *
>>> + * Write a value to the iosys_map assuming its layout is described
>>> by a struct,
>>> + * passed as argument. The offset and size to the struct member is
>>> calculated
>>> + * and possible un-aligned accesses to the mapping handled.
>>> + */
>>> +#define iosys_map_wr_field(map__, struct_type__, field__, val__)
>>> ({ \
>>
>> And this one should also have an offset__ parameter.
>>
>> Best regards
>> Thomas
>>
>>> + struct_type__ *s; \
>>> + iosys_map_wr(map__, offsetof(struct_type__, field__), \
>>> + typeof(s->field__), val__); \
>>> +})
>>> +
>>> #endif /* __IOSYS_MAP_H__ */
>>
>> --
>> Thomas Zimmermann
>> Graphics Driver Developer
>> SUSE Software Solutions Germany GmbH
>> Maxfeldstr. 5, 90409 Nürnberg, Germany
>> (HRB 36809, AG Nürnberg)
>> Geschäftsführer: Ivo Totev
>
>
>
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]
next prev parent reply other threads:[~2022-02-07 8:36 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-04 17:44 [Intel-gfx] [PATCH 00/19] drm/i915/guc: Refactor ADS access to use iosys_map Lucas De Marchi
2022-02-04 17:44 ` [Intel-gfx] [PATCH 01/19] dma-buf-map: Rename to iosys-map Lucas De Marchi
2022-02-04 17:44 ` [Intel-gfx] [PATCH 02/19] iosys-map: Add offset to iosys_map_memcpy_to() Lucas De Marchi
2022-02-04 18:35 ` Christian König
2022-02-04 18:48 ` Thomas Zimmermann
2022-02-04 19:28 ` Lucas De Marchi
2022-02-04 17:44 ` [Intel-gfx] [PATCH 03/19] iosys-map: Add a few more helpers Lucas De Marchi
2022-02-04 19:05 ` Thomas Zimmermann
2022-02-04 19:44 ` Lucas De Marchi
2022-02-07 8:36 ` Thomas Zimmermann [this message]
2022-02-04 17:44 ` [Intel-gfx] [PATCH 04/19] drm/i915/gt: Add helper for shmem copy to iosys_map Lucas De Marchi
2022-02-04 19:15 ` Thomas Zimmermann
2022-02-07 20:35 ` Lucas De Marchi
2022-02-04 17:44 ` [Intel-gfx] [PATCH 05/19] drm/i915/guc: Keep iosys_map of ads_blob around Lucas De Marchi
2022-02-04 17:44 ` [Intel-gfx] [PATCH 06/19] drm/i915/guc: Add read/write helpers for ADS blob Lucas De Marchi
2022-02-04 17:44 ` [Intel-gfx] [PATCH 07/19] drm/i915/guc: Convert golden context init to iosys_map Lucas De Marchi
2022-02-04 19:19 ` Thomas Zimmermann
2022-02-04 17:44 ` [Intel-gfx] [PATCH 08/19] drm/i915/guc: Convert policies update " Lucas De Marchi
2022-02-04 17:44 ` [Intel-gfx] [PATCH 09/19] drm/i915/guc: Convert engine record " Lucas De Marchi
2022-02-04 19:23 ` Thomas Zimmermann
2022-02-04 17:44 ` [Intel-gfx] [PATCH 10/19] drm/i915/guc: Convert guc_ads_private_data_reset " Lucas De Marchi
2022-02-04 17:44 ` [Intel-gfx] [PATCH 11/19] drm/i915/guc: Convert golden context prep " Lucas De Marchi
2022-02-04 17:44 ` [Intel-gfx] [PATCH 12/19] drm/i915/guc: Replace check for golden context size Lucas De Marchi
2022-02-04 17:44 ` [Intel-gfx] [PATCH 13/19] drm/i915/guc: Convert mapping table to iosys_map Lucas De Marchi
2022-02-04 17:44 ` [Intel-gfx] [PATCH 14/19] drm/i915/guc: Convert capture list " Lucas De Marchi
2022-02-04 17:44 ` [Intel-gfx] [PATCH 15/19] drm/i915/guc: Prepare for error propagation Lucas De Marchi
2022-02-04 17:44 ` [Intel-gfx] [PATCH 16/19] drm/i915/guc: Use a single pass to calculate regset Lucas De Marchi
2022-02-04 17:44 ` [Intel-gfx] [PATCH 17/19] drm/i915/guc: Convert guc_mmio_reg_state_init to iosys_map Lucas De Marchi
2022-02-04 17:44 ` [Intel-gfx] [PATCH 18/19] drm/i915/guc: Convert __guc_ads_init " Lucas De Marchi
2022-02-04 17:44 ` [Intel-gfx] [PATCH 19/19] drm/i915/guc: Remove plain ads_blob pointer Lucas De Marchi
2022-02-04 18:38 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for drm/i915/guc: Refactor ADS access to use iosys_map Patchwork
2022-02-04 18:40 ` [Intel-gfx] ✗ Fi.CI.SPARSE: " Patchwork
2022-02-04 19:12 ` [Intel-gfx] ✗ Fi.CI.BAT: failure " 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=f9fd1bca-0404-e14c-c129-a4114215f156@suse.de \
--to=tzimmermann@suse.de \
--cc=christian.koenig@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lucas.demarchi@intel.com \
--cc=thomas.hellstrom@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