From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by gabe.freedesktop.org (Postfix) with ESMTPS id B811A10E138 for ; Fri, 7 Jul 2023 00:03:41 +0000 (UTC) Date: Thu, 06 Jul 2023 16:46:27 -0700 Message-ID: <87fs60d2ng.wl-ashutosh.dixit@intel.com> From: "Dixit, Ashutosh" To: Himal Prasad Ghimiray In-Reply-To: <20230706104500.595707-2-himal.prasad.ghimiray@intel.com> References: <20230706104500.595707-1-himal.prasad.ghimiray@intel.com> <20230706104500.595707-2-himal.prasad.ghimiray@intel.com> MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII Subject: Re: [igt-dev] [PATCH i-g-t v7 1/4] lib/igt_sysfs: Add support to query number of tiles List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: igt-dev@lists.freedesktop.org, Upadhyay Errors-To: igt-dev-bounces@lists.freedesktop.org Sender: "igt-dev" List-ID: On Thu, 06 Jul 2023 03:44:57 -0700, Himal Prasad Ghimiray wrote: > > With tile and GT seperation in KMD, we need to know > number of tiles supported by platform. > We will need to access tile associated properties from IGT. > Hence adding iterator for all supported tiles. > > v2: > - Calculate number of tiles once within iterator. (Rahul) > - Use snprintf instead of sprintf. > > v3: > - Remove unrequired for_each_sysfs_tile_dirfd (Ashutosh) > > v4: > - Implement tiles related functions in lib. > > Cc: Ashutosh Dixit > Cc: Aravind Iddamsetty > Cc: Upadhyay > Cc: Janga Rahul Kumar > Signed-off-by: Himal Prasad Ghimiray > --- > lib/igt_sysfs.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++ > lib/igt_sysfs.h | 10 +++++++ > 2 files changed, 87 insertions(+) > > diff --git a/lib/igt_sysfs.c b/lib/igt_sysfs.c > index 0876f4c6b..dcb38cfc9 100644 > --- a/lib/igt_sysfs.c > +++ b/lib/igt_sysfs.c > @@ -903,3 +903,80 @@ void igt_sysfs_engines(int xe, int engines, const char **property, > close(engine_fd); > } > } > + > +/** > + * xe_sysfs_tile_path: > + * @device: fd of the device xe_device > + * @tile: tile number > + * @path: buffer to fill with the sysfs tile path to the device > + * @pathlen: length of @path buffer > + * > + * This finds the sysfs directory corresponding to @device and @tile. If the tile > + * specific directory is not available and tile is 0, path is filled with sysfs > + * base directory. > + * > + * Returns: > + * The directory path, or NULL on failure. > + */ > +char *xe_sysfs_tile_path(int xe_device, int tile, char *path, int pathlen) > +{ > + struct stat st; > + > + if (xe_device < 0) > + return NULL; > + > + if (igt_debug_on(fstat(xe_device, &st)) || igt_debug_on(!S_ISCHR(st.st_mode))) > + return NULL; > + > + snprintf(path, pathlen, "/sys/dev/char/%d:%d/device/tile%d", > + major(st.st_rdev), minor(st.st_rdev), tile); > + > + if (!access(path, F_OK)) > + return path; > + if (!tile) > + return igt_sysfs_path(xe_device, path, pathlen); This if () is in igt_sysfs_gt_path to take care of the legacy case. There is no such thing for xe, so let's remove this if (). Fix the comment above the function too. > + return NULL; > +} > + > +/** > + * xe_sysfs_tile_open: > + * @xe_device: fd of the device > + * @tile: tile number > + * > + * This opens the sysfs tile directory corresponding to device and tile for use > + * > + * Returns: > + * The directory fd, or -1 on failure. > + */ > +int xe_sysfs_tile_open(int xe_device, int tile) > +{ > + char path[96]; > + > + if (!xe_sysfs_tile_path(xe_device, tile, path, sizeof(path))) > + return -1; > + > + return open(path, O_RDONLY); > +} > + > +/** > + * xe_sysfs_get_num_tiles: > + * @xe_device: fd of the device > + * > + * Reads number of tile sysfs entries. > + * Asserts for at least one tile entry. > + * (see xe_sysfs_tile_path). > + * > + * Returns: Number of tiles. > + */ > +int xe_sysfs_get_num_tiles(int xe_device) > +{ > + int num_tiles = 0; > + char path[96]; > + > + while (xe_sysfs_tile_path(xe_device, num_tiles, path, sizeof(path))) > + ++num_tiles; > + > + igt_assert_f(num_tiles > 0, "No GT sysfs entry is found."); > + > + return num_tiles; > +} > diff --git a/lib/igt_sysfs.h b/lib/igt_sysfs.h > index 5635fc690..5d584b1c7 100644 > --- a/lib/igt_sysfs.h > +++ b/lib/igt_sysfs.h > @@ -38,6 +38,11 @@ > (dirfd__ = igt_sysfs_gt_open(i915__, gt__)) != -1; \ > close(dirfd__), gt__++) > > +#define for_each_sysfs_tile_dirfd(xe__, dirfd__, tile__) \ > + for (tile__ = 0; \ > + (dirfd__ = xe_sysfs_tile_open(xe__, tile__)) != -1; \ > + close(dirfd__), tile__++) > + > #define i915_for_each_gt for_each_sysfs_gt_dirfd > > #define igt_sysfs_rps_write(dir, id, data, len) \ > @@ -73,6 +78,8 @@ > #define igt_sysfs_rps_set_boolean(dir, id, value) \ > igt_sysfs_set_boolean(dir, igt_sysfs_dir_id_to_name(dir, id), value) > > +#define xe_for_each_tile for_each_sysfs_tile_dirfd > + > enum i915_attr_id { > RPS_ACT_FREQ_MHZ, > RPS_CUR_FREQ_MHZ, > @@ -150,4 +157,7 @@ void igt_sysfs_rw_attr_verify(igt_sysfs_rw_attr_t *rw); > void igt_sysfs_engines(int xe, int engines, const char **property, > void (*test)(int, int, const char **)); > > +char *xe_sysfs_tile_path(int xe_device, int tile, char *path, int pathlen); > +int xe_sysfs_tile_open(int xe_device, int tile); > +int xe_sysfs_get_num_tiles(int xe_device); > #endif /* __IGT_SYSFS_H__ */ > -- > 2.25.1 >